summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/Document.cpp2459
-rw-r--r--fpdfsdk/src/javascript/Field.cpp6345
-rw-r--r--fpdfsdk/src/javascript/JS_EventHandler.cpp755
-rw-r--r--fpdfsdk/src/javascript/JS_GlobalData.cpp845
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp445
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp3949
-rw-r--r--fpdfsdk/src/javascript/global.cpp872
-rw-r--r--fpdfsdk/src/javascript/util.cpp1035
8 files changed, 8403 insertions, 8302 deletions
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index fc453b0fc8..c35045c76b 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -22,13 +22,13 @@
static v8::Isolate* GetIsolate(IFXJS_Context* cc)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
- return pRuntime->GetIsolate();
+ return pRuntime->GetIsolate();
}
BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
@@ -45,14 +45,14 @@ IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj)
PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject)
: CJS_EmbedObj(pJSObject)
{
- bUI = TRUE;
- nStart = 0;
- nEnd = 0;
- bSilent = FALSE;
- bShrinkToFit = FALSE;
- bPrintAsImage = FALSE;
- bReverse = FALSE;
- bAnnotations = TRUE;
+ bUI = TRUE;
+ nStart = 0;
+ nEnd = 0;
+ bSilent = FALSE;
+ bShrinkToFit = FALSE;
+ bPrintAsImage = FALSE;
+ bReverse = FALSE;
+ bAnnotations = TRUE;
}
/* ---------------------- Document ---------------------- */
@@ -64,255 +64,255 @@ BEGIN_JS_STATIC_CONST(CJS_Document)
END_JS_STATIC_CONST()
BEGIN_JS_STATIC_PROP(CJS_Document)
- JS_STATIC_PROP_ENTRY(ADBE)
- JS_STATIC_PROP_ENTRY(author)
- JS_STATIC_PROP_ENTRY(baseURL)
- JS_STATIC_PROP_ENTRY(bookmarkRoot)
- JS_STATIC_PROP_ENTRY(calculate)
- JS_STATIC_PROP_ENTRY(Collab)
- JS_STATIC_PROP_ENTRY(creationDate)
- JS_STATIC_PROP_ENTRY(creator)
- JS_STATIC_PROP_ENTRY(delay)
- JS_STATIC_PROP_ENTRY(dirty)
- JS_STATIC_PROP_ENTRY(documentFileName)
- JS_STATIC_PROP_ENTRY(external)
- JS_STATIC_PROP_ENTRY(filesize)
- JS_STATIC_PROP_ENTRY(icons)
- JS_STATIC_PROP_ENTRY(info)
- JS_STATIC_PROP_ENTRY(keywords)
- JS_STATIC_PROP_ENTRY(layout)
- JS_STATIC_PROP_ENTRY(media)
- JS_STATIC_PROP_ENTRY(modDate)
- JS_STATIC_PROP_ENTRY(mouseX)
- JS_STATIC_PROP_ENTRY(mouseY)
- JS_STATIC_PROP_ENTRY(numFields)
- JS_STATIC_PROP_ENTRY(numPages)
- JS_STATIC_PROP_ENTRY(pageNum)
- JS_STATIC_PROP_ENTRY(pageWindowRect)
- JS_STATIC_PROP_ENTRY(path)
- JS_STATIC_PROP_ENTRY(producer)
- JS_STATIC_PROP_ENTRY(subject)
- JS_STATIC_PROP_ENTRY(title)
- JS_STATIC_PROP_ENTRY(zoom)
- JS_STATIC_PROP_ENTRY(zoomType)
+ JS_STATIC_PROP_ENTRY(ADBE)
+ JS_STATIC_PROP_ENTRY(author)
+ JS_STATIC_PROP_ENTRY(baseURL)
+ JS_STATIC_PROP_ENTRY(bookmarkRoot)
+ JS_STATIC_PROP_ENTRY(calculate)
+ JS_STATIC_PROP_ENTRY(Collab)
+ JS_STATIC_PROP_ENTRY(creationDate)
+ JS_STATIC_PROP_ENTRY(creator)
+ JS_STATIC_PROP_ENTRY(delay)
+ JS_STATIC_PROP_ENTRY(dirty)
+ JS_STATIC_PROP_ENTRY(documentFileName)
+ JS_STATIC_PROP_ENTRY(external)
+ JS_STATIC_PROP_ENTRY(filesize)
+ JS_STATIC_PROP_ENTRY(icons)
+ JS_STATIC_PROP_ENTRY(info)
+ JS_STATIC_PROP_ENTRY(keywords)
+ JS_STATIC_PROP_ENTRY(layout)
+ JS_STATIC_PROP_ENTRY(media)
+ JS_STATIC_PROP_ENTRY(modDate)
+ JS_STATIC_PROP_ENTRY(mouseX)
+ JS_STATIC_PROP_ENTRY(mouseY)
+ JS_STATIC_PROP_ENTRY(numFields)
+ JS_STATIC_PROP_ENTRY(numPages)
+ JS_STATIC_PROP_ENTRY(pageNum)
+ JS_STATIC_PROP_ENTRY(pageWindowRect)
+ JS_STATIC_PROP_ENTRY(path)
+ JS_STATIC_PROP_ENTRY(producer)
+ JS_STATIC_PROP_ENTRY(subject)
+ JS_STATIC_PROP_ENTRY(title)
+ JS_STATIC_PROP_ENTRY(zoom)
+ JS_STATIC_PROP_ENTRY(zoomType)
END_JS_STATIC_PROP()
BEGIN_JS_STATIC_METHOD(CJS_Document)
- JS_STATIC_METHOD_ENTRY(addAnnot)
- JS_STATIC_METHOD_ENTRY(addField)
- JS_STATIC_METHOD_ENTRY(addLink)
- JS_STATIC_METHOD_ENTRY(addIcon)
- JS_STATIC_METHOD_ENTRY(calculateNow)
- JS_STATIC_METHOD_ENTRY(closeDoc)
- JS_STATIC_METHOD_ENTRY(createDataObject)
- JS_STATIC_METHOD_ENTRY(deletePages)
- JS_STATIC_METHOD_ENTRY(exportAsText)
- JS_STATIC_METHOD_ENTRY(exportAsFDF)
- JS_STATIC_METHOD_ENTRY(exportAsXFDF)
- JS_STATIC_METHOD_ENTRY(extractPages)
- JS_STATIC_METHOD_ENTRY(getAnnot)
- JS_STATIC_METHOD_ENTRY(getAnnots)
- JS_STATIC_METHOD_ENTRY(getAnnot3D)
- JS_STATIC_METHOD_ENTRY(getAnnots3D)
- JS_STATIC_METHOD_ENTRY(getField)
- JS_STATIC_METHOD_ENTRY(getIcon)
- JS_STATIC_METHOD_ENTRY(getLinks)
- JS_STATIC_METHOD_ENTRY(getNthFieldName)
- JS_STATIC_METHOD_ENTRY(getOCGs)
- JS_STATIC_METHOD_ENTRY(getPageBox)
- JS_STATIC_METHOD_ENTRY(getPageNthWord)
- JS_STATIC_METHOD_ENTRY(getPageNthWordQuads)
- JS_STATIC_METHOD_ENTRY(getPageNumWords)
- JS_STATIC_METHOD_ENTRY(getPrintParams)
- JS_STATIC_METHOD_ENTRY(getURL)
- JS_STATIC_METHOD_ENTRY(importAnFDF)
- JS_STATIC_METHOD_ENTRY(importAnXFDF)
- JS_STATIC_METHOD_ENTRY(importTextData)
- JS_STATIC_METHOD_ENTRY(insertPages)
- JS_STATIC_METHOD_ENTRY(mailForm)
- JS_STATIC_METHOD_ENTRY(print)
- JS_STATIC_METHOD_ENTRY(removeField)
- JS_STATIC_METHOD_ENTRY(replacePages)
- JS_STATIC_METHOD_ENTRY(resetForm)
- JS_STATIC_METHOD_ENTRY(removeIcon)
- JS_STATIC_METHOD_ENTRY(saveAs)
- JS_STATIC_METHOD_ENTRY(submitForm)
- JS_STATIC_METHOD_ENTRY(mailDoc)
+ JS_STATIC_METHOD_ENTRY(addAnnot)
+ JS_STATIC_METHOD_ENTRY(addField)
+ JS_STATIC_METHOD_ENTRY(addLink)
+ JS_STATIC_METHOD_ENTRY(addIcon)
+ JS_STATIC_METHOD_ENTRY(calculateNow)
+ JS_STATIC_METHOD_ENTRY(closeDoc)
+ JS_STATIC_METHOD_ENTRY(createDataObject)
+ JS_STATIC_METHOD_ENTRY(deletePages)
+ JS_STATIC_METHOD_ENTRY(exportAsText)
+ JS_STATIC_METHOD_ENTRY(exportAsFDF)
+ JS_STATIC_METHOD_ENTRY(exportAsXFDF)
+ JS_STATIC_METHOD_ENTRY(extractPages)
+ JS_STATIC_METHOD_ENTRY(getAnnot)
+ JS_STATIC_METHOD_ENTRY(getAnnots)
+ JS_STATIC_METHOD_ENTRY(getAnnot3D)
+ JS_STATIC_METHOD_ENTRY(getAnnots3D)
+ JS_STATIC_METHOD_ENTRY(getField)
+ JS_STATIC_METHOD_ENTRY(getIcon)
+ JS_STATIC_METHOD_ENTRY(getLinks)
+ JS_STATIC_METHOD_ENTRY(getNthFieldName)
+ JS_STATIC_METHOD_ENTRY(getOCGs)
+ JS_STATIC_METHOD_ENTRY(getPageBox)
+ JS_STATIC_METHOD_ENTRY(getPageNthWord)
+ JS_STATIC_METHOD_ENTRY(getPageNthWordQuads)
+ JS_STATIC_METHOD_ENTRY(getPageNumWords)
+ JS_STATIC_METHOD_ENTRY(getPrintParams)
+ JS_STATIC_METHOD_ENTRY(getURL)
+ JS_STATIC_METHOD_ENTRY(importAnFDF)
+ JS_STATIC_METHOD_ENTRY(importAnXFDF)
+ JS_STATIC_METHOD_ENTRY(importTextData)
+ JS_STATIC_METHOD_ENTRY(insertPages)
+ JS_STATIC_METHOD_ENTRY(mailForm)
+ JS_STATIC_METHOD_ENTRY(print)
+ JS_STATIC_METHOD_ENTRY(removeField)
+ JS_STATIC_METHOD_ENTRY(replacePages)
+ JS_STATIC_METHOD_ENTRY(resetForm)
+ JS_STATIC_METHOD_ENTRY(removeIcon)
+ JS_STATIC_METHOD_ENTRY(saveAs)
+ JS_STATIC_METHOD_ENTRY(submitForm)
+ JS_STATIC_METHOD_ENTRY(mailDoc)
END_JS_STATIC_METHOD()
IMPLEMENT_JS_CLASS(CJS_Document, Document)
-FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc)
+FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc)
{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
- Document* pDoc = (Document*)GetEmbedObject();
- ASSERT(pDoc != NULL);
+ Document* pDoc = (Document*)GetEmbedObject();
+ ASSERT(pDoc != NULL);
- pDoc->AttachDoc(pContext->GetReaderDocument());
- pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
- return TRUE;
+ pDoc->AttachDoc(pContext->GetReaderDocument());
+ pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
+ return TRUE;
};
/* --------------------------------- Document --------------------------------- */
Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
- m_isolate(NULL),
- m_pIconTree(NULL),
- m_pDocument(NULL),
- m_cwBaseURL(L""),
- m_bDelay(FALSE)
+ m_isolate(NULL),
+ m_pIconTree(NULL),
+ m_pDocument(NULL),
+ m_cwBaseURL(L""),
+ m_bDelay(FALSE)
{
}
Document::~Document()
{
- if (m_pIconTree)
- {
- m_pIconTree->DeleteIconTree();
- delete m_pIconTree;
- m_pIconTree = NULL;
- }
- for (int i=0; i<m_DelayData.GetSize(); i++)
- {
- if (CJS_DelayData* pData = m_DelayData.GetAt(i))
- {
- delete pData;
- pData = NULL;
- m_DelayData.SetAt(i, NULL);
+ if (m_pIconTree)
+ {
+ m_pIconTree->DeleteIconTree();
+ delete m_pIconTree;
+ m_pIconTree = NULL;
+ }
+ for (int i=0; i<m_DelayData.GetSize(); i++)
+ {
+ if (CJS_DelayData* pData = m_DelayData.GetAt(i))
+ {
+ delete pData;
+ pData = NULL;
+ m_DelayData.SetAt(i, NULL);
- }
- }
+ }
+ }
- m_DelayData.RemoveAll();
- m_DelayAnnotData.RemoveAll();
+ m_DelayData.RemoveAll();
+ m_DelayAnnotData.RemoveAll();
}
//the total number of fileds in document.
FX_BOOL Document::numFields(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
- return FALSE;
- }
- CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();
- CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();
- vp << (int)pPDFForm->CountFields();
- return TRUE;
+ if (vp.IsSetting()) {
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ return FALSE;
+ }
+ CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();
+ CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();
+ vp << (int)pPDFForm->CountFields();
+ return TRUE;
}
FX_BOOL Document::dirty(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsGetting())
- {
- if (m_pDocument->GetChangeMark())
- vp << true;
- else
- vp << false;
- }
- else
- {
- bool bChanged = false;
+ if (vp.IsGetting())
+ {
+ if (m_pDocument->GetChangeMark())
+ vp << true;
+ else
+ vp << false;
+ }
+ else
+ {
+ bool bChanged = false;
- vp >> bChanged;
+ vp >> bChanged;
- if (bChanged)
- m_pDocument->SetChangeMark();
- else
- m_pDocument->ClearChangeMark();
- }
+ if (bChanged)
+ m_pDocument->SetChangeMark();
+ else
+ m_pDocument->ClearChangeMark();
+ }
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::ADBE(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsGetting())
- {
- vp.SetNull();
- }
- else
- {
- }
+ if (vp.IsGetting())
+ {
+ vp.SetNull();
+ }
+ else
+ {
+ }
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::pageNum(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsGetting())
- {
- if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView())
- {
- vp << pPageView->GetPageIndex();
- }
- }
- else
- {
- int iPageCount = m_pDocument->GetPageCount();
- int iPageNum = 0;
- vp >> iPageNum;
-
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- if (iPageNum >= 0 && iPageNum < iPageCount)
- {
- pEnv->JS_docgotoPage(iPageNum);
- }
- else if (iPageNum >= iPageCount)
- {
- pEnv->JS_docgotoPage(iPageCount-1);
- }
- else if (iPageNum < 0)
- {
- pEnv->JS_docgotoPage(0);
- }
- }
-
- return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsGetting())
+ {
+ if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView())
+ {
+ vp << pPageView->GetPageIndex();
+ }
+ }
+ else
+ {
+ int iPageCount = m_pDocument->GetPageCount();
+ int iPageNum = 0;
+ vp >> iPageNum;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ if (iPageNum >= 0 && iPageNum < iPageCount)
+ {
+ pEnv->JS_docgotoPage(iPageNum);
+ }
+ else if (iPageNum >= iPageCount)
+ {
+ pEnv->JS_docgotoPage(iPageCount-1);
+ }
+ else if (iPageNum < 0)
+ {
+ pEnv->JS_docgotoPage(0);
+ }
+ }
+
+ return TRUE;
}
FX_BOOL Document::ParserParams(JSObject* pObj,CJS_AnnotObj& annotobj)
{
- // Not supported.
- return TRUE;
+ // Not supported.
+ return TRUE;
}
FX_BOOL Document::addAnnot(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- // Not supported.
- return TRUE;
+ // Not supported.
+ return TRUE;
}
FX_BOOL Document::addField(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- // Not supported.
- return TRUE;
+ // Not supported.
+ return TRUE;
}
FX_BOOL Document::exportAsText(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- // Unsafe, not supported.
- return TRUE;
+ // Unsafe, not supported.
+ return TRUE;
}
FX_BOOL Document::exportAsFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- // Unsafe, not supported.
- return TRUE;
+ // Unsafe, not supported.
+ return TRUE;
}
FX_BOOL Document::exportAsXFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- // Unsafe, not supported.
- return TRUE;
+ // Unsafe, not supported.
+ return TRUE;
}
//Maps a field object in PDF document to a JavaScript variable
@@ -321,75 +321,75 @@ FX_BOOL Document::exportAsXFDF(IFXJS_Context* cc, const CJS_Parameters& params,
FX_BOOL Document::getField(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context*)cc;
- if (params.size() < 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
+ CJS_Context* pContext = (CJS_Context*)cc;
+ if (params.size() < 1) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
- CFX_WideString wideName = params[0].ToCFXWideString();
+ CFX_WideString wideName = params[0].ToCFXWideString();
- CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- if (pPDFForm->CountFields(wideName) <= 0)
- {
- vRet.SetNull();
- return TRUE;
- }
+ CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ if (pPDFForm->CountFields(wideName) <= 0)
+ {
+ vRet.SetNull();
+ return TRUE;
+ }
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
- v8::Isolate* isolate = GetIsolate(cc);
- CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj);
- Field* pField = (Field *)pJSField->GetEmbedObject();
- pField->AttachField(this, wideName);
+ v8::Isolate* isolate = GetIsolate(cc);
+ CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj);
+ Field* pField = (Field *)pJSField->GetEmbedObject();
+ pField->AttachField(this, wideName);
- vRet = pJSField;
- return TRUE;
+ vRet = pJSField;
+ return TRUE;
}
//Gets the name of the nth field in the document
FX_BOOL Document::getNthFieldName(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context*)cc;
- if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
+ CJS_Context* pContext = (CJS_Context*)cc;
+ if (params.size() != 1) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
- int nIndex = params[0].ToInt();
- if (nIndex < 0) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
- return FALSE;
- }
+ int nIndex = params[0].ToInt();
+ if (nIndex < 0) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+ return FALSE;
+ }
- CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- CPDF_FormField* pField = pPDFForm->GetField(nIndex);
- if (!pField)
- return FALSE;
+ CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ CPDF_FormField* pField = pPDFForm->GetField(nIndex);
+ if (!pField)
+ return FALSE;
- vRet = pField->GetFullName().c_str();
- return TRUE;
+ vRet = pField->GetFullName().c_str();
+ return TRUE;
}
FX_BOOL Document::importAnFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- // Unsafe, not supported.
- return TRUE;
+ // Unsafe, not supported.
+ return TRUE;
}
FX_BOOL Document::importAnXFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- // Unsafe, not supported.
- return TRUE;
+ // Unsafe, not supported.
+ return TRUE;
}
FX_BOOL Document::importTextData(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- // Unsafe, not supported.
- return TRUE;
+ // Unsafe, not supported.
+ return TRUE;
}
//exports the form data and mails the resulting fdf file as an attachment to all recipients.
@@ -399,110 +399,110 @@ FX_BOOL Document::importTextData(IFXJS_Context* cc, const CJS_Parameters& params
FX_BOOL Document::mailForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
- int iLength = params.size();
+ int iLength = params.size();
- FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE;
- CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L"";
- CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L"";
- CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L"";
- CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L"";
- CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L"";
+ FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE;
+ CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L"";
+ CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L"";
+ CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L"";
+ CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L"";
+ CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L"";
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
- CFX_ByteTextBuf textBuf;
- if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
- return FALSE;
+ CFX_ByteTextBuf textBuf;
+ if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
+ return FALSE;
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CPDFDoc_Environment* pEnv = pContext->GetReaderApp();
- ASSERT(pEnv != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CPDFDoc_Environment* pEnv = pContext->GetReaderApp();
+ ASSERT(pEnv != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
- pRuntime->BeginBlock();
- pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
- pRuntime->EndBlock();
- return TRUE;
+ pRuntime->BeginBlock();
+ pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
+ pRuntime->EndBlock();
+ return TRUE;
}
FX_BOOL Document::print(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- FX_BOOL bUI = TRUE;
- int nStart = 0;
- int nEnd = 0;
- FX_BOOL bSilent = FALSE;
- FX_BOOL bShrinkToFit = FALSE;
- FX_BOOL bPrintAsImage = FALSE;
- FX_BOOL bReverse = FALSE;
- FX_BOOL bAnnotations = FALSE;
-
- int nlength = params.size();
- if(nlength ==9)
- {
- if (params[8].GetType() == VT_fxobject)
- {
- JSFXObject pObj = params[8].ToV8Object();
- {
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"))
- {
- if (CJS_Object* pJSObj = params[8].ToCJSObject())
- {
- if (PrintParamsObj* pprintparamsObj = (PrintParamsObj*)pJSObj->GetEmbedObject())
- {
- bUI = pprintparamsObj->bUI;
- nStart = pprintparamsObj->nStart;
- nEnd = pprintparamsObj->nEnd;
- bSilent = pprintparamsObj->bSilent;
- bShrinkToFit = pprintparamsObj->bShrinkToFit;
- bPrintAsImage = pprintparamsObj->bPrintAsImage;
- bReverse = pprintparamsObj->bReverse;
- bAnnotations = pprintparamsObj->bAnnotations;
- }
- }
- }
- }
- }
- }
- else
- {
- if(nlength >= 1)
- bUI = params[0].ToBool();
- if(nlength >= 2)
- nStart = params[1].ToInt();
- if(nlength >= 3)
- nEnd = params[2].ToInt();
- if(nlength >= 4)
- bSilent = params[3].ToBool();
- if(nlength >= 5)
- bShrinkToFit = params[4].ToBool();
- if(nlength >= 6)
- bPrintAsImage = params[5].ToBool();
- if(nlength >= 7)
- bReverse = params[6].ToBool();
- if(nlength >= 8)
- bAnnotations = params[7].ToBool();
- }
-
- ASSERT(m_pDocument != NULL);
-
- if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv())
- {
- pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
- return TRUE;
- }
- return FALSE;
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ FX_BOOL bUI = TRUE;
+ int nStart = 0;
+ int nEnd = 0;
+ FX_BOOL bSilent = FALSE;
+ FX_BOOL bShrinkToFit = FALSE;
+ FX_BOOL bPrintAsImage = FALSE;
+ FX_BOOL bReverse = FALSE;
+ FX_BOOL bAnnotations = FALSE;
+
+ int nlength = params.size();
+ if(nlength ==9)
+ {
+ if (params[8].GetType() == VT_fxobject)
+ {
+ JSFXObject pObj = params[8].ToV8Object();
+ {
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"))
+ {
+ if (CJS_Object* pJSObj = params[8].ToCJSObject())
+ {
+ if (PrintParamsObj* pprintparamsObj = (PrintParamsObj*)pJSObj->GetEmbedObject())
+ {
+ bUI = pprintparamsObj->bUI;
+ nStart = pprintparamsObj->nStart;
+ nEnd = pprintparamsObj->nEnd;
+ bSilent = pprintparamsObj->bSilent;
+ bShrinkToFit = pprintparamsObj->bShrinkToFit;
+ bPrintAsImage = pprintparamsObj->bPrintAsImage;
+ bReverse = pprintparamsObj->bReverse;
+ bAnnotations = pprintparamsObj->bAnnotations;
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ if(nlength >= 1)
+ bUI = params[0].ToBool();
+ if(nlength >= 2)
+ nStart = params[1].ToInt();
+ if(nlength >= 3)
+ nEnd = params[2].ToInt();
+ if(nlength >= 4)
+ bSilent = params[3].ToBool();
+ if(nlength >= 5)
+ bShrinkToFit = params[4].ToBool();
+ if(nlength >= 6)
+ bPrintAsImage = params[5].ToBool();
+ if(nlength >= 7)
+ bReverse = params[6].ToBool();
+ if(nlength >= 8)
+ bAnnotations = params[7].ToBool();
+ }
+
+ ASSERT(m_pDocument != NULL);
+
+ if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv())
+ {
+ pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
+ return TRUE;
+ }
+ return FALSE;
}
//removes the specified field from the document.
@@ -511,54 +511,54 @@ FX_BOOL Document::print(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Val
FX_BOOL Document::removeField(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE;
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE;
- CJS_Context* pContext = (CJS_Context*)cc;
- if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
+ CJS_Context* pContext = (CJS_Context*)cc;
+ if (params.size() != 1) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
- CFX_WideString sFieldName = params[0].ToCFXWideString();
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CFX_WideString sFieldName = params[0].ToCFXWideString();
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
- CFX_PtrArray widgets;
- pInterForm->GetWidgets(sFieldName, widgets);
+ CFX_PtrArray widgets;
+ pInterForm->GetWidgets(sFieldName, widgets);
- int nSize = widgets.GetSize();
+ int nSize = widgets.GetSize();
- if (nSize > 0)
- {
- for (int i=0; i<nSize; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i];
- ASSERT(pWidget != NULL);
+ if (nSize > 0)
+ {
+ for (int i=0; i<nSize; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i];
+ ASSERT(pWidget != NULL);
- CPDF_Rect rcAnnot = pWidget->GetRect();
- rcAnnot.left -= 1;
- rcAnnot.bottom -= 1;
- rcAnnot.right += 1;
- rcAnnot.top += 1;
+ CPDF_Rect rcAnnot = pWidget->GetRect();
+ rcAnnot.left -= 1;
+ rcAnnot.bottom -= 1;
+ rcAnnot.right += 1;
+ rcAnnot.top += 1;
- CFX_RectArray aRefresh;
- aRefresh.Add(rcAnnot);
+ CFX_RectArray aRefresh;
+ aRefresh.Add(rcAnnot);
- CPDF_Page* pPage = pWidget->GetPDFPage();
- ASSERT(pPage != NULL);
+ CPDF_Page* pPage = pWidget->GetPDFPage();
+ ASSERT(pPage != NULL);
- CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
- pPageView->DeleteAnnot(pWidget);
+ CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
+ pPageView->DeleteAnnot(pWidget);
- pPageView->UpdateRects(aRefresh);
- }
- m_pDocument->SetChangeMark();
- }
+ pPageView->UpdateRects(aRefresh);
+ }
+ m_pDocument->SetChangeMark();
+ }
- return TRUE;
+ return TRUE;
}
//reset filed values within a document.
@@ -567,62 +567,62 @@ FX_BOOL Document::removeField(IFXJS_Context* cc, const CJS_Parameters& params, C
FX_BOOL Document::resetForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
- v8::Isolate* isolate = GetIsolate(cc);
- CJS_Array aName(isolate);
+ v8::Isolate* isolate = GetIsolate(cc);
+ CJS_Array aName(isolate);
- if (params.size() > 0)
- {
- switch (params[0].GetType())
- {
- default:
- aName.Attach(params[0].ToV8Array());
- break;
- case VT_string:
- aName.SetElement(0,params[0]);
- break;
- }
+ if (params.size() > 0)
+ {
+ switch (params[0].GetType())
+ {
+ default:
+ aName.Attach(params[0].ToV8Array());
+ break;
+ case VT_string:
+ aName.SetElement(0,params[0]);
+ break;
+ }
- CFX_PtrArray aFields;
+ CFX_PtrArray aFields;
- for (int i=0,isz=aName.GetLength(); i<isz; i++)
- {
- CJS_Value valElement(isolate);
- aName.GetElement(i,valElement);
- CFX_WideString swVal = valElement.ToCFXWideString();
+ for (int i=0,isz=aName.GetLength(); i<isz; i++)
+ {
+ CJS_Value valElement(isolate);
+ aName.GetElement(i,valElement);
+ CFX_WideString swVal = valElement.ToCFXWideString();
- for (int j=0,jsz=pPDFForm->CountFields(swVal); j<jsz; j++)
- {
- aFields.Add((void*)pPDFForm->GetField(j,swVal));
- }
- }
+ for (int j=0,jsz=pPDFForm->CountFields(swVal); j<jsz; j++)
+ {
+ aFields.Add((void*)pPDFForm->GetField(j,swVal));
+ }
+ }
- if (aFields.GetSize() > 0)
- {
- pPDFForm->ResetForm(aFields, TRUE, TRUE);
- m_pDocument->SetChangeMark();
+ if (aFields.GetSize() > 0)
+ {
+ pPDFForm->ResetForm(aFields, TRUE, TRUE);
+ m_pDocument->SetChangeMark();
- }
- }
- else
- {
- pPDFForm->ResetForm(TRUE);
- m_pDocument->SetChangeMark();
+ }
+ }
+ else
+ {
+ pPDFForm->ResetForm(TRUE);
+ m_pDocument->SetChangeMark();
- }
+ }
- return TRUE;
+ return TRUE;
}
@@ -635,859 +635,907 @@ FX_BOOL Document::saveAs(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
- CJS_Context* pContext = (CJS_Context*)cc;
- int nSize = params.size();
- if (nSize < 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CFX_WideString strURL;
- FX_BOOL bFDF = TRUE;
- FX_BOOL bEmpty = FALSE;
- v8::Isolate* isolate = GetIsolate(cc);
- CJS_Array aFields(isolate);
-
- CJS_Value v = params[0];
- if (v.GetType() == VT_string)
- {
- strURL = params[0].ToCFXWideString();
- if (nSize > 1)
- bFDF = params[1].ToBool();
- if (nSize > 2)
- bEmpty = params[2].ToBool();
- if (nSize > 3)
- aFields.Attach(params[3].ToV8Array());
- }
- else if (v.GetType() == VT_object)
- {
- JSObject pObj = params[0].ToV8Object();
- v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cURL");
- if (!pValue.IsEmpty())
- strURL = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
- pValue = JS_GetObjectElement(isolate, pObj, L"bFDF");
- bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
- pValue = JS_GetObjectElement(isolate, pObj, L"bEmpty");
- bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
- pValue = JS_GetObjectElement(isolate, pObj,L"aFields");
- aFields.Attach(CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToV8Array());
- }
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
- FX_BOOL bAll = (aFields.GetLength() == 0);
- if (bAll && bEmpty)
- {
- if (pPDFInterForm->CheckRequiredFields())
- {
- pRuntime->BeginBlock();
- pInterForm->SubmitForm(strURL, FALSE);
- pRuntime->EndBlock();
- }
- return TRUE;
- }
-
- CFX_PtrArray fieldObjects;
- for (int i=0,sz=aFields.GetLength(); i<sz; i++)
- {
- CJS_Value valName(isolate);
- aFields.GetElement(i, valName);
-
- CFX_WideString sName = valName.ToCFXWideString();
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j)
- {
- CPDF_FormField* pField = pPDFForm->GetField(j, sName);
- if (!bEmpty && pField->GetValue().IsEmpty())
- continue;
-
- fieldObjects.Add(pField);
- }
- }
-
- if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE))
- {
- pRuntime->BeginBlock();
- pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);
- pRuntime->EndBlock();
- }
- return TRUE;
+ ASSERT(m_pDocument != NULL);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ int nSize = params.size();
+ if (nSize < 1) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CFX_WideString strURL;
+ FX_BOOL bFDF = TRUE;
+ FX_BOOL bEmpty = FALSE;
+ v8::Isolate* isolate = GetIsolate(cc);
+ CJS_Array aFields(isolate);
+
+ CJS_Value v = params[0];
+ if (v.GetType() == VT_string)
+ {
+ strURL = params[0].ToCFXWideString();
+ if (nSize > 1)
+ bFDF = params[1].ToBool();
+ if (nSize > 2)
+ bEmpty = params[2].ToBool();
+ if (nSize > 3)
+ aFields.Attach(params[3].ToV8Array());
+ }
+ else if (v.GetType() == VT_object)
+ {
+ JSObject pObj = params[0].ToV8Object();
+ v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cURL");
+ if (!pValue.IsEmpty())
+ strURL = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ pValue = JS_GetObjectElement(isolate, pObj, L"bFDF");
+ bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+ pValue = JS_GetObjectElement(isolate, pObj, L"bEmpty");
+ bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+ pValue = JS_GetObjectElement(isolate, pObj,L"aFields");
+ aFields.Attach(CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToV8Array());
+ }
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+ CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
+ ASSERT(pPDFInterForm != NULL);
+
+ FX_BOOL bAll = (aFields.GetLength() == 0);
+
+ if (bAll && bEmpty)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+
+ if (pPDFInterForm->CheckRequiredFields())
+ {
+ pRuntime->BeginBlock();
+ pInterForm->SubmitForm(strURL, FALSE);
+ pRuntime->EndBlock();
+ }
+
+ return TRUE;
+ }
+ else
+ {
+ CFX_PtrArray fieldObjects;
+
+ for (int i=0,sz=aFields.GetLength(); i<sz; i++)
+ {
+ CJS_Value valName(isolate);
+ aFields.GetElement(i, valName);
+ CFX_WideString sName = valName.ToCFXWideString();
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ for (int j=0, jsz=pPDFForm->CountFields(sName); j<jsz; j++)
+ {
+ CPDF_FormField* pField = pPDFForm->GetField(j, sName);
+ if (!bEmpty && pField->GetValue().IsEmpty())
+ continue;
+
+ fieldObjects.Add(pField);
+ }
+ }
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+
+ if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE))
+ {
+ pRuntime->BeginBlock();
+ pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);
+ pRuntime->EndBlock();
+ }
+
+ return TRUE;
+ }
+
}
//////////////////////////////////////////////////////////////////////////////////////////////
void Document::AttachDoc(CPDFSDK_Document *pDoc)
{
- m_pDocument = pDoc;
+ m_pDocument = pDoc;
}
CPDFSDK_Document * Document::GetReaderDoc()
{
- return m_pDocument;
+ return m_pDocument;
}
FX_BOOL Document::ExtractFileName(CPDFSDK_Document *pDoc,CFX_ByteString &strFileName)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Document::ExtractFolderName(CPDFSDK_Document *pDoc,CFX_ByteString &strFolderName)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Document::bookmarkRoot(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::mailDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- FX_BOOL bUI = TRUE;
- CFX_WideString cTo = L"";
- CFX_WideString cCc = L"";
- CFX_WideString cBcc = L"";
- CFX_WideString cSubject = L"";
- CFX_WideString cMsg = L"";
+ FX_BOOL bUI = TRUE;
+ CFX_WideString cTo = L"";
+ CFX_WideString cCc = L"";
+ CFX_WideString cBcc = L"";
+ CFX_WideString cSubject = L"";
+ CFX_WideString cMsg = L"";
- if (params.size() >= 1)
- bUI = params[0].ToBool();
- if (params.size() >= 2)
- cTo = params[1].ToCFXWideString();
- if (params.size() >= 3)
- cCc = params[2].ToCFXWideString();
- if (params.size() >= 4)
- cBcc = params[3].ToCFXWideString();
- if (params.size() >= 5)
- cSubject = params[4].ToCFXWideString();
- if (params.size() >= 6)
- cMsg = params[5].ToCFXWideString();
+ if (params.size() >= 1)
+ bUI = params[0].ToBool();
+ if (params.size() >= 2)
+ cTo = params[1].ToCFXWideString();
+ if (params.size() >= 3)
+ cCc = params[2].ToCFXWideString();
+ if (params.size() >= 4)
+ cBcc = params[3].ToCFXWideString();
+ if (params.size() >= 5)
+ cSubject = params[4].ToCFXWideString();
+ if (params.size() >= 6)
+ cMsg = params[5].ToCFXWideString();
- v8::Isolate* isolate = GetIsolate(cc);
+ v8::Isolate* isolate = GetIsolate(cc);
- if(params.size() >= 1 && params[0].GetType() == VT_object)
- {
- JSObject pObj = params[0].ToV8Object();
+ if(params.size() >= 1 && params[0].GetType() == VT_object)
+ {
+ JSObject pObj = params[0].ToV8Object();
- v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
- bUI = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToInt();
+ v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
+ bUI = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToInt();
- pValue = JS_GetObjectElement(isolate,pObj, L"cTo");
- cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ pValue = JS_GetObjectElement(isolate,pObj, L"cTo");
+ cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
- pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
- cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
+ cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
- pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
- cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
+ cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
- pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
- cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
+ cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
- pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
- cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
+ pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
+ cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
- }
+ }
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
- pRuntime->BeginBlock();
- CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
- pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
- pRuntime->EndBlock();
+ pRuntime->BeginBlock();
+ CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
+ pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
+ pRuntime->EndBlock();
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::author(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Author");
- return TRUE;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Author");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
- CFX_WideString csAuthor;
- vp >> csAuthor;
- pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));
- m_pDocument->SetChangeMark();
- return TRUE;
- }
+ CFX_WideString csAuthor;
+ vp >> csAuthor;
+ pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
}
FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)
- return FALSE;
-
- CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author");
- CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title");
- CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject");
- CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords");
- CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator");
- CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer");
- CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate");
- CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate");
- CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped");
-
- v8::Isolate* isolate = GetIsolate(cc);
- if (vp.IsGetting())
- {
- CJS_Context* pContext = (CJS_Context *)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
- JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
- JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
- JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
- JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
- JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
- JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
- JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate.c_str());
- JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
- JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
-
- // It's to be compatible to non-standard info dictionary.
- FX_POSITION pos = pDictionary->GetStartPos();
- while(pos)
- {
- CFX_ByteString bsKey;
- CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);
- CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength());
- if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )
- JS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str());
- if(pValueObj->GetType()==PDFOBJ_NUMBER)
- JS_PutObjectNumber(isolate,pObj, wsKey.c_str(), (float)pValueObj->GetNumber());
- if(pValueObj->GetType()==PDFOBJ_BOOLEAN)
- JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger());
- }
- vp << pObj;
- }
- return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author");
+ CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title");
+ CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject");
+ CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords");
+ CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator");
+ CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer");
+ CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate");
+ CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate");
+ CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped");
+
+ v8::Isolate* isolate = GetIsolate(cc);
+ if (vp.IsGetting())
+ {
+ CJS_Context* pContext = (CJS_Context *)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
+
+ JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
+ JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
+ JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
+ JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
+ JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
+ JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
+ JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate.c_str());
+ JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
+ JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
+
+// It's to be compatible to non-standard info dictionary.
+ FX_POSITION pos = pDictionary->GetStartPos();
+ while(pos)
+ {
+ CFX_ByteString bsKey;
+ CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);
+ CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength());
+ if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )
+ JS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str());
+ if(pValueObj->GetType()==PDFOBJ_NUMBER)
+ JS_PutObjectNumber(isolate,pObj, wsKey.c_str(), (float)pValueObj->GetNumber());
+ if(pValueObj->GetType()==PDFOBJ_BOOLEAN)
+ JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger());
+ }
+
+ vp << pObj;
+ return TRUE;
+ }
+ else
+ {
+ return TRUE;
+ }
}
FX_BOOL Document::creationDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)
- return FALSE;
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("CreationDate");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("CreationDate");
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
- return FALSE;
+ CFX_WideString csCreationDate;
+ vp >> csCreationDate;
+ pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));
+ m_pDocument->SetChangeMark();
- CFX_WideString csCreationDate;
- vp >> csCreationDate;
- pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));
- m_pDocument->SetChangeMark();
- }
- return TRUE;
+ return TRUE;
+ }
}
FX_BOOL Document::creator(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)
- return FALSE;
+ ASSERT(m_pDocument != NULL);
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Creator");
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
- return FALSE;
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
- CFX_WideString csCreator;
- vp >> csCreator;
- pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));
- m_pDocument->SetChangeMark();
- }
- return TRUE;
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Creator");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString csCreator;
+ vp >> csCreator;
+ pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
}
FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsGetting())
- {
- vp << m_bDelay;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
- return FALSE;
-
- bool b;
- vp >> b;
- m_bDelay = b;
- if (m_bDelay)
- {
- for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
- delete m_DelayData.GetAt(i);
-
- m_DelayData.RemoveAll();
- }
- else
- {
- CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess;
- for (int i=0,sz=m_DelayData.GetSize(); i < sz; i++)
- {
- if (CJS_DelayData* pData = m_DelayData.GetAt(i))
- {
- DelayDataToProcess.Add(pData);
- m_DelayData.SetAt(i, NULL);
- }
- }
- m_DelayData.RemoveAll();
- for (int i=0,sz=DelayDataToProcess.GetSize(); i < sz; i++)
- {
- CJS_DelayData* pData = DelayDataToProcess.GetAt(i);
- Field::DoDelay(m_pDocument, pData);
- DelayDataToProcess.SetAt(i,NULL);
- delete pData;
- }
- }
- }
- return TRUE;
+ if (vp.IsGetting())
+ {
+ vp << m_bDelay;
+ return TRUE;
+ }
+ else
+ {
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ bool b;
+ vp >> b;
+
+ m_bDelay = b;
+
+ if (m_bDelay)
+ {
+ for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
+ delete m_DelayData.GetAt(i);
+
+ m_DelayData.RemoveAll();
+ }
+ else
+ {
+ CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess;
+
+ for (int i=0,sz=m_DelayData.GetSize(); i < sz; i++)
+ {
+ if (CJS_DelayData* pData = m_DelayData.GetAt(i))
+ {
+ DelayDataToProcess.Add(pData);
+ m_DelayData.SetAt(i, NULL);
+ }
+ }
+ m_DelayData.RemoveAll();
+
+ for (int i=0,sz=DelayDataToProcess.GetSize(); i < sz; i++)
+ {
+ CJS_DelayData* pData = DelayDataToProcess.GetAt(i);
+ Field::DoDelay(m_pDocument, pData);
+ DelayDataToProcess.SetAt(i,NULL);
+ delete pData;
+ }
+ }
+
+ return TRUE;
+ }
}
FX_BOOL Document::keywords(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)
- return FALSE;
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Keywords");
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
- return FALSE;
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Keywords");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
- CFX_WideString csKeywords;
- vp >> csKeywords;
- pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords));
- m_pDocument->SetChangeMark();
- }
- return TRUE;
+ CFX_WideString csKeywords;
+ vp >> csKeywords;
+ pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
}
FX_BOOL Document::modDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)
- return FALSE;
+ ASSERT(m_pDocument != NULL);
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("ModDate");
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
- return FALSE;
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
- CFX_WideString csmodDate;
- vp >> csmodDate;
- pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));
- m_pDocument->SetChangeMark();
- }
- return TRUE;
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("ModDate");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString csmodDate;
+ vp >> csmodDate;
+ pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
}
FX_BOOL Document::producer(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)
- return FALSE;
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Producer");
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
- return FALSE;
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Producer");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
- CFX_WideString csproducer;
- vp >> csproducer;
- pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer));
- m_pDocument->SetChangeMark();
- }
- return TRUE;
+ CFX_WideString csproducer;
+ vp >> csproducer;
+ pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
}
FX_BOOL Document::subject(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)
- return FALSE;
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Subject");
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
- return FALSE;
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Subject");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
- CFX_WideString cssubject;
- vp >> cssubject;
- pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));
- m_pDocument->SetChangeMark();
- }
- return TRUE;
+ CFX_WideString cssubject;
+ vp >> cssubject;
+ pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
}
FX_BOOL Document::title(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
- return FALSE;
+ ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)
- return FALSE;
+ if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
+ return FALSE;
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Title");
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
- return FALSE;
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
- CFX_WideString cstitle;
- vp >> cstitle;
- pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));
- m_pDocument->SetChangeMark();
- }
- return TRUE;
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Title");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString cstitle;
+ vp >> cstitle;
+ pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
}
FX_BOOL Document::numPages(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
- return FALSE;
- }
- vp << m_pDocument->GetPageCount();
- return TRUE;
+ if (vp.IsSetting()) {
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ return FALSE;
+ }
+ vp << m_pDocument->GetPageCount();
+ return TRUE;
}
FX_BOOL Document::external(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- //In Chrome case,should always return true.
- if (vp.IsGetting()) {
- vp << TRUE;
- }
- return TRUE;
+ //In Chrome case,should always return true.
+ if (vp.IsGetting()) {
+ vp << TRUE;
+ }
+ return TRUE;
}
FX_BOOL Document::filesize(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
- return FALSE;
- }
- vp << 0;
- return TRUE;
+ if (vp.IsSetting()) {
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ return FALSE;
+ }
+ vp << 0;
+ return TRUE;
}
FX_BOOL Document::mouseX(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::mouseY(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::baseURL(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsGetting())
- {
- vp << m_cwBaseURL;
- }
- else
- {
- vp >> m_cwBaseURL;
- }
- return TRUE;
+ if (vp.IsGetting())
+ {
+ vp << m_cwBaseURL;
+ }
+ else
+ {
+ vp >> m_cwBaseURL;
+ }
+ return TRUE;
}
FX_BOOL Document::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
- if (vp.IsGetting())
- {
- if (pInterForm->IsCalculateEnabled())
- vp << true;
- else
- vp << false;
- }
- else
- {
- bool bCalculate;
- vp >> bCalculate;
+ if (vp.IsGetting())
+ {
+ if (pInterForm->IsCalculateEnabled())
+ vp << true;
+ else
+ vp << false;
+ }
+ else
+ {
+ bool bCalculate;
+ vp >> bCalculate;
- pInterForm->EnableCalculate(bCalculate);
- }
+ pInterForm->EnableCalculate(bCalculate);
+ }
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::documentFileName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
- return FALSE;
- }
- CFX_WideString wsFilePath = m_pDocument->GetPath();
- int32_t i = wsFilePath.GetLength() - 1;
- for ( ; i >= 0; i-- )
- {
- if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' )
- break;
- }
- if ( i >= 0 && i < wsFilePath.GetLength() - 1 )
- {
- vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 );
- }else{
- vp << L"";
- }
- return TRUE;
+ if (vp.IsSetting()) {
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ return FALSE;
+ }
+ CFX_WideString wsFilePath = m_pDocument->GetPath();
+ int32_t i = wsFilePath.GetLength() - 1;
+ for ( ; i >= 0; i-- )
+ {
+ if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' )
+ break;
+ }
+ if ( i >= 0 && i < wsFilePath.GetLength() - 1 )
+ {
+ vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 );
+ }else{
+ vp << L"";
+ }
+ return TRUE;
}
CFX_WideString Document::ReversalStr(CFX_WideString cbFrom)
{
- size_t iLength = cbFrom.GetLength();
+ size_t iLength = cbFrom.GetLength();
pdfium::base::CheckedNumeric<size_t> iSize = sizeof(wchar_t);
- iSize *= (iLength + 1);
- wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie());
- wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength);
+ iSize *= (iLength + 1);
+ wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie());
+ wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength);
- for (size_t i = 0; i < iLength; i++)
- {
- pResult[i] = *(pFrom + iLength - i - 1);
- }
- pResult[iLength] = L'\0';
+ for (size_t i = 0; i < iLength; i++)
+ {
+ pResult[i] = *(pFrom + iLength - i - 1);
+ }
+ pResult[iLength] = L'\0';
- cbFrom.ReleaseBuffer();
- CFX_WideString cbRet = CFX_WideString(pResult);
- free(pResult);
- pResult = NULL;
- return cbRet;
+ cbFrom.ReleaseBuffer();
+ CFX_WideString cbRet = CFX_WideString(pResult);
+ free(pResult);
+ pResult = NULL;
+ return cbRet;
}
CFX_WideString Document::CutString(CFX_WideString cbFrom)
{
- size_t iLength = cbFrom.GetLength();
- pdfium::base::CheckedNumeric<size_t> iSize = sizeof(wchar_t);
- iSize *= (iLength + 1);
- wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie());
- wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength);
-
- for (int i = 0; i < iLength; i++)
- {
- if (pFrom[i] == L'\\' || pFrom[i] == L'/')
- {
- pResult[i] = L'\0';
- break;
- }
- pResult[i] = pFrom[i];
- }
- pResult[iLength] = L'\0';
-
- cbFrom.ReleaseBuffer();
- CFX_WideString cbRet = CFX_WideString(pResult);
- free(pResult);
- pResult = NULL;
- return cbRet;
+ size_t iLength = cbFrom.GetLength();
+ pdfium::base::CheckedNumeric<size_t> iSize = sizeof(wchar_t);
+ iSize *= (iLength + 1);
+ wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie());
+ wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength);
+
+ for (int i = 0; i < iLength; i++)
+ {
+ if (pFrom[i] == L'\\' || pFrom[i] == L'/')
+ {
+ pResult[i] = L'\0';
+ break;
+ }
+ pResult[i] = pFrom[i];
+ }
+ pResult[iLength] = L'\0';
+
+ cbFrom.ReleaseBuffer();
+ CFX_WideString cbRet = CFX_WideString(pResult);
+ free(pResult);
+ pResult = NULL;
+ return cbRet;
}
FX_BOOL Document::path(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
- return FALSE;
- }
- vp << app::SysPathToPDFPath(m_pDocument->GetPath());
- return TRUE;
+ if (vp.IsSetting()) {
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ return FALSE;
+ }
+ vp << app::SysPathToPDFPath(m_pDocument->GetPath());
+ return TRUE;
}
FX_BOOL Document::pageWindowRect(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::layout(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::addLink(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::closeDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
- return TRUE;
+ ASSERT(m_pDocument != NULL);
+ return TRUE;
}
FX_BOOL Document::getPageBox(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::getAnnot(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::getAnnots(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- vRet.SetNull();
- return TRUE;
+ vRet.SetNull();
+ return TRUE;
}
FX_BOOL Document::getAnnot3D(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- vRet.SetNull();
- return TRUE;
+ vRet.SetNull();
+ return TRUE;
}
FX_BOOL Document::getAnnots3D(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- vRet = VT_undefined;
- return TRUE;
+ vRet = VT_undefined;
+ return TRUE;
}
FX_BOOL Document::getOCGs(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::getLinks(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect)
{
- return (rect.left <= LinkRect.left &&
- rect.top <= LinkRect.top &&
- rect.right >= LinkRect.right &&
- rect.bottom >= LinkRect.bottom);
+ if (rect.left <= LinkRect.left
+ && rect.top <= LinkRect.top
+ && rect.right >= LinkRect.right
+ && rect.bottom >= LinkRect.bottom)
+ return true;
+ else
+ return false;
}
void IconTree::InsertIconElement(IconElement* pNewIcon)
{
- if (!pNewIcon)return;
+ if (!pNewIcon)return;
- if (m_pHead == NULL && m_pEnd == NULL)
- {
- m_pHead = m_pEnd = pNewIcon;
- m_iLength++;
- }
- else
- {
- m_pEnd->NextIcon = pNewIcon;
- m_pEnd = pNewIcon;
- m_iLength++;
- }
+ if (m_pHead == NULL && m_pEnd == NULL)
+ {
+ m_pHead = m_pEnd = pNewIcon;
+ m_iLength++;
+ }
+ else
+ {
+ m_pEnd->NextIcon = pNewIcon;
+ m_pEnd = pNewIcon;
+ m_iLength++;
+ }
}
void IconTree::DeleteIconTree()
{
- if (!m_pHead || !m_pEnd)return;
+ if (!m_pHead || !m_pEnd)return;
- IconElement* pTemp = NULL;
- while(m_pEnd != m_pHead)
- {
- pTemp = m_pHead;
- m_pHead = m_pHead->NextIcon;
- delete pTemp;
- }
+ IconElement* pTemp = NULL;
+ while(m_pEnd != m_pHead)
+ {
+ pTemp = m_pHead;
+ m_pHead = m_pHead->NextIcon;
+ delete pTemp;
+ }
- delete m_pEnd;
- m_pHead = NULL;
- m_pEnd = NULL;
+ delete m_pEnd;
+ m_pHead = NULL;
+ m_pEnd = NULL;
}
int IconTree::GetLength()
{
- return m_iLength;
+ return m_iLength;
}
IconElement* IconTree::operator [](int iIndex)
{
- if (iIndex >= 0 && iIndex <= m_iLength)
- {
- IconElement* pTemp = m_pHead;
- for (int i = 0; i < iIndex; i++)
- {
- pTemp = pTemp->NextIcon;
- }
- return pTemp;
- }
- return NULL;
+ if (iIndex >= 0 && iIndex <= m_iLength)
+ {
+ IconElement* pTemp = m_pHead;
+ for (int i = 0; i < iIndex; i++)
+ {
+ pTemp = pTemp->NextIcon;
+ }
+ return pTemp;
+ }
+ else
+ return NULL;
}
FX_BOOL Document::addIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context*)cc;
- if (params.size() != 2) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
+ CJS_Context* pContext = (CJS_Context*)cc;
+ if (params.size() != 2) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
- CFX_WideString swIconName = params[0].ToCFXWideString();
- JSFXObject pJSIcon = params[1].ToV8Object();
+ CFX_WideString swIconName = params[0].ToCFXWideString();
+ JSFXObject pJSIcon = params[1].ToV8Object();
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
- return FALSE;
- }
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
+ return FALSE;
+ }
- CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject();
- if (!pEmbedObj) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
- return FALSE;
- }
+ CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject();
+ if (!pEmbedObj) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
+ return FALSE;
+ }
- Icon* pIcon = (Icon*)pEmbedObj;
- if (!m_pIconTree)
- m_pIconTree = new IconTree();
+ Icon* pIcon = (Icon*)pEmbedObj;
+ if (!m_pIconTree)
+ m_pIconTree = new IconTree();
- IconElement* pNewIcon = new IconElement();
- pNewIcon->IconName = swIconName;
- pNewIcon->NextIcon = NULL;
- pNewIcon->IconStream = pIcon;
- m_pIconTree->InsertIconElement(pNewIcon);
- return TRUE;
+ IconElement* pNewIcon = new IconElement();
+ pNewIcon->IconName = swIconName;
+ pNewIcon->NextIcon = NULL;
+ pNewIcon->IconStream = pIcon;
+ m_pIconTree->InsertIconElement(pNewIcon);
+ return TRUE;
}
FX_BOOL Document::icons(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
- return FALSE;
- }
+ if (vp.IsSetting()) {
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ return FALSE;
+ }
- if (!m_pIconTree)
- {
- vp.SetNull();
- return TRUE;
- }
+ if (!m_pIconTree)
+ {
+ vp.SetNull();
+ return TRUE;
+ }
- CJS_Array Icons(m_isolate);
- IconElement* pIconElement = NULL;
- int iIconTreeLength = m_pIconTree->GetLength();
+ CJS_Array Icons(m_isolate);
+ IconElement* pIconElement = NULL;
+ int iIconTreeLength = m_pIconTree->GetLength();
- CJS_Context* pContext = (CJS_Context *)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ CJS_Context* pContext = (CJS_Context *)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- for (int i = 0; i < iIconTreeLength; i++)
- {
- pIconElement = (*m_pIconTree)[i];
+ for (int i = 0; i < iIconTreeLength; i++)
+ {
+ pIconElement = (*m_pIconTree)[i];
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
- if (pObj.IsEmpty()) return FALSE;
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
+ if (pObj.IsEmpty()) return FALSE;
- CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
- if (!pJS_Icon) return FALSE;
+ CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
+ if (!pJS_Icon) return FALSE;
- Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
- if (!pIcon)return FALSE;
+ Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+ if (!pIcon)return FALSE;
- pIcon->SetStream(pIconElement->IconStream->GetStream());
- pIcon->SetIconName(pIconElement->IconName);
- Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon));
- }
+ pIcon->SetStream(pIconElement->IconStream->GetStream());
+ pIcon->SetIconName(pIconElement->IconName);
+ Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon));
+ }
- vp << Icons;
- return TRUE;
+ vp << Icons;
+ return TRUE;
}
FX_BOOL Document::getIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
+ CJS_Context* pContext = (CJS_Context *)cc;
+ if (params.size() != 1) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
- if(!m_pIconTree)
- return FALSE;
- CFX_WideString swIconName = params[0].ToCFXWideString();
- int iIconCounts = m_pIconTree->GetLength();
+ if(!m_pIconTree)
+ return FALSE;
+ CFX_WideString swIconName = params[0].ToCFXWideString();
+ int iIconCounts = m_pIconTree->GetLength();
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- for (int i = 0; i < iIconCounts; i++)
- {
- if ((*m_pIconTree)[i]->IconName == swIconName)
- {
- Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
+ for (int i = 0; i < iIconCounts; i++)
+ {
+ if ((*m_pIconTree)[i]->IconName == swIconName)
+ {
+ Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
- if (pObj.IsEmpty()) return FALSE;
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
+ if (pObj.IsEmpty()) return FALSE;
- CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
- if (!pJS_Icon) return FALSE;
+ CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
+ if (!pJS_Icon) return FALSE;
- Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
- if (!pIcon)return FALSE;
+ Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+ if (!pIcon)return FALSE;
- pIcon->SetIconName(swIconName);
- pIcon->SetStream(pRetIcon->GetStream());
- vRet = pJS_Icon;
- return TRUE;
- }
- }
+ pIcon->SetIconName(swIconName);
+ pIcon->SetStream(pRetIcon->GetStream());
+ vRet = pJS_Icon;
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
FX_BOOL Document::removeIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
@@ -1504,255 +1552,255 @@ FX_BOOL Document::createDataObject(IFXJS_Context* cc, const CJS_Parameters& para
FX_BOOL Document::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::calculateNow(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
- pInterForm->OnCalculate();
- return TRUE;
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+ pInterForm->OnCalculate();
+ return TRUE;
}
FX_BOOL Document::Collab(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::getPageNthWord(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
- int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
- int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0;
- bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true;
+ int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
+ int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0;
+ bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true;
- CPDF_Document* pDocument = m_pDocument->GetDocument();
- if (!pDocument) return FALSE;
+ CPDF_Document* pDocument = m_pDocument->GetDocument();
+ if (!pDocument) return FALSE;
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
- return FALSE;
- }
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+ return FALSE;
+ }
- CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
- if (!pPageDict) return FALSE;
+ CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
+ if (!pPageDict) return FALSE;
- CPDF_Page page;
- page.Load(pDocument, pPageDict);
- page.StartParse();
- page.ParseContent();
+ CPDF_Page page;
+ page.Load(pDocument, pPageDict);
+ page.StartParse();
+ page.ParseContent();
- FX_POSITION pos = page.GetFirstObjectPosition();
+ FX_POSITION pos = page.GetFirstObjectPosition();
- int nWords = 0;
+ int nWords = 0;
- CFX_WideString swRet;
+ CFX_WideString swRet;
- while (pos)
- {
- if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
- {
- if (pPageObj->m_Type == PDFPAGE_TEXT)
- {
- int nObjWords = CountWords((CPDF_TextObject*)pPageObj);
+ while (pos)
+ {
+ if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
+ {
+ if (pPageObj->m_Type == PDFPAGE_TEXT)
+ {
+ int nObjWords = CountWords((CPDF_TextObject*)pPageObj);
- if (nWords + nObjWords >= nWordNo)
- {
- swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords);
- break;
- }
+ if (nWords + nObjWords >= nWordNo)
+ {
+ swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords);
+ break;
+ }
- nWords += nObjWords;
- }
- }
- }
+ nWords += nObjWords;
+ }
+ }
+ }
- if (bStrip)
- {
- swRet.TrimLeft();
- swRet.TrimRight();
- }
+ if (bStrip)
+ {
+ swRet.TrimLeft();
+ swRet.TrimRight();
+ }
- vRet = swRet.c_str();
- return TRUE;
+ vRet = swRet.c_str();
+ return TRUE;
}
FX_BOOL Document::getPageNthWordQuads(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
- return FALSE;
+ return FALSE;
}
FX_BOOL Document::getPageNumWords(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
- int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
+ int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
- CPDF_Document* pDocument = m_pDocument->GetDocument();
- ASSERT(pDocument != NULL);
+ CPDF_Document* pDocument = m_pDocument->GetDocument();
+ ASSERT(pDocument != NULL);
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
- return FALSE;
- }
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+ return FALSE;
+ }
- CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
- if (!pPageDict) return FALSE;
+ CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
+ if (!pPageDict) return FALSE;
- CPDF_Page page;
- page.Load(pDocument, pPageDict);
- page.StartParse();
- page.ParseContent();
+ CPDF_Page page;
+ page.Load(pDocument, pPageDict);
+ page.StartParse();
+ page.ParseContent();
- FX_POSITION pos = page.GetFirstObjectPosition();
+ FX_POSITION pos = page.GetFirstObjectPosition();
- int nWords = 0;
+ int nWords = 0;
- while (pos)
- {
- if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
- {
- if (pPageObj->m_Type == PDFPAGE_TEXT)
- {
- CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj;
- nWords += CountWords(pTextObj);
- }
- }
- }
+ while (pos)
+ {
+ if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
+ {
+ if (pPageObj->m_Type == PDFPAGE_TEXT)
+ {
+ CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj;
+ nWords += CountWords(pTextObj);
+ }
+ }
+ }
- vRet = nWords;
+ vRet = nWords;
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::getPrintParams(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"));
+ CJS_Context* pContext = (CJS_Context*)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"));
- // Not implemented yet.
+ // Not implemented yet.
- vRet = pRetObj;
- return TRUE;
+ vRet = pRetObj;
+ return TRUE;
}
-#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
+#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
-int Document::CountWords(CPDF_TextObject* pTextObj)
+int Document::CountWords(CPDF_TextObject* pTextObj)
{
- if (!pTextObj) return 0;
+ if (!pTextObj) return 0;
- int nWords = 0;
+ int nWords = 0;
- CPDF_Font* pFont = pTextObj->GetFont();
- if (!pFont) return 0;
+ CPDF_Font* pFont = pTextObj->GetFont();
+ if (!pFont) return 0;
- FX_BOOL bIsLatin = FALSE;
+ FX_BOOL bIsLatin = FALSE;
- for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
- {
- FX_DWORD charcode = -1;
- FX_FLOAT kerning;
+ for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
+ {
+ FX_DWORD charcode = -1;
+ FX_FLOAT kerning;
- pTextObj->GetCharInfo(i, charcode, kerning);
- CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
+ pTextObj->GetCharInfo(i, charcode, kerning);
+ CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
- FX_WORD unicode = 0;
- if (swUnicode.GetLength() > 0)
- unicode = swUnicode[0];
+ FX_WORD unicode = 0;
+ if (swUnicode.GetLength() > 0)
+ unicode = swUnicode[0];
- if (ISLATINWORD(unicode) && bIsLatin)
- continue;
+ if (ISLATINWORD(unicode) && bIsLatin)
+ continue;
- bIsLatin = ISLATINWORD(unicode);
- if (unicode != 0x20)
- nWords++;
- }
+ bIsLatin = ISLATINWORD(unicode);
+ if (unicode != 0x20)
+ nWords++;
+ }
- return nWords;
+ return nWords;
}
CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex)
{
- ASSERT(pTextObj != NULL);
+ ASSERT(pTextObj != NULL);
- CFX_WideString swRet;
+ CFX_WideString swRet;
- CPDF_Font* pFont = pTextObj->GetFont();
- if (!pFont) return L"";
+ CPDF_Font* pFont = pTextObj->GetFont();
+ if (!pFont) return L"";
- int nWords = 0;
- FX_BOOL bIsLatin = FALSE;
+ int nWords = 0;
+ FX_BOOL bIsLatin = FALSE;
- for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
- {
- FX_DWORD charcode = -1;
- FX_FLOAT kerning;
+ for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
+ {
+ FX_DWORD charcode = -1;
+ FX_FLOAT kerning;
- pTextObj->GetCharInfo(i, charcode, kerning);
- CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
+ pTextObj->GetCharInfo(i, charcode, kerning);
+ CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
- FX_WORD unicode = 0;
- if (swUnicode.GetLength() > 0)
- unicode = swUnicode[0];
+ FX_WORD unicode = 0;
+ if (swUnicode.GetLength() > 0)
+ unicode = swUnicode[0];
- if (ISLATINWORD(unicode) && bIsLatin)
- {
- }
- else
- {
- bIsLatin = ISLATINWORD(unicode);
- if (unicode != 0x20)
- nWords++;
- }
+ if (ISLATINWORD(unicode) && bIsLatin)
+ {
+ }
+ else
+ {
+ bIsLatin = ISLATINWORD(unicode);
+ if (unicode != 0x20)
+ nWords++;
+ }
- if (nWords-1 == nWordIndex)
- swRet += unicode;
- }
+ if (nWords-1 == nWordIndex)
+ swRet += unicode;
+ }
- return swRet;
+ return swRet;
}
FX_BOOL Document::zoom(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
/**
-(none, NoVary)
-(fitP, FitPage)
-(fitW, FitWidth)
-(fitH, FitHeight)
-(fitV, FitVisibleWidth)
-(pref, Preferred)
-(refW, ReflowWidth)
+(none, NoVary)
+(fitP, FitPage)
+(fitW, FitWidth)
+(fitH, FitHeight)
+(fitV, FitVisibleWidth)
+(pref, Preferred)
+(refW, ReflowWidth)
*/
FX_BOOL Document::zoomType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Document::deletePages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
@@ -1787,57 +1835,58 @@ FX_BOOL Document::getURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
void Document::AddDelayData(CJS_DelayData* pData)
{
- m_DelayData.Add(pData);
+ m_DelayData.Add(pData);
}
void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex)
{
- CFX_DWordArray DelArray;
- CFX_ArrayTemplate<CJS_DelayData*> DelayDataForFieldAndControlIndex;
-
- for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
- {
- if (CJS_DelayData* pData = m_DelayData.GetAt(i))
- {
- if (pData->sFieldName == sFieldName && pData->nControlIndex == nControlIndex)
- {
- DelayDataForFieldAndControlIndex.Add(pData);
- m_DelayData.SetAt(i, NULL);
- DelArray.Add(i);
- }
- }
- }
-
- for (int j=DelArray.GetSize()-1; j>=0; j--)
- {
- m_DelayData.RemoveAt(DelArray[j]);
- }
-
- for (int i=0,sz=DelayDataForFieldAndControlIndex.GetSize(); i < sz; i++)
- {
- CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i);
- Field::DoDelay(m_pDocument, pData);
- DelayDataForFieldAndControlIndex.SetAt(i,NULL);
- delete pData;
- }
+ CFX_DWordArray DelArray;
+ CFX_ArrayTemplate<CJS_DelayData*> DelayDataForFieldAndControlIndex;
+
+ for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
+ {
+ if (CJS_DelayData* pData = m_DelayData.GetAt(i))
+ {
+ if (pData->sFieldName == sFieldName && pData->nControlIndex == nControlIndex)
+ {
+ DelayDataForFieldAndControlIndex.Add(pData);
+ m_DelayData.SetAt(i, NULL);
+ DelArray.Add(i);
+ }
+ }
+ }
+
+ for (int j=DelArray.GetSize()-1; j>=0; j--)
+ {
+ m_DelayData.RemoveAt(DelArray[j]);
+ }
+
+ for (int i=0,sz=DelayDataForFieldAndControlIndex.GetSize(); i < sz; i++)
+ {
+ CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i);
+ Field::DoDelay(m_pDocument, pData);
+ DelayDataForFieldAndControlIndex.SetAt(i,NULL);
+ delete pData;
+ }
}
void Document::AddDelayAnnotData(CJS_AnnotObj *pData)
{
- m_DelayAnnotData.Add(pData);
+ m_DelayAnnotData.Add(pData);
}
void Document::DoAnnotDelay()
{
- CFX_DWordArray DelArray;
+ CFX_DWordArray DelArray;
- for (int j=DelArray.GetSize()-1; j>=0; j--)
- {
- m_DelayData.RemoveAt(DelArray[j]);
- }
+ for (int j=DelArray.GetSize()-1; j>=0; j--)
+ {
+ m_DelayData.RemoveAt(DelArray[j]);
+ }
}
CJS_Document* Document::GetCJSDoc() const
{
- return static_cast<CJS_Document*>(m_pJSObject);
+ return static_cast<CJS_Document*>(m_pJSObject);
}
+
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index 614843426e..8393d9d5ff 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -25,111 +25,111 @@ 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)
+ 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)
- JS_STATIC_METHOD_ENTRY(buttonGetCaption)
- JS_STATIC_METHOD_ENTRY(buttonGetIcon)
- JS_STATIC_METHOD_ENTRY(buttonImportIcon)
- JS_STATIC_METHOD_ENTRY(buttonSetCaption)
- JS_STATIC_METHOD_ENTRY(buttonSetIcon)
- JS_STATIC_METHOD_ENTRY(checkThisBox)
- JS_STATIC_METHOD_ENTRY(clearItems)
- JS_STATIC_METHOD_ENTRY(defaultIsChecked)
- JS_STATIC_METHOD_ENTRY(deleteItemAt)
- JS_STATIC_METHOD_ENTRY(getArray )
- JS_STATIC_METHOD_ENTRY(getItemAt)
- JS_STATIC_METHOD_ENTRY(getLock)
- JS_STATIC_METHOD_ENTRY(insertItemAt)
- JS_STATIC_METHOD_ENTRY(isBoxChecked)
- JS_STATIC_METHOD_ENTRY(isDefaultChecked)
- JS_STATIC_METHOD_ENTRY(setAction)
- JS_STATIC_METHOD_ENTRY(setFocus)
- JS_STATIC_METHOD_ENTRY(setItems)
- JS_STATIC_METHOD_ENTRY(setLock)
- JS_STATIC_METHOD_ENTRY(signatureGetModifications)
- JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
- JS_STATIC_METHOD_ENTRY(signatureInfo)
- JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
- JS_STATIC_METHOD_ENTRY(signatureSign)
- JS_STATIC_METHOD_ENTRY(signatureValidate)
+ JS_STATIC_METHOD_ENTRY(browseForFileToSubmit)
+ JS_STATIC_METHOD_ENTRY(buttonGetCaption)
+ JS_STATIC_METHOD_ENTRY(buttonGetIcon)
+ JS_STATIC_METHOD_ENTRY(buttonImportIcon)
+ JS_STATIC_METHOD_ENTRY(buttonSetCaption)
+ JS_STATIC_METHOD_ENTRY(buttonSetIcon)
+ JS_STATIC_METHOD_ENTRY(checkThisBox)
+ JS_STATIC_METHOD_ENTRY(clearItems)
+ JS_STATIC_METHOD_ENTRY(defaultIsChecked)
+ JS_STATIC_METHOD_ENTRY(deleteItemAt)
+ JS_STATIC_METHOD_ENTRY(getArray )
+ JS_STATIC_METHOD_ENTRY(getItemAt)
+ JS_STATIC_METHOD_ENTRY(getLock)
+ JS_STATIC_METHOD_ENTRY(insertItemAt)
+ JS_STATIC_METHOD_ENTRY(isBoxChecked)
+ JS_STATIC_METHOD_ENTRY(isDefaultChecked)
+ JS_STATIC_METHOD_ENTRY(setAction)
+ JS_STATIC_METHOD_ENTRY(setFocus)
+ JS_STATIC_METHOD_ENTRY(setItems)
+ JS_STATIC_METHOD_ENTRY(setLock)
+ JS_STATIC_METHOD_ENTRY(signatureGetModifications)
+ JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
+ JS_STATIC_METHOD_ENTRY(signatureInfo)
+ JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
+ JS_STATIC_METHOD_ENTRY(signatureSign)
+ JS_STATIC_METHOD_ENTRY(signatureValidate)
END_JS_STATIC_METHOD()
IMPLEMENT_JS_CLASS(CJS_Field, Field)
-FX_BOOL CJS_Field::InitInstance(IFXJS_Context* cc)
+FX_BOOL CJS_Field::InitInstance(IFXJS_Context* cc)
{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
- Field* pField = (Field*)GetEmbedObject();
- ASSERT(pField != NULL);
+ Field* pField = (Field*)GetEmbedObject();
+ ASSERT(pField != NULL);
- pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
+ pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
- return TRUE;
+ 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)
+ m_pJSDoc(NULL),
+ m_pDocument(NULL),
+ m_nFormControlIndex(-1),
+ m_bCanSet(FALSE),
+ m_bDelay(FALSE),
+ m_isolate(NULL)
{
}
@@ -140,3320 +140,3319 @@ 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(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);
+ 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(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;
+ ASSERT(pDocument != NULL);
+ m_pJSDoc = pDocument;
- m_pDocument = pDocument->GetReaderDoc();
- ASSERT(m_pDocument != NULL);
+ 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);
+ 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);
+ CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
+ ASSERT(pRDInterForm != NULL);
- CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
- CFX_WideString swFieldNameTemp = csFieldName;
- swFieldNameTemp.Replace(L"..", L".");
+ CFX_WideString swFieldNameTemp = csFieldName;
+ swFieldNameTemp.Replace(L"..", L".");
- if (pInterForm->CountFields(swFieldNameTemp) <= 0)
- {
- std::wstring strFieldName;
- int iControlNo = -1;
- ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
- if (iControlNo == -1) return FALSE;
+ if (pInterForm->CountFields(swFieldNameTemp) <= 0)
+ {
+ std::wstring strFieldName;
+ int iControlNo = -1;
+ ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
+ if (iControlNo == -1) return FALSE;
- m_FieldName = strFieldName.c_str();
- m_nFormControlIndex = iControlNo;
- return TRUE;
- }
+ m_FieldName = strFieldName.c_str();
+ m_nFormControlIndex = iControlNo;
+ return TRUE;
+ }
- m_FieldName = swFieldNameTemp;
- m_nFormControlIndex = -1;
+ m_FieldName = swFieldNameTemp;
+ m_nFormControlIndex = -1;
- return TRUE;
+ return TRUE;
}
void Field::GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
{
- ASSERT(pDocument != NULL);
+ ASSERT(pDocument != NULL);
- CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
- ASSERT(pReaderInterForm != NULL);
+ CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
+ ASSERT(pReaderInterForm != NULL);
- CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
- ASSERT(FieldArray.GetSize() == 0);
+ 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);
- }
+ 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);
+ ASSERT(m_pDocument != NULL);
- Field::GetFormFields(m_pDocument, csFieldName, FieldArray);
+ 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(bFormated);
- if (bFormated)
- pWidget->ResetAppearance(sValue.c_str(), 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();
+ 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(bFormated);
+ if (bFormated)
+ pWidget->ResetAppearance(sValue.c_str(), 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(bFormated);
- if (bFormated)
- pWidget->ResetAppearance(sValue.c_str(), 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();
+ 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(bFormated);
+ if (bFormated)
+ pWidget->ResetAppearance(sValue.c_str(), 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);
+ ASSERT(pDocument != NULL);
+ ASSERT(pFormControl != NULL);
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
- return pInterForm->GetWidget(pFormControl);
+ return pInterForm->GetWidget(pFormControl);
}
FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel)
{
- ASSERT(pFormField != NULL);
+ ASSERT(pFormField != NULL);
- for (int i=0,sz = pFormField->CountOptions(); i < sz; i++)
- {
- if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
- return TRUE;
- }
+ for (int i=0,sz = pFormField->CountOptions(); i < sz; i++)
+ {
+ if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField)
{
- if (!pFormField->CountControls() || m_nFormControlIndex >= pFormField->CountControls())
- return NULL;
+ ASSERT(pFormField != NULL);
+ if(!pFormField->CountControls() || m_nFormControlIndex>=pFormField->CountControls()) return NULL;
- if (m_nFormControlIndex < 0)
- return pFormField->GetControl(0);
-
- return pFormField->GetControl(m_nFormControlIndex);
+ if (m_nFormControlIndex<0)
+ return pFormField->GetControl(0);
+ else
+ return pFormField->GetControl(m_nFormControlIndex);
}
/* ---------------------------------------- property ---------------------------------------- */
FX_BOOL Field::alignment(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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 << L"center";
- break;
- case 0:
- vp << L"left";
- break;
- case 2:
- vp << L"right";
- break;
- default:
- vp << L"";
- }
- }
-
- return TRUE;
+ 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 << L"center";
+ break;
+ case 0:
+ vp << L"left";
+ break;
+ case 2:
+ vp << L"right";
+ break;
+ default:
+ vp << L"";
+ }
+ }
+
+ return TRUE;
}
void Field::SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_ByteString& string)
+ const CFX_ByteString& string)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::borderStyle(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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 << L"solid";
- break;
- case BBS_DASH:
- vp << L"dashed";
- break;
- case BBS_BEVELED:
- vp << L"beveled";
- break;
- case BBS_INSET:
- vp << L"inset";
- break;
- case BBS_UNDERLINE:
- vp << L"underline";
- break;
- default:
- vp << L"";
- break;
- }
- }
-
- return TRUE;
+ 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 << L"solid";
+ break;
+ case BBS_DASH:
+ vp << L"dashed";
+ break;
+ case BBS_BEVELED:
+ vp << L"beveled";
+ break;
+ case BBS_INSET:
+ vp << L"inset";
+ break;
+ case BBS_UNDERLINE:
+ vp << L"underline";
+ break;
+ default:
+ vp << 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);
- }
- }
- }
- }
- }
+ 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- int nVP;
- vp >> nVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
- FX_FLOAT fLeft,fBottom;
- IconFit.GetIconPosition(fLeft,fBottom);
+ FX_FLOAT fLeft,fBottom;
+ IconFit.GetIconPosition(fLeft,fBottom);
- vp << (int32_t)fLeft;
- }
+ vp << (int32_t)fLeft;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::buttonAlignY(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- int nVP;
- vp >> nVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
- FX_FLOAT fLeft,fBottom;
- IconFit.GetIconPosition(fLeft,fBottom);
+ FX_FLOAT fLeft,fBottom;
+ IconFit.GetIconPosition(fLeft,fBottom);
- vp << (int32_t)fBottom;
- }
+ vp << (int32_t)fBottom;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::buttonFitBounds(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
- vp << IconFit.GetFittingBounds();
- }
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ vp << IconFit.GetFittingBounds();
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::buttonPosition(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- int nVP;
- vp >> nVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- vp << pFormControl->GetTextPosition();
- }
- return TRUE;
+ vp << pFormControl->GetTextPosition();
+ }
+ return TRUE;
}
void Field::SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::buttonScaleHow(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- int nVP;
- vp >> nVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
- if (IconFit.IsProportionalScale())
- vp << (int32_t)0;
- else
- vp << (int32_t)1;
- }
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ if (IconFit.IsProportionalScale())
+ vp << (int32_t)0;
+ else
+ vp << (int32_t)1;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::buttonScaleWhen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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 << (int32_t) CPDF_IconFit::Always;
- break;
- case CPDF_IconFit::Bigger :
- vp << (int32_t) CPDF_IconFit::Bigger;
- break;
- case CPDF_IconFit::Never :
- vp << (int32_t) CPDF_IconFit::Never;
- break;
- case CPDF_IconFit::Smaller :
- vp << (int32_t) CPDF_IconFit::Smaller;
- break;
- }
- }
-
- return TRUE;
+ 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 << (int32_t) CPDF_IconFit::Always;
+ break;
+ case CPDF_IconFit::Bigger :
+ vp << (int32_t) CPDF_IconFit::Bigger;
+ break;
+ case CPDF_IconFit::Never :
+ vp << (int32_t) CPDF_IconFit::Never;
+ break;
+ case CPDF_IconFit::Smaller :
+ vp << (int32_t) CPDF_IconFit::Smaller;
+ break;
+ }
+ }
+
+ return TRUE;
}
void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::calcOrderIndex(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- int nVP;
- vp >> nVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
- CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
- ASSERT(pRDInterForm != NULL);
+ CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
+ ASSERT(pRDInterForm != NULL);
- CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
- vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
- }
+ vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::charLimit(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- int nVP;
- vp >> nVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
- vp << (int32_t)pFormField->GetMaxLen();
- }
- return TRUE;
+ vp << (int32_t)pFormField->GetMaxLen();
+ }
+ return TRUE;
}
void Field::SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::comb(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::commitOnSelChange(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::currentValueIndices(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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 = SelValue.ToInt();
- 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;
+ 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 = SelValue.ToInt();
+ 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)
+ const CFX_DWordArray& array)
{
- ASSERT(pDocument != NULL);
+ ASSERT(pDocument != NULL);
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
+ 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);
+ 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);
+ 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;
- }
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ {
+ if (i>0 && !(dwFieldFlags & (1<<21)))
+ {
+ break;
+ }
- int iSelecting = (int32_t)array.GetAt(i);
- if (iSelecting < pFormField->CountOptions() && !pFormField->IsItemSelected(iSelecting))
- pFormField->SetItemSelection(iSelecting, TRUE);
+ int iSelecting = (int32_t)array.GetAt(i);
+ if (iSelecting < pFormField->CountOptions() && !pFormField->IsItemSelected(iSelecting))
+ pFormField->SetItemSelection(iSelecting, TRUE);
- }
- UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- }
+ }
+ UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ }
}
FX_BOOL Field::defaultStyle(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT);
- return FALSE;
+ // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT);
+ return FALSE;
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- ;
- }
- else
- {
- ;
- }
- return TRUE;
+ ;
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
}
void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::defaultValue(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- CFX_WideString WideStr;
- vp >> WideStr;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
- pFormField->GetFieldType() == FIELDTYPE_SIGNATURE)
- return FALSE;
+ if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
+ pFormField->GetFieldType() == FIELDTYPE_SIGNATURE)
+ return FALSE;
- vp << pFormField->GetDefaultValue();
- }
- return TRUE;
+ vp << pFormField->GetDefaultValue();
+ }
+ return TRUE;
}
void Field::SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_WideString& string)
+ const CFX_WideString& string)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::doNotScroll(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::doNotSpellCheck(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
- pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
+ pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetDelay(FX_BOOL bDelay)
{
- m_bDelay = bDelay;
+ m_bDelay = bDelay;
- if (!m_bDelay)
- {
- if (m_pJSDoc)
- m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
- }
+ if (!m_bDelay)
+ {
+ if (m_pJSDoc)
+ m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
+ }
}
FX_BOOL Field::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ bool bVP;
+ vp >> bVP;
- SetDelay(bVP);
- }
- else
- {
- vp << m_bDelay;
- }
- return TRUE;
+ SetDelay(bVP);
+ }
+ else
+ {
+ vp << m_bDelay;
+ }
+ return TRUE;
}
FX_BOOL Field::display(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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 << (int32_t)1;
- }
- else
- {
- if (ANNOTFLAG_PRINT & dwFlag)
- {
- if (ANNOTFLAG_NOVIEW & dwFlag)
- {
- vp << (int32_t)3;
- }
- else
- {
- vp << (int32_t)0;
- }
- }
- else
- {
- vp << (int32_t)2;
- }
- }
- }
-
- return TRUE;
+ 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 << (int32_t)1;
+ }
+ else
+ {
+ if (ANNOTFLAG_PRINT & dwFlag)
+ {
+ if (ANNOTFLAG_NOVIEW & dwFlag)
+ {
+ vp << (int32_t)3;
+ }
+ else
+ {
+ vp << (int32_t)0;
+ }
+ }
+ else
+ {
+ vp << (int32_t)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);
- }
- }
- }
- }
- }
+ 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (!vp.IsGetting()) {
- return FALSE;
- }
- vp << m_pJSDoc->GetCJSDoc();
- return TRUE;
+ if (!vp.IsGetting()) {
+ return FALSE;
+ }
+ vp << m_pJSDoc->GetCJSDoc();
+ return TRUE;
}
FX_BOOL Field::editable(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::exportValues(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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);
- 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);
- ExportValusArray.SetElement(i, CJS_Value(m_isolate,pFormControl->GetExportValue().c_str()));
- }
- }
- 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,pFormControl->GetExportValue().c_str()));
- }
- vp << ExportValusArray;
- }
- return TRUE;
+ 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,pFormControl->GetExportValue().c_str()));
+ }
+ }
+ 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,pFormControl->GetExportValue().c_str()));
+ }
+
+ vp << ExportValusArray;
+ }
+
+ return TRUE;
}
FX_BOOL Field::fileSelect(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ 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;
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0)
- return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
+ bool bVP;
+ vp >> bVP;
- if (vp.IsSetting())
- {
- if (!m_bCanSet)
- return FALSE;
+ }
+ else
+ {
+ if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
+ vp << true;
+ else
+ vp << false;
+ }
- bool bVP;
- vp >> bVP;
- }
- else
- {
- if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
- vp << true;
- else
- vp << false;
- }
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::fillColor(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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);
+ 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;
+ return TRUE;
}
void Field::SetFillColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::hidden(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
- if (!pWidget) return FALSE;
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
+ if (!pWidget) return FALSE;
- FX_DWORD dwFlags = pWidget->GetFlags();
+ FX_DWORD dwFlags = pWidget->GetFlags();
- if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
- {
- vp << true;
- }
- else
- vp << false;
- }
+ if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
+ {
+ vp << true;
+ }
+ else
+ vp << false;
+ }
- return TRUE;
+ 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);
- }
- }
- }
- }
- }
+ 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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 << L"none";
- break;
- case CPDF_FormControl::Push:
- vp << L"push";
- break;
- case CPDF_FormControl::Invert:
- vp << L"invert";
- break;
- case CPDF_FormControl::Outline:
- vp << L"outline";
- break;
- case CPDF_FormControl::Toggle:
- vp << L"toggle";
- break;
- }
- }
-
- return TRUE;
+ 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 << L"none";
+ break;
+ case CPDF_FormControl::Push:
+ vp << L"push";
+ break;
+ case CPDF_FormControl::Invert:
+ vp << L"invert";
+ break;
+ case CPDF_FormControl::Outline:
+ vp << L"outline";
+ break;
+ case CPDF_FormControl::Toggle:
+ vp << L"toggle";
+ break;
+ }
+ }
+
+ return TRUE;
}
void Field::SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::lineWidth(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- int iWidth;
- vp >> iWidth;
+ 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;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl) return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl) return FALSE;
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
- if(!pFormField->CountControls()) return FALSE;
+ if(!pFormField->CountControls()) return FALSE;
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
- if (!pWidget) return FALSE;
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
+ if (!pWidget) return FALSE;
- vp << (int32_t)pWidget->GetBorderWidth();
- }
+ vp << (int32_t)pWidget->GetBorderWidth();
+ }
- return TRUE;
+ 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);
- }
- }
- }
- }
- }
+ 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::multipleSelection(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::name(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (!vp.IsGetting()) return FALSE;
+ if (!vp.IsGetting()) return FALSE;
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
- vp << m_FieldName;
+ vp << m_FieldName;
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::numItems(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
- pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
+ pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
- if (!vp.IsGetting()) return FALSE;
+ if (!vp.IsGetting()) return FALSE;
- vp << (int32_t)pFormField->CountOptions();
+ vp << (int32_t)pFormField->CountOptions();
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::page(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (!vp.IsGetting()) return FALSE;
+ if (!vp.IsGetting()) return FALSE;
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) 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;
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ if (!pFormField) return FALSE;
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
- CFX_PtrArray widgetArray;
- pInterForm->GetWidgets(pFormField, widgetArray);
+ CFX_PtrArray widgetArray;
+ pInterForm->GetWidgets(pFormField, widgetArray);
- if (widgetArray.GetSize() > 0)
- {
- CJS_Array PageArray(m_isolate);
+ 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);
+ 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;
+ CPDFSDK_PageView* pPageView = pWidget->GetPageView();
+ if(!pPageView)
+ return FALSE;
- PageArray.SetElement(i, CJS_Value(m_isolate,(int32_t)pPageView->GetPageIndex()));
- }
+ PageArray.SetElement(i, CJS_Value(m_isolate,(int32_t)pPageView->GetPageIndex()));
+ }
- vp << PageArray;
- }
- else
- {
- vp << (int32_t) -1;
- }
+ vp << PageArray;
+ }
+ else
+ {
+ vp << (int32_t) -1;
+ }
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::password(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::print(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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;
+ 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ bool bVP;
+ vp >> bVP;
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::readonly(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ bool bVP;
+ vp >> bVP;
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::rect(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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)Upper_Leftx.ToInt();
- pArray[1] = (FX_FLOAT)Lower_Righty.ToInt();
- pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt();
- pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
-
- 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 = (int32_t)crRect.left;
- Upper_Lefty = (int32_t)crRect.top;
- Lower_Rightx = (int32_t)crRect.right;
- Lower_Righty = (int32_t)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;
+ 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)Upper_Leftx.ToInt();
+ pArray[1] = (FX_FLOAT)Lower_Righty.ToInt();
+ pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt();
+ pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
+
+ 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 = (int32_t)crRect.left;
+ Upper_Lefty = (int32_t)crRect.top;
+ Lower_Rightx = (int32_t)crRect.right;
+ Lower_Righty = (int32_t)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);
- }
- }
- }
- }
- }
- }
+ 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ bool bVP;
+ vp >> bVP;
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
- return FALSE;
+ if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::richText(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- bool bVP;
- vp >> bVP;
+ 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;
+ 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);
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
- if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
- vp << true;
- else
- vp << false;
- }
+ if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
+ vp << true;
+ else
+ vp << false;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::richValue(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
- ;
- }
- else
- {
- ;
- }
- return TRUE;
+ 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.
+ //Not supported.
}
FX_BOOL Field::rotation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- int nVP;
- vp >> nVP;
+ 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;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- vp << (int32_t)pFormControl->GetRotation();
- }
+ vp << (int32_t)pFormControl->GetRotation();
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::strokeColor(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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);
+ 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;
+ return TRUE;
}
void Field::SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::style(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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;
+ 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)
+ const CFX_ByteString& string)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::submitName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::textColor(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- 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);
- int32_t 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);
+ 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);
+ int32_t 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;
+ return TRUE;
}
void Field::SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::textFont(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- CFX_ByteString csFontName;
- vp >> csFontName;
- if (csFontName.IsEmpty()) 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;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- int nFieldType = pFormField->GetFieldType();
+ 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;
+ 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;
- }
+ vp << pFont->GetBaseFont();
+ }
+ else
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetTextFont(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::textSize(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- int nVP;
- vp >> nVP;
+ int nVP;
+ vp >> nVP;
- if (m_bDelay)
- {
- AddDelay_Int(FP_TEXTSIZE, nVP);
- }
- else
- {
- Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_TEXTSIZE, nVP);
+ }
+ else
+ {
+ Field::SetTextSize(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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
+ CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
- CFX_ByteString csFontNameTag;
- FX_FLOAT fFontSize;
- FieldAppearance.GetFont(csFontNameTag,fFontSize);
+ CFX_ByteString csFontNameTag;
+ FX_FLOAT fFontSize;
+ FieldAppearance.GetFont(csFontNameTag,fFontSize);
- vp << (int)fFontSize;
- }
+ vp << (int)fFontSize;
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetTextSize(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::type(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
-
- 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);
- ASSERT(pFormField != NULL);
-
- switch (pFormField->GetFieldType())
- {
- case FIELDTYPE_UNKNOWN:
- vp << L"unknown";
- break;
- case FIELDTYPE_PUSHBUTTON:
- vp << L"button";
- break;
- case FIELDTYPE_CHECKBOX:
- vp << L"checkbox";
- break;
- case FIELDTYPE_RADIOBUTTON:
- vp << L"radiobutton";
- break;
- case FIELDTYPE_COMBOBOX:
- vp << L"combobox";
- break;
- case FIELDTYPE_LISTBOX:
- vp << L"listbox";
- break;
- case FIELDTYPE_TEXTFIELD:
- vp << L"text";
- break;
- case FIELDTYPE_SIGNATURE:
- vp << L"signature";
- break;
- default :
- vp << L"unknown";
- break;
- }
-
- return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ 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);
+ ASSERT(pFormField != NULL);
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_UNKNOWN:
+ vp << L"unknown";
+ break;
+ case FIELDTYPE_PUSHBUTTON:
+ vp << L"button";
+ break;
+ case FIELDTYPE_CHECKBOX:
+ vp << L"checkbox";
+ break;
+ case FIELDTYPE_RADIOBUTTON:
+ vp << L"radiobutton";
+ break;
+ case FIELDTYPE_COMBOBOX:
+ vp << L"combobox";
+ break;
+ case FIELDTYPE_LISTBOX:
+ vp << L"listbox";
+ break;
+ case FIELDTYPE_TEXTFIELD:
+ vp << L"text";
+ break;
+ case FIELDTYPE_SIGNATURE:
+ vp << L"signature";
+ break;
+ default :
+ vp << L"unknown";
+ break;
+ }
+
+ return TRUE;
}
FX_BOOL Field::userName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
- CFX_WideString swName;
- vp >> swName;
+ CFX_WideString swName;
+ vp >> swName;
- if (m_bDelay)
- {
- AddDelay_WideString(FP_USERNAME, swName);
- }
- else
- {
- Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ if (m_bDelay)
+ {
+ AddDelay_WideString(FP_USERNAME, swName);
+ }
+ else
+ {
+ Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
+ }
+ }
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- vp << (CFX_WideString)pFormField->GetAlternateName();
- }
+ vp << (CFX_WideString)pFormField->GetAlternateName();
+ }
- return TRUE;
+ return TRUE;
}
void Field::SetUserName(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string)
{
- //Not supported.
+ //Not supported.
}
FX_BOOL Field::value(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CJS_WideStringArray strArray;
-
- if (vp.IsArrayObject())
- {
- CJS_Array ValueArray(m_isolate);
- vp.ConvertToArray(ValueArray);
- for (int i = 0,sz = ValueArray.GetLength(); i < sz; i++)
- {
- CJS_Value ElementValue(m_isolate);
- ValueArray.GetElement(i, ElementValue);
- strArray.Add(ElementValue.ToCFXWideString());
- }
- }
- else
- {
- CFX_WideString swValue;
- vp >> swValue;
-
- strArray.Add(swValue);
- }
-
- if (m_bDelay)
- {
- AddDelay_WideStringArray(FP_VALUE, strArray);
- }
- else
- {
- Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
- }
- }
- 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);
-
-
-
- switch (pFormField->GetFieldType())
- {
- case FIELDTYPE_PUSHBUTTON:
- return FALSE;
- case FIELDTYPE_COMBOBOX:
- case FIELDTYPE_TEXTFIELD:
- {
- CFX_WideString swValue = pFormField->GetValue();
-
- double dRet;
- FX_BOOL bDot;
- if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, bDot))
- {
- if (bDot)
- vp << dRet;
- else
- vp << dRet;
- }
- else
- vp << swValue;
- }
- break;
- case FIELDTYPE_LISTBOX:
- {
- if (pFormField->CountSelectedItems() > 1)
- {
- CJS_Array ValueArray(m_isolate);
- CJS_Value ElementValue(m_isolate);
- int iIndex;
- for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++)
- {
- iIndex = pFormField->GetSelectedIndex(i);
- ElementValue = pFormField->GetOptionValue(iIndex).c_str();
- if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
- ElementValue = pFormField->GetOptionLabel(iIndex).c_str();
- ValueArray.SetElement(i, ElementValue);
- }
- vp << ValueArray;
- }
- else
- {
- CFX_WideString swValue = pFormField->GetValue();
-
- double dRet;
- FX_BOOL bDot;
- if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, bDot))
- {
- if (bDot)
- vp << dRet;
- else
- vp << dRet;
- }
- else
- vp << swValue;
- }
- }
- break;
- case FIELDTYPE_CHECKBOX:
- case FIELDTYPE_RADIOBUTTON:
- {
- FX_BOOL bFind = FALSE;
- for (int i = 0 , sz = pFormField->CountControls(); i < sz; i++)
- {
- if (pFormField->GetControl(i)->IsChecked())
- {
- CFX_WideString swValue = pFormField->GetControl(i)->GetExportValue();
- double dRet;
- FX_BOOL bDot;
- if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, bDot))
- {
- if (bDot)
- vp << dRet;
- else
- vp << dRet;
- }
- else
- vp << swValue;
-
- bFind = TRUE;
- break;
- }
- else
- continue;
- }
- if (!bFind)
- vp << L"Off";
- }
- break;
- default:
- vp << pFormField->GetValue();
- break;
- }
- }
-
- return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CJS_WideStringArray strArray;
+
+ if (vp.IsArrayObject())
+ {
+ CJS_Array ValueArray(m_isolate);
+ vp.ConvertToArray(ValueArray);
+ for (int i = 0,sz = ValueArray.GetLength(); i < sz; i++)
+ {
+ CJS_Value ElementValue(m_isolate);
+ ValueArray.GetElement(i, ElementValue);
+ strArray.Add(ElementValue.ToCFXWideString());
+ }
+ }
+ else
+ {
+ CFX_WideString swValue;
+ vp >> swValue;
+
+ strArray.Add(swValue);
+ }
+
+ if (m_bDelay)
+ {
+ AddDelay_WideStringArray(FP_VALUE, strArray);
+ }
+ else
+ {
+ Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
+ }
+ }
+ 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);
+
+
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_PUSHBUTTON:
+ return FALSE;
+ case FIELDTYPE_COMBOBOX:
+ case FIELDTYPE_TEXTFIELD:
+ {
+ CFX_WideString swValue = pFormField->GetValue();
+
+ double dRet;
+ FX_BOOL bDot;
+ if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, bDot))
+ {
+ if (bDot)
+ vp << dRet;
+ else
+ vp << dRet;
+ }
+ else
+ vp << swValue;
+ }
+ break;
+ case FIELDTYPE_LISTBOX:
+ {
+ if (pFormField->CountSelectedItems() > 1)
+ {
+ CJS_Array ValueArray(m_isolate);
+ CJS_Value ElementValue(m_isolate);
+ int iIndex;
+ for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++)
+ {
+ iIndex = pFormField->GetSelectedIndex(i);
+ ElementValue = pFormField->GetOptionValue(iIndex).c_str();
+ if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
+ ElementValue = pFormField->GetOptionLabel(iIndex).c_str();
+ ValueArray.SetElement(i, ElementValue);
+ }
+ vp << ValueArray;
+ }
+ else
+ {
+ CFX_WideString swValue = pFormField->GetValue();
+
+ double dRet;
+ FX_BOOL bDot;
+ if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, bDot))
+ {
+ if (bDot)
+ vp << dRet;
+ else
+ vp << dRet;
+ }
+ else
+ vp << swValue;
+ }
+ }
+ break;
+ case FIELDTYPE_CHECKBOX:
+ case FIELDTYPE_RADIOBUTTON:
+ {
+ FX_BOOL bFind = FALSE;
+ for (int i = 0 , sz = pFormField->CountControls(); i < sz; i++)
+ {
+ if (pFormField->GetControl(i)->IsChecked())
+ {
+ CFX_WideString swValue = pFormField->GetControl(i)->GetExportValue();
+ double dRet;
+ FX_BOOL bDot;
+ if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, bDot))
+ {
+ if (bDot)
+ vp << dRet;
+ else
+ vp << dRet;
+ }
+ else
+ vp << swValue;
+
+ bFind = TRUE;
+ break;
+ }
+ else
+ continue;
+ }
+ if (!bFind)
+ vp << L"Off";
+ }
+ break;
+ default:
+ vp << pFormField->GetValue();
+ break;
+ }
+ }
+
+ return TRUE;
}
void Field::SetValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName,
- int nControlIndex, const CJS_WideStringArray& strArray)
-{
- ASSERT(pDocument != NULL);
-
- if (strArray.GetSize() < 1) 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 (pFormField->GetFullName().Compare(swFieldName) != 0)
- continue;
-
- switch (pFormField->GetFieldType())
- {
- case FIELDTYPE_TEXTFIELD:
- case FIELDTYPE_COMBOBOX:
- if (pFormField->GetValue() != strArray.GetAt(0))
- {
- CFX_WideString WideString = strArray.GetAt(0);
- pFormField->SetValue(strArray.GetAt(0), TRUE);
- UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- break;
- case FIELDTYPE_CHECKBOX: //mantis: 0004493
- case FIELDTYPE_RADIOBUTTON:
- {
- if (pFormField->GetValue() != strArray.GetAt(0))
- {
- pFormField->SetValue(strArray.GetAt(0), TRUE);
- UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- }
- break;
- case FIELDTYPE_LISTBOX:
- {
- FX_BOOL bModified = FALSE;
-
- for (int i=0,sz=strArray.GetSize(); i<sz; i++)
- {
- int iIndex = pFormField->FindOption(strArray.GetAt(i));
-
- if (!pFormField->IsItemSelected(iIndex))
- {
- bModified = TRUE;
- break;
- }
- }
-
- if (bModified)
- {
- pFormField->ClearSelection(TRUE);
- for (int i=0,sz=strArray.GetSize(); i<sz; i++)
- {
- int iIndex = pFormField->FindOption(strArray.GetAt(i));
- pFormField->SetItemSelection(iIndex, TRUE, TRUE);
- }
-
- UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- }
- break;
- default:
- break;
- }
- }
+ int nControlIndex, const CJS_WideStringArray& strArray)
+{
+ ASSERT(pDocument != NULL);
+
+ if (strArray.GetSize() < 1) 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 (pFormField->GetFullName().Compare(swFieldName) != 0)
+ continue;
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_TEXTFIELD:
+ case FIELDTYPE_COMBOBOX:
+ if (pFormField->GetValue() != strArray.GetAt(0))
+ {
+ CFX_WideString WideString = strArray.GetAt(0);
+ pFormField->SetValue(strArray.GetAt(0), TRUE);
+ UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ break;
+ case FIELDTYPE_CHECKBOX: //mantis: 0004493
+ case FIELDTYPE_RADIOBUTTON:
+ {
+ if (pFormField->GetValue() != strArray.GetAt(0))
+ {
+ pFormField->SetValue(strArray.GetAt(0), TRUE);
+ UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ }
+ break;
+ case FIELDTYPE_LISTBOX:
+ {
+ FX_BOOL bModified = FALSE;
+
+ for (int i=0,sz=strArray.GetSize(); i<sz; i++)
+ {
+ int iIndex = pFormField->FindOption(strArray.GetAt(i));
+
+ if (!pFormField->IsItemSelected(iIndex))
+ {
+ bModified = TRUE;
+ break;
+ }
+ }
+
+ if (bModified)
+ {
+ pFormField->ClearSelection(TRUE);
+ for (int i=0,sz=strArray.GetSize(); i<sz; i++)
+ {
+ int iIndex = pFormField->FindOption(strArray.GetAt(i));
+ pFormField->SetItemSelection(iIndex, TRUE, TRUE);
+ }
+
+ UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
}
FX_BOOL Field::valueAsString(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
-
- 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);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
- {
- if(!pFormField->CountControls()) return FALSE;
-
- if (pFormField->GetControl(0)->IsChecked())
- vp << L"Yes";
- else
- vp << L"Off";
- }
- else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON && !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON))
- {
- for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
- {
- if (pFormField->GetControl(i)->IsChecked())
- {
- vp << pFormField->GetControl(i)->GetExportValue().c_str();
- break;
- }
- else
- vp << L"Off";
- }
- }
- else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && (pFormField->CountSelectedItems() > 1))
- {
- vp << L"";
- }
- else
- vp << pFormField->GetValue().c_str();
-
- return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ 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);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
+ {
+ if(!pFormField->CountControls()) return FALSE;
+
+ if (pFormField->GetControl(0)->IsChecked())
+ vp << L"Yes";
+ else
+ vp << L"Off";
+ }
+ else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON && !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON))
+ {
+ for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
+ {
+ if (pFormField->GetControl(i)->IsChecked())
+ {
+ vp << pFormField->GetControl(i)->GetExportValue().c_str();
+ break;
+ }
+ else
+ vp << L"Off";
+ }
+ }
+ else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && (pFormField->CountSelectedItems() > 1))
+ {
+ vp << L"";
+ }
+ else
+ vp << pFormField->GetValue().c_str();
+
+ return TRUE;
}
/* --------------------------------- methods --------------------------------- */
FX_BOOL Field::browseForFileToSubmit(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
- ASSERT(pApp != NULL);
+ CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
+ ASSERT(pApp != NULL);
- if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
- (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD))
- {
- CFX_WideString wsFileName = pApp->JS_fieldBrowse();
- if(!wsFileName.IsEmpty())
- {
- pFormField->SetValue(wsFileName);
- UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
+ if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
+ (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD))
+ {
+ CFX_WideString wsFileName = pApp->JS_fieldBrowse();
+ if(!wsFileName.IsEmpty())
+ {
+ pFormField->SetValue(wsFileName);
+ UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
}
- }
- else
- return FALSE;
+ }
+ else
+ return FALSE;
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::buttonGetCaption(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- int nface = 0;
- int iSize = params.size();
- if (iSize >= 1)
- nface = params[0].ToInt();
+ int nface = 0;
+ int iSize = params.size();
+ if (iSize >= 1)
+ nface = params[0].ToInt();
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- if (nface == 0)
- vRet = pFormControl->GetNormalCaption().c_str();
- else if (nface == 1)
- vRet = pFormControl->GetDownCaption().c_str();
- else if (nface == 2)
- vRet = pFormControl->GetRolloverCaption().c_str();
- else
- return FALSE;
+ if (nface == 0)
+ vRet = pFormControl->GetNormalCaption().c_str();
+ else if (nface == 1)
+ vRet = pFormControl->GetDownCaption().c_str();
+ else if (nface == 2)
+ vRet = pFormControl->GetRolloverCaption().c_str();
+ else
+ return FALSE;
- return TRUE;
+ return TRUE;
}
//#pragma warning(disable: 4800)
FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- int nface = 0;
- int iSize = params.size();
- if (iSize >= 1)
- nface = params[0].ToInt();
+ int nface = 0;
+ int iSize = params.size();
+ if (iSize >= 1)
+ nface = params[0].ToInt();
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
- ASSERT(pObj.IsEmpty() == FALSE);
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
+ ASSERT(pObj.IsEmpty() == FALSE);
- CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj);
- ASSERT(pJS_Icon != NULL);
+ CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj);
+ ASSERT(pJS_Icon != NULL);
- Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
- ASSERT(pIcon != NULL);
+ Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+ ASSERT(pIcon != NULL);
- CPDF_Stream* pIconStream = NULL;
- if (nface == 0)
- pIconStream = pFormControl->GetNormalIcon();
- else if (nface == 1)
- pIconStream = pFormControl->GetDownIcon();
- else if (nface == 2)
- pIconStream = pFormControl->GetRolloverIcon();
- else
- return FALSE;
+ CPDF_Stream* pIconStream = NULL;
+ if (nface == 0)
+ pIconStream = pFormControl->GetNormalIcon();
+ else if (nface == 1)
+ pIconStream = pFormControl->GetDownIcon();
+ else if (nface == 2)
+ pIconStream = pFormControl->GetRolloverIcon();
+ else
+ return FALSE;
- pIcon->SetStream(pIconStream);
- vRet = pJS_Icon;
+ pIcon->SetStream(pIconStream);
+ vRet = pJS_Icon;
- return TRUE;
+ return TRUE;
}
//#pragma warning(default: 4800)
@@ -3461,656 +3460,656 @@ FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJ
FX_BOOL Field::buttonImportIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
#if 0
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) 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;
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ if (!pFormField)return FALSE;
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv);
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv);
- CFX_WideString sIconFileName = pEnv->JS_fieldBrowse();
- if (sIconFileName.IsEmpty())
- {
- vRet = 1;
- return TRUE;
- }
+ CFX_WideString sIconFileName = pEnv->JS_fieldBrowse();
+ if (sIconFileName.IsEmpty())
+ {
+ vRet = 1;
+ return TRUE;
+ }
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
- CPDF_Stream* pStream = pInterForm->LoadImageFromFile(sIconFileName);
- if (!pStream)
- {
- vRet = -1;
- return TRUE;
- }
+ CPDF_Stream* pStream = pInterForm->LoadImageFromFile(sIconFileName);
+ if (!pStream)
+ {
+ vRet = -1;
+ return TRUE;
+ }
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
- pFormControl->SetNormalIcon(pStream);
- UpdateFormControl(m_pDocument, pFormControl, TRUE, TRUE, TRUE);
+ pFormControl->SetNormalIcon(pStream);
+ UpdateFormControl(m_pDocument, pFormControl, TRUE, TRUE, TRUE);
- vRet = 0;
+ vRet = 0;
#endif // 0
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::buttonSetCaption(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::buttonSetIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::checkThisBox(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (!m_bCanSet) return FALSE;
+ if (!m_bCanSet) return FALSE;
- int iSize = params.size();
- if (iSize < 1)
- return FALSE;
+ int iSize = params.size();
+ if (iSize < 1)
+ return FALSE;
- int nWidget = params[0].ToInt();
+ int nWidget = params[0].ToInt();
- FX_BOOL bCheckit = TRUE;
- if (iSize >= 2)
- bCheckit = params[1].ToBool();
+ FX_BOOL bCheckit = TRUE;
+ if (iSize >= 2)
+ bCheckit = params[1].ToBool();
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
- return FALSE;
- if(nWidget <0 || nWidget >= pFormField->CountControls())
- return FALSE;
- if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
- pFormField->CheckControl(nWidget, bCheckit, TRUE);
- else
- pFormField->CheckControl(nWidget, bCheckit, TRUE);
+ if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
+ return FALSE;
+ if(nWidget <0 || nWidget >= pFormField->CountControls())
+ return FALSE;
+ if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
+ pFormField->CheckControl(nWidget, bCheckit, TRUE);
+ else
+ pFormField->CheckControl(nWidget, bCheckit, TRUE);
- UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
- return TRUE;
+ UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
+ return TRUE;
}
FX_BOOL Field::clearItems(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::defaultIsChecked(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- if (!m_bCanSet) return FALSE;
+ if (!m_bCanSet) return FALSE;
- int iSize = params.size();
- if (iSize < 1)
- return FALSE;
+ int iSize = params.size();
+ if (iSize < 1)
+ return FALSE;
- int nWidget = params[0].ToInt();
+ int nWidget = params[0].ToInt();
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if(nWidget <0 || nWidget >= pFormField->CountControls())
- {
- vRet = FALSE;
- return FALSE;
- }
- if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
- || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
- {
+ if(nWidget <0 || nWidget >= pFormField->CountControls())
+ {
+ vRet = FALSE;
+ return FALSE;
+ }
+ if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
+ || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
+ {
- vRet = TRUE;
- }
- else
- vRet = FALSE;
+ vRet = TRUE;
+ }
+ else
+ vRet = FALSE;
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::deleteItemAt(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2)
{
- ASSERT(ps1 != NULL);
- ASSERT(ps2 != NULL);
+ ASSERT(ps1 != NULL);
+ ASSERT(ps2 != NULL);
- return ps1->Compare(*ps2);
+ return ps1->Compare(*ps2);
}
FX_BOOL Field::getArray(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
- CGW_ArrayTemplate<CFX_WideString*> swSort;
+ CGW_ArrayTemplate<CFX_WideString*> swSort;
- for (int i=0,sz=FieldArray.GetSize(); i<sz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
+ for (int i=0,sz=FieldArray.GetSize(); i<sz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
- swSort.Add(new CFX_WideString(pFormField->GetFullName()));
+ swSort.Add(new CFX_WideString(pFormField->GetFullName()));
- }
- swSort.Sort(JS_COMPARESTRING);
+ }
+ swSort.Sort(JS_COMPARESTRING);
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
- CJS_Array FormFieldArray(m_isolate);
- for (int j=0,jsz = swSort.GetSize(); j<jsz; j++)
- {
- CFX_WideString* pStr = swSort.GetAt(j);
+ CJS_Array FormFieldArray(m_isolate);
+ for (int j=0,jsz = swSort.GetSize(); j<jsz; j++)
+ {
+ CFX_WideString* pStr = swSort.GetAt(j);
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
- ASSERT(pObj.IsEmpty() == FALSE);
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
+ ASSERT(pObj.IsEmpty() == FALSE);
- CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pObj);
- ASSERT(pJSField != NULL);
+ CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pObj);
+ ASSERT(pJSField != NULL);
- Field* pField = (Field*)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
+ Field* pField = (Field*)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
- pField->AttachField(m_pJSDoc, *pStr);
+ pField->AttachField(m_pJSDoc, *pStr);
- CJS_Value FormFieldValue(m_isolate);
- FormFieldValue = pJSField;
- FormFieldArray.SetElement(j, FormFieldValue);
+ CJS_Value FormFieldValue(m_isolate);
+ FormFieldValue = pJSField;
+ FormFieldArray.SetElement(j, FormFieldValue);
- delete pStr;
- }
+ delete pStr;
+ }
- vRet = FormFieldArray;
- swSort.RemoveAll();
- return TRUE;
+ vRet = FormFieldArray;
+ swSort.RemoveAll();
+ return TRUE;
}
FX_BOOL Field::getItemAt(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
- int iSize = params.size();
-
- int nIdx = -1;
- if (iSize >= 1)
- nIdx = params[0].ToInt();
-
- FX_BOOL bExport = TRUE;
- if (iSize >= 2)
- bExport = params[1].ToBool();
-
- 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)
- || (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX))
- {
- if (nIdx == -1 || nIdx > pFormField->CountOptions())
- nIdx = pFormField->CountOptions() -1;
- if (bExport)
- {
- CFX_WideString strval = pFormField->GetOptionValue(nIdx);
- if (strval.IsEmpty())
- vRet = pFormField->GetOptionLabel(nIdx).c_str();
- else
- vRet = strval.c_str();
- }
- else
- vRet = pFormField->GetOptionLabel(nIdx).c_str();
- }
- else
- return FALSE;
-
- return TRUE;
+ ASSERT(m_pDocument != NULL);
+ int iSize = params.size();
+
+ int nIdx = -1;
+ if (iSize >= 1)
+ nIdx = params[0].ToInt();
+
+ FX_BOOL bExport = TRUE;
+ if (iSize >= 2)
+ bExport = params[1].ToBool();
+
+ 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)
+ || (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX))
+ {
+ if (nIdx == -1 || nIdx > pFormField->CountOptions())
+ nIdx = pFormField->CountOptions() -1;
+ if (bExport)
+ {
+ CFX_WideString strval = pFormField->GetOptionValue(nIdx);
+ if (strval.IsEmpty())
+ vRet = pFormField->GetOptionLabel(nIdx).c_str();
+ else
+ vRet = strval.c_str();
+ }
+ else
+ vRet = pFormField->GetOptionLabel(nIdx).c_str();
+ }
+ else
+ return FALSE;
+
+ return TRUE;
}
FX_BOOL Field::getLock(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::insertItemAt(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::isBoxChecked(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- int nIndex = -1;
- if (params.size() >= 1)
- nIndex = params[0].ToInt();
+ int nIndex = -1;
+ if (params.size() >= 1)
+ nIndex = params[0].ToInt();
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if(nIndex <0 || nIndex >= pFormField->CountControls())
- {
- vRet = FALSE;
- return FALSE;
- }
+ if(nIndex <0 || nIndex >= pFormField->CountControls())
+ {
+ vRet = FALSE;
+ return FALSE;
+ }
- if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
- || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
- {
- if (pFormField->GetControl(nIndex)->IsChecked() !=0 )
- vRet = TRUE;
- else
- vRet = FALSE;
- }
- else
- vRet = FALSE;
+ if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
+ || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
+ {
+ if (pFormField->GetControl(nIndex)->IsChecked() !=0 )
+ vRet = TRUE;
+ else
+ vRet = FALSE;
+ }
+ else
+ vRet = FALSE;
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::isDefaultChecked(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- ASSERT(m_pDocument != NULL);
+ ASSERT(m_pDocument != NULL);
- int nIndex = -1;
- if (params.size() >= 1)
- nIndex = params[0].ToInt();
+ int nIndex = -1;
+ if (params.size() >= 1)
+ nIndex = params[0].ToInt();
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
+ 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
- if(nIndex <0 || nIndex >= pFormField->CountControls())
- {
- vRet = FALSE;
- return FALSE;
- }
- if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
- || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
- {
- if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)
- vRet = TRUE;
- else
- vRet = FALSE;
- }
- else
- vRet = FALSE;
+ if(nIndex <0 || nIndex >= pFormField->CountControls())
+ {
+ vRet = FALSE;
+ return FALSE;
+ }
+ if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
+ || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
+ {
+ if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)
+ vRet = TRUE;
+ else
+ vRet = FALSE;
+ }
+ else
+ vRet = FALSE;
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::setAction(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::setFocus(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- 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);
-
- int32_t nCount = pFormField->CountControls();
-
- if (nCount < 1) return FALSE;
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = NULL;
- if (nCount == 1)
- {
- pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
- }
- else
- {
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv);
- CPDF_Page* pPage = (CPDF_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument());
- if(!pPage)
- return FALSE;
- if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage))
- {
- for (int32_t i=0; i<nCount; i++)
- {
- if (CPDFSDK_Widget* pTempWidget = pInterForm->GetWidget(pFormField->GetControl(i)))
- {
- if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage())
- {
- pWidget = pTempWidget;
- break;
- }
- }
- }
- }
- }
-
- if (pWidget)
- {
- m_pDocument->SetFocusAnnot(pWidget);
- }
-
- return TRUE;
+ 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);
+
+ int32_t nCount = pFormField->CountControls();
+
+ if (nCount < 1) return FALSE;
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = NULL;
+ if (nCount == 1)
+ {
+ pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
+ }
+ else
+ {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv);
+ CPDF_Page* pPage = (CPDF_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument());
+ if(!pPage)
+ return FALSE;
+ if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage))
+ {
+ for (int32_t i=0; i<nCount; i++)
+ {
+ if (CPDFSDK_Widget* pTempWidget = pInterForm->GetWidget(pFormField->GetControl(i)))
+ {
+ if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage())
+ {
+ pWidget = pTempWidget;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (pWidget)
+ {
+ m_pDocument->SetFocusAnnot(pWidget);
+ }
+
+ return TRUE;
}
FX_BOOL Field::setItems(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return TRUE;
+ return TRUE;
}
FX_BOOL Field::setLock(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::signatureGetModifications(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::signatureGetSeedValue(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::signatureInfo(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::signatureSetSeedValue(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::signatureSign(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::signatureValidate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return FALSE;
+ return FALSE;
}
FX_BOOL Field::source(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsGetting())
- {
- vp << (CJS_Object*)NULL;
- }
+ if (vp.IsGetting())
+ {
+ vp << (CJS_Object*)NULL;
+ }
- return TRUE;
+ return TRUE;
}
/////////////////////////////////////////// delay /////////////////////////////////////////////
void Field::AddDelay_Int(enum FIELD_PROP prop, int32_t n)
{
- ASSERT(m_pJSDoc != NULL);
+ ASSERT(m_pJSDoc != NULL);
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->num = n;
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->num = n;
- m_pJSDoc->AddDelayData(pNewData);
+ m_pJSDoc->AddDelayData(pNewData);
}
void Field::AddDelay_Bool(enum FIELD_PROP prop,bool b)
{
- ASSERT(m_pJSDoc != NULL);
+ ASSERT(m_pJSDoc != NULL);
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->b = b;
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->b = b;
- m_pJSDoc->AddDelayData(pNewData);
+ m_pJSDoc->AddDelayData(pNewData);
}
void Field::AddDelay_String(enum FIELD_PROP prop, const CFX_ByteString& string)
{
- ASSERT(m_pJSDoc != NULL);
+ ASSERT(m_pJSDoc != NULL);
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->string = string;
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->string = string;
- m_pJSDoc->AddDelayData(pNewData);
+ m_pJSDoc->AddDelayData(pNewData);
}
void Field::AddDelay_WideString(enum FIELD_PROP prop, const CFX_WideString& string)
{
- ASSERT(m_pJSDoc != NULL);
+ ASSERT(m_pJSDoc != NULL);
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->widestring = string;
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->widestring = string;
- m_pJSDoc->AddDelayData(pNewData);
+ m_pJSDoc->AddDelayData(pNewData);
}
void Field::AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect)
{
- ASSERT(m_pJSDoc != NULL);
+ ASSERT(m_pJSDoc != NULL);
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->rect = rect;
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->rect = rect;
- m_pJSDoc->AddDelayData(pNewData);
+ m_pJSDoc->AddDelayData(pNewData);
}
void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color)
{
- ASSERT(m_pJSDoc != NULL);
+ ASSERT(m_pJSDoc != NULL);
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->color = color;
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->color = color;
- m_pJSDoc->AddDelayData(pNewData);
+ m_pJSDoc->AddDelayData(pNewData);
}
void Field::AddDelay_WordArray(enum FIELD_PROP prop, const CFX_DWordArray& array)
{
- ASSERT(m_pJSDoc != NULL);
+ ASSERT(m_pJSDoc != NULL);
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
- for (int i=0,sz=array.GetSize(); i<sz; i++)
- pNewData->wordarray.Add(array.GetAt(i));
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ pNewData->wordarray.Add(array.GetAt(i));
- m_pJSDoc->AddDelayData(pNewData);
+ m_pJSDoc->AddDelayData(pNewData);
}
void Field::AddDelay_WideStringArray(enum FIELD_PROP prop, const CJS_WideStringArray& array)
{
- ASSERT(m_pJSDoc != NULL);
+ ASSERT(m_pJSDoc != NULL);
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- for (int i=0,sz=array.GetSize(); i<sz; i++)
- pNewData->widestringarray.Add(array.GetAt(i));
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ pNewData->widestringarray.Add(array.GetAt(i));
- m_pJSDoc->AddDelayData(pNewData);
+ m_pJSDoc->AddDelayData(pNewData);
}
void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData)
{
- ASSERT(pDocument != NULL);
- ASSERT(pData != NULL);
-
- switch (pData->eProp)
- {
- case FP_ALIGNMENT:
- Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_BORDERSTYLE:
- Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_BUTTONALIGNX:
- Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_BUTTONALIGNY:
- Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_BUTTONFITBOUNDS:
- Field::SetButtonFitBounds(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_BUTTONPOSITION:
- Field::SetButtonPosition(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_BUTTONSCALEHOW:
- Field::SetButtonScaleHow(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_BUTTONSCALEWHEN:
- Field::SetButtonScaleWhen(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_CALCORDERINDEX:
- Field::SetCalcOrderIndex(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_CHARLIMIT:
- Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_COMB:
- Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_COMMITONSELCHANGE:
- Field::SetCommitOnSelChange(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_CURRENTVALUEINDICES:
- Field::SetCurrentValueIndices(pDocument, pData->sFieldName, pData->nControlIndex, pData->wordarray);
- break;
- case FP_DEFAULTVALUE:
- Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring);
- break;
- case FP_DONOTSCROLL:
- Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_DISPLAY:
- Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_FILLCOLOR:
- Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
- break;
- case FP_HIDDEN:
- Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_HIGHLIGHT:
- Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_LINEWIDTH:
- Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_MULTILINE:
- Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_MULTIPLESELECTION:
- Field::SetMultipleSelection(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_PASSWORD:
- Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_RECT:
- Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex, pData->rect);
- break;
- case FP_RICHTEXT:
- Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_RICHVALUE:
- break;
- case FP_ROTATION:
- Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_STROKECOLOR:
- Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
- break;
- case FP_STYLE:
- Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_TEXTCOLOR:
- Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
- break;
- case FP_TEXTFONT:
- Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_TEXTSIZE:
- Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_USERNAME:
- Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring);
- break;
- case FP_VALUE:
- Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestringarray);
- break;
- }
-}
-
-#define JS_FIELD_MINWIDTH 1
-#define JS_FIELD_MINHEIGHT 1
+ ASSERT(pDocument != NULL);
+ ASSERT(pData != NULL);
+
+ switch (pData->eProp)
+ {
+ case FP_ALIGNMENT:
+ Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_BORDERSTYLE:
+ Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_BUTTONALIGNX:
+ Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_BUTTONALIGNY:
+ Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_BUTTONFITBOUNDS:
+ Field::SetButtonFitBounds(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_BUTTONPOSITION:
+ Field::SetButtonPosition(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_BUTTONSCALEHOW:
+ Field::SetButtonScaleHow(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_BUTTONSCALEWHEN:
+ Field::SetButtonScaleWhen(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_CALCORDERINDEX:
+ Field::SetCalcOrderIndex(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_CHARLIMIT:
+ Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_COMB:
+ Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_COMMITONSELCHANGE:
+ Field::SetCommitOnSelChange(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_CURRENTVALUEINDICES:
+ Field::SetCurrentValueIndices(pDocument, pData->sFieldName, pData->nControlIndex, pData->wordarray);
+ break;
+ case FP_DEFAULTVALUE:
+ Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring);
+ break;
+ case FP_DONOTSCROLL:
+ Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_DISPLAY:
+ Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_FILLCOLOR:
+ Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
+ break;
+ case FP_HIDDEN:
+ Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_HIGHLIGHT:
+ Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_LINEWIDTH:
+ Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_MULTILINE:
+ Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_MULTIPLESELECTION:
+ Field::SetMultipleSelection(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_PASSWORD:
+ Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_RECT:
+ Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex, pData->rect);
+ break;
+ case FP_RICHTEXT:
+ Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_RICHVALUE:
+ break;
+ case FP_ROTATION:
+ Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_STROKECOLOR:
+ Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
+ break;
+ case FP_STYLE:
+ Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_TEXTCOLOR:
+ Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
+ break;
+ case FP_TEXTFONT:
+ Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_TEXTSIZE:
+ Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_USERNAME:
+ Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring);
+ break;
+ case FP_VALUE:
+ Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestringarray);
+ break;
+ }
+}
+
+#define JS_FIELD_MINWIDTH 1
+#define JS_FIELD_MINHEIGHT 1
void Field::AddField(CPDFSDK_Document* pDocument, int nPageIndex, int nFieldType,
- const CFX_WideString& sName, const CPDF_Rect& rcCoords)
+ const CFX_WideString& sName, const CPDF_Rect& rcCoords)
{
- //Not supported.
+ //Not supported.
}
diff --git a/fpdfsdk/src/javascript/JS_EventHandler.cpp b/fpdfsdk/src/javascript/JS_EventHandler.cpp
index 1769e3053f..7d27c66f6b 100644
--- a/fpdfsdk/src/javascript/JS_EventHandler.cpp
+++ b/fpdfsdk/src/javascript/JS_EventHandler.cpp
@@ -7,6 +7,7 @@
#include "../../include/javascript/JavaScript.h"
#include "../../include/javascript/IJavaScript.h"
#include "../../include/javascript/JS_EventHandler.h"
+//#include "../../include/javascript/JS_ResMgr.h"
#include "../../include/javascript/JS_Context.h"
#include "../../include/javascript/JS_Runtime.h"
#include "../../include/javascript/JS_Define.h"
@@ -17,28 +18,28 @@
/* ---------------------------- CJS_EventHandler ---------------------------- */
-CJS_EventHandler::CJS_EventHandler(CJS_Context * pContext) :
- m_pJSContext(pContext),
- m_eEventType(JET_UNKNOWN),
- m_bValid(FALSE),
- m_pWideStrChange(NULL),
- m_nCommitKey(-1),
- m_bKeyDown(FALSE),
- m_bModifier(FALSE),
- m_bShift(FALSE),
- m_pISelEnd(NULL),
- m_nSelEndDu(0),
- m_pISelStart(NULL),
- m_nSelStartDu(0),
- m_bWillCommit(FALSE),
- m_pValue(NULL),
- m_bFieldFull(FALSE),
- m_pbRc(NULL),
- m_bRcDu(FALSE),
- m_pSourceDoc(NULL),
- m_pTargetBookMark(NULL),
- m_pTargetDoc(NULL),
- m_pTargetAnnot(NULL)
+CJS_EventHandler::CJS_EventHandler(CJS_Context * pContext) :
+ m_pJSContext(pContext),
+ m_eEventType(JET_UNKNOWN),
+ m_bValid(FALSE),
+ m_pWideStrChange(NULL),
+ m_nCommitKey(-1),
+ m_bKeyDown(FALSE),
+ m_bModifier(FALSE),
+ m_bShift(FALSE),
+ m_pISelEnd(NULL),
+ m_nSelEndDu(0),
+ m_pISelStart(NULL),
+ m_nSelStartDu(0),
+ m_bWillCommit(FALSE),
+ m_pValue(NULL),
+ m_bFieldFull(FALSE),
+ m_pbRc(NULL),
+ m_bRcDu(FALSE),
+ m_pSourceDoc(NULL),
+ m_pTargetBookMark(NULL),
+ m_pTargetDoc(NULL),
+ m_pTargetAnnot(NULL)
{
}
@@ -48,617 +49,629 @@ CJS_EventHandler::~CJS_EventHandler()
void CJS_EventHandler::OnApp_Init()
{
- Initial(JET_APP_INIT);
+ Initial(JET_APP_INIT);
}
void CJS_EventHandler::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName)
{
- Initial(JET_DOC_OPEN);
+ Initial(JET_DOC_OPEN);
- m_pTargetDoc = pDoc;
- m_strTargetName = strTargetName;
+ m_pTargetDoc = pDoc;
+ m_strTargetName = strTargetName;
}
void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc)
{
- Initial(JET_DOC_WILLPRINT);
+ Initial(JET_DOC_WILLPRINT);
- m_pTargetDoc = pDoc;
+ m_pTargetDoc = pDoc;
}
void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc)
{
- Initial(JET_DOC_DIDPRINT);
+ Initial(JET_DOC_DIDPRINT);
- m_pTargetDoc = pDoc;
+ m_pTargetDoc = pDoc;
}
void CJS_EventHandler::OnDoc_WillSave(CPDFSDK_Document* pDoc)
{
- Initial(JET_DOC_WILLSAVE);
- m_pTargetDoc = pDoc;
+ Initial(JET_DOC_WILLSAVE);
+ m_pTargetDoc = pDoc;
}
void CJS_EventHandler::OnDoc_DidSave(CPDFSDK_Document* pDoc)
{
- Initial(JET_DOC_DIDSAVE);
+ Initial(JET_DOC_DIDSAVE);
- m_pTargetDoc = pDoc;
+ m_pTargetDoc = pDoc;
}
void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc)
{
- Initial(JET_DOC_WILLCLOSE);
+ Initial(JET_DOC_WILLCLOSE);
- m_pTargetDoc = pDoc;
+ m_pTargetDoc = pDoc;
}
void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc)
{
- Initial(JET_PAGE_OPEN);
+ Initial(JET_PAGE_OPEN);
- m_pTargetDoc = pDoc;
+ m_pTargetDoc = pDoc;
}
void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc)
{
- Initial(JET_PAGE_CLOSE);
+ Initial(JET_PAGE_CLOSE);
- m_pTargetDoc = pDoc;
+ m_pTargetDoc = pDoc;
}
void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc)
{
- Initial(JET_PAGE_INVIEW);
+ Initial(JET_PAGE_INVIEW);
- m_pTargetDoc = pDoc;
+ m_pTargetDoc = pDoc;
}
void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc)
{
- Initial(JET_PAGE_OUTVIEW);
+ Initial(JET_PAGE_OUTVIEW);
- m_pTargetDoc = pDoc;
+ m_pTargetDoc = pDoc;
}
void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
{
- Initial(JET_FIELD_MOUSEENTER);
+ Initial(JET_FIELD_MOUSEENTER);
- m_bModifier = bModifier;
- m_bShift = bShift;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
}
void CJS_EventHandler::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
{
- Initial(JET_FIELD_MOUSEEXIT);
+ Initial(JET_FIELD_MOUSEEXIT);
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
}
void CJS_EventHandler::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
{
- Initial(JET_FIELD_MOUSEDOWN);
- m_eEventType = JET_FIELD_MOUSEDOWN;
+ Initial(JET_FIELD_MOUSEDOWN);
+ m_eEventType = JET_FIELD_MOUSEDOWN;
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
}
void CJS_EventHandler::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
{
- Initial(JET_FIELD_MOUSEUP);
+ Initial(JET_FIELD_MOUSEUP);
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
}
void CJS_EventHandler::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget,
- const CFX_WideString& Value)
+ const CFX_WideString& Value)
{
- Initial(JET_FIELD_FOCUS);
+ Initial(JET_FIELD_FOCUS);
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = (CFX_WideString*)&Value;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = (CFX_WideString*)&Value;
}
void CJS_EventHandler::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget,
- const CFX_WideString& Value)
+ const CFX_WideString& Value)
{
- Initial(JET_FIELD_BLUR);
+ Initial(JET_FIELD_BLUR);
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = (CFX_WideString*)&Value;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = (CFX_WideString*)&Value;
}
void CJS_EventHandler::OnField_Keystroke(CFX_WideString &strChange,
- const CFX_WideString& strChangeEx, FX_BOOL KeyDown,
- FX_BOOL bModifier, int& nSelEnd, int& nSelStart,
- FX_BOOL bShift, CPDF_FormField* pTarget,
- CFX_WideString& Value, FX_BOOL bWillCommit,
- FX_BOOL bFieldFull, FX_BOOL& bRc)
-{
- Initial(JET_FIELD_KEYSTROKE);
-
- m_nCommitKey = 0;
- m_pWideStrChange = &strChange;
- m_WideStrChangeEx = strChangeEx;
- m_bKeyDown = KeyDown;
- m_bModifier = bModifier;
- m_pISelEnd = &nSelEnd;
- m_pISelStart = &nSelStart;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = &Value;
- m_bWillCommit = bWillCommit;
- m_pbRc = &bRc;
- m_bFieldFull = bFieldFull;
+ const CFX_WideString& strChangeEx, FX_BOOL KeyDown,
+ FX_BOOL bModifier, int& nSelEnd, int& nSelStart,
+ FX_BOOL bShift, CPDF_FormField* pTarget,
+ CFX_WideString& Value, FX_BOOL bWillCommit,
+ FX_BOOL bFieldFull, FX_BOOL& bRc)
+{
+ Initial(JET_FIELD_KEYSTROKE);
+
+ m_nCommitKey = 0;
+ m_pWideStrChange = &strChange;
+ m_WideStrChangeEx = strChangeEx;
+ m_bKeyDown = KeyDown;
+ m_bModifier = bModifier;
+ m_pISelEnd = &nSelEnd;
+ m_pISelStart = &nSelStart;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = &Value;
+ m_bWillCommit = bWillCommit;
+ m_pbRc = &bRc;
+ m_bFieldFull = bFieldFull;
}
void CJS_EventHandler::OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx,
- FX_BOOL bKeyDown, FX_BOOL bModifier, FX_BOOL bShift,
- CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc)
-{
- Initial(JET_FIELD_VALIDATE);
-
- m_pWideStrChange = &strChange;
- m_WideStrChangeEx = strChangeEx;
- m_bKeyDown = bKeyDown;
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = &Value;
- m_pbRc = &bRc;
+ FX_BOOL bKeyDown, FX_BOOL bModifier, FX_BOOL bShift,
+ CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc)
+{
+ Initial(JET_FIELD_VALIDATE);
+
+ m_pWideStrChange = &strChange;
+ m_WideStrChangeEx = strChangeEx;
+ m_bKeyDown = bKeyDown;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = &Value;
+ m_pbRc = &bRc;
}
void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget,
- CFX_WideString& Value, FX_BOOL& bRc)
+ CFX_WideString& Value, FX_BOOL& bRc)
{
- Initial(JET_FIELD_CALCULATE);
+ Initial(JET_FIELD_CALCULATE);
- if (pSource)
- m_strSourceName = pSource->GetFullName();
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
+ if (pSource)
+ m_strSourceName = pSource->GetFullName();
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
m_pValue = &Value;
- m_pbRc = &bRc;
+ m_pbRc = &bRc;
}
void CJS_EventHandler::OnField_Format(CPDF_FormField* pTarget,
CFX_WideString& Value,
FX_BOOL bWillCommit)
{
- Initial(JET_FIELD_FORMAT);
+ Initial(JET_FIELD_FORMAT);
- m_nCommitKey = 0;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = &Value;
- m_bWillCommit = bWillCommit;
+ m_nCommitKey = 0;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = &Value;
+ m_bWillCommit = bWillCommit;
}
void CJS_EventHandler::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_FOCUS);
+ Initial(JET_SCREEN_FOCUS);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_BLUR);
+ Initial(JET_SCREEN_BLUR);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_OPEN);
+ Initial(JET_SCREEN_OPEN);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_CLOSE);
+ Initial(JET_SCREEN_CLOSE);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_MOUSEDOWN);
+ Initial(JET_SCREEN_MOUSEDOWN);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_MOUSEUP);
+ Initial(JET_SCREEN_MOUSEUP);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_MOUSEENTER);
+ Initial(JET_SCREEN_MOUSEENTER);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_MOUSEEXIT);
+ Initial(JET_SCREEN_MOUSEEXIT);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_INVIEW);
+ Initial(JET_SCREEN_INVIEW);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
{
- Initial(JET_SCREEN_OUTVIEW);
+ Initial(JET_SCREEN_OUTVIEW);
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
}
void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget)
{
- Initial(JET_LINK_MOUSEUP);
+ Initial(JET_LINK_MOUSEUP);
- m_pTargetDoc = pTarget;
+ m_pTargetDoc = pTarget;
}
void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
{
- Initial(JET_BOOKMARK_MOUSEUP);
+ Initial(JET_BOOKMARK_MOUSEUP);
- m_pTargetBookMark = pBookMark;
+ m_pTargetBookMark = pBookMark;
}
void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName)
{
- Initial(JET_MENU_EXEC);
+ Initial(JET_MENU_EXEC);
- m_pTargetDoc = pTarget;
- m_strTargetName = strTargetName;
+ m_pTargetDoc = pTarget;
+ m_strTargetName = strTargetName;
}
void CJS_EventHandler::OnExternal_Exec()
{
- Initial(JET_EXTERNAL_EXEC);
+ Initial(JET_EXTERNAL_EXEC);
}
void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget)
{
- Initial(JET_BATCH_EXEC);
+ Initial(JET_BATCH_EXEC);
- m_pTargetDoc = pTarget;
+ m_pTargetDoc = pTarget;
}
void CJS_EventHandler::OnConsole_Exec()
{
- Initial(JET_CONSOLE_EXEC);
+ Initial(JET_CONSOLE_EXEC);
}
void CJS_EventHandler::Initial(JS_EVENT_T type)
{
- m_eEventType = type;
-
- m_strTargetName = L"";
- m_strSourceName = L"";
- m_pWideStrChange = NULL;
- m_WideStrChangeDu = L"";
- m_WideStrChangeEx = L"";
- m_nCommitKey = -1;
- m_bKeyDown = FALSE;
- m_bModifier = FALSE;
- m_bShift = FALSE;
- m_pISelEnd = NULL;
- m_nSelEndDu = 0;
- m_pISelStart = NULL;
- m_nSelStartDu = 0;
- m_bWillCommit = FALSE;
- m_pValue = NULL;
- m_bFieldFull = FALSE;
- m_pbRc = NULL;
- m_bRcDu = FALSE;
-
- m_pSourceDoc = NULL;
- m_pTargetBookMark = NULL;
- m_pTargetDoc = NULL;
- m_pTargetAnnot = NULL;
-
- m_bValid = TRUE;
+ m_eEventType = type;
+
+ m_strTargetName = L"";
+ m_strSourceName = L"";
+ m_pWideStrChange = NULL;
+ m_WideStrChangeDu = L"";
+ m_WideStrChangeEx = L"";
+ m_nCommitKey = -1;
+ m_bKeyDown = FALSE;
+ m_bModifier = FALSE;
+ m_bShift = FALSE;
+ m_pISelEnd = NULL;
+ m_nSelEndDu = 0;
+ m_pISelStart = NULL;
+ m_nSelStartDu = 0;
+ m_bWillCommit = FALSE;
+ m_pValue = NULL;
+ m_bFieldFull = FALSE;
+ m_pbRc = NULL;
+ m_bRcDu = FALSE;
+
+ m_pSourceDoc = NULL;
+ m_pTargetBookMark = NULL;
+ m_pTargetDoc = NULL;
+ m_pTargetAnnot = NULL;
+
+ m_bValid = TRUE;
}
void CJS_EventHandler::Destroy()
{
- m_bValid = FALSE;
+ m_bValid = FALSE;
}
FX_BOOL CJS_EventHandler::IsValid()
{
- return m_bValid;
+ return m_bValid;
}
CFX_WideString & CJS_EventHandler::Change()
{
- if (m_pWideStrChange) {
- return *m_pWideStrChange;
- }
- return m_WideStrChangeDu;
+ if (m_pWideStrChange != NULL)
+ return *m_pWideStrChange;
+ else
+ {
+ return m_WideStrChangeDu;
+ }
}
CFX_WideString CJS_EventHandler::ChangeEx()
{
- return m_WideStrChangeEx;
+ return m_WideStrChangeEx;
}
int CJS_EventHandler::CommitKey()
{
- return m_nCommitKey;
+ return m_nCommitKey;
}
FX_BOOL CJS_EventHandler::FieldFull()
{
- return m_bFieldFull;
+ return m_bFieldFull;
}
FX_BOOL CJS_EventHandler::KeyDown()
{
- return m_bKeyDown;
+ return m_bKeyDown;
}
FX_BOOL CJS_EventHandler::Modifier()
{
- return m_bModifier;
+ return m_bModifier;
}
const FX_WCHAR* CJS_EventHandler::Name()
{
- switch (m_eEventType)
- {
- case JET_APP_INIT: return L"Init";
- case JET_BATCH_EXEC: return L"Exec";
- case JET_BOOKMARK_MOUSEUP: return L"Mouse Up";
- case JET_CONSOLE_EXEC: return L"Exec";
- case JET_DOC_DIDPRINT: return L"DidPrint";
- case JET_DOC_DIDSAVE: return L"DidSave";
- case JET_DOC_OPEN: return L"Open";
- case JET_DOC_WILLCLOSE: return L"WillClose";
- case JET_DOC_WILLPRINT: return L"WillPrint";
- case JET_DOC_WILLSAVE: return L"WillSave";
- case JET_EXTERNAL_EXEC: return L"Exec";
- case JET_FIELD_FOCUS:
- case JET_SCREEN_FOCUS: return L"Focus";
- case JET_FIELD_BLUR:
- case JET_SCREEN_BLUR: return L"Blur";
- case JET_FIELD_MOUSEDOWN:
- case JET_SCREEN_MOUSEDOWN: return L"Mouse Down";
- case JET_FIELD_MOUSEUP:
- case JET_SCREEN_MOUSEUP: return L"Mouse Up";
- case JET_FIELD_MOUSEENTER:
- case JET_SCREEN_MOUSEENTER: return L"Mouse Enter";
- case JET_FIELD_MOUSEEXIT:
- case JET_SCREEN_MOUSEEXIT: return L"Mouse Exit";
- case JET_FIELD_CALCULATE: return L"Calculate";
- case JET_FIELD_FORMAT: return L"Format";
- case JET_FIELD_KEYSTROKE: return L"Keystroke";
- case JET_FIELD_VALIDATE: return L"Validate";
- case JET_LINK_MOUSEUP: return L"Mouse Up";
- case JET_MENU_EXEC: return L"Exec";
- case JET_PAGE_OPEN:
- case JET_SCREEN_OPEN: return L"Open";
- case JET_PAGE_CLOSE:
- case JET_SCREEN_CLOSE: return L"Close";
- case JET_SCREEN_INVIEW:
- case JET_PAGE_INVIEW: return L"InView";
- case JET_PAGE_OUTVIEW:
- case JET_SCREEN_OUTVIEW: return L"OutView";
- default:
- return L"";
- }
-
- return L"";
+ switch (m_eEventType)
+ {
+ case JET_APP_INIT: return L"Init";
+ case JET_BATCH_EXEC: return L"Exec";
+ case JET_BOOKMARK_MOUSEUP: return L"Mouse Up";
+ case JET_CONSOLE_EXEC: return L"Exec";
+ case JET_DOC_DIDPRINT: return L"DidPrint";
+ case JET_DOC_DIDSAVE: return L"DidSave";
+ case JET_DOC_OPEN: return L"Open";
+ case JET_DOC_WILLCLOSE: return L"WillClose";
+ case JET_DOC_WILLPRINT: return L"WillPrint";
+ case JET_DOC_WILLSAVE: return L"WillSave";
+ case JET_EXTERNAL_EXEC: return L"Exec";
+ case JET_FIELD_FOCUS:
+ case JET_SCREEN_FOCUS: return L"Focus";
+ case JET_FIELD_BLUR:
+ case JET_SCREEN_BLUR: return L"Blur";
+ case JET_FIELD_MOUSEDOWN:
+ case JET_SCREEN_MOUSEDOWN: return L"Mouse Down";
+ case JET_FIELD_MOUSEUP:
+ case JET_SCREEN_MOUSEUP: return L"Mouse Up";
+ case JET_FIELD_MOUSEENTER:
+ case JET_SCREEN_MOUSEENTER: return L"Mouse Enter";
+ case JET_FIELD_MOUSEEXIT:
+ case JET_SCREEN_MOUSEEXIT: return L"Mouse Exit";
+ case JET_FIELD_CALCULATE: return L"Calculate";
+ case JET_FIELD_FORMAT: return L"Format";
+ case JET_FIELD_KEYSTROKE: return L"Keystroke";
+ case JET_FIELD_VALIDATE: return L"Validate";
+ case JET_LINK_MOUSEUP: return L"Mouse Up";
+ case JET_MENU_EXEC: return L"Exec";
+ case JET_PAGE_OPEN:
+ case JET_SCREEN_OPEN: return L"Open";
+ case JET_PAGE_CLOSE:
+ case JET_SCREEN_CLOSE: return L"Close";
+ case JET_SCREEN_INVIEW:
+ case JET_PAGE_INVIEW: return L"InView";
+ case JET_PAGE_OUTVIEW:
+ case JET_SCREEN_OUTVIEW: return L"OutView";
+ default:
+ return L"";
+ }
+
+ return L"";
}
const FX_WCHAR* CJS_EventHandler::Type()
{
- switch (m_eEventType)
- {
- case JET_APP_INIT: return L"App";
- case JET_BATCH_EXEC: return L"Batch";
- case JET_BOOKMARK_MOUSEUP: return L"BookMark";
- case JET_CONSOLE_EXEC: return L"Console";
- case JET_DOC_DIDPRINT:
- case JET_DOC_DIDSAVE:
- case JET_DOC_OPEN:
- case JET_DOC_WILLCLOSE:
- case JET_DOC_WILLPRINT:
- case JET_DOC_WILLSAVE: return L"Doc";
- case JET_EXTERNAL_EXEC: return L"External";
- case JET_FIELD_BLUR:
- case JET_FIELD_FOCUS:
- case JET_FIELD_MOUSEDOWN:
- case JET_FIELD_MOUSEENTER:
- case JET_FIELD_MOUSEEXIT:
- case JET_FIELD_MOUSEUP:
- case JET_FIELD_CALCULATE:
- case JET_FIELD_FORMAT:
- case JET_FIELD_KEYSTROKE:
- case JET_FIELD_VALIDATE: return L"Field";
- case JET_SCREEN_FOCUS:
- case JET_SCREEN_BLUR:
- case JET_SCREEN_OPEN:
- case JET_SCREEN_CLOSE:
- case JET_SCREEN_MOUSEDOWN:
- case JET_SCREEN_MOUSEUP:
- case JET_SCREEN_MOUSEENTER:
- case JET_SCREEN_MOUSEEXIT:
- case JET_SCREEN_INVIEW:
- case JET_SCREEN_OUTVIEW: return L"Screen";
- case JET_LINK_MOUSEUP: return L"Link";
- case JET_MENU_EXEC: return L"Menu";
- case JET_PAGE_OPEN:
- case JET_PAGE_CLOSE:
- case JET_PAGE_INVIEW:
- case JET_PAGE_OUTVIEW:return L"Page";
- default:
- return L"";
- }
-
- return L"";
+ switch (m_eEventType)
+ {
+ case JET_APP_INIT: return L"App";
+ case JET_BATCH_EXEC: return L"Batch";
+ case JET_BOOKMARK_MOUSEUP: return L"BookMark";
+ case JET_CONSOLE_EXEC: return L"Console";
+ case JET_DOC_DIDPRINT:
+ case JET_DOC_DIDSAVE:
+ case JET_DOC_OPEN:
+ case JET_DOC_WILLCLOSE:
+ case JET_DOC_WILLPRINT:
+ case JET_DOC_WILLSAVE: return L"Doc";
+ case JET_EXTERNAL_EXEC: return L"External";
+ case JET_FIELD_BLUR:
+ case JET_FIELD_FOCUS:
+ case JET_FIELD_MOUSEDOWN:
+ case JET_FIELD_MOUSEENTER:
+ case JET_FIELD_MOUSEEXIT:
+ case JET_FIELD_MOUSEUP:
+ case JET_FIELD_CALCULATE:
+ case JET_FIELD_FORMAT:
+ case JET_FIELD_KEYSTROKE:
+ case JET_FIELD_VALIDATE: return L"Field";
+ case JET_SCREEN_FOCUS:
+ case JET_SCREEN_BLUR:
+ case JET_SCREEN_OPEN:
+ case JET_SCREEN_CLOSE:
+ case JET_SCREEN_MOUSEDOWN:
+ case JET_SCREEN_MOUSEUP:
+ case JET_SCREEN_MOUSEENTER:
+ case JET_SCREEN_MOUSEEXIT:
+ case JET_SCREEN_INVIEW:
+ case JET_SCREEN_OUTVIEW: return L"Screen";
+ case JET_LINK_MOUSEUP: return L"Link";
+ case JET_MENU_EXEC: return L"Menu";
+ case JET_PAGE_OPEN:
+ case JET_PAGE_CLOSE:
+ case JET_PAGE_INVIEW:
+ case JET_PAGE_OUTVIEW:return L"Page";
+ default:
+ return L"";
+ }
+
+ return L"";
}
FX_BOOL& CJS_EventHandler::Rc()
{
- if (m_pbRc) {
- return *m_pbRc;
- }
- return m_bRcDu;
+ if (m_pbRc != NULL)
+ return *m_pbRc;
+ else
+ {
+ return m_bRcDu;
+ }
}
int & CJS_EventHandler::SelEnd()
{
- if (m_pISelEnd) {
- return *m_pISelEnd;
- }
- return m_nSelEndDu;
+ if (m_pISelEnd != NULL)
+ {
+ return *m_pISelEnd;
+ }
+ else
+ {
+ return m_nSelEndDu;
+ }
}
int & CJS_EventHandler::SelStart()
{
- if (m_pISelStart) {
- return *m_pISelStart;
- }
- return m_nSelStartDu;
+ if (m_pISelStart != NULL)
+ return * m_pISelStart;
+ else
+ {
+ return m_nSelStartDu;
+ }
}
FX_BOOL CJS_EventHandler::Shift()
{
- return m_bShift;
+ return m_bShift;
}
Field* CJS_EventHandler::Source()
{
- ASSERT(m_pJSContext != NULL);
-
- CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
-
- JSFXObject pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
- ASSERT(pDocObj.IsEmpty() == FALSE);
- JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
- ASSERT(pFieldObj.IsEmpty() == FALSE);
-
- CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
- ASSERT(pJSDocument != NULL);
- Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
- ASSERT(pDocument != NULL);
- if (m_pTargetDoc != NULL)
- pDocument->AttachDoc(m_pTargetDoc);
- else
- pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
-
- //if (m_pSourceField == NULL)
- // return NULL;
- //CRAO_Widget *pWidget = IBCL_Widget::GetWidget(m_pSourceField);
- //CPDF_FormField* pFormField = pWidget->GetFormField();
- //ASSERT(pFormField);
- //CFX_WideString csFieldName = pFormField->GetFullName();
- CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
- ASSERT(pJSField != NULL);
- Field * pField = (Field *)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
- pField->AttachField(pDocument, m_strSourceName);
- return pField;
+ ASSERT(m_pJSContext != NULL);
+
+ CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
+
+ JSFXObject pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
+ ASSERT(pDocObj.IsEmpty() == FALSE);
+ JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
+ ASSERT(pFieldObj.IsEmpty() == FALSE);
+
+ CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
+ ASSERT(pJSDocument != NULL);
+ Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
+ ASSERT(pDocument != NULL);
+ if (m_pTargetDoc != NULL)
+ pDocument->AttachDoc(m_pTargetDoc);
+ else
+ pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
+
+ //if (m_pSourceField == NULL)
+ // return NULL;
+ //CRAO_Widget *pWidget = IBCL_Widget::GetWidget(m_pSourceField);
+ //CPDF_FormField* pFormField = pWidget->GetFormField();
+ //ASSERT(pFormField);
+ //CFX_WideString csFieldName = pFormField->GetFullName();
+ CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
+ ASSERT(pJSField != NULL);
+ Field * pField = (Field *)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
+ pField->AttachField(pDocument, m_strSourceName);
+ return pField;
}
Field* CJS_EventHandler::Target_Field()
{
- ASSERT(m_pJSContext != NULL);
+ ASSERT(m_pJSContext != NULL);
- CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
+ CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
- JSFXObject pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
- ASSERT(pDocObj.IsEmpty() == FALSE);
- JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
- ASSERT(pFieldObj.IsEmpty() == FALSE);
+ JSFXObject pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
+ ASSERT(pDocObj.IsEmpty() == FALSE);
+ JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
+ ASSERT(pFieldObj.IsEmpty() == FALSE);
- CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
- ASSERT(pJSDocument != NULL);
- Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
- ASSERT(pDocument != NULL);
- if (m_pTargetDoc != NULL)
- pDocument->AttachDoc(m_pTargetDoc);
- else
- pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
+ CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
+ ASSERT(pJSDocument != NULL);
+ Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
+ ASSERT(pDocument != NULL);
+ if (m_pTargetDoc != NULL)
+ pDocument->AttachDoc(m_pTargetDoc);
+ else
+ pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
- CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
- ASSERT(pJSField != NULL);
+ CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
+ ASSERT(pJSField != NULL);
- Field* pField = (Field *)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
+ Field* pField = (Field *)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
- pField->AttachField(pDocument, m_strTargetName);
- return pField;
+ pField->AttachField(pDocument, m_strTargetName);
+ return pField;
}
CFX_WideString& CJS_EventHandler::Value()
{
- return *m_pValue;
+ return *m_pValue;
}
FX_BOOL CJS_EventHandler::WillCommit()
{
- return m_bWillCommit;
+ return m_bWillCommit;
}
CFX_WideString CJS_EventHandler::TargetName()
{
- return m_strTargetName;
+ return m_strTargetName;
}
+
+
diff --git a/fpdfsdk/src/javascript/JS_GlobalData.cpp b/fpdfsdk/src/javascript/JS_GlobalData.cpp
index 8c7bd7150e..2ba5c3bca5 100644
--- a/fpdfsdk/src/javascript/JS_GlobalData.cpp
+++ b/fpdfsdk/src/javascript/JS_GlobalData.cpp
@@ -9,7 +9,7 @@
#include "../../include/javascript/IJavaScript.h"
#include "../../include/javascript/JS_GlobalData.h"
-#define JS_MAXGLOBALDATA (1024 * 4 - 8)
+#define JS_MAXGLOBALDATA (1024 * 4 - 8)
/* --------------------- CJS_GlobalVariableArray --------------------- */
@@ -19,495 +19,497 @@ CJS_GlobalVariableArray::CJS_GlobalVariableArray()
CJS_GlobalVariableArray::~CJS_GlobalVariableArray()
{
- Empty();
+ Empty();
}
void CJS_GlobalVariableArray::Copy(const CJS_GlobalVariableArray& array)
{
- Empty();
- for (int i=0,sz=array.Count(); i<sz; i++)
- {
- CJS_KeyValue* pOldObjData = array.GetAt(i);
- ASSERT(pOldObjData != NULL);
-
- switch (pOldObjData->nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- pNewObjData->dData = pOldObjData->dData;
- Add(pNewObjData);
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- pNewObjData->bData = pOldObjData->bData;
- Add(pNewObjData);
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- pNewObjData->sData = pOldObjData->sData;
- Add(pNewObjData);
- }
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- pNewObjData->objData.Copy(pOldObjData->objData);
- Add(pNewObjData);
- }
- case JS_GLOBALDATA_TYPE_NULL:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- Add(pNewObjData);
- }
- }
- }
+ Empty();
+ for (int i=0,sz=array.Count(); i<sz; i++)
+ {
+ CJS_KeyValue* pOldObjData = array.GetAt(i);
+ ASSERT(pOldObjData != NULL);
+
+ switch (pOldObjData->nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ pNewObjData->dData = pOldObjData->dData;
+ Add(pNewObjData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ pNewObjData->bData = pOldObjData->bData;
+ Add(pNewObjData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ pNewObjData->sData = pOldObjData->sData;
+ Add(pNewObjData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ pNewObjData->objData.Copy(pOldObjData->objData);
+ Add(pNewObjData);
+ }
+ case JS_GLOBALDATA_TYPE_NULL:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ Add(pNewObjData);
+ }
+ }
+ }
}
void CJS_GlobalVariableArray::Add(CJS_KeyValue* p)
{
- array.Add(p);
+ array.Add(p);
}
int CJS_GlobalVariableArray::Count() const
{
- return array.GetSize();
+ return array.GetSize();
}
CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const
{
- return array.GetAt(index);
+ return array.GetAt(index);
}
void CJS_GlobalVariableArray::Empty()
{
- for (int i=0,sz=array.GetSize(); i<sz; i++)
- delete array.GetAt(i);
- array.RemoveAll();
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ delete array.GetAt(i);
+ array.RemoveAll();
}
/* -------------------------- CJS_GlobalData -------------------------- */
-#define READER_JS_GLOBALDATA_FILENAME L"Reader_JsGlobal.Data"
-#define PHANTOM_JS_GLOBALDATA_FILENAME L"Phantom_JsGlobal.Data"
-#define SDK_JS_GLOBALDATA_FILENAME L"SDK_JsGlobal.Data"
+#define READER_JS_GLOBALDATA_FILENAME L"Reader_JsGlobal.Data"
+#define PHANTOM_JS_GLOBALDATA_FILENAME L"Phantom_JsGlobal.Data"
+#define SDK_JS_GLOBALDATA_FILENAME L"SDK_JsGlobal.Data"
static const uint8_t JS_RC4KEY[] = {0x19,0xa8,0xe8,0x01,0xf6,0xa8,0xb6,0x4d,0x82,0x04,
- 0x45,0x6d,0xb4,0xcf,0xd7,0x77,0x67,0xf9,0x75,0x9f,
- 0xf0,0xe0,0x1e,0x51,0xee,0x46,0xfd,0x0b,0xc9,0x93,
- 0x25,0x55,0x4a,0xee,0xe0,0x16,0xd0,0xdf,0x8c,0xfa,
- 0x2a,0xa9,0x49,0xfd,0x97,0x1c,0x0e,0x22,0x13,0x28,
- 0x7c,0xaf,0xc4,0xfc,0x9c,0x12,0x65,0x8c,0x4e,0x5b,
- 0x04,0x75,0x89,0xc9,0xb1,0xed,0x50,0xca,0x96,0x6f,
- 0x1a,0x7a,0xfe,0x58,0x5d,0xec,0x19,0x4a,0xf6,0x35,
- 0x6a,0x97,0x14,0x00,0x0e,0xd0,0x6b,0xbb,0xd5,0x75,
- 0x55,0x8b,0x6e,0x6b,0x19,0xa0,0xf8,0x77,0xd5,0xa3
- };
+ 0x45,0x6d,0xb4,0xcf,0xd7,0x77,0x67,0xf9,0x75,0x9f,
+ 0xf0,0xe0,0x1e,0x51,0xee,0x46,0xfd,0x0b,0xc9,0x93,
+ 0x25,0x55,0x4a,0xee,0xe0,0x16,0xd0,0xdf,0x8c,0xfa,
+ 0x2a,0xa9,0x49,0xfd,0x97,0x1c,0x0e,0x22,0x13,0x28,
+ 0x7c,0xaf,0xc4,0xfc,0x9c,0x12,0x65,0x8c,0x4e,0x5b,
+ 0x04,0x75,0x89,0xc9,0xb1,0xed,0x50,0xca,0x96,0x6f,
+ 0x1a,0x7a,0xfe,0x58,0x5d,0xec,0x19,0x4a,0xf6,0x35,
+ 0x6a,0x97,0x14,0x00,0x0e,0xd0,0x6b,0xbb,0xd5,0x75,
+ 0x55,0x8b,0x6e,0x6b,0x19,0xa0,0xf8,0x77,0xd5,0xa3
+ };
CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp)
{
-// IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp);
-// ASSERT(pBaseAnnot != NULL);
+// IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp);
+// ASSERT(pBaseAnnot != NULL);
//
-// m_sFilePath = pBaseAnnot->GetUserPath();
- m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
+// m_sFilePath = pBaseAnnot->GetUserPath();
+ m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
- LoadGlobalPersistentVariables();
+ LoadGlobalPersistentVariables();
}
CJS_GlobalData::~CJS_GlobalData()
{
- SaveGlobalPersisitentVariables();
+ SaveGlobalPersisitentVariables();
- for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
- delete m_arrayGlobalData.GetAt(i);
+ for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
+ delete m_arrayGlobalData.GetAt(i);
- m_arrayGlobalData.RemoveAll();
+ m_arrayGlobalData.RemoveAll();
}
-int CJS_GlobalData::FindGlobalVariable(const FX_CHAR* propname)
+int CJS_GlobalData::FindGlobalVariable(const FX_CHAR* propname)
{
- ASSERT(propname != NULL);
+ ASSERT(propname != NULL);
- int nRet = -1;
+ int nRet = -1;
- for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
- {
- CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i);
- if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname)
- {
- nRet = i;
- break;
- }
- }
+ for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
+ {
+ CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i);
+ if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname)
+ {
+ nRet = i;
+ break;
+ }
+ }
- return nRet;
+ return nRet;
}
CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(const FX_CHAR* propname)
{
- ASSERT(propname != NULL);
+ ASSERT(propname != NULL);
- int nFind = FindGlobalVariable(propname);
- if (nFind >= 0)
- return m_arrayGlobalData.GetAt(nFind);
+ int nFind = FindGlobalVariable(propname);
- return NULL;
+ if (nFind >= 0)
+ return m_arrayGlobalData.GetAt(nFind);
+ else
+ return NULL;
}
void CJS_GlobalData::SetGlobalVariableNumber(const FX_CHAR* propname, double dData)
{
- ASSERT(propname != NULL);
-
- CFX_ByteString sPropName = propname;
- sPropName.TrimLeft();
- sPropName.TrimRight();
- if (sPropName.GetLength() == 0)
- return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
- pData->data.dData = dData;
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
- pNewData->data.dData = dData;
- m_arrayGlobalData.Add(pNewData);
- }
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
+ pData->data.dData = dData;
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
+ pNewData->data.dData = dData;
+
+ m_arrayGlobalData.Add(pNewData);
+ }
}
void CJS_GlobalData::SetGlobalVariableBoolean(const FX_CHAR* propname, bool bData)
{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
- pData->data.bData = bData;
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
- pNewData->data.bData = bData;
-
- m_arrayGlobalData.Add(pNewData);
- }
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
+ pData->data.bData = bData;
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
+ pNewData->data.bData = bData;
+
+ m_arrayGlobalData.Add(pNewData);
+ }
}
void CJS_GlobalData::SetGlobalVariableString(const FX_CHAR* propname, const CFX_ByteString& sData)
{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_STRING;
- pData->data.sData = sData;
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_STRING;
- pNewData->data.sData = sData;
-
- m_arrayGlobalData.Add(pNewData);
- }
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_STRING;
+ pData->data.sData = sData;
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_STRING;
+ pNewData->data.sData = sData;
+
+ m_arrayGlobalData.Add(pNewData);
+ }
}
void CJS_GlobalData::SetGlobalVariableObject(const FX_CHAR* propname, const CJS_GlobalVariableArray& array)
{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
- pData->data.objData.Copy(array);
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
- pNewData->data.objData.Copy(array);
-
- m_arrayGlobalData.Add(pNewData);
- }
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
+ pData->data.objData.Copy(array);
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
+ pNewData->data.objData.Copy(array);
+
+ m_arrayGlobalData.Add(pNewData);
+ }
}
void CJS_GlobalData::SetGlobalVariableNull(const FX_CHAR* propname)
{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_NULL;
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_NULL;
-
- m_arrayGlobalData.Add(pNewData);
- }
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_NULL;
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_NULL;
+
+ m_arrayGlobalData.Add(pNewData);
+ }
}
FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(const FX_CHAR* propname, FX_BOOL bPersistent)
{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
- sPropName.TrimLeft();
- sPropName.TrimRight();
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
- if (sPropName.GetLength() == 0) return FALSE;
+ if (sPropName.GetLength() == 0) return FALSE;
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->bPersistent = bPersistent;
- return TRUE;
- }
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->bPersistent = bPersistent;
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
FX_BOOL CJS_GlobalData::DeleteGlobalVariable(const FX_CHAR* propname)
{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
- sPropName.TrimLeft();
- sPropName.TrimRight();
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
- if (sPropName.GetLength() == 0) return FALSE;
+ if (sPropName.GetLength() == 0) return FALSE;
- int nFind = FindGlobalVariable(sPropName);
+ int nFind = FindGlobalVariable(sPropName);
- if (nFind >= 0)
- {
- delete m_arrayGlobalData.GetAt(nFind);
- m_arrayGlobalData.RemoveAt(nFind);
- return TRUE;
- }
+ if (nFind >= 0)
+ {
+ delete m_arrayGlobalData.GetAt(nFind);
+ m_arrayGlobalData.RemoveAt(nFind);
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
int32_t CJS_GlobalData::GetSize() const
{
- return m_arrayGlobalData.GetSize();
+ return m_arrayGlobalData.GetSize();
}
CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const
{
- return m_arrayGlobalData.GetAt(index);
+ return m_arrayGlobalData.GetAt(index);
}
void CJS_GlobalData::LoadGlobalPersistentVariables()
{
- uint8_t* pBuffer = NULL;
- int32_t nLength = 0;
-
- LoadFileBuffer(m_sFilePath.c_str(), pBuffer, nLength);
- CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY));
-
- if (pBuffer)
- {
- uint8_t* p = pBuffer;
- FX_WORD wType = *((FX_WORD*)p);
- p += sizeof(FX_WORD);
-
- //FX_WORD wTemp = (FX_WORD)(('X' << 8) | 'F');
-
- if (wType == (FX_WORD)(('X' << 8) | 'F'))
- {
- FX_WORD wVersion = *((FX_WORD*)p);
- p += sizeof(FX_WORD);
-
- ASSERT(wVersion <= 2);
-
- FX_DWORD dwCount = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
-
- FX_DWORD dwSize = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
-
- if (dwSize == nLength - sizeof(FX_WORD) * 2 - sizeof(FX_DWORD)* 2)
- {
- for (int32_t i=0,sz=dwCount; i<sz; i++)
- {
- if (p > pBuffer + nLength)
- break;
-
- FX_DWORD dwNameLen = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
-
- if (p + dwNameLen > pBuffer + nLength)
- break;
-
- CFX_ByteString sEntry = CFX_ByteString(p, dwNameLen);
- p += sizeof(char) * dwNameLen;
-
- FX_WORD wDataType = *((FX_WORD*)p);
- p += sizeof(FX_WORD);
-
- switch (wDataType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- double dData = 0;
- switch (wVersion)
- {
- case 1:
- {
- FX_DWORD dwData = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
- dData = dwData;
- }
- break;
- case 2:
- {
- dData = *((double*)p);
- p += sizeof(double);
- }
- break;
- }
- SetGlobalVariableNumber(sEntry, dData);
- SetGlobalVariablePersistent(sEntry, TRUE);
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- FX_WORD wData = *((FX_WORD*)p);
- p += sizeof(FX_WORD);
- SetGlobalVariableBoolean(sEntry, (bool)(wData == 1));
- SetGlobalVariablePersistent(sEntry, TRUE);
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- FX_DWORD dwLength = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
-
- if (p + dwLength > pBuffer + nLength)
- break;
-
- SetGlobalVariableString(sEntry, CFX_ByteString(p, dwLength));
- SetGlobalVariablePersistent(sEntry, TRUE);
- p += sizeof(char) * dwLength;
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- {
- SetGlobalVariableNull(sEntry);
- SetGlobalVariablePersistent(sEntry, TRUE);
- }
- }
- }
- }
- }
- FX_Free(pBuffer);
- }
+ uint8_t* pBuffer = NULL;
+ int32_t nLength = 0;
+
+ LoadFileBuffer(m_sFilePath.c_str(), pBuffer, nLength);
+ CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY));
+
+ if (pBuffer)
+ {
+ uint8_t* p = pBuffer;
+ FX_WORD wType = *((FX_WORD*)p);
+ p += sizeof(FX_WORD);
+
+ //FX_WORD wTemp = (FX_WORD)(('X' << 8) | 'F');
+
+ if (wType == (FX_WORD)(('X' << 8) | 'F'))
+ {
+ FX_WORD wVersion = *((FX_WORD*)p);
+ p += sizeof(FX_WORD);
+
+ ASSERT(wVersion <= 2);
+
+ FX_DWORD dwCount = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+
+ FX_DWORD dwSize = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+
+ if (dwSize == nLength - sizeof(FX_WORD) * 2 - sizeof(FX_DWORD)* 2)
+ {
+ for (int32_t i=0,sz=dwCount; i<sz; i++)
+ {
+ if (p > pBuffer + nLength)
+ break;
+
+ FX_DWORD dwNameLen = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+
+ if (p + dwNameLen > pBuffer + nLength)
+ break;
+
+ CFX_ByteString sEntry = CFX_ByteString(p, dwNameLen);
+ p += sizeof(char) * dwNameLen;
+
+ FX_WORD wDataType = *((FX_WORD*)p);
+ p += sizeof(FX_WORD);
+
+ switch (wDataType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ double dData = 0;
+ switch (wVersion)
+ {
+ case 1:
+ {
+ FX_DWORD dwData = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+ dData = dwData;
+ }
+ break;
+ case 2:
+ {
+ dData = *((double*)p);
+ p += sizeof(double);
+ }
+ break;
+ }
+ SetGlobalVariableNumber(sEntry, dData);
+ SetGlobalVariablePersistent(sEntry, TRUE);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ FX_WORD wData = *((FX_WORD*)p);
+ p += sizeof(FX_WORD);
+ SetGlobalVariableBoolean(sEntry, (bool)(wData == 1));
+ SetGlobalVariablePersistent(sEntry, TRUE);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ FX_DWORD dwLength = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+
+ if (p + dwLength > pBuffer + nLength)
+ break;
+
+ SetGlobalVariableString(sEntry, CFX_ByteString(p, dwLength));
+ SetGlobalVariablePersistent(sEntry, TRUE);
+ p += sizeof(char) * dwLength;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ {
+ SetGlobalVariableNull(sEntry);
+ SetGlobalVariablePersistent(sEntry, TRUE);
+ }
+ }
+ }
+ }
+ }
+ FX_Free(pBuffer);
+ }
}
/*
struct js_global_datafile_header
{
- FX_WORD type; //FX ('X' << 8) | 'F'
- FX_WORD version; //1.0
- FX_DWORD datacount;
+ FX_WORD type; //FX ('X' << 8) | 'F'
+ FX_WORD version; //1.0
+ FX_DWORD datacount;
};
struct js_global_datafile_data
{
- FX_WORD type;
- FX_DWORD nData;
- FX_WORD bData;
- FX_DWORD nStrLen;
- char* pStr;
+ FX_WORD type;
+ FX_DWORD nData;
+ FX_WORD bData;
+ FX_DWORD nStrLen;
+ char* pStr;
};
*/
void CJS_GlobalData::SaveGlobalPersisitentVariables()
{
- FX_DWORD nCount = 0;
- CFX_BinaryBuf sData;
+ FX_DWORD nCount = 0;
+ CFX_BinaryBuf sData;
- for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
- {
- CJS_GlobalData_Element* pElement = m_arrayGlobalData.GetAt(i);
- ASSERT(pElement != NULL);
+ for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
+ {
+ CJS_GlobalData_Element* pElement = m_arrayGlobalData.GetAt(i);
+ ASSERT(pElement != NULL);
- if (pElement->bPersistent)
- {
- CFX_BinaryBuf sElement;
- MakeByteString(pElement->data.sKey, &pElement->data, sElement);
+ if (pElement->bPersistent)
+ {
+ CFX_BinaryBuf sElement;
+ MakeByteString(pElement->data.sKey, &pElement->data, sElement);
- if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA)
- break;
+ if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA)
+ break;
- sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize());
- nCount++;
- }
- }
+ sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize());
+ nCount++;
+ }
+ }
- CFX_BinaryBuf sFile;
+ CFX_BinaryBuf sFile;
- FX_WORD wType = (FX_WORD)(('X' << 8) | 'F');
- sFile.AppendBlock(&wType, sizeof(FX_WORD));
- FX_WORD wVersion = 2;
- sFile.AppendBlock(&wVersion, sizeof(FX_WORD));
- sFile.AppendBlock(&nCount, sizeof(FX_DWORD));
- FX_DWORD dwSize = sData.GetSize();
- sFile.AppendBlock(&dwSize, sizeof(FX_DWORD));
+ FX_WORD wType = (FX_WORD)(('X' << 8) | 'F');
+ sFile.AppendBlock(&wType, sizeof(FX_WORD));
+ FX_WORD wVersion = 2;
+ sFile.AppendBlock(&wVersion, sizeof(FX_WORD));
+ sFile.AppendBlock(&nCount, sizeof(FX_DWORD));
+ FX_DWORD dwSize = sData.GetSize();
+ sFile.AppendBlock(&dwSize, sizeof(FX_DWORD));
- sFile.AppendBlock(sData.GetBuffer(), sData.GetSize());
+ sFile.AppendBlock(sData.GetBuffer(), sData.GetSize());
- CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY, sizeof(JS_RC4KEY));
- WriteFileBuffer(m_sFilePath.c_str(), (const FX_CHAR*)sFile.GetBuffer(), sFile.GetSize());
+ CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY, sizeof(JS_RC4KEY));
+ WriteFileBuffer(m_sFilePath.c_str(), (const FX_CHAR*)sFile.GetBuffer(), sFile.GetSize());
}
void CJS_GlobalData::LoadFileBuffer(const FX_WCHAR* sFilePath, uint8_t*& pBuffer, int32_t& nLength)
@@ -522,53 +524,58 @@ void CJS_GlobalData::WriteFileBuffer(const FX_WCHAR* sFilePath, const FX_CHAR* p
void CJS_GlobalData::MakeByteString(const CFX_ByteString& name, CJS_KeyValue* pData, CFX_BinaryBuf& sData)
{
- FX_WORD wType = (FX_WORD)pData->nType;
- switch (wType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
- sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
- sData.AppendString(name);
- sData.AppendBlock(&wType, sizeof(FX_WORD));
-
- double dData = pData->dData;
- sData.AppendBlock(&dData, sizeof(double));
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
- sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
- sData.AppendString(name);
- sData.AppendBlock(&wType, sizeof(FX_WORD));
-
- FX_WORD wData = (FX_WORD)pData->bData;
- sData.AppendBlock(&wData, sizeof(FX_WORD));
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
- sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
- sData.AppendString(name);
- sData.AppendBlock(&wType, sizeof(FX_WORD));
-
- FX_DWORD dwDataLen = (FX_DWORD)pData->sData.GetLength();
- sData.AppendBlock(&dwDataLen, sizeof(FX_DWORD));
- sData.AppendString(pData->sData);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- {
- FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
- sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
- sData.AppendString(name);
- sData.AppendBlock(&wType, sizeof(FX_DWORD));
- }
- break;
- default:
- break;
- }
+ ASSERT(pData != NULL);
+
+ FX_WORD wType = (FX_WORD)pData->nType;
+
+ switch (wType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
+ sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
+ sData.AppendString(name);
+
+ sData.AppendBlock(&wType, sizeof(FX_WORD));
+ double dData = pData->dData;
+ sData.AppendBlock(&dData, sizeof(double));
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
+ sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
+ sData.AppendString(name);
+
+ sData.AppendBlock(&wType, sizeof(FX_WORD));
+ FX_WORD wData = (FX_WORD)pData->bData;
+ sData.AppendBlock(&wData, sizeof(FX_WORD));
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
+ sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
+ sData.AppendString(name);
+
+ sData.AppendBlock(&wType, sizeof(FX_WORD));
+
+ FX_DWORD dwDataLen = (FX_DWORD)pData->sData.GetLength();
+ sData.AppendBlock(&dwDataLen, sizeof(FX_DWORD));
+ sData.AppendString(pData->sData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ {
+ FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
+ sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
+ sData.AppendString(name);
+
+ sData.AppendBlock(&wType, sizeof(FX_DWORD));
+ }
+ break;
+ default:
+ break;
+ }
}
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 485cd27813..34a451b0ee 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -31,64 +31,67 @@ CJS_RuntimeFactory::~CJS_RuntimeFactory()
{
}
-IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
+IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
{
- if (!m_bInit)
- {
- unsigned int embedderDataSlot = 0;
- if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
- embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot;
+ if (!m_bInit)
+ {
+ unsigned int embedderDataSlot = 0;
+ if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
+ embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot;
}
- JS_Initial(embedderDataSlot);
- m_bInit = TRUE;
- }
- return new CJS_Runtime(pApp);
+ JS_Initial(embedderDataSlot);
+ m_bInit = TRUE;
+ }
+ return new CJS_Runtime(pApp);
}
-void CJS_RuntimeFactory::AddRef()
+void CJS_RuntimeFactory::AddRef()
{
- //to do.Should be implemented as atom manipulation.
- m_nRef++;
+ //to do.Should be implemented as atom manipulation.
+ m_nRef++;
}
-void CJS_RuntimeFactory::Release()
+void CJS_RuntimeFactory::Release()
{
- if(m_bInit)
- {
- //to do.Should be implemented as atom manipulation.
- if (--m_nRef == 0)
- {
- JS_Release();
- ReleaseGlobalData();
- m_bInit = FALSE;
- }
- }
+ if(m_bInit)
+ {
+ //to do.Should be implemented as atom manipulation.
+ if (--m_nRef == 0)
+ {
+ JS_Release();
+ ReleaseGlobalData();
+ m_bInit = FALSE;
+ }
+ }
}
-void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime)
+void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime)
{
delete (CJS_Runtime*)pRuntime;
}
-CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
+CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
{
- if (m_pGlobalData)
- {
- m_nGlobalDataCount++;
- return m_pGlobalData;
- }
- m_nGlobalDataCount = 1;
- m_pGlobalData = new CJS_GlobalData(pApp);
- return m_pGlobalData;
+ if (m_pGlobalData)
+ {
+ m_nGlobalDataCount++;
+ return m_pGlobalData;
+ }
+ else
+ {
+ m_nGlobalDataCount = 1;
+ m_pGlobalData = new CJS_GlobalData(pApp);
+ return m_pGlobalData;
+ }
}
void CJS_RuntimeFactory::ReleaseGlobalData()
{
- m_nGlobalDataCount--;
+ m_nGlobalDataCount--;
- if (m_nGlobalDataCount <= 0)
- {
- delete m_pGlobalData;
- m_pGlobalData = NULL;
- }
+ if (m_nGlobalDataCount <= 0)
+ {
+ delete m_pGlobalData;
+ m_pGlobalData = NULL;
+ }
}
void* CJS_ArrayBufferAllocator::Allocate(size_t length) {
@@ -110,237 +113,237 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
m_pDocument(NULL),
m_bBlocking(FALSE),
m_pFieldEventPath(NULL),
- m_isolate(NULL)
+ m_isolate(NULL)
{
- if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
- m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate);
- }
- if (!m_isolate) {
- m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator());
-
- v8::Isolate::CreateParams params;
- params.array_buffer_allocator = m_pArrayBufferAllocator.get();
- m_isolate = v8::Isolate::New(params);
+ if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
+ m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate);
+ }
+ if (!m_isolate) {
+ m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator());
+
+ v8::Isolate::CreateParams params;
+ params.array_buffer_allocator = m_pArrayBufferAllocator.get();
+ m_isolate = v8::Isolate::New(params);
}
- InitJSObjects();
+ InitJSObjects();
- CJS_Context * pContext = (CJS_Context*)NewContext();
- JS_InitialRuntime(*this, this, pContext, m_context);
- ReleaseContext(pContext);
+ CJS_Context * pContext = (CJS_Context*)NewContext();
+ JS_InitialRuntime(*this, this, pContext, m_context);
+ ReleaseContext(pContext);
}
CJS_Runtime::~CJS_Runtime()
{
- for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
- delete m_ContextArray.GetAt(i);
+ for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
+ delete m_ContextArray.GetAt(i);
- m_ContextArray.RemoveAll();
+ m_ContextArray.RemoveAll();
- JS_ReleaseRuntime(*this, m_context);
+ JS_ReleaseRuntime(*this, m_context);
- RemoveEventsInLoop(m_pFieldEventPath);
+ RemoveEventsInLoop(m_pFieldEventPath);
- m_pApp = NULL;
- m_pDocument = NULL;
- m_pFieldEventPath = NULL;
- m_context.Reset();
+ m_pApp = NULL;
+ m_pDocument = NULL;
+ m_pFieldEventPath = NULL;
+ m_context.Reset();
- //m_isolate->Exit();
- m_isolate->Dispose();
+ //m_isolate->Exit();
+ m_isolate->Dispose();
}
FX_BOOL CJS_Runtime::InitJSObjects()
{
- v8::Isolate::Scope isolate_scope(GetIsolate());
- v8::HandleScope handle_scope(GetIsolate());
- v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
- v8::Context::Scope context_scope(context);
- //0 - 8
- if (CJS_Border::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Display::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Font::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Position::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Style::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return FALSE;
-
- //9 - 11
- if (CJS_App::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Color::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Console::Init(*this, JS_STATIC) < 0) return FALSE;
-
- //12 - 14
- if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return FALSE;
- if (CJS_Event::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return FALSE;
-
- //15 - 17
- if (CJS_Global::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return FALSE;
- if (CJS_Util::Init(*this, JS_STATIC) < 0) return FALSE;
-
- if (CJS_PublicMethods::Init(*this) < 0) return FALSE;
- if (CJS_GlobalConsts::Init(*this) < 0) return FALSE;
- if (CJS_GlobalArrays::Init(*this) < 0) return FALSE;
-
- if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return FALSE;
- if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return FALSE;
-
- return TRUE;
+ v8::Isolate::Scope isolate_scope(GetIsolate());
+ v8::HandleScope handle_scope(GetIsolate());
+ v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
+ v8::Context::Scope context_scope(context);
+ //0 - 8
+ if (CJS_Border::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Display::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Font::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Position::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Style::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return FALSE;
+
+ //9 - 11
+ if (CJS_App::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Color::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Console::Init(*this, JS_STATIC) < 0) return FALSE;
+
+ //12 - 14
+ if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return FALSE;
+ if (CJS_Event::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return FALSE;
+
+ //15 - 17
+ if (CJS_Global::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return FALSE;
+ if (CJS_Util::Init(*this, JS_STATIC) < 0) return FALSE;
+
+ if (CJS_PublicMethods::Init(*this) < 0) return FALSE;
+ if (CJS_GlobalConsts::Init(*this) < 0) return FALSE;
+ if (CJS_GlobalArrays::Init(*this) < 0) return FALSE;
+
+ if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return FALSE;
+ if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return FALSE;
+
+ return TRUE;
}
IFXJS_Context* CJS_Runtime::NewContext()
{
- CJS_Context * p = new CJS_Context(this);
- m_ContextArray.Add(p);
- return p;
+ CJS_Context * p = new CJS_Context(this);
+ m_ContextArray.Add(p);
+ return p;
}
void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext)
{
- CJS_Context* pJSContext = (CJS_Context*)pContext;
-
- for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
- {
- if (pJSContext == m_ContextArray.GetAt(i))
- {
- delete pJSContext;
- m_ContextArray.RemoveAt(i);
- break;
- }
- }
+ CJS_Context* pJSContext = (CJS_Context*)pContext;
+
+ for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
+ {
+ if (pJSContext == m_ContextArray.GetAt(i))
+ {
+ delete pJSContext;
+ m_ContextArray.RemoveAt(i);
+ break;
+ }
+ }
}
-IFXJS_Context* CJS_Runtime::GetCurrentContext()
+IFXJS_Context* CJS_Runtime::GetCurrentContext()
{
- if(!m_ContextArray.GetSize())
- return NULL;
- return m_ContextArray.GetAt(m_ContextArray.GetSize()-1);
+ if(!m_ContextArray.GetSize())
+ return NULL;
+ return m_ContextArray.GetAt(m_ContextArray.GetSize()-1);
}
void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc)
{
- if (m_pDocument != pReaderDoc)
- {
- v8::Isolate::Scope isolate_scope(m_isolate);
- v8::HandleScope handle_scope(m_isolate);
- v8::Local<v8::Context> context =v8::Local<v8::Context>::New(m_isolate, m_context);
- v8::Context::Scope context_scope(context);
-
- m_pDocument = pReaderDoc;
-
- if (pReaderDoc)
- {
- JSObject pThis = JS_GetThisObj(*this);
- if(!pThis.IsEmpty())
- {
- if (JS_GetObjDefnID(pThis) == JS_GetObjDefnID(*this, L"Document"))
- {
- if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis))
- {
- if (Document * pDocument = (Document*)pJSDocument->GetEmbedObject())
- pDocument->AttachDoc(pReaderDoc);
- }
- }
- }
- JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document"));
- }
- else
- {
- JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app"));
- }
- }
+ if (m_pDocument != pReaderDoc)
+ {
+ v8::Isolate::Scope isolate_scope(m_isolate);
+ v8::HandleScope handle_scope(m_isolate);
+ v8::Local<v8::Context> context =v8::Local<v8::Context>::New(m_isolate, m_context);
+ v8::Context::Scope context_scope(context);
+
+ m_pDocument = pReaderDoc;
+
+ if (pReaderDoc)
+ {
+ JSObject pThis = JS_GetThisObj(*this);
+ if(!pThis.IsEmpty())
+ {
+ if (JS_GetObjDefnID(pThis) == JS_GetObjDefnID(*this, L"Document"))
+ {
+ if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis))
+ {
+ if (Document * pDocument = (Document*)pJSDocument->GetEmbedObject())
+ pDocument->AttachDoc(pReaderDoc);
+ }
+ }
+ }
+ JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document"));
+ }
+ else
+ {
+ JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app"));
+ }
+ }
}
-FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType)
+FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType)
{
- if (m_pFieldEventPath == NULL)
- {
- m_pFieldEventPath = new CJS_FieldEvent;
- m_pFieldEventPath->sTargetName = sTargetName;
- m_pFieldEventPath->eEventType = eEventType;
- m_pFieldEventPath->pNext = NULL;
-
- return TRUE;
- }
-
- //to search
- CJS_FieldEvent* p = m_pFieldEventPath;
- CJS_FieldEvent* pLast = m_pFieldEventPath;
- while (p)
- {
- if (p->eEventType == eEventType && p->sTargetName == sTargetName)
- return FALSE;
-
- pLast = p;
- p = p->pNext;
- }
-
- //to add
- CJS_FieldEvent* pNew = new CJS_FieldEvent;
- pNew->sTargetName = sTargetName;
- pNew->eEventType = eEventType;
- pNew->pNext = NULL;
-
- pLast->pNext = pNew;
-
- return TRUE;
+ if (m_pFieldEventPath == NULL)
+ {
+ m_pFieldEventPath = new CJS_FieldEvent;
+ m_pFieldEventPath->sTargetName = sTargetName;
+ m_pFieldEventPath->eEventType = eEventType;
+ m_pFieldEventPath->pNext = NULL;
+
+ return TRUE;
+ }
+
+ //to search
+ CJS_FieldEvent* p = m_pFieldEventPath;
+ CJS_FieldEvent* pLast = m_pFieldEventPath;
+ while (p)
+ {
+ if (p->eEventType == eEventType && p->sTargetName == sTargetName)
+ return FALSE;
+
+ pLast = p;
+ p = p->pNext;
+ }
+
+ //to add
+ CJS_FieldEvent* pNew = new CJS_FieldEvent;
+ pNew->sTargetName = sTargetName;
+ pNew->eEventType = eEventType;
+ pNew->pNext = NULL;
+
+ pLast->pNext = pNew;
+
+ return TRUE;
}
void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType)
{
- FX_BOOL bFind = FALSE;
-
- CJS_FieldEvent* p = m_pFieldEventPath;
- CJS_FieldEvent* pLast = NULL;
- while (p)
- {
- if (p->eEventType == eEventType && p->sTargetName == sTargetName)
- {
- bFind = TRUE;
- break;
- }
-
- pLast = p;
- p = p->pNext;
- }
-
- if (bFind)
- {
- RemoveEventsInLoop(p);
-
- if (p == m_pFieldEventPath)
- m_pFieldEventPath = NULL;
-
- if (pLast)
- pLast->pNext = NULL;
- }
+ FX_BOOL bFind = FALSE;
+
+ CJS_FieldEvent* p = m_pFieldEventPath;
+ CJS_FieldEvent* pLast = NULL;
+ while (p)
+ {
+ if (p->eEventType == eEventType && p->sTargetName == sTargetName)
+ {
+ bFind = TRUE;
+ break;
+ }
+
+ pLast = p;
+ p = p->pNext;
+ }
+
+ if (bFind)
+ {
+ RemoveEventsInLoop(p);
+
+ if (p == m_pFieldEventPath)
+ m_pFieldEventPath = NULL;
+
+ if (pLast)
+ pLast->pNext = NULL;
+ }
}
void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart)
{
- CJS_FieldEvent* p = pStart;
+ CJS_FieldEvent* p = pStart;
- while (p)
- {
- CJS_FieldEvent* pOld = p;
- p = pOld->pNext;
+ while (p)
+ {
+ CJS_FieldEvent* pOld = p;
+ p = pOld->pNext;
- delete pOld;
- }
+ delete pOld;
+ }
}
-v8::Local<v8::Context> CJS_Runtime::NewJSContext()
+v8::Local<v8::Context> CJS_Runtime::NewJSContext()
{
- return v8::Local<v8::Context>::New(m_isolate, m_context);
+ return v8::Local<v8::Context>::New(m_isolate, m_context);
}
CFX_WideString ChangeObjName(const CFX_WideString& str)
{
- CFX_WideString sRet = str;
- sRet.Replace(L"_", L".");
- return sRet;
+ CFX_WideString sRet = str;
+ sRet.Replace(L"_", L".");
+ return sRet;
}
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index b8967c4d53..a615d4409b 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -21,131 +21,130 @@
static v8::Isolate* GetIsolate(IFXJS_Context* cc)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
- return pRuntime->GetIsolate();
+ return pRuntime->GetIsolate();
}
/* -------------------------------- CJS_PublicMethods -------------------------------- */
-#define DOUBLE_CORRECT 0.000000000000001
+#define DOUBLE_CORRECT 0.000000000000001
BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums)
END_JS_STATIC_GLOBAL_FUN()
IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
static const FX_WCHAR* months[] =
{
- L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"
+ L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"
};
static const FX_WCHAR* fullmonths[] =
{
- L"January", L"February", L"March", L"April", L"May", L"June", L"July", L"August", L"September", L"October", L"November", L"December"
+ L"January", L"February", L"March", L"April", L"May", L"June", L"July", L"August", L"September", L"October", L"November", L"December"
};
FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* string)
{
- CFX_WideString sTrim = StrTrim(string);
- const FX_WCHAR* pTrim = sTrim.c_str();
- const FX_WCHAR* p = pTrim;
-
-
- FX_BOOL bDot = FALSE;
- FX_BOOL bKXJS = FALSE;
-
- wchar_t c;
- while ((c = *p))
- {
- if (c == '.' || c == ',')
- {
- if (bDot) return FALSE;
- bDot = TRUE;
- }
- else if (c == '-' || c == '+')
- {
- if (p != pTrim)
- return FALSE;
- }
- else if (c == 'e' || c == 'E')
- {
- if (bKXJS)
- return FALSE;
-
- p++;
- c = *p;
- if (c == '+' || c == '-')
- {
- bKXJS = TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- else if (!IsDigit(c))
- {
- return FALSE;
- }
- p++;
- }
-
- return TRUE;
+ CFX_WideString sTrim = StrTrim(string);
+ const FX_WCHAR* pTrim = sTrim.c_str();
+ const FX_WCHAR* p = pTrim;
+
+
+ FX_BOOL bDot = FALSE;
+ FX_BOOL bKXJS = FALSE;
+
+ wchar_t c;
+ while ((c = *p))
+ {
+ if (c == '.' || c == ',')
+ {
+ if (bDot) return FALSE;
+ bDot = TRUE;
+ }
+ else if (c == '-' || c == '+')
+ {
+ if (p != pTrim)
+ return FALSE;
+ }
+ else if (c == 'e' || c == 'E')
+ {
+ if (bKXJS) return FALSE;
+
+ p++;
+ c = *p;
+ if (c == '+' || c == '-')
+ {
+ bKXJS = TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ else if (!IsDigit(c))
+ {
+ return FALSE;
+ }
+ p++;
+ }
+
+ return TRUE;
}
FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch)
{
- return (ch >= L'0' && ch <= L'9');
+ return (ch >= L'0' && ch <= L'9');
}
FX_BOOL CJS_PublicMethods::IsDigit(char ch)
{
- return (ch >= '0' && ch <= '9');
+ return (ch >= '0' && ch <= '9');
}
FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch)
{
- return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
+ return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
}
FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch)
{
- return (IsDigit(ch) || IsAlphabetic(ch));
+ return (IsDigit(ch) || IsAlphabetic(ch));
}
FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask)
{
- switch (c_Mask)
- {
- case L'9':
+ switch (c_Mask)
+ {
+ case L'9':
return IsDigit(c_Change);
case L'A':
return IsAlphabetic(c_Change);
@@ -153,869 +152,870 @@ FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask)
return IsAlphaNumeric(c_Change);
case L'X':
return TRUE;
- default:
+ default:
return (c_Change == c_Mask);
- }
+ }
}
FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch)
{
- return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X';
+ return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X';
}
double CJS_PublicMethods::AF_Simple(const FX_WCHAR* sFuction, double dValue1, double dValue2)
{
- if (FXSYS_wcsicmp(sFuction,L"AVG") == 0 || FXSYS_wcsicmp(sFuction,L"SUM") == 0)
- {
- return dValue1 + dValue2;
- }
- if (FXSYS_wcsicmp(sFuction, L"PRD") == 0)
- {
- return dValue1 * dValue2;
- }
- if (FXSYS_wcsicmp(sFuction,L"MIN") == 0)
- {
- return FX_MIN(dValue1, dValue2);
- }
- if (FXSYS_wcsicmp(sFuction,L"MAX") == 0)
- {
- return FX_MAX(dValue1, dValue2);
- }
- return dValue1;
+ if (FXSYS_wcsicmp(sFuction,L"AVG") == 0 || FXSYS_wcsicmp(sFuction,L"SUM") == 0)
+ {
+ return dValue1 + dValue2;
+ }
+ else if (FXSYS_wcsicmp(sFuction, L"PRD") == 0)
+ {
+ return dValue1 * dValue2;
+ }
+ else if (FXSYS_wcsicmp(sFuction,L"MIN") == 0)
+ {
+ return FX_MIN(dValue1, dValue2);
+ }
+ else if (FXSYS_wcsicmp(sFuction,L"MAX") == 0)
+ {
+ return FX_MAX(dValue1, dValue2);
+ }
+
+ return dValue1;
}
CFX_WideString CJS_PublicMethods::StrLTrim(const FX_WCHAR* pStr)
{
- while (*pStr && *pStr == L' ') pStr++;
+ while (*pStr && *pStr == L' ') pStr++;
- return pStr;
+ return pStr;
}
CFX_WideString CJS_PublicMethods::StrRTrim(const FX_WCHAR* pStr)
{
- const FX_WCHAR* p = pStr;
- while (*p) p++;
- while (p > pStr && *(p - 1) == L' ') p--;
+ const FX_WCHAR* p = pStr;
+ while (*p) p++;
+ while (p > pStr && *(p - 1) == L' ') p--;
- return CFX_WideString(pStr, p - pStr);
+ return CFX_WideString(pStr, p - pStr);
}
CFX_WideString CJS_PublicMethods::StrTrim(const FX_WCHAR* pStr)
{
- return StrRTrim(StrLTrim(pStr).c_str());
+ return StrRTrim(StrLTrim(pStr).c_str());
}
CFX_ByteString CJS_PublicMethods::StrLTrim(const FX_CHAR* pStr)
{
- while (*pStr && *pStr == ' ') pStr++;
+ while (*pStr && *pStr == ' ') pStr++;
return pStr;
}
CFX_ByteString CJS_PublicMethods::StrRTrim(const FX_CHAR* pStr)
{
- const FX_CHAR* p = pStr;
- while (*p) p++;
- while (p > pStr && *(p - 1) == L' ') p--;
+ const FX_CHAR* p = pStr;
+ while (*p) p++;
+ while (p > pStr && *(p - 1) == L' ') p--;
- return CFX_ByteString(pStr,p-pStr);
+ return CFX_ByteString(pStr,p-pStr);
}
CFX_ByteString CJS_PublicMethods::StrTrim(const FX_CHAR* pStr)
{
- return StrRTrim(StrLTrim(pStr));
+ return StrRTrim(StrLTrim(pStr));
}
double CJS_PublicMethods::ParseNumber(const FX_WCHAR* swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS)
{
- bDot = FALSE;
- bSign = FALSE;
- bKXJS = FALSE;
-
- FX_BOOL bDigitExist = FALSE;
-
- const FX_WCHAR* p = swSource;
- wchar_t c;
-
- const FX_WCHAR* pStart = NULL;
- const FX_WCHAR* pEnd = NULL;
-
- while ((c = *p))
- {
- if (!pStart && c != L' ')
- {
- pStart = p;
- }
-
- pEnd = p;
- p++;
- }
-
- if (!pStart)
- {
- bAllDigits = FALSE;
- return 0;
- }
-
- while (pEnd != pStart)
- {
- if (*pEnd == L' ')
- pEnd --;
- else
- break;
- }
-
- double dRet = 0;
- p = pStart;
- bAllDigits = TRUE;
- CFX_WideString swDigits;
-
- while (p <= pEnd)
- {
- c = *p;
-
- if (IsDigit(c))
- {
- swDigits += c;
- bDigitExist = TRUE;
- }
- else
- {
- switch (c)
- {
- case L' ':
- bAllDigits = FALSE;
- break;
- case L'.':
- case L',':
- if (!bDot)
- {
- if (bDigitExist)
- {
- swDigits += L'.';
- }
- else
- {
- swDigits += L'0';
- swDigits += L'.';
- bDigitExist = TRUE;
- }
-
- bDot = TRUE;
- break;
- }
- case 'e':
- case 'E':
- if (!bKXJS)
- {
- p++;
- c = *p;
- if (c == '+' || c == '-')
- {
- bKXJS = TRUE;
- swDigits += 'e';
- swDigits += c;
- }
- break;
- }
- case L'-':
- if (!bDigitExist && !bSign)
- {
- swDigits += c;
- bSign = TRUE;
- break;
- }
- default:
- bAllDigits = FALSE;
-
- if (p != pStart && !bDot && bDigitExist)
- {
- swDigits += L'.';
- bDot = TRUE;
- }
- else
- {
- bDot = FALSE;
- bDigitExist = FALSE;
- swDigits = L"";
- }
- break;
- }
- }
-
- p++;
- }
-
- if (swDigits.GetLength() > 0 && swDigits.GetLength() < 17)
- {
- CFX_ByteString sDigits = swDigits.UTF8Encode();
-
- if (bKXJS)
- {
- dRet = atof(sDigits);
- }
- else
- {
- if (bDot)
- {
- char* pStopString;
- dRet = ::strtod(sDigits, &pStopString);
- }
- else
- {
- dRet = atol(sDigits);
- }
- }
-
- }
-
- return dRet;
+ bDot = FALSE;
+ bSign = FALSE;
+ bKXJS = FALSE;
+
+ FX_BOOL bDigitExist = FALSE;
+
+ const FX_WCHAR* p = swSource;
+ wchar_t c;
+
+ const FX_WCHAR* pStart = NULL;
+ const FX_WCHAR* pEnd = NULL;
+
+ while ((c = *p))
+ {
+ if (!pStart && c != L' ')
+ {
+ pStart = p;
+ }
+
+ pEnd = p;
+ p++;
+ }
+
+ if (!pStart)
+ {
+ bAllDigits = FALSE;
+ return 0;
+ }
+
+ while (pEnd != pStart)
+ {
+ if (*pEnd == L' ')
+ pEnd --;
+ else
+ break;
+ }
+
+ double dRet = 0;
+ p = pStart;
+ bAllDigits = TRUE;
+ CFX_WideString swDigits;
+
+ while (p <= pEnd)
+ {
+ c = *p;
+
+ if (IsDigit(c))
+ {
+ swDigits += c;
+ bDigitExist = TRUE;
+ }
+ else
+ {
+ switch (c)
+ {
+ case L' ':
+ bAllDigits = FALSE;
+ break;
+ case L'.':
+ case L',':
+ if (!bDot)
+ {
+ if (bDigitExist)
+ {
+ swDigits += L'.';
+ }
+ else
+ {
+ swDigits += L'0';
+ swDigits += L'.';
+ bDigitExist = TRUE;
+ }
+
+ bDot = TRUE;
+ break;
+ }
+ case 'e':
+ case 'E':
+ if (!bKXJS)
+ {
+ p++;
+ c = *p;
+ if (c == '+' || c == '-')
+ {
+ bKXJS = TRUE;
+ swDigits += 'e';
+ swDigits += c;
+ }
+ break;
+ }
+ case L'-':
+ if (!bDigitExist && !bSign)
+ {
+ swDigits += c;
+ bSign = TRUE;
+ break;
+ }
+ default:
+ bAllDigits = FALSE;
+
+ if (p != pStart && !bDot && bDigitExist)
+ {
+ swDigits += L'.';
+ bDot = TRUE;
+ }
+ else
+ {
+ bDot = FALSE;
+ bDigitExist = FALSE;
+ swDigits = L"";
+ }
+ break;
+ }
+ }
+
+ p++;
+ }
+
+ if (swDigits.GetLength() > 0 && swDigits.GetLength() < 17)
+ {
+ CFX_ByteString sDigits = swDigits.UTF8Encode();
+
+ if (bKXJS)
+ {
+ dRet = atof(sDigits);
+ }
+ else
+ {
+ if (bDot)
+ {
+ char* pStopString;
+ dRet = ::strtod(sDigits, &pStopString);
+ }
+ else
+ {
+ dRet = atol(sDigits);
+ }
+ }
+
+ }
+
+ return dRet;
}
double CJS_PublicMethods::ParseStringToNumber(const FX_WCHAR* swSource)
{
- FX_BOOL bAllDigits = FALSE;
- FX_BOOL bDot = FALSE;
- FX_BOOL bSign = FALSE;
- FX_BOOL bKXJS = FALSE;
+ FX_BOOL bAllDigits = FALSE;
+ FX_BOOL bDot = FALSE;
+ FX_BOOL bSign = FALSE;
+ FX_BOOL bKXJS = FALSE;
- return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
+ return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
}
-FX_BOOL CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* swSource, double & dRet, FX_BOOL & bDot)
+FX_BOOL CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* swSource, double & dRet, FX_BOOL & bDot)
{
- FX_BOOL bAllDigits = FALSE;
- FX_BOOL bSign = FALSE;
- FX_BOOL bKXJS = FALSE;
+ FX_BOOL bAllDigits = FALSE;
+ FX_BOOL bSign = FALSE;
+ FX_BOOL bKXJS = FALSE;
- dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
+ dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
- return bAllDigits;
+ return bAllDigits;
}
CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val)
{
- CJS_Array StrArray(isolate);
- if(val.IsArrayObject())
- {
- val.ConvertToArray(StrArray);
- return StrArray;
- }
- CFX_WideString wsStr = val.ToCFXWideString();
- CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr);
- const char * p = (const char *)t;
-
-
- int ch = ',' ;
- int nIndex = 0;
-
- while (*p)
- {
- const char * pTemp = strchr(p, ch);
- if (pTemp == NULL)
- {
- StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p).c_str()));
- break;
- }
- else
- {
- char * pSub = new char[pTemp - p + 1];
- strncpy(pSub, p, pTemp - p);
- *(pSub + (pTemp - p)) = '\0';
-
- StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str()));
- delete []pSub;
-
- nIndex ++;
- p = ++pTemp;
- }
-
- }
- return StrArray;
+ CJS_Array StrArray(isolate);
+ if(val.IsArrayObject())
+ {
+ val.ConvertToArray(StrArray);
+ return StrArray;
+ }
+ CFX_WideString wsStr = val.ToCFXWideString();
+ CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr);
+ const char * p = (const char *)t;
+
+
+ int ch = ',' ;
+ int nIndex = 0;
+
+ while (*p)
+ {
+ const char * pTemp = strchr(p, ch);
+ if (pTemp == NULL)
+ {
+ StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p).c_str()));
+ break;
+ }
+ else
+ {
+ char * pSub = new char[pTemp - p + 1];
+ strncpy(pSub, p, pTemp - p);
+ *(pSub + (pTemp - p)) = '\0';
+
+ StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str()));
+ delete []pSub;
+
+ nIndex ++;
+ p = ++pTemp;
+ }
+
+ }
+ return StrArray;
}
int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,int nStart,int& nSkip, int nMaxStep)
{
- int nRet = 0;
- nSkip = 0;
- for (int i=nStart, sz=string.GetLength(); i < sz; i++)
- {
- if (i-nStart > 10)
- break;
-
- FX_WCHAR c = string.GetAt(i);
- if (IsDigit((wchar_t)c))
- {
- nRet = nRet * 10 + (c - '0');
- nSkip = i - nStart + 1;
- if (nSkip >= nMaxStep)
- break;
- }
- else
- break;
- }
-
- return nRet;
+ int nRet = 0;
+ nSkip = 0;
+ for (int i=nStart, sz=string.GetLength(); i < sz; i++)
+ {
+ if (i-nStart > 10)
+ break;
+
+ FX_WCHAR c = string.GetAt(i);
+ if (IsDigit((wchar_t)c))
+ {
+ nRet = nRet * 10 + (c - '0');
+ nSkip = i - nStart + 1;
+ if (nSkip >= nMaxStep)
+ break;
+ }
+ else
+ break;
+ }
+
+ return nRet;
}
CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& string, int nStart, int& nSkip)
{
- CFX_WideString swRet;
- nSkip = 0;
- for (int i=nStart, sz=string.GetLength(); i < sz; i++)
- {
- FX_WCHAR c = string.GetAt(i);
- if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'))
- {
- swRet += c;
- nSkip = i - nStart + 1;
- }
- else
- break;
- }
-
- return swRet;
+ CFX_WideString swRet;
+ nSkip = 0;
+ for (int i=nStart, sz=string.GetLength(); i < sz; i++)
+ {
+ FX_WCHAR c = string.GetAt(i);
+ if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'))
+ {
+ swRet += c;
+ nSkip = i - nStart + 1;
+ }
+ else
+ break;
+ }
+
+ return swRet;
}
double CJS_PublicMethods::ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat)
{
- double dt = JS_GetDateTime();
-
- int nYear = JS_GetYearFromTime(dt);
- int nMonth = JS_GetMonthFromTime(dt) + 1;
- int nDay = JS_GetDayFromTime(dt);
- int nHour = JS_GetHourFromTime(dt);
- int nMin = JS_GetMinFromTime(dt);
- int nSec = JS_GetSecFromTime(dt);
-
- int number[3];
-
- int nSkip = 0;
- int nLen = value.GetLength();
- int nIndex = 0;
- int i = 0;
- while (i < nLen)
- {
- if (nIndex > 2) break;
-
- FX_WCHAR c = value.GetAt(i);
- if (IsDigit((wchar_t)c))
- {
- number[nIndex++] = ParseStringInteger(value, i, nSkip, 4);
- i += nSkip;
- }
- else
- {
- i ++;
- }
- }
-
- if (nIndex == 2)
- {
- // case2: month/day
- // case3: day/month
- if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31))
- {
- nMonth = number[0];
- nDay = number[1];
- }
- else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12))
- {
- nDay = number[0];
- nMonth = number[1];
- }
-
- bWrongFormat = FALSE;
- }
- else if (nIndex == 3)
- {
- // case1: year/month/day
- // case2: month/day/year
- // case3: day/month/year
-
- if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && (number[2] >= 1 && number[2] <= 31))
- {
- nYear = number[0];
- nMonth = number[1];
- nDay = number[2];
- }
- else if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31) && number[2] > 31)
- {
- nMonth = number[0];
- nDay = number[1];
- nYear = number[2];
- }
- else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12) && number[2] > 31)
- {
- nDay = number[0];
- nMonth = number[1];
- nYear = number[2];
- }
-
- bWrongFormat = FALSE;
- }
- else
- {
- bWrongFormat = TRUE;
- return dt;
- }
-
- CFX_WideString swTemp;
- swTemp.Format(L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
- return JS_DateParse(swTemp.c_str());
+ double dt = JS_GetDateTime();
+
+ int nYear = JS_GetYearFromTime(dt);
+ int nMonth = JS_GetMonthFromTime(dt) + 1;
+ int nDay = JS_GetDayFromTime(dt);
+ int nHour = JS_GetHourFromTime(dt);
+ int nMin = JS_GetMinFromTime(dt);
+ int nSec = JS_GetSecFromTime(dt);
+
+ int number[3];
+
+ int nSkip = 0;
+ int nLen = value.GetLength();
+ int nIndex = 0;
+ int i = 0;
+ while (i < nLen)
+ {
+ if (nIndex > 2) break;
+
+ FX_WCHAR c = value.GetAt(i);
+ if (IsDigit((wchar_t)c))
+ {
+ number[nIndex++] = ParseStringInteger(value, i, nSkip, 4);
+ i += nSkip;
+ }
+ else
+ {
+ i ++;
+ }
+ }
+
+ if (nIndex == 2)
+ {
+ // case2: month/day
+ // case3: day/month
+ if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31))
+ {
+ nMonth = number[0];
+ nDay = number[1];
+ }
+ else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12))
+ {
+ nDay = number[0];
+ nMonth = number[1];
+ }
+
+ bWrongFormat = FALSE;
+ }
+ else if (nIndex == 3)
+ {
+ // case1: year/month/day
+ // case2: month/day/year
+ // case3: day/month/year
+
+ if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && (number[2] >= 1 && number[2] <= 31))
+ {
+ nYear = number[0];
+ nMonth = number[1];
+ nDay = number[2];
+ }
+ else if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31) && number[2] > 31)
+ {
+ nMonth = number[0];
+ nDay = number[1];
+ nYear = number[2];
+ }
+ else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12) && number[2] > 31)
+ {
+ nDay = number[0];
+ nMonth = number[1];
+ nYear = number[2];
+ }
+
+ bWrongFormat = FALSE;
+ }
+ else
+ {
+ bWrongFormat = TRUE;
+ return dt;
+ }
+
+ CFX_WideString swTemp;
+ swTemp.Format(L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
+ return JS_DateParse(swTemp.c_str());
}
double CJS_PublicMethods::MakeRegularDate(const CFX_WideString & value, const CFX_WideString & format, FX_BOOL& bWrongFormat)
{
- double dt = JS_GetDateTime();
-
- if (format.IsEmpty() || value.IsEmpty())
- return dt;
-
- int nYear = JS_GetYearFromTime(dt);
- int nMonth = JS_GetMonthFromTime(dt) + 1;
- int nDay = JS_GetDayFromTime(dt);
- int nHour = JS_GetHourFromTime(dt);
- int nMin = JS_GetMinFromTime(dt);
- int nSec = JS_GetSecFromTime(dt);
-
- int nYearSub = 99; //nYear - 2000;
-
- FX_BOOL bPm = FALSE;
- FX_BOOL bExit = FALSE;
- bWrongFormat = FALSE;
-
- int i=0;
- int j=0;
-
- while (i < format.GetLength())
- {
- if (bExit) break;
-
- FX_WCHAR c = format.GetAt(i);
- switch (c)
- {
- case ':':
- case '.':
- case '-':
- case '\\':
- case '/':
- i++;
- j++;
- break;
-
- case 'y':
- case 'm':
- case 'd':
- case 'H':
- case 'h':
- case 'M':
- case 's':
- case 't':
- {
- int oldj = j;
- int nSkip = 0;
- int remaining = format.GetLength() - i - 1;
-
- if (remaining == 0 || format.GetAt(i+1) != c)
- {
- switch (c)
- {
- case 'y':
- i++;
- j++;
- break;
- case 'm':
- nMonth = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 'd':
- nDay = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 'H':
- nHour = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 'h':
- nHour = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 'M':
- nMin = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 's':
- nSec = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 't':
- bPm = (j < value.GetLength() && value.GetAt(j) == 'p');
- i++;
- j++;
- break;
- }
- }
- else if (remaining == 1 || format.GetAt(i+2) != c)
- {
- switch (c)
- {
- case 'y':
- nYear = ParseStringInteger(value, j, nSkip, 4);
- i += 2;
- j += nSkip;
- break;
- case 'm':
- nMonth = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 'd':
- nDay = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 'H':
- nHour = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 'h':
- nHour = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 'M':
- nMin = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 's':
- nSec = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 't':
- bPm = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm');
- i += 2;
- j += 2;
- break;
- }
- }
- else if (remaining == 2 || format.GetAt(i+3) != c)
- {
- switch (c)
- {
- case 'm':
- {
- CFX_WideString sMonth = ParseStringString(value, j, nSkip);
- FX_BOOL bFind = FALSE;
- for (int m = 0; m < 12; m++)
- {
- if (sMonth.CompareNoCase(months[m]) == 0)
- {
- nMonth = m + 1;
- i+=3;
- j+=nSkip;
- bFind = TRUE;
- break;
- }
- }
-
- if (!bFind)
- {
- nMonth = ParseStringInteger(value, j, nSkip, 3);
- i+=3;
- j += nSkip;
- }
- }
- break;
- case 'y':
- break;
- default:
- i+=3;
- j+=3;
- break;
- }
- }
- else if (remaining == 3 || format.GetAt(i+4) != c)
- {
- switch (c)
- {
-
-
- case 'y':
- nYear = ParseStringInteger(value, j, nSkip, 4);
- j += nSkip;
- i += 4;
- break;
- case 'm':
- {
- FX_BOOL bFind = FALSE;
-
- CFX_WideString sMonth = ParseStringString(value, j, nSkip);
- sMonth.MakeLower();
-
- for (int m = 0; m < 12; m++)
- {
- CFX_WideString sFullMonths = fullmonths[m];
- sFullMonths.MakeLower();
-
- if (sFullMonths.Find(sMonth.c_str(), 0) != -1)
- {
- nMonth = m + 1;
- i += 4;
- j += nSkip;
- bFind = TRUE;
- break;
- }
- }
-
- if (!bFind)
- {
- nMonth = ParseStringInteger(value, j, nSkip, 4);
- i+=4;
- j += nSkip;
- }
- }
- break;
- default:
- i += 4;
- j += 4;
- break;
- }
- }
- else
- {
- if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j))
- {
- bWrongFormat = TRUE;
- bExit = TRUE;
- }
- i++;
- j++;
- }
-
- if (oldj == j)
- {
- bWrongFormat = TRUE;
- bExit = TRUE;
- }
- }
-
- break;
- default:
- if (value.GetLength() <= j)
- {
- bExit = TRUE;
- }
- else if (format.GetAt(i) != value.GetAt(j))
- {
- bWrongFormat = TRUE;
- bExit = TRUE;
- }
-
- i++;
- j++;
- break;
- }
- }
-
- if (bPm) nHour += 12;
-
- if (nYear >= 0 && nYear <= nYearSub)
- nYear += 2000;
-
- if (nMonth < 1 || nMonth > 12)
- bWrongFormat = TRUE;
-
- if (nDay < 1 || nDay > 31)
- bWrongFormat = TRUE;
-
- if (nHour < 0 || nHour > 24)
- bWrongFormat = TRUE;
-
- if (nMin < 0 || nMin > 60)
- bWrongFormat = TRUE;
-
- if (nSec < 0 || nSec > 60)
- bWrongFormat = TRUE;
-
- double dRet = 0;
-
- if (bWrongFormat)
- {
- dRet = ParseNormalDate(value, bWrongFormat);
- }
- else
- {
- dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
-
- if (JS_PortIsNan(dRet))
- {
- dRet = JS_DateParse(value.c_str());
- }
- }
-
- if (JS_PortIsNan(dRet))
- {
- dRet = ParseNormalDate(value, bWrongFormat);
- }
-
- return dRet;
+ double dt = JS_GetDateTime();
+
+ if (format.IsEmpty() || value.IsEmpty())
+ return dt;
+
+ int nYear = JS_GetYearFromTime(dt);
+ int nMonth = JS_GetMonthFromTime(dt) + 1;
+ int nDay = JS_GetDayFromTime(dt);
+ int nHour = JS_GetHourFromTime(dt);
+ int nMin = JS_GetMinFromTime(dt);
+ int nSec = JS_GetSecFromTime(dt);
+
+ int nYearSub = 99; //nYear - 2000;
+
+ FX_BOOL bPm = FALSE;
+ FX_BOOL bExit = FALSE;
+ bWrongFormat = FALSE;
+
+ int i=0;
+ int j=0;
+
+ while (i < format.GetLength())
+ {
+ if (bExit) break;
+
+ FX_WCHAR c = format.GetAt(i);
+ switch (c)
+ {
+ case ':':
+ case '.':
+ case '-':
+ case '\\':
+ case '/':
+ i++;
+ j++;
+ break;
+
+ case 'y':
+ case 'm':
+ case 'd':
+ case 'H':
+ case 'h':
+ case 'M':
+ case 's':
+ case 't':
+ {
+ int oldj = j;
+ int nSkip = 0;
+ int remaining = format.GetLength() - i - 1;
+
+ if (remaining == 0 || format.GetAt(i+1) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ i++;
+ j++;
+ break;
+ case 'm':
+ nMonth = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 'd':
+ nDay = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 'H':
+ nHour = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 'h':
+ nHour = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 'M':
+ nMin = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 's':
+ nSec = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 't':
+ bPm = (j < value.GetLength() && value.GetAt(j) == 'p');
+ i++;
+ j++;
+ break;
+ }
+ }
+ else if (remaining == 1 || format.GetAt(i+2) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ nYear = ParseStringInteger(value, j, nSkip, 4);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'm':
+ nMonth = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'd':
+ nDay = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'H':
+ nHour = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'h':
+ nHour = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'M':
+ nMin = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 's':
+ nSec = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 't':
+ bPm = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm');
+ i += 2;
+ j += 2;
+ break;
+ }
+ }
+ else if (remaining == 2 || format.GetAt(i+3) != c)
+ {
+ switch (c)
+ {
+ case 'm':
+ {
+ CFX_WideString sMonth = ParseStringString(value, j, nSkip);
+ FX_BOOL bFind = FALSE;
+ for (int m = 0; m < 12; m++)
+ {
+ if (sMonth.CompareNoCase(months[m]) == 0)
+ {
+ nMonth = m + 1;
+ i+=3;
+ j+=nSkip;
+ bFind = TRUE;
+ break;
+ }
+ }
+
+ if (!bFind)
+ {
+ nMonth = ParseStringInteger(value, j, nSkip, 3);
+ i+=3;
+ j += nSkip;
+ }
+ }
+ break;
+ case 'y':
+ break;
+ default:
+ i+=3;
+ j+=3;
+ break;
+ }
+ }
+ else if (remaining == 3 || format.GetAt(i+4) != c)
+ {
+ switch (c)
+ {
+
+
+ case 'y':
+ nYear = ParseStringInteger(value, j, nSkip, 4);
+ j += nSkip;
+ i += 4;
+ break;
+ case 'm':
+ {
+ FX_BOOL bFind = FALSE;
+
+ CFX_WideString sMonth = ParseStringString(value, j, nSkip);
+ sMonth.MakeLower();
+
+ for (int m = 0; m < 12; m++)
+ {
+ CFX_WideString sFullMonths = fullmonths[m];
+ sFullMonths.MakeLower();
+
+ if (sFullMonths.Find(sMonth.c_str(), 0) != -1)
+ {
+ nMonth = m + 1;
+ i += 4;
+ j += nSkip;
+ bFind = TRUE;
+ break;
+ }
+ }
+
+ if (!bFind)
+ {
+ nMonth = ParseStringInteger(value, j, nSkip, 4);
+ i+=4;
+ j += nSkip;
+ }
+ }
+ break;
+ default:
+ i += 4;
+ j += 4;
+ break;
+ }
+ }
+ else
+ {
+ if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j))
+ {
+ bWrongFormat = TRUE;
+ bExit = TRUE;
+ }
+ i++;
+ j++;
+ }
+
+ if (oldj == j)
+ {
+ bWrongFormat = TRUE;
+ bExit = TRUE;
+ }
+ }
+
+ break;
+ default:
+ if (value.GetLength() <= j)
+ {
+ bExit = TRUE;
+ }
+ else if (format.GetAt(i) != value.GetAt(j))
+ {
+ bWrongFormat = TRUE;
+ bExit = TRUE;
+ }
+
+ i++;
+ j++;
+ break;
+ }
+ }
+
+ if (bPm) nHour += 12;
+
+ if (nYear >= 0 && nYear <= nYearSub)
+ nYear += 2000;
+
+ if (nMonth < 1 || nMonth > 12)
+ bWrongFormat = TRUE;
+
+ if (nDay < 1 || nDay > 31)
+ bWrongFormat = TRUE;
+
+ if (nHour < 0 || nHour > 24)
+ bWrongFormat = TRUE;
+
+ if (nMin < 0 || nMin > 60)
+ bWrongFormat = TRUE;
+
+ if (nSec < 0 || nSec > 60)
+ bWrongFormat = TRUE;
+
+ double dRet = 0;
+
+ if (bWrongFormat)
+ {
+ dRet = ParseNormalDate(value, bWrongFormat);
+ }
+ else
+ {
+ dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
+
+ if (JS_PortIsNan(dRet))
+ {
+ dRet = JS_DateParse(value.c_str());
+ }
+ }
+
+ if (JS_PortIsNan(dRet))
+ {
+ dRet = ParseNormalDate(value, bWrongFormat);
+ }
+
+ return dRet;
}
CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideString & format)
{
- CFX_WideString sRet = L"",sPart = L"";
-
- int nYear = JS_GetYearFromTime(dDate);
- int nMonth = JS_GetMonthFromTime(dDate) + 1;
- int nDay = JS_GetDayFromTime(dDate);
- int nHour = JS_GetHourFromTime(dDate);
- int nMin = JS_GetMinFromTime(dDate);
- int nSec = JS_GetSecFromTime(dDate);
-
- int i = 0;
- while (i < format.GetLength())
- {
- FX_WCHAR c = format.GetAt(i);
+ CFX_WideString sRet = L"",sPart = L"";
+
+ int nYear = JS_GetYearFromTime(dDate);
+ int nMonth = JS_GetMonthFromTime(dDate) + 1;
+ int nDay = JS_GetDayFromTime(dDate);
+ int nHour = JS_GetHourFromTime(dDate);
+ int nMin = JS_GetMinFromTime(dDate);
+ int nSec = JS_GetSecFromTime(dDate);
+
+ int i = 0;
+ while (i < format.GetLength())
+ {
+ FX_WCHAR c = format.GetAt(i);
int remaining = format.GetLength() - i - 1;
- sPart = L"";
- switch (c)
- {
- case 'y':
- case 'm':
- case 'd':
- case 'H':
- case 'h':
- case 'M':
- case 's':
- case 't':
- if (remaining == 0 || format.GetAt(i+1) != c)
- {
- switch (c)
- {
- case 'y':
- sPart += c;
- break;
- case 'm':
- sPart.Format(L"%d",nMonth);
- break;
- case 'd':
- sPart.Format(L"%d",nDay);
- break;
- case 'H':
- sPart.Format(L"%d",nHour);
- break;
- case 'h':
- sPart.Format(L"%d",nHour>12?nHour - 12:nHour);
- break;
- case 'M':
- sPart.Format(L"%d",nMin);
- break;
- case 's':
- sPart.Format(L"%d",nSec);
- break;
- case 't':
- sPart += nHour>12?'p':'a';
- break;
- }
- i++;
- }
- else if (remaining == 1 || format.GetAt(i+2) != c)
- {
- switch (c)
- {
- case 'y':
- sPart.Format(L"%02d",nYear - (nYear / 100) * 100);
- break;
- case 'm':
- sPart.Format(L"%02d",nMonth);
- break;
- case 'd':
- sPart.Format(L"%02d",nDay);
- break;
- case 'H':
- sPart.Format(L"%02d",nHour);
- break;
- case 'h':
- sPart.Format(L"%02d",nHour>12?nHour - 12:nHour);
- break;
- case 'M':
- sPart.Format(L"%02d",nMin);
- break;
- case 's':
- sPart.Format(L"%02d",nSec);
- break;
- case 't':
- sPart = nHour>12? L"pm": L"am";
- break;
- }
- i+=2;
- }
- else if (remaining == 2 || format.GetAt(i+3) != c)
- {
- switch (c)
- {
- case 'm':
- i+=3;
- if (nMonth > 0&&nMonth <= 12)
- sPart += months[nMonth - 1];
- break;
- default:
- i+=3;
- sPart += c;
- sPart += c;
- sPart += c;
- break;
- }
- }
- else if (remaining == 3 || format.GetAt(i+4) != c)
- {
- switch (c)
- {
- case 'y':
- sPart.Format(L"%04d",nYear);
- i += 4;
- break;
- case 'm':
- i+=4;
- if (nMonth > 0&&nMonth <= 12)
- sPart += fullmonths[nMonth - 1];
- break;
- default:
- i += 4;
- sPart += c;
- sPart += c;
- sPart += c;
- sPart += c;
- break;
- }
- }
- else
- {
- i++;
- sPart += c;
- }
- break;
- default:
- i++;
- sPart += c;
- break;
- }
-
- sRet += sPart;
- }
-
- return sRet;
+ sPart = L"";
+ switch (c)
+ {
+ case 'y':
+ case 'm':
+ case 'd':
+ case 'H':
+ case 'h':
+ case 'M':
+ case 's':
+ case 't':
+ if (remaining == 0 || format.GetAt(i+1) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ sPart += c;
+ break;
+ case 'm':
+ sPart.Format(L"%d",nMonth);
+ break;
+ case 'd':
+ sPart.Format(L"%d",nDay);
+ break;
+ case 'H':
+ sPart.Format(L"%d",nHour);
+ break;
+ case 'h':
+ sPart.Format(L"%d",nHour>12?nHour - 12:nHour);
+ break;
+ case 'M':
+ sPart.Format(L"%d",nMin);
+ break;
+ case 's':
+ sPart.Format(L"%d",nSec);
+ break;
+ case 't':
+ sPart += nHour>12?'p':'a';
+ break;
+ }
+ i++;
+ }
+ else if (remaining == 1 || format.GetAt(i+2) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ sPart.Format(L"%02d",nYear - (nYear / 100) * 100);
+ break;
+ case 'm':
+ sPart.Format(L"%02d",nMonth);
+ break;
+ case 'd':
+ sPart.Format(L"%02d",nDay);
+ break;
+ case 'H':
+ sPart.Format(L"%02d",nHour);
+ break;
+ case 'h':
+ sPart.Format(L"%02d",nHour>12?nHour - 12:nHour);
+ break;
+ case 'M':
+ sPart.Format(L"%02d",nMin);
+ break;
+ case 's':
+ sPart.Format(L"%02d",nSec);
+ break;
+ case 't':
+ sPart = nHour>12? L"pm": L"am";
+ break;
+ }
+ i+=2;
+ }
+ else if (remaining == 2 || format.GetAt(i+3) != c)
+ {
+ switch (c)
+ {
+ case 'm':
+ i+=3;
+ if (nMonth > 0&&nMonth <= 12)
+ sPart += months[nMonth - 1];
+ break;
+ default:
+ i+=3;
+ sPart += c;
+ sPart += c;
+ sPart += c;
+ break;
+ }
+ }
+ else if (remaining == 3 || format.GetAt(i+4) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ sPart.Format(L"%04d",nYear);
+ i += 4;
+ break;
+ case 'm':
+ i+=4;
+ if (nMonth > 0&&nMonth <= 12)
+ sPart += fullmonths[nMonth - 1];
+ break;
+ default:
+ i += 4;
+ sPart += c;
+ sPart += c;
+ sPart += c;
+ sPart += c;
+ break;
+ }
+ }
+ else
+ {
+ i++;
+ sPart += c;
+ }
+ break;
+ default:
+ i++;
+ sPart += c;
+ break;
+ }
+
+ sRet += sPart;
+ }
+
+ return sRet;
}
/* -------------------------------------------------------------------------- */
@@ -1024,334 +1024,337 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideStr
FX_BOOL CJS_PublicMethods::AFNumber_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
#if _FX_OS_ != _FX_ANDROID_
- v8::Isolate* isolate = ::GetIsolate(cc);
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 6)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString& Value = pEvent->Value();
- CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
-
- if (strValue.IsEmpty()) return TRUE;
-
- int iDec = params[0].ToInt();
- int iSepStyle = params[1].ToInt();
- int iNegStyle = params[2].ToInt();
- // params[3] is iCurrStyle, it's not used.
- std::wstring wstrCurrency(params[4].ToCFXWideString().c_str());
- FX_BOOL bCurrencyPrepend = params[5].ToBool();
-
- if (iDec < 0) iDec = -iDec;
-
- if (iSepStyle < 0 || iSepStyle > 3)
- iSepStyle = 0;
-
- if (iNegStyle < 0 || iNegStyle > 3)
- iNegStyle = 0;
-
-
- //////////////////////////////////////////////////////
- //for processing decimal places
- strValue.Replace(",", ".");
- double dValue = atof(strValue);
- if (iDec > 0)
- dValue += DOUBLE_CORRECT;
-
- int iDec2;
- FX_BOOL bNegative = FALSE;
-
- strValue = fcvt(dValue,iDec,&iDec2,&bNegative);
- if (strValue.IsEmpty())
- {
- dValue = 0;
- strValue = fcvt(dValue,iDec,&iDec2,&bNegative);
- if (strValue.IsEmpty())
- {
- strValue = "0";
- iDec2 = 1;
- }
-
- }
-
- if (iDec2 < 0)
- {
- for (int iNum = 0;iNum < abs(iDec2);iNum++)
- {
- strValue = "0" + strValue;
- }
- iDec2 = 0;
-
- }
- int iMax = strValue.GetLength();
- if (iDec2 > iMax)
- {
- for (int iNum = 0;iNum <= iDec2 - iMax ;iNum++)
- {
- strValue += "0";
- }
- iMax = iDec2+1;
- }
- ///////////////////////////////////////////////////////
+ v8::Isolate* isolate = ::GetIsolate(cc);
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 6)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString& Value = pEvent->Value();
+ CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
+
+ if (strValue.IsEmpty()) return TRUE;
+
+ int iDec = params[0].ToInt();
+ int iSepStyle = params[1].ToInt();
+ int iNegStyle = params[2].ToInt();
+ // params[3] is iCurrStyle, it's not used.
+ std::wstring wstrCurrency(params[4].ToCFXWideString().c_str());
+ FX_BOOL bCurrencyPrepend = params[5].ToBool();
+
+ if (iDec < 0) iDec = -iDec;
+
+ if (iSepStyle < 0 || iSepStyle > 3)
+ iSepStyle = 0;
+
+ if (iNegStyle < 0 || iNegStyle > 3)
+ iNegStyle = 0;
+
+
+ //////////////////////////////////////////////////////
+ //for processing decimal places
+ strValue.Replace(",", ".");
+ double dValue = atof(strValue);
+ if (iDec > 0)
+ dValue += DOUBLE_CORRECT;
+
+ int iDec2;
+ FX_BOOL bNegative = FALSE;
+
+ strValue = fcvt(dValue,iDec,&iDec2,&bNegative);
+ if (strValue.IsEmpty())
+ {
+ dValue = 0;
+ strValue = fcvt(dValue,iDec,&iDec2,&bNegative);
+ if (strValue.IsEmpty())
+ {
+ strValue = "0";
+ iDec2 = 1;
+ }
+
+ }
+
+ if (iDec2 < 0)
+ {
+ for (int iNum = 0;iNum < abs(iDec2);iNum++)
+ {
+ strValue = "0" + strValue;
+ }
+ iDec2 = 0;
+
+ }
+ int iMax = strValue.GetLength();
+ if (iDec2 > iMax)
+ {
+ for (int iNum = 0;iNum <= iDec2 - iMax ;iNum++)
+ {
+ strValue += "0";
+ }
+ iMax = iDec2+1;
+ }
+ ///////////////////////////////////////////////////////
//for processing seperator style
- if (iDec2 < iMax)
- {
- if (iSepStyle == 0 || iSepStyle == 1)
- {
- strValue.Insert(iDec2, '.');
- iMax++;
- }
- else if (iSepStyle == 2 || iSepStyle == 3)
- {
- strValue.Insert(iDec2, ',');
- iMax++;
- }
-
- if (iDec2 == 0)
- strValue.Insert(iDec2, '0');
- }
- if (iSepStyle == 0 || iSepStyle == 2)
- {
- char cSeperator;
- if (iSepStyle == 0)
- cSeperator = ',';
- else
- cSeperator = '.';
-
- int iDecPositive;
- iDecPositive = iDec2;
-
- for (iDecPositive = iDec2 -3; iDecPositive > 0;iDecPositive -= 3)
- {
- strValue.Insert(iDecPositive, cSeperator);
- iMax++;
- }
- }
-
- //////////////////////////////////////////////////////////////////////
+ if (iDec2 < iMax)
+ {
+ if (iSepStyle == 0 || iSepStyle == 1)
+ {
+ strValue.Insert(iDec2, '.');
+ iMax++;
+ }
+ else if (iSepStyle == 2 || iSepStyle == 3)
+ {
+ strValue.Insert(iDec2, ',');
+ iMax++;
+ }
+
+ if (iDec2 == 0)
+ strValue.Insert(iDec2, '0');
+ }
+ if (iSepStyle == 0 || iSepStyle == 2)
+ {
+ char cSeperator;
+ if (iSepStyle == 0)
+ cSeperator = ',';
+ else
+ cSeperator = '.';
+
+ int iDecPositive;
+ iDecPositive = iDec2;
+
+ for (iDecPositive = iDec2 -3; iDecPositive > 0;iDecPositive -= 3)
+ {
+ strValue.Insert(iDecPositive, cSeperator);
+ iMax++;
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////
//for processing currency string
- Value = CFX_WideString::FromLocal(strValue);
- std::wstring strValue2 = Value.c_str();
-
- if (bCurrencyPrepend)
- strValue2 = wstrCurrency + strValue2;
- else
- strValue2 = strValue2 + wstrCurrency;
-
-
-
- /////////////////////////////////////////////////////////////////////////
- //for processing negative style
- if (bNegative)
- {
- if (iNegStyle == 0)
- {
- strValue2.insert(0,L"-");
- }
- if (iNegStyle == 2 || iNegStyle == 3)
- {
- strValue2.insert(0,L"(");
- strValue2.insert(strValue2.length(),L")");
- }
- if (iNegStyle == 1 || iNegStyle == 3)
- {
- if (Field * fTarget = pEvent->Target_Field())
- {
- CJS_Array arColor(isolate);
- CJS_Value vColElm(isolate);
- vColElm = L"RGB";
- arColor.SetElement(0,vColElm);
- vColElm = 1;
- arColor.SetElement(1,vColElm);
- vColElm = 0;
- arColor.SetElement(2,vColElm);
-
- arColor.SetElement(3,vColElm);
-
- CJS_PropValue vProp(isolate);
- vProp.StartGetting();
- vProp<<arColor;
- vProp.StartSetting();
- fTarget->textColor(cc,vProp,sError);// red
- }
- }
- }
- else
- {
- if (iNegStyle == 1 || iNegStyle == 3)
- {
- if (Field *fTarget = pEvent->Target_Field())
- {
- CJS_Array arColor(isolate);
- CJS_Value vColElm(isolate);
- vColElm = L"RGB";
- arColor.SetElement(0,vColElm);
- vColElm = 0;
- arColor.SetElement(1,vColElm);
- arColor.SetElement(2,vColElm);
- arColor.SetElement(3,vColElm);
-
- CJS_PropValue vProp(isolate);
- vProp.StartGetting();
- fTarget->textColor(cc,vProp,sError);
-
- CJS_Array aProp(isolate);
- vProp.ConvertToArray(aProp);
-
- CPWL_Color crProp;
- CPWL_Color crColor;
- color::ConvertArrayToPWLColor(aProp, crProp);
- color::ConvertArrayToPWLColor(arColor, crColor);
-
- if (crColor != crProp)
- {
- CJS_PropValue vProp2(isolate);
- vProp2.StartGetting();
- vProp2<<arColor;
- vProp2.StartSetting();
- fTarget->textColor(cc,vProp2,sError);
- }
- }
- }
- }
- Value = strValue2.c_str();
+ Value = CFX_WideString::FromLocal(strValue);
+ std::wstring strValue2 = Value.c_str();
+
+ if (bCurrencyPrepend)
+ strValue2 = wstrCurrency + strValue2;
+ else
+ strValue2 = strValue2 + wstrCurrency;
+
+
+
+ /////////////////////////////////////////////////////////////////////////
+ //for processing negative style
+ if (bNegative)
+ {
+ if (iNegStyle == 0)
+ {
+ strValue2.insert(0,L"-");
+ }
+ if (iNegStyle == 2 || iNegStyle == 3)
+ {
+ strValue2.insert(0,L"(");
+ strValue2.insert(strValue2.length(),L")");
+ }
+ if (iNegStyle == 1 || iNegStyle == 3)
+ {
+ if (Field * fTarget = pEvent->Target_Field())
+ {
+ CJS_Array arColor(isolate);
+ CJS_Value vColElm(isolate);
+ vColElm = L"RGB";
+ arColor.SetElement(0,vColElm);
+ vColElm = 1;
+ arColor.SetElement(1,vColElm);
+ vColElm = 0;
+ arColor.SetElement(2,vColElm);
+
+ arColor.SetElement(3,vColElm);
+
+ CJS_PropValue vProp(isolate);
+ vProp.StartGetting();
+ vProp<<arColor;
+ vProp.StartSetting();
+ fTarget->textColor(cc,vProp,sError);// red
+ }
+ }
+ }
+ else
+ {
+ if (iNegStyle == 1 || iNegStyle == 3)
+ {
+ if (Field *fTarget = pEvent->Target_Field())
+ {
+ CJS_Array arColor(isolate);
+ CJS_Value vColElm(isolate);
+ vColElm = L"RGB";
+ arColor.SetElement(0,vColElm);
+ vColElm = 0;
+ arColor.SetElement(1,vColElm);
+ arColor.SetElement(2,vColElm);
+ arColor.SetElement(3,vColElm);
+
+ CJS_PropValue vProp(isolate);
+ vProp.StartGetting();
+ fTarget->textColor(cc,vProp,sError);
+
+ CJS_Array aProp(isolate);
+ vProp.ConvertToArray(aProp);
+
+ CPWL_Color crProp;
+ CPWL_Color crColor;
+ color::ConvertArrayToPWLColor(aProp, crProp);
+ color::ConvertArrayToPWLColor(arColor, crColor);
+
+ if (crColor != crProp)
+ {
+ CJS_PropValue vProp2(isolate);
+ vProp2.StartGetting();
+ vProp2<<arColor;
+ vProp2.StartSetting();
+ fTarget->textColor(cc,vProp2,sError);
+ }
+ }
+ }
+ }
+ Value = strValue2.c_str();
#endif
- return TRUE;
+ return TRUE;
}
//function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if(params.size() < 2)
- return FALSE;
- int iSepStyle = params[1].ToInt();
-
- if (iSepStyle < 0 || iSepStyle > 3)
- iSepStyle = 0;
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString & val = pEvent->Value();
- CFX_WideString & w_strChange = pEvent->Change();
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if(params.size() < 2)
+ return FALSE;
+ int iSepStyle = params[1].ToInt();
+
+ if (iSepStyle < 0 || iSepStyle > 3)
+ iSepStyle = 0;
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString & val = pEvent->Value();
+ CFX_WideString & w_strChange = pEvent->Change();
CFX_WideString w_strValue = val;
- if (pEvent->WillCommit())
- {
- CFX_WideString wstrChange = w_strChange;
- CFX_WideString wstrValue = StrLTrim(w_strValue.c_str());
- if (wstrValue.IsEmpty())
- return TRUE;
-
- CFX_WideString swTemp = wstrValue;
- swTemp.Replace(L",", L".");
- if (!IsNumber(swTemp.c_str()))
- {
- pEvent->Rc() = FALSE;
- sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
- Alert(pContext, sError.c_str());
- return TRUE;
- }
- return TRUE; // it happens after the last keystroke and before validating,
- }
-
- std::wstring w_strValue2 = w_strValue.c_str();
- std::wstring w_strChange2 = w_strChange.c_str();
- std::wstring w_strSelected;
- if(-1 != pEvent->SelStart())
- w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd() - pEvent->SelStart()));
- FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-') == -1);
- if (bHasSign)
- {
- //can't insert "change" in front to sign postion.
- if (pEvent->SelStart() == 0)
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- }
-
- char cSep = L'.';
-
- switch (iSepStyle)
- {
- case 0:
- case 1:
- cSep = L'.';
- break;
- case 2:
- case 3:
- cSep = L',';
- break;
- }
-
- FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1);
- for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.end(); it++)
- {
- if (*it == cSep)
- {
- if (bHasSep)
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- bHasSep = TRUE;
- continue;
- }
- if (*it == L'-')
- {
- if (bHasSign)
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- if (it != w_strChange2.begin()) //sign's position is not correct
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- if (pEvent->SelStart() != 0)
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- bHasSign = TRUE;
- continue;
- }
-
- if (!IsDigit(*it))
- {
+ if (pEvent->WillCommit())
+ {
+ CFX_WideString wstrChange = w_strChange;
+ CFX_WideString wstrValue = StrLTrim(w_strValue.c_str());
+ if (wstrValue.IsEmpty())
+ return TRUE;
+
+ CFX_WideString swTemp = wstrValue;
+ swTemp.Replace(L",", L".");
+ if (!IsNumber(swTemp.c_str()))
+ {
+ pEvent->Rc() = FALSE;
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ Alert(pContext, sError.c_str());
+ return TRUE;
+ }
+ return TRUE; // it happens after the last keystroke and before validating,
+ }
+
+ std::wstring w_strValue2 = w_strValue.c_str();
+ std::wstring w_strChange2 = w_strChange.c_str();
+ std::wstring w_strSelected;
+ if(-1 != pEvent->SelStart())
+ w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd() - pEvent->SelStart()));
+ FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-') == -1);
+ if (bHasSign)
+ {
+ //can't insert "change" in front to sign postion.
+ if (pEvent->SelStart() == 0)
+ {
FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- }
-
-
- std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart());
- std::wstring w_postfix;
- if (pEvent->SelEnd()<(int)w_strValue2.length())
- w_postfix = w_strValue2.substr(pEvent->SelEnd());
- w_strValue2 = w_prefix + w_strChange2 + w_postfix;
- w_strValue = w_strValue2.c_str();
- val = w_strValue;
- return TRUE;
+ bRc = FALSE;
+ return TRUE;
+ }
+ }
+
+ char cSep = L'.';
+
+ switch (iSepStyle)
+ {
+ case 0:
+ case 1:
+ cSep = L'.';
+ break;
+ case 2:
+ case 3:
+ cSep = L',';
+ break;
+ }
+
+ FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1);
+ for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.end(); it++)
+ {
+ if (*it == cSep)
+ {
+ if (bHasSep)
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ else
+ {
+ bHasSep = TRUE;
+ continue;
+ }
+ }
+ if (*it == L'-')
+ {
+ if (bHasSign)
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ else if (it != w_strChange2.begin()) //sign's position is not correct
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ else if (pEvent->SelStart() != 0)
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ bHasSign = TRUE;
+ continue;
+ }
+
+ if (!IsDigit(*it))
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ }
+
+
+ std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart());
+ std::wstring w_postfix;
+ if (pEvent->SelEnd()<(int)w_strValue2.length())
+ w_postfix = w_strValue2.substr(pEvent->SelEnd());
+ w_strValue2 = w_prefix + w_strChange2 + w_postfix;
+ w_strValue = w_strValue2.c_str();
+ val = w_strValue;
+ return TRUE;
}
@@ -1359,810 +1362,810 @@ FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(IFXJS_Context* cc, const CJS_Param
FX_BOOL CJS_PublicMethods::AFPercent_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
#if _FX_OS_ != _FX_ANDROID_
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
if (params.size() != 2)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
- if(!pEvent->m_pValue)
- return FALSE;
-
- CFX_WideString& Value = pEvent->Value();
- CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
- if (strValue.IsEmpty())
- return TRUE;
-
- int iDec = params[0].ToInt();
- if (iDec < 0)
- iDec = -iDec;
-
- int iSepStyle = params[1].ToInt();
- if (iSepStyle < 0 || iSepStyle > 3)
- iSepStyle = 0;
-
- //////////////////////////////////////////////////////
- //for processing decimal places
- double dValue = atof(strValue);
- dValue *= 100;
- if (iDec > 0)
- dValue += DOUBLE_CORRECT;//УÕý
-
- int iDec2;
- FX_BOOL bNegative = FALSE;
- strValue = fcvt(dValue,iDec,&iDec2,&bNegative);
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+ if(!pEvent->m_pValue)
+ return FALSE;
+
+ CFX_WideString& Value = pEvent->Value();
+ CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
+ if (strValue.IsEmpty())
+ return TRUE;
+
+ int iDec = params[0].ToInt();
+ if (iDec < 0)
+ iDec = -iDec;
+
+ int iSepStyle = params[1].ToInt();
+ if (iSepStyle < 0 || iSepStyle > 3)
+ iSepStyle = 0;
+
+ //////////////////////////////////////////////////////
+ //for processing decimal places
+ double dValue = atof(strValue);
+ dValue *= 100;
+ if (iDec > 0)
+ dValue += DOUBLE_CORRECT;//УÕý
+
+ int iDec2;
+ FX_BOOL bNegative = FALSE;
+ strValue = fcvt(dValue,iDec,&iDec2,&bNegative);
if (strValue.IsEmpty())
- {
- dValue = 0;
- strValue = fcvt(dValue,iDec,&iDec2,&bNegative);
- }
-
- if (iDec2 < 0)
- {
- for (int iNum = 0; iNum < abs(iDec2); iNum++)
- {
- strValue = "0" + strValue;
- }
- iDec2 = 0;
-
- }
- int iMax = strValue.GetLength();
- if (iDec2 > iMax)
- {
- for (int iNum = 0; iNum <= iDec2 - iMax; iNum++)
- {
- strValue += "0";
- }
- iMax = iDec2+1;
- }
- ///////////////////////////////////////////////////////
+ {
+ dValue = 0;
+ strValue = fcvt(dValue,iDec,&iDec2,&bNegative);
+ }
+
+ if (iDec2 < 0)
+ {
+ for (int iNum = 0; iNum < abs(iDec2); iNum++)
+ {
+ strValue = "0" + strValue;
+ }
+ iDec2 = 0;
+
+ }
+ int iMax = strValue.GetLength();
+ if (iDec2 > iMax)
+ {
+ for (int iNum = 0; iNum <= iDec2 - iMax; iNum++)
+ {
+ strValue += "0";
+ }
+ iMax = iDec2+1;
+ }
+ ///////////////////////////////////////////////////////
//for processing seperator style
- if (iDec2 < iMax)
- {
- if (iSepStyle == 0 || iSepStyle == 1)
- {
- strValue.Insert(iDec2, '.');
- iMax++;
- }
- else if (iSepStyle == 2 || iSepStyle == 3)
- {
- strValue.Insert(iDec2, ',');
- iMax++;
- }
-
- if (iDec2 == 0)
- strValue.Insert(iDec2, '0');
- }
- if (iSepStyle == 0 || iSepStyle == 2)
- {
- char cSeperator;
- if (iSepStyle == 0)
- cSeperator = ',';
- else
- cSeperator = '.';
-
- int iDecPositive;
- iDecPositive = iDec2;
-
- for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3)
- {
- strValue.Insert(iDecPositive,cSeperator);
- iMax++;
- }
- }
- ////////////////////////////////////////////////////////////////////
- //negative mark
- if(bNegative)
- strValue = "-" + strValue;
- strValue += "%";
- Value = CFX_WideString::FromLocal(strValue);
+ if (iDec2 < iMax)
+ {
+ if (iSepStyle == 0 || iSepStyle == 1)
+ {
+ strValue.Insert(iDec2, '.');
+ iMax++;
+ }
+ else if (iSepStyle == 2 || iSepStyle == 3)
+ {
+ strValue.Insert(iDec2, ',');
+ iMax++;
+ }
+
+ if (iDec2 == 0)
+ strValue.Insert(iDec2, '0');
+ }
+ if (iSepStyle == 0 || iSepStyle == 2)
+ {
+ char cSeperator;
+ if (iSepStyle == 0)
+ cSeperator = ',';
+ else
+ cSeperator = '.';
+
+ int iDecPositive;
+ iDecPositive = iDec2;
+
+ for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3)
+ {
+ strValue.Insert(iDecPositive,cSeperator);
+ iMax++;
+ }
+ }
+ ////////////////////////////////////////////////////////////////////
+ //negative mark
+ if(bNegative)
+ strValue = "-" + strValue;
+ strValue += "%";
+ Value = CFX_WideString::FromLocal(strValue);
#endif
- return TRUE;
+ return TRUE;
}
//AFPercent_Keystroke(nDec, sepStyle)
FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return AFNumber_Keystroke(cc,params,vRet,sError);
+ return AFNumber_Keystroke(cc,params,vRet,sError);
}
//function AFDate_FormatEx(cFormat)
FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
- if(!pEvent->m_pValue)
- return FALSE;
-
- CFX_WideString& val = pEvent->Value();
- CFX_WideString strValue = val;
- if (strValue.IsEmpty())
- return TRUE;
-
- CFX_WideString sFormat = params[0].ToCFXWideString();
- FX_BOOL bWrongFormat = FALSE;
- double dDate = 0.0f;
-
- if(strValue.Find(L"GMT") != -1)
- {
- //for GMT format time
- //such as "Tue Aug 11 14:24:16 GMT+08002009"
- dDate = MakeInterDate(strValue);
- }
- else
- {
- dDate = MakeRegularDate(strValue,sFormat,bWrongFormat);
- }
-
- if (JS_PortIsNan(dDate))
- {
- CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str());
- Alert(pContext, swMsg.c_str());
- return FALSE;
- }
-
- val = MakeFormatDate(dDate,sFormat);
- return TRUE;
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+ if(!pEvent->m_pValue)
+ return FALSE;
+
+ CFX_WideString& val = pEvent->Value();
+ CFX_WideString strValue = val;
+ if (strValue.IsEmpty())
+ return TRUE;
+
+ CFX_WideString sFormat = params[0].ToCFXWideString();
+ FX_BOOL bWrongFormat = FALSE;
+ double dDate = 0.0f;
+
+ if(strValue.Find(L"GMT") != -1)
+ {
+ //for GMT format time
+ //such as "Tue Aug 11 14:24:16 GMT+08002009"
+ dDate = MakeInterDate(strValue);
+ }
+ else
+ {
+ dDate = MakeRegularDate(strValue,sFormat,bWrongFormat);
+ }
+
+ if (JS_PortIsNan(dDate))
+ {
+ CFX_WideString swMsg;
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str());
+ Alert(pContext, swMsg.c_str());
+ return FALSE;
+ }
+
+ val = MakeFormatDate(dDate,sFormat);
+ return TRUE;
}
double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue)
{
- int nHour;
- int nMin;
- int nSec;
- int nYear;
- int nMonth;
- int nDay;
-
- CFX_WideStringArray wsArray;
- CFX_WideString sMonth = L"";
- CFX_WideString sTemp = L"";
- int nSize = strValue.GetLength();
-
- for(int i = 0; i < nSize; i++)
- {
- FX_WCHAR c = strValue.GetAt(i);
- if(c == L' ' || c == L':')
- {
- wsArray.Add(sTemp);
- sTemp = L"";
- continue;
- }
-
- sTemp += c;
- }
-
- wsArray.Add(sTemp);
- if(wsArray.GetSize() != 8)return 0;
-
- sTemp = wsArray[1];
- if(sTemp.Compare(L"Jan") == 0) nMonth = 1;
- if(sTemp.Compare(L"Feb") == 0) nMonth = 2;
- if(sTemp.Compare(L"Mar") == 0) nMonth = 3;
- if(sTemp.Compare(L"Apr") == 0) nMonth = 4;
- if(sTemp.Compare(L"May") == 0) nMonth = 5;
- if(sTemp.Compare(L"Jun") == 0) nMonth = 6;
- if(sTemp.Compare(L"Jul") == 0) nMonth = 7;
- if(sTemp.Compare(L"Aug") == 0) nMonth = 8;
- if(sTemp.Compare(L"Sep") == 0) nMonth = 9;
- if(sTemp.Compare(L"Oct") == 0) nMonth = 10;
- if(sTemp.Compare(L"Nov") == 0) nMonth = 11;
- if(sTemp.Compare(L"Dec") == 0) nMonth = 12;
-
- nDay = (int)ParseStringToNumber(wsArray[2].c_str());
- nHour = (int)ParseStringToNumber(wsArray[3].c_str());
- nMin = (int)ParseStringToNumber(wsArray[4].c_str());
- nSec = (int)ParseStringToNumber(wsArray[5].c_str());
- nYear = (int)ParseStringToNumber(wsArray[7].c_str());
-
- double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
-
- if (JS_PortIsNan(dRet))
- {
- dRet = JS_DateParse(strValue.c_str());
- }
-
- return dRet;
+ int nHour;
+ int nMin;
+ int nSec;
+ int nYear;
+ int nMonth;
+ int nDay;
+
+ CFX_WideStringArray wsArray;
+ CFX_WideString sMonth = L"";
+ CFX_WideString sTemp = L"";
+ int nSize = strValue.GetLength();
+
+ for(int i = 0; i < nSize; i++)
+ {
+ FX_WCHAR c = strValue.GetAt(i);
+ if(c == L' ' || c == L':')
+ {
+ wsArray.Add(sTemp);
+ sTemp = L"";
+ continue;
+ }
+
+ sTemp += c;
+ }
+
+ wsArray.Add(sTemp);
+ if(wsArray.GetSize() != 8)return 0;
+
+ sTemp = wsArray[1];
+ if(sTemp.Compare(L"Jan") == 0) nMonth = 1;
+ if(sTemp.Compare(L"Feb") == 0) nMonth = 2;
+ if(sTemp.Compare(L"Mar") == 0) nMonth = 3;
+ if(sTemp.Compare(L"Apr") == 0) nMonth = 4;
+ if(sTemp.Compare(L"May") == 0) nMonth = 5;
+ if(sTemp.Compare(L"Jun") == 0) nMonth = 6;
+ if(sTemp.Compare(L"Jul") == 0) nMonth = 7;
+ if(sTemp.Compare(L"Aug") == 0) nMonth = 8;
+ if(sTemp.Compare(L"Sep") == 0) nMonth = 9;
+ if(sTemp.Compare(L"Oct") == 0) nMonth = 10;
+ if(sTemp.Compare(L"Nov") == 0) nMonth = 11;
+ if(sTemp.Compare(L"Dec") == 0) nMonth = 12;
+
+ nDay = (int)ParseStringToNumber(wsArray[2].c_str());
+ nHour = (int)ParseStringToNumber(wsArray[3].c_str());
+ nMin = (int)ParseStringToNumber(wsArray[4].c_str());
+ nSec = (int)ParseStringToNumber(wsArray[5].c_str());
+ nYear = (int)ParseStringToNumber(wsArray[7].c_str());
+
+ double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
+
+ if (JS_PortIsNan(dRet))
+ {
+ dRet = JS_DateParse(strValue.c_str());
+ }
+
+ return dRet;
}
//AFDate_KeystrokeEx(cFormat)
FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 1)
- {
- sError = L"AFDate_KeystrokeEx's parameters' size r not correct";
- return FALSE;
- }
-
- if (pEvent->WillCommit())
- {
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString strValue = pEvent->Value();
- if (strValue.IsEmpty())
- return TRUE;
-
- CFX_WideString sFormat = params[0].ToCFXWideString();
- FX_BOOL bWrongFormat = FALSE;
- double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat);
- if (bWrongFormat || JS_PortIsNan(dRet))
- {
- CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str());
- Alert(pContext, swMsg.c_str());
- pEvent->Rc() = FALSE;
- return TRUE;
- }
- }
- return TRUE;
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = L"AFDate_KeystrokeEx's parameters' size r not correct";
+ return FALSE;
+ }
+
+ if (pEvent->WillCommit())
+ {
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString strValue = pEvent->Value();
+ if (strValue.IsEmpty())
+ return TRUE;
+
+ CFX_WideString sFormat = params[0].ToCFXWideString();
+ FX_BOOL bWrongFormat = FALSE;
+ double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat);
+ if (bWrongFormat || JS_PortIsNan(dRet))
+ {
+ CFX_WideString swMsg;
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str());
+ Alert(pContext, swMsg.c_str());
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+ }
+ return TRUE;
}
FX_BOOL CJS_PublicMethods::AFDate_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- int iIndex = params[0].ToInt();
- const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy",
- L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy",
- L"m/d/yy h:MM tt", L"m/d/yy HH:MM" };
-
- ASSERT(iIndex < FX_ArraySize(cFormats));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= FX_ArraySize(cFormats))
- iIndex = 0;
- CJS_Parameters newParams;
- CJS_Value val(isolate,cFormats[iIndex]);
- newParams.push_back(val);
- return AFDate_FormatEx(cc,newParams,vRet,sError);
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ int iIndex = params[0].ToInt();
+ const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy",
+ L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy",
+ L"m/d/yy h:MM tt", L"m/d/yy HH:MM" };
+
+ ASSERT(iIndex < FX_ArraySize(cFormats));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= FX_ArraySize(cFormats))
+ iIndex = 0;
+ CJS_Parameters newParams;
+ CJS_Value val(isolate,cFormats[iIndex]);
+ newParams.push_back(val);
+ return AFDate_FormatEx(cc,newParams,vRet,sError);
}
//AFDate_KeystrokeEx(cFormat)
FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- int iIndex = params[0].ToInt();
- const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy",
- L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy",
- L"m/d/yy h:MM tt", L"m/d/yy HH:MM" };
-
- ASSERT(iIndex<FX_ArraySize(cFormats));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= FX_ArraySize(cFormats))
- iIndex = 0;
- CJS_Parameters newParams;
- CJS_Value val(isolate,cFormats[iIndex]);
- newParams.push_back(val);
- return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ int iIndex = params[0].ToInt();
+ const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy",
+ L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy",
+ L"m/d/yy h:MM tt", L"m/d/yy HH:MM" };
+
+ ASSERT(iIndex<FX_ArraySize(cFormats));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= FX_ArraySize(cFormats))
+ iIndex = 0;
+ CJS_Parameters newParams;
+ CJS_Value val(isolate,cFormats[iIndex]);
+ newParams.push_back(val);
+ return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
}
//function AFTime_Format(ptf)
FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- int iIndex = params[0].ToInt();
- const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"};
-
- ASSERT(iIndex<FX_ArraySize(cFormats));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= FX_ArraySize(cFormats))
- iIndex = 0;
- CJS_Parameters newParams;
- CJS_Value val(isolate,cFormats[iIndex]);
- newParams.push_back(val);
- return AFDate_FormatEx(cc,newParams,vRet,sError);
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ int iIndex = params[0].ToInt();
+ const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"};
+
+ ASSERT(iIndex<FX_ArraySize(cFormats));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= FX_ArraySize(cFormats))
+ iIndex = 0;
+ CJS_Parameters newParams;
+ CJS_Value val(isolate,cFormats[iIndex]);
+ newParams.push_back(val);
+ return AFDate_FormatEx(cc,newParams,vRet,sError);
}
FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- v8::Isolate* isolate = ::GetIsolate(cc);
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- int iIndex = params[0].ToInt();
- const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"};
-
- ASSERT(iIndex<FX_ArraySize(cFormats));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= FX_ArraySize(cFormats))
- iIndex = 0;
- CJS_Parameters newParams;
- CJS_Value val(isolate,cFormats[iIndex]);
- newParams.push_back(val);
- return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
+ v8::Isolate* isolate = ::GetIsolate(cc);
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ int iIndex = params[0].ToInt();
+ const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"};
+
+ ASSERT(iIndex<FX_ArraySize(cFormats));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= FX_ArraySize(cFormats))
+ iIndex = 0;
+ CJS_Parameters newParams;
+ CJS_Value val(isolate,cFormats[iIndex]);
+ newParams.push_back(val);
+ return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
}
FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return AFDate_FormatEx(cc,params,vRet,sError);
+ return AFDate_FormatEx(cc,params,vRet,sError);
}
FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- return AFDate_KeystrokeEx(cc,params,vRet,sError);
+ return AFDate_KeystrokeEx(cc,params,vRet,sError);
}
//function AFSpecial_Format(psf)
FX_BOOL CJS_PublicMethods::AFSpecial_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- std::string cFormat;
- int iIndex = params[0].ToInt();
-
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString& Value = pEvent->Value();
- std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str();
-
- switch (iIndex)
- {
- case 0:
- cFormat = "99999";
- break;
- case 1:
- cFormat = "99999-9999";
- break;
- case 2:
- {
- std::string NumberStr;
- util::printx("9999999999", strSrc,NumberStr);
- if (NumberStr.length() >= 10 )
- cFormat = "(999) 999-9999";
- else
- cFormat = "999-9999";
- break;
- }
- case 3:
- cFormat = "999-99-9999";
- break;
- }
-
- std::string strDes;
- util::printx(cFormat,strSrc,strDes);
- Value = CFX_WideString::FromLocal(strDes.c_str());
- return TRUE;
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ std::string cFormat;
+ int iIndex = params[0].ToInt();
+
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString& Value = pEvent->Value();
+ std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str();
+
+ switch (iIndex)
+ {
+ case 0:
+ cFormat = "99999";
+ break;
+ case 1:
+ cFormat = "99999-9999";
+ break;
+ case 2:
+ {
+ std::string NumberStr;
+ util::printx("9999999999", strSrc,NumberStr);
+ if (NumberStr.length() >= 10 )
+ cFormat = "(999) 999-9999";
+ else
+ cFormat = "999-9999";
+ break;
+ }
+ case 3:
+ cFormat = "999-99-9999";
+ break;
+ }
+
+ std::string strDes;
+ util::printx(cFormat,strSrc,strDes);
+ Value = CFX_WideString::FromLocal(strDes.c_str());
+ return TRUE;
}
//function AFSpecial_KeystrokeEx(mask)
FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
-
- ASSERT(pEvent != NULL);
-
- if (params.size() < 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString& valEvent = pEvent->Value();
-
- CFX_WideString wstrMask = params[0].ToCFXWideString();
- if (wstrMask.IsEmpty())
- return TRUE;
-
- std::wstring wstrValue = valEvent.c_str();
-
- if (pEvent->WillCommit())
- {
- if (wstrValue.empty())
- return TRUE;
- int iIndexMask = 0;
- for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); it++)
- {
- wchar_t w_Value = *it;
- if (!maskSatisfied(w_Value,wstrMask[iIndexMask]))
- break;
- iIndexMask++;
- }
-
- if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0))
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str());
- pEvent->Rc() = FALSE;
- }
- return TRUE;
- }
-
- CFX_WideString &wideChange = pEvent->Change();
- std::wstring wChange = wideChange.c_str();
- if (wChange.empty())
- return TRUE;
-
- int iIndexMask = pEvent->SelStart();
-
- if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength())
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
- pEvent->Rc() = FALSE;
- return TRUE;
- }
-
- if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
- pEvent->Rc() = FALSE;
- return TRUE;
- }
-
- for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++)
- {
- if (iIndexMask >= wstrMask.GetLength())
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
- pEvent->Rc() = FALSE;
- return TRUE;
- }
- wchar_t w_Mask = wstrMask[iIndexMask];
- if (!isReservedMaskChar(w_Mask))
- {
- *it = w_Mask;
- }
- wchar_t w_Change = *it;
- if (!maskSatisfied(w_Change,w_Mask))
- {
- pEvent->Rc() = FALSE;
- return TRUE;
- }
- iIndexMask++;
- }
-
- wideChange = wChange.c_str();
- return TRUE;
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+
+ ASSERT(pEvent != NULL);
+
+ if (params.size() < 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString& valEvent = pEvent->Value();
+
+ CFX_WideString wstrMask = params[0].ToCFXWideString();
+ if (wstrMask.IsEmpty())
+ return TRUE;
+
+ std::wstring wstrValue = valEvent.c_str();
+
+ if (pEvent->WillCommit())
+ {
+ if (wstrValue.empty())
+ return TRUE;
+ int iIndexMask = 0;
+ for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); it++)
+ {
+ wchar_t w_Value = *it;
+ if (!maskSatisfied(w_Value,wstrMask[iIndexMask]))
+ break;
+ iIndexMask++;
+ }
+
+ if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0))
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str());
+ pEvent->Rc() = FALSE;
+ }
+ return TRUE;
+ }
+
+ CFX_WideString &wideChange = pEvent->Change();
+ std::wstring wChange = wideChange.c_str();
+ if (wChange.empty())
+ return TRUE;
+
+ int iIndexMask = pEvent->SelStart();
+
+ if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength())
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+
+ if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+
+ for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++)
+ {
+ if (iIndexMask >= wstrMask.GetLength())
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+ wchar_t w_Mask = wstrMask[iIndexMask];
+ if (!isReservedMaskChar(w_Mask))
+ {
+ *it = w_Mask;
+ }
+ wchar_t w_Change = *it;
+ if (!maskSatisfied(w_Change,w_Mask))
+ {
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+ iIndexMask++;
+ }
+
+ wideChange = wChange.c_str();
+ return TRUE;
}
//function AFSpecial_Keystroke(psf)
FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- std::string cFormat;
- int iIndex = params[0].ToInt();
-
- if(!pEvent->m_pValue)
- return FALSE;
- //CJS_Value val = pEvent->Value();
- CFX_WideString& val = pEvent->Value();
- std::string strSrc = CFX_ByteString::FromUnicode(val).c_str();
- std::wstring wstrChange = pEvent->Change().c_str();
-
- switch (iIndex)
- {
- case 0:
- cFormat = "99999";
- break;
- case 1:
- //cFormat = "99999-9999";
- cFormat = "999999999";
- break;
- case 2:
- {
- std::string NumberStr;
- util::printx("9999999999", strSrc,NumberStr);
- if (strSrc.length() + wstrChange.length() > 7 )
- //cFormat = "(999) 999-9999";
- cFormat = "9999999999";
- else
- //cFormat = "999-9999";
- cFormat = "9999999";
- break;
- }
- case 3:
- //cFormat = "999-99-9999";
- cFormat = "999999999";
- break;
- }
-
- CJS_Parameters params2;
- CJS_Value vMask(isolate, cFormat.c_str());
- params2.push_back(vMask);
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ std::string cFormat;
+ int iIndex = params[0].ToInt();
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ //CJS_Value val = pEvent->Value();
+ CFX_WideString& val = pEvent->Value();
+ std::string strSrc = CFX_ByteString::FromUnicode(val).c_str();
+ std::wstring wstrChange = pEvent->Change().c_str();
+
+ switch (iIndex)
+ {
+ case 0:
+ cFormat = "99999";
+ break;
+ case 1:
+ //cFormat = "99999-9999";
+ cFormat = "999999999";
+ break;
+ case 2:
+ {
+ std::string NumberStr;
+ util::printx("9999999999", strSrc,NumberStr);
+ if (strSrc.length() + wstrChange.length() > 7 )
+ //cFormat = "(999) 999-9999";
+ cFormat = "9999999999";
+ else
+ //cFormat = "999-9999";
+ cFormat = "9999999";
+ break;
+ }
+ case 3:
+ //cFormat = "999-99-9999";
+ cFormat = "999999999";
+ break;
+ }
+
+ CJS_Parameters params2;
+ CJS_Value vMask(isolate, cFormat.c_str());
+ params2.push_back(vMask);
return AFSpecial_KeystrokeEx(cc,params2,vRet,sError);
}
FX_BOOL CJS_PublicMethods::AFMergeChange(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
- ASSERT(pEventHandler != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CFX_WideString swValue;
- if (pEventHandler->m_pValue != NULL)
- swValue = pEventHandler->Value();
-
- if (pEventHandler->WillCommit())
- {
- vRet = swValue.c_str();
- return TRUE;
- }
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
+ ASSERT(pEventHandler != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CFX_WideString swValue;
+ if (pEventHandler->m_pValue != NULL)
+ swValue = pEventHandler->Value();
+
+ if (pEventHandler->WillCommit())
+ {
+ vRet = swValue.c_str();
+ return TRUE;
+ }
- CFX_WideString prefix,postfix;
+ CFX_WideString prefix,postfix;
- if (pEventHandler->SelStart() >= 0)
- prefix = swValue.Mid(0,pEventHandler->SelStart());
- else
- prefix = L"";
+ if (pEventHandler->SelStart() >= 0)
+ prefix = swValue.Mid(0,pEventHandler->SelStart());
+ else
+ prefix = L"";
- if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLength())
- postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEventHandler->SelEnd());
- else postfix = L"";
+ if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLength())
+ postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEventHandler->SelEnd());
+ else postfix = L"";
- vRet = (prefix + pEventHandler->Change() + postfix).c_str();
+ vRet = (prefix + pEventHandler->Change() + postfix).c_str();
- return TRUE;
+ return TRUE;
}
FX_BOOL CJS_PublicMethods::AFParseDateEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- if (params.size() != 2)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CFX_WideString sValue = params[0].ToCFXWideString();
- CFX_WideString sFormat = params[1].ToCFXWideString();
-
- FX_BOOL bWrongFormat = FALSE;
- double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
-
- if (JS_PortIsNan(dDate))
- {
- CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str());
- Alert((CJS_Context *)cc, swMsg.c_str());
- return FALSE;
- }
-
- vRet = dDate;
- return TRUE;
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ if (params.size() != 2)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CFX_WideString sValue = params[0].ToCFXWideString();
+ CFX_WideString sFormat = params[1].ToCFXWideString();
+
+ FX_BOOL bWrongFormat = FALSE;
+ double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
+
+ if (JS_PortIsNan(dDate))
+ {
+ CFX_WideString swMsg;
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str());
+ Alert((CJS_Context *)cc, swMsg.c_str());
+ return FALSE;
+ }
+
+ vRet = dDate;
+ return TRUE;
}
FX_BOOL CJS_PublicMethods::AFSimple(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- if (params.size() != 3)
- {
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
+ if (params.size() != 3)
+ {
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
- vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), params[1].ToDouble(), params[2].ToDouble());
- return TRUE;
+ vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), params[1].ToDouble(), params[2].ToDouble());
+ return TRUE;
}
FX_BOOL CJS_PublicMethods::AFMakeNumber(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
- vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str());
- return TRUE;
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+ vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str());
+ return TRUE;
}
FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- v8::Isolate* isolate = ::GetIsolate(cc);
+ v8::Isolate* isolate = ::GetIsolate(cc);
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
- if (params.size() != 2)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
+ if (params.size() != 2)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
- CJS_Value params1 = params[1];
+ CJS_Value params1 = params[1];
- if (!params1.IsArrayObject() && params1.GetType() != VT_string)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
+ if (!params1.IsArrayObject() && params1.GetType() != VT_string)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
- CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
+ CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
ASSERT(pReaderDoc != NULL);
- CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
- ASSERT(pReaderInterForm != NULL);
+ CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
+ ASSERT(pReaderInterForm != NULL);
- CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
+ CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
- double dValue;
- CFX_WideString sFunction = params[0].ToCFXWideString();
- if (wcscmp(sFunction.c_str(), L"PRD") == 0)
- dValue = 1.0;
- else
- dValue = 0.0;
+ double dValue;
+ CFX_WideString sFunction = params[0].ToCFXWideString();
+ if (wcscmp(sFunction.c_str(), L"PRD") == 0)
+ dValue = 1.0;
+ else
+ dValue = 0.0;
- CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
+ CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
- int nFieldsCount = 0;
+ int nFieldsCount = 0;
- for (int i=0,isz=FieldNameArray.GetLength(); i<isz; i++)
- {
- CJS_Value jsValue(isolate);
- FieldNameArray.GetElement(i,jsValue);
- CFX_WideString wsFieldName = jsValue.ToCFXWideString();
+ for (int i=0,isz=FieldNameArray.GetLength(); i<isz; i++)
+ {
+ CJS_Value jsValue(isolate);
+ FieldNameArray.GetElement(i,jsValue);
+ CFX_WideString wsFieldName = jsValue.ToCFXWideString();
for (int j=0,jsz=pInterForm->CountFields(wsFieldName); j<jsz; j++)
- {
- if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName))
- {
- double dTemp = 0.0;
-
- switch (pFormField->GetFieldType())
- {
- case FIELDTYPE_TEXTFIELD:
- case FIELDTYPE_COMBOBOX:
- {
- dTemp = ParseStringToNumber(pFormField->GetValue().c_str());
- break;
- }
- case FIELDTYPE_PUSHBUTTON:
- {
- dTemp = 0.0;
- break;
- }
- case FIELDTYPE_CHECKBOX:
- case FIELDTYPE_RADIOBUTTON:
- {
- dTemp = 0.0;
- for (int c=0,csz=pFormField->CountControls(); c<csz; c++)
- {
- if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c))
- {
- if (pFormCtrl->IsChecked())
- {
- dTemp += ParseStringToNumber(pFormCtrl->GetExportValue().c_str());
- break;
- }
- else
- continue;
- }
- }
- break;
- }
- case FIELDTYPE_LISTBOX:
- {
- dTemp = 0.0;
- if (pFormField->CountSelectedItems() > 1)
- break;
- else
- {
- dTemp = ParseStringToNumber(pFormField->GetValue().c_str());
- break;
- }
- }
- default:
- break;
- }
-
- if (i == 0 && j == 0 && (wcscmp(sFunction.c_str(), L"MIN") == 0 || wcscmp(sFunction.c_str(), L"MAX") == 0))
- dValue = dTemp;
-
- dValue = AF_Simple(sFunction.c_str(), dValue, dTemp);
-
- nFieldsCount++;
- }
- }
- }
-
- if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0)
- dValue /= nFieldsCount;
-
- dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FXSYS_pow((double)10,(double)6);
- CJS_Value jsValue(isolate,dValue);
- if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue)
- ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue.ToCFXWideString();
-
- return TRUE;
+ {
+ if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName))
+ {
+ double dTemp = 0.0;
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_TEXTFIELD:
+ case FIELDTYPE_COMBOBOX:
+ {
+ dTemp = ParseStringToNumber(pFormField->GetValue().c_str());
+ break;
+ }
+ case FIELDTYPE_PUSHBUTTON:
+ {
+ dTemp = 0.0;
+ break;
+ }
+ case FIELDTYPE_CHECKBOX:
+ case FIELDTYPE_RADIOBUTTON:
+ {
+ dTemp = 0.0;
+ for (int c=0,csz=pFormField->CountControls(); c<csz; c++)
+ {
+ if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c))
+ {
+ if (pFormCtrl->IsChecked())
+ {
+ dTemp += ParseStringToNumber(pFormCtrl->GetExportValue().c_str());
+ break;
+ }
+ else
+ continue;
+ }
+ }
+ break;
+ }
+ case FIELDTYPE_LISTBOX:
+ {
+ dTemp = 0.0;
+ if (pFormField->CountSelectedItems() > 1)
+ break;
+ else
+ {
+ dTemp = ParseStringToNumber(pFormField->GetValue().c_str());
+ break;
+ }
+ }
+ default:
+ break;
+ }
+
+ if (i == 0 && j == 0 && (wcscmp(sFunction.c_str(), L"MIN") == 0 || wcscmp(sFunction.c_str(), L"MAX") == 0))
+ dValue = dTemp;
+
+ dValue = AF_Simple(sFunction.c_str(), dValue, dTemp);
+
+ nFieldsCount++;
+ }
+ }
+ }
+
+ if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0)
+ dValue /= nFieldsCount;
+
+ dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FXSYS_pow((double)10,(double)6);
+ CJS_Value jsValue(isolate,dValue);
+ if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue)
+ ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue.ToCFXWideString();
+
+ return TRUE;
}
/* This function validates the current event to ensure that its value is
@@ -2170,104 +2173,104 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc, const CJS_Param
FX_BOOL CJS_PublicMethods::AFRange_Validate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 4)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- if(!pEvent->m_pValue)
- return FALSE;
- if (pEvent->Value().IsEmpty() )
- return TRUE;
- double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value()));
- FX_BOOL bGreaterThan = params[0].ToBool();
- double dGreaterThan = params[1].ToDouble();
- FX_BOOL bLessThan = params[2].ToBool();
- double dLessThan = params[3].ToDouble();
- CFX_WideString swMsg;
-
- if (bGreaterThan && bLessThan)
- {
- if (dEentValue < dGreaterThan || dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(),
- params[1].ToCFXWideString().c_str(),
- params[3].ToCFXWideString().c_str());
- }
- else if (bGreaterThan)
- {
- if (dEentValue < dGreaterThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(),
- params[1].ToCFXWideString().c_str());
- }
- else if (bLessThan)
- {
- if (dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(),
- params[3].ToCFXWideString().c_str());
- }
-
- if (!swMsg.IsEmpty())
- {
- Alert(pContext, swMsg.c_str());
- pEvent->Rc() = FALSE;
- }
- return TRUE;
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 4)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ if (pEvent->Value().IsEmpty() )
+ return TRUE;
+ double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value()));
+ FX_BOOL bGreaterThan = params[0].ToBool();
+ double dGreaterThan = params[1].ToDouble();
+ FX_BOOL bLessThan = params[2].ToBool();
+ double dLessThan = params[3].ToDouble();
+ CFX_WideString swMsg;
+
+ if (bGreaterThan && bLessThan)
+ {
+ if (dEentValue < dGreaterThan || dEentValue > dLessThan)
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(),
+ params[1].ToCFXWideString().c_str(),
+ params[3].ToCFXWideString().c_str());
+ }
+ else if (bGreaterThan)
+ {
+ if (dEentValue < dGreaterThan)
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(),
+ params[1].ToCFXWideString().c_str());
+ }
+ else if (bLessThan)
+ {
+ if (dEentValue > dLessThan)
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(),
+ params[3].ToCFXWideString().c_str());
+ }
+
+ if (!swMsg.IsEmpty())
+ {
+ Alert(pContext, swMsg.c_str());
+ pEvent->Rc() = FALSE;
+ }
+ return TRUE;
}
FX_BOOL CJS_PublicMethods::AFExtractNums(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- v8::Isolate* isolate = ::GetIsolate(cc);
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CJS_Array nums(isolate);
-
- CFX_WideString str = params[0].ToCFXWideString();
- CFX_WideString sPart;
-
- if (str.GetAt(0) == L'.' || str.GetAt(0) == L',')
- str = L"0" + str;
-
- int nIndex = 0;
- for (int i=0, sz=str.GetLength(); i<sz; i++)
- {
- FX_WCHAR wc = str.GetAt(i);
- if (IsDigit((wchar_t)wc))
- {
- sPart += wc;
- }
- else
- {
- if (sPart.GetLength() > 0)
- {
- nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));
- sPart = L"";
- nIndex ++;
- }
- }
- }
-
- if (sPart.GetLength() > 0)
- {
- nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));
- }
-
- if (nums.GetLength() > 0)
- vRet = nums;
- else
- vRet.SetNull();
-
- return TRUE;
+ v8::Isolate* isolate = ::GetIsolate(cc);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CJS_Array nums(isolate);
+
+ CFX_WideString str = params[0].ToCFXWideString();
+ CFX_WideString sPart;
+
+ if (str.GetAt(0) == L'.' || str.GetAt(0) == L',')
+ str = L"0" + str;
+
+ int nIndex = 0;
+ for (int i=0, sz=str.GetLength(); i<sz; i++)
+ {
+ FX_WCHAR wc = str.GetAt(i);
+ if (IsDigit((wchar_t)wc))
+ {
+ sPart += wc;
+ }
+ else
+ {
+ if (sPart.GetLength() > 0)
+ {
+ nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));
+ sPart = L"";
+ nIndex ++;
+ }
+ }
+ }
+
+ if (sPart.GetLength() > 0)
+ {
+ nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));
+ }
+
+ if (nums.GetLength() > 0)
+ vRet = nums;
+ else
+ vRet.SetNull();
+
+ return TRUE;
}
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index 6965c8c884..6eea290f68 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -91,496 +91,509 @@ BEGIN_JS_STATIC_PROP(CJS_Global)
END_JS_STATIC_PROP()
BEGIN_JS_STATIC_METHOD(CJS_Global)
- JS_STATIC_METHOD_ENTRY(setPersistent)
+ JS_STATIC_METHOD_ENTRY(setPersistent)
END_JS_STATIC_METHOD()
IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, global_alternate, global);
-FX_BOOL CJS_Global::InitInstance(IFXJS_Context* cc)
+FX_BOOL CJS_Global::InitInstance(IFXJS_Context* cc)
{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
- global_alternate* pGlobal = (global_alternate*)GetEmbedObject();
- ASSERT(pGlobal != NULL);
+ global_alternate* pGlobal = (global_alternate*)GetEmbedObject();
+ ASSERT(pGlobal != NULL);
- pGlobal->Initial(pContext->GetReaderApp());
+ pGlobal->Initial(pContext->GetReaderApp());
- return TRUE;
+ return TRUE;
};
global_alternate::global_alternate(CJS_Object* pJSObject)
- : CJS_EmbedObj(pJSObject),
- m_pApp(NULL)
+ : CJS_EmbedObj(pJSObject),
+ m_pApp(NULL)
{
}
global_alternate::~global_alternate(void)
{
- DestroyGlobalPersisitentVariables();
- m_pApp->GetRuntimeFactory()->ReleaseGlobalData();
+ DestroyGlobalPersisitentVariables();
+ m_pApp->GetRuntimeFactory()->ReleaseGlobalData();
}
void global_alternate::Initial(CPDFDoc_Environment* pApp)
{
- m_pApp = pApp;
- m_pGlobalData = pApp->GetRuntimeFactory()->NewGlobalData(pApp);
- UpdateGlobalPersistentVariables();
+ m_pApp = pApp;
+ m_pGlobalData = pApp->GetRuntimeFactory()->NewGlobalData(pApp);
+ UpdateGlobalPersistentVariables();
}
-FX_BOOL global_alternate::QueryProperty(const FX_WCHAR* propname)
+FX_BOOL global_alternate::QueryProperty(const FX_WCHAR* propname)
{
- return CFX_WideString(propname) != L"setPersistent";
+ return CFX_WideString(propname) != L"setPersistent";
}
-FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc, const FX_WCHAR* propname, CFX_WideString& sError)
+FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc, const FX_WCHAR* propname, CFX_WideString& sError)
{
- js_global_data* pData = NULL;
- CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
+ js_global_data* pData = NULL;
+ CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
- if (m_mapGlobal.Lookup(sPropName, (void*&)pData))
- {
- pData->bDeleted = TRUE;
- return TRUE;
- }
+ if (m_mapGlobal.Lookup(sPropName, (void*&)pData))
+ {
+ pData->bDeleted = TRUE;
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc, const FX_WCHAR* propname, CJS_PropValue& vp, CFX_WideString& sError)
{
- if (vp.IsSetting())
- {
- CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
- switch (vp.GetType())
- {
- case VT_number:
- {
- double dData;
- vp >> dData;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NUMBER, dData, false, "", v8::Local<v8::Object>(), FALSE);
- }
- case VT_boolean:
- {
- bool bData;
- vp >> bData;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, bData, "", v8::Local<v8::Object>(), FALSE);
- }
- case VT_string:
- {
- CFX_ByteString sData;
- vp >> sData;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, false, sData, v8::Local<v8::Object>(), FALSE);
- }
- case VT_object:
- {
- JSObject pData;
- vp >> pData;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "", pData, FALSE);
- }
- case VT_null:
- {
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Local<v8::Object>(), FALSE);
- }
- case VT_undefined:
- {
- DelProperty(cc, propname, sError);
- return TRUE;
- }
- default:
- break;
- }
- }
- else
- {
- void* pVoid = nullptr;
- if (!m_mapGlobal.Lookup(CFX_ByteString::FromUnicode(propname), pVoid))
- {
- vp.SetNull();
- return TRUE;
- }
- if (!pVoid)
- {
- vp.SetNull();
- return TRUE;
- }
- js_global_data* pData = (js_global_data*)pVoid;
- if (pData->bDeleted)
- return TRUE;
-
- switch (pData->nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- vp << pData->dData;
- return TRUE;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- vp << pData->bData;
- return TRUE;
- case JS_GLOBALDATA_TYPE_STRING:
- vp << pData->sData;
- return TRUE;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(vp.GetIsolate(),pData->pData);
- vp << obj;
- return TRUE;
- }
- case JS_GLOBALDATA_TYPE_NULL:
- vp.SetNull();
- return TRUE;
- default:
- break;
- }
- }
- return FALSE;
+ if (vp.IsSetting())
+ {
+ CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
+ switch (vp.GetType())
+ {
+ case VT_number:
+ {
+ double dData;
+ vp >> dData;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NUMBER, dData, false, "", v8::Local<v8::Object>(), FALSE);
+ }
+ case VT_boolean:
+ {
+ bool bData;
+ vp >> bData;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, bData, "", v8::Local<v8::Object>(), FALSE);
+ }
+ case VT_string:
+ {
+ CFX_ByteString sData;
+ vp >> sData;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, false, sData, v8::Local<v8::Object>(), FALSE);
+ }
+ case VT_object:
+ {
+ JSObject pData;
+ vp >> pData;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "", pData, FALSE);
+ }
+ case VT_null:
+ {
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Local<v8::Object>(), FALSE);
+ }
+ case VT_undefined:
+ {
+ DelProperty(cc, propname, sError);
+ return TRUE;
+ }
+ default:
+ return FALSE;
+ }
+ }
+ else
+ {
+ js_global_data* pData = NULL;
+ CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
+
+ if (m_mapGlobal.Lookup(sPropName, (void*&)pData))
+ {
+ if (pData)
+ {
+ if (!pData->bDeleted)
+ {
+ switch (pData->nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ vp << pData->dData;
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ vp << pData->bData;
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ vp << pData->sData;
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(vp.GetIsolate(),pData->pData);
+ vp << obj;
+ break;
+ }
+ case JS_GLOBALDATA_TYPE_NULL:
+ vp.SetNull();
+ break;
+ default:
+ return FALSE;
+ }
+ return TRUE;
+ }
+ else
+ {
+ return TRUE;
+ }
+ }
+ else
+ {
+ vp.SetNull();
+ return TRUE;
+ }
+ }
+ else
+ {
+ vp.SetNull();
+ return TRUE;
+ }
+ }
+
+ return FALSE;
}
FX_BOOL global_alternate::setPersistent(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- if (params.size() != 2)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CFX_ByteString sName = params[0].ToCFXByteString();
-
- js_global_data* pData = NULL;
- if (m_mapGlobal.Lookup(sName, (void*&)pData))
- {
- if (pData && !pData->bDeleted)
- {
- pData->bPersistent = params[1].ToBool();
- return TRUE;
- }
- }
-
- sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL);
- return FALSE;
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ if (params.size() != 2)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CFX_ByteString sName = params[0].ToCFXByteString();
+
+ js_global_data* pData = NULL;
+ if (m_mapGlobal.Lookup(sName, (void*&)pData))
+ {
+ if (pData && !pData->bDeleted)
+ {
+ pData->bPersistent = params[1].ToBool();
+ return TRUE;
+ }
+ }
+
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL);
+ return FALSE;
}
void global_alternate::UpdateGlobalPersistentVariables()
{
- ASSERT(m_pGlobalData != NULL);
-
- for (int i=0,sz=m_pGlobalData->GetSize(); i<sz; i++)
- {
- CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i);
- ASSERT(pData != NULL);
-
- switch (pData->data.nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, pData->data.dData, false, "", v8::Local<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectNumber(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode().c_str(), pData->data.dData);
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)(pData->data.bData == 1), "", v8::Local<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectBoolean(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode().c_str(), (bool)(pData->data.bData == 1));
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, false, pData->data.sData, v8::Local<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectString(NULL, (JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode().c_str(),
- pData->data.sData.UTF8Decode().c_str());
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
- v8::Local<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
-
- PutObjectProperty(pObj, &pData->data);
-
- SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "",
- (JSObject)pObj, pData->bPersistent == 1);
- JS_PutObjectObject(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode().c_str(), (JSObject)pObj);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Local<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectNull(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode().c_str());
- break;
- }
- }
+ ASSERT(m_pGlobalData != NULL);
+
+ for (int i=0,sz=m_pGlobalData->GetSize(); i<sz; i++)
+ {
+ CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i);
+ ASSERT(pData != NULL);
+
+ switch (pData->data.nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, pData->data.dData, false, "", v8::Local<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectNumber(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode().c_str(), pData->data.dData);
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)(pData->data.bData == 1), "", v8::Local<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectBoolean(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode().c_str(), (bool)(pData->data.bData == 1));
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, false, pData->data.sData, v8::Local<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectString(NULL, (JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode().c_str(),
+ pData->data.sData.UTF8Decode().c_str());
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
+ v8::Local<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
+
+ PutObjectProperty(pObj, &pData->data);
+
+ SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "",
+ (JSObject)pObj, pData->bPersistent == 1);
+ JS_PutObjectObject(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode().c_str(), (JSObject)pObj);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Local<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectNull(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode().c_str());
+ break;
+ }
+ }
}
void global_alternate::CommitGlobalPersisitentVariables()
{
- ASSERT(m_pGlobalData != NULL);
-
- FX_POSITION pos = m_mapGlobal.GetStartPosition();
- while (pos)
- {
- CFX_ByteString name;
- js_global_data* pData = NULL;
- m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData);
-
- if (pData)
- {
- if (pData->bDeleted)
- {
- m_pGlobalData->DeleteGlobalVariable(name);
- }
- else
- {
- switch (pData->nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- m_pGlobalData->SetGlobalVariableNumber(name, pData->dData);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- m_pGlobalData->SetGlobalVariableString(name, pData->sData);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- //if (pData->pData)
- {
- CJS_GlobalVariableArray array;
- v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(GetJSObject()->GetIsolate(),pData->pData);
- ObjectToArray(obj, array);
- m_pGlobalData->SetGlobalVariableObject(name, array);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- m_pGlobalData->SetGlobalVariableNull(name);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- break;
- }
- }
- }
- }
+ ASSERT(m_pGlobalData != NULL);
+
+ FX_POSITION pos = m_mapGlobal.GetStartPosition();
+ while (pos)
+ {
+ CFX_ByteString name;
+ js_global_data* pData = NULL;
+ m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData);
+
+ if (pData)
+ {
+ if (pData->bDeleted)
+ {
+ m_pGlobalData->DeleteGlobalVariable(name);
+ }
+ else
+ {
+ switch (pData->nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ m_pGlobalData->SetGlobalVariableNumber(name, pData->dData);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ m_pGlobalData->SetGlobalVariableString(name, pData->sData);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ //if (pData->pData)
+ {
+ CJS_GlobalVariableArray array;
+ v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(GetJSObject()->GetIsolate(),pData->pData);
+ ObjectToArray(obj, array);
+ m_pGlobalData->SetGlobalVariableObject(name, array);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ m_pGlobalData->SetGlobalVariableNull(name);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ break;
+ }
+ }
+ }
+ }
}
void global_alternate::ObjectToArray(v8::Local<v8::Object> pObj, CJS_GlobalVariableArray& array)
{
- v8::Local<v8::Context> context = pObj->CreationContext();
- v8::Isolate* isolate = context->GetIsolate();
- v8::Local<v8::Array> pKeyList = JS_GetObjectElementNames(isolate, pObj);
- int nObjElements = pKeyList->Length();
-
- for (int i=0; i<nObjElements; i++)
- {
-
- CFX_WideString ws = JS_ToString(isolate, JS_GetArrayElement(isolate, pKeyList, i));
- CFX_ByteString sKey = ws.UTF8Encode();
-
- v8::Local<v8::Value> v = JS_GetObjectElement(isolate, pObj, ws.c_str());
- FXJSVALUETYPE vt = GET_VALUE_TYPE(v);
- switch (vt)
- {
- case VT_number:
- {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_NUMBER;
- pObjElement->sKey = sKey;
- pObjElement->dData = JS_ToNumber(isolate, v);
- array.Add(pObjElement);
- }
- break;
- case VT_boolean:
- {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
- pObjElement->sKey = sKey;
- pObjElement->dData = JS_ToBoolean(isolate, v);
- array.Add(pObjElement);
- }
- break;
- case VT_string:
- {
- CFX_ByteString sValue = CJS_Value(isolate, v, VT_string).ToCFXByteString();
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_STRING;
- pObjElement->sKey = sKey;
- pObjElement->sData = sValue;
- array.Add(pObjElement);
- }
- break;
- case VT_object:
- {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT;
- pObjElement->sKey = sKey;
- ObjectToArray(JS_ToObject(isolate, v), pObjElement->objData);
- array.Add(pObjElement);
- }
- break;
- case VT_null:
- {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_NULL;
- pObjElement->sKey = sKey;
- array.Add(pObjElement);
- }
- break;
- default:
- break;
- }
- }
+ v8::Local<v8::Context> context = pObj->CreationContext();
+ v8::Isolate* isolate = context->GetIsolate();
+ v8::Local<v8::Array> pKeyList = JS_GetObjectElementNames(isolate, pObj);
+ int nObjElements = pKeyList->Length();
+
+ for (int i=0; i<nObjElements; i++)
+ {
+
+ CFX_WideString ws = JS_ToString(isolate, JS_GetArrayElement(isolate, pKeyList, i));
+ CFX_ByteString sKey = ws.UTF8Encode();
+
+ v8::Local<v8::Value> v = JS_GetObjectElement(isolate, pObj, ws.c_str());
+ FXJSVALUETYPE vt = GET_VALUE_TYPE(v);
+ switch (vt)
+ {
+ case VT_number:
+ {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_NUMBER;
+ pObjElement->sKey = sKey;
+ pObjElement->dData = JS_ToNumber(isolate, v);
+ array.Add(pObjElement);
+ }
+ break;
+ case VT_boolean:
+ {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
+ pObjElement->sKey = sKey;
+ pObjElement->dData = JS_ToBoolean(isolate, v);
+ array.Add(pObjElement);
+ }
+ break;
+ case VT_string:
+ {
+ CFX_ByteString sValue = CJS_Value(isolate, v, VT_string).ToCFXByteString();
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_STRING;
+ pObjElement->sKey = sKey;
+ pObjElement->sData = sValue;
+ array.Add(pObjElement);
+ }
+ break;
+ case VT_object:
+ {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT;
+ pObjElement->sKey = sKey;
+ ObjectToArray(JS_ToObject(isolate, v), pObjElement->objData);
+ array.Add(pObjElement);
+ }
+ break;
+ case VT_null:
+ {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_NULL;
+ pObjElement->sKey = sKey;
+ array.Add(pObjElement);
+ }
+ break;
+ default:
+ break;
+ }
+ }
}
void global_alternate::PutObjectProperty(v8::Local<v8::Object> pObj, CJS_KeyValue* pData)
{
- ASSERT(pData != NULL);
-
- for (int i=0,sz=pData->objData.Count(); i<sz; i++)
- {
- CJS_KeyValue* pObjData = pData->objData.GetAt(i);
- ASSERT(pObjData != NULL);
-
- switch (pObjData->nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- JS_PutObjectNumber(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), pObjData->dData);
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- JS_PutObjectBoolean(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), (bool)(pObjData->bData == 1));
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- JS_PutObjectString(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), pObjData->sData.UTF8Decode().c_str());
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
- v8::Local<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
- PutObjectProperty(pNewObj, pObjData);
- JS_PutObjectObject(NULL, (JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), (JSObject)pNewObj);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- JS_PutObjectNull(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str());
- break;
- }
- }
+ ASSERT(pData != NULL);
+
+ for (int i=0,sz=pData->objData.Count(); i<sz; i++)
+ {
+ CJS_KeyValue* pObjData = pData->objData.GetAt(i);
+ ASSERT(pObjData != NULL);
+
+ switch (pObjData->nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ JS_PutObjectNumber(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), pObjData->dData);
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ JS_PutObjectBoolean(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), (bool)(pObjData->bData == 1));
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ JS_PutObjectString(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), pObjData->sData.UTF8Decode().c_str());
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
+ v8::Local<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
+ PutObjectProperty(pNewObj, pObjData);
+ JS_PutObjectObject(NULL, (JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), (JSObject)pNewObj);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ JS_PutObjectNull(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str());
+ break;
+ }
+ }
}
void global_alternate::DestroyGlobalPersisitentVariables()
{
- FX_POSITION pos = m_mapGlobal.GetStartPosition();
- while (pos)
- {
- CFX_ByteString name;
- js_global_data* pData = NULL;
- m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData);
- delete pData;
- }
-
- m_mapGlobal.RemoveAll();
+ FX_POSITION pos = m_mapGlobal.GetStartPosition();
+ while (pos)
+ {
+ CFX_ByteString name;
+ js_global_data* pData = NULL;
+ m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData);
+ delete pData;
+ }
+
+ m_mapGlobal.RemoveAll();
}
FX_BOOL global_alternate::SetGlobalVariables(const FX_CHAR* propname, int nType,
- double dData, bool bData, const CFX_ByteString& sData, JSObject pData, bool bDefaultPersistent)
+ double dData, bool bData, const CFX_ByteString& sData, JSObject pData, bool bDefaultPersistent)
{
- if (propname == NULL) return FALSE;
-
- js_global_data* pTemp = NULL;
- m_mapGlobal.Lookup(propname, (void*&)pTemp);
-
- if (pTemp)
- {
- if (pTemp->bDeleted || pTemp->nType != nType)
- {
- pTemp->dData = 0;
- pTemp->bData = 0;
- pTemp->sData = "";
- pTemp->nType = nType;
- }
-
- pTemp->bDeleted = FALSE;
-
- switch (nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- pTemp->dData = dData;
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- pTemp->bData = bData;
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- pTemp->sData = sData;
- }
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- pTemp->pData.Reset(JS_GetRuntime(pData), pData);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- break;
- default:
- return FALSE;
- }
-
- return TRUE;
- }
-
- js_global_data* pNewData = NULL;
-
- switch (nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER;
- pNewData->dData = dData;
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
- pNewData->bData = bData;
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_STRING;
- pNewData->sData = sData;
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_OBJECT;
- pNewData->pData.Reset(JS_GetRuntime(pData), pData);
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_NULL;
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- default:
- return FALSE;
- }
-
- m_mapGlobal.SetAt(propname, (void*)pNewData);
-
- return TRUE;
+ if (propname == NULL) return FALSE;
+
+ js_global_data* pTemp = NULL;
+ m_mapGlobal.Lookup(propname, (void*&)pTemp);
+
+ if (pTemp)
+ {
+ if (pTemp->bDeleted || pTemp->nType != nType)
+ {
+ pTemp->dData = 0;
+ pTemp->bData = 0;
+ pTemp->sData = "";
+ pTemp->nType = nType;
+ }
+
+ pTemp->bDeleted = FALSE;
+
+ switch (nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ pTemp->dData = dData;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ pTemp->bData = bData;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ pTemp->sData = sData;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ pTemp->pData.Reset(JS_GetRuntime(pData), pData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ break;
+ default:
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ js_global_data* pNewData = NULL;
+
+ switch (nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER;
+ pNewData->dData = dData;
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
+ pNewData->bData = bData;
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_STRING;
+ pNewData->sData = sData;
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_OBJECT;
+ pNewData->pData.Reset(JS_GetRuntime(pData), pData);
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_NULL;
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ default:
+ return FALSE;
+ }
+
+ m_mapGlobal.SetAt(propname, (void*)pNewData);
+
+ return TRUE;
}
FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p)
@@ -606,3 +619,4 @@ FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p)
return VT_unknown;
}
+
diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp
index 4083ed58da..c4f03093a7 100644
--- a/fpdfsdk/src/javascript/util.cpp
+++ b/fpdfsdk/src/javascript/util.cpp
@@ -22,13 +22,13 @@
static v8::Isolate* GetIsolate(IFXJS_Context* cc)
{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
- return pRuntime->GetIsolate();
+ return pRuntime->GetIsolate();
}
BEGIN_JS_STATIC_CONST(CJS_Util)
@@ -38,11 +38,11 @@ BEGIN_JS_STATIC_PROP(CJS_Util)
END_JS_STATIC_PROP()
BEGIN_JS_STATIC_METHOD(CJS_Util)
- JS_STATIC_METHOD_ENTRY(printd)
- JS_STATIC_METHOD_ENTRY(printf)
- JS_STATIC_METHOD_ENTRY(printx)
- JS_STATIC_METHOD_ENTRY(scand)
- JS_STATIC_METHOD_ENTRY(byteToChar)
+ JS_STATIC_METHOD_ENTRY(printd)
+ JS_STATIC_METHOD_ENTRY(printf)
+ JS_STATIC_METHOD_ENTRY(printx)
+ JS_STATIC_METHOD_ENTRY(scand)
+ JS_STATIC_METHOD_ENTRY(byteToChar)
END_JS_STATIC_METHOD()
IMPLEMENT_JS_CLASS(CJS_Util,util)
@@ -58,539 +58,549 @@ util::~util(void)
struct stru_TbConvert
{
- const FX_WCHAR* lpszJSMark;
- const FX_WCHAR* lpszCppMark;
+ const FX_WCHAR* lpszJSMark;
+ const FX_WCHAR* lpszCppMark;
};
const stru_TbConvert fcTable[] = {
- { L"mmmm", L"%B" },
- { L"mmm", L"%b" },
- { L"mm", L"%m" },
- //"m"
- { L"dddd", L"%A" },
- { L"ddd", L"%a" },
- { L"dd", L"%d" },
- //"d", "%w",
- { L"yyyy", L"%Y" },
- { L"yy", L"%y" },
- { L"HH", L"%H" },
- //"H"
- { L"hh", L"%I" },
- //"h"
- { L"MM", L"%M" },
- //"M"
- { L"ss", L"%S" },
- //"s
- { L"TT", L"%p" },
- //"t"
+ { L"mmmm", L"%B" },
+ { L"mmm", L"%b" },
+ { L"mm", L"%m" },
+ //"m"
+ { L"dddd", L"%A" },
+ { L"ddd", L"%a" },
+ { L"dd", L"%d" },
+ //"d", "%w",
+ { L"yyyy", L"%Y" },
+ { L"yy", L"%y" },
+ { L"HH", L"%H" },
+ //"H"
+ { L"hh", L"%I" },
+ //"h"
+ { L"MM", L"%M" },
+ //"M"
+ { L"ss", L"%S" },
+ //"s
+ { L"TT", L"%p" },
+ //"t"
#if defined(_WIN32)
- { L"tt", L"%p" },
- { L"h", L"%#I" },
+ { L"tt", L"%p" },
+ { L"h", L"%#I" },
#else
- { L"tt", L"%P" },
- { L"h", L"%l" },
+ { L"tt", L"%P" },
+ { L"h", L"%l" },
#endif
};
-#define UTIL_INT 0
-#define UTIL_DOUBLE 1
-#define UTIL_STRING 2
+#define UTIL_INT 0
+#define UTIL_DOUBLE 1
+#define UTIL_STRING 2
int util::ParstDataType(std::wstring* sFormat)
{
- bool bPercent = FALSE;
- for (size_t i = 0; i < sFormat->length(); ++i)
- {
- wchar_t c = (*sFormat)[i];
- if (c == L'%')
- {
- bPercent = true;
- continue;
- }
-
- if (bPercent)
- {
- if (c == L'c' || c == L'C' || c == L'd' || c == L'i' || c == L'o' || c == L'u' || c == L'x' || c == L'X')
- {
- return UTIL_INT;
- }
- if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G')
- {
- return UTIL_DOUBLE;
- }
- if (c == L's' || c == L'S')
- {
- // Map s to S since we always deal internally
- // with wchar_t strings.
- (*sFormat)[i] = L'S';
- return UTIL_STRING;
- }
- if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' || CJS_PublicMethods::IsDigit(c))
- {
- continue;
- }
- break;
- }
- }
-
- return -1;
+ size_t i = 0;
+ bool bPercent = FALSE;
+ for (i=0; i<sFormat->length(); ++i)
+ {
+ wchar_t c = (*sFormat)[i];
+ if (c == L'%')
+ {
+ bPercent = true;
+ continue;
+ }
+
+ if (bPercent)
+ {
+ if (c == L'c' || c == L'C' || c == L'd' || c == L'i' || c == L'o' || c == L'u' || c == L'x' || c == L'X')
+ {
+ return UTIL_INT;
+ }
+ else if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G')
+ {
+ return UTIL_DOUBLE;
+ }
+ else if (c == L's' || c == L'S')
+ {
+ // Map s to S since we always deal internally
+ // with wchar_t strings.
+ (*sFormat)[i] = L'S';
+ return UTIL_STRING;
+ }
+ else if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' || CJS_PublicMethods::IsDigit(c))
+ {
+ continue;
+ }
+ else break;
+ }
+ }
+
+ return -1;
}
FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- int iSize = params.size();
- if (iSize < 1)
- return FALSE;
- std::wstring c_ConvChar(params[0].ToCFXWideString().c_str());
- std::vector<std::wstring> c_strConvers;
- int iOffset = 0;
- int iOffend = 0;
- c_ConvChar.insert(c_ConvChar.begin(),L'S');
- while(iOffset != -1)
- {
- iOffend = c_ConvChar.find(L"%",iOffset+1);
- std::wstring strSub;
- if (iOffend == -1)
- strSub = c_ConvChar.substr(iOffset);
- else
- strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset);
- c_strConvers.push_back(strSub);
- iOffset = iOffend ;
- }
-
- std::wstring c_strResult;
-
- //for(int iIndex = 1;iIndex < params.size();iIndex++)
- std::wstring c_strFormat;
- for(int iIndex = 0;iIndex < (int)c_strConvers.size();iIndex++)
- {
- c_strFormat = c_strConvers[iIndex];
- if (iIndex == 0)
- {
- c_strResult = c_strFormat;
- continue;
- }
-
-
- CFX_WideString strSegment;
- if (iIndex >= iSize) {
- c_strResult += c_strFormat;
- continue;
- }
-
- switch (ParstDataType(&c_strFormat))
- {
- case UTIL_INT:
- strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt());
- break;
- case UTIL_DOUBLE:
- strSegment.Format(c_strFormat.c_str(), params[iIndex].ToDouble());
- break;
- case UTIL_STRING:
- strSegment.Format(c_strFormat.c_str(), params[iIndex].ToCFXWideString().c_str());
- break;
- default:
- strSegment.Format(L"%S", c_strFormat.c_str());
- break;
- }
- c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1);
- }
-
- c_strResult.erase(c_strResult.begin());
- vRet = c_strResult.c_str();
- return TRUE;
+ int iSize = params.size();
+ if (iSize < 1)
+ return FALSE;
+ std::wstring c_ConvChar(params[0].ToCFXWideString().c_str());
+ std::vector<std::wstring> c_strConvers;
+ int iOffset = 0;
+ int iOffend = 0;
+ c_ConvChar.insert(c_ConvChar.begin(),L'S');
+ while(iOffset != -1)
+ {
+ iOffend = c_ConvChar.find(L"%",iOffset+1);
+ std::wstring strSub;
+ if (iOffend == -1)
+ strSub = c_ConvChar.substr(iOffset);
+ else
+ strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset);
+ c_strConvers.push_back(strSub);
+ iOffset = iOffend ;
+ }
+
+ std::wstring c_strResult;
+
+ //for(int iIndex = 1;iIndex < params.size();iIndex++)
+ std::wstring c_strFormat;
+ for(int iIndex = 0;iIndex < (int)c_strConvers.size();iIndex++)
+ {
+ c_strFormat = c_strConvers[iIndex];
+ if (iIndex == 0)
+ {
+ c_strResult = c_strFormat;
+ continue;
+ }
+
+
+ CFX_WideString strSegment;
+ if (iIndex >= iSize) {
+ c_strResult += c_strFormat;
+ continue;
+ }
+
+ switch (ParstDataType(&c_strFormat))
+ {
+ case UTIL_INT:
+ strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt());
+ break;
+ case UTIL_DOUBLE:
+ strSegment.Format(c_strFormat.c_str(), params[iIndex].ToDouble());
+ break;
+ case UTIL_STRING:
+ strSegment.Format(c_strFormat.c_str(), params[iIndex].ToCFXWideString().c_str());
+ break;
+ default:
+ strSegment.Format(L"%S", c_strFormat.c_str());
+ break;
+ }
+ c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1);
+ }
+
+ c_strResult.erase(c_strResult.begin());
+ vRet = c_strResult.c_str();
+ return TRUE;
}
FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- v8::Isolate* isolate = GetIsolate(cc);
-
- int iSize = params.size();
- if (iSize < 2)
- return FALSE;
-
- CJS_Value p1(isolate);
- p1 = params[0];
-
- CJS_Value p2 = params[1];
- CJS_Date jsDate(isolate);
- if (!p2.ConvertToDate(jsDate))
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1);
- return FALSE;
- }
-
- if (!jsDate.IsValidDate())
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2);
- return FALSE;
- }
-
- if (p1.GetType() == VT_number)
- {
- int nFormat = p1.ToInt();
- CFX_WideString swResult;
-
- switch (nFormat)
- {
- case 0:
- swResult.Format(L"D:%04d%02d%02d%02d%02d%02d",
- jsDate.GetYear(),
- jsDate.GetMonth() + 1,
- jsDate.GetDay(),
- jsDate.GetHours(),
- jsDate.GetMinutes(),
- jsDate.GetSeconds());
- break;
- case 1:
- swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d",
- jsDate.GetYear(),
- jsDate.GetMonth() + 1,
- jsDate.GetDay(),
- jsDate.GetHours(),
- jsDate.GetMinutes(),
- jsDate.GetSeconds());
- break;
- case 2:
- swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d",
- jsDate.GetYear(),
- jsDate.GetMonth() + 1,
- jsDate.GetDay(),
- jsDate.GetHours(),
- jsDate.GetMinutes(),
- jsDate.GetSeconds());
- break;
- default:
- return FALSE;
- }
-
- vRet = swResult.c_str();
- return TRUE;
- }
- if (p1.GetType() == VT_string)
- {
- std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str();
-
- bool bXFAPicture = false;
- if (iSize > 2)
- {
- bXFAPicture = params[2].ToBool();
- }
-
- if (bXFAPicture)
- {
- return FALSE; //currently, it doesn't support XFAPicture.
- }
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ int iSize = params.size();
+ if (iSize < 2)
+ return FALSE;
+
+ CJS_Value p1(isolate);
+ p1 = params[0];
+
+ CJS_Value p2 = params[1];
+ CJS_Date jsDate(isolate);
+ if (!p2.ConvertToDate(jsDate))
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1);
+ return FALSE;
+ }
+
+ if (!jsDate.IsValidDate())
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2);
+ return FALSE;
+ }
+
+ if (p1.GetType() == VT_number)
+ {
+ int nFormat = p1.ToInt();
+ CFX_WideString swResult;
+
+ switch (nFormat)
+ {
+ case 0:
+ swResult.Format(L"D:%04d%02d%02d%02d%02d%02d",
+ jsDate.GetYear(),
+ jsDate.GetMonth() + 1,
+ jsDate.GetDay(),
+ jsDate.GetHours(),
+ jsDate.GetMinutes(),
+ jsDate.GetSeconds());
+ break;
+ case 1:
+ swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d",
+ jsDate.GetYear(),
+ jsDate.GetMonth() + 1,
+ jsDate.GetDay(),
+ jsDate.GetHours(),
+ jsDate.GetMinutes(),
+ jsDate.GetSeconds());
+ break;
+ case 2:
+ swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d",
+ jsDate.GetYear(),
+ jsDate.GetMonth() + 1,
+ jsDate.GetDay(),
+ jsDate.GetHours(),
+ jsDate.GetMinutes(),
+ jsDate.GetSeconds());
+ break;
+ default:
+ return FALSE;
+ }
+
+ vRet = swResult.c_str();
+ return TRUE;
+ }
+ else if (p1.GetType() == VT_string)
+ {
+ std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str();
+
+ bool bXFAPicture = false;
+ if (iSize > 2)
+ {
+ bXFAPicture = params[2].ToBool();
+ }
+
+ if (bXFAPicture)
+ {
+ return FALSE; //currently, it doesn't support XFAPicture.
+ }
int iIndex;
- for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++)
- {
- int iStart = 0;
- int iEnd;
- while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1)
- {
- cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTable[iIndex].lpszCppMark);
- iStart = iEnd;
- }
- }
-
- int iYear,iMonth,iDay,iHour,iMin,iSec;
- iYear = jsDate.GetYear();
- iMonth = jsDate.GetMonth();
- iDay = jsDate.GetDay();
- iHour = jsDate.GetHours();
- iMin = jsDate.GetMinutes();
- iSec = jsDate.GetSeconds();
-
- struct tm time = {};
- time.tm_year = iYear-1900;
- time.tm_mon = iMonth;
- time.tm_mday = iDay;
- time.tm_hour = iHour;
- time.tm_min = iMin;
- time.tm_sec = iSec;
-
- struct stru_TbConvertAd
- {
- const FX_WCHAR* lpszJSMark;
- int iValue;
- };
-
- stru_TbConvertAd cTableAd[] ={
- { L"m", iMonth+1 },
- { L"d", iDay },
- { L"H", iHour },
- { L"h", iHour>12?iHour-12:iHour },
- { L"M", iMin },
- { L"s", iSec },
- };
-
- for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++)
- {
- wchar_t tszValue[10];
- CFX_WideString sValue;
- sValue.Format(L"%d",cTableAd[iIndex].iValue);
- memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),
+ for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++)
+ {
+ int iStart = 0;
+ int iEnd;
+ while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1)
+ {
+ cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTable[iIndex].lpszCppMark);
+ iStart = iEnd;
+ }
+ }
+
+ int iYear,iMonth,iDay,iHour,iMin,iSec;
+ iYear = jsDate.GetYear();
+ iMonth = jsDate.GetMonth();
+ iDay = jsDate.GetDay();
+ iHour = jsDate.GetHours();
+ iMin = jsDate.GetMinutes();
+ iSec = jsDate.GetSeconds();
+
+ struct tm time = {};
+ time.tm_year = iYear-1900;
+ time.tm_mon = iMonth;
+ time.tm_mday = iDay;
+ time.tm_hour = iHour;
+ time.tm_min = iMin;
+ time.tm_sec = iSec;
+ //COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
+ //CString strFormat = cppTm.Format(cFormat.c_str());
+
+ struct stru_TbConvertAd
+ {
+ const FX_WCHAR* lpszJSMark;
+ int iValue;
+ };
+
+ stru_TbConvertAd cTableAd[] ={
+ { L"m", iMonth+1 },
+ { L"d", iDay },
+ { L"H", iHour },
+ { L"h", iHour>12?iHour-12:iHour },
+ { L"M", iMin },
+ { L"s", iSec },
+ };
+
+ //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
+ for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++)
+ {
+ wchar_t tszValue[10];
+ //_itot(cTableAd[iIndex].iValue,tszValue,10);
+ CFX_WideString sValue;
+ sValue.Format(L"%d",cTableAd[iIndex].iValue);
+ memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),
(sValue.GetLength()+1)*sizeof(wchar_t));
- int iStart = 0;
- int iEnd;
- while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1)
- {
- if (iEnd > 0)
- {
- if (cFormat[iEnd-1] == L'%')
- {
- iStart = iEnd+1;
- continue;
- }
- }
- cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark), tszValue);
- iStart = iEnd;
- }
- }
-
- CFX_WideString strFormat;
- wchar_t buf[64] = {};
- strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
- cFormat = buf;
- vRet = cFormat.c_str();
- return TRUE;
- }
- return FALSE;
+ //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
+ //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
+ int iStart = 0;
+ int iEnd;
+ while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1)
+ {
+ if (iEnd > 0)
+ {
+ if (cFormat[iEnd-1] == L'%')
+ {
+ iStart = iEnd+1;
+ continue;
+ }
+ }
+ cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark), tszValue);
+ iStart = iEnd;
+ }
+ }
+
+ CFX_WideString strFormat;
+// strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
+// CString strFormat = cppTm.Format(cFormat.c_str());
+ wchar_t buf[64] = {};
+ strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
+ cFormat = buf;
+ vRet = cFormat.c_str();
+ //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1);
+ return TRUE;
+ }
+ return FALSE;
}
void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPicture, std::wstring &cPurpose)
{
- std::wstring cFormat = cFormat2;
+ std::wstring cFormat = cFormat2;
- if (bXFAPicture)
- {
- return ; //currently, it doesn't support XFAPicture.
- }
+ if (bXFAPicture)
+ {
+ return ; //currently, it doesn't support XFAPicture.
+ }
int iIndex;
- for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++)
- {
- int iStart = 0;
- int iEnd;
- while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1)
- {
- cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTable[iIndex].lpszCppMark);
- iStart = iEnd;
- }
- }
-
- int iYear,iMonth,iDay,iHour,iMin,iSec;
- iYear = jsDate.GetYear();
- iMonth = jsDate.GetMonth();
- iDay = jsDate.GetDay();
- iHour = jsDate.GetHours();
- iMin = jsDate.GetMinutes();
- iSec = jsDate.GetSeconds();
-
- struct tm time = {};
- time.tm_year = iYear-1900;
- time.tm_mon = iMonth;
- time.tm_mday = iDay;
- time.tm_hour = iHour;
- time.tm_min = iMin;
- time.tm_sec = iSec;
-// COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
- //CString strFormat = cppTm.Format(cFormat.c_str());
-
- struct stru_TbConvertAd
- {
- const FX_WCHAR* lpszJSMark;
- int iValue;
- };
-
- stru_TbConvertAd cTableAd[] ={
- { L"m", iMonth+1 },
- { L"d", iDay },
- { L"H", iHour },
- { L"h", iHour>12?iHour-12:iHour },
- { L"M", iMin },
- { L"s", iSec },
- };
-
- //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
- for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++)
- {
- wchar_t tszValue[10];
- //_itot(cTableAd[iIndex].iValue,tszValue,10);
- CFX_WideString sValue;
- sValue.Format(L"%d",cTableAd[iIndex].iValue);
- memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),sValue.GetLength()*sizeof(wchar_t));
-
-
- //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
- //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
- int iStart = 0;
- int iEnd;
- while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1)
- {
- if (iEnd > 0)
- {
- if (cFormat[iEnd-1] == L'%')
- {
- iStart = iEnd+1;
- continue;
- }
- }
- cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),tszValue);
- iStart = iEnd;
- }
- }
-
- CFX_WideString strFormat;
- wchar_t buf[64] = {};
- strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
- cFormat = buf;
- cPurpose = cFormat;
+ for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++)
+ {
+ int iStart = 0;
+ int iEnd;
+ while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1)
+ {
+ cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTable[iIndex].lpszCppMark);
+ iStart = iEnd;
+ }
+ }
+
+ int iYear,iMonth,iDay,iHour,iMin,iSec;
+ iYear = jsDate.GetYear();
+ iMonth = jsDate.GetMonth();
+ iDay = jsDate.GetDay();
+ iHour = jsDate.GetHours();
+ iMin = jsDate.GetMinutes();
+ iSec = jsDate.GetSeconds();
+
+ struct tm time = {};
+ time.tm_year = iYear-1900;
+ time.tm_mon = iMonth;
+ time.tm_mday = iDay;
+ time.tm_hour = iHour;
+ time.tm_min = iMin;
+ time.tm_sec = iSec;
+// COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
+ //CString strFormat = cppTm.Format(cFormat.c_str());
+
+ struct stru_TbConvertAd
+ {
+ const FX_WCHAR* lpszJSMark;
+ int iValue;
+ };
+
+ stru_TbConvertAd cTableAd[] ={
+ { L"m", iMonth+1 },
+ { L"d", iDay },
+ { L"H", iHour },
+ { L"h", iHour>12?iHour-12:iHour },
+ { L"M", iMin },
+ { L"s", iSec },
+ };
+
+ //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
+ for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++)
+ {
+ wchar_t tszValue[10];
+ //_itot(cTableAd[iIndex].iValue,tszValue,10);
+ CFX_WideString sValue;
+ sValue.Format(L"%d",cTableAd[iIndex].iValue);
+ memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),sValue.GetLength()*sizeof(wchar_t));
+
+
+ //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
+ //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
+ int iStart = 0;
+ int iEnd;
+ while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1)
+ {
+ if (iEnd > 0)
+ {
+ if (cFormat[iEnd-1] == L'%')
+ {
+ iStart = iEnd+1;
+ continue;
+ }
+ }
+ cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),tszValue);
+ iStart = iEnd;
+ }
+ }
+
+ CFX_WideString strFormat;
+ wchar_t buf[64] = {};
+ strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
+ cFormat = buf;
+ cPurpose = cFormat;
}
FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- int iSize = params.size();
- if (iSize<2)
- return FALSE;
- CFX_WideString sFormat = params[0].ToCFXWideString();
- CFX_WideString sSource = params[1].ToCFXWideString();
- std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str();
- std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str();
- std::string cDest;
- printx(cFormat,cSource,cDest);
- vRet = cDest.c_str();
- return TRUE;
+ int iSize = params.size();
+ if (iSize<2)
+ return FALSE;
+ CFX_WideString sFormat = params[0].ToCFXWideString();
+ CFX_WideString sSource = params[1].ToCFXWideString();
+ std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str();
+ std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str();
+ std::string cDest;
+ printx(cFormat,cSource,cDest);
+ vRet = cDest.c_str();
+ return TRUE;
}
void util::printx(const std::string &cFormat,const std::string &cSource2,std::string &cPurpose)
{
- std::string cSource(cSource2);
- if (!cPurpose.empty())
- //cPurpose.clear();
- cPurpose.erase();
- int itSource = 0;
- int iSize = cSource.size();
- for(int iIndex = 0; iIndex < (int)cFormat.size() && itSource<iSize; iIndex++)
- {
- char letter = cFormat[iIndex];
- switch(letter)
- {
- case '?':
- //cPurpose.push_back(cSource[itSource]);
- cPurpose += cSource[itSource];
- itSource++;
- break;
- case 'X':
- {
- while(itSource < iSize)
- {
- if ((cSource[itSource]>='0'&&cSource[itSource]<='9') || (cSource[itSource]>='a' && cSource[itSource]<='z') || (cSource[itSource]>='A' && cSource[itSource]<='Z'))
- {
- //cPurpose.push_back(cSource[itSource]);
- cPurpose += cSource[itSource];
- itSource++;
- break;
- }
- itSource++;
- }
- break;
- }
- break;
- case 'A':
- {
- while(itSource < iSize)
- {
- if ((cSource[itSource]>='a' && cSource[itSource]<='z') || (cSource[itSource]>='A' && cSource[itSource]<='Z'))
- {
- //cPurpose.push_back(cSource[itSource]);
- cPurpose += cSource[itSource];
- itSource++;
- break;
- }
- itSource++;
- }
- break;
- }
- break;
- case '9':
- {
- while(itSource < iSize)
- {
- if (cSource[itSource]>='0'&&cSource[itSource]<='9')
- {
- //cPurpose.push_back(cSource[itSource]);
- cPurpose += cSource[itSource];
- itSource++;
- break;
- }
- itSource++;
- }
- break;
- }
- case '*':
- {
- cPurpose.append(cSource,itSource,iSize-itSource);
- itSource = iSize-1;
- break;
- }
- case '\\':
- break;
- case '>':
- {
- for(std::string::iterator it = cSource.begin();it != cSource.end(); it++)
- {
- *it = toupper(*it);
- }
- break;
- }
- case '<':
- {
- for(std::string::iterator it = cSource.begin();it != cSource.end(); it++)
- {
- *it = tolower(*it);
- }
- break;
- }
- case '=':
- break;
- default:
- //cPurpose.push_back(letter);
- cPurpose += letter;
- break;
- }
- }
+ std::string cSource(cSource2);
+ if (!cPurpose.empty())
+ //cPurpose.clear();
+ cPurpose.erase();
+ int itSource = 0;
+ int iSize = cSource.size();
+ for(int iIndex = 0; iIndex < (int)cFormat.size() && itSource<iSize; iIndex++)
+ {
+ char letter = cFormat[iIndex];
+ switch(letter)
+ {
+ case '?':
+ //cPurpose.push_back(cSource[itSource]);
+ cPurpose += cSource[itSource];
+ itSource++;
+ break;
+ case 'X':
+ {
+ while(itSource < iSize)
+ {
+ if ((cSource[itSource]>='0'&&cSource[itSource]<='9') || (cSource[itSource]>='a' && cSource[itSource]<='z') || (cSource[itSource]>='A' && cSource[itSource]<='Z'))
+ {
+ //cPurpose.push_back(cSource[itSource]);
+ cPurpose += cSource[itSource];
+ itSource++;
+ break;
+ }
+ itSource++;
+ }
+ break;
+ }
+ break;
+ case 'A':
+ {
+ while(itSource < iSize)
+ {
+ if ((cSource[itSource]>='a' && cSource[itSource]<='z') || (cSource[itSource]>='A' && cSource[itSource]<='Z'))
+ {
+ //cPurpose.push_back(cSource[itSource]);
+ cPurpose += cSource[itSource];
+ itSource++;
+ break;
+ }
+ itSource++;
+ }
+ break;
+ }
+ break;
+ case '9':
+ {
+ while(itSource < iSize)
+ {
+ if (cSource[itSource]>='0'&&cSource[itSource]<='9')
+ {
+ //cPurpose.push_back(cSource[itSource]);
+ cPurpose += cSource[itSource];
+ itSource++;
+ break;
+ }
+ itSource++;
+ }
+ break;
+ }
+ case '*':
+ {
+ cPurpose.append(cSource,itSource,iSize-itSource);
+ itSource = iSize-1;
+ break;
+ }
+ case '\\':
+ break;
+ case '>':
+ {
+ for(std::string::iterator it = cSource.begin();it != cSource.end(); it++)
+ {
+ *it = toupper(*it);
+ }
+ break;
+ }
+ case '<':
+ {
+ for(std::string::iterator it = cSource.begin();it != cSource.end(); it++)
+ {
+ *it = tolower(*it);
+ }
+ break;
+ }
+ case '=':
+ break;
+ default:
+ //cPurpose.push_back(letter);
+ cPurpose += letter;
+ break;
+ }
+ }
}
FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- v8::Isolate* isolate = GetIsolate(cc);
- int iSize = params.size();
- if (iSize < 2)
- return FALSE;
-
- CFX_WideString sFormat = params[0].ToCFXWideString();
- CFX_WideString sDate = params[1].ToCFXWideString();
- double dDate = JS_GetDateTime();
- if (sDate.GetLength() > 0)
- {
- FX_BOOL bWrongFormat = FALSE;
- dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongFormat);
- }
-
- if (!JS_PortIsNan(dDate))
- {
- CJS_Date date(isolate,dDate);
- vRet = date;
- }
- else
- {
- vRet.SetNull();
- }
-
- return TRUE;
+ v8::Isolate* isolate = GetIsolate(cc);
+ int iSize = params.size();
+ if (iSize < 2)
+ return FALSE;
+
+ CFX_WideString sFormat = params[0].ToCFXWideString();
+ CFX_WideString sDate = params[1].ToCFXWideString();
+ double dDate = JS_GetDateTime();
+ if (sDate.GetLength() > 0)
+ {
+ FX_BOOL bWrongFormat = FALSE;
+ dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongFormat);
+ }
+
+ if (!JS_PortIsNan(dDate))
+ {
+ CJS_Date date(isolate,dDate);
+ vRet = date;
+ }
+ else
+ {
+ vRet.SetNull();
+ }
+
+ return TRUE;
}
int64_t FX_atoi64(const char *nptr)
@@ -615,18 +625,21 @@ int64_t FX_atoi64(const char *nptr)
c = (int)(unsigned char)*nptr++; /* get next char */
}
- return sign == '-' ? -total : total;
+ if (sign == '-')
+ return -total;
+ else
+ return total; /* return result, negated if necessary */
}
FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
- int iSize = params.size();
- if (iSize == 0)
- return FALSE;
- int nByte = params[0].ToInt();
- unsigned char cByte = (unsigned char)nByte;
- CFX_WideString csValue;
- csValue.Format(L"%c", cByte);
- vRet = csValue.c_str();
- return TRUE;
+ int iSize = params.size();
+ if (iSize == 0)
+ return FALSE;
+ int nByte = params[0].ToInt();
+ unsigned char cByte = (unsigned char)nByte;
+ CFX_WideString csValue;
+ csValue.Format(L"%c", cByte);
+ vRet = csValue.c_str();
+ return TRUE;
}