summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp600
-rw-r--r--fpdfsdk/src/formfiller/FFL_CheckBox.cpp288
-rw-r--r--fpdfsdk/src/formfiller/FFL_ComboBox.cpp884
-rw-r--r--fpdfsdk/src/formfiller/FFL_FormFiller.cpp1850
-rw-r--r--fpdfsdk/src/formfiller/FFL_IFormFiller.cpp2394
-rw-r--r--fpdfsdk/src/formfiller/FFL_ListBox.cpp638
-rw-r--r--fpdfsdk/src/formfiller/FFL_Notify.cpp344
-rw-r--r--fpdfsdk/src/formfiller/FFL_PushButton.cpp86
-rw-r--r--fpdfsdk/src/formfiller/FFL_RadioButton.cpp274
-rw-r--r--fpdfsdk/src/formfiller/FFL_TextField.cpp824
-rw-r--r--fpdfsdk/src/formfiller/FFL_Utils.cpp266
-rw-r--r--fpdfsdk/src/fpdf_dataavail.cpp330
-rw-r--r--fpdfsdk/src/fpdf_ext.cpp490
-rw-r--r--fpdfsdk/src/fpdf_flatten.cpp1122
-rw-r--r--fpdfsdk/src/fpdf_progressive.cpp228
-rw-r--r--fpdfsdk/src/fpdf_searchex.cpp30
-rw-r--r--fpdfsdk/src/fpdf_transformpage.cpp650
-rw-r--r--fpdfsdk/src/fpdfdoc.cpp518
-rw-r--r--fpdfsdk/src/fpdfeditimg.cpp148
-rw-r--r--fpdfsdk/src/fpdfeditpage.cpp632
-rw-r--r--fpdfsdk/src/fpdfformfill.cpp882
-rw-r--r--fpdfsdk/src/fpdfoom.cpp54
-rw-r--r--fpdfsdk/src/fpdfppo.cpp920
-rw-r--r--fpdfsdk/src/fpdfsave.cpp182
-rw-r--r--fpdfsdk/src/fpdfsdkdll.rc218
-rw-r--r--fpdfsdk/src/fpdftext.cpp556
-rw-r--r--fpdfsdk/src/fpdfview.cpp1758
-rw-r--r--fpdfsdk/src/fsdk_actionhandler.cpp1700
-rw-r--r--fpdfsdk/src/fsdk_annothandler.cpp1890
-rw-r--r--fpdfsdk/src/fsdk_baseannot.cpp2374
-rw-r--r--fpdfsdk/src/fsdk_baseform.cpp6222
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp2110
-rw-r--r--fpdfsdk/src/fsdk_rendercontext.cpp98
-rw-r--r--fpdfsdk/src/fxedit/fxet_ap.cpp450
-rw-r--r--fpdfsdk/src/fxedit/fxet_edit.cpp7220
-rw-r--r--fpdfsdk/src/fxedit/fxet_list.cpp2024
-rw-r--r--fpdfsdk/src/fxedit/fxet_module.cpp92
-rw-r--r--fpdfsdk/src/fxedit/fxet_pageobjs.cpp1374
-rw-r--r--fpdfsdk/src/javascript/Consts.cpp494
-rw-r--r--fpdfsdk/src/javascript/Document.cpp5054
-rw-r--r--fpdfsdk/src/javascript/Field.cpp8256
-rw-r--r--fpdfsdk/src/javascript/Icon.cpp134
-rw-r--r--fpdfsdk/src/javascript/JS_Context.cpp728
-rw-r--r--fpdfsdk/src/javascript/JS_EventHandler.cpp1352
-rw-r--r--fpdfsdk/src/javascript/JS_GlobalData.cpp1162
-rw-r--r--fpdfsdk/src/javascript/JS_Object.cpp290
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp940
-rw-r--r--fpdfsdk/src/javascript/JS_Value.cpp1286
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp4670
-rw-r--r--fpdfsdk/src/javascript/app.cpp2268
-rw-r--r--fpdfsdk/src/javascript/color.cpp506
-rw-r--r--fpdfsdk/src/javascript/console.cpp156
-rw-r--r--fpdfsdk/src/javascript/event.cpp758
-rw-r--r--fpdfsdk/src/javascript/global.cpp1100
-rw-r--r--fpdfsdk/src/javascript/report.cpp100
-rw-r--r--fpdfsdk/src/javascript/util.cpp1298
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Button.cpp106
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Caret.cpp394
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp1324
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Edit.cpp2632
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_EditCtrl.cpp1456
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_FontMap.cpp1202
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Icon.cpp544
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_IconList.cpp1184
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Label.cpp374
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_ListBox.cpp1264
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_ListCtrl.cpp490
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Note.cpp3558
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_ScrollBar.cpp2706
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Signature.cpp440
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_SpecialButton.cpp220
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Utils.cpp5688
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Wnd.cpp2684
-rw-r--r--fpdfsdk/src/resource.h42
74 files changed, 49790 insertions, 49790 deletions
diff --git a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
index 59617ac09a..0c7cd48553 100644
--- a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
+++ b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
@@ -1,300 +1,300 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/formfiller/FormFiller.h"
-#include "../../include/formfiller/FFL_CBA_Fontmap.h"
-
-CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, IFX_SystemHandler* pSystemHandler) :
- CPWL_FontMap(pSystemHandler),
- m_pDocument(NULL),
- m_pAnnotDict(NULL),
- m_pDefaultFont(NULL),
- m_sAPType("N")
-{
- ASSERT(pAnnot != NULL);
-
- CPDF_Page* pPage = pAnnot->GetPDFPage();
-
- m_pDocument = pPage->m_pDocument;
- m_pAnnotDict = pAnnot->GetPDFAnnot()->m_pAnnotDict;
-}
-
-CBA_FontMap::CBA_FontMap(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict,
- IFX_SystemHandler* pSystemHandler) :
- CPWL_FontMap(pSystemHandler),
- m_pDocument(pDocument),
- m_pAnnotDict(pAnnotDict),
- m_pDefaultFont(NULL),
- m_sAPType("N")
-{
-}
-
-CBA_FontMap::~CBA_FontMap()
-{
-}
-
-void CBA_FontMap::Reset()
-{
- Empty();
- m_pDefaultFont = NULL;
- m_sDefaultFontName = "";
-}
-
-void CBA_FontMap::Initial(FX_LPCSTR fontname)
-{
- FX_INT32 nCharset = DEFAULT_CHARSET;
-
- if (!m_pDefaultFont)
- {
- m_pDefaultFont = GetAnnotDefaultFont(m_sDefaultFontName);
- if (m_pDefaultFont)
- {
- if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont())
- nCharset = pSubstFont->m_Charset;
- else
- {
- if (m_sDefaultFontName == "Wingdings" || m_sDefaultFontName == "Wingdings2" ||
- m_sDefaultFontName == "Wingdings3" || m_sDefaultFontName == "Webdings")
- nCharset = SYMBOL_CHARSET;
- else
- nCharset = ANSI_CHARSET;
- }
- AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset);
- AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName);
- }
- }
-
- if (nCharset != ANSI_CHARSET)
- CPWL_FontMap::Initial(fontname);
-}
-
-void CBA_FontMap::SetDefaultFont(CPDF_Font * pFont, const CFX_ByteString & sFontName)
-{
- ASSERT(pFont != NULL);
-
- if (m_pDefaultFont) return;
-
- m_pDefaultFont = pFont;
- m_sDefaultFontName = sFontName;
-
-// if (m_sDefaultFontName.IsEmpty())
-// m_sDefaultFontName = pFont->GetFontTypeName();
-
- FX_INT32 nCharset = DEFAULT_CHARSET;
- if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont())
- nCharset = pSubstFont->m_Charset;
- AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset);
-}
-
-CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, FX_INT32 nCharset)
-{
- ASSERT(m_pAnnotDict != NULL);
-
- if (m_pAnnotDict->GetString("Subtype") == "Widget")
- {
- CPDF_Document* pDocument = GetDocument();
- ASSERT(pDocument != NULL);
-
- CPDF_Dictionary * pRootDict = pDocument->GetRoot();
- if (!pRootDict) return NULL;
-
- CPDF_Dictionary* pAcroFormDict = pRootDict->GetDict("AcroForm");
- if (!pAcroFormDict) return NULL;
-
- CPDF_Dictionary * pDRDict = pAcroFormDict->GetDict("DR");
- if (!pDRDict) return NULL;
-
- return FindResFontSameCharset(pDRDict, sFontAlias, nCharset);
- }
-
- return NULL;
-}
-
-CPDF_Document* CBA_FontMap::GetDocument()
-{
- return m_pDocument;
-}
-
-CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, CFX_ByteString& sFontAlias,
- FX_INT32 nCharset)
-{
- if (!pResDict) return NULL;
-
- CPDF_Document* pDocument = GetDocument();
- ASSERT(pDocument != NULL);
-
- CPDF_Dictionary* pFonts = pResDict->GetDict("Font");
- if (pFonts == NULL) return NULL;
-
- CPDF_Font* pFind = NULL;
-
- FX_POSITION pos = pFonts->GetStartPos();
- while (pos)
- {
- CPDF_Object* pObj = NULL;
- CFX_ByteString csKey;
- pObj = pFonts->GetNextElement(pos, csKey);
- if (pObj == NULL) continue;
-
- CPDF_Object* pDirect = pObj->GetDirect();
- if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) continue;
-
- CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
- if (pElement->GetString("Type") != "Font") continue;
-
- CPDF_Font* pFont = pDocument->LoadFont(pElement);
- if (pFont == NULL) continue;
- const CFX_SubstFont* pSubst = pFont->GetSubstFont();
- if (pSubst == NULL) continue;
- if (pSubst->m_Charset == nCharset)
- {
- sFontAlias = csKey;
- pFind = pFont;
- }
- }
- return pFind;
-}
-
-void CBA_FontMap::AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias)
-{
- AddFontToAnnotDict(pFont, sFontAlias);
-}
-
-void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, const CFX_ByteString& sAlias)
-{
- if (!pFont) return;
-
- ASSERT(m_pAnnotDict != NULL);
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP");
-
- if (pAPDict == NULL)
- {
- pAPDict = FX_NEW CPDF_Dictionary;
- m_pAnnotDict->SetAt("AP", pAPDict);
- }
-
- //to avoid checkbox and radiobutton
- CPDF_Object* pObject = pAPDict->GetElement(m_sAPType);
- if (pObject && pObject->GetType() == PDFOBJ_DICTIONARY)
- return;
-
- CPDF_Stream* pStream = pAPDict->GetStream(m_sAPType);
- if (pStream == NULL)
- {
- pStream = FX_NEW CPDF_Stream(NULL, 0, NULL);
- FX_INT32 objnum = m_pDocument->AddIndirectObject(pStream);
- pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum);
- }
-
- CPDF_Dictionary * pStreamDict = pStream->GetDict();
-
- if (!pStreamDict)
- {
- pStreamDict = FX_NEW CPDF_Dictionary;
- pStream->InitStream(NULL, 0, pStreamDict);
- }
-
- if (pStreamDict)
- {
- CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
- if (!pStreamResList)
- {
- pStreamResList = FX_NEW CPDF_Dictionary();
- pStreamDict->SetAt("Resources", pStreamResList);
- }
-
- if (pStreamResList)
- {
- CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font");
- if (!pStreamResFontList)
- {
- pStreamResFontList = FX_NEW CPDF_Dictionary;
- FX_INT32 objnum = m_pDocument->AddIndirectObject(pStreamResFontList);
- pStreamResList->SetAtReference("Font", m_pDocument, objnum);
- }
- if (!pStreamResFontList->KeyExist(sAlias))
- pStreamResFontList->SetAtReference(sAlias, m_pDocument, pFont->GetFontDict());
- }
- }
-}
-
-CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString &sAlias)
-{
- ASSERT(m_pAnnotDict != NULL);
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pAcroFormDict = NULL;
-
- FX_BOOL bWidget = (m_pAnnotDict->GetString("Subtype") == "Widget");
-
- if (bWidget)
- {
- if (CPDF_Dictionary * pRootDict = m_pDocument->GetRoot())
- pAcroFormDict = pRootDict->GetDict("AcroForm");
- }
-
- CFX_ByteString sDA;
-
- sDA = FPDF_GetFieldAttr(m_pAnnotDict, "DA")->GetString();
-
- if (bWidget)
- {
- if (sDA.IsEmpty())
- {
- sDA = FPDF_GetFieldAttr(pAcroFormDict, "DA")->GetString();
- }
- }
-
- CPDF_Dictionary * pFontDict = NULL;
-
- if (!sDA.IsEmpty())
- {
- CPDF_SimpleParser syntax(sDA);
- syntax.FindTagParam("Tf", 2);
- CFX_ByteString sFontName = syntax.GetWord();
- sAlias = PDF_NameDecode(sFontName).Mid(1);
-
- if (CPDF_Dictionary * pDRDict = m_pAnnotDict->GetDict("DR"))
- if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Font"))
- pFontDict = pDRFontDict->GetDict(sAlias);
-
- if (!pFontDict)
- if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP"))
- if (CPDF_Dictionary* pNormalDict = pAPDict->GetDict("N"))
- if (CPDF_Dictionary* pNormalResDict = pNormalDict->GetDict("Resources"))
- if (CPDF_Dictionary* pResFontDict = pNormalResDict->GetDict("Font"))
- pFontDict = pResFontDict->GetDict(sAlias);
-
- if (bWidget)
- {
- if (!pFontDict)
- {
- if (pAcroFormDict)
- {
- if (CPDF_Dictionary * pDRDict = pAcroFormDict->GetDict("DR"))
- if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Font"))
- pFontDict = pDRFontDict->GetDict(sAlias);
- }
- }
- }
- }
-
- if (pFontDict)
- return m_pDocument->LoadFont(pFontDict);
- else
- return NULL;
-}
-
-void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType)
-{
- m_sAPType = sAPType;
-
- Reset();
- Initial();
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/formfiller/FormFiller.h"
+#include "../../include/formfiller/FFL_CBA_Fontmap.h"
+
+CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, IFX_SystemHandler* pSystemHandler) :
+ CPWL_FontMap(pSystemHandler),
+ m_pDocument(NULL),
+ m_pAnnotDict(NULL),
+ m_pDefaultFont(NULL),
+ m_sAPType("N")
+{
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Page* pPage = pAnnot->GetPDFPage();
+
+ m_pDocument = pPage->m_pDocument;
+ m_pAnnotDict = pAnnot->GetPDFAnnot()->m_pAnnotDict;
+}
+
+CBA_FontMap::CBA_FontMap(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict,
+ IFX_SystemHandler* pSystemHandler) :
+ CPWL_FontMap(pSystemHandler),
+ m_pDocument(pDocument),
+ m_pAnnotDict(pAnnotDict),
+ m_pDefaultFont(NULL),
+ m_sAPType("N")
+{
+}
+
+CBA_FontMap::~CBA_FontMap()
+{
+}
+
+void CBA_FontMap::Reset()
+{
+ Empty();
+ m_pDefaultFont = NULL;
+ m_sDefaultFontName = "";
+}
+
+void CBA_FontMap::Initial(FX_LPCSTR fontname)
+{
+ FX_INT32 nCharset = DEFAULT_CHARSET;
+
+ if (!m_pDefaultFont)
+ {
+ m_pDefaultFont = GetAnnotDefaultFont(m_sDefaultFontName);
+ if (m_pDefaultFont)
+ {
+ if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont())
+ nCharset = pSubstFont->m_Charset;
+ else
+ {
+ if (m_sDefaultFontName == "Wingdings" || m_sDefaultFontName == "Wingdings2" ||
+ m_sDefaultFontName == "Wingdings3" || m_sDefaultFontName == "Webdings")
+ nCharset = SYMBOL_CHARSET;
+ else
+ nCharset = ANSI_CHARSET;
+ }
+ AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset);
+ AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName);
+ }
+ }
+
+ if (nCharset != ANSI_CHARSET)
+ CPWL_FontMap::Initial(fontname);
+}
+
+void CBA_FontMap::SetDefaultFont(CPDF_Font * pFont, const CFX_ByteString & sFontName)
+{
+ ASSERT(pFont != NULL);
+
+ if (m_pDefaultFont) return;
+
+ m_pDefaultFont = pFont;
+ m_sDefaultFontName = sFontName;
+
+// if (m_sDefaultFontName.IsEmpty())
+// m_sDefaultFontName = pFont->GetFontTypeName();
+
+ FX_INT32 nCharset = DEFAULT_CHARSET;
+ if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont())
+ nCharset = pSubstFont->m_Charset;
+ AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset);
+}
+
+CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, FX_INT32 nCharset)
+{
+ ASSERT(m_pAnnotDict != NULL);
+
+ if (m_pAnnotDict->GetString("Subtype") == "Widget")
+ {
+ CPDF_Document* pDocument = GetDocument();
+ ASSERT(pDocument != NULL);
+
+ CPDF_Dictionary * pRootDict = pDocument->GetRoot();
+ if (!pRootDict) return NULL;
+
+ CPDF_Dictionary* pAcroFormDict = pRootDict->GetDict("AcroForm");
+ if (!pAcroFormDict) return NULL;
+
+ CPDF_Dictionary * pDRDict = pAcroFormDict->GetDict("DR");
+ if (!pDRDict) return NULL;
+
+ return FindResFontSameCharset(pDRDict, sFontAlias, nCharset);
+ }
+
+ return NULL;
+}
+
+CPDF_Document* CBA_FontMap::GetDocument()
+{
+ return m_pDocument;
+}
+
+CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, CFX_ByteString& sFontAlias,
+ FX_INT32 nCharset)
+{
+ if (!pResDict) return NULL;
+
+ CPDF_Document* pDocument = GetDocument();
+ ASSERT(pDocument != NULL);
+
+ CPDF_Dictionary* pFonts = pResDict->GetDict("Font");
+ if (pFonts == NULL) return NULL;
+
+ CPDF_Font* pFind = NULL;
+
+ FX_POSITION pos = pFonts->GetStartPos();
+ while (pos)
+ {
+ CPDF_Object* pObj = NULL;
+ CFX_ByteString csKey;
+ pObj = pFonts->GetNextElement(pos, csKey);
+ if (pObj == NULL) continue;
+
+ CPDF_Object* pDirect = pObj->GetDirect();
+ if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) continue;
+
+ CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
+ if (pElement->GetString("Type") != "Font") continue;
+
+ CPDF_Font* pFont = pDocument->LoadFont(pElement);
+ if (pFont == NULL) continue;
+ const CFX_SubstFont* pSubst = pFont->GetSubstFont();
+ if (pSubst == NULL) continue;
+ if (pSubst->m_Charset == nCharset)
+ {
+ sFontAlias = csKey;
+ pFind = pFont;
+ }
+ }
+ return pFind;
+}
+
+void CBA_FontMap::AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias)
+{
+ AddFontToAnnotDict(pFont, sFontAlias);
+}
+
+void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, const CFX_ByteString& sAlias)
+{
+ if (!pFont) return;
+
+ ASSERT(m_pAnnotDict != NULL);
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP");
+
+ if (pAPDict == NULL)
+ {
+ pAPDict = FX_NEW CPDF_Dictionary;
+ m_pAnnotDict->SetAt("AP", pAPDict);
+ }
+
+ //to avoid checkbox and radiobutton
+ CPDF_Object* pObject = pAPDict->GetElement(m_sAPType);
+ if (pObject && pObject->GetType() == PDFOBJ_DICTIONARY)
+ return;
+
+ CPDF_Stream* pStream = pAPDict->GetStream(m_sAPType);
+ if (pStream == NULL)
+ {
+ pStream = FX_NEW CPDF_Stream(NULL, 0, NULL);
+ FX_INT32 objnum = m_pDocument->AddIndirectObject(pStream);
+ pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum);
+ }
+
+ CPDF_Dictionary * pStreamDict = pStream->GetDict();
+
+ if (!pStreamDict)
+ {
+ pStreamDict = FX_NEW CPDF_Dictionary;
+ pStream->InitStream(NULL, 0, pStreamDict);
+ }
+
+ if (pStreamDict)
+ {
+ CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
+ if (!pStreamResList)
+ {
+ pStreamResList = FX_NEW CPDF_Dictionary();
+ pStreamDict->SetAt("Resources", pStreamResList);
+ }
+
+ if (pStreamResList)
+ {
+ CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font");
+ if (!pStreamResFontList)
+ {
+ pStreamResFontList = FX_NEW CPDF_Dictionary;
+ FX_INT32 objnum = m_pDocument->AddIndirectObject(pStreamResFontList);
+ pStreamResList->SetAtReference("Font", m_pDocument, objnum);
+ }
+ if (!pStreamResFontList->KeyExist(sAlias))
+ pStreamResFontList->SetAtReference(sAlias, m_pDocument, pFont->GetFontDict());
+ }
+ }
+}
+
+CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString &sAlias)
+{
+ ASSERT(m_pAnnotDict != NULL);
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pAcroFormDict = NULL;
+
+ FX_BOOL bWidget = (m_pAnnotDict->GetString("Subtype") == "Widget");
+
+ if (bWidget)
+ {
+ if (CPDF_Dictionary * pRootDict = m_pDocument->GetRoot())
+ pAcroFormDict = pRootDict->GetDict("AcroForm");
+ }
+
+ CFX_ByteString sDA;
+
+ sDA = FPDF_GetFieldAttr(m_pAnnotDict, "DA")->GetString();
+
+ if (bWidget)
+ {
+ if (sDA.IsEmpty())
+ {
+ sDA = FPDF_GetFieldAttr(pAcroFormDict, "DA")->GetString();
+ }
+ }
+
+ CPDF_Dictionary * pFontDict = NULL;
+
+ if (!sDA.IsEmpty())
+ {
+ CPDF_SimpleParser syntax(sDA);
+ syntax.FindTagParam("Tf", 2);
+ CFX_ByteString sFontName = syntax.GetWord();
+ sAlias = PDF_NameDecode(sFontName).Mid(1);
+
+ if (CPDF_Dictionary * pDRDict = m_pAnnotDict->GetDict("DR"))
+ if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Font"))
+ pFontDict = pDRFontDict->GetDict(sAlias);
+
+ if (!pFontDict)
+ if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP"))
+ if (CPDF_Dictionary* pNormalDict = pAPDict->GetDict("N"))
+ if (CPDF_Dictionary* pNormalResDict = pNormalDict->GetDict("Resources"))
+ if (CPDF_Dictionary* pResFontDict = pNormalResDict->GetDict("Font"))
+ pFontDict = pResFontDict->GetDict(sAlias);
+
+ if (bWidget)
+ {
+ if (!pFontDict)
+ {
+ if (pAcroFormDict)
+ {
+ if (CPDF_Dictionary * pDRDict = pAcroFormDict->GetDict("DR"))
+ if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Font"))
+ pFontDict = pDRFontDict->GetDict(sAlias);
+ }
+ }
+ }
+ }
+
+ if (pFontDict)
+ return m_pDocument->LoadFont(pFontDict);
+ else
+ return NULL;
+}
+
+void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType)
+{
+ m_sAPType = sAPType;
+
+ Reset();
+ Initial();
+}
+
diff --git a/fpdfsdk/src/formfiller/FFL_CheckBox.cpp b/fpdfsdk/src/formfiller/FFL_CheckBox.cpp
index db79926733..f8035c7ec9 100644
--- a/fpdfsdk/src/formfiller/FFL_CheckBox.cpp
+++ b/fpdfsdk/src/formfiller/FFL_CheckBox.cpp
@@ -1,144 +1,144 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/formfiller/FormFiller.h"
-#include "../../include/formfiller/FFL_FormFiller.h"
-#include "../../include/formfiller/FFL_CheckBox.h"
-
-
-/* ------------------------------- CFFL_CheckBox ------------------------------- */
-
-CFFL_CheckBox::CFFL_CheckBox(CPDFDoc_Environment* pApp, CPDFSDK_Widget* pWidget) :
- CFFL_Button(pApp, pWidget)
-{
-}
-
-CFFL_CheckBox::~CFFL_CheckBox()
-{
-}
-
-CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
-{
- CPWL_CheckBox* pWnd = new CPWL_CheckBox();
- pWnd->Create(cp);
-
- ASSERT(m_pWidget != NULL);
- pWnd->SetCheck(m_pWidget->IsChecked());
-
- return pWnd;
-}
-
-FX_BOOL CFFL_CheckBox::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
-{
- switch (nKeyCode)
- {
- case FWL_VKEY_Return:
- case FWL_VKEY_Space:
- return TRUE;
- default:
- return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags);
- }
-}
-FX_BOOL CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
-{
- switch (nChar)
- {
- case FWL_VKEY_Return:
- case FWL_VKEY_Space:
- {
- CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
- ASSERT(pIFormFiller != NULL);
-
- CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
- ASSERT(pPageView != NULL);
-
- FX_BOOL bReset = FALSE;
- FX_BOOL bExit = FALSE;
-
- pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit,nFlags);
-
- if (bReset) return TRUE;
- if (bExit) return TRUE;
-
- CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
-
- if (CPWL_CheckBox * pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE))
- pWnd->SetCheck(!pWnd->IsChecked());
-
- CommitData(pPageView,nFlags);
- return TRUE;
- }
- default:
- return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
- }
-}
-
-FX_BOOL CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point);
-
- if (IsValid())
- {
- if (CPWL_CheckBox * pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE))
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- pWnd->SetCheck(!pWidget->IsChecked());
- // pWnd->SetCheck(!pWnd->IsChecked());
- }
-
- if (!CommitData(pPageView, nFlags)) return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView)
-{
-
- ASSERT(m_pWidget != NULL);
-
- if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE))
- {
- return pWnd->IsChecked() != m_pWidget->IsChecked();
- }
-
- return FALSE;
-}
-
-void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView)
-{
-
- ASSERT(m_pWidget != NULL);
-
- if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE))
- {
-
- FX_BOOL bNewChecked = pWnd->IsChecked();
-
-
- if (bNewChecked)
- {
- CPDF_FormField* pField = m_pWidget->GetFormField();
- ASSERT(pField != NULL);
-
- for (FX_INT32 i=0,sz=pField->CountControls(); i<sz; i++)
- {
- if (CPDF_FormControl* pCtrl = pField->GetControl(i))
- {
- if (pCtrl->IsChecked())
- {
- break;
- }
- }
- }
- }
-
- m_pWidget->SetCheck(bNewChecked, FALSE);
- m_pWidget->UpdateField();
- SetChangeMark();
- }
-
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/formfiller/FormFiller.h"
+#include "../../include/formfiller/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_CheckBox.h"
+
+
+/* ------------------------------- CFFL_CheckBox ------------------------------- */
+
+CFFL_CheckBox::CFFL_CheckBox(CPDFDoc_Environment* pApp, CPDFSDK_Widget* pWidget) :
+ CFFL_Button(pApp, pWidget)
+{
+}
+
+CFFL_CheckBox::~CFFL_CheckBox()
+{
+}
+
+CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
+{
+ CPWL_CheckBox* pWnd = new CPWL_CheckBox();
+ pWnd->Create(cp);
+
+ ASSERT(m_pWidget != NULL);
+ pWnd->SetCheck(m_pWidget->IsChecked());
+
+ return pWnd;
+}
+
+FX_BOOL CFFL_CheckBox::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
+{
+ switch (nKeyCode)
+ {
+ case FWL_VKEY_Return:
+ case FWL_VKEY_Space:
+ return TRUE;
+ default:
+ return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags);
+ }
+}
+FX_BOOL CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
+{
+ switch (nChar)
+ {
+ case FWL_VKEY_Return:
+ case FWL_VKEY_Space:
+ {
+ CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
+ ASSERT(pIFormFiller != NULL);
+
+ CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
+ ASSERT(pPageView != NULL);
+
+ FX_BOOL bReset = FALSE;
+ FX_BOOL bExit = FALSE;
+
+ pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit,nFlags);
+
+ if (bReset) return TRUE;
+ if (bExit) return TRUE;
+
+ CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
+
+ if (CPWL_CheckBox * pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE))
+ pWnd->SetCheck(!pWnd->IsChecked());
+
+ CommitData(pPageView,nFlags);
+ return TRUE;
+ }
+ default:
+ return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
+ }
+}
+
+FX_BOOL CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point);
+
+ if (IsValid())
+ {
+ if (CPWL_CheckBox * pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE))
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ pWnd->SetCheck(!pWidget->IsChecked());
+ // pWnd->SetCheck(!pWnd->IsChecked());
+ }
+
+ if (!CommitData(pPageView, nFlags)) return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView)
+{
+
+ ASSERT(m_pWidget != NULL);
+
+ if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ return pWnd->IsChecked() != m_pWidget->IsChecked();
+ }
+
+ return FALSE;
+}
+
+void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView)
+{
+
+ ASSERT(m_pWidget != NULL);
+
+ if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE))
+ {
+
+ FX_BOOL bNewChecked = pWnd->IsChecked();
+
+
+ if (bNewChecked)
+ {
+ CPDF_FormField* pField = m_pWidget->GetFormField();
+ ASSERT(pField != NULL);
+
+ for (FX_INT32 i=0,sz=pField->CountControls(); i<sz; i++)
+ {
+ if (CPDF_FormControl* pCtrl = pField->GetControl(i))
+ {
+ if (pCtrl->IsChecked())
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ m_pWidget->SetCheck(bNewChecked, FALSE);
+ m_pWidget->UpdateField();
+ SetChangeMark();
+ }
+
+}
diff --git a/fpdfsdk/src/formfiller/FFL_ComboBox.cpp b/fpdfsdk/src/formfiller/FFL_ComboBox.cpp
index 3f2c453e5d..ee6b7bd83a 100644
--- a/fpdfsdk/src/formfiller/FFL_ComboBox.cpp
+++ b/fpdfsdk/src/formfiller/FFL_ComboBox.cpp
@@ -1,442 +1,442 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/formfiller/FormFiller.h"
-#include "../../include/formfiller/FFL_FormFiller.h"
-#include "../../include/formfiller/FFL_IFormFiller.h"
-#include "../../include/formfiller/FFL_CBA_Fontmap.h"
-#include "../../include/formfiller/FFL_ComboBox.h"
-
-
-/* ------------------------------- CFFL_ComboBox ------------------------------- */
-
-CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) :
- CFFL_FormFiller(pApp, pAnnot), m_pFontMap( NULL )
-{
- //m_pFontMap = new CBA_FontMap( pAnnot, GetSystemHandler() );
- m_State.nIndex = 0;
- m_State.nStart = 0;
- m_State.nEnd = 0;
-}
-
-CFFL_ComboBox::~CFFL_ComboBox()
-{
- if (m_pFontMap)
- {
- delete m_pFontMap;
- m_pFontMap = NULL;
- }
-
-// for (int i=0,sz=m_IMBox.GetSize(); i<sz; i++)
-// {
-// delete m_IMBox.GetAt(i);
-// }
-//
-// m_IMBox.RemoveAll();
-}
-
-PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam()
-{
- PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
-
- ASSERT(m_pWidget != NULL);
-
- int nFlags = m_pWidget->GetFieldFlags();
-
- if (nFlags & FIELDFLAG_EDIT)
- {
- cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT;
- }
-
- /*
- if (nFlags & FIELDFLAG_COMMITONSELCHANGE)
- {
- m_bCommitOnSelectChange = TRUE;
- }
- */
-
- if (!m_pFontMap)
- {
- ASSERT(this->m_pApp != NULL);
- m_pFontMap = new CBA_FontMap(m_pWidget, GetSystemHandler());
- m_pFontMap->Initial();
- }
-
- cp.pFontMap = m_pFontMap;
- cp.pFocusHandler = this;
-
- return cp;
-}
-
-CPWL_Wnd* CFFL_ComboBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
-{
- CPWL_ComboBox * pWnd = new CPWL_ComboBox();
- pWnd->AttachFFLData(this);
- pWnd->Create(cp);
-
- ASSERT(m_pApp != NULL);
- CFFL_IFormFiller* pFormFiller = m_pApp->GetIFormFiller();
- pWnd->SetFillerNotify(pFormFiller);
-
- ASSERT(m_pWidget != NULL);
- FX_INT32 nCurSel = m_pWidget->GetSelectedIndex(0);
-
- CFX_WideString swText;
-
- if (nCurSel < 0)
- swText = m_pWidget->GetValue();
- else
- swText = m_pWidget->GetOptionLabel(nCurSel);
-
- for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
- {
- pWnd->AddString(m_pWidget->GetOptionLabel(i));
- }
-
- pWnd->SetSelect(nCurSel);
- pWnd->SetText(swText);
-
- return pWnd;
-}
-
-
-FX_BOOL CFFL_ComboBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
-{
- return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
-}
-
-FX_BOOL CFFL_ComboBox::IsDataChanged(CPDFSDK_PageView* pPageView)
-{
- if (CPWL_ComboBox * pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
- {
- FX_INT32 nCurSel = pWnd->GetSelect();
-
- ASSERT(m_pWidget != NULL);
-
- if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)
- {
- if (nCurSel >= 0)
- {
- return nCurSel != m_pWidget->GetSelectedIndex(0);
- }
- else
- {
- return pWnd->GetText() != m_pWidget->GetValue();
- }
- }
- else
- {
- return nCurSel != m_pWidget->GetSelectedIndex(0);
- }
- }
-
- return FALSE;
-}
-
-void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView)
-{
- ASSERT(m_pWidget != NULL);
-
- if (CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
- {
- CFX_WideString swText = pWnd->GetText();
- FX_INT32 nCurSel = pWnd->GetSelect();
-
- //mantis:0004157
- FX_BOOL bSetValue = TRUE;
-
- if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)
- {
- if (nCurSel >= 0)
- {
- if (swText != m_pWidget->GetOptionLabel(nCurSel))
- bSetValue = TRUE;
- else
- bSetValue = FALSE;
- }
- else
- bSetValue = TRUE;
- }
- else
- bSetValue = FALSE;
-
- CFX_WideString sOldValue;
-
-
- if (bSetValue)
- {
- sOldValue = m_pWidget->GetValue();
- m_pWidget->SetValue(swText, FALSE);
- }
- else
- {
- m_pWidget->GetSelectedIndex(0);
- m_pWidget->SetOptionSelection(nCurSel, TRUE, FALSE);
- }
-
- m_pWidget->ResetFieldAppearance(TRUE);
- m_pWidget->UpdateField();
- SetChangeMark();
-
- m_pWidget->GetPDFPage();
-
-
- }
-}
-
- void CFFL_ComboBox::GetActionData( CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, PDFSDK_FieldAction& fa)
-{
- switch (type)
- {
- case CPDF_AAction::KeyStroke:
- if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
- {
- if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
- {
- fa.bFieldFull = pEdit->IsTextFull();
- int nSelStart = 0;
- int nSelEnd = 0;
- pEdit->GetSel(nSelStart, nSelEnd);
- fa.nSelEnd = nSelEnd;
- fa.nSelStart = nSelStart;
- fa.sValue = pEdit->GetText();
- fa.sChangeEx = GetSelectExportText();
-
- if (fa.bFieldFull)
- {
- fa.sChange = L"";
- fa.sChangeEx = L"";
- }
- }
- }
- break;
- case CPDF_AAction::Validate:
- if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
- {
- if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
- {
- fa.sValue = pEdit->GetText();
- }
- }
- break;
- case CPDF_AAction::LoseFocus:
- case CPDF_AAction::GetFocus:
- ASSERT(m_pWidget != NULL);
- fa.sValue = m_pWidget->GetValue();
- break;
- default:
- break;
- }
-}
-
-
-
-void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
- const PDFSDK_FieldAction& fa)
-{
- switch (type)
- {
- case CPDF_AAction::KeyStroke:
- if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
- {
- if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
- {
- pEdit->SetSel(fa.nSelStart, fa.nSelEnd);
- pEdit->ReplaceSel(fa.sChange);
- }
- }
- break;
- default:
- break;
- }
-}
-
-FX_BOOL CFFL_ComboBox::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld,
- const PDFSDK_FieldAction& faNew)
-{
- switch (type)
- {
- case CPDF_AAction::KeyStroke:
- return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || faOld.nSelStart != faNew.nSelStart ||
- faOld.sChange != faNew.sChange;
- default:
- break;
- }
-
- return FALSE;
-}
-
-void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView)
-{
- ASSERT(pPageView != NULL);
-
- if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
- {
- m_State.nIndex = pComboBox->GetSelect();
-
- if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
- {
- pEdit->GetSel(m_State.nStart, m_State.nEnd);
- m_State.sValue = pEdit->GetText();
- }
- }
-}
-
-void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView)
-{
- ASSERT(pPageView != NULL);
-
- if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, TRUE))
- {
- if (m_State.nIndex >= 0)
- pComboBox->SetSelect(m_State.nIndex);
- else
- {
- if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
- {
- pEdit->SetText(m_State.sValue);
- pEdit->SetSel(m_State.nStart, m_State.nEnd);
- }
- }
- }
-}
-
-CPWL_Wnd* CFFL_ComboBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
-{
- if (bRestoreValue)
- SaveState(pPageView);
-
- DestroyPDFWindow(pPageView);
-
- CPWL_Wnd* pRet = NULL;
-
- if (bRestoreValue)
- {
- RestoreState(pPageView);
- pRet = this->GetPDFWindow(pPageView, FALSE);
- }
- else
- pRet = this->GetPDFWindow(pPageView, TRUE);
-
- m_pWidget->UpdateField();
-
- return pRet;
-}
-
-void CFFL_ComboBox::OnKeyStroke(FX_BOOL bKeyDown, FX_UINT nFlag)
-{
- ASSERT(m_pWidget != NULL);
-
- int nFlags = m_pWidget->GetFieldFlags();
-
- if (nFlags & FIELDFLAG_COMMITONSELCHANGE)
- {
- if (m_bValid)
- {
- CPDFSDK_PageView* pPageView = this->GetCurPageView();
- ASSERT(pPageView != NULL);
-
- if (CommitData(pPageView, nFlag))
- {
- DestroyPDFWindow(pPageView);
- m_bValid = FALSE;
- }
- }
- }
-}
-
-void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd)
-{
- ASSERT(m_pApp != NULL);
-
- ASSERT(pWnd != NULL);
-
- if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT)
- {
- CPWL_Edit* pEdit = (CPWL_Edit*)pWnd;
- pEdit->SetCharSet(134);
- pEdit->SetCodePage(936);
-
- pEdit->SetReadyToInput();
- CFX_WideString wsText = pEdit->GetText();
- int nCharacters = wsText.GetLength();
- CFX_ByteString bsUTFText = wsText.UTF16LE_Encode();
- unsigned short* pBuffer = (unsigned short*)(FX_LPCSTR)bsUTFText;
- m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, nCharacters, TRUE);
-
- pEdit->SetEditNotify(this);
- }
-}
-
-void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd)
-{
- ASSERT(m_pApp != NULL);
-}
-
-FX_BOOL CFFL_ComboBox::CanCopy(CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-
- return FALSE;
-}
-
-FX_BOOL CFFL_ComboBox::CanCut(CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-
- return FALSE;
-}
-
-FX_BOOL CFFL_ComboBox::CanPaste(CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-
- return FALSE;
-}
-
-void CFFL_ComboBox::DoCopy(CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-}
-
-void CFFL_ComboBox::DoCut(CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-}
-
-void CFFL_ComboBox::DoPaste(CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-}
-
-void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit)
-{
- ASSERT(pEdit != NULL);
-}
-
-CFX_WideString CFFL_ComboBox::GetSelectExportText()
-{
- CFX_WideString swRet;
-
- int nExport = -1;
- CPDFSDK_PageView *pPageView = GetCurPageView();
- if (CPWL_ComboBox * pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
- {
- nExport = pComboBox->GetSelect();
- }
-
- if (nExport >= 0)
- {
- if (CPDF_FormField * pFormField = m_pWidget->GetFormField())
- {
- swRet = pFormField->GetOptionValue(nExport);
- if (swRet.IsEmpty())
- swRet = pFormField->GetOptionLabel(nExport);
- }
- }
-
- return swRet;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/formfiller/FormFiller.h"
+#include "../../include/formfiller/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_IFormFiller.h"
+#include "../../include/formfiller/FFL_CBA_Fontmap.h"
+#include "../../include/formfiller/FFL_ComboBox.h"
+
+
+/* ------------------------------- CFFL_ComboBox ------------------------------- */
+
+CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) :
+ CFFL_FormFiller(pApp, pAnnot), m_pFontMap( NULL )
+{
+ //m_pFontMap = new CBA_FontMap( pAnnot, GetSystemHandler() );
+ m_State.nIndex = 0;
+ m_State.nStart = 0;
+ m_State.nEnd = 0;
+}
+
+CFFL_ComboBox::~CFFL_ComboBox()
+{
+ if (m_pFontMap)
+ {
+ delete m_pFontMap;
+ m_pFontMap = NULL;
+ }
+
+// for (int i=0,sz=m_IMBox.GetSize(); i<sz; i++)
+// {
+// delete m_IMBox.GetAt(i);
+// }
+//
+// m_IMBox.RemoveAll();
+}
+
+PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam()
+{
+ PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
+
+ ASSERT(m_pWidget != NULL);
+
+ int nFlags = m_pWidget->GetFieldFlags();
+
+ if (nFlags & FIELDFLAG_EDIT)
+ {
+ cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT;
+ }
+
+ /*
+ if (nFlags & FIELDFLAG_COMMITONSELCHANGE)
+ {
+ m_bCommitOnSelectChange = TRUE;
+ }
+ */
+
+ if (!m_pFontMap)
+ {
+ ASSERT(this->m_pApp != NULL);
+ m_pFontMap = new CBA_FontMap(m_pWidget, GetSystemHandler());
+ m_pFontMap->Initial();
+ }
+
+ cp.pFontMap = m_pFontMap;
+ cp.pFocusHandler = this;
+
+ return cp;
+}
+
+CPWL_Wnd* CFFL_ComboBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
+{
+ CPWL_ComboBox * pWnd = new CPWL_ComboBox();
+ pWnd->AttachFFLData(this);
+ pWnd->Create(cp);
+
+ ASSERT(m_pApp != NULL);
+ CFFL_IFormFiller* pFormFiller = m_pApp->GetIFormFiller();
+ pWnd->SetFillerNotify(pFormFiller);
+
+ ASSERT(m_pWidget != NULL);
+ FX_INT32 nCurSel = m_pWidget->GetSelectedIndex(0);
+
+ CFX_WideString swText;
+
+ if (nCurSel < 0)
+ swText = m_pWidget->GetValue();
+ else
+ swText = m_pWidget->GetOptionLabel(nCurSel);
+
+ for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
+ {
+ pWnd->AddString(m_pWidget->GetOptionLabel(i));
+ }
+
+ pWnd->SetSelect(nCurSel);
+ pWnd->SetText(swText);
+
+ return pWnd;
+}
+
+
+FX_BOOL CFFL_ComboBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
+{
+ return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
+}
+
+FX_BOOL CFFL_ComboBox::IsDataChanged(CPDFSDK_PageView* pPageView)
+{
+ if (CPWL_ComboBox * pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ FX_INT32 nCurSel = pWnd->GetSelect();
+
+ ASSERT(m_pWidget != NULL);
+
+ if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)
+ {
+ if (nCurSel >= 0)
+ {
+ return nCurSel != m_pWidget->GetSelectedIndex(0);
+ }
+ else
+ {
+ return pWnd->GetText() != m_pWidget->GetValue();
+ }
+ }
+ else
+ {
+ return nCurSel != m_pWidget->GetSelectedIndex(0);
+ }
+ }
+
+ return FALSE;
+}
+
+void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(m_pWidget != NULL);
+
+ if (CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ CFX_WideString swText = pWnd->GetText();
+ FX_INT32 nCurSel = pWnd->GetSelect();
+
+ //mantis:0004157
+ FX_BOOL bSetValue = TRUE;
+
+ if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)
+ {
+ if (nCurSel >= 0)
+ {
+ if (swText != m_pWidget->GetOptionLabel(nCurSel))
+ bSetValue = TRUE;
+ else
+ bSetValue = FALSE;
+ }
+ else
+ bSetValue = TRUE;
+ }
+ else
+ bSetValue = FALSE;
+
+ CFX_WideString sOldValue;
+
+
+ if (bSetValue)
+ {
+ sOldValue = m_pWidget->GetValue();
+ m_pWidget->SetValue(swText, FALSE);
+ }
+ else
+ {
+ m_pWidget->GetSelectedIndex(0);
+ m_pWidget->SetOptionSelection(nCurSel, TRUE, FALSE);
+ }
+
+ m_pWidget->ResetFieldAppearance(TRUE);
+ m_pWidget->UpdateField();
+ SetChangeMark();
+
+ m_pWidget->GetPDFPage();
+
+
+ }
+}
+
+ void CFFL_ComboBox::GetActionData( CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, PDFSDK_FieldAction& fa)
+{
+ switch (type)
+ {
+ case CPDF_AAction::KeyStroke:
+ if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
+ {
+ fa.bFieldFull = pEdit->IsTextFull();
+ int nSelStart = 0;
+ int nSelEnd = 0;
+ pEdit->GetSel(nSelStart, nSelEnd);
+ fa.nSelEnd = nSelEnd;
+ fa.nSelStart = nSelStart;
+ fa.sValue = pEdit->GetText();
+ fa.sChangeEx = GetSelectExportText();
+
+ if (fa.bFieldFull)
+ {
+ fa.sChange = L"";
+ fa.sChangeEx = L"";
+ }
+ }
+ }
+ break;
+ case CPDF_AAction::Validate:
+ if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
+ {
+ fa.sValue = pEdit->GetText();
+ }
+ }
+ break;
+ case CPDF_AAction::LoseFocus:
+ case CPDF_AAction::GetFocus:
+ ASSERT(m_pWidget != NULL);
+ fa.sValue = m_pWidget->GetValue();
+ break;
+ default:
+ break;
+ }
+}
+
+
+
+void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
+ const PDFSDK_FieldAction& fa)
+{
+ switch (type)
+ {
+ case CPDF_AAction::KeyStroke:
+ if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
+ {
+ pEdit->SetSel(fa.nSelStart, fa.nSelEnd);
+ pEdit->ReplaceSel(fa.sChange);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+FX_BOOL CFFL_ComboBox::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld,
+ const PDFSDK_FieldAction& faNew)
+{
+ switch (type)
+ {
+ case CPDF_AAction::KeyStroke:
+ return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || faOld.nSelStart != faNew.nSelStart ||
+ faOld.sChange != faNew.sChange;
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(pPageView != NULL);
+
+ if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ m_State.nIndex = pComboBox->GetSelect();
+
+ if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
+ {
+ pEdit->GetSel(m_State.nStart, m_State.nEnd);
+ m_State.sValue = pEdit->GetText();
+ }
+ }
+}
+
+void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(pPageView != NULL);
+
+ if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, TRUE))
+ {
+ if (m_State.nIndex >= 0)
+ pComboBox->SetSelect(m_State.nIndex);
+ else
+ {
+ if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
+ {
+ pEdit->SetText(m_State.sValue);
+ pEdit->SetSel(m_State.nStart, m_State.nEnd);
+ }
+ }
+ }
+}
+
+CPWL_Wnd* CFFL_ComboBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
+{
+ if (bRestoreValue)
+ SaveState(pPageView);
+
+ DestroyPDFWindow(pPageView);
+
+ CPWL_Wnd* pRet = NULL;
+
+ if (bRestoreValue)
+ {
+ RestoreState(pPageView);
+ pRet = this->GetPDFWindow(pPageView, FALSE);
+ }
+ else
+ pRet = this->GetPDFWindow(pPageView, TRUE);
+
+ m_pWidget->UpdateField();
+
+ return pRet;
+}
+
+void CFFL_ComboBox::OnKeyStroke(FX_BOOL bKeyDown, FX_UINT nFlag)
+{
+ ASSERT(m_pWidget != NULL);
+
+ int nFlags = m_pWidget->GetFieldFlags();
+
+ if (nFlags & FIELDFLAG_COMMITONSELCHANGE)
+ {
+ if (m_bValid)
+ {
+ CPDFSDK_PageView* pPageView = this->GetCurPageView();
+ ASSERT(pPageView != NULL);
+
+ if (CommitData(pPageView, nFlag))
+ {
+ DestroyPDFWindow(pPageView);
+ m_bValid = FALSE;
+ }
+ }
+ }
+}
+
+void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd)
+{
+ ASSERT(m_pApp != NULL);
+
+ ASSERT(pWnd != NULL);
+
+ if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT)
+ {
+ CPWL_Edit* pEdit = (CPWL_Edit*)pWnd;
+ pEdit->SetCharSet(134);
+ pEdit->SetCodePage(936);
+
+ pEdit->SetReadyToInput();
+ CFX_WideString wsText = pEdit->GetText();
+ int nCharacters = wsText.GetLength();
+ CFX_ByteString bsUTFText = wsText.UTF16LE_Encode();
+ unsigned short* pBuffer = (unsigned short*)(FX_LPCSTR)bsUTFText;
+ m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, nCharacters, TRUE);
+
+ pEdit->SetEditNotify(this);
+ }
+}
+
+void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd)
+{
+ ASSERT(m_pApp != NULL);
+}
+
+FX_BOOL CFFL_ComboBox::CanCopy(CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_ComboBox::CanCut(CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_ComboBox::CanPaste(CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+
+ return FALSE;
+}
+
+void CFFL_ComboBox::DoCopy(CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+}
+
+void CFFL_ComboBox::DoCut(CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+}
+
+void CFFL_ComboBox::DoPaste(CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+}
+
+void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit)
+{
+ ASSERT(pEdit != NULL);
+}
+
+CFX_WideString CFFL_ComboBox::GetSelectExportText()
+{
+ CFX_WideString swRet;
+
+ int nExport = -1;
+ CPDFSDK_PageView *pPageView = GetCurPageView();
+ if (CPWL_ComboBox * pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ nExport = pComboBox->GetSelect();
+ }
+
+ if (nExport >= 0)
+ {
+ if (CPDF_FormField * pFormField = m_pWidget->GetFormField())
+ {
+ swRet = pFormField->GetOptionValue(nExport);
+ if (swRet.IsEmpty())
+ swRet = pFormField->GetOptionLabel(nExport);
+ }
+ }
+
+ return swRet;
+}
diff --git a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
index f514bf29d5..530b80ce6f 100644
--- a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
+++ b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
@@ -1,925 +1,925 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-
-#include "../../include/formfiller/FFL_FormFiller.h"
-#include "../../include/formfiller/FFL_Notify.h"
-#include "../../include/formfiller/FFL_CBA_Fontmap.h"
-
-#define GetRed(rgb) ((FX_BYTE)(rgb))
-#define GetGreen(rgb) ((FX_BYTE)(((FX_WORD)(rgb)) >> 8))
-#define GetBlue(rgb) ((FX_BYTE)((rgb)>>16))
-
-#define FFL_HINT_ELAPSE 800
-
-/* ------------------------- CFFL_FormFiller ------------------------- */
-
-CFFL_FormFiller::CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot)
- :m_pApp(pApp),
- m_pAnnot(pAnnot),
- m_bValid(FALSE),
- m_ptOldPos(0,0)
-{
- m_pWidget = (CPDFSDK_Widget*) pAnnot;
-}
-
-CFFL_FormFiller::~CFFL_FormFiller()
-{
- FX_POSITION pos = m_Maps.GetStartPosition();
- while (pos)
- {
- CPDFSDK_PageView * pPageView = NULL;
- CPWL_Wnd* pWnd = NULL;
- m_Maps.GetNextAssoc(pos, pPageView, pWnd);
-
- if (pWnd)
- {
- CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
- pWnd->Destroy();
- delete pWnd;
- delete pData;
- }
- }
- m_Maps.RemoveAll();
-
-}
-
-void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow)
-{
- if (CPWL_Wnd* pWnd = this->GetPDFWindow(pPageView, FALSE))
- {
- pWnd->Move(CPDF_Rect(rcWindow), TRUE, FALSE);
- }
-}
-
-CPDF_Rect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView)
-{
- if (CPWL_Wnd* pWnd = this->GetPDFWindow(pPageView, FALSE))
- {
- return pWnd->GetWindowRect();
- }
-
- return CPDF_Rect(0,0,0,0);
-}
-
-FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pPageView != NULL);
- ASSERT(pAnnot != NULL);
-
- CPDF_Rect rcAnnot = m_pWidget->GetRect();
-
- if (CPWL_Wnd* pWnd = this->GetPDFWindow(pPageView, FALSE))
- {
- CPDF_Rect rcWindow = pWnd->GetWindowRect();
- rcAnnot = PWLtoFFL(rcWindow);
- }
-
- CPDF_Rect rcWin = rcAnnot;
-// pPageView->DocToWindow(rcAnnot, rcWin);
-
- CPDF_Rect rcFocus = this->GetFocusBox(pPageView);
- if (!rcFocus.IsEmpty())
- rcWin.Union(rcFocus);
-
- CPDF_Rect rect = CPWL_Utils::InflateRect(rcWin,1);
-
- return rect.GetOutterRect();
-}
-
-void CFFL_FormFiller::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
-{
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
- {
- CPDF_Matrix mt = this->GetCurMatrix();
- mt.Concat(*pUser2Device);
- pWnd->DrawAppearance(pDevice,&mt);
- }
- else
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- if (CFFL_IFormFiller::IsVisible(pWidget))
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
- }
-}
-
-void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
-{
- ASSERT(pAnnot != NULL);
-
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
-
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
-}
-
-
-void CFFL_FormFiller::OnCreate(CPDFSDK_Annot* pAnnot)
-{
-}
-
-void CFFL_FormFiller::OnLoad(CPDFSDK_Annot* pAnnot)
-{
-}
-
-void CFFL_FormFiller::OnDelete(CPDFSDK_Annot* pAnnot)
-{
-}
-
-void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
-{
-}
-
-void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
-{
- EndTimer();
- ASSERT(m_pWidget != NULL);
-}
-
-FX_BOOL CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE))
- {
- m_bValid = TRUE;
- FX_RECT rect = this->GetViewBBox(pPageView,pAnnot);
- this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
-
- if(!rect.Contains((int)point.x, (int)point.y))
- return FALSE;
-
- return pWnd->OnLButtonDown(WndtoPWL(pPageView, point),nFlags);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
- {
- FX_RECT rcFFL = this->GetViewBBox(pPageView, pAnnot);
- this->InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom);
- pWnd->OnLButtonUp(WndtoPWL(pPageView, point),nFlags);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
- {
- pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point),nFlags);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- if ((m_ptOldPos.x != point.x) || (m_ptOldPos.y != point.y))
- {
- m_ptOldPos = point;
- }
-
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
- {
- pWnd->OnMouseMove(WndtoPWL(pPageView, point),nFlags);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, short zDelta, const CPDF_Point& point)
-{
- if (!IsValid()) return FALSE;
-
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE))
- {
- return pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point),nFlags);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE))
- {
- pWnd->OnRButtonDown(WndtoPWL(pPageView, point),nFlags);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
- {
- pWnd->OnRButtonUp(WndtoPWL(pPageView, point),nFlags);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
- {
- pWnd->OnRButtonDblClk(WndtoPWL(pPageView, point),nFlags);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
-{
- if (IsValid())
- {
- CPDFSDK_PageView* pPageView = this->GetCurPageView();
- ASSERT(pPageView != NULL);
-
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
- {
- return pWnd->OnKeyDown(nKeyCode,nFlags);
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
-{
- if (IsValid())
- {
- CPDFSDK_PageView* pPageView = this->GetCurPageView();
- ASSERT(pPageView != NULL);
-
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
- {
- return pWnd->OnChar(nChar,nFlags);
- }
- }
-
- return FALSE;
-}
-
-void CFFL_FormFiller::OnDeSelected(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(FALSE);
-}
-
-void CFFL_FormFiller::OnSelected(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(FALSE);
-}
-
-FX_BOOL CFFL_FormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
-{
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
-
- CPDF_Page * pPage = pWidget->GetPDFPage();
- CPDFSDK_Document * pDoc = m_pApp->GetCurrentDoc();
- CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage);
- ASSERT(pPageView != NULL);
-
-
-
- CPWL_Wnd * pWnd = NULL;
- if ( (pWnd = GetPDFWindow(pPageView, TRUE)))
- {
- pWnd->SetFocus();
- }
-
- m_bValid = TRUE;
-
-
-
-
- m_bValid = TRUE;
- FX_RECT rcRect = this->GetViewBBox(pPageView,pAnnot);
- this->InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
-
- return TRUE;
-}
-
-FX_BOOL CFFL_FormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
-{
- if (IsValid())
- {
- CPDFSDK_PageView* pPageView = this->GetCurPageView();
- ASSERT(pPageView != NULL);
-
- CommitData(pPageView, nFlag);
-
- if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE))
- {
- pWnd->KillFocus();
- }
-
- switch (m_pWidget->GetFieldType())
- {
- case FIELDTYPE_PUSHBUTTON:
- case FIELDTYPE_CHECKBOX:
- case FIELDTYPE_RADIOBUTTON:
- EscapeFiller(pPageView, TRUE);
- break;
- default:
- EscapeFiller(pPageView, FALSE);
- break;
- }
- }
-
- return TRUE;
-}
-
-FX_BOOL CFFL_FormFiller::IsValid() const
-{
- return m_bValid;
-}
-
-PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam()
-{
- ASSERT(m_pApp != NULL);
-
- PWL_CREATEPARAM cp;
-
- cp.pParentWnd = NULL;
- cp.pProvider = this;
- cp.rcRectWnd = GetPDFWindowRect();
-
- FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE;
-
- ASSERT(m_pWidget != NULL);
-
-
- FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
-
- if (dwFieldFlag & FIELDFLAG_READONLY)
- {
- dwCreateFlags |= PWS_READONLY;
- }
-
- FX_COLORREF color;
- if (m_pWidget->GetFillColor(color))
- {
- cp.sBackgroundColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
- }
-
- if (m_pWidget->GetBorderColor(color))
- {
- cp.sBorderColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
- }
-
- cp.sTextColor = CPWL_Color(COLORTYPE_GRAY,0);
-
- if (m_pWidget->GetTextColor(color))
- {
- cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
- }
-
- cp.fFontSize = m_pWidget->GetFontSize();
- cp.dwBorderWidth = m_pWidget->GetBorderWidth();
-
- int nBorderStyle = m_pWidget->GetBorderStyle();
-
- switch (nBorderStyle)
- {
- case BBS_SOLID:
- cp.nBorderStyle = PBS_SOLID;
- break;
- case BBS_DASH:
- cp.nBorderStyle = PBS_DASH;
- cp.sDash = CPWL_Dash(3,3,0);
- break;
- case BBS_BEVELED:
- cp.nBorderStyle = PBS_BEVELED;
- cp.dwBorderWidth *= 2;
- break;
- case BBS_INSET:
- cp.nBorderStyle = PBS_INSET;
- cp.dwBorderWidth *= 2;
- break;
- case BBS_UNDERLINE:
- cp.nBorderStyle = PBS_UNDERLINED;
- break;
- }
-
- if (cp.fFontSize <= 0)
- {
- dwCreateFlags |= PWS_AUTOFONTSIZE;
- }
-
- cp.dwFlags = dwCreateFlags;
- cp.pSystemHandler = m_pApp->GetSysHandler();
- return cp;
-}
-
-CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew)
-{
- ASSERT(pPageView != NULL);
- ASSERT(m_pWidget != NULL);
-
- CPWL_Wnd* pWnd = NULL;
- m_Maps.Lookup(pPageView, pWnd);
-
- if (bNew)
- {
- if (pWnd)
- {
- CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData();
- ASSERT(pPrivateData != NULL);
-
- if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge())
- {
- return this->ResetPDFWindow(pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge);
- }
- }
- else
- {
- PWL_CREATEPARAM cp = GetCreateParam();
- cp.hAttachedWnd = (FX_HWND)m_pWidget;
-
- CFFL_PrivateData* pPrivateData = new CFFL_PrivateData;
- pPrivateData->pWidget = m_pWidget;
- pPrivateData->pPageView = pPageView;
- pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge();
- pPrivateData->nValueAge = 0;
-
- cp.pAttachedData = pPrivateData;
-
- pWnd = NewPDFWindow(cp, pPageView);
-
- if (pWnd)
- {
- m_Maps.SetAt(pPageView, pWnd);
- }
- }
- }
-
- return pWnd;
-}
-
-void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView)
-{
- CPWL_Wnd* pWnd = NULL;
- m_Maps.Lookup(pPageView, pWnd);
-
- if (pWnd)
- {
- CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
- pData->pPageView = NULL;
- pWnd->Destroy();
- delete pWnd;
- delete pData;
- }
-
- m_Maps.RemoveKey(pPageView);
-}
-
-CPDF_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData)
-{
- if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData)
- {
- if (pPrivateData->pPageView)
- {
- CPDF_Matrix mtPageView;
- pPrivateData->pPageView->GetCurrentMatrix(mtPageView);
- CPDF_Matrix mt = GetCurMatrix();
- mt.Concat(mtPageView);
-
- return mt;
- }
- }
- return CPDF_Matrix(1,0,0,1,0,0);
-}
-
-CPDF_Matrix CFFL_FormFiller::GetCurMatrix()
-{
- CPDF_Matrix mt;
-
- ASSERT(m_pWidget != NULL);
-
- CPDF_Rect rcDA ;
- m_pWidget->GetPDFAnnot()->GetRect(rcDA);
-
-
- switch (m_pWidget->GetRotate())
- {
- default:
- case 0:
- mt = CPDF_Matrix(1,0,0,1,0,0);
- break;
- case 90:
- mt = CPDF_Matrix(0,1,-1,0,rcDA.right - rcDA.left,0);
- break;
- case 180:
- mt = CPDF_Matrix(-1,0,0,-1,rcDA.right - rcDA.left,rcDA.top - rcDA.bottom);
- break;
- case 270:
- mt = CPDF_Matrix(0,-1,1,0,0,rcDA.top - rcDA.bottom);
- break;
- }
- mt.e += rcDA.left;
- mt.f += rcDA.bottom;
-
- return mt;
-}
-
-CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex)
-{
- ASSERT(m_pApp != NULL);
-
- return L"";
-}
-
-CPDF_Rect CFFL_FormFiller::GetPDFWindowRect() const
-{
- ASSERT(m_pWidget != NULL);
-
- CPDF_Rect rectAnnot;
- m_pWidget->GetPDFAnnot()->GetRect(rectAnnot);
-
- FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
- FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
-
-
- if ((m_pWidget->GetRotate() / 90) & 0x01)
- return CPDF_Rect(0,0,fHeight,fWidth);
- else
- return CPDF_Rect(0,0,fWidth,fHeight);
-}
-
-CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView()
-{
-
- CPDF_Page* pPage = m_pAnnot->GetPDFPage();
- CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc();
- if(pSDKDoc)
- {
- return pSDKDoc->GetPageView(pPage);
- }
- return NULL;
-}
-
-CPDF_Rect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView)
-{
- if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
- {
- CPDF_Rect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect()));
- ASSERT(pPageView);
- CPDF_Rect rcPage = pPageView->GetPDFPage()->GetPageBBox();
- if(rcPage.Contains(rcFocus))
- return rcFocus;
- else
- return CPDF_Rect(0,0,0,0);
- }
- return CPDF_Rect(0,0,0,0);
-}
-
-CPDF_Rect CFFL_FormFiller::FFLtoPWL(const CPDF_Rect& rect)
-{
- CPDF_Matrix mt;
- mt.SetReverse(GetCurMatrix());
-
- CPDF_Rect temp = rect;
- mt.TransformRect(temp);
-
- return temp;
-}
-
-CPDF_Rect CFFL_FormFiller::PWLtoFFL(const CPDF_Rect& rect)
-{
- CPDF_Matrix mt = GetCurMatrix();
-
- CPDF_Rect temp = rect;
- mt.TransformRect(temp);
-
- return temp;
-}
-
-CPDF_Point CFFL_FormFiller::FFLtoPWL(const CPDF_Point& point)
-{
- CPDF_Matrix mt;
- mt.SetReverse(GetCurMatrix());
-
- CPDF_Point pt = point;
- mt.Transform(pt.x,pt.y);
-
- return pt;
-}
-
-CPDF_Point CFFL_FormFiller::PWLtoFFL(const CPDF_Point & point)
-{
- CPDF_Matrix mt = GetCurMatrix();
-
- CPDF_Point pt = point;
- mt.Transform(pt.x,pt.y);
-
- return pt;
-}
-
-CPDF_Point CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, const CPDF_Point& pt)
-{
-// ASSERT(pPageView != NULL);
-//
-// CPDF_Point point(0.0f, 0.0f);
-// pPageView->WindowToDoc(pt.x, pt.y, point.x, point.y);
-//
- return FFLtoPWL(pt);
-// return CPDF_Point(0, 0);
-}
-
-CPDF_Rect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, const CPDF_Rect & rect)
-{
-// FX_RECT rcRet(0,0,0,0);
-//
-// ASSERT(pPageView != NULL);
-// pPageView->DocToWindow(rect, rcRet);
-//
- return rect;
-
-}
-
-void CFFL_FormFiller::FFL_FreeData(void* pData)
-{
- ASSERT(pData != NULL);
-
- delete (CFFL_PrivateData*)pData;
-}
-
-FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag)
-{
- if (IsDataChanged(pPageView))
- {
- //CFFL_IFormFiller* pIFormFiller = CFFL_Module::GetFormFiller(m_pApp);
- CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();//NULL;
- ASSERT(pIFormFiller != NULL);
-
- FX_BOOL bRC = TRUE;
- FX_BOOL bExit = FALSE;
-
- pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag);
- if (bExit) return TRUE;
- if (!bRC)
- {
- this->ResetPDFWindow(pPageView, FALSE);
- return TRUE;
- }
-
- pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag);
- if (bExit) return TRUE;
- if (!bRC)
- {
- this->ResetPDFWindow(pPageView, FALSE);
- return TRUE;
- }
-
- SaveData(pPageView);
-
- pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit,nFlag);
- if (bExit) return TRUE;
-
- pIFormFiller->OnFormat(m_pWidget, pPageView, bExit,nFlag);
- }
-
- return TRUE;
-}
-
-FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView)
-{
- return FALSE;
-}
-
-void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView)
-{
-}
-
-void CFFL_FormFiller::GetKeyStrokeData(CPDFSDK_PageView* pPageView, FFL_KeyStrokeData& data)
-{
-}
-
-void CFFL_FormFiller::SetChangeMark()
-{
- m_pApp->FFI_OnChange();
-}
-
-void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
- PDFSDK_FieldAction& fa)
-{
- fa.sValue = m_pWidget->GetValue();
-}
-
-void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
- const PDFSDK_FieldAction& fa)
-{
-}
-
-FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld,
- const PDFSDK_FieldAction& faNew)
-{
- return FALSE;
-}
-
-void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView)
-{
-}
-
-void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView)
-{
-}
-
-CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
-{
- return GetPDFWindow(pPageView, FALSE);
-}
-
-void CFFL_FormFiller::TimerProc()
-{
-
-}
-
-IFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const
-{
- return m_pApp->GetSysHandler();
-// return NULL;
-}
-
-void CFFL_FormFiller::OnKeyStroke(FX_BOOL bKeyDown)
-{
-}
-
-void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow)
-{
- m_bValid = FALSE;
-
- FX_RECT rcRect = this->GetViewBBox(pPageView, m_pWidget);
- this->InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
-
- if(bDestroyPDFWindow)
- DestroyPDFWindow(pPageView);
-}
-
-FX_BOOL CFFL_FormFiller::CanCopy(CPDFSDK_Document* pDocument)
-{
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::CanCut(CPDFSDK_Document* pDocument)
-{
- return FALSE;
-}
-
-FX_BOOL CFFL_FormFiller::CanPaste(CPDFSDK_Document* pDocument)
-{
- return FALSE;
-}
-
-void CFFL_FormFiller::DoCopy(CPDFSDK_Document* pDocument)
-{
-}
-
-void CFFL_FormFiller::DoCut(CPDFSDK_Document* pDocument)
-{
-}
-
-void CFFL_FormFiller::DoPaste(CPDFSDK_Document* pDocument)
-{
-}
-
-void CFFL_FormFiller::InvalidateRect(double left, double top, double right, double bottom)
-{
- CPDF_Page * pPage = m_pWidget->GetPDFPage();
- m_pApp->FFI_Invalidate(pPage, left, top, right, bottom);
-}
-
-/* ------------------------- CFFL_Button ------------------------- */
-
-CFFL_Button::CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
- CFFL_FormFiller(pApp, pWidget),
- m_bMouseIn(FALSE),
- m_bMouseDown(FALSE)
-{
-}
-
-CFFL_Button::~CFFL_Button()
-{
-}
-
-void CFFL_Button::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
-{
- m_bMouseIn = TRUE;
- FX_RECT rect = this->GetViewBBox(pPageView,pAnnot);
- this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
-// ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE);
-}
-
-void CFFL_Button::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
-{
- m_bMouseIn = FALSE;
-
- FX_RECT rect = this->GetViewBBox(pPageView,pAnnot);
- this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
-// ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE);
- EndTimer();
- ASSERT(m_pWidget != NULL);
-// m_pWidget->HideHint();
-}
-
-FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- CPDF_Rect rcAnnot = pAnnot->GetRect();
- if(!rcAnnot.Contains(point.x, point.y))
- return FALSE;
-
- m_bMouseDown = TRUE;
- m_bValid = TRUE;
- FX_RECT rect = this->GetViewBBox(pPageView, pAnnot);
- this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
-// ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE);
- return TRUE;
-}
-
-FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- CPDF_Rect rcAnnot = pAnnot->GetRect();
- if(!rcAnnot.Contains(point.x, point.y))
- return FALSE;
-
- m_bMouseDown = FALSE;
- m_pWidget->GetPDFPage();
-
-
- FX_RECT rect = this->GetViewBBox(pPageView, pAnnot);
- this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
-// ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE);
- return TRUE;
-}
-
-FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- ASSERT(m_pApp != NULL);
-
- return TRUE;
-}
-
-void CFFL_Button::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
-{
- ASSERT(pPageView != NULL);
- ASSERT(pAnnot != NULL);
-
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
-
- CPDF_FormControl* pCtrl = pWidget->GetFormControl();
- ASSERT(pCtrl != NULL);
-
- CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode();
-
- if (eHM == CPDF_FormControl::Push)
- {
- if (m_bMouseDown)
- {
- if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down))
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL);
- else
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
- }
- else if (m_bMouseIn)
- {
- if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover))
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, NULL);
- else
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
- }
- else
- {
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
- }
- }
- else
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
-}
-
-
-void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- /*const CRect& rcWindow, */FX_DWORD dwFlags)
-{
- OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+
+#include "../../include/formfiller/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_Notify.h"
+#include "../../include/formfiller/FFL_CBA_Fontmap.h"
+
+#define GetRed(rgb) ((FX_BYTE)(rgb))
+#define GetGreen(rgb) ((FX_BYTE)(((FX_WORD)(rgb)) >> 8))
+#define GetBlue(rgb) ((FX_BYTE)((rgb)>>16))
+
+#define FFL_HINT_ELAPSE 800
+
+/* ------------------------- CFFL_FormFiller ------------------------- */
+
+CFFL_FormFiller::CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot)
+ :m_pApp(pApp),
+ m_pAnnot(pAnnot),
+ m_bValid(FALSE),
+ m_ptOldPos(0,0)
+{
+ m_pWidget = (CPDFSDK_Widget*) pAnnot;
+}
+
+CFFL_FormFiller::~CFFL_FormFiller()
+{
+ FX_POSITION pos = m_Maps.GetStartPosition();
+ while (pos)
+ {
+ CPDFSDK_PageView * pPageView = NULL;
+ CPWL_Wnd* pWnd = NULL;
+ m_Maps.GetNextAssoc(pos, pPageView, pWnd);
+
+ if (pWnd)
+ {
+ CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
+ pWnd->Destroy();
+ delete pWnd;
+ delete pData;
+ }
+ }
+ m_Maps.RemoveAll();
+
+}
+
+void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow)
+{
+ if (CPWL_Wnd* pWnd = this->GetPDFWindow(pPageView, FALSE))
+ {
+ pWnd->Move(CPDF_Rect(rcWindow), TRUE, FALSE);
+ }
+}
+
+CPDF_Rect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView)
+{
+ if (CPWL_Wnd* pWnd = this->GetPDFWindow(pPageView, FALSE))
+ {
+ return pWnd->GetWindowRect();
+ }
+
+ return CPDF_Rect(0,0,0,0);
+}
+
+FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pPageView != NULL);
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Rect rcAnnot = m_pWidget->GetRect();
+
+ if (CPWL_Wnd* pWnd = this->GetPDFWindow(pPageView, FALSE))
+ {
+ CPDF_Rect rcWindow = pWnd->GetWindowRect();
+ rcAnnot = PWLtoFFL(rcWindow);
+ }
+
+ CPDF_Rect rcWin = rcAnnot;
+// pPageView->DocToWindow(rcAnnot, rcWin);
+
+ CPDF_Rect rcFocus = this->GetFocusBox(pPageView);
+ if (!rcFocus.IsEmpty())
+ rcWin.Union(rcFocus);
+
+ CPDF_Rect rect = CPWL_Utils::InflateRect(rcWin,1);
+
+ return rect.GetOutterRect();
+}
+
+void CFFL_FormFiller::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
+{
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ CPDF_Matrix mt = this->GetCurMatrix();
+ mt.Concat(*pUser2Device);
+ pWnd->DrawAppearance(pDevice,&mt);
+ }
+ else
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ if (CFFL_IFormFiller::IsVisible(pWidget))
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+ }
+}
+
+void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
+{
+ ASSERT(pAnnot != NULL);
+
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+}
+
+
+void CFFL_FormFiller::OnCreate(CPDFSDK_Annot* pAnnot)
+{
+}
+
+void CFFL_FormFiller::OnLoad(CPDFSDK_Annot* pAnnot)
+{
+}
+
+void CFFL_FormFiller::OnDelete(CPDFSDK_Annot* pAnnot)
+{
+}
+
+void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
+{
+}
+
+void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
+{
+ EndTimer();
+ ASSERT(m_pWidget != NULL);
+}
+
+FX_BOOL CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE))
+ {
+ m_bValid = TRUE;
+ FX_RECT rect = this->GetViewBBox(pPageView,pAnnot);
+ this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
+
+ if(!rect.Contains((int)point.x, (int)point.y))
+ return FALSE;
+
+ return pWnd->OnLButtonDown(WndtoPWL(pPageView, point),nFlags);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ FX_RECT rcFFL = this->GetViewBBox(pPageView, pAnnot);
+ this->InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom);
+ pWnd->OnLButtonUp(WndtoPWL(pPageView, point),nFlags);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point),nFlags);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ if ((m_ptOldPos.x != point.x) || (m_ptOldPos.y != point.y))
+ {
+ m_ptOldPos = point;
+ }
+
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ pWnd->OnMouseMove(WndtoPWL(pPageView, point),nFlags);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, short zDelta, const CPDF_Point& point)
+{
+ if (!IsValid()) return FALSE;
+
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE))
+ {
+ return pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point),nFlags);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE))
+ {
+ pWnd->OnRButtonDown(WndtoPWL(pPageView, point),nFlags);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ pWnd->OnRButtonUp(WndtoPWL(pPageView, point),nFlags);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ pWnd->OnRButtonDblClk(WndtoPWL(pPageView, point),nFlags);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
+{
+ if (IsValid())
+ {
+ CPDFSDK_PageView* pPageView = this->GetCurPageView();
+ ASSERT(pPageView != NULL);
+
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ return pWnd->OnKeyDown(nKeyCode,nFlags);
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
+{
+ if (IsValid())
+ {
+ CPDFSDK_PageView* pPageView = this->GetCurPageView();
+ ASSERT(pPageView != NULL);
+
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ return pWnd->OnChar(nChar,nFlags);
+ }
+ }
+
+ return FALSE;
+}
+
+void CFFL_FormFiller::OnDeSelected(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(FALSE);
+}
+
+void CFFL_FormFiller::OnSelected(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(FALSE);
+}
+
+FX_BOOL CFFL_FormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
+{
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+
+ CPDF_Page * pPage = pWidget->GetPDFPage();
+ CPDFSDK_Document * pDoc = m_pApp->GetCurrentDoc();
+ CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage);
+ ASSERT(pPageView != NULL);
+
+
+
+ CPWL_Wnd * pWnd = NULL;
+ if ( (pWnd = GetPDFWindow(pPageView, TRUE)))
+ {
+ pWnd->SetFocus();
+ }
+
+ m_bValid = TRUE;
+
+
+
+
+ m_bValid = TRUE;
+ FX_RECT rcRect = this->GetViewBBox(pPageView,pAnnot);
+ this->InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
+
+ return TRUE;
+}
+
+FX_BOOL CFFL_FormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
+{
+ if (IsValid())
+ {
+ CPDFSDK_PageView* pPageView = this->GetCurPageView();
+ ASSERT(pPageView != NULL);
+
+ CommitData(pPageView, nFlag);
+
+ if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ pWnd->KillFocus();
+ }
+
+ switch (m_pWidget->GetFieldType())
+ {
+ case FIELDTYPE_PUSHBUTTON:
+ case FIELDTYPE_CHECKBOX:
+ case FIELDTYPE_RADIOBUTTON:
+ EscapeFiller(pPageView, TRUE);
+ break;
+ default:
+ EscapeFiller(pPageView, FALSE);
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CFFL_FormFiller::IsValid() const
+{
+ return m_bValid;
+}
+
+PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam()
+{
+ ASSERT(m_pApp != NULL);
+
+ PWL_CREATEPARAM cp;
+
+ cp.pParentWnd = NULL;
+ cp.pProvider = this;
+ cp.rcRectWnd = GetPDFWindowRect();
+
+ FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE;
+
+ ASSERT(m_pWidget != NULL);
+
+
+ FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
+
+ if (dwFieldFlag & FIELDFLAG_READONLY)
+ {
+ dwCreateFlags |= PWS_READONLY;
+ }
+
+ FX_COLORREF color;
+ if (m_pWidget->GetFillColor(color))
+ {
+ cp.sBackgroundColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
+ }
+
+ if (m_pWidget->GetBorderColor(color))
+ {
+ cp.sBorderColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
+ }
+
+ cp.sTextColor = CPWL_Color(COLORTYPE_GRAY,0);
+
+ if (m_pWidget->GetTextColor(color))
+ {
+ cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
+ }
+
+ cp.fFontSize = m_pWidget->GetFontSize();
+ cp.dwBorderWidth = m_pWidget->GetBorderWidth();
+
+ int nBorderStyle = m_pWidget->GetBorderStyle();
+
+ switch (nBorderStyle)
+ {
+ case BBS_SOLID:
+ cp.nBorderStyle = PBS_SOLID;
+ break;
+ case BBS_DASH:
+ cp.nBorderStyle = PBS_DASH;
+ cp.sDash = CPWL_Dash(3,3,0);
+ break;
+ case BBS_BEVELED:
+ cp.nBorderStyle = PBS_BEVELED;
+ cp.dwBorderWidth *= 2;
+ break;
+ case BBS_INSET:
+ cp.nBorderStyle = PBS_INSET;
+ cp.dwBorderWidth *= 2;
+ break;
+ case BBS_UNDERLINE:
+ cp.nBorderStyle = PBS_UNDERLINED;
+ break;
+ }
+
+ if (cp.fFontSize <= 0)
+ {
+ dwCreateFlags |= PWS_AUTOFONTSIZE;
+ }
+
+ cp.dwFlags = dwCreateFlags;
+ cp.pSystemHandler = m_pApp->GetSysHandler();
+ return cp;
+}
+
+CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew)
+{
+ ASSERT(pPageView != NULL);
+ ASSERT(m_pWidget != NULL);
+
+ CPWL_Wnd* pWnd = NULL;
+ m_Maps.Lookup(pPageView, pWnd);
+
+ if (bNew)
+ {
+ if (pWnd)
+ {
+ CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData();
+ ASSERT(pPrivateData != NULL);
+
+ if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge())
+ {
+ return this->ResetPDFWindow(pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge);
+ }
+ }
+ else
+ {
+ PWL_CREATEPARAM cp = GetCreateParam();
+ cp.hAttachedWnd = (FX_HWND)m_pWidget;
+
+ CFFL_PrivateData* pPrivateData = new CFFL_PrivateData;
+ pPrivateData->pWidget = m_pWidget;
+ pPrivateData->pPageView = pPageView;
+ pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge();
+ pPrivateData->nValueAge = 0;
+
+ cp.pAttachedData = pPrivateData;
+
+ pWnd = NewPDFWindow(cp, pPageView);
+
+ if (pWnd)
+ {
+ m_Maps.SetAt(pPageView, pWnd);
+ }
+ }
+ }
+
+ return pWnd;
+}
+
+void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView)
+{
+ CPWL_Wnd* pWnd = NULL;
+ m_Maps.Lookup(pPageView, pWnd);
+
+ if (pWnd)
+ {
+ CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
+ pData->pPageView = NULL;
+ pWnd->Destroy();
+ delete pWnd;
+ delete pData;
+ }
+
+ m_Maps.RemoveKey(pPageView);
+}
+
+CPDF_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData)
+{
+ if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData)
+ {
+ if (pPrivateData->pPageView)
+ {
+ CPDF_Matrix mtPageView;
+ pPrivateData->pPageView->GetCurrentMatrix(mtPageView);
+ CPDF_Matrix mt = GetCurMatrix();
+ mt.Concat(mtPageView);
+
+ return mt;
+ }
+ }
+ return CPDF_Matrix(1,0,0,1,0,0);
+}
+
+CPDF_Matrix CFFL_FormFiller::GetCurMatrix()
+{
+ CPDF_Matrix mt;
+
+ ASSERT(m_pWidget != NULL);
+
+ CPDF_Rect rcDA ;
+ m_pWidget->GetPDFAnnot()->GetRect(rcDA);
+
+
+ switch (m_pWidget->GetRotate())
+ {
+ default:
+ case 0:
+ mt = CPDF_Matrix(1,0,0,1,0,0);
+ break;
+ case 90:
+ mt = CPDF_Matrix(0,1,-1,0,rcDA.right - rcDA.left,0);
+ break;
+ case 180:
+ mt = CPDF_Matrix(-1,0,0,-1,rcDA.right - rcDA.left,rcDA.top - rcDA.bottom);
+ break;
+ case 270:
+ mt = CPDF_Matrix(0,-1,1,0,0,rcDA.top - rcDA.bottom);
+ break;
+ }
+ mt.e += rcDA.left;
+ mt.f += rcDA.bottom;
+
+ return mt;
+}
+
+CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex)
+{
+ ASSERT(m_pApp != NULL);
+
+ return L"";
+}
+
+CPDF_Rect CFFL_FormFiller::GetPDFWindowRect() const
+{
+ ASSERT(m_pWidget != NULL);
+
+ CPDF_Rect rectAnnot;
+ m_pWidget->GetPDFAnnot()->GetRect(rectAnnot);
+
+ FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
+ FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
+
+
+ if ((m_pWidget->GetRotate() / 90) & 0x01)
+ return CPDF_Rect(0,0,fHeight,fWidth);
+ else
+ return CPDF_Rect(0,0,fWidth,fHeight);
+}
+
+CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView()
+{
+
+ CPDF_Page* pPage = m_pAnnot->GetPDFPage();
+ CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc();
+ if(pSDKDoc)
+ {
+ return pSDKDoc->GetPageView(pPage);
+ }
+ return NULL;
+}
+
+CPDF_Rect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView)
+{
+ if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
+ {
+ CPDF_Rect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect()));
+ ASSERT(pPageView);
+ CPDF_Rect rcPage = pPageView->GetPDFPage()->GetPageBBox();
+ if(rcPage.Contains(rcFocus))
+ return rcFocus;
+ else
+ return CPDF_Rect(0,0,0,0);
+ }
+ return CPDF_Rect(0,0,0,0);
+}
+
+CPDF_Rect CFFL_FormFiller::FFLtoPWL(const CPDF_Rect& rect)
+{
+ CPDF_Matrix mt;
+ mt.SetReverse(GetCurMatrix());
+
+ CPDF_Rect temp = rect;
+ mt.TransformRect(temp);
+
+ return temp;
+}
+
+CPDF_Rect CFFL_FormFiller::PWLtoFFL(const CPDF_Rect& rect)
+{
+ CPDF_Matrix mt = GetCurMatrix();
+
+ CPDF_Rect temp = rect;
+ mt.TransformRect(temp);
+
+ return temp;
+}
+
+CPDF_Point CFFL_FormFiller::FFLtoPWL(const CPDF_Point& point)
+{
+ CPDF_Matrix mt;
+ mt.SetReverse(GetCurMatrix());
+
+ CPDF_Point pt = point;
+ mt.Transform(pt.x,pt.y);
+
+ return pt;
+}
+
+CPDF_Point CFFL_FormFiller::PWLtoFFL(const CPDF_Point & point)
+{
+ CPDF_Matrix mt = GetCurMatrix();
+
+ CPDF_Point pt = point;
+ mt.Transform(pt.x,pt.y);
+
+ return pt;
+}
+
+CPDF_Point CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, const CPDF_Point& pt)
+{
+// ASSERT(pPageView != NULL);
+//
+// CPDF_Point point(0.0f, 0.0f);
+// pPageView->WindowToDoc(pt.x, pt.y, point.x, point.y);
+//
+ return FFLtoPWL(pt);
+// return CPDF_Point(0, 0);
+}
+
+CPDF_Rect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, const CPDF_Rect & rect)
+{
+// FX_RECT rcRet(0,0,0,0);
+//
+// ASSERT(pPageView != NULL);
+// pPageView->DocToWindow(rect, rcRet);
+//
+ return rect;
+
+}
+
+void CFFL_FormFiller::FFL_FreeData(void* pData)
+{
+ ASSERT(pData != NULL);
+
+ delete (CFFL_PrivateData*)pData;
+}
+
+FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag)
+{
+ if (IsDataChanged(pPageView))
+ {
+ //CFFL_IFormFiller* pIFormFiller = CFFL_Module::GetFormFiller(m_pApp);
+ CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();//NULL;
+ ASSERT(pIFormFiller != NULL);
+
+ FX_BOOL bRC = TRUE;
+ FX_BOOL bExit = FALSE;
+
+ pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag);
+ if (bExit) return TRUE;
+ if (!bRC)
+ {
+ this->ResetPDFWindow(pPageView, FALSE);
+ return TRUE;
+ }
+
+ pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag);
+ if (bExit) return TRUE;
+ if (!bRC)
+ {
+ this->ResetPDFWindow(pPageView, FALSE);
+ return TRUE;
+ }
+
+ SaveData(pPageView);
+
+ pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit,nFlag);
+ if (bExit) return TRUE;
+
+ pIFormFiller->OnFormat(m_pWidget, pPageView, bExit,nFlag);
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView)
+{
+ return FALSE;
+}
+
+void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView)
+{
+}
+
+void CFFL_FormFiller::GetKeyStrokeData(CPDFSDK_PageView* pPageView, FFL_KeyStrokeData& data)
+{
+}
+
+void CFFL_FormFiller::SetChangeMark()
+{
+ m_pApp->FFI_OnChange();
+}
+
+void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
+ PDFSDK_FieldAction& fa)
+{
+ fa.sValue = m_pWidget->GetValue();
+}
+
+void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
+ const PDFSDK_FieldAction& fa)
+{
+}
+
+FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld,
+ const PDFSDK_FieldAction& faNew)
+{
+ return FALSE;
+}
+
+void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView)
+{
+}
+
+void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView)
+{
+}
+
+CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
+{
+ return GetPDFWindow(pPageView, FALSE);
+}
+
+void CFFL_FormFiller::TimerProc()
+{
+
+}
+
+IFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const
+{
+ return m_pApp->GetSysHandler();
+// return NULL;
+}
+
+void CFFL_FormFiller::OnKeyStroke(FX_BOOL bKeyDown)
+{
+}
+
+void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow)
+{
+ m_bValid = FALSE;
+
+ FX_RECT rcRect = this->GetViewBBox(pPageView, m_pWidget);
+ this->InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
+
+ if(bDestroyPDFWindow)
+ DestroyPDFWindow(pPageView);
+}
+
+FX_BOOL CFFL_FormFiller::CanCopy(CPDFSDK_Document* pDocument)
+{
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::CanCut(CPDFSDK_Document* pDocument)
+{
+ return FALSE;
+}
+
+FX_BOOL CFFL_FormFiller::CanPaste(CPDFSDK_Document* pDocument)
+{
+ return FALSE;
+}
+
+void CFFL_FormFiller::DoCopy(CPDFSDK_Document* pDocument)
+{
+}
+
+void CFFL_FormFiller::DoCut(CPDFSDK_Document* pDocument)
+{
+}
+
+void CFFL_FormFiller::DoPaste(CPDFSDK_Document* pDocument)
+{
+}
+
+void CFFL_FormFiller::InvalidateRect(double left, double top, double right, double bottom)
+{
+ CPDF_Page * pPage = m_pWidget->GetPDFPage();
+ m_pApp->FFI_Invalidate(pPage, left, top, right, bottom);
+}
+
+/* ------------------------- CFFL_Button ------------------------- */
+
+CFFL_Button::CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
+ CFFL_FormFiller(pApp, pWidget),
+ m_bMouseIn(FALSE),
+ m_bMouseDown(FALSE)
+{
+}
+
+CFFL_Button::~CFFL_Button()
+{
+}
+
+void CFFL_Button::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
+{
+ m_bMouseIn = TRUE;
+ FX_RECT rect = this->GetViewBBox(pPageView,pAnnot);
+ this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
+// ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE);
+}
+
+void CFFL_Button::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
+{
+ m_bMouseIn = FALSE;
+
+ FX_RECT rect = this->GetViewBBox(pPageView,pAnnot);
+ this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
+// ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE);
+ EndTimer();
+ ASSERT(m_pWidget != NULL);
+// m_pWidget->HideHint();
+}
+
+FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ CPDF_Rect rcAnnot = pAnnot->GetRect();
+ if(!rcAnnot.Contains(point.x, point.y))
+ return FALSE;
+
+ m_bMouseDown = TRUE;
+ m_bValid = TRUE;
+ FX_RECT rect = this->GetViewBBox(pPageView, pAnnot);
+ this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
+// ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE);
+ return TRUE;
+}
+
+FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ CPDF_Rect rcAnnot = pAnnot->GetRect();
+ if(!rcAnnot.Contains(point.x, point.y))
+ return FALSE;
+
+ m_bMouseDown = FALSE;
+ m_pWidget->GetPDFPage();
+
+
+ FX_RECT rect = this->GetViewBBox(pPageView, pAnnot);
+ this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
+// ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE);
+ return TRUE;
+}
+
+FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ ASSERT(m_pApp != NULL);
+
+ return TRUE;
+}
+
+void CFFL_Button::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
+{
+ ASSERT(pPageView != NULL);
+ ASSERT(pAnnot != NULL);
+
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+
+ CPDF_FormControl* pCtrl = pWidget->GetFormControl();
+ ASSERT(pCtrl != NULL);
+
+ CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode();
+
+ if (eHM == CPDF_FormControl::Push)
+ {
+ if (m_bMouseDown)
+ {
+ if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down))
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL);
+ else
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+ }
+ else if (m_bMouseIn)
+ {
+ if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover))
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, NULL);
+ else
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+ }
+ else
+ {
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+ }
+ }
+ else
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+}
+
+
+void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ /*const CRect& rcWindow, */FX_DWORD dwFlags)
+{
+ OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
+}
diff --git a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
index 686b38c557..2b21e13cfc 100644
--- a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
+++ b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
@@ -1,1197 +1,1197 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/formfiller/FFL_FormFiller.h"
-#include "../../include/formfiller/FFL_IFormFiller.h"
-#include "../../include/formfiller/FFL_CheckBox.h"
-#include "../../include/formfiller/FFL_ComboBox.h"
-#include "../../include/formfiller/FFL_ListBox.h"
-#include "../../include/formfiller/FFL_PushButton.h"
-#include "../../include/formfiller/FFL_RadioButton.h"
-#include "../../include/formfiller/FFL_TextField.h"
-
-#define FFL_MAXLISTBOXHEIGHT 140.0f
-
-// HHOOK CFFL_IFormFiller::m_hookSheet = NULL;
-// MSG CFFL_IFormFiller::g_Msg;
-
-/* ----------------------------- CFFL_IFormFiller ----------------------------- */
-
-CFFL_IFormFiller::CFFL_IFormFiller(CPDFDoc_Environment* pApp) :
- m_pApp(pApp),
- m_bNotifying(FALSE)
-{
-}
-
-CFFL_IFormFiller::~CFFL_IFormFiller()
-{
- FX_POSITION pos = m_Maps.GetStartPosition();
- while (pos)
- {
- CPDFSDK_Annot * pAnnot = NULL;
- CFFL_FormFiller * pFormFiller = NULL;
- m_Maps.GetNextAssoc(pos,pAnnot,pFormFiller);
- delete pFormFiller;
- }
- m_Maps.RemoveAll();
-}
-
-FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView,CPDFSDK_Annot* pAnnot, CPDF_Point point)
-{
- CPDF_Rect rc = pAnnot->GetRect();
- if(rc.Contains(point.x, point.y))
- return TRUE;
- return FALSE;
-}
-
-FX_RECT CFFL_IFormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot)
-{
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- return pFormFiller->GetViewBBox(pPageView, pAnnot);
- }
- else
- {
- ASSERT(pPageView != NULL);
- ASSERT(pAnnot != NULL);
-
- CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
- ASSERT(pPDFAnnot != NULL);
-
- CPDF_Rect rcAnnot;
- pPDFAnnot->GetRect(rcAnnot);
-
-// CRect rcWin;
-// pPageView->DocToWindow(rcAnnot, rcWin);
- CPDF_Rect rcWin = CPWL_Utils::InflateRect(rcAnnot,1);
-// rcWin.InflateRect(1, 1);
-
- return rcWin.GetOutterRect();
- }
-}
-
-void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
-{
- ASSERT(pPageView != NULL);
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
-
- if (IsVisible(pWidget))
- {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- if (pFormFiller->IsValid())
- {
- pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
-
- pAnnot->GetPDFPage();
-
-
- CPDFSDK_Document* pDocument = m_pApp->GetCurrentDoc();
- ASSERT(pDocument != NULL);
-
- if (pDocument->GetFocusAnnot() == pAnnot)
- {
- CPDF_Rect rcFocus = pFormFiller->GetFocusBox(pPageView);
- if (!rcFocus.IsEmpty())
- {
- CFX_PathData path;
-
- path.SetPointCount(5);
- path.SetPoint(0, rcFocus.left, rcFocus.top, FXPT_MOVETO);
- path.SetPoint(1, rcFocus.left, rcFocus.bottom, FXPT_LINETO);
- path.SetPoint(2, rcFocus.right, rcFocus.bottom, FXPT_LINETO);
- path.SetPoint(3, rcFocus.right, rcFocus.top, FXPT_LINETO);
- path.SetPoint(4, rcFocus.left, rcFocus.top, FXPT_LINETO);
-
- CFX_GraphStateData gsd;
- gsd.SetDashCount(1);
- gsd.m_DashArray[0] = 1.0f;
- gsd.m_DashPhase = 0;
-
- gsd.m_LineWidth = 1.0f;
- pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,0,0,0), FXFILL_ALTERNATE);
-
- // ::DrawFocusRect(hDC, &rcFocus);
- }
- }
-
- return;
- }
- }
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- pFormFiller->OnDrawDeactive(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
- else
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
-
- if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget))
- {
- pWidget->DrawShadow(pDevice, pPageView);
- }
-
- }
-}
-
-void CFFL_IFormFiller::OnCreate(CPDFSDK_Annot* pAnnot)
-{
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- pFormFiller->OnCreate(pAnnot);
- }
-}
-
-void CFFL_IFormFiller::OnLoad(CPDFSDK_Annot* pAnnot)
-{
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- pFormFiller->OnLoad(pAnnot);
- }
-}
-
-void CFFL_IFormFiller::OnDelete(CPDFSDK_Annot* pAnnot)
-{
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- pFormFiller->OnDelete(pAnnot);
- }
-
- UnRegisterFormFiller(pAnnot);
-}
-
-void CFFL_IFormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (!m_bNotifying)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- if (pWidget->GetAAction(CPDF_AAction::CursorEnter))
- {
- m_bNotifying = TRUE;
-
- int nValueAge = pWidget->GetValueAge();
-
- pWidget->ClearAppModified();
-
- ASSERT(pPageView != NULL);
-
-
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
- fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
- pWidget->OnAAction(CPDF_AAction::CursorEnter, fa, pPageView );
- m_bNotifying = FALSE;
-
- //if ( !IsValidAnnot(pPageView, pAnnot) ) return;
-
- if (pWidget->IsAppModified())
- {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
- {
- pFormFiller->ResetPDFWindow(pPageView, pWidget->GetValueAge() == nValueAge);
- }
- }
- }
- }
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))
- {
- pFormFiller->OnMouseEnter(pPageView, pAnnot);
- }
-}
-
-void CFFL_IFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (!m_bNotifying)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- if (pWidget->GetAAction(CPDF_AAction::CursorExit))
- {
- m_bNotifying = TRUE;
- pWidget->GetAppearanceAge();
- int nValueAge = pWidget->GetValueAge();
- pWidget->ClearAppModified();
-
- ASSERT(pPageView != NULL);
-
-
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
- fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
-
- pWidget->OnAAction(CPDF_AAction::CursorExit, fa, pPageView);
- m_bNotifying = FALSE;
-
- //if (!IsValidAnnot(pPageView, pAnnot)) return;
-
- if (pWidget->IsAppModified())
- {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
- {
- pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
- }
- }
- }
- }
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- pFormFiller->OnMouseExit(pPageView, pAnnot);
- }
-}
-
-FX_BOOL CFFL_IFormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (!m_bNotifying)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- if (Annot_HitTest(pPageView, pAnnot, point) && pWidget->GetAAction(CPDF_AAction::ButtonDown))
- {
- m_bNotifying = TRUE;
- pWidget->GetAppearanceAge();
- int nValueAge = pWidget->GetValueAge();
- pWidget->ClearAppModified();
-
- ASSERT(pPageView != NULL);
-
-
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlags);
- fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlags);
- pWidget->OnAAction(CPDF_AAction::ButtonDown, fa, pPageView);
- m_bNotifying = FALSE;
-
- if (!IsValidAnnot(pPageView, pAnnot)) return TRUE;
-
- if (pWidget->IsAppModified())
- {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
- {
- pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
- }
- }
- }
- }
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- return pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- // CReader_Page* pPage = pAnnot->GetPage();
- // ASSERT(pPage != NULL);
- CPDFSDK_Document* pDocument = m_pApp->GetCurrentDoc();
- ASSERT(pDocument != NULL);
-
- switch (pWidget->GetFieldType())
- {
- case FIELDTYPE_PUSHBUTTON:
- case FIELDTYPE_CHECKBOX:
- case FIELDTYPE_RADIOBUTTON:
- if (GetViewBBox(pPageView, pAnnot).Contains((int)point.x, (int)point.y))
- {
- pDocument->SetFocusAnnot(pAnnot);
- }
- break;
- default:
- pDocument->SetFocusAnnot(pAnnot);
- break;
- }
-
- FX_BOOL bRet = FALSE;
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- bRet = pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
- }
-
- if (pDocument->GetFocusAnnot() == pAnnot)
- {
- FX_BOOL bExit = FALSE;
- FX_BOOL bReset = FALSE;
- OnButtonUp(pWidget, pPageView, bReset, bExit,nFlags);
- if (bExit) return TRUE;
- }
- return bRet;
-}
-
-void CFFL_IFormFiller::OnButtonUp(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, FX_BOOL& bExit,FX_UINT nFlag)
-{
- ASSERT(pWidget != NULL);
-
- if (!m_bNotifying)
- {
- if (pWidget->GetAAction(CPDF_AAction::ButtonUp))
- {
- m_bNotifying = TRUE;
- int nAge = pWidget->GetAppearanceAge();
- int nValueAge = pWidget->GetValueAge();
-
- ASSERT(pPageView != NULL);
-// CReader_DocView* pDocView = pPageView->GetDocView();
-// ASSERT(pDocView != NULL);
-
-
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
- fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
-
- pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView);
- m_bNotifying = FALSE;
-
- if (!IsValidAnnot(pPageView, pWidget))
- {
- bExit = TRUE;
- return;
- }
-
- if (nAge != pWidget->GetAppearanceAge())
- {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
- {
- pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
- }
-
- bReset = TRUE;
- }
- }
- }
-}
-
-FX_BOOL CFFL_IFormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- return pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- //change cursor
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))
- {
- return pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, short zDelta, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- return pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- return pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- return pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::OnRButtonDblClk(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- return pFormFiller->OnRButtonDblClk(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags);
- }
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (nChar == FWL_VKEY_Tab) return TRUE;
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- return pFormFiller->OnChar(pAnnot, nChar, nFlags);
- }
-
- return FALSE;
-}
-
-void CFFL_IFormFiller::OnDeSelected(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- pFormFiller->OnDeSelected(pAnnot);
- }
-}
-
-void CFFL_IFormFiller::OnSelected(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- pFormFiller->OnSelected(pAnnot);
- }
-}
-
-FX_BOOL CFFL_IFormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
-{
- if(!pAnnot) return FALSE;
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (!m_bNotifying)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- if (pWidget->GetAAction(CPDF_AAction::GetFocus))
- {
- m_bNotifying = TRUE;
- pWidget->GetAppearanceAge();
- int nValueAge = pWidget->GetValueAge();
- pWidget->ClearAppModified();
-
-
- CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
- ASSERT(pPageView != NULL);
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
- fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
-
-
- CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, TRUE);
- if(!pFormFiller) return FALSE;
- pFormFiller->GetActionData(pPageView, CPDF_AAction::GetFocus, fa);
-
- pWidget->OnAAction(CPDF_AAction::GetFocus, fa, pPageView);
- m_bNotifying = FALSE;
-
- // if (!IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pAnnot)) return FALSE;
-
- if (pWidget->IsAppModified())
- {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
- {
- pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
- }
- }
- }
- }
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))
- {
- if (pFormFiller->OnSetFocus(pAnnot, nFlag))
- {
- return TRUE;
- }
- else
- return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CFFL_IFormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
-{
- if(!pAnnot) return FALSE;
- ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
- {
- if (pFormFiller->OnKillFocus(pAnnot, nFlag))
- {
- if (!m_bNotifying)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- if (pWidget->GetAAction(CPDF_AAction::LoseFocus))
- {
- m_bNotifying = TRUE;
- pWidget->ClearAppModified();
-
- CPDFSDK_PageView* pPageView = pWidget->GetPageView();
- ASSERT(pPageView != NULL);
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
- fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
-
- pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa);
-
- pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView);
- m_bNotifying = FALSE;
-
- }
- }
- }
- else
- return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CFFL_IFormFiller::IsVisible(CPDFSDK_Widget* pWidget)
-{
- return pWidget->IsVisible();
-}
-
-FX_BOOL CFFL_IFormFiller::IsReadOnly(CPDFSDK_Widget* pWidget)
-{
- ASSERT(pWidget != NULL);
-
- int nFieldFlags = pWidget->GetFieldFlags();
-
- return (nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY;
-}
-
-FX_BOOL CFFL_IFormFiller::IsFillingAllowed(CPDFSDK_Widget* pWidget)
-{
- ASSERT(pWidget != NULL);
-
- if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
- return TRUE;
- else
- {
- CPDF_Page* pPage = pWidget->GetPDFPage();
- ASSERT(pPage != NULL);
-
- CPDF_Document* pDocument = pPage->m_pDocument;
- ASSERT(pDocument != NULL);
-
- FX_DWORD dwPermissions = pDocument->GetUserPermissions();
- return (dwPermissions&FPDFPERM_FILL_FORM) ||
- (dwPermissions&FPDFPERM_ANNOT_FORM) ||
- (dwPermissions&FPDFPERM_MODIFY);
- }
- return TRUE;
-}
-
-CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister)
-{
-// ASSERT(pAnnot != NULL);
-// ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
-
- CFFL_FormFiller * pFormFiller = NULL;
- m_Maps.Lookup(pAnnot, pFormFiller);
-
- if (pFormFiller)
- return pFormFiller;
-
- if (bRegister)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
-
- int nFieldType = pWidget->GetFieldType();
- switch(nFieldType)
- {
- case FIELDTYPE_PUSHBUTTON:
- pFormFiller = new CFFL_PushButton(m_pApp, pWidget);
- break;
- case FIELDTYPE_CHECKBOX:
- pFormFiller = new CFFL_CheckBox(m_pApp, pWidget);
- break;
- case FIELDTYPE_RADIOBUTTON:
- pFormFiller = new CFFL_RadioButton(m_pApp, pWidget);
- break;
- case FIELDTYPE_TEXTFIELD:
- pFormFiller = new CFFL_TextField(m_pApp, pWidget);
- break;
- case FIELDTYPE_LISTBOX:
- pFormFiller = new CFFL_ListBox(m_pApp, pWidget);
- break;
- case FIELDTYPE_COMBOBOX:
- pFormFiller = new CFFL_ComboBox(m_pApp, pWidget);
- break;
- case FIELDTYPE_UNKNOWN:
- default:
- pFormFiller = NULL;
- break;
- }
-
- if (pFormFiller)
- {
- m_Maps.SetAt(pAnnot, pFormFiller);
- }
- }
-
- return pFormFiller;
-}
-
-void CFFL_IFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot)
-{
- if ( pAnnot != NULL )
- {
- UnRegisterFormFiller( pAnnot );
- }
-}
-
-void CFFL_IFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot)
-{
- CFFL_FormFiller * pFormFiller = NULL;
-
- if (m_Maps.Lookup(pAnnot,pFormFiller))
- {
- if (pFormFiller)
- delete pFormFiller;
- m_Maps.RemoveKey(pAnnot);
- }
-}
-
-void CFFL_IFormFiller::SetFocusAnnotTab(CPDFSDK_Annot* pWidget, FX_BOOL bSameField, FX_BOOL bNext)
-{
-
-}
-
-void CFFL_IFormFiller::QueryWherePopup(void* pPrivateData, FX_FLOAT fPopupMin,FX_FLOAT fPopupMax, FX_INT32 & nRet, FX_FLOAT & fPopupRet)
-{
- ASSERT(pPrivateData != NULL);
-
- CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
-
-
-
-
- CPDF_Rect rcPageView(0,0,0,0);
- rcPageView.right = pData->pWidget->GetPDFPage()->GetPageWidth();
- rcPageView.bottom = pData->pWidget->GetPDFPage()->GetPageHeight();
- rcPageView.Normalize();
-
-
- ASSERT(pData->pWidget != NULL);
- CPDF_Rect rcAnnot = pData->pWidget->GetRect();
-
- FX_FLOAT fTop = 0.0f;
- FX_FLOAT fBottom = 0.0f;
-
- CPDFSDK_Widget * pWidget = (CPDFSDK_Widget*)pData->pWidget;
- switch (pWidget->GetRotate() / 90)
- {
- default:
- case 0:
- fTop = rcPageView.top - rcAnnot.top;
- fBottom = rcAnnot.bottom - rcPageView.bottom;
- break;
- case 1:
- fTop = rcAnnot.left - rcPageView.left;
- fBottom = rcPageView.right - rcAnnot.right;
- break;
- case 2:
- fTop = rcAnnot.bottom - rcPageView.bottom;
- fBottom = rcPageView.top - rcAnnot.top;
- break;
- case 3:
- fTop = rcPageView.right - rcAnnot.right;
- fBottom = rcAnnot.left - rcPageView.left;
- break;
- }
-
- FX_FLOAT fFactHeight = 0;
- FX_BOOL bBottom = TRUE;
- FX_FLOAT fMaxListBoxHeight = 0;
- if (fPopupMax > FFL_MAXLISTBOXHEIGHT)
- {
- if (fPopupMin > FFL_MAXLISTBOXHEIGHT)
- {
- fMaxListBoxHeight = fPopupMin;
- }
- else
- {
- fMaxListBoxHeight = FFL_MAXLISTBOXHEIGHT;
- }
- }
- else
- fMaxListBoxHeight = fPopupMax;
-
- if (fBottom > fMaxListBoxHeight)
- {
- fFactHeight = fMaxListBoxHeight;
- bBottom = TRUE;
- }
- else
- {
- if (fTop > fMaxListBoxHeight)
- {
- fFactHeight = fMaxListBoxHeight;
- bBottom = FALSE;
- }
- else
- {
- if (fTop > fBottom)
- {
- fFactHeight = fTop;
- bBottom = FALSE;
- }
- else
- {
- fFactHeight = fBottom;
- bBottom = TRUE;
- }
- }
- }
-
- nRet = bBottom ? 0 : 1;
- fPopupRet = fFactHeight;
-}
-
-void CFFL_IFormFiller::OnSetWindowRect(void* pPrivateData, const CPDF_Rect & rcWindow)
-{
- ASSERT(pPrivateData != NULL);
-
- CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
-
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, TRUE))
- {
-
- CPDF_Rect rcOld = pFormFiller->PWLtoFFL(pFormFiller->GetWindowRect(pData->pPageView));
- CPDF_Rect rcNew = pFormFiller->PWLtoFFL(rcWindow);
- pFormFiller->SetWindowRect(pData->pPageView, rcWindow);
-
- CPDF_Rect unRect = rcOld;
- unRect.Union(rcNew);
- //FX_RECT rcRect = unRect.GetOutterRect();
- unRect.left = (FX_FLOAT)(unRect.left - 0.5);
- unRect.right = (FX_FLOAT)(unRect.right + 0.5);
- unRect.top = (FX_FLOAT)(unRect.top + 0.5);
- unRect.bottom = (FX_FLOAT)(unRect.bottom -0.5);
- m_pApp->FFI_Invalidate(pData->pWidget->GetPDFPage(), unRect.left, unRect.top, unRect.right, unRect.bottom);
- }
-}
-
-void CFFL_IFormFiller::OnKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_INT32 nKeyCode, CFX_WideString& strChange,
- const CFX_WideString& strChangeEx, FX_BOOL bKeyDown,
- FX_BOOL & bRC, FX_BOOL & bExit)
-{
- ASSERT(pPrivateData != NULL);
- CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
- ASSERT(pData->pWidget != NULL);
-
- CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);
- ASSERT(pFormFiller != NULL);
-
- pFormFiller->OnKeyStroke(bKeyDown);
-}
-
-void CFFL_IFormFiller::OnKeyStrokeCommit(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bRC, FX_BOOL& bExit, FX_DWORD nFlag)
-{
- if (!m_bNotifying)
- {
- ASSERT(pWidget != NULL);
- if (pWidget->GetAAction(CPDF_AAction::KeyStroke))
- {
- m_bNotifying = TRUE;
- pWidget->ClearAppModified();
-
- ASSERT(pPageView != NULL);
-// CReader_DocView* pDocView = pPageView->GetDocView();
-// ASSERT(pDocView != NULL);
-
-
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
- fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
- fa.bWillCommit = TRUE;
- fa.nCommitKey = GetCommitKey();
- fa.bKeyDown = GetKeyDown();
- fa.bRC = TRUE;
-
- CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE);
- ASSERT(pFormFiller != NULL);
-
- pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa);
- pFormFiller->SaveState(pPageView);
-
- PDFSDK_FieldAction faOld = fa;
- pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView);
-
- bRC = fa.bRC;
-// bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);
-
- m_bNotifying = FALSE;
- }
- }
-}
-
-void CFFL_IFormFiller::OnValidate(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bRC, FX_BOOL& bExit, FX_DWORD nFlag)
-{
- if (!m_bNotifying)
- {
- ASSERT(pWidget != NULL);
- if (pWidget->GetAAction(CPDF_AAction::Validate))
- {
- m_bNotifying = TRUE;
- pWidget->ClearAppModified();
-
- ASSERT(pPageView != NULL);
-// CReader_DocView* pDocView = pPageView->GetDocView();
-// ASSERT(pDocView != NULL);
-
-
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
- fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
- fa.bKeyDown = GetKeyDown();
- fa.bRC = TRUE;
-
- CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE);
- ASSERT(pFormFiller != NULL);
-
- pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa);
- pFormFiller->SaveState(pPageView);
-
- PDFSDK_FieldAction faOld = fa;
- pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView);
-
- bRC = fa.bRC;
-// bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);
-
- m_bNotifying = FALSE;
- }
- }
-}
-
-void CFFL_IFormFiller::OnCalculate(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bExit, FX_DWORD nFlag)
-{
- if (!m_bNotifying)
- {
- ASSERT(pWidget != NULL);
- ASSERT(pPageView != NULL);
-// CReader_DocView* pDocView = pPageView->GetDocView();
-// ASSERT(pDocView != NULL);
- CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- pInterForm->OnCalculate(pWidget->GetFormField());
-
-// bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);
-
- m_bNotifying = FALSE;
- }
-}
-
-void CFFL_IFormFiller::OnFormat(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bExit, FX_DWORD nFlag)
-{
- if (!m_bNotifying)
- {
- ASSERT(pWidget != NULL);
- ASSERT(pPageView != NULL);
-// CReader_DocView* pDocView = pPageView->GetDocView();
-// ASSERT(pDocView != NULL);
- CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- FX_BOOL bFormated = FALSE;
- CFX_WideString sValue = pInterForm->OnFormat(pWidget->GetFormField(), GetCommitKey(), bFormated);
-
-// bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);
-
- if (bExit) return;
-
- if (bFormated)
- {
- pInterForm->ResetFieldAppearance(pWidget->GetFormField(), sValue, TRUE);
- pInterForm->UpdateField(pWidget->GetFormField());
- }
-
- m_bNotifying = FALSE;
- }
-}
-
-// LRESULT CALLBACK CFFL_IFormFiller::FFL_WndProc(
-// int code, // hook code
-// WPARAM wParam, // virtual-key code
-// LPARAM lParam // keystroke-message information
-// )
-// {
-// if (code != HC_ACTION)
-// {
-// return CallNextHookEx (m_hookSheet, code, wParam, lParam);
-// }
-//
-// FXSYS_memcpy(&g_Msg, (void*)lParam, sizeof(MSG));
-//
-// return 0;
-// }
-
-// MSG CFFL_IFormFiller::GetLastMessage()
-// {
-// return g_Msg;
-// }
-
-int CFFL_IFormFiller::GetCommitKey()
-{
-// MSG msg = CFFL_IFormFiller::GetLastMessage();
-
- int nCommitKey = 0;
-// switch (msg.message)
-// {
-// case WM_LBUTTONDOWN:
-// case WM_LBUTTONUP:
-// nCommitKey = 1;
-// break;
-// case WM_KEYDOWN:
-// switch (msg.wParam)
-// {
-// case VK_RETURN:
-// nCommitKey = 2;
-// break;
-// case VK_TAB:
-// nCommitKey = 3;
-// break;
-// }
-// break;
-// }
-
- return nCommitKey;
-}
-
-FX_BOOL CFFL_IFormFiller::GetKeyDown()
-{
- return TRUE;
-// MSG msg = CFFL_IFormFiller::GetLastMessage();
-//
-// return msg.message == WM_KEYDOWN || msg.message == WM_CHAR;
-}
-
-FX_BOOL CFFL_IFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot)
-{
-
- ASSERT(pPageView != NULL);
- ASSERT(pAnnot != NULL);
-
- if(pPageView)
- return pPageView->IsValidAnnot(pAnnot->GetPDFAnnot());
- else
- return FALSE;
-}
-
-void CFFL_IFormFiller::BeforeUndo(CPDFSDK_Document* pDocument)
-{
-
-}
-
-void CFFL_IFormFiller::BeforeRedo(CPDFSDK_Document* pDocument)
-{
- BeforeUndo(pDocument);
-}
-
-void CFFL_IFormFiller::AfterUndo(CPDFSDK_Document* pDocument)
-{
-}
-
-void CFFL_IFormFiller::AfterRedo(CPDFSDK_Document* pDocument)
-{
-}
-
-FX_BOOL CFFL_IFormFiller::CanCopy(CPDFSDK_Document* pDocument)
-{
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::CanCut(CPDFSDK_Document* pDocument)
-{
-
- return FALSE;
-}
-
-FX_BOOL CFFL_IFormFiller::CanPaste(CPDFSDK_Document* pDocument)
-{
-
- return FALSE;
-}
-
-void CFFL_IFormFiller::DoCopy(CPDFSDK_Document* pDocument)
-{
-}
-
-void CFFL_IFormFiller::DoCut(CPDFSDK_Document* pDocument)
-{
-}
-
-void CFFL_IFormFiller::DoPaste(CPDFSDK_Document* pDocument)
-{
-
-}
-void CFFL_IFormFiller::OnBeforeKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_INT32 nKeyCode,
- CFX_WideString & strChange, const CFX_WideString& strChangeEx,
- int nSelStart, int nSelEnd,
- FX_BOOL bKeyDown, FX_BOOL & bRC, FX_BOOL & bExit, FX_DWORD nFlag)
-{
- ASSERT(pPrivateData != NULL);
- CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
- ASSERT(pData->pWidget != NULL);
-
- CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);
- ASSERT(pFormFiller != NULL);
-
- if (!m_bNotifying)
- {
- if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke))
- {
- m_bNotifying = TRUE;
- int nAge = pData->pWidget->GetAppearanceAge();
- int nValueAge = pData->pWidget->GetValueAge();
-
- ASSERT(pData->pPageView != NULL);
- CPDFSDK_Document* pDocument = pData->pPageView->GetSDKDocument();
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
- fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
- fa.sChange = strChange;
- fa.sChangeEx = strChangeEx;
- fa.bKeyDown = bKeyDown;
- fa.bWillCommit = FALSE;
- fa.bRC = TRUE;
- fa.nSelStart = nSelStart;
- fa.nSelEnd = nSelEnd;
-
-
- pFormFiller->GetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa);
- pFormFiller->SaveState(pData->pPageView);
-
- if (pData->pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pData->pPageView))
- {
- if (!IsValidAnnot(pData->pPageView, pData->pWidget))
- {
- bExit = TRUE;
- m_bNotifying = FALSE;
- return;
- }
-
- if (nAge != pData->pWidget->GetAppearanceAge())
- {
- CPWL_Wnd* pWnd = pFormFiller->ResetPDFWindow(pData->pPageView, nValueAge == pData->pWidget->GetValueAge());
- pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
- bExit = TRUE;
- }
-
- if (fa.bRC)
- {
- pFormFiller->SetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa);
- bRC = FALSE;
- }
- else
- {
- pFormFiller->RestoreState(pData->pPageView);
- bRC = FALSE;
- }
-
- if (pDocument->GetFocusAnnot() != pData->pWidget)
- {
- pFormFiller->CommitData(pData->pPageView,nFlag);
- bExit = TRUE;
- }
- }
- else
- {
- if (!IsValidAnnot(pData->pPageView, pData->pWidget))
- {
- bExit = TRUE;
- m_bNotifying = FALSE;
- return;
- }
- }
-
- m_bNotifying = FALSE;
- }
- }
-}
-
-void CFFL_IFormFiller::OnAfterKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_BOOL & bExit,FX_DWORD nFlag)
-{
- ASSERT(pPrivateData != NULL);
- CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
- ASSERT(pData->pWidget != NULL);
-
- CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);
- ASSERT(pFormFiller != NULL);
-
- if (!bEditOrList)
- pFormFiller->OnKeyStroke(bExit);
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/formfiller/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_IFormFiller.h"
+#include "../../include/formfiller/FFL_CheckBox.h"
+#include "../../include/formfiller/FFL_ComboBox.h"
+#include "../../include/formfiller/FFL_ListBox.h"
+#include "../../include/formfiller/FFL_PushButton.h"
+#include "../../include/formfiller/FFL_RadioButton.h"
+#include "../../include/formfiller/FFL_TextField.h"
+
+#define FFL_MAXLISTBOXHEIGHT 140.0f
+
+// HHOOK CFFL_IFormFiller::m_hookSheet = NULL;
+// MSG CFFL_IFormFiller::g_Msg;
+
+/* ----------------------------- CFFL_IFormFiller ----------------------------- */
+
+CFFL_IFormFiller::CFFL_IFormFiller(CPDFDoc_Environment* pApp) :
+ m_pApp(pApp),
+ m_bNotifying(FALSE)
+{
+}
+
+CFFL_IFormFiller::~CFFL_IFormFiller()
+{
+ FX_POSITION pos = m_Maps.GetStartPosition();
+ while (pos)
+ {
+ CPDFSDK_Annot * pAnnot = NULL;
+ CFFL_FormFiller * pFormFiller = NULL;
+ m_Maps.GetNextAssoc(pos,pAnnot,pFormFiller);
+ delete pFormFiller;
+ }
+ m_Maps.RemoveAll();
+}
+
+FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView,CPDFSDK_Annot* pAnnot, CPDF_Point point)
+{
+ CPDF_Rect rc = pAnnot->GetRect();
+ if(rc.Contains(point.x, point.y))
+ return TRUE;
+ return FALSE;
+}
+
+FX_RECT CFFL_IFormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot)
+{
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ return pFormFiller->GetViewBBox(pPageView, pAnnot);
+ }
+ else
+ {
+ ASSERT(pPageView != NULL);
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
+ ASSERT(pPDFAnnot != NULL);
+
+ CPDF_Rect rcAnnot;
+ pPDFAnnot->GetRect(rcAnnot);
+
+// CRect rcWin;
+// pPageView->DocToWindow(rcAnnot, rcWin);
+ CPDF_Rect rcWin = CPWL_Utils::InflateRect(rcAnnot,1);
+// rcWin.InflateRect(1, 1);
+
+ return rcWin.GetOutterRect();
+ }
+}
+
+void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
+{
+ ASSERT(pPageView != NULL);
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+
+ if (IsVisible(pWidget))
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ if (pFormFiller->IsValid())
+ {
+ pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
+
+ pAnnot->GetPDFPage();
+
+
+ CPDFSDK_Document* pDocument = m_pApp->GetCurrentDoc();
+ ASSERT(pDocument != NULL);
+
+ if (pDocument->GetFocusAnnot() == pAnnot)
+ {
+ CPDF_Rect rcFocus = pFormFiller->GetFocusBox(pPageView);
+ if (!rcFocus.IsEmpty())
+ {
+ CFX_PathData path;
+
+ path.SetPointCount(5);
+ path.SetPoint(0, rcFocus.left, rcFocus.top, FXPT_MOVETO);
+ path.SetPoint(1, rcFocus.left, rcFocus.bottom, FXPT_LINETO);
+ path.SetPoint(2, rcFocus.right, rcFocus.bottom, FXPT_LINETO);
+ path.SetPoint(3, rcFocus.right, rcFocus.top, FXPT_LINETO);
+ path.SetPoint(4, rcFocus.left, rcFocus.top, FXPT_LINETO);
+
+ CFX_GraphStateData gsd;
+ gsd.SetDashCount(1);
+ gsd.m_DashArray[0] = 1.0f;
+ gsd.m_DashPhase = 0;
+
+ gsd.m_LineWidth = 1.0f;
+ pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,0,0,0), FXFILL_ALTERNATE);
+
+ // ::DrawFocusRect(hDC, &rcFocus);
+ }
+ }
+
+ return;
+ }
+ }
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ pFormFiller->OnDrawDeactive(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
+ else
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+
+ if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget))
+ {
+ pWidget->DrawShadow(pDevice, pPageView);
+ }
+
+ }
+}
+
+void CFFL_IFormFiller::OnCreate(CPDFSDK_Annot* pAnnot)
+{
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ pFormFiller->OnCreate(pAnnot);
+ }
+}
+
+void CFFL_IFormFiller::OnLoad(CPDFSDK_Annot* pAnnot)
+{
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ pFormFiller->OnLoad(pAnnot);
+ }
+}
+
+void CFFL_IFormFiller::OnDelete(CPDFSDK_Annot* pAnnot)
+{
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ pFormFiller->OnDelete(pAnnot);
+ }
+
+ UnRegisterFormFiller(pAnnot);
+}
+
+void CFFL_IFormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (!m_bNotifying)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ if (pWidget->GetAAction(CPDF_AAction::CursorEnter))
+ {
+ m_bNotifying = TRUE;
+
+ int nValueAge = pWidget->GetValueAge();
+
+ pWidget->ClearAppModified();
+
+ ASSERT(pPageView != NULL);
+
+
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+ pWidget->OnAAction(CPDF_AAction::CursorEnter, fa, pPageView );
+ m_bNotifying = FALSE;
+
+ //if ( !IsValidAnnot(pPageView, pAnnot) ) return;
+
+ if (pWidget->IsAppModified())
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
+ {
+ pFormFiller->ResetPDFWindow(pPageView, pWidget->GetValueAge() == nValueAge);
+ }
+ }
+ }
+ }
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))
+ {
+ pFormFiller->OnMouseEnter(pPageView, pAnnot);
+ }
+}
+
+void CFFL_IFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (!m_bNotifying)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ if (pWidget->GetAAction(CPDF_AAction::CursorExit))
+ {
+ m_bNotifying = TRUE;
+ pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
+ pWidget->ClearAppModified();
+
+ ASSERT(pPageView != NULL);
+
+
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+
+ pWidget->OnAAction(CPDF_AAction::CursorExit, fa, pPageView);
+ m_bNotifying = FALSE;
+
+ //if (!IsValidAnnot(pPageView, pAnnot)) return;
+
+ if (pWidget->IsAppModified())
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
+ {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+ }
+ }
+ }
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ pFormFiller->OnMouseExit(pPageView, pAnnot);
+ }
+}
+
+FX_BOOL CFFL_IFormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (!m_bNotifying)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ if (Annot_HitTest(pPageView, pAnnot, point) && pWidget->GetAAction(CPDF_AAction::ButtonDown))
+ {
+ m_bNotifying = TRUE;
+ pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
+ pWidget->ClearAppModified();
+
+ ASSERT(pPageView != NULL);
+
+
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlags);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlags);
+ pWidget->OnAAction(CPDF_AAction::ButtonDown, fa, pPageView);
+ m_bNotifying = FALSE;
+
+ if (!IsValidAnnot(pPageView, pAnnot)) return TRUE;
+
+ if (pWidget->IsAppModified())
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
+ {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+ }
+ }
+ }
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ return pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ // CReader_Page* pPage = pAnnot->GetPage();
+ // ASSERT(pPage != NULL);
+ CPDFSDK_Document* pDocument = m_pApp->GetCurrentDoc();
+ ASSERT(pDocument != NULL);
+
+ switch (pWidget->GetFieldType())
+ {
+ case FIELDTYPE_PUSHBUTTON:
+ case FIELDTYPE_CHECKBOX:
+ case FIELDTYPE_RADIOBUTTON:
+ if (GetViewBBox(pPageView, pAnnot).Contains((int)point.x, (int)point.y))
+ {
+ pDocument->SetFocusAnnot(pAnnot);
+ }
+ break;
+ default:
+ pDocument->SetFocusAnnot(pAnnot);
+ break;
+ }
+
+ FX_BOOL bRet = FALSE;
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ bRet = pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
+ }
+
+ if (pDocument->GetFocusAnnot() == pAnnot)
+ {
+ FX_BOOL bExit = FALSE;
+ FX_BOOL bReset = FALSE;
+ OnButtonUp(pWidget, pPageView, bReset, bExit,nFlags);
+ if (bExit) return TRUE;
+ }
+ return bRet;
+}
+
+void CFFL_IFormFiller::OnButtonUp(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, FX_BOOL& bExit,FX_UINT nFlag)
+{
+ ASSERT(pWidget != NULL);
+
+ if (!m_bNotifying)
+ {
+ if (pWidget->GetAAction(CPDF_AAction::ButtonUp))
+ {
+ m_bNotifying = TRUE;
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
+
+ ASSERT(pPageView != NULL);
+// CReader_DocView* pDocView = pPageView->GetDocView();
+// ASSERT(pDocView != NULL);
+
+
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+
+ pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView);
+ m_bNotifying = FALSE;
+
+ if (!IsValidAnnot(pPageView, pWidget))
+ {
+ bExit = TRUE;
+ return;
+ }
+
+ if (nAge != pWidget->GetAppearanceAge())
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
+ {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+
+ bReset = TRUE;
+ }
+ }
+ }
+}
+
+FX_BOOL CFFL_IFormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ return pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ //change cursor
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))
+ {
+ return pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, short zDelta, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ return pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ return pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ return pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::OnRButtonDblClk(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ return pFormFiller->OnRButtonDblClk(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (nChar == FWL_VKEY_Tab) return TRUE;
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ return pFormFiller->OnChar(pAnnot, nChar, nFlags);
+ }
+
+ return FALSE;
+}
+
+void CFFL_IFormFiller::OnDeSelected(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ pFormFiller->OnDeSelected(pAnnot);
+ }
+}
+
+void CFFL_IFormFiller::OnSelected(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ pFormFiller->OnSelected(pAnnot);
+ }
+}
+
+FX_BOOL CFFL_IFormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
+{
+ if(!pAnnot) return FALSE;
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (!m_bNotifying)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ if (pWidget->GetAAction(CPDF_AAction::GetFocus))
+ {
+ m_bNotifying = TRUE;
+ pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
+ pWidget->ClearAppModified();
+
+
+ CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
+ ASSERT(pPageView != NULL);
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+
+
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, TRUE);
+ if(!pFormFiller) return FALSE;
+ pFormFiller->GetActionData(pPageView, CPDF_AAction::GetFocus, fa);
+
+ pWidget->OnAAction(CPDF_AAction::GetFocus, fa, pPageView);
+ m_bNotifying = FALSE;
+
+ // if (!IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pAnnot)) return FALSE;
+
+ if (pWidget->IsAppModified())
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
+ {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+ }
+ }
+ }
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))
+ {
+ if (pFormFiller->OnSetFocus(pAnnot, nFlag))
+ {
+ return TRUE;
+ }
+ else
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CFFL_IFormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
+{
+ if(!pAnnot) return FALSE;
+ ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
+ {
+ if (pFormFiller->OnKillFocus(pAnnot, nFlag))
+ {
+ if (!m_bNotifying)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ if (pWidget->GetAAction(CPDF_AAction::LoseFocus))
+ {
+ m_bNotifying = TRUE;
+ pWidget->ClearAppModified();
+
+ CPDFSDK_PageView* pPageView = pWidget->GetPageView();
+ ASSERT(pPageView != NULL);
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+
+ pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa);
+
+ pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView);
+ m_bNotifying = FALSE;
+
+ }
+ }
+ }
+ else
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CFFL_IFormFiller::IsVisible(CPDFSDK_Widget* pWidget)
+{
+ return pWidget->IsVisible();
+}
+
+FX_BOOL CFFL_IFormFiller::IsReadOnly(CPDFSDK_Widget* pWidget)
+{
+ ASSERT(pWidget != NULL);
+
+ int nFieldFlags = pWidget->GetFieldFlags();
+
+ return (nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY;
+}
+
+FX_BOOL CFFL_IFormFiller::IsFillingAllowed(CPDFSDK_Widget* pWidget)
+{
+ ASSERT(pWidget != NULL);
+
+ if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
+ return TRUE;
+ else
+ {
+ CPDF_Page* pPage = pWidget->GetPDFPage();
+ ASSERT(pPage != NULL);
+
+ CPDF_Document* pDocument = pPage->m_pDocument;
+ ASSERT(pDocument != NULL);
+
+ FX_DWORD dwPermissions = pDocument->GetUserPermissions();
+ return (dwPermissions&FPDFPERM_FILL_FORM) ||
+ (dwPermissions&FPDFPERM_ANNOT_FORM) ||
+ (dwPermissions&FPDFPERM_MODIFY);
+ }
+ return TRUE;
+}
+
+CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister)
+{
+// ASSERT(pAnnot != NULL);
+// ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+
+ CFFL_FormFiller * pFormFiller = NULL;
+ m_Maps.Lookup(pAnnot, pFormFiller);
+
+ if (pFormFiller)
+ return pFormFiller;
+
+ if (bRegister)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+
+ int nFieldType = pWidget->GetFieldType();
+ switch(nFieldType)
+ {
+ case FIELDTYPE_PUSHBUTTON:
+ pFormFiller = new CFFL_PushButton(m_pApp, pWidget);
+ break;
+ case FIELDTYPE_CHECKBOX:
+ pFormFiller = new CFFL_CheckBox(m_pApp, pWidget);
+ break;
+ case FIELDTYPE_RADIOBUTTON:
+ pFormFiller = new CFFL_RadioButton(m_pApp, pWidget);
+ break;
+ case FIELDTYPE_TEXTFIELD:
+ pFormFiller = new CFFL_TextField(m_pApp, pWidget);
+ break;
+ case FIELDTYPE_LISTBOX:
+ pFormFiller = new CFFL_ListBox(m_pApp, pWidget);
+ break;
+ case FIELDTYPE_COMBOBOX:
+ pFormFiller = new CFFL_ComboBox(m_pApp, pWidget);
+ break;
+ case FIELDTYPE_UNKNOWN:
+ default:
+ pFormFiller = NULL;
+ break;
+ }
+
+ if (pFormFiller)
+ {
+ m_Maps.SetAt(pAnnot, pFormFiller);
+ }
+ }
+
+ return pFormFiller;
+}
+
+void CFFL_IFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot)
+{
+ if ( pAnnot != NULL )
+ {
+ UnRegisterFormFiller( pAnnot );
+ }
+}
+
+void CFFL_IFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot)
+{
+ CFFL_FormFiller * pFormFiller = NULL;
+
+ if (m_Maps.Lookup(pAnnot,pFormFiller))
+ {
+ if (pFormFiller)
+ delete pFormFiller;
+ m_Maps.RemoveKey(pAnnot);
+ }
+}
+
+void CFFL_IFormFiller::SetFocusAnnotTab(CPDFSDK_Annot* pWidget, FX_BOOL bSameField, FX_BOOL bNext)
+{
+
+}
+
+void CFFL_IFormFiller::QueryWherePopup(void* pPrivateData, FX_FLOAT fPopupMin,FX_FLOAT fPopupMax, FX_INT32 & nRet, FX_FLOAT & fPopupRet)
+{
+ ASSERT(pPrivateData != NULL);
+
+ CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
+
+
+
+
+ CPDF_Rect rcPageView(0,0,0,0);
+ rcPageView.right = pData->pWidget->GetPDFPage()->GetPageWidth();
+ rcPageView.bottom = pData->pWidget->GetPDFPage()->GetPageHeight();
+ rcPageView.Normalize();
+
+
+ ASSERT(pData->pWidget != NULL);
+ CPDF_Rect rcAnnot = pData->pWidget->GetRect();
+
+ FX_FLOAT fTop = 0.0f;
+ FX_FLOAT fBottom = 0.0f;
+
+ CPDFSDK_Widget * pWidget = (CPDFSDK_Widget*)pData->pWidget;
+ switch (pWidget->GetRotate() / 90)
+ {
+ default:
+ case 0:
+ fTop = rcPageView.top - rcAnnot.top;
+ fBottom = rcAnnot.bottom - rcPageView.bottom;
+ break;
+ case 1:
+ fTop = rcAnnot.left - rcPageView.left;
+ fBottom = rcPageView.right - rcAnnot.right;
+ break;
+ case 2:
+ fTop = rcAnnot.bottom - rcPageView.bottom;
+ fBottom = rcPageView.top - rcAnnot.top;
+ break;
+ case 3:
+ fTop = rcPageView.right - rcAnnot.right;
+ fBottom = rcAnnot.left - rcPageView.left;
+ break;
+ }
+
+ FX_FLOAT fFactHeight = 0;
+ FX_BOOL bBottom = TRUE;
+ FX_FLOAT fMaxListBoxHeight = 0;
+ if (fPopupMax > FFL_MAXLISTBOXHEIGHT)
+ {
+ if (fPopupMin > FFL_MAXLISTBOXHEIGHT)
+ {
+ fMaxListBoxHeight = fPopupMin;
+ }
+ else
+ {
+ fMaxListBoxHeight = FFL_MAXLISTBOXHEIGHT;
+ }
+ }
+ else
+ fMaxListBoxHeight = fPopupMax;
+
+ if (fBottom > fMaxListBoxHeight)
+ {
+ fFactHeight = fMaxListBoxHeight;
+ bBottom = TRUE;
+ }
+ else
+ {
+ if (fTop > fMaxListBoxHeight)
+ {
+ fFactHeight = fMaxListBoxHeight;
+ bBottom = FALSE;
+ }
+ else
+ {
+ if (fTop > fBottom)
+ {
+ fFactHeight = fTop;
+ bBottom = FALSE;
+ }
+ else
+ {
+ fFactHeight = fBottom;
+ bBottom = TRUE;
+ }
+ }
+ }
+
+ nRet = bBottom ? 0 : 1;
+ fPopupRet = fFactHeight;
+}
+
+void CFFL_IFormFiller::OnSetWindowRect(void* pPrivateData, const CPDF_Rect & rcWindow)
+{
+ ASSERT(pPrivateData != NULL);
+
+ CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, TRUE))
+ {
+
+ CPDF_Rect rcOld = pFormFiller->PWLtoFFL(pFormFiller->GetWindowRect(pData->pPageView));
+ CPDF_Rect rcNew = pFormFiller->PWLtoFFL(rcWindow);
+ pFormFiller->SetWindowRect(pData->pPageView, rcWindow);
+
+ CPDF_Rect unRect = rcOld;
+ unRect.Union(rcNew);
+ //FX_RECT rcRect = unRect.GetOutterRect();
+ unRect.left = (FX_FLOAT)(unRect.left - 0.5);
+ unRect.right = (FX_FLOAT)(unRect.right + 0.5);
+ unRect.top = (FX_FLOAT)(unRect.top + 0.5);
+ unRect.bottom = (FX_FLOAT)(unRect.bottom -0.5);
+ m_pApp->FFI_Invalidate(pData->pWidget->GetPDFPage(), unRect.left, unRect.top, unRect.right, unRect.bottom);
+ }
+}
+
+void CFFL_IFormFiller::OnKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_INT32 nKeyCode, CFX_WideString& strChange,
+ const CFX_WideString& strChangeEx, FX_BOOL bKeyDown,
+ FX_BOOL & bRC, FX_BOOL & bExit)
+{
+ ASSERT(pPrivateData != NULL);
+ CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
+ ASSERT(pData->pWidget != NULL);
+
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);
+ ASSERT(pFormFiller != NULL);
+
+ pFormFiller->OnKeyStroke(bKeyDown);
+}
+
+void CFFL_IFormFiller::OnKeyStrokeCommit(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bRC, FX_BOOL& bExit, FX_DWORD nFlag)
+{
+ if (!m_bNotifying)
+ {
+ ASSERT(pWidget != NULL);
+ if (pWidget->GetAAction(CPDF_AAction::KeyStroke))
+ {
+ m_bNotifying = TRUE;
+ pWidget->ClearAppModified();
+
+ ASSERT(pPageView != NULL);
+// CReader_DocView* pDocView = pPageView->GetDocView();
+// ASSERT(pDocView != NULL);
+
+
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+ fa.bWillCommit = TRUE;
+ fa.nCommitKey = GetCommitKey();
+ fa.bKeyDown = GetKeyDown();
+ fa.bRC = TRUE;
+
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE);
+ ASSERT(pFormFiller != NULL);
+
+ pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa);
+ pFormFiller->SaveState(pPageView);
+
+ PDFSDK_FieldAction faOld = fa;
+ pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView);
+
+ bRC = fa.bRC;
+// bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);
+
+ m_bNotifying = FALSE;
+ }
+ }
+}
+
+void CFFL_IFormFiller::OnValidate(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bRC, FX_BOOL& bExit, FX_DWORD nFlag)
+{
+ if (!m_bNotifying)
+ {
+ ASSERT(pWidget != NULL);
+ if (pWidget->GetAAction(CPDF_AAction::Validate))
+ {
+ m_bNotifying = TRUE;
+ pWidget->ClearAppModified();
+
+ ASSERT(pPageView != NULL);
+// CReader_DocView* pDocView = pPageView->GetDocView();
+// ASSERT(pDocView != NULL);
+
+
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+ fa.bKeyDown = GetKeyDown();
+ fa.bRC = TRUE;
+
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE);
+ ASSERT(pFormFiller != NULL);
+
+ pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa);
+ pFormFiller->SaveState(pPageView);
+
+ PDFSDK_FieldAction faOld = fa;
+ pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView);
+
+ bRC = fa.bRC;
+// bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);
+
+ m_bNotifying = FALSE;
+ }
+ }
+}
+
+void CFFL_IFormFiller::OnCalculate(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bExit, FX_DWORD nFlag)
+{
+ if (!m_bNotifying)
+ {
+ ASSERT(pWidget != NULL);
+ ASSERT(pPageView != NULL);
+// CReader_DocView* pDocView = pPageView->GetDocView();
+// ASSERT(pDocView != NULL);
+ CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ pInterForm->OnCalculate(pWidget->GetFormField());
+
+// bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);
+
+ m_bNotifying = FALSE;
+ }
+}
+
+void CFFL_IFormFiller::OnFormat(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bExit, FX_DWORD nFlag)
+{
+ if (!m_bNotifying)
+ {
+ ASSERT(pWidget != NULL);
+ ASSERT(pPageView != NULL);
+// CReader_DocView* pDocView = pPageView->GetDocView();
+// ASSERT(pDocView != NULL);
+ CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ FX_BOOL bFormated = FALSE;
+ CFX_WideString sValue = pInterForm->OnFormat(pWidget->GetFormField(), GetCommitKey(), bFormated);
+
+// bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);
+
+ if (bExit) return;
+
+ if (bFormated)
+ {
+ pInterForm->ResetFieldAppearance(pWidget->GetFormField(), sValue, TRUE);
+ pInterForm->UpdateField(pWidget->GetFormField());
+ }
+
+ m_bNotifying = FALSE;
+ }
+}
+
+// LRESULT CALLBACK CFFL_IFormFiller::FFL_WndProc(
+// int code, // hook code
+// WPARAM wParam, // virtual-key code
+// LPARAM lParam // keystroke-message information
+// )
+// {
+// if (code != HC_ACTION)
+// {
+// return CallNextHookEx (m_hookSheet, code, wParam, lParam);
+// }
+//
+// FXSYS_memcpy(&g_Msg, (void*)lParam, sizeof(MSG));
+//
+// return 0;
+// }
+
+// MSG CFFL_IFormFiller::GetLastMessage()
+// {
+// return g_Msg;
+// }
+
+int CFFL_IFormFiller::GetCommitKey()
+{
+// MSG msg = CFFL_IFormFiller::GetLastMessage();
+
+ int nCommitKey = 0;
+// switch (msg.message)
+// {
+// case WM_LBUTTONDOWN:
+// case WM_LBUTTONUP:
+// nCommitKey = 1;
+// break;
+// case WM_KEYDOWN:
+// switch (msg.wParam)
+// {
+// case VK_RETURN:
+// nCommitKey = 2;
+// break;
+// case VK_TAB:
+// nCommitKey = 3;
+// break;
+// }
+// break;
+// }
+
+ return nCommitKey;
+}
+
+FX_BOOL CFFL_IFormFiller::GetKeyDown()
+{
+ return TRUE;
+// MSG msg = CFFL_IFormFiller::GetLastMessage();
+//
+// return msg.message == WM_KEYDOWN || msg.message == WM_CHAR;
+}
+
+FX_BOOL CFFL_IFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot)
+{
+
+ ASSERT(pPageView != NULL);
+ ASSERT(pAnnot != NULL);
+
+ if(pPageView)
+ return pPageView->IsValidAnnot(pAnnot->GetPDFAnnot());
+ else
+ return FALSE;
+}
+
+void CFFL_IFormFiller::BeforeUndo(CPDFSDK_Document* pDocument)
+{
+
+}
+
+void CFFL_IFormFiller::BeforeRedo(CPDFSDK_Document* pDocument)
+{
+ BeforeUndo(pDocument);
+}
+
+void CFFL_IFormFiller::AfterUndo(CPDFSDK_Document* pDocument)
+{
+}
+
+void CFFL_IFormFiller::AfterRedo(CPDFSDK_Document* pDocument)
+{
+}
+
+FX_BOOL CFFL_IFormFiller::CanCopy(CPDFSDK_Document* pDocument)
+{
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::CanCut(CPDFSDK_Document* pDocument)
+{
+
+ return FALSE;
+}
+
+FX_BOOL CFFL_IFormFiller::CanPaste(CPDFSDK_Document* pDocument)
+{
+
+ return FALSE;
+}
+
+void CFFL_IFormFiller::DoCopy(CPDFSDK_Document* pDocument)
+{
+}
+
+void CFFL_IFormFiller::DoCut(CPDFSDK_Document* pDocument)
+{
+}
+
+void CFFL_IFormFiller::DoPaste(CPDFSDK_Document* pDocument)
+{
+
+}
+void CFFL_IFormFiller::OnBeforeKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_INT32 nKeyCode,
+ CFX_WideString & strChange, const CFX_WideString& strChangeEx,
+ int nSelStart, int nSelEnd,
+ FX_BOOL bKeyDown, FX_BOOL & bRC, FX_BOOL & bExit, FX_DWORD nFlag)
+{
+ ASSERT(pPrivateData != NULL);
+ CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
+ ASSERT(pData->pWidget != NULL);
+
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);
+ ASSERT(pFormFiller != NULL);
+
+ if (!m_bNotifying)
+ {
+ if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke))
+ {
+ m_bNotifying = TRUE;
+ int nAge = pData->pWidget->GetAppearanceAge();
+ int nValueAge = pData->pWidget->GetValueAge();
+
+ ASSERT(pData->pPageView != NULL);
+ CPDFSDK_Document* pDocument = pData->pPageView->GetSDKDocument();
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+ fa.sChange = strChange;
+ fa.sChangeEx = strChangeEx;
+ fa.bKeyDown = bKeyDown;
+ fa.bWillCommit = FALSE;
+ fa.bRC = TRUE;
+ fa.nSelStart = nSelStart;
+ fa.nSelEnd = nSelEnd;
+
+
+ pFormFiller->GetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa);
+ pFormFiller->SaveState(pData->pPageView);
+
+ if (pData->pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pData->pPageView))
+ {
+ if (!IsValidAnnot(pData->pPageView, pData->pWidget))
+ {
+ bExit = TRUE;
+ m_bNotifying = FALSE;
+ return;
+ }
+
+ if (nAge != pData->pWidget->GetAppearanceAge())
+ {
+ CPWL_Wnd* pWnd = pFormFiller->ResetPDFWindow(pData->pPageView, nValueAge == pData->pWidget->GetValueAge());
+ pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
+ bExit = TRUE;
+ }
+
+ if (fa.bRC)
+ {
+ pFormFiller->SetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa);
+ bRC = FALSE;
+ }
+ else
+ {
+ pFormFiller->RestoreState(pData->pPageView);
+ bRC = FALSE;
+ }
+
+ if (pDocument->GetFocusAnnot() != pData->pWidget)
+ {
+ pFormFiller->CommitData(pData->pPageView,nFlag);
+ bExit = TRUE;
+ }
+ }
+ else
+ {
+ if (!IsValidAnnot(pData->pPageView, pData->pWidget))
+ {
+ bExit = TRUE;
+ m_bNotifying = FALSE;
+ return;
+ }
+ }
+
+ m_bNotifying = FALSE;
+ }
+ }
+}
+
+void CFFL_IFormFiller::OnAfterKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_BOOL & bExit,FX_DWORD nFlag)
+{
+ ASSERT(pPrivateData != NULL);
+ CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
+ ASSERT(pData->pWidget != NULL);
+
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);
+ ASSERT(pFormFiller != NULL);
+
+ if (!bEditOrList)
+ pFormFiller->OnKeyStroke(bExit);
+}
diff --git a/fpdfsdk/src/formfiller/FFL_ListBox.cpp b/fpdfsdk/src/formfiller/FFL_ListBox.cpp
index 9ddb6a00d9..87ae552a66 100644
--- a/fpdfsdk/src/formfiller/FFL_ListBox.cpp
+++ b/fpdfsdk/src/formfiller/FFL_ListBox.cpp
@@ -1,319 +1,319 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/formfiller/FormFiller.h"
-#include "../../include/formfiller/FFL_FormFiller.h"
-#include "../../include/formfiller/FFL_ListBox.h"
-//#include "../../include/formfiller/FFL_Module.h"
-#include "../../include/formfiller/FFL_IFormFiller.h"
-//#include "../../include/formfiller/FFL_Undo.h"
-#include "../../include/formfiller/FFL_CBA_Fontmap.h"
-
-
-#define FFL_DEFAULTLISTBOXFONTSIZE 12.0f
-
-
-/* ------------------------------- CFFL_ListBox ------------------------------- */
-
-CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
- CFFL_FormFiller(pApp, pWidget),
- m_pFontMap(NULL)
-{
-}
-
-CFFL_ListBox::~CFFL_ListBox()
-{
- if (m_pFontMap)
- {
- delete m_pFontMap;
- m_pFontMap = NULL;
- }
-}
-
-PWL_CREATEPARAM CFFL_ListBox::GetCreateParam()
-{
- PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
-
- ASSERT(m_pWidget != NULL);
- FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
-
- if (dwFieldFlag & FIELDFLAG_MULTISELECT)
- {
- cp.dwFlags |= PLBS_MULTIPLESEL;
- }
-
- if (dwFieldFlag & FIELDFLAG_COMMITONSELCHANGE)
- {
- //cp.dwFlags |= PLBS_COMMITSELECTEDVALUE;
- }
-
- cp.dwFlags |= PWS_VSCROLL;
-
- if (cp.dwFlags & PWS_AUTOFONTSIZE)
- cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE;
-
- if (!m_pFontMap)
- {
- ASSERT(this->m_pApp != NULL);
- m_pFontMap = new CBA_FontMap(m_pWidget,m_pApp->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pApp));
- m_pFontMap->Initial();
- }
- cp.pFontMap = m_pFontMap;
-
- return cp;
-}
-
-CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
-{
- CPWL_ListBox* pWnd = new CPWL_ListBox();
- pWnd->AttachFFLData(this);
- pWnd->Create(cp);
-
- ASSERT(m_pApp != NULL);
- CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
- pWnd->SetFillerNotify(pIFormFiller);
-
- ASSERT(m_pWidget != NULL);
-
- for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
- pWnd->AddString(m_pWidget->GetOptionLabel(i));
-
- if (pWnd->HasFlag(PLBS_MULTIPLESEL))
- {
- m_OriginSelections.RemoveAll();
-
- FX_BOOL bSetCaret = FALSE;
- for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
- {
- if (m_pWidget->IsOptionSelected(i))
- {
- if (!bSetCaret)
- {
- pWnd->SetCaret(i);
- bSetCaret = TRUE;
- }
- pWnd->Select(i);
- m_OriginSelections.SetAt(i, NULL);
- }
- }
- }
- else
- {
- for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
- {
- if (m_pWidget->IsOptionSelected(i))
- {
- pWnd->Select(i);
- break;
- }
- }
- }
-
- pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex());
-
- return pWnd;
-}
-
-
-FX_BOOL CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
-{
- return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
-}
-
-FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView)
-{
- ASSERT(m_pWidget != NULL);
-
- if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
- {
- if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
- {
- int nSelCount = 0;
- for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++)
- {
- if (pListBox->IsItemSelected(i))
- {
- void* p = NULL;
- if (!m_OriginSelections.Lookup(i, p))
- return TRUE;
-
- nSelCount++;
- }
- }
-
- return nSelCount != m_OriginSelections.GetCount();
- }
- else
- {
- return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0);
- }
- }
-
- return FALSE;
-}
-
-void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView)
-{
- ASSERT(m_pWidget != NULL);
-
- if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
- {
- CFX_IntArray aOldSelect, aNewSelect;
-
- {
- for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
- {
- if (m_pWidget->IsOptionSelected(i))
- {
- aOldSelect.Add(i);
- }
- }
- }
-
-
- FX_INT32 nNewTopIndex = pListBox->GetTopVisibleIndex();
-
- m_pWidget->ClearSelection(FALSE);
-
- if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
- {
- for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++)
- {
- if (pListBox->IsItemSelected(i))
- {
- m_pWidget->SetOptionSelection(i, TRUE, FALSE);
- aNewSelect.Add(i);
- }
- }
- }
- else
- {
- m_pWidget->SetOptionSelection(pListBox->GetCurSel(), TRUE, FALSE);
- aNewSelect.Add(pListBox->GetCurSel());
- }
-
- m_pWidget->SetTopVisibleIndex(nNewTopIndex);
- m_pWidget->ResetFieldAppearance(TRUE);
- m_pWidget->UpdateField();
- SetChangeMark();
- }
-}
-
-void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
- PDFSDK_FieldAction& fa)
-{
- switch (type)
- {
- case CPDF_AAction::Validate:
- if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
- {
- fa.sValue = L"";
- }
- else
- {
- if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
- {
- ASSERT(m_pWidget != NULL);
- FX_INT32 nCurSel = pListBox->GetCurSel();
- if (nCurSel >= 0)
- fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
- }
- }
- break;
- case CPDF_AAction::LoseFocus:
- case CPDF_AAction::GetFocus:
- if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
- {
- fa.sValue = L"";
- }
- else
- {
- ASSERT(m_pWidget != NULL);
- FX_INT32 nCurSel = m_pWidget->GetSelectedIndex(0);
- if (nCurSel >= 0)
- fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
- }
- break;
- default:
- break;
- }
-}
-
-
-void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
- const PDFSDK_FieldAction& fa)
-{
-}
-
-void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView)
-{
- ASSERT(pPageView != NULL);
-
- if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
- {
- for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++)
- {
- if (pListBox->IsItemSelected(i))
- {
- m_State.Add(i);
- }
- }
- }
-}
-
-void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView)
-{
- if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
- {
- for (int i=0,sz=m_State.GetSize(); i<sz; i++)
- pListBox->Select(m_State[i]);
- }
-}
-
-CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
-{
- if (bRestoreValue)
- SaveState(pPageView);
-
- DestroyPDFWindow(pPageView);
-
- CPWL_Wnd* pRet = NULL;
-
- if (bRestoreValue)
- {
- RestoreState(pPageView);
- pRet = this->GetPDFWindow(pPageView, FALSE);
- }
- else
- pRet = this->GetPDFWindow(pPageView, TRUE);
-
- m_pWidget->UpdateField();
-
- return pRet;
-}
-
-void CFFL_ListBox::OnKeyStroke(FX_BOOL bKeyDown, FX_DWORD nFlag)
-{
- ASSERT(m_pWidget != NULL);
-
- int nFlags = m_pWidget->GetFieldFlags();
-
- if (nFlags & FIELDFLAG_COMMITONSELCHANGE)
- {
- if (m_bValid)
- {
- CPDFSDK_PageView* pPageView = this->GetCurPageView();
- ASSERT(pPageView != NULL);
-
- if (CommitData(pPageView, nFlag))
- {
- DestroyPDFWindow(pPageView);
- m_bValid = FALSE;
- }
- }
- }
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/formfiller/FormFiller.h"
+#include "../../include/formfiller/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_ListBox.h"
+//#include "../../include/formfiller/FFL_Module.h"
+#include "../../include/formfiller/FFL_IFormFiller.h"
+//#include "../../include/formfiller/FFL_Undo.h"
+#include "../../include/formfiller/FFL_CBA_Fontmap.h"
+
+
+#define FFL_DEFAULTLISTBOXFONTSIZE 12.0f
+
+
+/* ------------------------------- CFFL_ListBox ------------------------------- */
+
+CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
+ CFFL_FormFiller(pApp, pWidget),
+ m_pFontMap(NULL)
+{
+}
+
+CFFL_ListBox::~CFFL_ListBox()
+{
+ if (m_pFontMap)
+ {
+ delete m_pFontMap;
+ m_pFontMap = NULL;
+ }
+}
+
+PWL_CREATEPARAM CFFL_ListBox::GetCreateParam()
+{
+ PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
+
+ ASSERT(m_pWidget != NULL);
+ FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
+
+ if (dwFieldFlag & FIELDFLAG_MULTISELECT)
+ {
+ cp.dwFlags |= PLBS_MULTIPLESEL;
+ }
+
+ if (dwFieldFlag & FIELDFLAG_COMMITONSELCHANGE)
+ {
+ //cp.dwFlags |= PLBS_COMMITSELECTEDVALUE;
+ }
+
+ cp.dwFlags |= PWS_VSCROLL;
+
+ if (cp.dwFlags & PWS_AUTOFONTSIZE)
+ cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE;
+
+ if (!m_pFontMap)
+ {
+ ASSERT(this->m_pApp != NULL);
+ m_pFontMap = new CBA_FontMap(m_pWidget,m_pApp->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pApp));
+ m_pFontMap->Initial();
+ }
+ cp.pFontMap = m_pFontMap;
+
+ return cp;
+}
+
+CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
+{
+ CPWL_ListBox* pWnd = new CPWL_ListBox();
+ pWnd->AttachFFLData(this);
+ pWnd->Create(cp);
+
+ ASSERT(m_pApp != NULL);
+ CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
+ pWnd->SetFillerNotify(pIFormFiller);
+
+ ASSERT(m_pWidget != NULL);
+
+ for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
+ pWnd->AddString(m_pWidget->GetOptionLabel(i));
+
+ if (pWnd->HasFlag(PLBS_MULTIPLESEL))
+ {
+ m_OriginSelections.RemoveAll();
+
+ FX_BOOL bSetCaret = FALSE;
+ for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
+ {
+ if (m_pWidget->IsOptionSelected(i))
+ {
+ if (!bSetCaret)
+ {
+ pWnd->SetCaret(i);
+ bSetCaret = TRUE;
+ }
+ pWnd->Select(i);
+ m_OriginSelections.SetAt(i, NULL);
+ }
+ }
+ }
+ else
+ {
+ for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
+ {
+ if (m_pWidget->IsOptionSelected(i))
+ {
+ pWnd->Select(i);
+ break;
+ }
+ }
+ }
+
+ pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex());
+
+ return pWnd;
+}
+
+
+FX_BOOL CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
+{
+ return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
+}
+
+FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(m_pWidget != NULL);
+
+ if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+ {
+ int nSelCount = 0;
+ for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++)
+ {
+ if (pListBox->IsItemSelected(i))
+ {
+ void* p = NULL;
+ if (!m_OriginSelections.Lookup(i, p))
+ return TRUE;
+
+ nSelCount++;
+ }
+ }
+
+ return nSelCount != m_OriginSelections.GetCount();
+ }
+ else
+ {
+ return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0);
+ }
+ }
+
+ return FALSE;
+}
+
+void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(m_pWidget != NULL);
+
+ if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ CFX_IntArray aOldSelect, aNewSelect;
+
+ {
+ for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
+ {
+ if (m_pWidget->IsOptionSelected(i))
+ {
+ aOldSelect.Add(i);
+ }
+ }
+ }
+
+
+ FX_INT32 nNewTopIndex = pListBox->GetTopVisibleIndex();
+
+ m_pWidget->ClearSelection(FALSE);
+
+ if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+ {
+ for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++)
+ {
+ if (pListBox->IsItemSelected(i))
+ {
+ m_pWidget->SetOptionSelection(i, TRUE, FALSE);
+ aNewSelect.Add(i);
+ }
+ }
+ }
+ else
+ {
+ m_pWidget->SetOptionSelection(pListBox->GetCurSel(), TRUE, FALSE);
+ aNewSelect.Add(pListBox->GetCurSel());
+ }
+
+ m_pWidget->SetTopVisibleIndex(nNewTopIndex);
+ m_pWidget->ResetFieldAppearance(TRUE);
+ m_pWidget->UpdateField();
+ SetChangeMark();
+ }
+}
+
+void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
+ PDFSDK_FieldAction& fa)
+{
+ switch (type)
+ {
+ case CPDF_AAction::Validate:
+ if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+ {
+ fa.sValue = L"";
+ }
+ else
+ {
+ if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ ASSERT(m_pWidget != NULL);
+ FX_INT32 nCurSel = pListBox->GetCurSel();
+ if (nCurSel >= 0)
+ fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
+ }
+ }
+ break;
+ case CPDF_AAction::LoseFocus:
+ case CPDF_AAction::GetFocus:
+ if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+ {
+ fa.sValue = L"";
+ }
+ else
+ {
+ ASSERT(m_pWidget != NULL);
+ FX_INT32 nCurSel = m_pWidget->GetSelectedIndex(0);
+ if (nCurSel >= 0)
+ fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+
+void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
+ const PDFSDK_FieldAction& fa)
+{
+}
+
+void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(pPageView != NULL);
+
+ if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++)
+ {
+ if (pListBox->IsItemSelected(i))
+ {
+ m_State.Add(i);
+ }
+ }
+ }
+}
+
+void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView)
+{
+ if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ for (int i=0,sz=m_State.GetSize(); i<sz; i++)
+ pListBox->Select(m_State[i]);
+ }
+}
+
+CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
+{
+ if (bRestoreValue)
+ SaveState(pPageView);
+
+ DestroyPDFWindow(pPageView);
+
+ CPWL_Wnd* pRet = NULL;
+
+ if (bRestoreValue)
+ {
+ RestoreState(pPageView);
+ pRet = this->GetPDFWindow(pPageView, FALSE);
+ }
+ else
+ pRet = this->GetPDFWindow(pPageView, TRUE);
+
+ m_pWidget->UpdateField();
+
+ return pRet;
+}
+
+void CFFL_ListBox::OnKeyStroke(FX_BOOL bKeyDown, FX_DWORD nFlag)
+{
+ ASSERT(m_pWidget != NULL);
+
+ int nFlags = m_pWidget->GetFieldFlags();
+
+ if (nFlags & FIELDFLAG_COMMITONSELCHANGE)
+ {
+ if (m_bValid)
+ {
+ CPDFSDK_PageView* pPageView = this->GetCurPageView();
+ ASSERT(pPageView != NULL);
+
+ if (CommitData(pPageView, nFlag))
+ {
+ DestroyPDFWindow(pPageView);
+ m_bValid = FALSE;
+ }
+ }
+ }
+}
+
diff --git a/fpdfsdk/src/formfiller/FFL_Notify.cpp b/fpdfsdk/src/formfiller/FFL_Notify.cpp
index f18ed51875..f6a2feb4a1 100644
--- a/fpdfsdk/src/formfiller/FFL_Notify.cpp
+++ b/fpdfsdk/src/formfiller/FFL_Notify.cpp
@@ -1,172 +1,172 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-// #include "../../include/formfiller/FormFiller.h"
-#include "../../include/formfiller/FFL_FormFiller.h"
-#include "../../include/formfiller/FFL_Notify.h"
-// #include "../../include/formfiller/FFL_ComboBox.h"
-// #include "../../include/formfiller/FFL_Module.h"
-
-/* -------------------------------- CFFL_Notify ------------------------------ */
-
-//#pragma warning(disable: 4800)
-
-CFFL_Notify::CFFL_Notify(CFFL_FormFiller * pFormFiller) :
- m_pFormFiller(pFormFiller),
- m_bDoActioning(FALSE),
- m_nNotifyFlag(0)
-{
- ASSERT(m_pFormFiller != NULL);
-}
-
-CFFL_Notify::~CFFL_Notify()
-{
-}
-
-void CFFL_Notify::BeforeNotify()
-{
- m_nNotifyFlag ++;
-}
-
-
-void CFFL_Notify::AfterNotify()
-{
- m_nNotifyFlag --;
-}
-
-FX_BOOL CFFL_Notify::OnMouseUp(FX_BOOL & bExit)
-{
- BeforeNotify();
- FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::ButtonUp, bExit);
- AfterNotify();
- return bRet;
-}
-
-FX_BOOL CFFL_Notify::OnMouseDown(FX_BOOL & bExit)
-{
- BeforeNotify();
- FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::ButtonDown, bExit);
- AfterNotify();
- return bRet;
-}
-
-FX_BOOL CFFL_Notify::OnMouseEnter(FX_BOOL & bExit)
-{
- BeforeNotify();
- FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::CursorEnter, bExit);
- AfterNotify();
- return bRet;
-}
-
-FX_BOOL CFFL_Notify::OnMouseExit(FX_BOOL & bExit)
-{
- BeforeNotify();
- FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::CursorExit, bExit);
- AfterNotify();
- return bRet;
-}
-
-FX_BOOL CFFL_Notify::OnSetFocus(FX_BOOL & bExit)
-{
- BeforeNotify();
- FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::GetFocus, bExit);
- AfterNotify();
- return bRet;
-}
-
-FX_BOOL CFFL_Notify::OnKillFocus(FX_BOOL & bExit)
-{
- BeforeNotify();
- FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::LoseFocus, bExit);
- AfterNotify();
- return bRet;
-}
-
-FX_BOOL CFFL_Notify::OnCalculate()
-{
- return TRUE;
-}
-
-FX_BOOL CFFL_Notify::OnFormat(int iCommitKey)
-{
- return TRUE;
-}
-
-FX_BOOL CFFL_Notify::OnKeyStroke(CPDF_FormField* pFormField, int nCommitKey, CFX_WideString& strValue, CFX_WideString& strChange,
- const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, FX_BOOL bModifier,
- FX_BOOL bShift, FX_BOOL bWillCommit, FX_BOOL bFieldFull,
- int& nSelStart, int& nSelEnd, FX_BOOL& bRC)
-{
- return TRUE;
-}
-
-FX_BOOL CFFL_Notify::OnValidate(CPDF_FormField* pFormField, CFX_WideString& strValue, CFX_WideString & strChange,
- const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, FX_BOOL bModifier,
- FX_BOOL bShift, FX_BOOL & bRC)
-{
- return TRUE;
-}
-
-FX_BOOL CFFL_Notify::DoAAction(CPDF_AAction::AActionType eAAT, FX_BOOL & bExit)
-{
- if (this->m_bDoActioning) return FALSE;
-
- CPDF_Action action;
- if (!FindAAction(eAAT,action)) return FALSE;
-
- this->m_bDoActioning = TRUE;
- ExecuteActionTree(eAAT,action,bExit);
- this->m_bDoActioning = FALSE;
- return TRUE;
-}
-
-FX_BOOL CFFL_Notify::ExecuteActionTree(CPDF_AAction::AActionType eAAT,CPDF_Action & action, FX_BOOL& bExit)
-{
- if (!ExecuteAction(eAAT,action,bExit)) return FALSE;
- if (bExit) return TRUE;
-
- for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
- {
- CPDF_Action subaction = action.GetSubAction(i);
- if (!ExecuteActionTree(eAAT,subaction,bExit)) return FALSE;
- if (bExit) break;
- }
-
- return TRUE;
-}
-
-
-FX_BOOL CFFL_Notify::FindAAction(CPDF_AAction::AActionType eAAT,CPDF_Action & action)
-{
- return FALSE;
-}
-
-FX_BOOL CFFL_Notify::FindAAction(CPDF_AAction aaction,CPDF_AAction::AActionType eAAT,CPDF_Action & action)
-{
- CPDF_Action MyAction;
-
- if (aaction.ActionExist(eAAT))
- {
- MyAction = aaction.GetAction(eAAT);
- }
- else
- return FALSE;
-
-
- if (MyAction.GetType() == CPDF_Action::Unknown)
- return FALSE;
-
- action = MyAction;
-
- return TRUE;
-}
-
-FX_BOOL CFFL_Notify::ExecuteAction(CPDF_AAction::AActionType eAAT,CPDF_Action & action,FX_BOOL& bExit)
-{
- return FALSE;
-}
-//#pragma warning(default: 4800)
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+// #include "../../include/formfiller/FormFiller.h"
+#include "../../include/formfiller/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_Notify.h"
+// #include "../../include/formfiller/FFL_ComboBox.h"
+// #include "../../include/formfiller/FFL_Module.h"
+
+/* -------------------------------- CFFL_Notify ------------------------------ */
+
+//#pragma warning(disable: 4800)
+
+CFFL_Notify::CFFL_Notify(CFFL_FormFiller * pFormFiller) :
+ m_pFormFiller(pFormFiller),
+ m_bDoActioning(FALSE),
+ m_nNotifyFlag(0)
+{
+ ASSERT(m_pFormFiller != NULL);
+}
+
+CFFL_Notify::~CFFL_Notify()
+{
+}
+
+void CFFL_Notify::BeforeNotify()
+{
+ m_nNotifyFlag ++;
+}
+
+
+void CFFL_Notify::AfterNotify()
+{
+ m_nNotifyFlag --;
+}
+
+FX_BOOL CFFL_Notify::OnMouseUp(FX_BOOL & bExit)
+{
+ BeforeNotify();
+ FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::ButtonUp, bExit);
+ AfterNotify();
+ return bRet;
+}
+
+FX_BOOL CFFL_Notify::OnMouseDown(FX_BOOL & bExit)
+{
+ BeforeNotify();
+ FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::ButtonDown, bExit);
+ AfterNotify();
+ return bRet;
+}
+
+FX_BOOL CFFL_Notify::OnMouseEnter(FX_BOOL & bExit)
+{
+ BeforeNotify();
+ FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::CursorEnter, bExit);
+ AfterNotify();
+ return bRet;
+}
+
+FX_BOOL CFFL_Notify::OnMouseExit(FX_BOOL & bExit)
+{
+ BeforeNotify();
+ FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::CursorExit, bExit);
+ AfterNotify();
+ return bRet;
+}
+
+FX_BOOL CFFL_Notify::OnSetFocus(FX_BOOL & bExit)
+{
+ BeforeNotify();
+ FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::GetFocus, bExit);
+ AfterNotify();
+ return bRet;
+}
+
+FX_BOOL CFFL_Notify::OnKillFocus(FX_BOOL & bExit)
+{
+ BeforeNotify();
+ FX_BOOL bRet = FALSE;//DoAAction(CPDF_AAction::AActionType::LoseFocus, bExit);
+ AfterNotify();
+ return bRet;
+}
+
+FX_BOOL CFFL_Notify::OnCalculate()
+{
+ return TRUE;
+}
+
+FX_BOOL CFFL_Notify::OnFormat(int iCommitKey)
+{
+ return TRUE;
+}
+
+FX_BOOL CFFL_Notify::OnKeyStroke(CPDF_FormField* pFormField, int nCommitKey, CFX_WideString& strValue, CFX_WideString& strChange,
+ const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, FX_BOOL bModifier,
+ FX_BOOL bShift, FX_BOOL bWillCommit, FX_BOOL bFieldFull,
+ int& nSelStart, int& nSelEnd, FX_BOOL& bRC)
+{
+ return TRUE;
+}
+
+FX_BOOL CFFL_Notify::OnValidate(CPDF_FormField* pFormField, CFX_WideString& strValue, CFX_WideString & strChange,
+ const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, FX_BOOL bModifier,
+ FX_BOOL bShift, FX_BOOL & bRC)
+{
+ return TRUE;
+}
+
+FX_BOOL CFFL_Notify::DoAAction(CPDF_AAction::AActionType eAAT, FX_BOOL & bExit)
+{
+ if (this->m_bDoActioning) return FALSE;
+
+ CPDF_Action action;
+ if (!FindAAction(eAAT,action)) return FALSE;
+
+ this->m_bDoActioning = TRUE;
+ ExecuteActionTree(eAAT,action,bExit);
+ this->m_bDoActioning = FALSE;
+ return TRUE;
+}
+
+FX_BOOL CFFL_Notify::ExecuteActionTree(CPDF_AAction::AActionType eAAT,CPDF_Action & action, FX_BOOL& bExit)
+{
+ if (!ExecuteAction(eAAT,action,bExit)) return FALSE;
+ if (bExit) return TRUE;
+
+ for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+ {
+ CPDF_Action subaction = action.GetSubAction(i);
+ if (!ExecuteActionTree(eAAT,subaction,bExit)) return FALSE;
+ if (bExit) break;
+ }
+
+ return TRUE;
+}
+
+
+FX_BOOL CFFL_Notify::FindAAction(CPDF_AAction::AActionType eAAT,CPDF_Action & action)
+{
+ return FALSE;
+}
+
+FX_BOOL CFFL_Notify::FindAAction(CPDF_AAction aaction,CPDF_AAction::AActionType eAAT,CPDF_Action & action)
+{
+ CPDF_Action MyAction;
+
+ if (aaction.ActionExist(eAAT))
+ {
+ MyAction = aaction.GetAction(eAAT);
+ }
+ else
+ return FALSE;
+
+
+ if (MyAction.GetType() == CPDF_Action::Unknown)
+ return FALSE;
+
+ action = MyAction;
+
+ return TRUE;
+}
+
+FX_BOOL CFFL_Notify::ExecuteAction(CPDF_AAction::AActionType eAAT,CPDF_Action & action,FX_BOOL& bExit)
+{
+ return FALSE;
+}
+//#pragma warning(default: 4800)
+
diff --git a/fpdfsdk/src/formfiller/FFL_PushButton.cpp b/fpdfsdk/src/formfiller/FFL_PushButton.cpp
index 1afbe8b84e..b8a07fb548 100644
--- a/fpdfsdk/src/formfiller/FFL_PushButton.cpp
+++ b/fpdfsdk/src/formfiller/FFL_PushButton.cpp
@@ -1,43 +1,43 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/formfiller/FormFiller.h"
-#include "../../include/formfiller/FFL_FormFiller.h"
-#include "../../include/formfiller/FFL_PushButton.h"
-
-/* ------------------------------- CFFL_PushButton ------------------------------- */
-
-CFFL_PushButton::CFFL_PushButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot):
- CFFL_Button( pApp, pAnnot)
-{
-}
-
-CFFL_PushButton::~CFFL_PushButton()
-{
-}
-
-CPWL_Wnd* CFFL_PushButton::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
-{
- CPWL_PushButton* pWnd = new CPWL_PushButton();
- pWnd->Create(cp);
-
- return pWnd;
-}
-
-
-FX_BOOL CFFL_PushButton::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
-{
- return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
-}
-
-void CFFL_PushButton::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- FX_DWORD dwFlags)
-{
- CFFL_Button::OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
-}
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/formfiller/FormFiller.h"
+#include "../../include/formfiller/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_PushButton.h"
+
+/* ------------------------------- CFFL_PushButton ------------------------------- */
+
+CFFL_PushButton::CFFL_PushButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot):
+ CFFL_Button( pApp, pAnnot)
+{
+}
+
+CFFL_PushButton::~CFFL_PushButton()
+{
+}
+
+CPWL_Wnd* CFFL_PushButton::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
+{
+ CPWL_PushButton* pWnd = new CPWL_PushButton();
+ pWnd->Create(cp);
+
+ return pWnd;
+}
+
+
+FX_BOOL CFFL_PushButton::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
+{
+ return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
+}
+
+void CFFL_PushButton::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ FX_DWORD dwFlags)
+{
+ CFFL_Button::OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
+}
+
+
diff --git a/fpdfsdk/src/formfiller/FFL_RadioButton.cpp b/fpdfsdk/src/formfiller/FFL_RadioButton.cpp
index 462c05ede2..aacb7d81e9 100644
--- a/fpdfsdk/src/formfiller/FFL_RadioButton.cpp
+++ b/fpdfsdk/src/formfiller/FFL_RadioButton.cpp
@@ -1,137 +1,137 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/formfiller/FormFiller.h"
-#include "../../include/formfiller/FFL_FormFiller.h"
-#include "../../include/formfiller/FFL_RadioButton.h"
-//#include "../include/FFL_Undo.h"
-
-/* ------------------------------- CFFL_RadioButton ------------------------------- */
-
-CFFL_RadioButton::CFFL_RadioButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
- CFFL_Button(pApp, pWidget)
-{
-}
-
-CFFL_RadioButton::~CFFL_RadioButton()
-{
-}
-
-CPWL_Wnd* CFFL_RadioButton::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
-{
- CPWL_RadioButton* pWnd = new CPWL_RadioButton();
- pWnd->Create(cp);
-
- ASSERT(m_pWidget != NULL);
- pWnd->SetCheck(m_pWidget->IsChecked());
-
- return pWnd;
-}
-
-FX_BOOL CFFL_RadioButton::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
-{
- switch (nKeyCode)
- {
- case FWL_VKEY_Return:
- case FWL_VKEY_Space:
- return TRUE;
- default:
- return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags);
- }
-}
-
-FX_BOOL CFFL_RadioButton::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
-{
- switch (nChar)
- {
- case FWL_VKEY_Return:
- case FWL_VKEY_Space:
- {
- CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
- ASSERT(pIFormFiller != NULL);
-
- CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
- ASSERT(pPageView != NULL);
-
- FX_BOOL bReset = FALSE;
- FX_BOOL bExit = FALSE;
-
- pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit,nFlags);
-
- if (bReset) return TRUE;
- if (bExit) return TRUE;
-
- CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
-
- if (CPWL_RadioButton * pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE))
- pWnd->SetCheck(TRUE);
- CommitData(pPageView,nFlags);
- return TRUE;
- }
- default:
- return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
- }
-}
-
-FX_BOOL CFFL_RadioButton::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
-{
- CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point);
-
- if (IsValid())
- {
- if (CPWL_RadioButton * pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE))
- pWnd->SetCheck(TRUE);
-
- if (!CommitData(pPageView,nFlags)) return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CFFL_RadioButton::IsDataChanged(CPDFSDK_PageView* pPageView)
-{
- ASSERT(m_pWidget != NULL);
-
- if (CPWL_RadioButton* pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE))
- {
- return pWnd->IsChecked() != m_pWidget->IsChecked();
- }
-
- return FALSE;
-}
-
-void CFFL_RadioButton::SaveData(CPDFSDK_PageView* pPageView)
-{
- ASSERT(m_pWidget != NULL);
-
- if (CPWL_RadioButton* pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE))
- {
-
- FX_BOOL bNewChecked = pWnd->IsChecked();
-
- if (bNewChecked)
- {
- CPDF_FormField* pField = m_pWidget->GetFormField();
- ASSERT(pField != NULL);
-
- for (FX_INT32 i=0,sz=pField->CountControls(); i<sz; i++)
- {
- if (CPDF_FormControl* pCtrl = pField->GetControl(i))
- {
- if (pCtrl->IsChecked())
- {
- break;
- }
- }
- }
- }
-
- m_pWidget->SetCheck(bNewChecked, FALSE);
- m_pWidget->UpdateField();
- SetChangeMark();
- }
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/formfiller/FormFiller.h"
+#include "../../include/formfiller/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_RadioButton.h"
+//#include "../include/FFL_Undo.h"
+
+/* ------------------------------- CFFL_RadioButton ------------------------------- */
+
+CFFL_RadioButton::CFFL_RadioButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
+ CFFL_Button(pApp, pWidget)
+{
+}
+
+CFFL_RadioButton::~CFFL_RadioButton()
+{
+}
+
+CPWL_Wnd* CFFL_RadioButton::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
+{
+ CPWL_RadioButton* pWnd = new CPWL_RadioButton();
+ pWnd->Create(cp);
+
+ ASSERT(m_pWidget != NULL);
+ pWnd->SetCheck(m_pWidget->IsChecked());
+
+ return pWnd;
+}
+
+FX_BOOL CFFL_RadioButton::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
+{
+ switch (nKeyCode)
+ {
+ case FWL_VKEY_Return:
+ case FWL_VKEY_Space:
+ return TRUE;
+ default:
+ return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags);
+ }
+}
+
+FX_BOOL CFFL_RadioButton::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
+{
+ switch (nChar)
+ {
+ case FWL_VKEY_Return:
+ case FWL_VKEY_Space:
+ {
+ CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
+ ASSERT(pIFormFiller != NULL);
+
+ CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
+ ASSERT(pPageView != NULL);
+
+ FX_BOOL bReset = FALSE;
+ FX_BOOL bExit = FALSE;
+
+ pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit,nFlags);
+
+ if (bReset) return TRUE;
+ if (bExit) return TRUE;
+
+ CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
+
+ if (CPWL_RadioButton * pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE))
+ pWnd->SetCheck(TRUE);
+ CommitData(pPageView,nFlags);
+ return TRUE;
+ }
+ default:
+ return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
+ }
+}
+
+FX_BOOL CFFL_RadioButton::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
+{
+ CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point);
+
+ if (IsValid())
+ {
+ if (CPWL_RadioButton * pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE))
+ pWnd->SetCheck(TRUE);
+
+ if (!CommitData(pPageView,nFlags)) return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CFFL_RadioButton::IsDataChanged(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(m_pWidget != NULL);
+
+ if (CPWL_RadioButton* pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE))
+ {
+ return pWnd->IsChecked() != m_pWidget->IsChecked();
+ }
+
+ return FALSE;
+}
+
+void CFFL_RadioButton::SaveData(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(m_pWidget != NULL);
+
+ if (CPWL_RadioButton* pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE))
+ {
+
+ FX_BOOL bNewChecked = pWnd->IsChecked();
+
+ if (bNewChecked)
+ {
+ CPDF_FormField* pField = m_pWidget->GetFormField();
+ ASSERT(pField != NULL);
+
+ for (FX_INT32 i=0,sz=pField->CountControls(); i<sz; i++)
+ {
+ if (CPDF_FormControl* pCtrl = pField->GetControl(i))
+ {
+ if (pCtrl->IsChecked())
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ m_pWidget->SetCheck(bNewChecked, FALSE);
+ m_pWidget->UpdateField();
+ SetChangeMark();
+ }
+}
+
diff --git a/fpdfsdk/src/formfiller/FFL_TextField.cpp b/fpdfsdk/src/formfiller/FFL_TextField.cpp
index 7644d4bc60..8cd62fa025 100644
--- a/fpdfsdk/src/formfiller/FFL_TextField.cpp
+++ b/fpdfsdk/src/formfiller/FFL_TextField.cpp
@@ -1,412 +1,412 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-//#include "../include/FormFiller.h"
-//#include "../include/FFL_FormFiller.h"
-#include "../../include/formfiller/FFL_TextField.h"
-#include "../../include/formfiller/FFL_CBA_Fontmap.h"
-//#include "../include/FFL_Notify.h"
-
-CFFL_EditUndoItem::CFFL_EditUndoItem(CPWL_Edit* pEdit) : m_pEdit(pEdit)
-{
-}
-
-CFFL_EditUndoItem::~CFFL_EditUndoItem()
-{
-}
-
-void CFFL_EditUndoItem::Undo()
-{
-}
-
-void CFFL_EditUndoItem::Redo()
-{
-}
-
-CFX_WideString CFFL_EditUndoItem::GetDescr()
-{
- return L"Input";
-}
-
-void CFFL_EditUndoItem::Release()
-{
- delete this;
-}
-
-/* ------------------------------- CFFL_TextField ------------------------------- */
-
-CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) :
- CFFL_FormFiller(pApp, pAnnot),
- m_pFontMap(NULL)//,
- //m_pSpellCheck(NULL)
-{
- m_State.nStart = m_State.nEnd = 0;
-}
-
-CFFL_TextField::~CFFL_TextField()
-{
- if (m_pFontMap)
- {
- delete m_pFontMap;
- m_pFontMap = NULL;
- }
-
-}
-
-PWL_CREATEPARAM CFFL_TextField::GetCreateParam()
-{
- PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
-
- ASSERT(m_pWidget != NULL);
- int nFlags = m_pWidget->GetFieldFlags();
-
-
- if (nFlags & FIELDFLAG_PASSWORD)
- {
- cp.dwFlags |= PES_PASSWORD;
- }
-
- if (!(nFlags & FIELDFLAG_DONOTSPELLCHECK))
- {
- }
-
- if (nFlags & FIELDFLAG_MULTILINE)
- {
- cp.dwFlags |= PES_MULTILINE | PES_AUTORETURN | PES_TOP;
-
- if (!(nFlags & FIELDFLAG_DONOTSCROLL))
- {
- cp.dwFlags |= PWS_VSCROLL | PES_AUTOSCROLL;
- }
- }
- else
- {
- cp.dwFlags |= PES_CENTER;
-
- if (!(nFlags & FIELDFLAG_DONOTSCROLL))
- {
- cp.dwFlags |= PES_AUTOSCROLL;
- }
- }
-
- if (nFlags & FIELDFLAG_COMB)
- {
- cp.dwFlags |= PES_CHARARRAY;
- }
-
- if (nFlags & FIELDFLAG_RICHTEXT)
- {
- cp.dwFlags |= PES_RICH;
- }
-
- cp.dwFlags |= PES_UNDO;
-
- switch (m_pWidget->GetAlignment())
- {
- default:
- case BF_ALIGN_LEFT:
- cp.dwFlags |= PES_LEFT;
- break;
- case BF_ALIGN_MIDDLE:
- cp.dwFlags |= PES_MIDDLE;
- break;
- case BF_ALIGN_RIGHT:
- cp.dwFlags |= PES_RIGHT;
- break;
- }
-
- if (!m_pFontMap)
- {
- ASSERT(this->m_pApp != NULL);
- m_pFontMap = new CBA_FontMap(m_pWidget, /*ISystemHandle::GetSystemHandler(m_pApp)*/m_pApp->GetSysHandler());
- m_pFontMap->Initial();
- }
- cp.pFontMap = m_pFontMap;
- cp.pFocusHandler = this;
-
- return cp;
-}
-
-CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
-{
- CPWL_Edit * pWnd = new CPWL_Edit();
- pWnd->AttachFFLData(this);
- pWnd->Create(cp);
-
-
-
- ASSERT(m_pApp != NULL);
- CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
- pWnd->SetFillerNotify(pIFormFiller);
-
- ASSERT(m_pWidget != NULL);
- FX_INT32 nMaxLen = m_pWidget->GetMaxLen();
- CFX_WideString swValue = m_pWidget->GetValue();
-
- if (nMaxLen > 0)
- {
- if (pWnd->HasFlag(PES_CHARARRAY))
- {
- pWnd->SetCharArray(nMaxLen);
- pWnd->SetAlignFormatV(PEAV_CENTER);
- }
- else
- {
- pWnd->SetLimitChar(nMaxLen);
- }
- }
-
- pWnd->SetText(swValue);
-
- return pWnd;
-}
-
-
-FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
-{
- switch (nChar)
- {
- case FWL_VKEY_Return:
- if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE))
- {
- CPDFSDK_PageView* pPageView = this->GetCurPageView();
- ASSERT(pPageView != NULL);
- m_bValid = !m_bValid;
- CPDF_Rect rcAnnot = pAnnot->GetRect();
- m_pApp->FFI_Invalidate(pAnnot->GetPDFPage(), rcAnnot.left, rcAnnot.top, rcAnnot.right, rcAnnot.bottom);
-
- if (m_bValid)
- {
- if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE))
- pWnd->SetFocus();
- }
- else
- {
- if (CommitData(pPageView, nFlags))
- {
- DestroyPDFWindow(pPageView);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- }
- break;
- case FWL_VKEY_Escape:
- {
- CPDFSDK_PageView* pPageView = this->GetCurPageView();
- ASSERT(pPageView != NULL);
- EscapeFiller(pPageView,TRUE);
- return TRUE;
- }
- }
-
- return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
-}
-
-FX_BOOL CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView)
-{
- ASSERT(m_pWidget != NULL);
-
- if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
- return pEdit->GetText() != m_pWidget->GetValue();
-
- return FALSE;
-}
-
-void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView)
-{
- ASSERT(m_pWidget != NULL);
-
- if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
- {
- CFX_WideString sOldValue = m_pWidget->GetValue();
- CFX_WideString sNewValue = pWnd->GetText();
-
- m_pWidget->SetValue(sNewValue, FALSE);
- m_pWidget->ResetFieldAppearance(TRUE);
- m_pWidget->UpdateField();
- SetChangeMark();
- }
-}
-
-void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
- PDFSDK_FieldAction& fa)
-{
- switch (type)
- {
- case CPDF_AAction::KeyStroke:
- if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
- {
- fa.bFieldFull = pWnd->IsTextFull();
-
- fa.sValue = pWnd->GetText();
-
- if (fa.bFieldFull)
- {
- fa.sChange = L"";
- fa.sChangeEx = L"";
- }
- }
- break;
- case CPDF_AAction::Validate:
- if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
- {
- fa.sValue = pWnd->GetText();
- }
- break;
- case CPDF_AAction::LoseFocus:
- case CPDF_AAction::GetFocus:
- ASSERT(m_pWidget != NULL);
- fa.sValue = m_pWidget->GetValue();
- break;
- default:
- break;
- }
-}
-
-void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
- const PDFSDK_FieldAction& fa)
-{
- switch (type)
- {
- case CPDF_AAction::KeyStroke:
- if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
- {
- pEdit->SetFocus();
- pEdit->SetSel(fa.nSelStart, fa.nSelEnd);
- pEdit->ReplaceSel(fa.sChange);
- }
- break;
- default:
- break;
- }
-}
-
-
-FX_BOOL CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld,
- const PDFSDK_FieldAction& faNew)
-{
- switch (type)
- {
- case CPDF_AAction::KeyStroke:
- return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || faOld.nSelStart != faNew.nSelStart ||
- faOld.sChange != faNew.sChange;
- default:
- break;
- }
-
- return FALSE;
-}
-
-void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView)
-{
- ASSERT(pPageView != NULL);
-
- if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
- {
- pWnd->GetSel(m_State.nStart, m_State.nEnd);
- m_State.sValue = pWnd->GetText();
- }
-}
-
-void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView)
-{
- ASSERT(pPageView != NULL);
-
- if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE))
- {
- pWnd->SetText(m_State.sValue);
- pWnd->SetSel(m_State.nStart, m_State.nEnd);
- }
-}
-
-CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
-{
- if (bRestoreValue)
- SaveState(pPageView);
-
- DestroyPDFWindow(pPageView);
-
- CPWL_Wnd* pRet = NULL;
-
- if (bRestoreValue)
- {
- RestoreState(pPageView);
- pRet = this->GetPDFWindow(pPageView, FALSE);
- }
- else
- pRet = this->GetPDFWindow(pPageView, TRUE);
-
- m_pWidget->UpdateField();
-
- return pRet;
-}
-
-void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd)
-{
- ASSERT(m_pApp != NULL);
-
- ASSERT(pWnd != NULL);
-
- if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT)
- {
- CPWL_Edit* pEdit = (CPWL_Edit*)pWnd;
- pEdit->SetCharSet(134);
- pEdit->SetCodePage(936);
-
- pEdit->SetReadyToInput();
- CFX_WideString wsText = pEdit->GetText();
- int nCharacters = wsText.GetLength();
- CFX_ByteString bsUTFText = wsText.UTF16LE_Encode();
- unsigned short* pBuffer = (unsigned short*)(FX_LPCSTR)bsUTFText;
- m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, nCharacters, TRUE);
-
- pEdit->SetEditNotify(this);
- //pUndo->BeginEdit(pDocument);
- }
-}
-
-void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd)
-{
-
-}
-
-FX_BOOL CFFL_TextField::CanCopy(CPDFSDK_Document* pDocument)
-{
- return FALSE;
-}
-
-FX_BOOL CFFL_TextField::CanCut(CPDFSDK_Document* pDocument)
-{
- return FALSE;
-}
-
-FX_BOOL CFFL_TextField::CanPaste(CPDFSDK_Document* pDocument)
-{
- return FALSE;
-}
-
-void CFFL_TextField::DoCopy(CPDFSDK_Document* pDocument)
-{
-
-}
-
-void CFFL_TextField::DoCut(CPDFSDK_Document* pDocument)
-{
-}
-
-void CFFL_TextField::DoPaste(CPDFSDK_Document* pDocument)
-{
-
-}
-
-void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit)
-{
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+//#include "../include/FormFiller.h"
+//#include "../include/FFL_FormFiller.h"
+#include "../../include/formfiller/FFL_TextField.h"
+#include "../../include/formfiller/FFL_CBA_Fontmap.h"
+//#include "../include/FFL_Notify.h"
+
+CFFL_EditUndoItem::CFFL_EditUndoItem(CPWL_Edit* pEdit) : m_pEdit(pEdit)
+{
+}
+
+CFFL_EditUndoItem::~CFFL_EditUndoItem()
+{
+}
+
+void CFFL_EditUndoItem::Undo()
+{
+}
+
+void CFFL_EditUndoItem::Redo()
+{
+}
+
+CFX_WideString CFFL_EditUndoItem::GetDescr()
+{
+ return L"Input";
+}
+
+void CFFL_EditUndoItem::Release()
+{
+ delete this;
+}
+
+/* ------------------------------- CFFL_TextField ------------------------------- */
+
+CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) :
+ CFFL_FormFiller(pApp, pAnnot),
+ m_pFontMap(NULL)//,
+ //m_pSpellCheck(NULL)
+{
+ m_State.nStart = m_State.nEnd = 0;
+}
+
+CFFL_TextField::~CFFL_TextField()
+{
+ if (m_pFontMap)
+ {
+ delete m_pFontMap;
+ m_pFontMap = NULL;
+ }
+
+}
+
+PWL_CREATEPARAM CFFL_TextField::GetCreateParam()
+{
+ PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
+
+ ASSERT(m_pWidget != NULL);
+ int nFlags = m_pWidget->GetFieldFlags();
+
+
+ if (nFlags & FIELDFLAG_PASSWORD)
+ {
+ cp.dwFlags |= PES_PASSWORD;
+ }
+
+ if (!(nFlags & FIELDFLAG_DONOTSPELLCHECK))
+ {
+ }
+
+ if (nFlags & FIELDFLAG_MULTILINE)
+ {
+ cp.dwFlags |= PES_MULTILINE | PES_AUTORETURN | PES_TOP;
+
+ if (!(nFlags & FIELDFLAG_DONOTSCROLL))
+ {
+ cp.dwFlags |= PWS_VSCROLL | PES_AUTOSCROLL;
+ }
+ }
+ else
+ {
+ cp.dwFlags |= PES_CENTER;
+
+ if (!(nFlags & FIELDFLAG_DONOTSCROLL))
+ {
+ cp.dwFlags |= PES_AUTOSCROLL;
+ }
+ }
+
+ if (nFlags & FIELDFLAG_COMB)
+ {
+ cp.dwFlags |= PES_CHARARRAY;
+ }
+
+ if (nFlags & FIELDFLAG_RICHTEXT)
+ {
+ cp.dwFlags |= PES_RICH;
+ }
+
+ cp.dwFlags |= PES_UNDO;
+
+ switch (m_pWidget->GetAlignment())
+ {
+ default:
+ case BF_ALIGN_LEFT:
+ cp.dwFlags |= PES_LEFT;
+ break;
+ case BF_ALIGN_MIDDLE:
+ cp.dwFlags |= PES_MIDDLE;
+ break;
+ case BF_ALIGN_RIGHT:
+ cp.dwFlags |= PES_RIGHT;
+ break;
+ }
+
+ if (!m_pFontMap)
+ {
+ ASSERT(this->m_pApp != NULL);
+ m_pFontMap = new CBA_FontMap(m_pWidget, /*ISystemHandle::GetSystemHandler(m_pApp)*/m_pApp->GetSysHandler());
+ m_pFontMap->Initial();
+ }
+ cp.pFontMap = m_pFontMap;
+ cp.pFocusHandler = this;
+
+ return cp;
+}
+
+CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
+{
+ CPWL_Edit * pWnd = new CPWL_Edit();
+ pWnd->AttachFFLData(this);
+ pWnd->Create(cp);
+
+
+
+ ASSERT(m_pApp != NULL);
+ CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
+ pWnd->SetFillerNotify(pIFormFiller);
+
+ ASSERT(m_pWidget != NULL);
+ FX_INT32 nMaxLen = m_pWidget->GetMaxLen();
+ CFX_WideString swValue = m_pWidget->GetValue();
+
+ if (nMaxLen > 0)
+ {
+ if (pWnd->HasFlag(PES_CHARARRAY))
+ {
+ pWnd->SetCharArray(nMaxLen);
+ pWnd->SetAlignFormatV(PEAV_CENTER);
+ }
+ else
+ {
+ pWnd->SetLimitChar(nMaxLen);
+ }
+ }
+
+ pWnd->SetText(swValue);
+
+ return pWnd;
+}
+
+
+FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
+{
+ switch (nChar)
+ {
+ case FWL_VKEY_Return:
+ if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE))
+ {
+ CPDFSDK_PageView* pPageView = this->GetCurPageView();
+ ASSERT(pPageView != NULL);
+ m_bValid = !m_bValid;
+ CPDF_Rect rcAnnot = pAnnot->GetRect();
+ m_pApp->FFI_Invalidate(pAnnot->GetPDFPage(), rcAnnot.left, rcAnnot.top, rcAnnot.right, rcAnnot.bottom);
+
+ if (m_bValid)
+ {
+ if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE))
+ pWnd->SetFocus();
+ }
+ else
+ {
+ if (CommitData(pPageView, nFlags))
+ {
+ DestroyPDFWindow(pPageView);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ }
+ break;
+ case FWL_VKEY_Escape:
+ {
+ CPDFSDK_PageView* pPageView = this->GetCurPageView();
+ ASSERT(pPageView != NULL);
+ EscapeFiller(pPageView,TRUE);
+ return TRUE;
+ }
+ }
+
+ return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
+}
+
+FX_BOOL CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(m_pWidget != NULL);
+
+ if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
+ return pEdit->GetText() != m_pWidget->GetValue();
+
+ return FALSE;
+}
+
+void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(m_pWidget != NULL);
+
+ if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
+ {
+ CFX_WideString sOldValue = m_pWidget->GetValue();
+ CFX_WideString sNewValue = pWnd->GetText();
+
+ m_pWidget->SetValue(sNewValue, FALSE);
+ m_pWidget->ResetFieldAppearance(TRUE);
+ m_pWidget->UpdateField();
+ SetChangeMark();
+ }
+}
+
+void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
+ PDFSDK_FieldAction& fa)
+{
+ switch (type)
+ {
+ case CPDF_AAction::KeyStroke:
+ if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
+ {
+ fa.bFieldFull = pWnd->IsTextFull();
+
+ fa.sValue = pWnd->GetText();
+
+ if (fa.bFieldFull)
+ {
+ fa.sChange = L"";
+ fa.sChangeEx = L"";
+ }
+ }
+ break;
+ case CPDF_AAction::Validate:
+ if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
+ {
+ fa.sValue = pWnd->GetText();
+ }
+ break;
+ case CPDF_AAction::LoseFocus:
+ case CPDF_AAction::GetFocus:
+ ASSERT(m_pWidget != NULL);
+ fa.sValue = m_pWidget->GetValue();
+ break;
+ default:
+ break;
+ }
+}
+
+void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
+ const PDFSDK_FieldAction& fa)
+{
+ switch (type)
+ {
+ case CPDF_AAction::KeyStroke:
+ if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
+ {
+ pEdit->SetFocus();
+ pEdit->SetSel(fa.nSelStart, fa.nSelEnd);
+ pEdit->ReplaceSel(fa.sChange);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+
+FX_BOOL CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld,
+ const PDFSDK_FieldAction& faNew)
+{
+ switch (type)
+ {
+ case CPDF_AAction::KeyStroke:
+ return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || faOld.nSelStart != faNew.nSelStart ||
+ faOld.sChange != faNew.sChange;
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(pPageView != NULL);
+
+ if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
+ {
+ pWnd->GetSel(m_State.nStart, m_State.nEnd);
+ m_State.sValue = pWnd->GetText();
+ }
+}
+
+void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView)
+{
+ ASSERT(pPageView != NULL);
+
+ if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE))
+ {
+ pWnd->SetText(m_State.sValue);
+ pWnd->SetSel(m_State.nStart, m_State.nEnd);
+ }
+}
+
+CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
+{
+ if (bRestoreValue)
+ SaveState(pPageView);
+
+ DestroyPDFWindow(pPageView);
+
+ CPWL_Wnd* pRet = NULL;
+
+ if (bRestoreValue)
+ {
+ RestoreState(pPageView);
+ pRet = this->GetPDFWindow(pPageView, FALSE);
+ }
+ else
+ pRet = this->GetPDFWindow(pPageView, TRUE);
+
+ m_pWidget->UpdateField();
+
+ return pRet;
+}
+
+void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd)
+{
+ ASSERT(m_pApp != NULL);
+
+ ASSERT(pWnd != NULL);
+
+ if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT)
+ {
+ CPWL_Edit* pEdit = (CPWL_Edit*)pWnd;
+ pEdit->SetCharSet(134);
+ pEdit->SetCodePage(936);
+
+ pEdit->SetReadyToInput();
+ CFX_WideString wsText = pEdit->GetText();
+ int nCharacters = wsText.GetLength();
+ CFX_ByteString bsUTFText = wsText.UTF16LE_Encode();
+ unsigned short* pBuffer = (unsigned short*)(FX_LPCSTR)bsUTFText;
+ m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, nCharacters, TRUE);
+
+ pEdit->SetEditNotify(this);
+ //pUndo->BeginEdit(pDocument);
+ }
+}
+
+void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd)
+{
+
+}
+
+FX_BOOL CFFL_TextField::CanCopy(CPDFSDK_Document* pDocument)
+{
+ return FALSE;
+}
+
+FX_BOOL CFFL_TextField::CanCut(CPDFSDK_Document* pDocument)
+{
+ return FALSE;
+}
+
+FX_BOOL CFFL_TextField::CanPaste(CPDFSDK_Document* pDocument)
+{
+ return FALSE;
+}
+
+void CFFL_TextField::DoCopy(CPDFSDK_Document* pDocument)
+{
+
+}
+
+void CFFL_TextField::DoCut(CPDFSDK_Document* pDocument)
+{
+}
+
+void CFFL_TextField::DoPaste(CPDFSDK_Document* pDocument)
+{
+
+}
+
+void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit)
+{
+}
+
diff --git a/fpdfsdk/src/formfiller/FFL_Utils.cpp b/fpdfsdk/src/formfiller/FFL_Utils.cpp
index 2e908108b8..3ea78918be 100644
--- a/fpdfsdk/src/formfiller/FFL_Utils.cpp
+++ b/fpdfsdk/src/formfiller/FFL_Utils.cpp
@@ -1,133 +1,133 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/formfiller/FormFiller.h"
-#include "../../include/formfiller/FFL_Utils.h"
-
-CPDF_Rect CFFL_Utils::MaxRect(const CPDF_Rect & rect1,const CPDF_Rect & rect2)
-{
- CPDF_Rect rcRet;
-
- rcRet.left = FFL_MIN(rect1.left,rect2.left);
- rcRet.bottom = FFL_MIN(rect1.bottom,rect2.bottom);
- rcRet.right = FFL_MAX(rect1.right,rect2.right);
- rcRet.top = FFL_MAX(rect1.top,rect2.top);
-
- return rcRet;
-}
-
-CPDF_Rect CFFL_Utils::InflateRect(const CPDF_Rect & crRect,const FX_FLOAT & fSize)
-{
- CPDF_Rect crNew(crRect.left - fSize,
- crRect.bottom - fSize,
- crRect.right + fSize,
- crRect.top + fSize);
- crNew.Normalize();
- return crNew;
-}
-
-CPDF_Rect CFFL_Utils::DeflateRect(const CPDF_Rect & crRect,const FX_FLOAT & fSize)
-{
- CPDF_Rect crNew(crRect.left + fSize,
- crRect.bottom + fSize,
- crRect.right - fSize,
- crRect.top - fSize);
- crNew.Normalize();
- return crNew;
-}
-
-/*
-FX_BOOL CFFL_Utils::RectContainsRect(const CPDF_Rect & father,const CPDF_Rect & son)
-{
- return (father.left <= son.left && father.right >= son.right &&
- father.bottom <= son.bottom && father.top >= son.top);
-
-}
-
-FX_BOOL CFFL_Utils::RectContainsPoint(const CPDF_Rect & father,const CPDF_Point & son)
-{
- return (father.left <= son.x && father.right >= son.x &&
- father.bottom <= son.y && father.top >= son.y);
-}
-
-FX_BOOL CFFL_Utils::RectContainsXY(const CPDF_Rect & father,FX_FLOAT x,FX_FLOAT y)
-{
- return (father.left <= x && father.right >= x &&
- father.bottom <= y && father.top >= y);
-}
-*/
-
-FX_BOOL CFFL_Utils::TraceObject(CPDF_Object* pObj)
-{
- if (!pObj) return FALSE;
-
- FX_DWORD dwObjNum = pObj->GetObjNum();
- switch (pObj->GetType())
- {
- case PDFOBJ_ARRAY:
- {
- CPDF_Array* pArray = (CPDF_Array*)pObj;
- for (FX_DWORD i = 0; i < pArray->GetCount(); i ++)
- {
- CPDF_Object* pElement = pArray->GetElementValue(i);
- TraceObject(pElement);
- }
- }
- break;
-
- case PDFOBJ_DICTIONARY:
- {
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
-
- FX_POSITION fPos = pDict->GetStartPos();
- CFX_ByteString csKey;
- do
- {
- CPDF_Object* pElement = pDict->GetNextElement(fPos, csKey);
- //TRACE(csKey + "\n");
- if (!pElement) break;
- TraceObject(pElement);
- }while (TRUE);
- }
- break;
-
- case PDFOBJ_STREAM:
- {
- CPDF_Stream* pStream = (CPDF_Stream*)pObj;
- CPDF_Dictionary* pDict = pStream->GetDict();
- TraceObject(pDict);
- }
- break;
-
- case PDFOBJ_REFERENCE:
- {
- CPDF_Object* pDirectObj = pObj->GetDirect();
- TraceObject(pDirectObj);
- }
- break;
-
- case PDFOBJ_BOOLEAN:
- break;
- case PDFOBJ_NUMBER:
- //TRACE("%d\n",(FX_INT32)pObj);
- break;
- case PDFOBJ_STRING:
- //TRACE(((CPDF_String*)pObj)->GetString() + "\n");
- break;
- case PDFOBJ_NAME:
- //TRACE(((CPDF_Name*)pObj)->GetString() + "\n");
- break;
- case PDFOBJ_NULL:
-// case PDFOBJ_KEYWORD:
-// case PDFOBJ_EOF:
- default:
- break;
- }
- if (dwObjNum == 0) return FALSE;
-
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/formfiller/FormFiller.h"
+#include "../../include/formfiller/FFL_Utils.h"
+
+CPDF_Rect CFFL_Utils::MaxRect(const CPDF_Rect & rect1,const CPDF_Rect & rect2)
+{
+ CPDF_Rect rcRet;
+
+ rcRet.left = FFL_MIN(rect1.left,rect2.left);
+ rcRet.bottom = FFL_MIN(rect1.bottom,rect2.bottom);
+ rcRet.right = FFL_MAX(rect1.right,rect2.right);
+ rcRet.top = FFL_MAX(rect1.top,rect2.top);
+
+ return rcRet;
+}
+
+CPDF_Rect CFFL_Utils::InflateRect(const CPDF_Rect & crRect,const FX_FLOAT & fSize)
+{
+ CPDF_Rect crNew(crRect.left - fSize,
+ crRect.bottom - fSize,
+ crRect.right + fSize,
+ crRect.top + fSize);
+ crNew.Normalize();
+ return crNew;
+}
+
+CPDF_Rect CFFL_Utils::DeflateRect(const CPDF_Rect & crRect,const FX_FLOAT & fSize)
+{
+ CPDF_Rect crNew(crRect.left + fSize,
+ crRect.bottom + fSize,
+ crRect.right - fSize,
+ crRect.top - fSize);
+ crNew.Normalize();
+ return crNew;
+}
+
+/*
+FX_BOOL CFFL_Utils::RectContainsRect(const CPDF_Rect & father,const CPDF_Rect & son)
+{
+ return (father.left <= son.left && father.right >= son.right &&
+ father.bottom <= son.bottom && father.top >= son.top);
+
+}
+
+FX_BOOL CFFL_Utils::RectContainsPoint(const CPDF_Rect & father,const CPDF_Point & son)
+{
+ return (father.left <= son.x && father.right >= son.x &&
+ father.bottom <= son.y && father.top >= son.y);
+}
+
+FX_BOOL CFFL_Utils::RectContainsXY(const CPDF_Rect & father,FX_FLOAT x,FX_FLOAT y)
+{
+ return (father.left <= x && father.right >= x &&
+ father.bottom <= y && father.top >= y);
+}
+*/
+
+FX_BOOL CFFL_Utils::TraceObject(CPDF_Object* pObj)
+{
+ if (!pObj) return FALSE;
+
+ FX_DWORD dwObjNum = pObj->GetObjNum();
+ switch (pObj->GetType())
+ {
+ case PDFOBJ_ARRAY:
+ {
+ CPDF_Array* pArray = (CPDF_Array*)pObj;
+ for (FX_DWORD i = 0; i < pArray->GetCount(); i ++)
+ {
+ CPDF_Object* pElement = pArray->GetElementValue(i);
+ TraceObject(pElement);
+ }
+ }
+ break;
+
+ case PDFOBJ_DICTIONARY:
+ {
+ CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
+
+ FX_POSITION fPos = pDict->GetStartPos();
+ CFX_ByteString csKey;
+ do
+ {
+ CPDF_Object* pElement = pDict->GetNextElement(fPos, csKey);
+ //TRACE(csKey + "\n");
+ if (!pElement) break;
+ TraceObject(pElement);
+ }while (TRUE);
+ }
+ break;
+
+ case PDFOBJ_STREAM:
+ {
+ CPDF_Stream* pStream = (CPDF_Stream*)pObj;
+ CPDF_Dictionary* pDict = pStream->GetDict();
+ TraceObject(pDict);
+ }
+ break;
+
+ case PDFOBJ_REFERENCE:
+ {
+ CPDF_Object* pDirectObj = pObj->GetDirect();
+ TraceObject(pDirectObj);
+ }
+ break;
+
+ case PDFOBJ_BOOLEAN:
+ break;
+ case PDFOBJ_NUMBER:
+ //TRACE("%d\n",(FX_INT32)pObj);
+ break;
+ case PDFOBJ_STRING:
+ //TRACE(((CPDF_String*)pObj)->GetString() + "\n");
+ break;
+ case PDFOBJ_NAME:
+ //TRACE(((CPDF_Name*)pObj)->GetString() + "\n");
+ break;
+ case PDFOBJ_NULL:
+// case PDFOBJ_KEYWORD:
+// case PDFOBJ_EOF:
+ default:
+ break;
+ }
+ if (dwObjNum == 0) return FALSE;
+
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/fpdf_dataavail.cpp b/fpdfsdk/src/fpdf_dataavail.cpp
index 9e56c2e0c8..b5483f9c39 100644
--- a/fpdfsdk/src/fpdf_dataavail.cpp
+++ b/fpdfsdk/src/fpdf_dataavail.cpp
@@ -1,165 +1,165 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdf_dataavail.h"
-
-extern void ProcessParseError(FX_DWORD err_code);
-class CFPDF_FileAvailWrap : public IFX_FileAvail
-{
-public:
- CFPDF_FileAvailWrap()
- {
- m_pfileAvail = NULL;
- }
-
- void Set(FX_FILEAVAIL* pfileAvail)
- {
- m_pfileAvail = pfileAvail;
- }
-
- virtual FX_BOOL IsDataAvail( FX_FILESIZE offset, FX_DWORD size)
- {
- return m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size);
- }
-
-private:
- FX_FILEAVAIL* m_pfileAvail;
-};
-
-class CFPDF_FileAccessWrap : public IFX_FileRead
-{
-public:
- CFPDF_FileAccessWrap()
- {
- m_pFileAccess = NULL;
- }
-
- void Set(FPDF_FILEACCESS* pFile)
- {
- m_pFileAccess = pFile;
- }
-
- virtual FX_FILESIZE GetSize()
- {
- return m_pFileAccess->m_FileLen;
- }
-
- virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
- {
- return m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, (FX_LPBYTE)buffer, size);
- }
-
- virtual void Release()
- {
- }
-
-private:
- FPDF_FILEACCESS* m_pFileAccess;
-};
-
-class CFPDF_DownloadHintsWrap : public IFX_DownloadHints
-{
-public:
- CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints)
- {
- m_pDownloadHints = pDownloadHints;
- }
-public:
- virtual void AddSegment(FX_FILESIZE offset, FX_DWORD size)
- {
- m_pDownloadHints->AddSegment(m_pDownloadHints, offset, size);
- }
-private:
- FX_DOWNLOADHINTS* m_pDownloadHints;
-};
-
-class CFPDF_DataAvail : public CFX_Object
-{
-public:
- CFPDF_DataAvail()
- {
- m_pDataAvail = NULL;
- }
-
- ~CFPDF_DataAvail()
- {
- if (m_pDataAvail) delete m_pDataAvail;
- }
-
- CPDF_DataAvail* m_pDataAvail;
- CFPDF_FileAvailWrap m_FileAvail;
- CFPDF_FileAccessWrap m_FileRead;
-};
-
-DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, FPDF_FILEACCESS* file)
-{
- CFPDF_DataAvail* pAvail = FX_NEW CFPDF_DataAvail;
- pAvail->m_FileAvail.Set(file_avail);
- pAvail->m_FileRead.Set(file);
- pAvail->m_pDataAvail = FX_NEW CPDF_DataAvail(&pAvail->m_FileAvail, &pAvail->m_FileRead);
- return pAvail;
-}
-
-DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail)
-{
- if (avail == NULL) return;
- delete (CFPDF_DataAvail*)avail;
-}
-
-DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints)
-{
- if (avail == NULL || hints == NULL) return 0;
- CFPDF_DownloadHintsWrap hints_wrap(hints);
- return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsDocAvail(&hints_wrap);
-}
-
-extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code);
-
-DLLEXPORT FPDF_DOCUMENT STDCALL FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password)
-{
- if (avail == NULL) return NULL;
- CPDF_Parser* pParser = FX_NEW CPDF_Parser;
- pParser->SetPassword(password);
-
- FX_DWORD err_code = pParser->StartAsynParse(((CFPDF_DataAvail*)avail)->m_pDataAvail->GetFileRead());
- if (err_code) {
- delete pParser;
- ProcessParseError(err_code);
- return NULL;
- }
- ((CFPDF_DataAvail*)avail)->m_pDataAvail->SetDocument(pParser->GetDocument());
- CheckUnSupportError(pParser->GetDocument(), FPDF_ERR_SUCCESS);
- return pParser->GetDocument();
-}
-
-DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc)
-{
- if (doc == NULL) return 0;
- CPDF_Document* pDoc = (CPDF_Document*)doc;
- return ((CPDF_Parser*)pDoc->GetParser())->GetFirstPageNo();
-}
-
-DLLEXPORT int STDCALL FPDFAvail_IsPageAvail(FPDF_AVAIL avail, int page_index, FX_DOWNLOADHINTS* hints)
-{
- if (avail == NULL || hints == NULL) return 0;
- CFPDF_DownloadHintsWrap hints_wrap(hints);
- return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsPageAvail(page_index, &hints_wrap);
-}
-
-DLLEXPORT int STDCALL FPDFAvail_IsFormAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints)
-{
- if (avail == NULL || hints == NULL) return -1;
- CFPDF_DownloadHintsWrap hints_wrap(hints);
- return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsFormAvail(&hints_wrap);
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail)
-{
- if (avail == NULL) return -1;
- return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsLinearizedPDF();
-
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdf_dataavail.h"
+
+extern void ProcessParseError(FX_DWORD err_code);
+class CFPDF_FileAvailWrap : public IFX_FileAvail
+{
+public:
+ CFPDF_FileAvailWrap()
+ {
+ m_pfileAvail = NULL;
+ }
+
+ void Set(FX_FILEAVAIL* pfileAvail)
+ {
+ m_pfileAvail = pfileAvail;
+ }
+
+ virtual FX_BOOL IsDataAvail( FX_FILESIZE offset, FX_DWORD size)
+ {
+ return m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size);
+ }
+
+private:
+ FX_FILEAVAIL* m_pfileAvail;
+};
+
+class CFPDF_FileAccessWrap : public IFX_FileRead
+{
+public:
+ CFPDF_FileAccessWrap()
+ {
+ m_pFileAccess = NULL;
+ }
+
+ void Set(FPDF_FILEACCESS* pFile)
+ {
+ m_pFileAccess = pFile;
+ }
+
+ virtual FX_FILESIZE GetSize()
+ {
+ return m_pFileAccess->m_FileLen;
+ }
+
+ virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
+ {
+ return m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, (FX_LPBYTE)buffer, size);
+ }
+
+ virtual void Release()
+ {
+ }
+
+private:
+ FPDF_FILEACCESS* m_pFileAccess;
+};
+
+class CFPDF_DownloadHintsWrap : public IFX_DownloadHints
+{
+public:
+ CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints)
+ {
+ m_pDownloadHints = pDownloadHints;
+ }
+public:
+ virtual void AddSegment(FX_FILESIZE offset, FX_DWORD size)
+ {
+ m_pDownloadHints->AddSegment(m_pDownloadHints, offset, size);
+ }
+private:
+ FX_DOWNLOADHINTS* m_pDownloadHints;
+};
+
+class CFPDF_DataAvail : public CFX_Object
+{
+public:
+ CFPDF_DataAvail()
+ {
+ m_pDataAvail = NULL;
+ }
+
+ ~CFPDF_DataAvail()
+ {
+ if (m_pDataAvail) delete m_pDataAvail;
+ }
+
+ CPDF_DataAvail* m_pDataAvail;
+ CFPDF_FileAvailWrap m_FileAvail;
+ CFPDF_FileAccessWrap m_FileRead;
+};
+
+DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, FPDF_FILEACCESS* file)
+{
+ CFPDF_DataAvail* pAvail = FX_NEW CFPDF_DataAvail;
+ pAvail->m_FileAvail.Set(file_avail);
+ pAvail->m_FileRead.Set(file);
+ pAvail->m_pDataAvail = FX_NEW CPDF_DataAvail(&pAvail->m_FileAvail, &pAvail->m_FileRead);
+ return pAvail;
+}
+
+DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail)
+{
+ if (avail == NULL) return;
+ delete (CFPDF_DataAvail*)avail;
+}
+
+DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints)
+{
+ if (avail == NULL || hints == NULL) return 0;
+ CFPDF_DownloadHintsWrap hints_wrap(hints);
+ return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsDocAvail(&hints_wrap);
+}
+
+extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code);
+
+DLLEXPORT FPDF_DOCUMENT STDCALL FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password)
+{
+ if (avail == NULL) return NULL;
+ CPDF_Parser* pParser = FX_NEW CPDF_Parser;
+ pParser->SetPassword(password);
+
+ FX_DWORD err_code = pParser->StartAsynParse(((CFPDF_DataAvail*)avail)->m_pDataAvail->GetFileRead());
+ if (err_code) {
+ delete pParser;
+ ProcessParseError(err_code);
+ return NULL;
+ }
+ ((CFPDF_DataAvail*)avail)->m_pDataAvail->SetDocument(pParser->GetDocument());
+ CheckUnSupportError(pParser->GetDocument(), FPDF_ERR_SUCCESS);
+ return pParser->GetDocument();
+}
+
+DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc)
+{
+ if (doc == NULL) return 0;
+ CPDF_Document* pDoc = (CPDF_Document*)doc;
+ return ((CPDF_Parser*)pDoc->GetParser())->GetFirstPageNo();
+}
+
+DLLEXPORT int STDCALL FPDFAvail_IsPageAvail(FPDF_AVAIL avail, int page_index, FX_DOWNLOADHINTS* hints)
+{
+ if (avail == NULL || hints == NULL) return 0;
+ CFPDF_DownloadHintsWrap hints_wrap(hints);
+ return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsPageAvail(page_index, &hints_wrap);
+}
+
+DLLEXPORT int STDCALL FPDFAvail_IsFormAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints)
+{
+ if (avail == NULL || hints == NULL) return -1;
+ CFPDF_DownloadHintsWrap hints_wrap(hints);
+ return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsFormAvail(&hints_wrap);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail)
+{
+ if (avail == NULL) return -1;
+ return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsLinearizedPDF();
+
+}
diff --git a/fpdfsdk/src/fpdf_ext.cpp b/fpdfsdk/src/fpdf_ext.cpp
index e2e2d84995..2d9e5ae74c 100644
--- a/fpdfsdk/src/fpdf_ext.cpp
+++ b/fpdfsdk/src/fpdf_ext.cpp
@@ -1,245 +1,245 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdf_ext.h"
-
-#define FPDFSDK_UNSUPPORT_CALL 100
-
-class CFSDK_UnsupportInfo_Adapter
-{
-public:
- CFSDK_UnsupportInfo_Adapter(UNSUPPORT_INFO* unsp_info){ m_unsp_info = unsp_info;}
-// FX_BOOL NeedToPauseNow();
- void ReportError(int nErrorType);
-
-private:
- UNSUPPORT_INFO* m_unsp_info;
-};
-
-void CFSDK_UnsupportInfo_Adapter::ReportError(int nErrorType)
-{
- if(m_unsp_info && m_unsp_info->FSDK_UnSupport_Handler)
- {
- m_unsp_info->FSDK_UnSupport_Handler(m_unsp_info,nErrorType);
- }
-}
-
-void FreeUnsupportInfo(FX_LPVOID pData)
-{
- CFSDK_UnsupportInfo_Adapter * pAdapter = (CFSDK_UnsupportInfo_Adapter *)pData;
- delete pAdapter;
-}
-
-FX_BOOL FPDF_UnSupportError(int nError)
-{
- CFSDK_UnsupportInfo_Adapter * pAdapter = (CFSDK_UnsupportInfo_Adapter *)CPDF_ModuleMgr::Get()->GetPrivateData((void *)FPDFSDK_UNSUPPORT_CALL);
-
- if(!pAdapter)
- return FALSE;
- pAdapter->ReportError(nError);
- return TRUE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info)
-{
- if (!unsp_info || unsp_info->version!=1)
- return FALSE;
- CFSDK_UnsupportInfo_Adapter * pAdapter = new CFSDK_UnsupportInfo_Adapter(unsp_info);
-
- CPDF_ModuleMgr::Get()->SetPrivateData((void *)FPDFSDK_UNSUPPORT_CALL,pAdapter, &FreeUnsupportInfo);
-
- return TRUE;
-}
-
-void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot)
-{
- CFX_ByteString cbSubType = pPDFAnnot->GetSubType();
- if(cbSubType.Compare("3D") == 0)
- {
- FPDF_UnSupportError(FPDF_UNSP_ANNOT_3DANNOT);
- }
- else if(cbSubType.Compare("Screen") ==0)
- {
- CPDF_Dictionary* pAnnotDict = pPDFAnnot->m_pAnnotDict;
- CFX_ByteString cbString;
- if(pAnnotDict->KeyExist("IT"))
- cbString = pAnnotDict->GetString("IT");
- if(cbString.Compare("Img") != 0)
- FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA);
- }
- else if(cbSubType.Compare("Movie") ==0)
- {
- FPDF_UnSupportError(FPDF_UNSP_ANNOT_MOVIE);
- }
- else if(cbSubType.Compare("Sound") ==0)
- {
- FPDF_UnSupportError(FPDF_UNSP_ANNOT_SOUND);
- }
- else if(cbSubType.Compare("RichMedia") ==0)
- {
- FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA);
- }
- else if(cbSubType.Compare("FileAttachment") ==0)
- {
- FPDF_UnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT);
- }
- else if(cbSubType.Compare("Widget") ==0)
- {
- CPDF_Dictionary* pAnnotDict = pPDFAnnot->m_pAnnotDict;
- CFX_ByteString cbString;
- if(pAnnotDict->KeyExist("FT"))
- {
- cbString = pAnnotDict->GetString("FT");
- }
- if(cbString.Compare("Sig") == 0)
- {
- FPDF_UnSupportError(FPDF_UNSP_ANNOT_SIG);
- }
- }
-
-}
-
-FX_BOOL CheckSharedForm(CXML_Element * pElement, CFX_ByteString cbName)
-{
- int count = pElement->CountAttrs();
- int i=0;
- for (i = 0; i < count; i++)
- {
- CFX_ByteString space, name;
- CFX_WideString value;
- pElement->GetAttrByIndex(i, space, name, value);
- if (space == FX_BSTRC("xmlns") && name == FX_BSTRC("adhocwf") && value == L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/")
- {
- CXML_Element *pVersion = pElement->GetElement("adhocwf",cbName);
- if (!pVersion)
- continue;
- CFX_WideString wsContent = pVersion->GetContent(0); // == 1.1
- int nType = wsContent.GetInteger();
- switch(nType)
- {
- case 1:
- FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_ACROBAT);
- break;
- case 2:
- FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM);
- break;
- case 0:
- FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_EMAIL);
- break;
- }
- }
- }
-
- FX_DWORD nCount = pElement->CountChildren();
- for(i=0; i<(int)nCount; i++)
- {
- CXML_Element::ChildType childType = pElement->GetChildType(i);
- if(childType == CXML_Element::Element)
- {
- CXML_Element * pChild = pElement->GetElement(i);
- if(CheckSharedForm(pChild, cbName))
- return TRUE;
- }
- }
- return FALSE;
-}
-
-void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code)
-{
- // Security
- if(err_code == FPDF_ERR_SECURITY)
- {
- FPDF_UnSupportError(FPDF_UNSP_DOC_SECURITY);
- return ;
- }
- if(!pDoc)
- return ;
-
- // Portfolios and Packages
- CPDF_Dictionary * pRootDict = pDoc->GetRoot();
- if(pRootDict)
- {
- CFX_ByteString cbString;
- if(pRootDict->KeyExist("Collection"))
- {
- FPDF_UnSupportError(FPDF_UNSP_DOC_PORTABLECOLLECTION);
- return ;
- }
- if(pRootDict->KeyExist("Names"))
- {
- CPDF_Dictionary* pNameDict = pRootDict->GetDict("Names");
- if(pNameDict->KeyExist("EmbeddedFiles"))
- {
- FPDF_UnSupportError(FPDF_UNSP_DOC_ATTACHMENT);
- return;
- }
- else if(pNameDict->KeyExist("JavaScript"))
- {
- CPDF_Dictionary* pJSDict = pNameDict->GetDict("JavaScript");
- CPDF_Array * pArray = pJSDict->GetArray("Names");
- if (pArray) {
- int nCount = pArray->GetCount();
- for(int i=0; i<nCount; i++)
- {
- CFX_ByteString cbStr = pArray->GetString(i);
- if(cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0)
- {
- FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDREVIEW);
- return;
- }
- }
- }
- }
- }
- }
-
- // SharedForm
- CPDF_Metadata metaData;
- metaData.LoadDoc(pDoc);
- CXML_Element * pElement = metaData.GetRoot();
- if(pElement)
- CheckSharedForm(pElement, "workflowType");
-
-
- // XFA Forms
- CPDF_InterForm * pInterForm = FX_NEW CPDF_InterForm(pDoc,FALSE);
- if (pInterForm)
- {
- if(pInterForm->HasXFAForm())
- {
- FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM);
- }
- delete pInterForm;
- }
-}
-
-DLLEXPORT int FPDFDoc_GetPageMode(FPDF_DOCUMENT document)
-{
- if (!document) return PAGEMODE_UNKONOWN;
- CPDF_Dictionary *pRoot = ((CPDF_Document*)document)->GetRoot();
- if (!pRoot)
- return PAGEMODE_UNKONOWN;
- CPDF_Object* pName = pRoot->GetElement("PageMode");
- if (!pName)
- return PAGEMODE_USENONE;
- CFX_ByteString strPageMode = pName->GetString();
-
- if (strPageMode.IsEmpty()||strPageMode.EqualNoCase(FX_BSTR("UseNone")))
- return PAGEMODE_USENONE;
- else if (strPageMode.EqualNoCase(FX_BSTR("UseOutlines")))
- return PAGEMODE_USEOUTLINES;
- else if (strPageMode.EqualNoCase(FX_BSTR("UseThumbs")))
- return PAGEMODE_USETHUMBS;
- else if (strPageMode.EqualNoCase(FX_BSTR("FullScreen")))
- return PAGEMODE_FULLSCREEN;
- else if (strPageMode.EqualNoCase(FX_BSTR("UseOC")))
- return PAGEMODE_USEOC;
- else if (strPageMode.EqualNoCase(FX_BSTR("UseAttachments")))
- return PAGEMODE_USEATTACHMENTS;
-
- return PAGEMODE_UNKONOWN;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdf_ext.h"
+
+#define FPDFSDK_UNSUPPORT_CALL 100
+
+class CFSDK_UnsupportInfo_Adapter
+{
+public:
+ CFSDK_UnsupportInfo_Adapter(UNSUPPORT_INFO* unsp_info){ m_unsp_info = unsp_info;}
+// FX_BOOL NeedToPauseNow();
+ void ReportError(int nErrorType);
+
+private:
+ UNSUPPORT_INFO* m_unsp_info;
+};
+
+void CFSDK_UnsupportInfo_Adapter::ReportError(int nErrorType)
+{
+ if(m_unsp_info && m_unsp_info->FSDK_UnSupport_Handler)
+ {
+ m_unsp_info->FSDK_UnSupport_Handler(m_unsp_info,nErrorType);
+ }
+}
+
+void FreeUnsupportInfo(FX_LPVOID pData)
+{
+ CFSDK_UnsupportInfo_Adapter * pAdapter = (CFSDK_UnsupportInfo_Adapter *)pData;
+ delete pAdapter;
+}
+
+FX_BOOL FPDF_UnSupportError(int nError)
+{
+ CFSDK_UnsupportInfo_Adapter * pAdapter = (CFSDK_UnsupportInfo_Adapter *)CPDF_ModuleMgr::Get()->GetPrivateData((void *)FPDFSDK_UNSUPPORT_CALL);
+
+ if(!pAdapter)
+ return FALSE;
+ pAdapter->ReportError(nError);
+ return TRUE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info)
+{
+ if (!unsp_info || unsp_info->version!=1)
+ return FALSE;
+ CFSDK_UnsupportInfo_Adapter * pAdapter = new CFSDK_UnsupportInfo_Adapter(unsp_info);
+
+ CPDF_ModuleMgr::Get()->SetPrivateData((void *)FPDFSDK_UNSUPPORT_CALL,pAdapter, &FreeUnsupportInfo);
+
+ return TRUE;
+}
+
+void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot)
+{
+ CFX_ByteString cbSubType = pPDFAnnot->GetSubType();
+ if(cbSubType.Compare("3D") == 0)
+ {
+ FPDF_UnSupportError(FPDF_UNSP_ANNOT_3DANNOT);
+ }
+ else if(cbSubType.Compare("Screen") ==0)
+ {
+ CPDF_Dictionary* pAnnotDict = pPDFAnnot->m_pAnnotDict;
+ CFX_ByteString cbString;
+ if(pAnnotDict->KeyExist("IT"))
+ cbString = pAnnotDict->GetString("IT");
+ if(cbString.Compare("Img") != 0)
+ FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA);
+ }
+ else if(cbSubType.Compare("Movie") ==0)
+ {
+ FPDF_UnSupportError(FPDF_UNSP_ANNOT_MOVIE);
+ }
+ else if(cbSubType.Compare("Sound") ==0)
+ {
+ FPDF_UnSupportError(FPDF_UNSP_ANNOT_SOUND);
+ }
+ else if(cbSubType.Compare("RichMedia") ==0)
+ {
+ FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA);
+ }
+ else if(cbSubType.Compare("FileAttachment") ==0)
+ {
+ FPDF_UnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT);
+ }
+ else if(cbSubType.Compare("Widget") ==0)
+ {
+ CPDF_Dictionary* pAnnotDict = pPDFAnnot->m_pAnnotDict;
+ CFX_ByteString cbString;
+ if(pAnnotDict->KeyExist("FT"))
+ {
+ cbString = pAnnotDict->GetString("FT");
+ }
+ if(cbString.Compare("Sig") == 0)
+ {
+ FPDF_UnSupportError(FPDF_UNSP_ANNOT_SIG);
+ }
+ }
+
+}
+
+FX_BOOL CheckSharedForm(CXML_Element * pElement, CFX_ByteString cbName)
+{
+ int count = pElement->CountAttrs();
+ int i=0;
+ for (i = 0; i < count; i++)
+ {
+ CFX_ByteString space, name;
+ CFX_WideString value;
+ pElement->GetAttrByIndex(i, space, name, value);
+ if (space == FX_BSTRC("xmlns") && name == FX_BSTRC("adhocwf") && value == L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/")
+ {
+ CXML_Element *pVersion = pElement->GetElement("adhocwf",cbName);
+ if (!pVersion)
+ continue;
+ CFX_WideString wsContent = pVersion->GetContent(0); // == 1.1
+ int nType = wsContent.GetInteger();
+ switch(nType)
+ {
+ case 1:
+ FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_ACROBAT);
+ break;
+ case 2:
+ FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM);
+ break;
+ case 0:
+ FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_EMAIL);
+ break;
+ }
+ }
+ }
+
+ FX_DWORD nCount = pElement->CountChildren();
+ for(i=0; i<(int)nCount; i++)
+ {
+ CXML_Element::ChildType childType = pElement->GetChildType(i);
+ if(childType == CXML_Element::Element)
+ {
+ CXML_Element * pChild = pElement->GetElement(i);
+ if(CheckSharedForm(pChild, cbName))
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code)
+{
+ // Security
+ if(err_code == FPDF_ERR_SECURITY)
+ {
+ FPDF_UnSupportError(FPDF_UNSP_DOC_SECURITY);
+ return ;
+ }
+ if(!pDoc)
+ return ;
+
+ // Portfolios and Packages
+ CPDF_Dictionary * pRootDict = pDoc->GetRoot();
+ if(pRootDict)
+ {
+ CFX_ByteString cbString;
+ if(pRootDict->KeyExist("Collection"))
+ {
+ FPDF_UnSupportError(FPDF_UNSP_DOC_PORTABLECOLLECTION);
+ return ;
+ }
+ if(pRootDict->KeyExist("Names"))
+ {
+ CPDF_Dictionary* pNameDict = pRootDict->GetDict("Names");
+ if(pNameDict->KeyExist("EmbeddedFiles"))
+ {
+ FPDF_UnSupportError(FPDF_UNSP_DOC_ATTACHMENT);
+ return;
+ }
+ else if(pNameDict->KeyExist("JavaScript"))
+ {
+ CPDF_Dictionary* pJSDict = pNameDict->GetDict("JavaScript");
+ CPDF_Array * pArray = pJSDict->GetArray("Names");
+ if (pArray) {
+ int nCount = pArray->GetCount();
+ for(int i=0; i<nCount; i++)
+ {
+ CFX_ByteString cbStr = pArray->GetString(i);
+ if(cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0)
+ {
+ FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDREVIEW);
+ return;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // SharedForm
+ CPDF_Metadata metaData;
+ metaData.LoadDoc(pDoc);
+ CXML_Element * pElement = metaData.GetRoot();
+ if(pElement)
+ CheckSharedForm(pElement, "workflowType");
+
+
+ // XFA Forms
+ CPDF_InterForm * pInterForm = FX_NEW CPDF_InterForm(pDoc,FALSE);
+ if (pInterForm)
+ {
+ if(pInterForm->HasXFAForm())
+ {
+ FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM);
+ }
+ delete pInterForm;
+ }
+}
+
+DLLEXPORT int FPDFDoc_GetPageMode(FPDF_DOCUMENT document)
+{
+ if (!document) return PAGEMODE_UNKONOWN;
+ CPDF_Dictionary *pRoot = ((CPDF_Document*)document)->GetRoot();
+ if (!pRoot)
+ return PAGEMODE_UNKONOWN;
+ CPDF_Object* pName = pRoot->GetElement("PageMode");
+ if (!pName)
+ return PAGEMODE_USENONE;
+ CFX_ByteString strPageMode = pName->GetString();
+
+ if (strPageMode.IsEmpty()||strPageMode.EqualNoCase(FX_BSTR("UseNone")))
+ return PAGEMODE_USENONE;
+ else if (strPageMode.EqualNoCase(FX_BSTR("UseOutlines")))
+ return PAGEMODE_USEOUTLINES;
+ else if (strPageMode.EqualNoCase(FX_BSTR("UseThumbs")))
+ return PAGEMODE_USETHUMBS;
+ else if (strPageMode.EqualNoCase(FX_BSTR("FullScreen")))
+ return PAGEMODE_FULLSCREEN;
+ else if (strPageMode.EqualNoCase(FX_BSTR("UseOC")))
+ return PAGEMODE_USEOC;
+ else if (strPageMode.EqualNoCase(FX_BSTR("UseAttachments")))
+ return PAGEMODE_USEATTACHMENTS;
+
+ return PAGEMODE_UNKONOWN;
+}
diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp
index f04100f95a..6d3440f556 100644
--- a/fpdfsdk/src/fpdf_flatten.cpp
+++ b/fpdfsdk/src/fpdf_flatten.cpp
@@ -1,561 +1,561 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdf_flatten.h"
-
-typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray;
-typedef CFX_ArrayTemplate<CPDF_Rect> CPDF_RectArray;
-
-enum FPDF_TYPE { MAX, MIN };
-enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM };
-
-FX_BOOL IsValiableRect(CPDF_Rect rect, CPDF_Rect rcPage)
-{
- if ( rect.left - rect.right > 0.000001f ||
- rect.bottom - rect.top > 0.000001f)
- return FALSE;
-
- if (rect.left == 0.0f &&
- rect.top == 0.0f &&
- rect.right == 0.0f &&
- rect.bottom == 0.0f)
- return FALSE;
-
- if (!rcPage.IsEmpty())
- {
- if (rect.left - rcPage.left < -10.000001f ||
- rect.right - rcPage.right > 10.000001f ||
- rect.top - rcPage.top > 10.000001f ||
- rect.bottom - rcPage.bottom < -10.000001f)
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-FX_BOOL GetContentsRect( CPDF_Document * pDoc, CPDF_Dictionary* pDict, CPDF_RectArray * pRectArray )
-{
- CPDF_Page* pPDFPage = FX_NEW CPDF_Page;
- pPDFPage->Load( pDoc, pDict, FALSE );
- pPDFPage->ParseContent();
-
- FX_POSITION pos = pPDFPage->GetFirstObjectPosition();
-
- while (pos)
- {
- CPDF_PageObject* pPageObject = pPDFPage->GetNextObject(pos);
- if (!pPageObject)continue;
-
- CPDF_Rect rc;
- rc.left = pPageObject->m_Left;
- rc.right = pPageObject->m_Right;
- rc.bottom = pPageObject->m_Bottom;
- rc.top = pPageObject->m_Top;
-
- if (IsValiableRect(rc, pDict->GetRect("MediaBox")))
- {
- pRectArray->Add(rc);
- }
- }
-
- delete pPDFPage;
- return TRUE;
-}
-
-
-void ParserStream( CPDF_Dictionary * pPageDic, CPDF_Dictionary* pStream, CPDF_RectArray * pRectArray, CPDF_ObjectArray * pObjectArray )
-{
- if (!pStream)return;
- CPDF_Rect rect;
- if (pStream->KeyExist("Rect"))
- rect = pStream->GetRect("Rect");
- else if (pStream->KeyExist("BBox"))
- rect = pStream->GetRect("BBox");
-
- if (IsValiableRect(rect, pPageDic->GetRect("MediaBox")))
- pRectArray->Add(rect);
-
- pObjectArray->Add(pStream);
-}
-
-
-int ParserAnnots( CPDF_Document* pSourceDoc, CPDF_Dictionary * pPageDic, CPDF_RectArray * pRectArray, CPDF_ObjectArray * pObjectArray, int nUsage)
-{
- if (!pSourceDoc || !pPageDic) return FLATTEN_FAIL;
-
- GetContentsRect( pSourceDoc, pPageDic, pRectArray );
- CPDF_Array* pAnnots = pPageDic->GetArray("Annots");
- if (pAnnots)
- {
- FX_DWORD dwSize = pAnnots->GetCount();
-
- for (int i = 0; i < (int)dwSize; i++)
- {
- CPDF_Object* pObj = pAnnots->GetElementValue(i);
-
- if (!pObj)continue;
-
- if (pObj->GetType() == PDFOBJ_DICTIONARY)
- {
- CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)pObj;
- CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype");
- if (sSubtype == "Popup")continue;
-
- int nAnnotFlag = pAnnotDic->GetInteger("F");
-
- if(nAnnotFlag & ANNOTFLAG_HIDDEN)
- continue;
- if(nUsage == FLAT_NORMALDISPLAY)
- {
- if(nAnnotFlag & ANNOTFLAG_INVISIBLE)
- continue;
- ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );
- }
- else
- {
- if(nAnnotFlag & ANNOTFLAG_PRINT)
- ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );
- }
- }
- }
- return FLATTEN_SUCCESS;
- }else{
- return FLATTEN_NOTINGTODO;
- }
-}
-
-
-FX_FLOAT GetMinMaxValue( CPDF_RectArray& array, FPDF_TYPE type, FPDF_VALUE value)
-{
- int nRects = array.GetSize();
- FX_FLOAT fRet = 0.0f;
-
- if (nRects <= 0)return 0.0f;
-
- FX_FLOAT* pArray = new FX_FLOAT[nRects];
- switch(value)
- {
- case LEFT:
- {
- for (int i = 0; i < nRects; i++)
- pArray[i] = CPDF_Rect(array.GetAt(i)).left;
-
- break;
- }
- case TOP:
- {
- for (int i = 0; i < nRects; i++)
- pArray[i] = CPDF_Rect(array.GetAt(i)).top;
-
- break;
- }
- case RIGHT:
- {
- for (int i = 0; i < nRects; i++)
- pArray[i] = CPDF_Rect(array.GetAt(i)).right;
-
- break;
- }
- case BOTTOM:
- {
- for (int i = 0; i < nRects; i++)
- pArray[i] = CPDF_Rect(array.GetAt(i)).bottom;
-
- break;
- }
- default:
- break;
- }
- fRet = pArray[0];
- if (type == MAX)
- {
- for (int i = 1; i < nRects; i++)
- if (fRet <= pArray[i])
- fRet = pArray[i];
- }
- else
- {
- for (int i = 1; i < nRects; i++)
- if (fRet >= pArray[i])
- fRet = pArray[i];
- }
- delete[] pArray;
- return fRet;
-}
-
-CPDF_Rect CalculateRect( CPDF_RectArray * pRectArray )
-{
-
- CPDF_Rect rcRet;
-
- rcRet.left = GetMinMaxValue(*pRectArray, MIN, LEFT);
- rcRet.top = GetMinMaxValue(*pRectArray, MAX, TOP);
- rcRet.right = GetMinMaxValue(*pRectArray, MAX, RIGHT);
- rcRet.bottom = GetMinMaxValue(*pRectArray, MIN, BOTTOM);
-
- return rcRet;
-}
-
-
-void SetPageContents(CFX_ByteString key, CPDF_Dictionary* pPage, CPDF_Document* pDocument)
-{
- CPDF_Object* pContentsObj = pPage->GetStream("Contents");
- if (!pContentsObj)
- {
- pContentsObj = pPage->GetArray("Contents");
- }
-
- if (!pContentsObj)
- {
- //Create a new contents dictionary
- if (!key.IsEmpty())
- {
- CPDF_Stream* pNewContents = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
- if (!pNewContents)return;
- pPage->SetAtReference("Contents", pDocument, pDocument->AddIndirectObject(pNewContents));
-
- CFX_ByteString sStream;
- sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", (FX_LPCSTR)key);
- pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
- }
- return;
- }
-
- int iType = pContentsObj->GetType();
- CPDF_Array* pContentsArray = NULL;
-
- switch(iType)
- {
- case PDFOBJ_STREAM:
- {
- pContentsArray = FX_NEW CPDF_Array;
- CPDF_Stream* pContents = (CPDF_Stream*)pContentsObj;
- FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContents);
- CPDF_StreamAcc acc;
- acc.LoadAllData(pContents);
- CFX_ByteString sStream = "q\n";
- CFX_ByteString sBody = CFX_ByteString((FX_LPCSTR)acc.GetData(), acc.GetSize());
- sStream = sStream + sBody + "\nQ";
- pContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
- pContentsArray->AddReference(pDocument, dwObjNum);
- break;
- }
-
- case PDFOBJ_ARRAY:
- {
- pContentsArray = (CPDF_Array*)pContentsObj;
- break;
- }
- default:
- break;
- }
-
- if (!pContentsArray)return;
-
- FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray);
- pPage->SetAtReference("Contents", pDocument, dwObjNum);
-
- if (!key.IsEmpty())
- {
- CPDF_Stream* pNewContents = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
- dwObjNum = pDocument->AddIndirectObject(pNewContents);
- pContentsArray->AddReference(pDocument, dwObjNum);
-
- CFX_ByteString sStream;
- sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", (FX_LPCSTR)key);
- pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
- }
-}
-
-CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatrix matrix)
-{
- if(rcStream.IsEmpty())
- return CFX_AffineMatrix();
-
- matrix.TransformRect(rcStream);
- rcStream.Normalize();
-
- FX_FLOAT a = rcAnnot.Width()/rcStream.Width();
- FX_FLOAT d = rcAnnot.Height()/rcStream.Height();
-
- FX_FLOAT e = rcAnnot.left - rcStream.left * a;
- FX_FLOAT f = rcAnnot.bottom - rcStream.bottom * d;
- return CFX_AffineMatrix(a, 0, 0, d, e, f);
-}
-
-void GetOffset(FX_FLOAT& fa, FX_FLOAT& fd, FX_FLOAT& fe, FX_FLOAT& ff, CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatrix matrix)
-{
- FX_FLOAT fStreamWidth = 0.0f;
- FX_FLOAT fStreamHeight = 0.0f;
-
-
-
- if (matrix.a != 0 && matrix.d != 0)
- {
- fStreamWidth = rcStream.right - rcStream.left;
- fStreamHeight = rcStream.top - rcStream.bottom;
- }
- else
- {
- fStreamWidth = rcStream.top - rcStream.bottom;
- fStreamHeight = rcStream.right - rcStream.left;
- }
-
- FX_FLOAT x1 = matrix.a * rcStream.left + matrix.c * rcStream.bottom + matrix.e;
- FX_FLOAT y1 = matrix.b * rcStream.left + matrix.d * rcStream.bottom + matrix.f;
- FX_FLOAT x2 = matrix.a * rcStream.left + matrix.c * rcStream.top + matrix.e;
- FX_FLOAT y2 = matrix.b * rcStream.left + matrix.d * rcStream.top + matrix.f;
- FX_FLOAT x3 = matrix.a * rcStream.right + matrix.c * rcStream.bottom + matrix.e;
- FX_FLOAT y3 = matrix.b * rcStream.right + matrix.d * rcStream.bottom + matrix.f;
- FX_FLOAT x4 = matrix.a * rcStream.right + matrix.c * rcStream.top + matrix.e;
- FX_FLOAT y4 = matrix.b * rcStream.right + matrix.d * rcStream.top + matrix.f;
-
- FX_FLOAT left = FX_MIN(FX_MIN(x1, x2), FX_MIN(x3, x4));
- FX_FLOAT bottom = FX_MIN(FX_MIN(y1, y2), FX_MIN(y3, y4));
-
- fa = (rcAnnot.right - rcAnnot.left)/fStreamWidth;
- fd = (rcAnnot.top - rcAnnot.bottom)/fStreamHeight;
- fe = rcAnnot.left - left * fa;
- ff = rcAnnot.bottom - bottom * fd;
-}
-
-
-DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag)
-{
- if (!page)
- {
- return FLATTEN_FAIL;
- }
-
- CPDF_Page * pPage = (CPDF_Page*)( page );
- CPDF_Document * pDocument = pPage->m_pDocument;
- CPDF_Dictionary * pPageDict = pPage->m_pFormDict;
-
- if ( !pDocument || !pPageDict )
- {
- return FLATTEN_FAIL;
- }
-
- CPDF_ObjectArray ObjectArray;
- CPDF_RectArray RectArray;
-
- int iRet = FLATTEN_FAIL;
- iRet = ParserAnnots( pDocument, pPageDict, &RectArray, &ObjectArray, nFlag);
- if (iRet == FLATTEN_NOTINGTODO)
- {
- return FLATTEN_NOTINGTODO;
- }else if (iRet == FLATTEN_FAIL)
- {
- return FLATTEN_FAIL;
- }
-
- CPDF_Rect rcOriginalCB;
- CPDF_Rect rcMerger = CalculateRect( &RectArray );
- CPDF_Rect rcOriginalMB = pPageDict->GetRect("MediaBox");
-
- if (pPageDict->KeyExist("CropBox"))
- rcOriginalMB = pPageDict->GetRect("CropBox");
-
- if (rcOriginalMB.IsEmpty())
- {
- rcOriginalMB = CPDF_Rect(0.0f, 0.0f, 612.0f, 792.0f);
- }
-
- rcMerger.left = rcMerger.left < rcOriginalMB.left? rcOriginalMB.left : rcMerger.left;
- rcMerger.right = rcMerger.right > rcOriginalMB.right? rcOriginalMB.right : rcMerger.right;
- rcMerger.top = rcMerger.top > rcOriginalMB.top? rcOriginalMB.top : rcMerger.top;
- rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom? rcOriginalMB.bottom : rcMerger.bottom;
-
- if (pPageDict->KeyExist("ArtBox"))
- rcOriginalCB = pPageDict->GetRect("ArtBox");
- else
- rcOriginalCB = rcOriginalMB;
-
- if (!rcOriginalMB.IsEmpty())
- {
- CPDF_Array* pMediaBox = FX_NEW CPDF_Array();
-
- pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.left));
- pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.bottom));
- pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.right));
- pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.top));
-
- pPageDict->SetAt("MediaBox",pMediaBox);
- }
-
- if (!rcOriginalCB.IsEmpty())
- {
- CPDF_Array* pCropBox = FX_NEW CPDF_Array();
- pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.left));
- pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.bottom));
- pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.right));
- pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.top));
- pPageDict->SetAt("ArtBox", pCropBox);
- }
-
- CPDF_Dictionary* pRes = NULL;
- pRes = pPageDict->GetDict("Resources");
- if (!pRes)
- {
- pRes = FX_NEW CPDF_Dictionary;
- pPageDict->SetAt( "Resources", pRes );
- }
-
- CPDF_Stream* pNewXObject = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
- FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject);
- CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject");
- if (!pPageXObject)
- {
- pPageXObject = FX_NEW CPDF_Dictionary;
- pRes->SetAt("XObject", pPageXObject);
- }
-
- CFX_ByteString key = "";
- int nStreams = ObjectArray.GetSize();
-
- if (nStreams > 0)
- {
- for (int iKey = 0; /*iKey < 100*/; iKey++)
- {
- char sExtend[5] = {0};
- FXSYS_itoa(iKey, sExtend, 10);
- key = CFX_ByteString("FFT") + CFX_ByteString(sExtend);
-
- if (!pPageXObject->KeyExist(key))
- break;
- }
- }
-
- SetPageContents(key, pPageDict, pDocument);
-
- CPDF_Dictionary* pNewXORes = NULL;
-
- if (!key.IsEmpty())
- {
- pPageXObject->SetAtReference(key, pDocument, dwObjNum);
- CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict();
- pNewXORes = FX_NEW CPDF_Dictionary;
- pNewOXbjectDic->SetAt("Resources", pNewXORes);
- pNewOXbjectDic->SetAtName("Type", "XObject");
- pNewOXbjectDic->SetAtName("Subtype", "Form");
- pNewOXbjectDic->SetAtInteger("FormType", 1);
- pNewOXbjectDic->SetAtName("Name", "FRM");
- CPDF_Rect rcBBox = pPageDict->GetRect("ArtBox");
- pNewOXbjectDic->SetAtRect("BBox", rcBBox);
- }
-
- for (int i = 0; i < nStreams; i++)
- {
- CPDF_Dictionary* pAnnotDic = ObjectArray.GetAt(i);
- if (!pAnnotDic)continue;
-
- CPDF_Rect rcAnnot = pAnnotDic->GetRect("Rect");
- rcAnnot.Normalize();
-
- CFX_ByteString sAnnotState = pAnnotDic->GetString("AS");
- CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDict("AP");
- if (!pAnnotAP)continue;
-
- CPDF_Stream* pAPStream = pAnnotAP->GetStream("N");
- if (!pAPStream)
- {
- CPDF_Dictionary* pAPDic = pAnnotAP->GetDict("N");
- if (!pAPDic)continue;
-
- if (!sAnnotState.IsEmpty())
- {
- pAPStream = pAPDic->GetStream(sAnnotState);
- }
- else
- {
- FX_POSITION pos = pAPDic->GetStartPos();
- if (pos)
- {
- CFX_ByteString sKey;
- CPDF_Object* pFirstObj = pAPDic->GetNextElement(pos, sKey);
- if (pFirstObj)
- {
- if (pFirstObj->GetType() == PDFOBJ_REFERENCE)
- pFirstObj = pFirstObj->GetDirect();
-
- if (pFirstObj->GetType() != PDFOBJ_STREAM)
- continue;
-
- pAPStream = (CPDF_Stream*)pFirstObj;
- }
- }
- }
- }
-
- if (!pAPStream)continue;
-
- CPDF_Dictionary* pAPDic = pAPStream->GetDict();
- CFX_AffineMatrix matrix = pAPDic->GetMatrix("Matrix");
-
- CPDF_Rect rcStream;
- if (pAPDic->KeyExist("Rect"))
- rcStream = pAPDic->GetRect("Rect");
- else if (pAPDic->KeyExist("BBox"))
- rcStream = pAPDic->GetRect("BBox");
-
- if (rcStream.IsEmpty())continue;
-
- CPDF_Object* pObj = pAPStream;
-
- if (pObj)
- {
- CPDF_Dictionary* pObjDic = pObj->GetDict();
- if (pObjDic)
- {
- pObjDic->SetAtName("Type", "XObject");
- pObjDic->SetAtName("Subtype", "Form");
- }
- }
-
- CPDF_Dictionary* pXObject = pNewXORes->GetDict("XObject");
- if (!pXObject)
- {
- pXObject = FX_NEW CPDF_Dictionary;
- pNewXORes->SetAt("XObject", pXObject);
- }
-
- CFX_ByteString sFormName;
- sFormName.Format("F%d", i);
- FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj);
- pXObject->SetAtReference(sFormName, pDocument, dwObjNum);
-
- CPDF_StreamAcc acc;
- acc.LoadAllData(pNewXObject);
-
- FX_LPCBYTE pData = acc.GetData();
- CFX_ByteString sStream(pData, acc.GetSize());
- CFX_ByteString sTemp;
-
- if (matrix.IsIdentity())
- {
- matrix.a = 1.0f;
- matrix.b = 0.0f;
- matrix.c = 0.0f;
- matrix.d = 1.0f;
- matrix.e = 0.0f;
- matrix.f = 0.0f;
- }
-
- CFX_AffineMatrix m = GetMatrix(rcAnnot, rcStream, matrix);
- sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, (FX_LPCSTR)sFormName);
- sStream += sTemp;
-
- pNewXObject->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
- }
- pPageDict->RemoveAt( "Annots" );
-
- ObjectArray.RemoveAll();
- RectArray.RemoveAll();
-
- return FLATTEN_SUCCESS;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdf_flatten.h"
+
+typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray;
+typedef CFX_ArrayTemplate<CPDF_Rect> CPDF_RectArray;
+
+enum FPDF_TYPE { MAX, MIN };
+enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM };
+
+FX_BOOL IsValiableRect(CPDF_Rect rect, CPDF_Rect rcPage)
+{
+ if ( rect.left - rect.right > 0.000001f ||
+ rect.bottom - rect.top > 0.000001f)
+ return FALSE;
+
+ if (rect.left == 0.0f &&
+ rect.top == 0.0f &&
+ rect.right == 0.0f &&
+ rect.bottom == 0.0f)
+ return FALSE;
+
+ if (!rcPage.IsEmpty())
+ {
+ if (rect.left - rcPage.left < -10.000001f ||
+ rect.right - rcPage.right > 10.000001f ||
+ rect.top - rcPage.top > 10.000001f ||
+ rect.bottom - rcPage.bottom < -10.000001f)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+FX_BOOL GetContentsRect( CPDF_Document * pDoc, CPDF_Dictionary* pDict, CPDF_RectArray * pRectArray )
+{
+ CPDF_Page* pPDFPage = FX_NEW CPDF_Page;
+ pPDFPage->Load( pDoc, pDict, FALSE );
+ pPDFPage->ParseContent();
+
+ FX_POSITION pos = pPDFPage->GetFirstObjectPosition();
+
+ while (pos)
+ {
+ CPDF_PageObject* pPageObject = pPDFPage->GetNextObject(pos);
+ if (!pPageObject)continue;
+
+ CPDF_Rect rc;
+ rc.left = pPageObject->m_Left;
+ rc.right = pPageObject->m_Right;
+ rc.bottom = pPageObject->m_Bottom;
+ rc.top = pPageObject->m_Top;
+
+ if (IsValiableRect(rc, pDict->GetRect("MediaBox")))
+ {
+ pRectArray->Add(rc);
+ }
+ }
+
+ delete pPDFPage;
+ return TRUE;
+}
+
+
+void ParserStream( CPDF_Dictionary * pPageDic, CPDF_Dictionary* pStream, CPDF_RectArray * pRectArray, CPDF_ObjectArray * pObjectArray )
+{
+ if (!pStream)return;
+ CPDF_Rect rect;
+ if (pStream->KeyExist("Rect"))
+ rect = pStream->GetRect("Rect");
+ else if (pStream->KeyExist("BBox"))
+ rect = pStream->GetRect("BBox");
+
+ if (IsValiableRect(rect, pPageDic->GetRect("MediaBox")))
+ pRectArray->Add(rect);
+
+ pObjectArray->Add(pStream);
+}
+
+
+int ParserAnnots( CPDF_Document* pSourceDoc, CPDF_Dictionary * pPageDic, CPDF_RectArray * pRectArray, CPDF_ObjectArray * pObjectArray, int nUsage)
+{
+ if (!pSourceDoc || !pPageDic) return FLATTEN_FAIL;
+
+ GetContentsRect( pSourceDoc, pPageDic, pRectArray );
+ CPDF_Array* pAnnots = pPageDic->GetArray("Annots");
+ if (pAnnots)
+ {
+ FX_DWORD dwSize = pAnnots->GetCount();
+
+ for (int i = 0; i < (int)dwSize; i++)
+ {
+ CPDF_Object* pObj = pAnnots->GetElementValue(i);
+
+ if (!pObj)continue;
+
+ if (pObj->GetType() == PDFOBJ_DICTIONARY)
+ {
+ CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)pObj;
+ CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype");
+ if (sSubtype == "Popup")continue;
+
+ int nAnnotFlag = pAnnotDic->GetInteger("F");
+
+ if(nAnnotFlag & ANNOTFLAG_HIDDEN)
+ continue;
+ if(nUsage == FLAT_NORMALDISPLAY)
+ {
+ if(nAnnotFlag & ANNOTFLAG_INVISIBLE)
+ continue;
+ ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );
+ }
+ else
+ {
+ if(nAnnotFlag & ANNOTFLAG_PRINT)
+ ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );
+ }
+ }
+ }
+ return FLATTEN_SUCCESS;
+ }else{
+ return FLATTEN_NOTINGTODO;
+ }
+}
+
+
+FX_FLOAT GetMinMaxValue( CPDF_RectArray& array, FPDF_TYPE type, FPDF_VALUE value)
+{
+ int nRects = array.GetSize();
+ FX_FLOAT fRet = 0.0f;
+
+ if (nRects <= 0)return 0.0f;
+
+ FX_FLOAT* pArray = new FX_FLOAT[nRects];
+ switch(value)
+ {
+ case LEFT:
+ {
+ for (int i = 0; i < nRects; i++)
+ pArray[i] = CPDF_Rect(array.GetAt(i)).left;
+
+ break;
+ }
+ case TOP:
+ {
+ for (int i = 0; i < nRects; i++)
+ pArray[i] = CPDF_Rect(array.GetAt(i)).top;
+
+ break;
+ }
+ case RIGHT:
+ {
+ for (int i = 0; i < nRects; i++)
+ pArray[i] = CPDF_Rect(array.GetAt(i)).right;
+
+ break;
+ }
+ case BOTTOM:
+ {
+ for (int i = 0; i < nRects; i++)
+ pArray[i] = CPDF_Rect(array.GetAt(i)).bottom;
+
+ break;
+ }
+ default:
+ break;
+ }
+ fRet = pArray[0];
+ if (type == MAX)
+ {
+ for (int i = 1; i < nRects; i++)
+ if (fRet <= pArray[i])
+ fRet = pArray[i];
+ }
+ else
+ {
+ for (int i = 1; i < nRects; i++)
+ if (fRet >= pArray[i])
+ fRet = pArray[i];
+ }
+ delete[] pArray;
+ return fRet;
+}
+
+CPDF_Rect CalculateRect( CPDF_RectArray * pRectArray )
+{
+
+ CPDF_Rect rcRet;
+
+ rcRet.left = GetMinMaxValue(*pRectArray, MIN, LEFT);
+ rcRet.top = GetMinMaxValue(*pRectArray, MAX, TOP);
+ rcRet.right = GetMinMaxValue(*pRectArray, MAX, RIGHT);
+ rcRet.bottom = GetMinMaxValue(*pRectArray, MIN, BOTTOM);
+
+ return rcRet;
+}
+
+
+void SetPageContents(CFX_ByteString key, CPDF_Dictionary* pPage, CPDF_Document* pDocument)
+{
+ CPDF_Object* pContentsObj = pPage->GetStream("Contents");
+ if (!pContentsObj)
+ {
+ pContentsObj = pPage->GetArray("Contents");
+ }
+
+ if (!pContentsObj)
+ {
+ //Create a new contents dictionary
+ if (!key.IsEmpty())
+ {
+ CPDF_Stream* pNewContents = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
+ if (!pNewContents)return;
+ pPage->SetAtReference("Contents", pDocument, pDocument->AddIndirectObject(pNewContents));
+
+ CFX_ByteString sStream;
+ sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", (FX_LPCSTR)key);
+ pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
+ }
+ return;
+ }
+
+ int iType = pContentsObj->GetType();
+ CPDF_Array* pContentsArray = NULL;
+
+ switch(iType)
+ {
+ case PDFOBJ_STREAM:
+ {
+ pContentsArray = FX_NEW CPDF_Array;
+ CPDF_Stream* pContents = (CPDF_Stream*)pContentsObj;
+ FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContents);
+ CPDF_StreamAcc acc;
+ acc.LoadAllData(pContents);
+ CFX_ByteString sStream = "q\n";
+ CFX_ByteString sBody = CFX_ByteString((FX_LPCSTR)acc.GetData(), acc.GetSize());
+ sStream = sStream + sBody + "\nQ";
+ pContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
+ pContentsArray->AddReference(pDocument, dwObjNum);
+ break;
+ }
+
+ case PDFOBJ_ARRAY:
+ {
+ pContentsArray = (CPDF_Array*)pContentsObj;
+ break;
+ }
+ default:
+ break;
+ }
+
+ if (!pContentsArray)return;
+
+ FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray);
+ pPage->SetAtReference("Contents", pDocument, dwObjNum);
+
+ if (!key.IsEmpty())
+ {
+ CPDF_Stream* pNewContents = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
+ dwObjNum = pDocument->AddIndirectObject(pNewContents);
+ pContentsArray->AddReference(pDocument, dwObjNum);
+
+ CFX_ByteString sStream;
+ sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", (FX_LPCSTR)key);
+ pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
+ }
+}
+
+CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatrix matrix)
+{
+ if(rcStream.IsEmpty())
+ return CFX_AffineMatrix();
+
+ matrix.TransformRect(rcStream);
+ rcStream.Normalize();
+
+ FX_FLOAT a = rcAnnot.Width()/rcStream.Width();
+ FX_FLOAT d = rcAnnot.Height()/rcStream.Height();
+
+ FX_FLOAT e = rcAnnot.left - rcStream.left * a;
+ FX_FLOAT f = rcAnnot.bottom - rcStream.bottom * d;
+ return CFX_AffineMatrix(a, 0, 0, d, e, f);
+}
+
+void GetOffset(FX_FLOAT& fa, FX_FLOAT& fd, FX_FLOAT& fe, FX_FLOAT& ff, CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatrix matrix)
+{
+ FX_FLOAT fStreamWidth = 0.0f;
+ FX_FLOAT fStreamHeight = 0.0f;
+
+
+
+ if (matrix.a != 0 && matrix.d != 0)
+ {
+ fStreamWidth = rcStream.right - rcStream.left;
+ fStreamHeight = rcStream.top - rcStream.bottom;
+ }
+ else
+ {
+ fStreamWidth = rcStream.top - rcStream.bottom;
+ fStreamHeight = rcStream.right - rcStream.left;
+ }
+
+ FX_FLOAT x1 = matrix.a * rcStream.left + matrix.c * rcStream.bottom + matrix.e;
+ FX_FLOAT y1 = matrix.b * rcStream.left + matrix.d * rcStream.bottom + matrix.f;
+ FX_FLOAT x2 = matrix.a * rcStream.left + matrix.c * rcStream.top + matrix.e;
+ FX_FLOAT y2 = matrix.b * rcStream.left + matrix.d * rcStream.top + matrix.f;
+ FX_FLOAT x3 = matrix.a * rcStream.right + matrix.c * rcStream.bottom + matrix.e;
+ FX_FLOAT y3 = matrix.b * rcStream.right + matrix.d * rcStream.bottom + matrix.f;
+ FX_FLOAT x4 = matrix.a * rcStream.right + matrix.c * rcStream.top + matrix.e;
+ FX_FLOAT y4 = matrix.b * rcStream.right + matrix.d * rcStream.top + matrix.f;
+
+ FX_FLOAT left = FX_MIN(FX_MIN(x1, x2), FX_MIN(x3, x4));
+ FX_FLOAT bottom = FX_MIN(FX_MIN(y1, y2), FX_MIN(y3, y4));
+
+ fa = (rcAnnot.right - rcAnnot.left)/fStreamWidth;
+ fd = (rcAnnot.top - rcAnnot.bottom)/fStreamHeight;
+ fe = rcAnnot.left - left * fa;
+ ff = rcAnnot.bottom - bottom * fd;
+}
+
+
+DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag)
+{
+ if (!page)
+ {
+ return FLATTEN_FAIL;
+ }
+
+ CPDF_Page * pPage = (CPDF_Page*)( page );
+ CPDF_Document * pDocument = pPage->m_pDocument;
+ CPDF_Dictionary * pPageDict = pPage->m_pFormDict;
+
+ if ( !pDocument || !pPageDict )
+ {
+ return FLATTEN_FAIL;
+ }
+
+ CPDF_ObjectArray ObjectArray;
+ CPDF_RectArray RectArray;
+
+ int iRet = FLATTEN_FAIL;
+ iRet = ParserAnnots( pDocument, pPageDict, &RectArray, &ObjectArray, nFlag);
+ if (iRet == FLATTEN_NOTINGTODO)
+ {
+ return FLATTEN_NOTINGTODO;
+ }else if (iRet == FLATTEN_FAIL)
+ {
+ return FLATTEN_FAIL;
+ }
+
+ CPDF_Rect rcOriginalCB;
+ CPDF_Rect rcMerger = CalculateRect( &RectArray );
+ CPDF_Rect rcOriginalMB = pPageDict->GetRect("MediaBox");
+
+ if (pPageDict->KeyExist("CropBox"))
+ rcOriginalMB = pPageDict->GetRect("CropBox");
+
+ if (rcOriginalMB.IsEmpty())
+ {
+ rcOriginalMB = CPDF_Rect(0.0f, 0.0f, 612.0f, 792.0f);
+ }
+
+ rcMerger.left = rcMerger.left < rcOriginalMB.left? rcOriginalMB.left : rcMerger.left;
+ rcMerger.right = rcMerger.right > rcOriginalMB.right? rcOriginalMB.right : rcMerger.right;
+ rcMerger.top = rcMerger.top > rcOriginalMB.top? rcOriginalMB.top : rcMerger.top;
+ rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom? rcOriginalMB.bottom : rcMerger.bottom;
+
+ if (pPageDict->KeyExist("ArtBox"))
+ rcOriginalCB = pPageDict->GetRect("ArtBox");
+ else
+ rcOriginalCB = rcOriginalMB;
+
+ if (!rcOriginalMB.IsEmpty())
+ {
+ CPDF_Array* pMediaBox = FX_NEW CPDF_Array();
+
+ pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.left));
+ pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.bottom));
+ pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.right));
+ pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.top));
+
+ pPageDict->SetAt("MediaBox",pMediaBox);
+ }
+
+ if (!rcOriginalCB.IsEmpty())
+ {
+ CPDF_Array* pCropBox = FX_NEW CPDF_Array();
+ pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.left));
+ pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.bottom));
+ pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.right));
+ pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.top));
+ pPageDict->SetAt("ArtBox", pCropBox);
+ }
+
+ CPDF_Dictionary* pRes = NULL;
+ pRes = pPageDict->GetDict("Resources");
+ if (!pRes)
+ {
+ pRes = FX_NEW CPDF_Dictionary;
+ pPageDict->SetAt( "Resources", pRes );
+ }
+
+ CPDF_Stream* pNewXObject = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
+ FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject);
+ CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject");
+ if (!pPageXObject)
+ {
+ pPageXObject = FX_NEW CPDF_Dictionary;
+ pRes->SetAt("XObject", pPageXObject);
+ }
+
+ CFX_ByteString key = "";
+ int nStreams = ObjectArray.GetSize();
+
+ if (nStreams > 0)
+ {
+ for (int iKey = 0; /*iKey < 100*/; iKey++)
+ {
+ char sExtend[5] = {0};
+ FXSYS_itoa(iKey, sExtend, 10);
+ key = CFX_ByteString("FFT") + CFX_ByteString(sExtend);
+
+ if (!pPageXObject->KeyExist(key))
+ break;
+ }
+ }
+
+ SetPageContents(key, pPageDict, pDocument);
+
+ CPDF_Dictionary* pNewXORes = NULL;
+
+ if (!key.IsEmpty())
+ {
+ pPageXObject->SetAtReference(key, pDocument, dwObjNum);
+ CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict();
+ pNewXORes = FX_NEW CPDF_Dictionary;
+ pNewOXbjectDic->SetAt("Resources", pNewXORes);
+ pNewOXbjectDic->SetAtName("Type", "XObject");
+ pNewOXbjectDic->SetAtName("Subtype", "Form");
+ pNewOXbjectDic->SetAtInteger("FormType", 1);
+ pNewOXbjectDic->SetAtName("Name", "FRM");
+ CPDF_Rect rcBBox = pPageDict->GetRect("ArtBox");
+ pNewOXbjectDic->SetAtRect("BBox", rcBBox);
+ }
+
+ for (int i = 0; i < nStreams; i++)
+ {
+ CPDF_Dictionary* pAnnotDic = ObjectArray.GetAt(i);
+ if (!pAnnotDic)continue;
+
+ CPDF_Rect rcAnnot = pAnnotDic->GetRect("Rect");
+ rcAnnot.Normalize();
+
+ CFX_ByteString sAnnotState = pAnnotDic->GetString("AS");
+ CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDict("AP");
+ if (!pAnnotAP)continue;
+
+ CPDF_Stream* pAPStream = pAnnotAP->GetStream("N");
+ if (!pAPStream)
+ {
+ CPDF_Dictionary* pAPDic = pAnnotAP->GetDict("N");
+ if (!pAPDic)continue;
+
+ if (!sAnnotState.IsEmpty())
+ {
+ pAPStream = pAPDic->GetStream(sAnnotState);
+ }
+ else
+ {
+ FX_POSITION pos = pAPDic->GetStartPos();
+ if (pos)
+ {
+ CFX_ByteString sKey;
+ CPDF_Object* pFirstObj = pAPDic->GetNextElement(pos, sKey);
+ if (pFirstObj)
+ {
+ if (pFirstObj->GetType() == PDFOBJ_REFERENCE)
+ pFirstObj = pFirstObj->GetDirect();
+
+ if (pFirstObj->GetType() != PDFOBJ_STREAM)
+ continue;
+
+ pAPStream = (CPDF_Stream*)pFirstObj;
+ }
+ }
+ }
+ }
+
+ if (!pAPStream)continue;
+
+ CPDF_Dictionary* pAPDic = pAPStream->GetDict();
+ CFX_AffineMatrix matrix = pAPDic->GetMatrix("Matrix");
+
+ CPDF_Rect rcStream;
+ if (pAPDic->KeyExist("Rect"))
+ rcStream = pAPDic->GetRect("Rect");
+ else if (pAPDic->KeyExist("BBox"))
+ rcStream = pAPDic->GetRect("BBox");
+
+ if (rcStream.IsEmpty())continue;
+
+ CPDF_Object* pObj = pAPStream;
+
+ if (pObj)
+ {
+ CPDF_Dictionary* pObjDic = pObj->GetDict();
+ if (pObjDic)
+ {
+ pObjDic->SetAtName("Type", "XObject");
+ pObjDic->SetAtName("Subtype", "Form");
+ }
+ }
+
+ CPDF_Dictionary* pXObject = pNewXORes->GetDict("XObject");
+ if (!pXObject)
+ {
+ pXObject = FX_NEW CPDF_Dictionary;
+ pNewXORes->SetAt("XObject", pXObject);
+ }
+
+ CFX_ByteString sFormName;
+ sFormName.Format("F%d", i);
+ FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj);
+ pXObject->SetAtReference(sFormName, pDocument, dwObjNum);
+
+ CPDF_StreamAcc acc;
+ acc.LoadAllData(pNewXObject);
+
+ FX_LPCBYTE pData = acc.GetData();
+ CFX_ByteString sStream(pData, acc.GetSize());
+ CFX_ByteString sTemp;
+
+ if (matrix.IsIdentity())
+ {
+ matrix.a = 1.0f;
+ matrix.b = 0.0f;
+ matrix.c = 0.0f;
+ matrix.d = 1.0f;
+ matrix.e = 0.0f;
+ matrix.f = 0.0f;
+ }
+
+ CFX_AffineMatrix m = GetMatrix(rcAnnot, rcStream, matrix);
+ sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, (FX_LPCSTR)sFormName);
+ sStream += sTemp;
+
+ pNewXObject->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
+ }
+ pPageDict->RemoveAt( "Annots" );
+
+ ObjectArray.RemoveAll();
+ RectArray.RemoveAll();
+
+ return FLATTEN_SUCCESS;
+}
diff --git a/fpdfsdk/src/fpdf_progressive.cpp b/fpdfsdk/src/fpdf_progressive.cpp
index 29496e05dc..b6691af82d 100644
--- a/fpdfsdk/src/fpdf_progressive.cpp
+++ b/fpdfsdk/src/fpdf_progressive.cpp
@@ -1,114 +1,114 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fpdf_progressive.h"
-#include "../include/fsdk_define.h"
-#include "../include/fpdfview.h"
-#include "../include/fsdk_rendercontext.h"
-
-extern void (*Func_RenderPage)( CRenderContext*, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
- int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause );
-
-extern void DropContext(void* data);
-
-DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE page,
- int start_x, int start_y, int size_x,
- int size_y, int rotate, int flags,
- IFSDK_PAUSE * pause )
-{
- if (bitmap == NULL || page == NULL)
- return FPDF_RENDER_FAILED;
-
- if (!pause)
- return FPDF_RENDER_FAILED;
-
- if (pause->version !=1)
- return FPDF_RENDER_FAILED;
-
- CPDF_Page* pPage = (CPDF_Page*)page;
-
-// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
-
- CRenderContext* pContext = FX_NEW CRenderContext;
- pPage->SetPrivateData((void*)1, pContext, DropContext );
-#ifdef _SKIA_SUPPORT_
- pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
- if (flags & FPDF_REVERSE_BYTE_ORDER)
- ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
- else
- ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
-#else
- pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
- if (flags & FPDF_REVERSE_BYTE_ORDER)
- ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
- else
- ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
-#endif
- IFSDK_PAUSE_Adapter IPauseAdapter(pause);
-
- if (flags & FPDF_NO_CATCH)
- Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);
- else {
- try {
- Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);
- }
- catch (...){}
- }
-
- if ( pContext->m_pRenderer )
- {
- CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;
- status = pContext->m_pRenderer->GetStatus();
- return status;
- }
- return FPDF_RENDER_FAILED;
-}
-
-DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * pause)
-{
- if (page == NULL)
- return FPDF_RENDER_FAILED;
-
- if (!pause)
- return FPDF_RENDER_FAILED;
-
- if (pause->version !=1)
- return FPDF_RENDER_FAILED;
-
- CPDF_Page* pPage = (CPDF_Page*)page;
-
-// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
-
- CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
- if (pContext && pContext->m_pRenderer)
- {
- IFSDK_PAUSE_Adapter IPauseAdapter(pause);
- pContext->m_pRenderer->Continue(&IPauseAdapter);
-
- CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;
- status = pContext->m_pRenderer->GetStatus();
- return status;
- }
- return FPDF_RENDER_FAILED;
-}
-
-
-DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page)
-{
- if (page == NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
-// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
-
- CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
- if (pContext)
- {
- pContext->m_pDevice->RestoreState();
- delete pContext;
- pPage->RemovePrivateData((void*)1);
- }
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fpdf_progressive.h"
+#include "../include/fsdk_define.h"
+#include "../include/fpdfview.h"
+#include "../include/fsdk_rendercontext.h"
+
+extern void (*Func_RenderPage)( CRenderContext*, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
+ int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause );
+
+extern void DropContext(void* data);
+
+DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE page,
+ int start_x, int start_y, int size_x,
+ int size_y, int rotate, int flags,
+ IFSDK_PAUSE * pause )
+{
+ if (bitmap == NULL || page == NULL)
+ return FPDF_RENDER_FAILED;
+
+ if (!pause)
+ return FPDF_RENDER_FAILED;
+
+ if (pause->version !=1)
+ return FPDF_RENDER_FAILED;
+
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
+
+ CRenderContext* pContext = FX_NEW CRenderContext;
+ pPage->SetPrivateData((void*)1, pContext, DropContext );
+#ifdef _SKIA_SUPPORT_
+ pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
+ if (flags & FPDF_REVERSE_BYTE_ORDER)
+ ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
+ else
+ ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
+#else
+ pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
+ if (flags & FPDF_REVERSE_BYTE_ORDER)
+ ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
+ else
+ ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
+#endif
+ IFSDK_PAUSE_Adapter IPauseAdapter(pause);
+
+ if (flags & FPDF_NO_CATCH)
+ Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);
+ else {
+ try {
+ Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);
+ }
+ catch (...){}
+ }
+
+ if ( pContext->m_pRenderer )
+ {
+ CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;
+ status = pContext->m_pRenderer->GetStatus();
+ return status;
+ }
+ return FPDF_RENDER_FAILED;
+}
+
+DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * pause)
+{
+ if (page == NULL)
+ return FPDF_RENDER_FAILED;
+
+ if (!pause)
+ return FPDF_RENDER_FAILED;
+
+ if (pause->version !=1)
+ return FPDF_RENDER_FAILED;
+
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
+
+ CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
+ if (pContext && pContext->m_pRenderer)
+ {
+ IFSDK_PAUSE_Adapter IPauseAdapter(pause);
+ pContext->m_pRenderer->Continue(&IPauseAdapter);
+
+ CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;
+ status = pContext->m_pRenderer->GetStatus();
+ return status;
+ }
+ return FPDF_RENDER_FAILED;
+}
+
+
+DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page)
+{
+ if (page == NULL) return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
+
+ CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
+ if (pContext)
+ {
+ pContext->m_pDevice->RestoreState();
+ delete pContext;
+ pPage->RemovePrivateData((void*)1);
+ }
+}
+
diff --git a/fpdfsdk/src/fpdf_searchex.cpp b/fpdfsdk/src/fpdf_searchex.cpp
index 540cd552fa..21831a3e3d 100644
--- a/fpdfsdk/src/fpdf_searchex.cpp
+++ b/fpdfsdk/src/fpdf_searchex.cpp
@@ -1,15 +1,15 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdf_searchex.h"
-
-
-DLLEXPORT int STDCALL FPDFText_GetCharIndexFromTextIndex(FPDF_TEXTPAGE text_page, int nTextIndex)
-{
- if(!text_page) return -1;
- return ((IPDF_TextPage*)text_page)->CharIndexFromTextIndex(nTextIndex);
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdf_searchex.h"
+
+
+DLLEXPORT int STDCALL FPDFText_GetCharIndexFromTextIndex(FPDF_TEXTPAGE text_page, int nTextIndex)
+{
+ if(!text_page) return -1;
+ return ((IPDF_TextPage*)text_page)->CharIndexFromTextIndex(nTextIndex);
+}
diff --git a/fpdfsdk/src/fpdf_transformpage.cpp b/fpdfsdk/src/fpdf_transformpage.cpp
index f171c5e526..729b1cd9bb 100644
--- a/fpdfsdk/src/fpdf_transformpage.cpp
+++ b/fpdfsdk/src/fpdf_transformpage.cpp
@@ -1,325 +1,325 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdf_transformpage.h"
-
-DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page, float left, float bottom, float right, float top)
-{
- if(!page)
- return;
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
- CPDF_Array* pMediaBoxArray = FX_NEW CPDF_Array;
- pMediaBoxArray->Add(FX_NEW CPDF_Number(left));
- pMediaBoxArray->Add(FX_NEW CPDF_Number(bottom));
- pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(right)));
- pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(top)));
-
- pPageDict->SetAt("MediaBox", pMediaBoxArray);
-}
-
-
-DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, float left, float bottom, float right, float top)
-{
- if(!page)
- return;
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
- CPDF_Array* pCropBoxArray = FX_NEW CPDF_Array;
- pCropBoxArray->Add(FX_NEW CPDF_Number(left));
- pCropBoxArray->Add(FX_NEW CPDF_Number(bottom));
- pCropBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(right)));
- pCropBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(top)));
-
-
- pPageDict->SetAt("CropBox", pCropBoxArray);
-}
-
-
-DLLEXPORT FX_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, float* left, float* bottom, float* right, float* top)
-{
- if(!page)
- return FALSE;
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
- CPDF_Array* pArray = pPageDict->GetArray("MediaBox");
- if(pArray)
- {
- *left = pArray->GetFloat(0);
- *bottom = pArray->GetFloat(1);
- *right = pArray->GetFloat(2);
- *top = pArray->GetFloat(3);
- return TRUE;
- }
- return FALSE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, float* left, float* bottom, float* right, float* top)
-{
- if(!page)
- return FALSE;
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
- CPDF_Array* pArray = pPageDict->GetArray("CropBox");
- if(pArray)
- {
- *left = pArray->GetFloat(0);
- *bottom = pArray->GetFloat(1);
- *right = pArray->GetFloat(2);
- *top = pArray->GetFloat(3);
- return TRUE;
- }
- return FALSE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, FS_MATRIX* matrix, FS_RECTF* clipRect)
-{
- if(!page)
- return FALSE;
-
- CFX_ByteTextBuf textBuf;
- textBuf<<"q ";
- CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, clipRect->top);
- rect.Normalize();
- CFX_ByteString bsClipping;
- bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, rect.Width(), rect.Height());
- textBuf<<bsClipping;
-
- CFX_ByteString bsMatix;
- bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b,matrix->c,matrix->d,matrix->e,matrix->f);
- textBuf<<bsMatix;
-
-
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
- CPDF_Object* pContentObj = pPageDic->GetElement("Contents");
- if(!pContentObj)
- pContentObj = pPageDic->GetArray("Contents");
- if(!pContentObj)
- return FALSE;
-
- CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary;
- CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic);
- pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE);
- CPDF_Document* pDoc = pPage->m_pDocument;
- if(!pDoc)
- return FALSE;
- pDoc->AddIndirectObject(pStream);
-
- pDic = FX_NEW CPDF_Dictionary;
- CPDF_Stream* pEndStream = FX_NEW CPDF_Stream(NULL,0, pDic);
- pEndStream->SetData((FX_LPCBYTE)" Q", 2, FALSE, FALSE);
- pDoc->AddIndirectObject(pEndStream);
-
- CPDF_Array* pContentArray = NULL;
- if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY)
- {
- pContentArray = (CPDF_Array*)pContentObj;
- CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
- pContentArray->InsertAt(0, pRef);
- pContentArray->AddReference(pDoc,pEndStream);
-
- }
- else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE)
- {
- CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
- CPDF_Object* pDirectObj = pReference->GetDirect();
- if(pDirectObj != NULL)
- {
- if(pDirectObj->GetType() == PDFOBJ_ARRAY)
- {
- pContentArray = (CPDF_Array*)pDirectObj;
- CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
- pContentArray->InsertAt(0, pRef);
- pContentArray->AddReference(pDoc,pEndStream);
-
- }
- else if(pDirectObj->GetType() == PDFOBJ_STREAM)
- {
- pContentArray = FX_NEW CPDF_Array();
- pContentArray->AddReference(pDoc,pStream->GetObjNum());
- pContentArray->AddReference(pDoc,pDirectObj->GetObjNum());
- pContentArray->AddReference(pDoc, pEndStream);
- pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray));
- }
- }
- }
-
- //Need to transform the patterns as well.
- CPDF_Dictionary* pRes = pPageDic->GetDict(FX_BSTRC("Resources"));
- if(pRes)
- {
- CPDF_Dictionary* pPattenDict = pRes->GetDict(FX_BSTRC("Pattern"));
- if(pPattenDict)
- {
- FX_POSITION pos = pPattenDict->GetStartPos();
- while(pos)
- {
- CPDF_Dictionary* pDict = NULL;
- CFX_ByteString key;
- CPDF_Object* pObj = pPattenDict->GetNextElement(pos, key);
- if(pObj->GetType() == PDFOBJ_REFERENCE)
- pObj = pObj->GetDirect();
- if(pObj->GetType() == PDFOBJ_DICTIONARY)
- {
- pDict = (CPDF_Dictionary*)pObj;
- }
- else if(pObj->GetType() == PDFOBJ_STREAM)
- {
- pDict = ((CPDF_Stream*)pObj)->GetDict();
- }
- else
- continue;
-
- CFX_AffineMatrix m = pDict->GetMatrix(FX_BSTRC("Matrix"));
- CFX_AffineMatrix t = *(CFX_AffineMatrix*)matrix;
- m.Concat(t);
- pDict->SetAtMatrix(FX_BSTRC("Matrix"), m);
- }
- }
- }
-
- return TRUE;
-}
-
-DLLEXPORT void STDCALL FPDFPageObj_TransformClipPath(FPDF_PAGEOBJECT page_object,double a, double b, double c, double d, double e, double f)
-{
- CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object;
- if(pPageObj == NULL)
- return;
- CFX_AffineMatrix matrix((FX_FLOAT)a,(FX_FLOAT)b,(FX_FLOAT)c,(FX_FLOAT)d,(FX_FLOAT)e,(FX_FLOAT)f);
-
- //Special treatment to shading object, because the ClipPath for shading object is already transformed.
- if(pPageObj->m_Type != PDFPAGE_SHADING)
- pPageObj->TransformClipPath(matrix);
- pPageObj->TransformGeneralState(matrix);
-}
-
-
-DLLEXPORT FPDF_CLIPPATH STDCALL FPDF_CreateClipPath(float left, float bottom, float right, float top)
-{
- CPDF_ClipPath* pNewClipPath = FX_NEW CPDF_ClipPath();
- pNewClipPath->GetModify();
- CPDF_Path Path;
- Path.GetModify();
- Path.AppendRect(left, bottom, right, top);
- pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, FALSE);
- return pNewClipPath;
-}
-
-DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath)
-{
- if(clipPath)
- delete (CPDF_ClipPath*)clipPath;
-}
-
-void OutputPath(CFX_ByteTextBuf& buf, CPDF_Path path)
-{
- const CFX_PathData* pPathData = path;
- if (pPathData == NULL) return;
-
- FX_PATHPOINT* pPoints = pPathData->GetPoints();
-
- if (path.IsRect()) {
- buf << (pPoints[0].m_PointX) << " " << (pPoints[0].m_PointY) << " "
- << (pPoints[2].m_PointX - pPoints[0].m_PointX) << " "
- << (pPoints[2].m_PointY - pPoints[0].m_PointY) << " re\n";
- return;
- }
-
- CFX_ByteString temp;
- for (int i = 0; i < pPathData->GetPointCount(); i ++) {
- buf << (pPoints[i].m_PointX) << " " << (pPoints[i].m_PointY);
- int point_type = pPoints[i].m_Flag & FXPT_TYPE;
- if (point_type == FXPT_MOVETO)
- buf << " m\n";
- else if (point_type == FXPT_BEZIERTO) {
- buf << " " << (pPoints[i+1].m_PointX) << " " << (pPoints[i+1].m_PointY) << " " <<
- (pPoints[i+2].m_PointX) << " " << (pPoints[i+2].m_PointY);
- if (pPoints[i+2].m_Flag & FXPT_CLOSEFIGURE)
- buf << " c h\n";
- else
- buf << " c\n";
- i += 2;
- } else if (point_type == FXPT_LINETO) {
- if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE)
- buf << " l h\n";
- else
- buf << " l\n";
- }
- }
-}
-
-DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,FPDF_CLIPPATH clipPath)
-{
- if(!page)
- return;
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
- CPDF_Object* pContentObj = pPageDic->GetElement("Contents");
- if(!pContentObj)
- pContentObj = pPageDic->GetArray("Contents");
- if(!pContentObj)
- return;
-
- CFX_ByteTextBuf strClip;
- CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath;
- FX_DWORD i;
- for (i = 0; i < pClipPath->GetPathCount(); i ++) {
- CPDF_Path path = pClipPath->GetPath(i);
- int iClipType = pClipPath->GetClipType(i);
- if (path.GetPointCount() == 0) {
- // Empty clipping (totally clipped out)
- strClip << "0 0 m W n ";
- } else {
- OutputPath(strClip, path);
- if (iClipType == FXFILL_WINDING)
- strClip << "W n\n";
- else
- strClip << "W* n\n";
- }
- }
- CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary;
- CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic);
- pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE);
- CPDF_Document* pDoc = pPage->m_pDocument;
- if(!pDoc)
- return;
- pDoc->AddIndirectObject(pStream);
-
- CPDF_Array* pContentArray = NULL;
- if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY)
- {
- pContentArray = (CPDF_Array*)pContentObj;
- CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
- pContentArray->InsertAt(0, pRef);
-
- }
- else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE)
- {
- CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
- CPDF_Object* pDirectObj = pReference->GetDirect();
- if(pDirectObj != NULL)
- {
- if(pDirectObj->GetType() == PDFOBJ_ARRAY)
- {
- pContentArray = (CPDF_Array*)pDirectObj;
- CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
- pContentArray->InsertAt(0, pRef);
-
- }
- else if(pDirectObj->GetType() == PDFOBJ_STREAM)
- {
- pContentArray = FX_NEW CPDF_Array();
- pContentArray->AddReference(pDoc,pStream->GetObjNum());
- pContentArray->AddReference(pDoc,pDirectObj->GetObjNum());
- pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray));
- }
- }
- }
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdf_transformpage.h"
+
+DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page, float left, float bottom, float right, float top)
+{
+ if(!page)
+ return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
+ CPDF_Array* pMediaBoxArray = FX_NEW CPDF_Array;
+ pMediaBoxArray->Add(FX_NEW CPDF_Number(left));
+ pMediaBoxArray->Add(FX_NEW CPDF_Number(bottom));
+ pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(right)));
+ pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(top)));
+
+ pPageDict->SetAt("MediaBox", pMediaBoxArray);
+}
+
+
+DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, float left, float bottom, float right, float top)
+{
+ if(!page)
+ return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
+ CPDF_Array* pCropBoxArray = FX_NEW CPDF_Array;
+ pCropBoxArray->Add(FX_NEW CPDF_Number(left));
+ pCropBoxArray->Add(FX_NEW CPDF_Number(bottom));
+ pCropBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(right)));
+ pCropBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(top)));
+
+
+ pPageDict->SetAt("CropBox", pCropBoxArray);
+}
+
+
+DLLEXPORT FX_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, float* left, float* bottom, float* right, float* top)
+{
+ if(!page)
+ return FALSE;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
+ CPDF_Array* pArray = pPageDict->GetArray("MediaBox");
+ if(pArray)
+ {
+ *left = pArray->GetFloat(0);
+ *bottom = pArray->GetFloat(1);
+ *right = pArray->GetFloat(2);
+ *top = pArray->GetFloat(3);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, float* left, float* bottom, float* right, float* top)
+{
+ if(!page)
+ return FALSE;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
+ CPDF_Array* pArray = pPageDict->GetArray("CropBox");
+ if(pArray)
+ {
+ *left = pArray->GetFloat(0);
+ *bottom = pArray->GetFloat(1);
+ *right = pArray->GetFloat(2);
+ *top = pArray->GetFloat(3);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, FS_MATRIX* matrix, FS_RECTF* clipRect)
+{
+ if(!page)
+ return FALSE;
+
+ CFX_ByteTextBuf textBuf;
+ textBuf<<"q ";
+ CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, clipRect->top);
+ rect.Normalize();
+ CFX_ByteString bsClipping;
+ bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, rect.Width(), rect.Height());
+ textBuf<<bsClipping;
+
+ CFX_ByteString bsMatix;
+ bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b,matrix->c,matrix->d,matrix->e,matrix->f);
+ textBuf<<bsMatix;
+
+
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
+ CPDF_Object* pContentObj = pPageDic->GetElement("Contents");
+ if(!pContentObj)
+ pContentObj = pPageDic->GetArray("Contents");
+ if(!pContentObj)
+ return FALSE;
+
+ CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary;
+ CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic);
+ pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE);
+ CPDF_Document* pDoc = pPage->m_pDocument;
+ if(!pDoc)
+ return FALSE;
+ pDoc->AddIndirectObject(pStream);
+
+ pDic = FX_NEW CPDF_Dictionary;
+ CPDF_Stream* pEndStream = FX_NEW CPDF_Stream(NULL,0, pDic);
+ pEndStream->SetData((FX_LPCBYTE)" Q", 2, FALSE, FALSE);
+ pDoc->AddIndirectObject(pEndStream);
+
+ CPDF_Array* pContentArray = NULL;
+ if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY)
+ {
+ pContentArray = (CPDF_Array*)pContentObj;
+ CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
+ pContentArray->InsertAt(0, pRef);
+ pContentArray->AddReference(pDoc,pEndStream);
+
+ }
+ else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE)
+ {
+ CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
+ CPDF_Object* pDirectObj = pReference->GetDirect();
+ if(pDirectObj != NULL)
+ {
+ if(pDirectObj->GetType() == PDFOBJ_ARRAY)
+ {
+ pContentArray = (CPDF_Array*)pDirectObj;
+ CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
+ pContentArray->InsertAt(0, pRef);
+ pContentArray->AddReference(pDoc,pEndStream);
+
+ }
+ else if(pDirectObj->GetType() == PDFOBJ_STREAM)
+ {
+ pContentArray = FX_NEW CPDF_Array();
+ pContentArray->AddReference(pDoc,pStream->GetObjNum());
+ pContentArray->AddReference(pDoc,pDirectObj->GetObjNum());
+ pContentArray->AddReference(pDoc, pEndStream);
+ pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray));
+ }
+ }
+ }
+
+ //Need to transform the patterns as well.
+ CPDF_Dictionary* pRes = pPageDic->GetDict(FX_BSTRC("Resources"));
+ if(pRes)
+ {
+ CPDF_Dictionary* pPattenDict = pRes->GetDict(FX_BSTRC("Pattern"));
+ if(pPattenDict)
+ {
+ FX_POSITION pos = pPattenDict->GetStartPos();
+ while(pos)
+ {
+ CPDF_Dictionary* pDict = NULL;
+ CFX_ByteString key;
+ CPDF_Object* pObj = pPattenDict->GetNextElement(pos, key);
+ if(pObj->GetType() == PDFOBJ_REFERENCE)
+ pObj = pObj->GetDirect();
+ if(pObj->GetType() == PDFOBJ_DICTIONARY)
+ {
+ pDict = (CPDF_Dictionary*)pObj;
+ }
+ else if(pObj->GetType() == PDFOBJ_STREAM)
+ {
+ pDict = ((CPDF_Stream*)pObj)->GetDict();
+ }
+ else
+ continue;
+
+ CFX_AffineMatrix m = pDict->GetMatrix(FX_BSTRC("Matrix"));
+ CFX_AffineMatrix t = *(CFX_AffineMatrix*)matrix;
+ m.Concat(t);
+ pDict->SetAtMatrix(FX_BSTRC("Matrix"), m);
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+DLLEXPORT void STDCALL FPDFPageObj_TransformClipPath(FPDF_PAGEOBJECT page_object,double a, double b, double c, double d, double e, double f)
+{
+ CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object;
+ if(pPageObj == NULL)
+ return;
+ CFX_AffineMatrix matrix((FX_FLOAT)a,(FX_FLOAT)b,(FX_FLOAT)c,(FX_FLOAT)d,(FX_FLOAT)e,(FX_FLOAT)f);
+
+ //Special treatment to shading object, because the ClipPath for shading object is already transformed.
+ if(pPageObj->m_Type != PDFPAGE_SHADING)
+ pPageObj->TransformClipPath(matrix);
+ pPageObj->TransformGeneralState(matrix);
+}
+
+
+DLLEXPORT FPDF_CLIPPATH STDCALL FPDF_CreateClipPath(float left, float bottom, float right, float top)
+{
+ CPDF_ClipPath* pNewClipPath = FX_NEW CPDF_ClipPath();
+ pNewClipPath->GetModify();
+ CPDF_Path Path;
+ Path.GetModify();
+ Path.AppendRect(left, bottom, right, top);
+ pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, FALSE);
+ return pNewClipPath;
+}
+
+DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath)
+{
+ if(clipPath)
+ delete (CPDF_ClipPath*)clipPath;
+}
+
+void OutputPath(CFX_ByteTextBuf& buf, CPDF_Path path)
+{
+ const CFX_PathData* pPathData = path;
+ if (pPathData == NULL) return;
+
+ FX_PATHPOINT* pPoints = pPathData->GetPoints();
+
+ if (path.IsRect()) {
+ buf << (pPoints[0].m_PointX) << " " << (pPoints[0].m_PointY) << " "
+ << (pPoints[2].m_PointX - pPoints[0].m_PointX) << " "
+ << (pPoints[2].m_PointY - pPoints[0].m_PointY) << " re\n";
+ return;
+ }
+
+ CFX_ByteString temp;
+ for (int i = 0; i < pPathData->GetPointCount(); i ++) {
+ buf << (pPoints[i].m_PointX) << " " << (pPoints[i].m_PointY);
+ int point_type = pPoints[i].m_Flag & FXPT_TYPE;
+ if (point_type == FXPT_MOVETO)
+ buf << " m\n";
+ else if (point_type == FXPT_BEZIERTO) {
+ buf << " " << (pPoints[i+1].m_PointX) << " " << (pPoints[i+1].m_PointY) << " " <<
+ (pPoints[i+2].m_PointX) << " " << (pPoints[i+2].m_PointY);
+ if (pPoints[i+2].m_Flag & FXPT_CLOSEFIGURE)
+ buf << " c h\n";
+ else
+ buf << " c\n";
+ i += 2;
+ } else if (point_type == FXPT_LINETO) {
+ if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE)
+ buf << " l h\n";
+ else
+ buf << " l\n";
+ }
+ }
+}
+
+DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,FPDF_CLIPPATH clipPath)
+{
+ if(!page)
+ return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
+ CPDF_Object* pContentObj = pPageDic->GetElement("Contents");
+ if(!pContentObj)
+ pContentObj = pPageDic->GetArray("Contents");
+ if(!pContentObj)
+ return;
+
+ CFX_ByteTextBuf strClip;
+ CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath;
+ FX_DWORD i;
+ for (i = 0; i < pClipPath->GetPathCount(); i ++) {
+ CPDF_Path path = pClipPath->GetPath(i);
+ int iClipType = pClipPath->GetClipType(i);
+ if (path.GetPointCount() == 0) {
+ // Empty clipping (totally clipped out)
+ strClip << "0 0 m W n ";
+ } else {
+ OutputPath(strClip, path);
+ if (iClipType == FXFILL_WINDING)
+ strClip << "W n\n";
+ else
+ strClip << "W* n\n";
+ }
+ }
+ CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary;
+ CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic);
+ pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE);
+ CPDF_Document* pDoc = pPage->m_pDocument;
+ if(!pDoc)
+ return;
+ pDoc->AddIndirectObject(pStream);
+
+ CPDF_Array* pContentArray = NULL;
+ if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY)
+ {
+ pContentArray = (CPDF_Array*)pContentObj;
+ CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
+ pContentArray->InsertAt(0, pRef);
+
+ }
+ else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE)
+ {
+ CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
+ CPDF_Object* pDirectObj = pReference->GetDirect();
+ if(pDirectObj != NULL)
+ {
+ if(pDirectObj->GetType() == PDFOBJ_ARRAY)
+ {
+ pContentArray = (CPDF_Array*)pDirectObj;
+ CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
+ pContentArray->InsertAt(0, pRef);
+
+ }
+ else if(pDirectObj->GetType() == PDFOBJ_STREAM)
+ {
+ pContentArray = FX_NEW CPDF_Array();
+ pContentArray->AddReference(pDoc,pStream->GetObjNum());
+ pContentArray->AddReference(pDoc,pDirectObj->GetObjNum());
+ pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray));
+ }
+ }
+ }
+}
+
diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp
index d5d9000bd2..4fa6ba2197 100644
--- a/fpdfsdk/src/fpdfdoc.cpp
+++ b/fpdfsdk/src/fpdfdoc.cpp
@@ -1,259 +1,259 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdfdoc.h"
-
-static int this_module = 0;
-
-static CPDF_Bookmark FindBookmark(CPDF_BookmarkTree& tree, CPDF_Bookmark This, const CFX_WideString& title)
-{
- if (This != NULL) {
- // First check this item
- CFX_WideString this_title = This.GetTitle();
- if (this_title.CompareNoCase(title) == 0)
- return This;
- }
- // go into children items
- CPDF_Bookmark Child = tree.GetFirstChild(This);
- while (Child != NULL) {
- // check if this item
- CPDF_Bookmark Found = FindBookmark(tree, Child, title);
- if (Found) return Found;
- Child = tree.GetNextSibling(Child);
- }
- return NULL;
-}
-
-DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title)
-{
- if (document == NULL) return NULL;
- if (title == NULL || title[0] == 0) return NULL;
-
- CPDF_Document* pDoc = (CPDF_Document*)document;
- CPDF_BookmarkTree tree(pDoc);
-
- CFX_WideString wstr = CFX_WideString::FromUTF16LE(title);
- return FindBookmark(tree, NULL, wstr);
-}
-
-DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark)
-{
- if (document == NULL) return NULL;
- if (bookmark == NULL) return NULL;
-
- CPDF_Bookmark Bookmark = (CPDF_Dictionary*)bookmark;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- CPDF_Dest dest = Bookmark.GetDest(pDoc);
- if (dest != NULL) return dest;
-
- // If this bookmark is not directly associated with a dest, we try to get action
- CPDF_Action Action = Bookmark.GetAction();
- if (Action == NULL) return NULL;
- return Action.GetDest(pDoc);
-}
-
-DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark)
-{
- if (bookmark == NULL) return NULL;
-
- CPDF_Bookmark Bookmark = (CPDF_Dictionary*)bookmark;
- return Bookmark.GetAction();
-}
-
-DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION action)
-{
- if (action == NULL) return 0;
-
- CPDF_Action Action = (CPDF_Dictionary*)action;
- CPDF_Action::ActionType type = Action.GetType();
- switch (type) {
- case CPDF_Action::GoTo:
- return PDFACTION_GOTO;
- case CPDF_Action::GoToR:
- return PDFACTION_REMOTEGOTO;
- case CPDF_Action::URI:
- return PDFACTION_URI;
- case CPDF_Action::Launch:
- return PDFACTION_LAUNCH;
- default:
- return PDFACTION_UNSUPPORTED;
- }
- return PDFACTION_UNSUPPORTED;
-}
-
-DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTION action)
-{
- if (document == NULL) return NULL;
- if (action == NULL) return NULL;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- CPDF_Action Action = (CPDF_Dictionary*)action;
-
- return Action.GetDest(pDoc);
-}
-
-DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, FPDF_ACTION action,
- void* buffer, unsigned long buflen)
-{
- if (document == NULL) return 0;
- if (action == NULL) return 0;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- CPDF_Action Action = (CPDF_Dictionary*)action;
-
- CFX_ByteString path = Action.GetURI(pDoc);
- unsigned long len = path.GetLength() + 1;
- if (buffer != NULL && buflen >= len)
- FXSYS_memcpy(buffer, (FX_LPCSTR)path, len);
- return len;
-}
-
-DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FPDF_DEST dest)
-{
- if (document == NULL) return 0;
- if (dest == NULL) return 0;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- CPDF_Dest Dest = (CPDF_Array*)dest;
-
- return Dest.GetPageIndex(pDoc);
-}
-
-static void ReleaseLinkList(FX_LPVOID data)
-{
- delete (CPDF_LinkList*)data;
-}
-
-DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y)
-{
- if (page == NULL) return NULL;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
- // Link list is stored with the document
- CPDF_Document* pDoc = pPage->m_pDocument;
- CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&this_module);
- if (pLinkList == NULL) {
- pLinkList = FX_NEW CPDF_LinkList(pDoc);
- pDoc->SetPrivateData(&this_module, pLinkList, ReleaseLinkList);
- }
-
- return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y);
-}
-
-DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK link)
-{
- if (document == NULL) return NULL;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if (link == NULL) return NULL;
- CPDF_Link Link = (CPDF_Dictionary*)link;
-
- FPDF_DEST dest = Link.GetDest(pDoc);
- if (dest) return dest;
-
- // If this link is not directly associated with a dest, we try to get action
- CPDF_Action Action = Link.GetAction();
- if (Action == NULL) return NULL;
- return Action.GetDest(pDoc);
-}
-
-DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK link)
-{
- if (link == NULL) return NULL;
- CPDF_Link Link = (CPDF_Dictionary*)link;
-
- return Link.GetAction();
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FPDF_LINK* linkAnnot)
-{
- if(!page || !startPos || !linkAnnot)
- return FALSE;
- CPDF_Page* pPage = (CPDF_Page*)page;
- if(!pPage->m_pFormDict) return FALSE;
- CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots");
- if(!pAnnots) return FALSE;
- for (int i = *startPos; i < (int)pAnnots->GetCount(); i ++) {
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i);
- if (pDict == NULL || pDict->GetType() != PDFOBJ_DICTIONARY) continue;
- if(pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link")))
- {
- *startPos = i+1;
- *linkAnnot = (FPDF_LINK)pDict;
- return TRUE;
- }
- }
- return FALSE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot, FS_RECTF* rect)
-{
- if(!linkAnnot || !rect)
- return FALSE;
- CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
- CPDF_Rect rt = pAnnotDict->GetRect(FX_BSTRC("Rect"));
- rect->left = rt.left;
- rect->bottom = rt.bottom;
- rect->right = rt.right;
- rect->top = rt.top;
- return TRUE;
-}
-
-DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot)
-{
- if(!linkAnnot)
- return 0;
- CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
- CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints"));
- if (pArray == NULL)
- return 0;
- else
- return pArray->GetCount() / 8;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot, int quadIndex, FS_QUADPOINTSF* quadPoints)
-{
- if(!linkAnnot || !quadPoints)
- return FALSE;
- CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
- CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints"));
- if (pArray) {
- if (0 > quadIndex || quadIndex >= (int)pArray->GetCount()/8 ||
- ((quadIndex*8+7) >= (int)pArray->GetCount())) return FALSE;
- quadPoints->x1 = pArray->GetNumber(quadIndex*8);
- quadPoints->y1 = pArray->GetNumber(quadIndex*8+1);
- quadPoints->x2 = pArray->GetNumber(quadIndex*8+2);
- quadPoints->y2 = pArray->GetNumber(quadIndex*8+3);
- quadPoints->x3 = pArray->GetNumber(quadIndex*8+4);
- quadPoints->y3 = pArray->GetNumber(quadIndex*8+5);
- quadPoints->x4 = pArray->GetNumber(quadIndex*8+6);
- quadPoints->y4 = pArray->GetNumber(quadIndex*8+7);
- return TRUE;
- }
- return FALSE;
-}
-
-
-DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTRING tag,
- void* buffer, unsigned long buflen)
-{
- if (doc == NULL || tag == NULL) return 0;
-
- CPDF_Document* pDoc = (CPDF_Document*)doc;
- // Get info dictionary
- CPDF_Dictionary* pInfo = pDoc->GetInfo();
- if (pInfo == NULL) return 0;
-
- CFX_WideString text = pInfo->GetUnicodeText(tag);
-
- // Use UTF-16LE encoding
- CFX_ByteString bstr = text.UTF16LE_Encode();
- unsigned long len = bstr.GetLength();
- if (buffer != NULL || buflen >= len+2) {
- FXSYS_memcpy(buffer, (FX_LPCSTR)bstr, len);
- // use double zero as trailer
- ((FX_BYTE*)buffer)[len] = ((FX_BYTE*)buffer)[len+1] = 0;
- }
- return len+2;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdfdoc.h"
+
+static int this_module = 0;
+
+static CPDF_Bookmark FindBookmark(CPDF_BookmarkTree& tree, CPDF_Bookmark This, const CFX_WideString& title)
+{
+ if (This != NULL) {
+ // First check this item
+ CFX_WideString this_title = This.GetTitle();
+ if (this_title.CompareNoCase(title) == 0)
+ return This;
+ }
+ // go into children items
+ CPDF_Bookmark Child = tree.GetFirstChild(This);
+ while (Child != NULL) {
+ // check if this item
+ CPDF_Bookmark Found = FindBookmark(tree, Child, title);
+ if (Found) return Found;
+ Child = tree.GetNextSibling(Child);
+ }
+ return NULL;
+}
+
+DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title)
+{
+ if (document == NULL) return NULL;
+ if (title == NULL || title[0] == 0) return NULL;
+
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_BookmarkTree tree(pDoc);
+
+ CFX_WideString wstr = CFX_WideString::FromUTF16LE(title);
+ return FindBookmark(tree, NULL, wstr);
+}
+
+DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark)
+{
+ if (document == NULL) return NULL;
+ if (bookmark == NULL) return NULL;
+
+ CPDF_Bookmark Bookmark = (CPDF_Dictionary*)bookmark;
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Dest dest = Bookmark.GetDest(pDoc);
+ if (dest != NULL) return dest;
+
+ // If this bookmark is not directly associated with a dest, we try to get action
+ CPDF_Action Action = Bookmark.GetAction();
+ if (Action == NULL) return NULL;
+ return Action.GetDest(pDoc);
+}
+
+DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark)
+{
+ if (bookmark == NULL) return NULL;
+
+ CPDF_Bookmark Bookmark = (CPDF_Dictionary*)bookmark;
+ return Bookmark.GetAction();
+}
+
+DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION action)
+{
+ if (action == NULL) return 0;
+
+ CPDF_Action Action = (CPDF_Dictionary*)action;
+ CPDF_Action::ActionType type = Action.GetType();
+ switch (type) {
+ case CPDF_Action::GoTo:
+ return PDFACTION_GOTO;
+ case CPDF_Action::GoToR:
+ return PDFACTION_REMOTEGOTO;
+ case CPDF_Action::URI:
+ return PDFACTION_URI;
+ case CPDF_Action::Launch:
+ return PDFACTION_LAUNCH;
+ default:
+ return PDFACTION_UNSUPPORTED;
+ }
+ return PDFACTION_UNSUPPORTED;
+}
+
+DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTION action)
+{
+ if (document == NULL) return NULL;
+ if (action == NULL) return NULL;
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Action Action = (CPDF_Dictionary*)action;
+
+ return Action.GetDest(pDoc);
+}
+
+DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, FPDF_ACTION action,
+ void* buffer, unsigned long buflen)
+{
+ if (document == NULL) return 0;
+ if (action == NULL) return 0;
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Action Action = (CPDF_Dictionary*)action;
+
+ CFX_ByteString path = Action.GetURI(pDoc);
+ unsigned long len = path.GetLength() + 1;
+ if (buffer != NULL && buflen >= len)
+ FXSYS_memcpy(buffer, (FX_LPCSTR)path, len);
+ return len;
+}
+
+DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FPDF_DEST dest)
+{
+ if (document == NULL) return 0;
+ if (dest == NULL) return 0;
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Dest Dest = (CPDF_Array*)dest;
+
+ return Dest.GetPageIndex(pDoc);
+}
+
+static void ReleaseLinkList(FX_LPVOID data)
+{
+ delete (CPDF_LinkList*)data;
+}
+
+DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y)
+{
+ if (page == NULL) return NULL;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+ // Link list is stored with the document
+ CPDF_Document* pDoc = pPage->m_pDocument;
+ CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&this_module);
+ if (pLinkList == NULL) {
+ pLinkList = FX_NEW CPDF_LinkList(pDoc);
+ pDoc->SetPrivateData(&this_module, pLinkList, ReleaseLinkList);
+ }
+
+ return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y);
+}
+
+DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK link)
+{
+ if (document == NULL) return NULL;
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ if (link == NULL) return NULL;
+ CPDF_Link Link = (CPDF_Dictionary*)link;
+
+ FPDF_DEST dest = Link.GetDest(pDoc);
+ if (dest) return dest;
+
+ // If this link is not directly associated with a dest, we try to get action
+ CPDF_Action Action = Link.GetAction();
+ if (Action == NULL) return NULL;
+ return Action.GetDest(pDoc);
+}
+
+DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK link)
+{
+ if (link == NULL) return NULL;
+ CPDF_Link Link = (CPDF_Dictionary*)link;
+
+ return Link.GetAction();
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FPDF_LINK* linkAnnot)
+{
+ if(!page || !startPos || !linkAnnot)
+ return FALSE;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ if(!pPage->m_pFormDict) return FALSE;
+ CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots");
+ if(!pAnnots) return FALSE;
+ for (int i = *startPos; i < (int)pAnnots->GetCount(); i ++) {
+ CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i);
+ if (pDict == NULL || pDict->GetType() != PDFOBJ_DICTIONARY) continue;
+ if(pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link")))
+ {
+ *startPos = i+1;
+ *linkAnnot = (FPDF_LINK)pDict;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot, FS_RECTF* rect)
+{
+ if(!linkAnnot || !rect)
+ return FALSE;
+ CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
+ CPDF_Rect rt = pAnnotDict->GetRect(FX_BSTRC("Rect"));
+ rect->left = rt.left;
+ rect->bottom = rt.bottom;
+ rect->right = rt.right;
+ rect->top = rt.top;
+ return TRUE;
+}
+
+DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot)
+{
+ if(!linkAnnot)
+ return 0;
+ CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
+ CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints"));
+ if (pArray == NULL)
+ return 0;
+ else
+ return pArray->GetCount() / 8;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot, int quadIndex, FS_QUADPOINTSF* quadPoints)
+{
+ if(!linkAnnot || !quadPoints)
+ return FALSE;
+ CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
+ CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints"));
+ if (pArray) {
+ if (0 > quadIndex || quadIndex >= (int)pArray->GetCount()/8 ||
+ ((quadIndex*8+7) >= (int)pArray->GetCount())) return FALSE;
+ quadPoints->x1 = pArray->GetNumber(quadIndex*8);
+ quadPoints->y1 = pArray->GetNumber(quadIndex*8+1);
+ quadPoints->x2 = pArray->GetNumber(quadIndex*8+2);
+ quadPoints->y2 = pArray->GetNumber(quadIndex*8+3);
+ quadPoints->x3 = pArray->GetNumber(quadIndex*8+4);
+ quadPoints->y3 = pArray->GetNumber(quadIndex*8+5);
+ quadPoints->x4 = pArray->GetNumber(quadIndex*8+6);
+ quadPoints->y4 = pArray->GetNumber(quadIndex*8+7);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTRING tag,
+ void* buffer, unsigned long buflen)
+{
+ if (doc == NULL || tag == NULL) return 0;
+
+ CPDF_Document* pDoc = (CPDF_Document*)doc;
+ // Get info dictionary
+ CPDF_Dictionary* pInfo = pDoc->GetInfo();
+ if (pInfo == NULL) return 0;
+
+ CFX_WideString text = pInfo->GetUnicodeText(tag);
+
+ // Use UTF-16LE encoding
+ CFX_ByteString bstr = text.UTF16LE_Encode();
+ unsigned long len = bstr.GetLength();
+ if (buffer != NULL || buflen >= len+2) {
+ FXSYS_memcpy(buffer, (FX_LPCSTR)bstr, len);
+ // use double zero as trailer
+ ((FX_BYTE*)buffer)[len] = ((FX_BYTE*)buffer)[len+1] = 0;
+ }
+ return len+2;
+}
+
diff --git a/fpdfsdk/src/fpdfeditimg.cpp b/fpdfsdk/src/fpdfeditimg.cpp
index ea81203cad..c29d2b74f8 100644
--- a/fpdfsdk/src/fpdfeditimg.cpp
+++ b/fpdfsdk/src/fpdfeditimg.cpp
@@ -1,74 +1,74 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdfedit.h"
-
-
-DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document)
-{
- if (!document)
- return NULL;
- CPDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;
- CPDF_Image* pImg = FX_NEW CPDF_Image((CPDF_Document *)document);
- pImageObj->m_pImage = pImg;
- return pImageObj;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, int nCount,FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS* fileAccess)
-{
- if (!image_object || !fileAccess)
- return FALSE;
-
- IFX_FileRead* pFile = FX_NEW CPDF_CustomAccess(fileAccess);
-
- CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
- pImgObj->m_GeneralState.GetModify();
- for (int index=0;index<nCount;index++)
- {
- CPDF_Page* pPage = (CPDF_Page*)pages[index];
- pImgObj->m_pImage->ResetCache(pPage,NULL);
- }
- pImgObj->m_pImage->SetJpegImage(pFile);
-
- return TRUE;
-}
-
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix (FPDF_PAGEOBJECT image_object,
- double a, double b, double c, double d, double e, double f)
-{
- if (!image_object)
- return FALSE;
- CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
- pImgObj->m_Matrix.a = (FX_FLOAT)a;
- pImgObj->m_Matrix.b = (FX_FLOAT)b;
- pImgObj->m_Matrix.c = (FX_FLOAT)c;
- pImgObj->m_Matrix.d = (FX_FLOAT)d;
- pImgObj->m_Matrix.e = (FX_FLOAT)e;
- pImgObj->m_Matrix.f = (FX_FLOAT)f;
- pImgObj->CalcBoundingBox();
- return TRUE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,int nCount,FPDF_PAGEOBJECT image_object,FPDF_BITMAP bitmap)
-{
- if (!image_object || !bitmap)
- return FALSE;
- CFX_DIBitmap* pBmp = NULL;
- pBmp = (CFX_DIBitmap*)bitmap;
- CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
- pImgObj->m_GeneralState.GetModify();
- for (int index=0;index<nCount;index++)
- {
- CPDF_Page* pPage = (CPDF_Page*)pages[index];
- pImgObj->m_pImage->ResetCache(pPage,NULL);
- }
- pImgObj->m_pImage->SetImage(pBmp,FALSE);
- pImgObj->CalcBoundingBox();
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdfedit.h"
+
+
+DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document)
+{
+ if (!document)
+ return NULL;
+ CPDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;
+ CPDF_Image* pImg = FX_NEW CPDF_Image((CPDF_Document *)document);
+ pImageObj->m_pImage = pImg;
+ return pImageObj;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, int nCount,FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS* fileAccess)
+{
+ if (!image_object || !fileAccess)
+ return FALSE;
+
+ IFX_FileRead* pFile = FX_NEW CPDF_CustomAccess(fileAccess);
+
+ CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
+ pImgObj->m_GeneralState.GetModify();
+ for (int index=0;index<nCount;index++)
+ {
+ CPDF_Page* pPage = (CPDF_Page*)pages[index];
+ pImgObj->m_pImage->ResetCache(pPage,NULL);
+ }
+ pImgObj->m_pImage->SetJpegImage(pFile);
+
+ return TRUE;
+}
+
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix (FPDF_PAGEOBJECT image_object,
+ double a, double b, double c, double d, double e, double f)
+{
+ if (!image_object)
+ return FALSE;
+ CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
+ pImgObj->m_Matrix.a = (FX_FLOAT)a;
+ pImgObj->m_Matrix.b = (FX_FLOAT)b;
+ pImgObj->m_Matrix.c = (FX_FLOAT)c;
+ pImgObj->m_Matrix.d = (FX_FLOAT)d;
+ pImgObj->m_Matrix.e = (FX_FLOAT)e;
+ pImgObj->m_Matrix.f = (FX_FLOAT)f;
+ pImgObj->CalcBoundingBox();
+ return TRUE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,int nCount,FPDF_PAGEOBJECT image_object,FPDF_BITMAP bitmap)
+{
+ if (!image_object || !bitmap)
+ return FALSE;
+ CFX_DIBitmap* pBmp = NULL;
+ pBmp = (CFX_DIBitmap*)bitmap;
+ CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
+ pImgObj->m_GeneralState.GetModify();
+ for (int index=0;index<nCount;index++)
+ {
+ CPDF_Page* pPage = (CPDF_Page*)pages[index];
+ pImgObj->m_pImage->ResetCache(pPage,NULL);
+ }
+ pImgObj->m_pImage->SetImage(pBmp,FALSE);
+ pImgObj->CalcBoundingBox();
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp
index d9cbbe4733..3f22b56b48 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -1,316 +1,316 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-// #include "x:/pdf/fpdfapi5/include/fpdfapi.h"
-#include "../include/fsdk_define.h"
-#include "../include/fpdfedit.h"
-
-
-#if _FX_OS_ == _FX_ANDROID_
-#include "time.h"
-#else
-#include <ctime>
-#endif
-
-DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument()
-{
- CPDF_Document* pDoc = FX_NEW CPDF_Document;
- if (!pDoc)
- return NULL;
- pDoc->CreateNewDoc();
- time_t currentTime;
-
- CFX_ByteString DateStr;
-
- if(FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
- {
- if ( -1 != time( &currentTime ) )
- {
- tm * pTM = localtime( &currentTime );
- if ( pTM )
- {
- DateStr.Format( "D:%04d%02d%02d%02d%02d%02d", pTM->tm_year+1900, pTM->tm_mon+1,
- pTM->tm_mday, pTM->tm_hour, pTM->tm_min, pTM->tm_sec );
- }
- }
- }
-
- CPDF_Dictionary* pInfoDict = NULL;
- pInfoDict = pDoc->GetInfo();
- if (pInfoDict)
- {
- if(FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
- pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr));
-#ifdef FOXIT_CHROME_BUILD
- pInfoDict->SetAt("Creator",FX_NEW CPDF_String(L"Google"));
-#else
- pInfoDict->SetAt("Creator",FX_NEW CPDF_String(L"Foxit PDF SDK DLL 2.0 - Foxit Software"));
-#endif
- }
-
- return pDoc;
-}
-
-DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index)
-{
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if (pDoc == NULL)
- return;
- if (page_index < 0 || page_index >= pDoc->GetPageCount())
- return;
-
- pDoc->DeletePage(page_index);
-}
-
-DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, int page_index, double width, double height)
-{
- if (!document)
- return NULL;
-
-// CPDF_Parser* pParser = (CPDF_Parser*)document;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if(page_index < 0)
- page_index = 0;
- if(pDoc->GetPageCount()<page_index)
- page_index = pDoc->GetPageCount();
-// if (page_index < 0 || page_index >= pDoc->GetPageCount())
-// return NULL;
-
- CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
- if(!pPageDict)
- return NULL;
- CPDF_Array* pMediaBoxArray = FX_NEW CPDF_Array;
- pMediaBoxArray->Add(FX_NEW CPDF_Number(0));
- pMediaBoxArray->Add(FX_NEW CPDF_Number(0));
- pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(width)));
- pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(height)));
-
- pPageDict->SetAt("MediaBox", pMediaBoxArray);
- pPageDict->SetAt("Rotate", FX_NEW CPDF_Number(0));
- pPageDict->SetAt("Resources", FX_NEW CPDF_Dictionary);
-
- CPDF_Page* pPage = FX_NEW CPDF_Page;
- pPage->Load(pDoc,pPageDict);
- pPage->ParseContent();
-
- return pPage;
-}
-
-DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page)
-{
- CPDF_Page* pPage = (CPDF_Page*)page;
- if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
- || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
- {
- return -1;
- }
- CPDF_Dictionary* pDict = pPage->m_pFormDict;
-
- int rotate = 0;
- if(pDict != NULL)
- {
- if(pDict->KeyExist("Rotate"))
- rotate = pDict->GetElement("Rotate")->GetDirect()->GetInteger() / 90;
- else
- {
- if(pDict->KeyExist("Parent"))
- {
- CPDF_Dictionary* pPages = (CPDF_Dictionary*)pDict->GetElement("Parent")->GetDirect();
- while(pPages)
- {
- if(pPages->KeyExist("Rotate"))
- {
- rotate = pPages->GetElement("Rotate")->GetDirect()->GetInteger() / 90;
- break;
- }
- else if(pPages->KeyExist("Parent"))
- pPages = (CPDF_Dictionary*)pPages->GetElement("Parent")->GetDirect();
- else break;
- }
- }
- }
- }
- else
- {
- return -1;
- }
-
- return rotate;
-}
-
-DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_obj)
-{
- CPDF_Page* pPage = (CPDF_Page*)page;
- if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
- || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
- {
- return;
- }
- CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj;
- if(pPageObj == NULL)
- return;
- FX_POSITION LastPersition = pPage->GetLastObjectPosition();
-
- pPage->InsertObject(LastPersition, pPageObj);
- switch(pPageObj->m_Type)
- {
- case FPDF_PAGEOBJ_PATH:
- {
- CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj;
- pPathObj->CalcBoundingBox();
- break;
- }
- case FPDF_PAGEOBJ_TEXT:
- {
- // CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj;
- // pPathObj->CalcBoundingBox();
- break;
- }
- case FPDF_PAGEOBJ_IMAGE:
- {
- CPDF_ImageObject* pImageObj = (CPDF_ImageObject*)pPageObj;
- pImageObj->CalcBoundingBox();
- break;
- }
- case FPDF_PAGEOBJ_SHADING:
- {
- CPDF_ShadingObject* pShadingObj = (CPDF_ShadingObject*)pPageObj;
- pShadingObj->CalcBoundingBox();
- break;
- }
- case FPDF_PAGEOBJ_FORM:
- {
- CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj;
- pFormObj->CalcBoundingBox();
- break;
- }
- default:
- break;
- }
-
- // pPage->ParseContent();
- //pPage->GenerateContent();
-
-}
-
-DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page)
-{
- CPDF_Page* pPage = (CPDF_Page*)page;
- if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
- || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
- {
- return -1;
- }
- return pPage->CountObjects();
-// return 0;
-}
-
-DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, int index)
-{
- CPDF_Page* pPage = (CPDF_Page*)page;
- if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
- || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
- {
- return NULL;
- }
- return pPage->GetObjectByIndex(index);
-// return NULL;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page)
-{
- if(!page) return FALSE;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
- return pPage->BackgroundAlphaNeeded();
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject)
-{
- if(!pageObject) return FALSE;
- CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject;
-
- const CPDF_GeneralStateData* pGeneralState = pPageObj->m_GeneralState;
- int blend_type = pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL;
- if (blend_type != FXDIB_BLEND_NORMAL) return TRUE;
-
- CPDF_Dictionary* pSMaskDict = pGeneralState ? (CPDF_Dictionary*)pGeneralState->m_pSoftMask : NULL;
- if(pSMaskDict) return TRUE;
-
- if(pGeneralState && pGeneralState->m_FillAlpha != 1.0f)
- return TRUE;
-
- if(pPageObj->m_Type == PDFPAGE_PATH)
- {
- if(pGeneralState && pGeneralState->m_StrokeAlpha != 1.0f)
- return TRUE;
- }
-
- if(pPageObj->m_Type == PDFPAGE_FORM)
- {
- CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj;
- if(pFormObj->m_pForm && (pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED))
- return TRUE;
- if(pFormObj->m_pForm && (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) && (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP)))
- return TRUE;
- }
- return FALSE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page)
-{
- CPDF_Page* pPage = (CPDF_Page*)page;
- if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
- || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
- {
- return FALSE;
- }
- CPDF_PageContentGenerate CG(pPage);
- CG.GenerateContent();
-
- return TRUE;
-}
-
-DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
- double a, double b, double c, double d, double e, double f)
-{
- CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object;
- if(pPageObj == NULL)
- return;
-//PDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;
- CFX_AffineMatrix matrix((FX_FLOAT)a,(FX_FLOAT)b,(FX_FLOAT)c,(FX_FLOAT)d,(FX_FLOAT)e,(FX_FLOAT)f);
- pPageObj->Transform(matrix);
-}
-DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
- double a, double b, double c, double d, double e, double f)
-{
- if(page == NULL)
- return;
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDF_AnnotList AnnotList(pPage);
- for (int i=0; i<AnnotList.Count();i++)
- {
- CPDF_Annot* pAnnot = AnnotList.GetAt(i);
- // transformAnnots Rectangle
- CPDF_Rect rect;
- pAnnot->GetRect(rect);
- CFX_AffineMatrix matrix((FX_FLOAT)a,(FX_FLOAT)b,(FX_FLOAT)c,(FX_FLOAT)d,(FX_FLOAT)e,(FX_FLOAT)f);
- rect.Transform(&matrix);
- CPDF_Array *pRectArray = NULL;
- pRectArray = pAnnot->m_pAnnotDict->GetArray("Rect");
- if (!pRectArray) pRectArray=CPDF_Array::Create();
- pRectArray->SetAt(0,FX_NEW CPDF_Number(rect.left));
- pRectArray->SetAt(1,FX_NEW CPDF_Number(rect.bottom));
- pRectArray->SetAt(2,FX_NEW CPDF_Number(rect.right));
- pRectArray->SetAt(3,FX_NEW CPDF_Number(rect.top));
- pAnnot->m_pAnnotDict->SetAt("Rect",pRectArray);
-
- //Transform AP's rectangle
- //To Do
-
- }
-
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+// #include "x:/pdf/fpdfapi5/include/fpdfapi.h"
+#include "../include/fsdk_define.h"
+#include "../include/fpdfedit.h"
+
+
+#if _FX_OS_ == _FX_ANDROID_
+#include "time.h"
+#else
+#include <ctime>
+#endif
+
+DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument()
+{
+ CPDF_Document* pDoc = FX_NEW CPDF_Document;
+ if (!pDoc)
+ return NULL;
+ pDoc->CreateNewDoc();
+ time_t currentTime;
+
+ CFX_ByteString DateStr;
+
+ if(FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
+ {
+ if ( -1 != time( &currentTime ) )
+ {
+ tm * pTM = localtime( &currentTime );
+ if ( pTM )
+ {
+ DateStr.Format( "D:%04d%02d%02d%02d%02d%02d", pTM->tm_year+1900, pTM->tm_mon+1,
+ pTM->tm_mday, pTM->tm_hour, pTM->tm_min, pTM->tm_sec );
+ }
+ }
+ }
+
+ CPDF_Dictionary* pInfoDict = NULL;
+ pInfoDict = pDoc->GetInfo();
+ if (pInfoDict)
+ {
+ if(FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
+ pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr));
+#ifdef FOXIT_CHROME_BUILD
+ pInfoDict->SetAt("Creator",FX_NEW CPDF_String(L"Google"));
+#else
+ pInfoDict->SetAt("Creator",FX_NEW CPDF_String(L"Foxit PDF SDK DLL 2.0 - Foxit Software"));
+#endif
+ }
+
+ return pDoc;
+}
+
+DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index)
+{
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ if (pDoc == NULL)
+ return;
+ if (page_index < 0 || page_index >= pDoc->GetPageCount())
+ return;
+
+ pDoc->DeletePage(page_index);
+}
+
+DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, int page_index, double width, double height)
+{
+ if (!document)
+ return NULL;
+
+// CPDF_Parser* pParser = (CPDF_Parser*)document;
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ if(page_index < 0)
+ page_index = 0;
+ if(pDoc->GetPageCount()<page_index)
+ page_index = pDoc->GetPageCount();
+// if (page_index < 0 || page_index >= pDoc->GetPageCount())
+// return NULL;
+
+ CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
+ if(!pPageDict)
+ return NULL;
+ CPDF_Array* pMediaBoxArray = FX_NEW CPDF_Array;
+ pMediaBoxArray->Add(FX_NEW CPDF_Number(0));
+ pMediaBoxArray->Add(FX_NEW CPDF_Number(0));
+ pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(width)));
+ pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(height)));
+
+ pPageDict->SetAt("MediaBox", pMediaBoxArray);
+ pPageDict->SetAt("Rotate", FX_NEW CPDF_Number(0));
+ pPageDict->SetAt("Resources", FX_NEW CPDF_Dictionary);
+
+ CPDF_Page* pPage = FX_NEW CPDF_Page;
+ pPage->Load(pDoc,pPageDict);
+ pPage->ParseContent();
+
+ return pPage;
+}
+
+DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page)
+{
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
+ || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
+ {
+ return -1;
+ }
+ CPDF_Dictionary* pDict = pPage->m_pFormDict;
+
+ int rotate = 0;
+ if(pDict != NULL)
+ {
+ if(pDict->KeyExist("Rotate"))
+ rotate = pDict->GetElement("Rotate")->GetDirect()->GetInteger() / 90;
+ else
+ {
+ if(pDict->KeyExist("Parent"))
+ {
+ CPDF_Dictionary* pPages = (CPDF_Dictionary*)pDict->GetElement("Parent")->GetDirect();
+ while(pPages)
+ {
+ if(pPages->KeyExist("Rotate"))
+ {
+ rotate = pPages->GetElement("Rotate")->GetDirect()->GetInteger() / 90;
+ break;
+ }
+ else if(pPages->KeyExist("Parent"))
+ pPages = (CPDF_Dictionary*)pPages->GetElement("Parent")->GetDirect();
+ else break;
+ }
+ }
+ }
+ }
+ else
+ {
+ return -1;
+ }
+
+ return rotate;
+}
+
+DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_obj)
+{
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
+ || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
+ {
+ return;
+ }
+ CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj;
+ if(pPageObj == NULL)
+ return;
+ FX_POSITION LastPersition = pPage->GetLastObjectPosition();
+
+ pPage->InsertObject(LastPersition, pPageObj);
+ switch(pPageObj->m_Type)
+ {
+ case FPDF_PAGEOBJ_PATH:
+ {
+ CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj;
+ pPathObj->CalcBoundingBox();
+ break;
+ }
+ case FPDF_PAGEOBJ_TEXT:
+ {
+ // CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj;
+ // pPathObj->CalcBoundingBox();
+ break;
+ }
+ case FPDF_PAGEOBJ_IMAGE:
+ {
+ CPDF_ImageObject* pImageObj = (CPDF_ImageObject*)pPageObj;
+ pImageObj->CalcBoundingBox();
+ break;
+ }
+ case FPDF_PAGEOBJ_SHADING:
+ {
+ CPDF_ShadingObject* pShadingObj = (CPDF_ShadingObject*)pPageObj;
+ pShadingObj->CalcBoundingBox();
+ break;
+ }
+ case FPDF_PAGEOBJ_FORM:
+ {
+ CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj;
+ pFormObj->CalcBoundingBox();
+ break;
+ }
+ default:
+ break;
+ }
+
+ // pPage->ParseContent();
+ //pPage->GenerateContent();
+
+}
+
+DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page)
+{
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
+ || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
+ {
+ return -1;
+ }
+ return pPage->CountObjects();
+// return 0;
+}
+
+DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, int index)
+{
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
+ || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
+ {
+ return NULL;
+ }
+ return pPage->GetObjectByIndex(index);
+// return NULL;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page)
+{
+ if(!page) return FALSE;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+ return pPage->BackgroundAlphaNeeded();
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject)
+{
+ if(!pageObject) return FALSE;
+ CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject;
+
+ const CPDF_GeneralStateData* pGeneralState = pPageObj->m_GeneralState;
+ int blend_type = pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL;
+ if (blend_type != FXDIB_BLEND_NORMAL) return TRUE;
+
+ CPDF_Dictionary* pSMaskDict = pGeneralState ? (CPDF_Dictionary*)pGeneralState->m_pSoftMask : NULL;
+ if(pSMaskDict) return TRUE;
+
+ if(pGeneralState && pGeneralState->m_FillAlpha != 1.0f)
+ return TRUE;
+
+ if(pPageObj->m_Type == PDFPAGE_PATH)
+ {
+ if(pGeneralState && pGeneralState->m_StrokeAlpha != 1.0f)
+ return TRUE;
+ }
+
+ if(pPageObj->m_Type == PDFPAGE_FORM)
+ {
+ CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj;
+ if(pFormObj->m_pForm && (pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED))
+ return TRUE;
+ if(pFormObj->m_pForm && (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) && (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP)))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page)
+{
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
+ || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
+ {
+ return FALSE;
+ }
+ CPDF_PageContentGenerate CG(pPage);
+ CG.GenerateContent();
+
+ return TRUE;
+}
+
+DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
+ double a, double b, double c, double d, double e, double f)
+{
+ CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object;
+ if(pPageObj == NULL)
+ return;
+//PDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;
+ CFX_AffineMatrix matrix((FX_FLOAT)a,(FX_FLOAT)b,(FX_FLOAT)c,(FX_FLOAT)d,(FX_FLOAT)e,(FX_FLOAT)f);
+ pPageObj->Transform(matrix);
+}
+DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
+ double a, double b, double c, double d, double e, double f)
+{
+ if(page == NULL)
+ return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_AnnotList AnnotList(pPage);
+ for (int i=0; i<AnnotList.Count();i++)
+ {
+ CPDF_Annot* pAnnot = AnnotList.GetAt(i);
+ // transformAnnots Rectangle
+ CPDF_Rect rect;
+ pAnnot->GetRect(rect);
+ CFX_AffineMatrix matrix((FX_FLOAT)a,(FX_FLOAT)b,(FX_FLOAT)c,(FX_FLOAT)d,(FX_FLOAT)e,(FX_FLOAT)f);
+ rect.Transform(&matrix);
+ CPDF_Array *pRectArray = NULL;
+ pRectArray = pAnnot->m_pAnnotDict->GetArray("Rect");
+ if (!pRectArray) pRectArray=CPDF_Array::Create();
+ pRectArray->SetAt(0,FX_NEW CPDF_Number(rect.left));
+ pRectArray->SetAt(1,FX_NEW CPDF_Number(rect.bottom));
+ pRectArray->SetAt(2,FX_NEW CPDF_Number(rect.right));
+ pRectArray->SetAt(3,FX_NEW CPDF_Number(rect.top));
+ pAnnot->m_pAnnotDict->SetAt("Rect",pRectArray);
+
+ //Transform AP's rectangle
+ //To Do
+
+ }
+
+}
diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp
index 101146b099..2de76033fe 100644
--- a/fpdfsdk/src/fpdfformfill.cpp
+++ b/fpdfsdk/src/fpdfformfill.cpp
@@ -1,441 +1,441 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fpdfview.h"
-#include "../include/fpdfformfill.h"
-#include "../include/fsdk_define.h"
-#include "../include/fsdk_mgr.h"
-
-
-#include "../include/javascript/IJavaScript.h"
-
-
-DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page,double page_x, double page_y)
-{
- if(!page || !hHandle)
- return -1;
- CPDF_Page * pPage = (CPDF_Page*) page;
-
- CPDF_InterForm * pInterForm = NULL;
- pInterForm = new CPDF_InterForm(pPage->m_pDocument,FALSE);
- if (!pInterForm)
- return -1;
- CPDF_FormControl* pFormCtrl = pInterForm->GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y);
- if(!pFormCtrl)
- {
- delete pInterForm;
- return -1;
- }
- CPDF_FormField* pFormField = pFormCtrl->GetField();
- if(!pFormField)
- {
- delete pInterForm;
- return -1;
- }
-
- int nType = pFormField->GetFieldType();
- delete pInterForm;
- return nType;
-}
-
-DLLEXPORT FPDF_FORMHANDLE STDCALL FPDFDOC_InitFormFillEnviroument(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo)
-{
- if(!document || !formInfo || formInfo->version!=1)
- return NULL;
- CPDF_Document * pDocument = (CPDF_Document*) document;
- CPDFDoc_Environment * pEnv = NULL;
- pEnv = new CPDFDoc_Environment(pDocument);
- if (!pEnv)
- return NULL;
- pEnv->RegAppHandle(formInfo);
-
- if(pEnv->GetPDFDocument())
- {
- CPDFSDK_Document* pSDKDoc = new CPDFSDK_Document(pEnv->GetPDFDocument(), pEnv);
- if(pSDKDoc)
- pEnv->SetCurrentDoc(pSDKDoc);
- }
- return pEnv;
-}
-
-DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnviroument(FPDF_FORMHANDLE hHandle)
-{
- if(!hHandle)
- return;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(pSDKDoc)
- {
- ((CPDFDoc_Environment*)hHandle)->SetCurrentDoc(NULL);
- delete pSDKDoc;
- }
- delete (CPDFDoc_Environment*)hHandle;
- hHandle = NULL;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
-{
- if (!hHandle || !page)
- return FALSE;
-// CPDF_Page * pPage = (CPDF_Page*) page;
-// CPDF_Document * pDoc = pPage->m_pDocument;
-// CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
- CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(!pFXDoc)
- return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
- if(!pPageView)
- return FALSE;
-
-// double page_x = 0;
-// double page_y = 0;
-// pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);
- CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
- return pPageView->OnMouseMove(pt, modifier);
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
-{
- if (!hHandle || !page)
- return FALSE;
- CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(!pFXDoc)
- return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
- if(!pPageView)
- return FALSE;
-// double page_x = 0;
-// double page_y = 0;
-// pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);
- CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
- return pPageView->OnLButtonDown(pt, modifier);
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
-{
- if (!hHandle || !page)
- return FALSE;
- CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(!pFXDoc)
- return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
- if(!pPageView)
- return FALSE;
-// double page_x = 0;
-// double page_y = 0;
-// pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);
- CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
- return pPageView->OnLButtonUp(pt, modifier);
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, int modifier)
-{
- if (!hHandle || !page)
- return FALSE;
- CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(!pFXDoc)
- return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
- if(!pPageView)
- return FALSE;
-
-
- return pPageView->OnKeyDown(nKeyCode, modifier);
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, int modifier)
-{
- if (!hHandle || !page)
- return FALSE;
- CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(!pFXDoc)
- return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
- if(!pPageView)
- return FALSE;
-
-
- return pPageView->OnKeyUp(nKeyCode, modifier);
-}
-
-
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nChar, int modifier)
-{
- if (!hHandle || !page)
- return FALSE;
- CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(!pFXDoc)
- return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
- if(!pPageView)
- return FALSE;
- return pPageView->OnChar(nChar, modifier);
-
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle)
-{
- if(!hHandle)
- return FALSE;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(!pSDKDoc)
- return FALSE;
- //Kill the current focus.
- return pSDKDoc->KillFocusAnnot(0);
-}
-
-DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y,
- int size_x, int size_y, int rotate, int flags)
-{
- if (!hHandle || !page)
- return ;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
- CPDF_RenderOptions options;
- if (flags & FPDF_LCD_TEXT)
- options.m_Flags |= RENDER_CLEARTYPE;
- else
- options.m_Flags &= ~RENDER_CLEARTYPE;
-
- //Grayscale output
- if (flags & FPDF_GRAYSCALE)
- {
- options.m_ColorMode = RENDER_COLOR_GRAY;
- options.m_ForeColor = 0;
- options.m_BackColor = 0xffffff;
- }
-
- options.m_AddFlags = flags >> 8;
-
- options.m_pOCContext = FX_NEW CPDF_OCContext(pPage->m_pDocument);
-
- //FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
-
- CFX_AffineMatrix matrix;
- pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
-
- FX_RECT clip;
- clip.left = start_x;
- clip.right = start_x + size_x;
- clip.top = start_y;
- clip.bottom = start_y + size_y;
-
-#ifdef _SKIA_SUPPORT_
- CFX_SkiaDevice* pDevice = FX_NEW CFX_SkiaDevice;
-#else
- CFX_FxgeDevice* pDevice = NULL;
- pDevice = FX_NEW CFX_FxgeDevice;
-#endif
-
- if (!pDevice)
- return;
- pDevice->Attach((CFX_DIBitmap*)bitmap);
- pDevice->SaveState();
- pDevice->SetClip_Rect(&clip);
-
-
- CPDF_RenderContext* pContext = NULL;
- pContext = FX_NEW CPDF_RenderContext;
- if (!pContext)
- {
- delete pDevice;
- pDevice = NULL;
- return;
- }
-
-
-// CPDF_Document* pDoc = pPage->m_pDocument;
- CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
- CPDFSDK_Document* pFXDoc = pEnv->GetCurrentDoc();
- if(!pFXDoc)
- {
- delete pContext;
- delete pDevice;
- pContext = NULL;
- pDevice = NULL;
- return;
- }
- if(CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage))
- {
- pPageView->PageView_OnDraw(pDevice, &matrix, &options);
- }
- pDevice->RestoreState();
-
- if(options.m_pOCContext)
- {
- delete options.m_pOCContext;
- options.m_pOCContext = NULL;
- }
- if(pContext)
- {
- delete pContext;
- pContext = NULL;
- }
- if(pDevice)
- {
- delete pDevice;
- pDevice = NULL;
- }
-
-}
-
-DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, int fieldType, unsigned long color)
-{
- if (!hHandle)
- return;
-// CPDFDoc_Environment* pEnv = (CPDFDoc_Environment* )hHandle;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(pSDKDoc)
- {
- if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())
- {
- pInterForm->SetHighlightColor(color, fieldType);
- }
-
- }
-
-}
-
-DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha)
-{
- if (!hHandle)
- return;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(pSDKDoc)
- {
- if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())
- pInterForm->SetHighlightAlpha(alpha);
- }
-}
-
-DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle)
-{
- if (!hHandle)
- return;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(pSDKDoc)
- {
- if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())
- pInterForm->RemoveAllHighLight();
- }
-}
-
-DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)
-{
- if(!hHandle || !page)
- return;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(!pSDKDoc)
- return;
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, TRUE);
- if(pPageView)
- {
- pPageView->SetValid(TRUE);
- }
-}
-
-DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)
-{
- if(!hHandle || !page)
- return;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
- if(pPageView)
- {
- pPageView->SetValid(FALSE);
- // ReMovePageView() takes care of the delete for us.
- pSDKDoc->ReMovePageView(pPage);
- }
-}
-DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle)
-{
- if(!hHandle)
- return;
- if( CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc())
- {
- pSDKDoc->InitPageView();
- if(((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
- pSDKDoc->ProcJavascriptFun();
- }
-}
-
-DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle)
-{
- if(!hHandle)
- return;
- if( CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc())
- {
- if(((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
- pSDKDoc->ProcOpenAction();
- }
-}
-DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, int aaType)
-{
- if(!hHandle)
- return;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(pSDKDoc)
- {
- CPDF_Document* pDoc = pSDKDoc->GetDocument();
- CPDF_Dictionary* pDic = pDoc->GetRoot();
- if (!pDic)
- return;
- CPDF_AAction aa = pDic->GetDict(FX_BSTRC("AA"));
-
- if(aa.ActionExist((CPDF_AAction::AActionType)aaType))
- {
- CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);
- CPDFSDK_ActionHandler *pActionHandler = ((CPDFDoc_Environment*)hHandle)->GetActionHander();
- ASSERT(pActionHandler != NULL);
- pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, pSDKDoc);
- }
- }
-}
-DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandle, int aaType)
-{
- if(!hHandle || !page)
- return;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
- if(pPageView)
- {
- CPDFDoc_Environment *pEnv = pSDKDoc->GetEnv();
- ASSERT(pEnv != NULL);
-
- CPDFSDK_ActionHandler *pActionHandler = pEnv->GetActionHander();
- ASSERT(pActionHandler != NULL);
-
- CPDF_Dictionary *pPageDict = pPage->m_pFormDict;
- ASSERT(pPageDict != NULL);
-
- CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA"));
-
- FX_BOOL bExistOAAction = FALSE;
- FX_BOOL bExistCAAction = FALSE;
- if (FPDFPAGE_AACTION_OPEN == aaType)
- {
- bExistOAAction = aa.ActionExist(CPDF_AAction::OpenPage);
- if (bExistOAAction)
- {
- CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);
- pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc);
- }
- }
- else
- {
- bExistCAAction = aa.ActionExist(CPDF_AAction::ClosePage);
- if (bExistCAAction)
- {
- CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);
- pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc);
- }
- }
- }
-}
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fpdfview.h"
+#include "../include/fpdfformfill.h"
+#include "../include/fsdk_define.h"
+#include "../include/fsdk_mgr.h"
+
+
+#include "../include/javascript/IJavaScript.h"
+
+
+DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page,double page_x, double page_y)
+{
+ if(!page || !hHandle)
+ return -1;
+ CPDF_Page * pPage = (CPDF_Page*) page;
+
+ CPDF_InterForm * pInterForm = NULL;
+ pInterForm = new CPDF_InterForm(pPage->m_pDocument,FALSE);
+ if (!pInterForm)
+ return -1;
+ CPDF_FormControl* pFormCtrl = pInterForm->GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y);
+ if(!pFormCtrl)
+ {
+ delete pInterForm;
+ return -1;
+ }
+ CPDF_FormField* pFormField = pFormCtrl->GetField();
+ if(!pFormField)
+ {
+ delete pInterForm;
+ return -1;
+ }
+
+ int nType = pFormField->GetFieldType();
+ delete pInterForm;
+ return nType;
+}
+
+DLLEXPORT FPDF_FORMHANDLE STDCALL FPDFDOC_InitFormFillEnviroument(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo)
+{
+ if(!document || !formInfo || formInfo->version!=1)
+ return NULL;
+ CPDF_Document * pDocument = (CPDF_Document*) document;
+ CPDFDoc_Environment * pEnv = NULL;
+ pEnv = new CPDFDoc_Environment(pDocument);
+ if (!pEnv)
+ return NULL;
+ pEnv->RegAppHandle(formInfo);
+
+ if(pEnv->GetPDFDocument())
+ {
+ CPDFSDK_Document* pSDKDoc = new CPDFSDK_Document(pEnv->GetPDFDocument(), pEnv);
+ if(pSDKDoc)
+ pEnv->SetCurrentDoc(pSDKDoc);
+ }
+ return pEnv;
+}
+
+DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnviroument(FPDF_FORMHANDLE hHandle)
+{
+ if(!hHandle)
+ return;
+ CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(pSDKDoc)
+ {
+ ((CPDFDoc_Environment*)hHandle)->SetCurrentDoc(NULL);
+ delete pSDKDoc;
+ }
+ delete (CPDFDoc_Environment*)hHandle;
+ hHandle = NULL;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
+{
+ if (!hHandle || !page)
+ return FALSE;
+// CPDF_Page * pPage = (CPDF_Page*) page;
+// CPDF_Document * pDoc = pPage->m_pDocument;
+// CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
+ CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pFXDoc)
+ return FALSE;
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ if(!pPageView)
+ return FALSE;
+
+// double page_x = 0;
+// double page_y = 0;
+// pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);
+ CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
+ return pPageView->OnMouseMove(pt, modifier);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
+{
+ if (!hHandle || !page)
+ return FALSE;
+ CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pFXDoc)
+ return FALSE;
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ if(!pPageView)
+ return FALSE;
+// double page_x = 0;
+// double page_y = 0;
+// pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);
+ CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
+ return pPageView->OnLButtonDown(pt, modifier);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
+{
+ if (!hHandle || !page)
+ return FALSE;
+ CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pFXDoc)
+ return FALSE;
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ if(!pPageView)
+ return FALSE;
+// double page_x = 0;
+// double page_y = 0;
+// pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);
+ CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
+ return pPageView->OnLButtonUp(pt, modifier);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, int modifier)
+{
+ if (!hHandle || !page)
+ return FALSE;
+ CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pFXDoc)
+ return FALSE;
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ if(!pPageView)
+ return FALSE;
+
+
+ return pPageView->OnKeyDown(nKeyCode, modifier);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, int modifier)
+{
+ if (!hHandle || !page)
+ return FALSE;
+ CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pFXDoc)
+ return FALSE;
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ if(!pPageView)
+ return FALSE;
+
+
+ return pPageView->OnKeyUp(nKeyCode, modifier);
+}
+
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nChar, int modifier)
+{
+ if (!hHandle || !page)
+ return FALSE;
+ CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pFXDoc)
+ return FALSE;
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ if(!pPageView)
+ return FALSE;
+ return pPageView->OnChar(nChar, modifier);
+
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle)
+{
+ if(!hHandle)
+ return FALSE;
+ CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pSDKDoc)
+ return FALSE;
+ //Kill the current focus.
+ return pSDKDoc->KillFocusAnnot(0);
+}
+
+DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y,
+ int size_x, int size_y, int rotate, int flags)
+{
+ if (!hHandle || !page)
+ return ;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+ CPDF_RenderOptions options;
+ if (flags & FPDF_LCD_TEXT)
+ options.m_Flags |= RENDER_CLEARTYPE;
+ else
+ options.m_Flags &= ~RENDER_CLEARTYPE;
+
+ //Grayscale output
+ if (flags & FPDF_GRAYSCALE)
+ {
+ options.m_ColorMode = RENDER_COLOR_GRAY;
+ options.m_ForeColor = 0;
+ options.m_BackColor = 0xffffff;
+ }
+
+ options.m_AddFlags = flags >> 8;
+
+ options.m_pOCContext = FX_NEW CPDF_OCContext(pPage->m_pDocument);
+
+ //FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
+
+ CFX_AffineMatrix matrix;
+ pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
+
+ FX_RECT clip;
+ clip.left = start_x;
+ clip.right = start_x + size_x;
+ clip.top = start_y;
+ clip.bottom = start_y + size_y;
+
+#ifdef _SKIA_SUPPORT_
+ CFX_SkiaDevice* pDevice = FX_NEW CFX_SkiaDevice;
+#else
+ CFX_FxgeDevice* pDevice = NULL;
+ pDevice = FX_NEW CFX_FxgeDevice;
+#endif
+
+ if (!pDevice)
+ return;
+ pDevice->Attach((CFX_DIBitmap*)bitmap);
+ pDevice->SaveState();
+ pDevice->SetClip_Rect(&clip);
+
+
+ CPDF_RenderContext* pContext = NULL;
+ pContext = FX_NEW CPDF_RenderContext;
+ if (!pContext)
+ {
+ delete pDevice;
+ pDevice = NULL;
+ return;
+ }
+
+
+// CPDF_Document* pDoc = pPage->m_pDocument;
+ CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
+ CPDFSDK_Document* pFXDoc = pEnv->GetCurrentDoc();
+ if(!pFXDoc)
+ {
+ delete pContext;
+ delete pDevice;
+ pContext = NULL;
+ pDevice = NULL;
+ return;
+ }
+ if(CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage))
+ {
+ pPageView->PageView_OnDraw(pDevice, &matrix, &options);
+ }
+ pDevice->RestoreState();
+
+ if(options.m_pOCContext)
+ {
+ delete options.m_pOCContext;
+ options.m_pOCContext = NULL;
+ }
+ if(pContext)
+ {
+ delete pContext;
+ pContext = NULL;
+ }
+ if(pDevice)
+ {
+ delete pDevice;
+ pDevice = NULL;
+ }
+
+}
+
+DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, int fieldType, unsigned long color)
+{
+ if (!hHandle)
+ return;
+// CPDFDoc_Environment* pEnv = (CPDFDoc_Environment* )hHandle;
+ CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(pSDKDoc)
+ {
+ if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())
+ {
+ pInterForm->SetHighlightColor(color, fieldType);
+ }
+
+ }
+
+}
+
+DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha)
+{
+ if (!hHandle)
+ return;
+ CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(pSDKDoc)
+ {
+ if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())
+ pInterForm->SetHighlightAlpha(alpha);
+ }
+}
+
+DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle)
+{
+ if (!hHandle)
+ return;
+ CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(pSDKDoc)
+ {
+ if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())
+ pInterForm->RemoveAllHighLight();
+ }
+}
+
+DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)
+{
+ if(!hHandle || !page)
+ return;
+ CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pSDKDoc)
+ return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, TRUE);
+ if(pPageView)
+ {
+ pPageView->SetValid(TRUE);
+ }
+}
+
+DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)
+{
+ if(!hHandle || !page)
+ return;
+ CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
+ if(pPageView)
+ {
+ pPageView->SetValid(FALSE);
+ // ReMovePageView() takes care of the delete for us.
+ pSDKDoc->ReMovePageView(pPage);
+ }
+}
+DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle)
+{
+ if(!hHandle)
+ return;
+ if( CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc())
+ {
+ pSDKDoc->InitPageView();
+ if(((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
+ pSDKDoc->ProcJavascriptFun();
+ }
+}
+
+DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle)
+{
+ if(!hHandle)
+ return;
+ if( CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc())
+ {
+ if(((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
+ pSDKDoc->ProcOpenAction();
+ }
+}
+DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, int aaType)
+{
+ if(!hHandle)
+ return;
+ CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(pSDKDoc)
+ {
+ CPDF_Document* pDoc = pSDKDoc->GetDocument();
+ CPDF_Dictionary* pDic = pDoc->GetRoot();
+ if (!pDic)
+ return;
+ CPDF_AAction aa = pDic->GetDict(FX_BSTRC("AA"));
+
+ if(aa.ActionExist((CPDF_AAction::AActionType)aaType))
+ {
+ CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);
+ CPDFSDK_ActionHandler *pActionHandler = ((CPDFDoc_Environment*)hHandle)->GetActionHander();
+ ASSERT(pActionHandler != NULL);
+ pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, pSDKDoc);
+ }
+ }
+}
+DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandle, int aaType)
+{
+ if(!hHandle || !page)
+ return;
+ CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
+ if(pPageView)
+ {
+ CPDFDoc_Environment *pEnv = pSDKDoc->GetEnv();
+ ASSERT(pEnv != NULL);
+
+ CPDFSDK_ActionHandler *pActionHandler = pEnv->GetActionHander();
+ ASSERT(pActionHandler != NULL);
+
+ CPDF_Dictionary *pPageDict = pPage->m_pFormDict;
+ ASSERT(pPageDict != NULL);
+
+ CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA"));
+
+ FX_BOOL bExistOAAction = FALSE;
+ FX_BOOL bExistCAAction = FALSE;
+ if (FPDFPAGE_AACTION_OPEN == aaType)
+ {
+ bExistOAAction = aa.ActionExist(CPDF_AAction::OpenPage);
+ if (bExistOAAction)
+ {
+ CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);
+ pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc);
+ }
+ }
+ else
+ {
+ bExistCAAction = aa.ActionExist(CPDF_AAction::ClosePage);
+ if (bExistCAAction)
+ {
+ CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);
+ pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc);
+ }
+ }
+ }
+}
+
+
diff --git a/fpdfsdk/src/fpdfoom.cpp b/fpdfsdk/src/fpdfoom.cpp
index fb67a5a1fe..9ba983b942 100644
--- a/fpdfsdk/src/fpdfoom.cpp
+++ b/fpdfsdk/src/fpdfoom.cpp
@@ -1,27 +1,27 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdfoom.h"
-
-void OOM_Handler(FXMEM_FoxitMgr* pFoxitMgr, void* param)
-{
- if (!param) return;
- ((OOM_INFO*)param)->FSDK_OOM_Handler((OOM_INFO*)param);
-}
-
-
-DLLEXPORT FX_BOOL STDCALL FSDK_SetOOMHandler(OOM_INFO* oomInfo)
-{
-#ifndef _FXSDK_OPENSOURCE_
- if (!oomInfo || oomInfo->version!=1)
- return FALSE;
- FXMEM_SetOOMHandler(FXMEM_GetDefaultMgr(),OOM_Handler,oomInfo);
- return TRUE;
-#else
- return TRUE;
-#endif
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdfoom.h"
+
+void OOM_Handler(FXMEM_FoxitMgr* pFoxitMgr, void* param)
+{
+ if (!param) return;
+ ((OOM_INFO*)param)->FSDK_OOM_Handler((OOM_INFO*)param);
+}
+
+
+DLLEXPORT FX_BOOL STDCALL FSDK_SetOOMHandler(OOM_INFO* oomInfo)
+{
+#ifndef _FXSDK_OPENSOURCE_
+ if (!oomInfo || oomInfo->version!=1)
+ return FALSE;
+ FXMEM_SetOOMHandler(FXMEM_GetDefaultMgr(),OOM_Handler,oomInfo);
+ return TRUE;
+#else
+ return TRUE;
+#endif
+}
diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp
index e605484cb3..a803454cc0 100644
--- a/fpdfsdk/src/fpdfppo.cpp
+++ b/fpdfsdk/src/fpdfppo.cpp
@@ -1,460 +1,460 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fpdfppo.h"
-#include "../include/fsdk_define.h"
-
-class CPDF_PageOrganizer
-{
-public:
- CPDF_PageOrganizer();
- ~CPDF_PageOrganizer();
-
-public:
- FX_BOOL PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document *pSrcPDFDoc);
- FX_BOOL ExportPage(CPDF_Document *pSrcPDFDoc, CFX_WordArray* nPageNum, CPDF_Document *pDestPDFDoc, int nIndex);
- CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary *pDict, CFX_ByteString nSrctag);
- FX_BOOL UpdateReference(CPDF_Object *pObj, CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr);
- int GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr, CPDF_Reference *pRef);
-
-};
-
-
-CPDF_PageOrganizer::CPDF_PageOrganizer()
-{
-
-}
-
-CPDF_PageOrganizer::~CPDF_PageOrganizer()
-{
-
-}
-
-FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document *pSrcPDFDoc)
-{
- if(!pDestPDFDoc || !pSrcPDFDoc)
- return false;
-
- CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot();
- if(!pNewRoot) return FALSE;
-
- //Set the document information////////////////////////////////////////////
-
- CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo();
-
- if(!DInfoDict)
- return FALSE;
-
- CFX_ByteString producerstr;
-
-#ifdef FOXIT_CHROME_BUILD
- producerstr.Format("Google");
-#else
- producerstr.Format("Foxit PDF SDK %s - Foxit Corporation", "2.0");
-#endif
- DInfoDict->SetAt("Producer", new CPDF_String(producerstr));
-
- //Set type////////////////////////////////////////////////////////////////
- CFX_ByteString cbRootType = pNewRoot->GetString("Type","");
- if( cbRootType.Equal("") )
- {
- pNewRoot->SetAt("Type", new CPDF_Name("Catalog"));
- }
-
- CPDF_Dictionary* pNewPages = (CPDF_Dictionary*)pNewRoot->GetElement("Pages")->GetDirect();
- if(!pNewPages)
- {
- pNewPages = new CPDF_Dictionary;
- FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
- pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON));
- }
-
- CFX_ByteString cbPageType = pNewPages->GetString("Type","");
- if(cbPageType.Equal(""))
- {
- pNewPages->SetAt("Type", new CPDF_Name("Pages"));
- }
-
- CPDF_Array* pKeysArray = pNewPages->GetArray("Kids");
- if(pKeysArray == NULL)
- {
- CPDF_Array* pNewKids = new CPDF_Array;
- FX_DWORD Kidsobjnum = -1;
- Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids);//, Kidsobjnum, Kidsgennum);
-
- pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum));//, Kidsgennum));
- pNewPages->SetAt("Count", new CPDF_Number(0));
- }
-
- return true;
-}
-
-FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document *pSrcPDFDoc, CFX_WordArray* nPageNum,
- CPDF_Document *pDestPDFDoc,int nIndex)
-{
- int curpage =nIndex;
-
- CFX_MapPtrToPtr* pMapPtrToPtr = new CFX_MapPtrToPtr;
- pMapPtrToPtr->InitHashTable(1001);
-
- for(int i=0; i<nPageNum->GetSize(); i++)
- {
-
- CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage);
- CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i)-1);
- if(!pSrcPageDict || !pCurPageDict)
- {
- delete pMapPtrToPtr;
- return FALSE;
- }
-
- // Clone the page dictionary///////////
- FX_POSITION SrcPos = pSrcPageDict->GetStartPos();
- while (SrcPos)
- {
- CFX_ByteString cbSrcKeyStr;
- CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, cbSrcKeyStr);
- if(cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent")))
- {
- if(pCurPageDict->KeyExist(cbSrcKeyStr))
- pCurPageDict->RemoveAt(cbSrcKeyStr);
- pCurPageDict->SetAt(cbSrcKeyStr, pObj->Clone());
- }
- }
-
- //inheritable item///////////////////////
- CPDF_Object* pInheritable = NULL;
- //1 MediaBox //required
- if(!pCurPageDict->KeyExist("MediaBox"))
- {
-
- pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox");
- if(!pInheritable)
- {
- //Search the "CropBox" from source page dictionary, if not exists,we take the letter size.
- pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox");
- if(pInheritable)
- pCurPageDict->SetAt("MediaBox", pInheritable->Clone());
- else
- {
- //Make the default size to be letter size (8.5'x11')
- CPDF_Array* pArray = new CPDF_Array;
- pArray->AddNumber(0);
- pArray->AddNumber(0);
- pArray->AddNumber(612);
- pArray->AddNumber(792);
- pCurPageDict->SetAt("MediaBox", pArray);
- }
- }
- else
- pCurPageDict->SetAt("MediaBox", pInheritable->Clone());
- }
- //2 Resources //required
- if(!pCurPageDict->KeyExist("Resources"))
- {
- pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources");
- if(!pInheritable)
- {
- delete pMapPtrToPtr;
- return FALSE;
- }
- pCurPageDict->SetAt("Resources", pInheritable->Clone());
- }
- //3 CropBox //Optional
- if(!pCurPageDict->KeyExist("CropBox"))
- {
- pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox");
- if(pInheritable)
- pCurPageDict->SetAt("CropBox", pInheritable->Clone());
- }
- //4 Rotate //Optional
- if(!pCurPageDict->KeyExist("Rotate"))
- {
- pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate");
- if(pInheritable)
- pCurPageDict->SetAt("Rotate", pInheritable->Clone());
- }
-
- /////////////////////////////////////////////
- //Update the reference
- FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum();
- FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum();
-
- pMapPtrToPtr->SetAt((FX_LPVOID)(FX_UINTPTR)dwOldPageObj, (FX_LPVOID)(FX_UINTPTR)dwNewPageObj);
-
- this->UpdateReference(pCurPageDict, pDestPDFDoc, pMapPtrToPtr);
- curpage++;
- }
-
- delete pMapPtrToPtr;
- return TRUE;
-}
-
-CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(CPDF_Dictionary *pDict, CFX_ByteString nSrctag)
-{
- if(!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty())
- return NULL;
-
- CPDF_Object* pType = pDict->GetElement("Type")->GetDirect();
- if(!pType || pType->GetType() != PDFOBJ_NAME) return NULL;
-
- if(pType->GetString().Compare("Page")) return NULL;
-
- if(!pDict->KeyExist("Parent")) return NULL;
- CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect();
- if(!pParent || pParent->GetType() != PDFOBJ_DICTIONARY) return NULL;
-
- CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent;
-
- if(pDict->KeyExist((const char*)nSrctag))
- return pDict->GetElement((const char*)nSrctag);
- while (pp)
- {
- if(pp->KeyExist((const char*)nSrctag))
- return pp->GetElement((const char*)nSrctag);
- else if(pp->KeyExist("Parent"))
- pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect();
- else break;
- }
-
- return NULL;
-}
-
-FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object *pObj, CPDF_Document *pDoc,
- CFX_MapPtrToPtr* pMapPtrToPtr)
-{
- switch (pObj->GetType())
- {
- case PDFOBJ_REFERENCE:
- {
- CPDF_Reference* pReference = (CPDF_Reference*)pObj;
- int newobjnum = GetNewObjId(pDoc, pMapPtrToPtr, pReference);
- if (newobjnum == 0) return FALSE;
- pReference->SetRef(pDoc, newobjnum);//, 0);
- break;
- }
- case PDFOBJ_DICTIONARY:
- {
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
-
- FX_POSITION pos = pDict->GetStartPos();
- while(pos)
- {
- CFX_ByteString key("");
- CPDF_Object* pNextObj = pDict->GetNextElement(pos, key);
- if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || !FXSYS_strcmp(key, "First"))
- continue;
- if(pNextObj)
- {
- if(!UpdateReference(pNextObj, pDoc, pMapPtrToPtr))
- pDict->RemoveAt(key);
- }
- else
- return FALSE;
- }
- break;
- }
- case PDFOBJ_ARRAY:
- {
- CPDF_Array* pArray = (CPDF_Array*)pObj;
- FX_DWORD count = pArray->GetCount();
- for(FX_DWORD i = 0; i < count; i ++)
- {
- CPDF_Object* pNextObj = pArray->GetElement(i);
- if(pNextObj)
- {
- if(!UpdateReference(pNextObj, pDoc, pMapPtrToPtr))
- return FALSE;
- }
- else
- return FALSE;
- }
- break;
- }
- case PDFOBJ_STREAM:
- {
- CPDF_Stream* pStream = (CPDF_Stream*)pObj;
- CPDF_Dictionary* pDict = pStream->GetDict();
- if(pDict)
- {
- if(!UpdateReference(pDict, pDoc, pMapPtrToPtr))
- return FALSE;
- }
- else
- return FALSE;
- break;
- }
- default: break;
- }
-
- return TRUE;
-}
-
-int CPDF_PageOrganizer::GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr,
- CPDF_Reference *pRef)
-{
- size_t dwObjnum = 0;
- if(!pRef)
- return 0;
- dwObjnum = pRef->GetRefObjNum();
-
- size_t dwNewObjNum = 0;
-
- pMapPtrToPtr->Lookup((FX_LPVOID)dwObjnum, (FX_LPVOID&)dwNewObjNum);
- if(dwNewObjNum)
- {
- return (int)dwNewObjNum;
- }
- else
- {
- CPDF_Object* pClone = pRef->GetDirect()->Clone();
- if(!pClone) return 0;
-
- if(pClone->GetType() == PDFOBJ_DICTIONARY)
- {
- CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone;
- if(pDictClone->KeyExist("Type"))
- {
- CFX_ByteString strType = pDictClone->GetString("Type");
- if(!FXSYS_stricmp(strType, "Pages"))
- {
- pDictClone->Release();
- return 4;
- }
- else if(!FXSYS_stricmp(strType, "Page"))
- {
- pDictClone->Release();
- return 0;
- }
- }
- }
- dwNewObjNum = pDoc->AddIndirectObject(pClone);//, onum, gnum);
- pMapPtrToPtr->SetAt((FX_LPVOID)dwObjnum, (FX_LPVOID)dwNewObjNum);
-
- if(!UpdateReference(pClone, pDoc, pMapPtrToPtr))
- {
- pClone->Release();
- return 0;
- }
- return (int)dwNewObjNum;
- }
- return 0;
-}
-
-FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, CFX_WordArray* pageArray,int nCount)
-{
-
- if(rangstring.GetLength() != 0)
- {
- rangstring.Remove(' ');
- int nLength = rangstring.GetLength();
- CFX_ByteString cbCompareString("0123456789-,");
- for(int i=0; i<nLength; i++)
- {
- if(cbCompareString.Find(rangstring[i]) == -1)
- return FALSE;
- }
- CFX_ByteString cbMidRange;
- int nStringFrom = 0;
- int nStringTo=0;
- while(nStringTo < nLength)
- {
- nStringTo = rangstring.Find(',',nStringFrom);
- if(nStringTo == -1)
- {
- nStringTo = nLength;
- }
- cbMidRange = rangstring.Mid(nStringFrom,nStringTo-nStringFrom);
-
- int nMid = cbMidRange.Find('-');
- if(nMid == -1)
- {
- long lPageNum = atol(cbMidRange);
- if(lPageNum <= 0 || lPageNum > nCount)
- return FALSE;
- pageArray->Add((FX_WORD)lPageNum);
- }
- else
- {
- int nStartPageNum = atol(cbMidRange.Mid(0,nMid));
- if (nStartPageNum ==0)
- {
- return FALSE;
- }
-
-
- nMid = nMid+1;
- int nEnd = cbMidRange.GetLength()-nMid;
-
- if(nEnd ==0)return FALSE;
-
- // int nEndPageNum = (nEnd == 0)?nCount:atol(cbMidRange.Mid(nMid,nEnd));
- int nEndPageNum = atol(cbMidRange.Mid(nMid,nEnd));
-
- if(nStartPageNum < 0 ||nStartPageNum >nEndPageNum|| nEndPageNum > nCount)
- {
- return FALSE;
- }
- else
- {
- for(int nIndex=nStartPageNum; nIndex <= nEndPageNum; nIndex ++)
- pageArray->Add(nIndex);
- }
- }
- nStringFrom = nStringTo +1;
- }
- }
- return TRUE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,FPDF_DOCUMENT src_doc,
- FPDF_BYTESTRING pagerange, int index)
-{
- if(dest_doc == NULL || src_doc == NULL )
- return FALSE;
- CFX_WordArray pageArray;
- CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc;
- int nCount = pSrcDoc->GetPageCount();
- if(pagerange)
- {
- if(ParserPageRangeString(pagerange,&pageArray,nCount) == FALSE)
- return FALSE;
- }
- else
- {
- for(int i=1; i<=nCount; i++)
- {
- pageArray.Add(i);
- }
- }
-
- CPDF_Document* pDestDoc = (CPDF_Document*)dest_doc;
- CPDF_PageOrganizer pageOrg;
-
- pageOrg.PDFDocInit(pDestDoc,pSrcDoc);
-
- if(pageOrg.ExportPage(pSrcDoc,&pageArray,pDestDoc,index))
- return TRUE;
- return FALSE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, FPDF_DOCUMENT src_doc)
-{
- if(src_doc == NULL || dest_doc == NULL)
- return false;
- CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc;
- CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot();
- pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences"));;
- if(!pSrcDict)
- return FALSE;
- CPDF_Document* pDstDoc = (CPDF_Document*)dest_doc;
- CPDF_Dictionary* pDstDict = pDstDoc->GetRoot();
- if(!pDstDict)
- return FALSE;
- pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE));
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fpdfppo.h"
+#include "../include/fsdk_define.h"
+
+class CPDF_PageOrganizer
+{
+public:
+ CPDF_PageOrganizer();
+ ~CPDF_PageOrganizer();
+
+public:
+ FX_BOOL PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document *pSrcPDFDoc);
+ FX_BOOL ExportPage(CPDF_Document *pSrcPDFDoc, CFX_WordArray* nPageNum, CPDF_Document *pDestPDFDoc, int nIndex);
+ CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary *pDict, CFX_ByteString nSrctag);
+ FX_BOOL UpdateReference(CPDF_Object *pObj, CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr);
+ int GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr, CPDF_Reference *pRef);
+
+};
+
+
+CPDF_PageOrganizer::CPDF_PageOrganizer()
+{
+
+}
+
+CPDF_PageOrganizer::~CPDF_PageOrganizer()
+{
+
+}
+
+FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document *pSrcPDFDoc)
+{
+ if(!pDestPDFDoc || !pSrcPDFDoc)
+ return false;
+
+ CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot();
+ if(!pNewRoot) return FALSE;
+
+ //Set the document information////////////////////////////////////////////
+
+ CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo();
+
+ if(!DInfoDict)
+ return FALSE;
+
+ CFX_ByteString producerstr;
+
+#ifdef FOXIT_CHROME_BUILD
+ producerstr.Format("Google");
+#else
+ producerstr.Format("Foxit PDF SDK %s - Foxit Corporation", "2.0");
+#endif
+ DInfoDict->SetAt("Producer", new CPDF_String(producerstr));
+
+ //Set type////////////////////////////////////////////////////////////////
+ CFX_ByteString cbRootType = pNewRoot->GetString("Type","");
+ if( cbRootType.Equal("") )
+ {
+ pNewRoot->SetAt("Type", new CPDF_Name("Catalog"));
+ }
+
+ CPDF_Dictionary* pNewPages = (CPDF_Dictionary*)pNewRoot->GetElement("Pages")->GetDirect();
+ if(!pNewPages)
+ {
+ pNewPages = new CPDF_Dictionary;
+ FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
+ pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON));
+ }
+
+ CFX_ByteString cbPageType = pNewPages->GetString("Type","");
+ if(cbPageType.Equal(""))
+ {
+ pNewPages->SetAt("Type", new CPDF_Name("Pages"));
+ }
+
+ CPDF_Array* pKeysArray = pNewPages->GetArray("Kids");
+ if(pKeysArray == NULL)
+ {
+ CPDF_Array* pNewKids = new CPDF_Array;
+ FX_DWORD Kidsobjnum = -1;
+ Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids);//, Kidsobjnum, Kidsgennum);
+
+ pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum));//, Kidsgennum));
+ pNewPages->SetAt("Count", new CPDF_Number(0));
+ }
+
+ return true;
+}
+
+FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document *pSrcPDFDoc, CFX_WordArray* nPageNum,
+ CPDF_Document *pDestPDFDoc,int nIndex)
+{
+ int curpage =nIndex;
+
+ CFX_MapPtrToPtr* pMapPtrToPtr = new CFX_MapPtrToPtr;
+ pMapPtrToPtr->InitHashTable(1001);
+
+ for(int i=0; i<nPageNum->GetSize(); i++)
+ {
+
+ CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage);
+ CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i)-1);
+ if(!pSrcPageDict || !pCurPageDict)
+ {
+ delete pMapPtrToPtr;
+ return FALSE;
+ }
+
+ // Clone the page dictionary///////////
+ FX_POSITION SrcPos = pSrcPageDict->GetStartPos();
+ while (SrcPos)
+ {
+ CFX_ByteString cbSrcKeyStr;
+ CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, cbSrcKeyStr);
+ if(cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent")))
+ {
+ if(pCurPageDict->KeyExist(cbSrcKeyStr))
+ pCurPageDict->RemoveAt(cbSrcKeyStr);
+ pCurPageDict->SetAt(cbSrcKeyStr, pObj->Clone());
+ }
+ }
+
+ //inheritable item///////////////////////
+ CPDF_Object* pInheritable = NULL;
+ //1 MediaBox //required
+ if(!pCurPageDict->KeyExist("MediaBox"))
+ {
+
+ pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox");
+ if(!pInheritable)
+ {
+ //Search the "CropBox" from source page dictionary, if not exists,we take the letter size.
+ pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox");
+ if(pInheritable)
+ pCurPageDict->SetAt("MediaBox", pInheritable->Clone());
+ else
+ {
+ //Make the default size to be letter size (8.5'x11')
+ CPDF_Array* pArray = new CPDF_Array;
+ pArray->AddNumber(0);
+ pArray->AddNumber(0);
+ pArray->AddNumber(612);
+ pArray->AddNumber(792);
+ pCurPageDict->SetAt("MediaBox", pArray);
+ }
+ }
+ else
+ pCurPageDict->SetAt("MediaBox", pInheritable->Clone());
+ }
+ //2 Resources //required
+ if(!pCurPageDict->KeyExist("Resources"))
+ {
+ pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources");
+ if(!pInheritable)
+ {
+ delete pMapPtrToPtr;
+ return FALSE;
+ }
+ pCurPageDict->SetAt("Resources", pInheritable->Clone());
+ }
+ //3 CropBox //Optional
+ if(!pCurPageDict->KeyExist("CropBox"))
+ {
+ pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox");
+ if(pInheritable)
+ pCurPageDict->SetAt("CropBox", pInheritable->Clone());
+ }
+ //4 Rotate //Optional
+ if(!pCurPageDict->KeyExist("Rotate"))
+ {
+ pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate");
+ if(pInheritable)
+ pCurPageDict->SetAt("Rotate", pInheritable->Clone());
+ }
+
+ /////////////////////////////////////////////
+ //Update the reference
+ FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum();
+ FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum();
+
+ pMapPtrToPtr->SetAt((FX_LPVOID)(FX_UINTPTR)dwOldPageObj, (FX_LPVOID)(FX_UINTPTR)dwNewPageObj);
+
+ this->UpdateReference(pCurPageDict, pDestPDFDoc, pMapPtrToPtr);
+ curpage++;
+ }
+
+ delete pMapPtrToPtr;
+ return TRUE;
+}
+
+CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(CPDF_Dictionary *pDict, CFX_ByteString nSrctag)
+{
+ if(!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty())
+ return NULL;
+
+ CPDF_Object* pType = pDict->GetElement("Type")->GetDirect();
+ if(!pType || pType->GetType() != PDFOBJ_NAME) return NULL;
+
+ if(pType->GetString().Compare("Page")) return NULL;
+
+ if(!pDict->KeyExist("Parent")) return NULL;
+ CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect();
+ if(!pParent || pParent->GetType() != PDFOBJ_DICTIONARY) return NULL;
+
+ CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent;
+
+ if(pDict->KeyExist((const char*)nSrctag))
+ return pDict->GetElement((const char*)nSrctag);
+ while (pp)
+ {
+ if(pp->KeyExist((const char*)nSrctag))
+ return pp->GetElement((const char*)nSrctag);
+ else if(pp->KeyExist("Parent"))
+ pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect();
+ else break;
+ }
+
+ return NULL;
+}
+
+FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object *pObj, CPDF_Document *pDoc,
+ CFX_MapPtrToPtr* pMapPtrToPtr)
+{
+ switch (pObj->GetType())
+ {
+ case PDFOBJ_REFERENCE:
+ {
+ CPDF_Reference* pReference = (CPDF_Reference*)pObj;
+ int newobjnum = GetNewObjId(pDoc, pMapPtrToPtr, pReference);
+ if (newobjnum == 0) return FALSE;
+ pReference->SetRef(pDoc, newobjnum);//, 0);
+ break;
+ }
+ case PDFOBJ_DICTIONARY:
+ {
+ CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
+
+ FX_POSITION pos = pDict->GetStartPos();
+ while(pos)
+ {
+ CFX_ByteString key("");
+ CPDF_Object* pNextObj = pDict->GetNextElement(pos, key);
+ if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || !FXSYS_strcmp(key, "First"))
+ continue;
+ if(pNextObj)
+ {
+ if(!UpdateReference(pNextObj, pDoc, pMapPtrToPtr))
+ pDict->RemoveAt(key);
+ }
+ else
+ return FALSE;
+ }
+ break;
+ }
+ case PDFOBJ_ARRAY:
+ {
+ CPDF_Array* pArray = (CPDF_Array*)pObj;
+ FX_DWORD count = pArray->GetCount();
+ for(FX_DWORD i = 0; i < count; i ++)
+ {
+ CPDF_Object* pNextObj = pArray->GetElement(i);
+ if(pNextObj)
+ {
+ if(!UpdateReference(pNextObj, pDoc, pMapPtrToPtr))
+ return FALSE;
+ }
+ else
+ return FALSE;
+ }
+ break;
+ }
+ case PDFOBJ_STREAM:
+ {
+ CPDF_Stream* pStream = (CPDF_Stream*)pObj;
+ CPDF_Dictionary* pDict = pStream->GetDict();
+ if(pDict)
+ {
+ if(!UpdateReference(pDict, pDoc, pMapPtrToPtr))
+ return FALSE;
+ }
+ else
+ return FALSE;
+ break;
+ }
+ default: break;
+ }
+
+ return TRUE;
+}
+
+int CPDF_PageOrganizer::GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr,
+ CPDF_Reference *pRef)
+{
+ size_t dwObjnum = 0;
+ if(!pRef)
+ return 0;
+ dwObjnum = pRef->GetRefObjNum();
+
+ size_t dwNewObjNum = 0;
+
+ pMapPtrToPtr->Lookup((FX_LPVOID)dwObjnum, (FX_LPVOID&)dwNewObjNum);
+ if(dwNewObjNum)
+ {
+ return (int)dwNewObjNum;
+ }
+ else
+ {
+ CPDF_Object* pClone = pRef->GetDirect()->Clone();
+ if(!pClone) return 0;
+
+ if(pClone->GetType() == PDFOBJ_DICTIONARY)
+ {
+ CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone;
+ if(pDictClone->KeyExist("Type"))
+ {
+ CFX_ByteString strType = pDictClone->GetString("Type");
+ if(!FXSYS_stricmp(strType, "Pages"))
+ {
+ pDictClone->Release();
+ return 4;
+ }
+ else if(!FXSYS_stricmp(strType, "Page"))
+ {
+ pDictClone->Release();
+ return 0;
+ }
+ }
+ }
+ dwNewObjNum = pDoc->AddIndirectObject(pClone);//, onum, gnum);
+ pMapPtrToPtr->SetAt((FX_LPVOID)dwObjnum, (FX_LPVOID)dwNewObjNum);
+
+ if(!UpdateReference(pClone, pDoc, pMapPtrToPtr))
+ {
+ pClone->Release();
+ return 0;
+ }
+ return (int)dwNewObjNum;
+ }
+ return 0;
+}
+
+FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, CFX_WordArray* pageArray,int nCount)
+{
+
+ if(rangstring.GetLength() != 0)
+ {
+ rangstring.Remove(' ');
+ int nLength = rangstring.GetLength();
+ CFX_ByteString cbCompareString("0123456789-,");
+ for(int i=0; i<nLength; i++)
+ {
+ if(cbCompareString.Find(rangstring[i]) == -1)
+ return FALSE;
+ }
+ CFX_ByteString cbMidRange;
+ int nStringFrom = 0;
+ int nStringTo=0;
+ while(nStringTo < nLength)
+ {
+ nStringTo = rangstring.Find(',',nStringFrom);
+ if(nStringTo == -1)
+ {
+ nStringTo = nLength;
+ }
+ cbMidRange = rangstring.Mid(nStringFrom,nStringTo-nStringFrom);
+
+ int nMid = cbMidRange.Find('-');
+ if(nMid == -1)
+ {
+ long lPageNum = atol(cbMidRange);
+ if(lPageNum <= 0 || lPageNum > nCount)
+ return FALSE;
+ pageArray->Add((FX_WORD)lPageNum);
+ }
+ else
+ {
+ int nStartPageNum = atol(cbMidRange.Mid(0,nMid));
+ if (nStartPageNum ==0)
+ {
+ return FALSE;
+ }
+
+
+ nMid = nMid+1;
+ int nEnd = cbMidRange.GetLength()-nMid;
+
+ if(nEnd ==0)return FALSE;
+
+ // int nEndPageNum = (nEnd == 0)?nCount:atol(cbMidRange.Mid(nMid,nEnd));
+ int nEndPageNum = atol(cbMidRange.Mid(nMid,nEnd));
+
+ if(nStartPageNum < 0 ||nStartPageNum >nEndPageNum|| nEndPageNum > nCount)
+ {
+ return FALSE;
+ }
+ else
+ {
+ for(int nIndex=nStartPageNum; nIndex <= nEndPageNum; nIndex ++)
+ pageArray->Add(nIndex);
+ }
+ }
+ nStringFrom = nStringTo +1;
+ }
+ }
+ return TRUE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,FPDF_DOCUMENT src_doc,
+ FPDF_BYTESTRING pagerange, int index)
+{
+ if(dest_doc == NULL || src_doc == NULL )
+ return FALSE;
+ CFX_WordArray pageArray;
+ CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc;
+ int nCount = pSrcDoc->GetPageCount();
+ if(pagerange)
+ {
+ if(ParserPageRangeString(pagerange,&pageArray,nCount) == FALSE)
+ return FALSE;
+ }
+ else
+ {
+ for(int i=1; i<=nCount; i++)
+ {
+ pageArray.Add(i);
+ }
+ }
+
+ CPDF_Document* pDestDoc = (CPDF_Document*)dest_doc;
+ CPDF_PageOrganizer pageOrg;
+
+ pageOrg.PDFDocInit(pDestDoc,pSrcDoc);
+
+ if(pageOrg.ExportPage(pSrcDoc,&pageArray,pDestDoc,index))
+ return TRUE;
+ return FALSE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, FPDF_DOCUMENT src_doc)
+{
+ if(src_doc == NULL || dest_doc == NULL)
+ return false;
+ CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc;
+ CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot();
+ pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences"));;
+ if(!pSrcDict)
+ return FALSE;
+ CPDF_Document* pDstDoc = (CPDF_Document*)dest_doc;
+ CPDF_Dictionary* pDstDict = pDstDoc->GetRoot();
+ if(!pDstDict)
+ return FALSE;
+ pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE));
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/fpdfsave.cpp b/fpdfsdk/src/fpdfsave.cpp
index 8272eb0fee..0c7acc8c47 100644
--- a/fpdfsdk/src/fpdfsave.cpp
+++ b/fpdfsdk/src/fpdfsave.cpp
@@ -1,91 +1,91 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdfsave.h"
-#include "../include/fpdfedit.h"
-#if _FX_OS_ == _FX_ANDROID_
-#include "time.h"
-#else
-#include <ctime>
-#endif
-
-class CFX_IFileWrite:public IFX_StreamWrite
-{
-
-public:
- CFX_IFileWrite();
- FX_BOOL Init( FPDF_FILEWRITE * pFileWriteStruct );
- virtual FX_BOOL WriteBlock(const void* pData, size_t size);
- virtual void Release(){};
-
-protected:
- FPDF_FILEWRITE* m_pFileWriteStruct;
-};
-
-CFX_IFileWrite::CFX_IFileWrite()
-{
- m_pFileWriteStruct = NULL;
-}
-
-FX_BOOL CFX_IFileWrite::Init( FPDF_FILEWRITE * pFileWriteStruct )
-{
- if (!pFileWriteStruct)
- return FALSE;
- else
- {
- m_pFileWriteStruct = pFileWriteStruct;
- }
- return TRUE;
-}
-
-FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size)
-{
- if (m_pFileWriteStruct)
- {
- m_pFileWriteStruct->WriteBlock( m_pFileWriteStruct, pData, size );
- return TRUE;
- }
- else
- return FALSE;
-}
-
-FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,FPDF_DWORD flags, FPDF_BOOL bSetVersion,
- int fileVerion)
-{
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if (!pDoc)
- return 0;
-
- if ( flags < 1 || flags > 2 )
- {
- flags = 0;
- }
-
- CPDF_Creator FileMaker(pDoc);
- if(bSetVersion)
- FileMaker.SetFileVersion(fileVerion);
- CFX_IFileWrite* pStreamWrite = NULL;
- FX_BOOL bRet;
- pStreamWrite = new CFX_IFileWrite;
- pStreamWrite->Init( pFileWrite );
- bRet = FileMaker.Create(pStreamWrite, flags);
- delete pStreamWrite;
- return bRet;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy( FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,
- FPDF_DWORD flags )
-{
- return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE , 0);
-}
-
-
-DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion( FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,
- FPDF_DWORD flags, int fileVersion)
-{
- return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE , fileVersion);
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdfsave.h"
+#include "../include/fpdfedit.h"
+#if _FX_OS_ == _FX_ANDROID_
+#include "time.h"
+#else
+#include <ctime>
+#endif
+
+class CFX_IFileWrite:public IFX_StreamWrite
+{
+
+public:
+ CFX_IFileWrite();
+ FX_BOOL Init( FPDF_FILEWRITE * pFileWriteStruct );
+ virtual FX_BOOL WriteBlock(const void* pData, size_t size);
+ virtual void Release(){};
+
+protected:
+ FPDF_FILEWRITE* m_pFileWriteStruct;
+};
+
+CFX_IFileWrite::CFX_IFileWrite()
+{
+ m_pFileWriteStruct = NULL;
+}
+
+FX_BOOL CFX_IFileWrite::Init( FPDF_FILEWRITE * pFileWriteStruct )
+{
+ if (!pFileWriteStruct)
+ return FALSE;
+ else
+ {
+ m_pFileWriteStruct = pFileWriteStruct;
+ }
+ return TRUE;
+}
+
+FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size)
+{
+ if (m_pFileWriteStruct)
+ {
+ m_pFileWriteStruct->WriteBlock( m_pFileWriteStruct, pData, size );
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,FPDF_DWORD flags, FPDF_BOOL bSetVersion,
+ int fileVerion)
+{
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ if (!pDoc)
+ return 0;
+
+ if ( flags < 1 || flags > 2 )
+ {
+ flags = 0;
+ }
+
+ CPDF_Creator FileMaker(pDoc);
+ if(bSetVersion)
+ FileMaker.SetFileVersion(fileVerion);
+ CFX_IFileWrite* pStreamWrite = NULL;
+ FX_BOOL bRet;
+ pStreamWrite = new CFX_IFileWrite;
+ pStreamWrite->Init( pFileWrite );
+ bRet = FileMaker.Create(pStreamWrite, flags);
+ delete pStreamWrite;
+ return bRet;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy( FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,
+ FPDF_DWORD flags )
+{
+ return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE , 0);
+}
+
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion( FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,
+ FPDF_DWORD flags, int fileVersion)
+{
+ return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE , fileVersion);
+}
diff --git a/fpdfsdk/src/fpdfsdkdll.rc b/fpdfsdk/src/fpdfsdkdll.rc
index ee12049847..f203f2e5be 100644
--- a/fpdfsdk/src/fpdfsdkdll.rc
+++ b/fpdfsdk/src/fpdfsdkdll.rc
@@ -1,109 +1,109 @@
-//Microsoft Developer Studio generated resource script.
-//
-#include "resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "afxres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// Chinese (P.R.C.) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
-#ifdef _WIN32
-LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
-#pragma code_page(936)
-#endif //_WIN32
-
-#ifndef _MAC
-/////////////////////////////////////////////////////////////////////////////
-//
-// Version
-//
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION 2,0,0,1705
- PRODUCTVERSION 2,0,0,1705
- FILEFLAGSMASK 0x3fL
-#ifdef _DEBUG
- FILEFLAGS 0x1L
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS 0x40004L
- FILETYPE 0x2L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "080904b0"
- BEGIN
- VALUE "Comments", "Foxit Corporation\0"
- VALUE "CompanyName", "Foxit Corporation\0"
- VALUE "FileDescription", "fpdfsdk\0"
- VALUE "FileVersion", "2, 0, 0, 1705\0"
- VALUE "InternalName", "fpdfsdk\0"
- VALUE "LegalCopyright", "Copyright (C) 2004-2009 Foxit Corporation\0"
- VALUE "LegalTrademarks", "\0"
- VALUE "OriginalFilename", "fpdfsdk.dll\0"
- VALUE "PrivateBuild", "\0"
- VALUE "ProductName", "Foxit PDF SDK DLL\0"
- VALUE "ProductVersion", "2, 0, 0, 1705\0"
- VALUE "SpecialBuild", "\0"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x809, 1200
- END
-END
-
-#endif // !_MAC
-
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE MOVEABLE PURE
-BEGIN
- "resource.h\0"
-END
-
-2 TEXTINCLUDE MOVEABLE PURE
-BEGIN
- "#include ""afxres.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE MOVEABLE PURE
-BEGIN
- "\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-#endif // Chinese (P.R.C.) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
+//Microsoft Developer Studio generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// Chinese (P.R.C.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
+#ifdef _WIN32
+LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
+#pragma code_page(936)
+#endif //_WIN32
+
+#ifndef _MAC
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 2,0,0,1705
+ PRODUCTVERSION 2,0,0,1705
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "080904b0"
+ BEGIN
+ VALUE "Comments", "Foxit Corporation\0"
+ VALUE "CompanyName", "Foxit Corporation\0"
+ VALUE "FileDescription", "fpdfsdk\0"
+ VALUE "FileVersion", "2, 0, 0, 1705\0"
+ VALUE "InternalName", "fpdfsdk\0"
+ VALUE "LegalCopyright", "Copyright (C) 2004-2009 Foxit Corporation\0"
+ VALUE "LegalTrademarks", "\0"
+ VALUE "OriginalFilename", "fpdfsdk.dll\0"
+ VALUE "PrivateBuild", "\0"
+ VALUE "ProductName", "Foxit PDF SDK DLL\0"
+ VALUE "ProductVersion", "2, 0, 0, 1705\0"
+ VALUE "SpecialBuild", "\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x809, 1200
+ END
+END
+
+#endif // !_MAC
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE MOVEABLE PURE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE MOVEABLE PURE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE MOVEABLE PURE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+#endif // Chinese (P.R.C.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/fpdfsdk/src/fpdftext.cpp b/fpdfsdk/src/fpdftext.cpp
index 6042fcc7b1..1aa0542124 100644
--- a/fpdfsdk/src/fpdftext.cpp
+++ b/fpdfsdk/src/fpdftext.cpp
@@ -1,278 +1,278 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdftext.h"
-
-#ifdef _WIN32
-#include <tchar.h>
-#endif
-
- // jabdelmalek: commented out to build on Linux. Not used.
- // extern HANDLE g_hModule;
-
-DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page)
-{
- if (!page) return NULL;
- IPDF_TextPage* textpage=NULL;
- try
- {
- CPDF_ViewerPreferences viewRef(((CPDF_Page*)page)->m_pDocument);
- textpage=IPDF_TextPage::CreateTextPage((CPDF_Page*)page,viewRef.IsDirectionR2L());
- textpage->ParseTextPage();
- }
- catch (...)
- {
- if (textpage)
- delete textpage;
- return NULL;
- }
- return textpage;
-}
-DLLEXPORT void STDCALL FPDFText_ClosePage(FPDF_TEXTPAGE text_page)
-{
- if (text_page){
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
- delete textpage;
- text_page=NULL;
- }
-}
-DLLEXPORT int STDCALL FPDFText_CountChars(FPDF_TEXTPAGE text_page)
-{
- if (!text_page) return -1;
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
- return textpage->CountChars();
-}
-DLLEXPORT unsigned int STDCALL FPDFText_GetUnicode(FPDF_TEXTPAGE text_page, int index)
-{
- if (!text_page) return -1;
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
-
- if (index<0 || index>=textpage->CountChars()) return 0;
-
- FPDF_CHAR_INFO charinfo;
- textpage->GetCharInfo(index,charinfo);
- return charinfo.m_Unicode;
-}
-DLLEXPORT double STDCALL FPDFText_GetFontSize(FPDF_TEXTPAGE text_page, int index)
-{
- if (!text_page) return 0;
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
-
- if (index<0 || index>=textpage->CountChars()) return 0;
-
- FPDF_CHAR_INFO charinfo;
- textpage->GetCharInfo(index,charinfo);
- return charinfo.m_FontSize;
-}
-
-DLLEXPORT void STDCALL FPDFText_GetCharBox(FPDF_TEXTPAGE text_page, int index,double* left,
- double* right, double* bottom, double* top)
-{
- if (!text_page) return;
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
-
- if (index<0 || index>=textpage->CountChars()) return ;
- FPDF_CHAR_INFO charinfo;
- textpage->GetCharInfo(index,charinfo);
- *left=charinfo.m_CharBox.left;
- *right=charinfo.m_CharBox.right;
- *bottom=charinfo.m_CharBox.bottom;
- *top=charinfo.m_CharBox.top;
-}
-
-//select
-DLLEXPORT int STDCALL FPDFText_GetCharIndexAtPos(FPDF_TEXTPAGE text_page,double x,double y,double xTorelance,double yTorelance)
-{
- if (!text_page) return -3;
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
- return textpage->GetIndexAtPos((FX_FLOAT)x,(FX_FLOAT)y,(FX_FLOAT)xTorelance,(FX_FLOAT)yTorelance);
-}
-
-DLLEXPORT int STDCALL FPDFText_GetText(FPDF_TEXTPAGE text_page,int start,int count,unsigned short* result)
-{
- if (!text_page) return 0;
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
-
- if (start>=textpage->CountChars()) return 0;
-
- CFX_WideString str=textpage->GetPageText(start,count);
- if(str.GetLength()>count)
- str = str.Left(count);
-
- CFX_ByteString cbUTF16str = str.UTF16LE_Encode();
- FXSYS_memcpy(result,cbUTF16str.GetBuffer(cbUTF16str.GetLength()),cbUTF16str.GetLength());
- cbUTF16str.ReleaseBuffer(cbUTF16str.GetLength());
-
- return cbUTF16str.GetLength()/sizeof(unsigned short);
-}
-
-DLLEXPORT int STDCALL FPDFText_CountRects(FPDF_TEXTPAGE text_page,int start,int count)
-{
- if (!text_page) return 0;
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
- return textpage->CountRects(start,count);
-
-}
-DLLEXPORT void STDCALL FPDFText_GetRect(FPDF_TEXTPAGE text_page,int rect_index, double* left,double* top,
- double* right, double* bottom)
-{
- if (!text_page) return;
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
- CFX_FloatRect rect;
- textpage->GetRect(rect_index,rect.left,rect.top,rect.right,rect.bottom);
- *left=rect.left;
- *top=rect.top;
- *right=rect.right;
- *bottom=rect.bottom;
-}
-
-DLLEXPORT int STDCALL FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page,double left, double top,
- double right, double bottom,unsigned short* buffer,int buflen)
-{
- if (!text_page) return 0;
- IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
- CFX_FloatRect rect((FX_FLOAT)left,(FX_FLOAT)bottom,(FX_FLOAT)right,(FX_FLOAT)top);
- CFX_WideString str=textpage->GetTextByRect(rect);
-
- if (buflen<=0 || buffer==NULL)
- {
- return str.GetLength();
- }
-
- CFX_ByteString cbUTF16Str = str.UTF16LE_Encode();
- int len = cbUTF16Str.GetLength()/sizeof(unsigned short);
- int size = buflen > len ? len : buflen;
- FXSYS_memcpy(buffer,cbUTF16Str.GetBuffer(size*sizeof(unsigned short)),size*sizeof(unsigned short));
- cbUTF16Str.ReleaseBuffer(size*sizeof(unsigned short));
-
- return size;
-
-}
-
-//Search
-//-1 for end
-DLLEXPORT FPDF_SCHHANDLE STDCALL FPDFText_FindStart(FPDF_TEXTPAGE text_page,FPDF_WIDESTRING findwhat,unsigned long flags,int start_index)
-{
- if (!text_page) return NULL;
- IPDF_TextPageFind* textpageFind=NULL;
- try
- {
- textpageFind=IPDF_TextPageFind::CreatePageFind((IPDF_TextPage*)text_page);
- textpageFind->FindFirst(CFX_WideString::FromUTF16LE(findwhat),flags,start_index);
- }
- catch (...)
- {
- if (textpageFind)
- delete textpageFind;
- return NULL;
- }
- return textpageFind;
-}
-DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindNext(FPDF_SCHHANDLE handle)
-{
- if (!handle) return FALSE;
- IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
- return textpageFind->FindNext();
-}
-DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindPrev(FPDF_SCHHANDLE handle)
-{
- if (!handle) return FALSE;
- IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
- return textpageFind->FindPrev();
-}
-DLLEXPORT int STDCALL FPDFText_GetSchResultIndex(FPDF_SCHHANDLE handle)
-{
- if (!handle) return 0;
- IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
- return textpageFind->GetCurOrder();
-}
-DLLEXPORT int STDCALL FPDFText_GetSchCount(FPDF_SCHHANDLE handle)
-{
- if (!handle) return 0;
- IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
- return textpageFind->GetMatchedCount();
-}
-DLLEXPORT void STDCALL FPDFText_FindClose(FPDF_SCHHANDLE handle)
-{
- if (!handle) return;
- IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
- delete textpageFind;
- handle=NULL;
-}
-
-//web link
-DLLEXPORT FPDF_PAGELINK STDCALL FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page)
-{
- if (!text_page) return NULL;
- IPDF_LinkExtract* pageLink=NULL;
- try
- {
- pageLink=IPDF_LinkExtract::CreateLinkExtract();
- pageLink->ExtractLinks((IPDF_TextPage*)text_page);
- }
- catch (...)
- {
- if (pageLink)
- delete pageLink;
- return NULL;
- }
- return pageLink;
-}
-DLLEXPORT int STDCALL FPDFLink_CountWebLinks(FPDF_PAGELINK link_page)
-{
- if (!link_page) return 0;
- IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
- return pageLink->CountLinks();
-}
-DLLEXPORT int STDCALL FPDFLink_GetURL(FPDF_PAGELINK link_page,int link_index, unsigned short* buffer,int buflen)
-{
- if (!link_page) return 0;
- IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
- CFX_WideString url=pageLink->GetURL(link_index);
-
- CFX_ByteString cbUTF16URL = url.UTF16LE_Encode();
- int len= cbUTF16URL.GetLength()/sizeof(unsigned short);
- if (buffer==NULL || buflen<=0)
- return len;
- int size=len<buflen ? len :buflen;
- if (size>0)
- {
- FXSYS_memcpy(buffer,cbUTF16URL.GetBuffer(size*sizeof(unsigned short)),size*sizeof(unsigned short));
- cbUTF16URL.ReleaseBuffer(size*sizeof(unsigned short));
- }
- return size;
-}
-DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page,int link_index)
-{
- if (!link_page) return 0;
- IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
- CFX_RectArray rectArray;
- pageLink->GetRects(link_index,rectArray);
- return rectArray.GetSize();
-}
-DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page,int link_index, int rect_index, double* left,
- double* top,double* right, double* bottom)
-{
- if (!link_page) return;
- IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
- CFX_RectArray rectArray;
- pageLink->GetRects(link_index,rectArray);
- CFX_FloatRect rect;
- rect=rectArray.GetAt(rect_index);
- *left=rect.left;
- *right=rect.right;
- *top=rect.top;
- *bottom=rect.bottom;
-}
-DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page)
-{
- if (!link_page) return;
- IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
- delete pageLink;
- pageLink =NULL;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdftext.h"
+
+#ifdef _WIN32
+#include <tchar.h>
+#endif
+
+ // jabdelmalek: commented out to build on Linux. Not used.
+ // extern HANDLE g_hModule;
+
+DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page)
+{
+ if (!page) return NULL;
+ IPDF_TextPage* textpage=NULL;
+ try
+ {
+ CPDF_ViewerPreferences viewRef(((CPDF_Page*)page)->m_pDocument);
+ textpage=IPDF_TextPage::CreateTextPage((CPDF_Page*)page,viewRef.IsDirectionR2L());
+ textpage->ParseTextPage();
+ }
+ catch (...)
+ {
+ if (textpage)
+ delete textpage;
+ return NULL;
+ }
+ return textpage;
+}
+DLLEXPORT void STDCALL FPDFText_ClosePage(FPDF_TEXTPAGE text_page)
+{
+ if (text_page){
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+ delete textpage;
+ text_page=NULL;
+ }
+}
+DLLEXPORT int STDCALL FPDFText_CountChars(FPDF_TEXTPAGE text_page)
+{
+ if (!text_page) return -1;
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+ return textpage->CountChars();
+}
+DLLEXPORT unsigned int STDCALL FPDFText_GetUnicode(FPDF_TEXTPAGE text_page, int index)
+{
+ if (!text_page) return -1;
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+
+ if (index<0 || index>=textpage->CountChars()) return 0;
+
+ FPDF_CHAR_INFO charinfo;
+ textpage->GetCharInfo(index,charinfo);
+ return charinfo.m_Unicode;
+}
+DLLEXPORT double STDCALL FPDFText_GetFontSize(FPDF_TEXTPAGE text_page, int index)
+{
+ if (!text_page) return 0;
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+
+ if (index<0 || index>=textpage->CountChars()) return 0;
+
+ FPDF_CHAR_INFO charinfo;
+ textpage->GetCharInfo(index,charinfo);
+ return charinfo.m_FontSize;
+}
+
+DLLEXPORT void STDCALL FPDFText_GetCharBox(FPDF_TEXTPAGE text_page, int index,double* left,
+ double* right, double* bottom, double* top)
+{
+ if (!text_page) return;
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+
+ if (index<0 || index>=textpage->CountChars()) return ;
+ FPDF_CHAR_INFO charinfo;
+ textpage->GetCharInfo(index,charinfo);
+ *left=charinfo.m_CharBox.left;
+ *right=charinfo.m_CharBox.right;
+ *bottom=charinfo.m_CharBox.bottom;
+ *top=charinfo.m_CharBox.top;
+}
+
+//select
+DLLEXPORT int STDCALL FPDFText_GetCharIndexAtPos(FPDF_TEXTPAGE text_page,double x,double y,double xTorelance,double yTorelance)
+{
+ if (!text_page) return -3;
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+ return textpage->GetIndexAtPos((FX_FLOAT)x,(FX_FLOAT)y,(FX_FLOAT)xTorelance,(FX_FLOAT)yTorelance);
+}
+
+DLLEXPORT int STDCALL FPDFText_GetText(FPDF_TEXTPAGE text_page,int start,int count,unsigned short* result)
+{
+ if (!text_page) return 0;
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+
+ if (start>=textpage->CountChars()) return 0;
+
+ CFX_WideString str=textpage->GetPageText(start,count);
+ if(str.GetLength()>count)
+ str = str.Left(count);
+
+ CFX_ByteString cbUTF16str = str.UTF16LE_Encode();
+ FXSYS_memcpy(result,cbUTF16str.GetBuffer(cbUTF16str.GetLength()),cbUTF16str.GetLength());
+ cbUTF16str.ReleaseBuffer(cbUTF16str.GetLength());
+
+ return cbUTF16str.GetLength()/sizeof(unsigned short);
+}
+
+DLLEXPORT int STDCALL FPDFText_CountRects(FPDF_TEXTPAGE text_page,int start,int count)
+{
+ if (!text_page) return 0;
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+ return textpage->CountRects(start,count);
+
+}
+DLLEXPORT void STDCALL FPDFText_GetRect(FPDF_TEXTPAGE text_page,int rect_index, double* left,double* top,
+ double* right, double* bottom)
+{
+ if (!text_page) return;
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+ CFX_FloatRect rect;
+ textpage->GetRect(rect_index,rect.left,rect.top,rect.right,rect.bottom);
+ *left=rect.left;
+ *top=rect.top;
+ *right=rect.right;
+ *bottom=rect.bottom;
+}
+
+DLLEXPORT int STDCALL FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page,double left, double top,
+ double right, double bottom,unsigned short* buffer,int buflen)
+{
+ if (!text_page) return 0;
+ IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
+ CFX_FloatRect rect((FX_FLOAT)left,(FX_FLOAT)bottom,(FX_FLOAT)right,(FX_FLOAT)top);
+ CFX_WideString str=textpage->GetTextByRect(rect);
+
+ if (buflen<=0 || buffer==NULL)
+ {
+ return str.GetLength();
+ }
+
+ CFX_ByteString cbUTF16Str = str.UTF16LE_Encode();
+ int len = cbUTF16Str.GetLength()/sizeof(unsigned short);
+ int size = buflen > len ? len : buflen;
+ FXSYS_memcpy(buffer,cbUTF16Str.GetBuffer(size*sizeof(unsigned short)),size*sizeof(unsigned short));
+ cbUTF16Str.ReleaseBuffer(size*sizeof(unsigned short));
+
+ return size;
+
+}
+
+//Search
+//-1 for end
+DLLEXPORT FPDF_SCHHANDLE STDCALL FPDFText_FindStart(FPDF_TEXTPAGE text_page,FPDF_WIDESTRING findwhat,unsigned long flags,int start_index)
+{
+ if (!text_page) return NULL;
+ IPDF_TextPageFind* textpageFind=NULL;
+ try
+ {
+ textpageFind=IPDF_TextPageFind::CreatePageFind((IPDF_TextPage*)text_page);
+ textpageFind->FindFirst(CFX_WideString::FromUTF16LE(findwhat),flags,start_index);
+ }
+ catch (...)
+ {
+ if (textpageFind)
+ delete textpageFind;
+ return NULL;
+ }
+ return textpageFind;
+}
+DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindNext(FPDF_SCHHANDLE handle)
+{
+ if (!handle) return FALSE;
+ IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
+ return textpageFind->FindNext();
+}
+DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindPrev(FPDF_SCHHANDLE handle)
+{
+ if (!handle) return FALSE;
+ IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
+ return textpageFind->FindPrev();
+}
+DLLEXPORT int STDCALL FPDFText_GetSchResultIndex(FPDF_SCHHANDLE handle)
+{
+ if (!handle) return 0;
+ IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
+ return textpageFind->GetCurOrder();
+}
+DLLEXPORT int STDCALL FPDFText_GetSchCount(FPDF_SCHHANDLE handle)
+{
+ if (!handle) return 0;
+ IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
+ return textpageFind->GetMatchedCount();
+}
+DLLEXPORT void STDCALL FPDFText_FindClose(FPDF_SCHHANDLE handle)
+{
+ if (!handle) return;
+ IPDF_TextPageFind* textpageFind=(IPDF_TextPageFind*)handle;
+ delete textpageFind;
+ handle=NULL;
+}
+
+//web link
+DLLEXPORT FPDF_PAGELINK STDCALL FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page)
+{
+ if (!text_page) return NULL;
+ IPDF_LinkExtract* pageLink=NULL;
+ try
+ {
+ pageLink=IPDF_LinkExtract::CreateLinkExtract();
+ pageLink->ExtractLinks((IPDF_TextPage*)text_page);
+ }
+ catch (...)
+ {
+ if (pageLink)
+ delete pageLink;
+ return NULL;
+ }
+ return pageLink;
+}
+DLLEXPORT int STDCALL FPDFLink_CountWebLinks(FPDF_PAGELINK link_page)
+{
+ if (!link_page) return 0;
+ IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
+ return pageLink->CountLinks();
+}
+DLLEXPORT int STDCALL FPDFLink_GetURL(FPDF_PAGELINK link_page,int link_index, unsigned short* buffer,int buflen)
+{
+ if (!link_page) return 0;
+ IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
+ CFX_WideString url=pageLink->GetURL(link_index);
+
+ CFX_ByteString cbUTF16URL = url.UTF16LE_Encode();
+ int len= cbUTF16URL.GetLength()/sizeof(unsigned short);
+ if (buffer==NULL || buflen<=0)
+ return len;
+ int size=len<buflen ? len :buflen;
+ if (size>0)
+ {
+ FXSYS_memcpy(buffer,cbUTF16URL.GetBuffer(size*sizeof(unsigned short)),size*sizeof(unsigned short));
+ cbUTF16URL.ReleaseBuffer(size*sizeof(unsigned short));
+ }
+ return size;
+}
+DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page,int link_index)
+{
+ if (!link_page) return 0;
+ IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
+ CFX_RectArray rectArray;
+ pageLink->GetRects(link_index,rectArray);
+ return rectArray.GetSize();
+}
+DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page,int link_index, int rect_index, double* left,
+ double* top,double* right, double* bottom)
+{
+ if (!link_page) return;
+ IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
+ CFX_RectArray rectArray;
+ pageLink->GetRects(link_index,rectArray);
+ CFX_FloatRect rect;
+ rect=rectArray.GetAt(rect_index);
+ *left=rect.left;
+ *right=rect.right;
+ *top=rect.top;
+ *bottom=rect.bottom;
+}
+DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page)
+{
+ if (!link_page) return;
+ IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
+ delete pageLink;
+ pageLink =NULL;
+}
+
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index e72e5ab0db..a5ba796158 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -1,879 +1,879 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fpdfview.h"
-#include "../include/fsdk_rendercontext.h"
-#include "../include/fpdf_progressive.h"
-#include "../include/fpdf_ext.h"
-
-
-CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
-{
- m_FileAccess = *pFileAccess;
- m_BufferOffset = (FX_DWORD)-1;
-}
-
-FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch)
-{
- if (pos >= m_FileAccess.m_FileLen) return FALSE;
- if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_BufferOffset + 512) {
- // Need to read from file access
- m_BufferOffset = pos;
- int size = 512;
- if (pos + 512 > m_FileAccess.m_FileLen)
- size = m_FileAccess.m_FileLen - pos;
- if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, size))
- return FALSE;
- }
- ch = m_Buffer[pos - m_BufferOffset];
- return TRUE;
-}
-
-FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size)
-{
- if (pos + size > m_FileAccess.m_FileLen) return FALSE;
- return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size);
-}
-
-FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
-{
- // m_FileAccess = *pFileAccess;
- // m_BufferOffset = (FX_DWORD)-1;
- if (offset + size > m_FileAccess.m_FileLen) return FALSE;
- return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,(FX_LPBYTE) buffer, size);
-
- // return FALSE;
-}
-
-//0 bit: FPDF_POLICY_MACHINETIME_ACCESS
-static FX_DWORD foxit_sandbox_policy = 0xFFFFFFFF;
-
-void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable)
-{
- switch(policy)
- {
- case FPDF_POLICY_MACHINETIME_ACCESS:
- {
- if(enable)
- foxit_sandbox_policy |= 0x01;
- else
- foxit_sandbox_policy &= 0xFFFFFFFE;
- }
- break;
- default:
- break;
- }
-}
-
-FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy)
-{
- switch(policy)
- {
- case FPDF_POLICY_MACHINETIME_ACCESS:
- {
- if(foxit_sandbox_policy&0x01)
- return TRUE;
- else
- return FALSE;
- }
- break;
- default:
- break;
- }
- return FALSE;
-}
-
-
-#ifndef _T
-#define _T(x) x
-#endif
-
-#ifdef API5
- CPDF_ModuleMgr* g_pModuleMgr = NULL;
-#else
- CCodec_ModuleMgr* g_pCodecModule = NULL;
-#ifdef _FXSDK_OPENSOURCE_
- FXMEM_FoxitMgr* g_pFoxitMgr = NULL;
-#endif
-#endif
-
-//extern CPDFSDK_FormFillApp* g_pFormFillApp;
-
-#if _FX_OS_ == _FX_LINUX_EMBEDDED_
-class CFontMapper : public IPDF_FontMapper
-{
-public:
- CFontMapper();
- virtual ~CFontMapper();
-
- virtual FT_Face FindSubstFont(
- CPDF_Document* pDoc, // [IN] The PDF document
- const CFX_ByteString& face_name, // [IN] Original name
- FX_BOOL bTrueType, // [IN] TrueType or Type1
- FX_DWORD flags, // [IN] PDF font flags (see PDF Reference section 5.7.1)
- int font_weight, // [IN] original font weight. 0 for not specified
- int CharsetCP, // [IN] code page for charset (see Win32 GetACP())
- FX_BOOL bVertical,
- CPDF_SubstFont* pSubstFont // [OUT] Subst font data
- );
-
- FT_Face m_SysFace;
-};
-
-CFontMapper* g_pFontMapper = NULL;
-#endif // #if _FX_OS_ == _FX_LINUX_EMBEDDED_
-
-DLLEXPORT void STDCALL FPDF_InitLibrary(FX_LPVOID hInstance)
-{
-#ifdef API5
- CPDF_ModuleMgr::Create();
- g_pModuleMgr = CPDF_ModuleMgr::Get();
- #if _FX_OS_ == _FX_WIN32_MOBILE_ || _FX_OS_ == _FX_LINUX_EMBEDDED_
- g_pModuleMgr->InitEmbedded();
- #ifdef _GB1_CMAPS_
- g_pModuleMgr->LoadEmbeddedGB1CMaps();
- #endif
- #ifdef _GB1_CMAPS_4_
- g_pModuleMgr->LoadEmbeddedGB1CMaps_4();
- #endif
- #ifdef _CNS1_CMAPS_
- g_pModuleMgr->LoadEmbeddedCNS1CMaps();
- #endif
- #ifdef _JAPAN1_CMAPS_
- g_pModuleMgr->LoadEmbeddedJapan1CMaps();
- #endif
- #ifdef _JAPAN1_CMAPS_6_
- g_pModuleMgr->LoadEmbeddedJapan1CMaps_6();
- #endif
- #ifdef _KOREA1_CMAPS_
- g_pModuleMgr->LoadEmbeddedKorea1CMaps();
- #endif
- #ifdef _JPX_DECODER_
- g_pModuleMgr->InitJpxModule();
- g_pModuleMgr->InitJbig2Module();
- // g_pModuleMgr->InitIccModule();
- #endif
- #else
- g_pModuleMgr->InitDesktop();
- #endif
-#else
-#ifdef _FXSDK_OPENSOURCE_
- g_pFoxitMgr = FXMEM_CreateMemoryMgr(1024 * 1024 * 32, TRUE);
-#endif
- g_pCodecModule = CCodec_ModuleMgr::Create();
-
- CFX_GEModule::Create();
- CFX_GEModule::Get()->SetCodecModule(g_pCodecModule);
-
- CPDF_ModuleMgr::Create();
- CPDF_ModuleMgr::Get()->SetCodecModule(g_pCodecModule);
- CPDF_ModuleMgr::Get()->InitPageModule();
- CPDF_ModuleMgr::Get()->InitRenderModule();
-#ifdef FOXIT_CHROME_BUILD
- CPDF_ModuleMgr * pModuleMgr = CPDF_ModuleMgr::Get();
- if ( pModuleMgr )
- {
- pModuleMgr->LoadEmbeddedGB1CMaps();
- pModuleMgr->LoadEmbeddedJapan1CMaps();
- pModuleMgr->LoadEmbeddedCNS1CMaps();
- pModuleMgr->LoadEmbeddedKorea1CMaps();
- }
-#endif
-#endif
-
-#ifdef _WIN32
- // Get module path
- TCHAR app_path[MAX_PATH];
- ::GetModuleFileName((HINSTANCE)hInstance, app_path, MAX_PATH);
- size_t len = _tcslen(app_path);
- for (size_t i = len; i >= 0; i --)
- if (app_path[i] == '\\') {
- app_path[i] = 0;
- break;
- }
-
-#ifdef _UNICODE
- #ifndef _FXSDK_OPENSOURCE_
- CPDF_ModuleMgr::Get()->SetModulePath(NULL, CFX_ByteString::FromUnicode(app_path));
- #endif
-#else
-#ifndef _FXSDK_OPENSOURCE_
- CPDF_ModuleMgr::Get()->SetModulePath(NULL, app_path);
-#endif
-#endif
-#endif
-}
-
-
-DLLEXPORT void STDCALL FPDF_DestroyLibrary()
-{
-
-#if _FX_OS_ == _FX_LINUX_EMBEDDED_
- if (g_pFontMapper) delete g_pFontMapper;
-#endif
-#ifdef API5
- g_pModuleMgr->Destroy();
-#else
- CPDF_ModuleMgr::Destroy();
- CFX_GEModule::Destroy();
- g_pCodecModule->Destroy();
-#endif
-#ifndef _FXSDK_OPENSOURCE_
- FXMEM_CollectAll(FXMEM_GetDefaultMgr());
-#else
- FXMEM_DestroyFoxitMgr(g_pFoxitMgr);
-#endif
-}
-
-#ifndef _WIN32
-int g_LastError;
-void SetLastError(int err)
-{
- g_LastError = err;
-}
-
-int GetLastError()
-{
- return g_LastError;
-}
-#endif
-
-void ProcessParseError(FX_DWORD err_code)
-{
- // Translate FPDFAPI error code to FPDFVIEW error code
- switch (err_code) {
- case PDFPARSE_ERROR_FILE:
- err_code = FPDF_ERR_FILE;
- break;
- case PDFPARSE_ERROR_FORMAT:
- err_code = FPDF_ERR_FORMAT;
- break;
- case PDFPARSE_ERROR_PASSWORD:
- err_code = FPDF_ERR_PASSWORD;
- break;
- case PDFPARSE_ERROR_HANDLER:
- err_code = FPDF_ERR_SECURITY;
- break;
- }
- SetLastError(err_code);
-}
-
-DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable)
-{
- return FSDK_SetSandBoxPolicy(policy, enable);
-}
-
-DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BYTESTRING password)
-{
- CPDF_Parser* pParser = FX_NEW CPDF_Parser;
- pParser->SetPassword(password);
- try {
- FX_DWORD err_code = pParser->StartParse((FX_LPCSTR)file_path);
- if (err_code) {
- delete pParser;
- ProcessParseError(err_code);
- return NULL;
- }
- }
- catch (...) {
- delete pParser;
- SetLastError(FPDF_ERR_UNKNOWN);
- return NULL;
- }
- return pParser->GetDocument();
-}
-
-extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code);
-
-class CMemFile: public IFX_FileRead, public CFX_Object
-{
-public:
- CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {}
-
- virtual void Release() {delete this;}
- virtual FX_FILESIZE GetSize() {return m_size;}
- virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
- {
- if(offset+size > (FX_DWORD)m_size) return FALSE;
- FXSYS_memcpy(buffer, m_pBuf+offset, size);
- return TRUE;
- }
-private:
- FX_BYTE* m_pBuf;
- FX_FILESIZE m_size;
-};
-DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int size, FPDF_BYTESTRING password)
-{
- CPDF_Parser* pParser = FX_NEW CPDF_Parser;
- pParser->SetPassword(password);
- try {
- CMemFile* pMemFile = FX_NEW CMemFile((FX_BYTE*)data_buf, size);
- FX_DWORD err_code = pParser->StartParse(pMemFile);
- if (err_code) {
- delete pParser;
- ProcessParseError(err_code);
- return NULL;
- }
- CPDF_Document * pDoc = NULL;
- pDoc = pParser?pParser->GetDocument():NULL;
- CheckUnSupportError(pDoc, err_code);
- }
- catch (...) {
- delete pParser;
- SetLastError(FPDF_ERR_UNKNOWN);
- return NULL;
- }
- return pParser->GetDocument();
-}
-
-DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password)
-{
- CPDF_Parser* pParser = FX_NEW CPDF_Parser;
- pParser->SetPassword(password);
- CPDF_CustomAccess* pFile = FX_NEW CPDF_CustomAccess(pFileAccess);
- try {
- FX_DWORD err_code = pParser->StartParse(pFile);
- if (err_code) {
- delete pParser;
- ProcessParseError(err_code);
- return NULL;
- }
- CPDF_Document * pDoc = NULL;
- pDoc = pParser?pParser->GetDocument():NULL;
- CheckUnSupportError(pDoc, err_code);
- }
- catch (...) {
- delete pParser;
- SetLastError(FPDF_ERR_UNKNOWN);
- return NULL;
- }
- return pParser->GetDocument();
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, int* fileVersion)
-{
- if(!doc||!fileVersion) return FALSE;
- *fileVersion = 0;
- CPDF_Document* pDoc = (CPDF_Document*)doc;
- CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
- if(!pParser)
- return FALSE;
- *fileVersion = pParser->GetFileVersion();
- return TRUE;
-}
-
-// jabdelmalek: changed return type from FX_DWORD to build on Linux (and match header).
-DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document)
-{
- if (document == NULL) return 0;
- CPDF_Document*pDoc = (CPDF_Document*)document;
- CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
- CPDF_Dictionary* pDict = pParser->GetEncryptDict();
- if (pDict == NULL) return (FX_DWORD)-1;
-
- return pDict->GetInteger("P");
-}
-
-DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document)
-{
- if (document == NULL) return 0;
- return ((CPDF_Document*)document)->GetPageCount();
-}
-
-DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index)
-{
- if (document == NULL) return NULL;
- if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL;
-// CPDF_Parser* pParser = (CPDF_Parser*)document;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if (pDoc == NULL) return NULL;
- CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
- if (pDict == NULL) return NULL;
- CPDF_Page* pPage = FX_NEW CPDF_Page;
- pPage->Load(pDoc, pDict);
- try {
- pPage->ParseContent();
- }
- catch (...) {
- delete pPage;
- return NULL;
- }
-
-// CheckUnSupportError(pDoc, 0);
-
- return pPage;
-}
-
-DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page)
-{
- if (!page)
- return 0.0;
- return ((CPDF_Page*)page)->GetPageWidth();
-}
-
-DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page)
-{
- if (!page) return 0.0;
- return ((CPDF_Page*)page)->GetPageHeight();
-}
-
-void DropContext(void* data)
-{
- delete (CRenderContext*)data;
-}
-
-void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
- int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause );
-void (*Func_RenderPage)(CRenderContext*, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
- int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause ) = FPDF_RenderPage_Retail;
-
-#if defined(_DEBUG) || defined(DEBUG)
-#define DEBUG_TRACE
-#endif
-
-#if defined(_WIN32)
-DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
- int rotate, int flags)
-{
- if (page==NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
- CRenderContext* pContext = FX_NEW CRenderContext;
- pPage->SetPrivateData((void*)1, pContext, DropContext);
-
-#ifndef _WIN32_WCE
- CFX_DIBitmap* pBitmap = NULL;
- FX_BOOL bBackgroundAlphaNeeded=FALSE;
- bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded();
- if (bBackgroundAlphaNeeded)
- {
-
- pBitmap = FX_NEW CFX_DIBitmap;
- pBitmap->Create(size_x, size_y, FXDIB_Argb);
- pBitmap->Clear(0x00ffffff);
-#ifdef _SKIA_SUPPORT_
- pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
- ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap);
-#else
- pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
- ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap);
-#endif
- }
- else
- pContext->m_pDevice = FX_NEW CFX_WindowsDevice(dc);
- if (flags & FPDF_NO_CATCH)
- Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL);
- else {
- try {
- Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL);
- } catch (...) {
- }
- }
- if (bBackgroundAlphaNeeded)
- {
- if (pBitmap)
- {
- CFX_WindowsDevice WinDC(dc);
-
- if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER)
- {
- CFX_DIBitmap* pDst = FX_NEW CFX_DIBitmap;
- pDst->Create(pBitmap->GetWidth(), pBitmap->GetHeight(),FXDIB_Rgb32);
- FXSYS_memcpy(pDst->GetBuffer(), pBitmap->GetBuffer(), pBitmap->GetPitch()*pBitmap->GetHeight());
-// WinDC.SetDIBits(pDst,0,0);
- WinDC.StretchDIBits(pDst,0,0,size_x*2,size_y*2);
- delete pDst;
- }
- else
- WinDC.SetDIBits(pBitmap,0,0);
-
- }
- }
-#else
- // get clip region
- RECT rect, cliprect;
- rect.left = start_x;
- rect.top = start_y;
- rect.right = start_x + size_x;
- rect.bottom = start_y + size_y;
- GetClipBox(dc, &cliprect);
- IntersectRect(&rect, &rect, &cliprect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
-
-#ifdef DEBUG_TRACE
- {
- char str[128];
- sprintf(str, "Rendering DIB %d x %d", width, height);
- CPDF_ModuleMgr::Get()->ReportError(999, str);
- }
-#endif
-
- // Create a DIB section
- LPVOID pBuffer;
- BITMAPINFOHEADER bmih;
- FXSYS_memset(&bmih, 0, sizeof bmih);
- bmih.biSize = sizeof bmih;
- bmih.biBitCount = 24;
- bmih.biHeight = -height;
- bmih.biPlanes = 1;
- bmih.biWidth = width;
- pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, &pBuffer, NULL, 0);
- if (pContext->m_hBitmap == NULL) {
-#if defined(DEBUG) || defined(_DEBUG)
- char str[128];
- sprintf(str, "Error CreateDIBSection: %d x %d, error code = %d", width, height, GetLastError());
- CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str);
-#else
- CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL);
-#endif
- }
- FXSYS_memset(pBuffer, 0xff, height*((width*3+3)/4*4));
-
-#ifdef DEBUG_TRACE
- {
- CPDF_ModuleMgr::Get()->ReportError(999, "DIBSection created");
- }
-#endif
-
- // Create a device with this external buffer
- pContext->m_pBitmap = FX_NEW CFX_DIBitmap;
- pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (FX_LPBYTE)pBuffer);
- pContext->m_pDevice = FX_NEW CPDF_FxgeDevice;
- ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap);
-
-#ifdef DEBUG_TRACE
- CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering");
-#endif
-
- // output to bitmap device
- if (flags & FPDF_NO_CATCH)
- Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top, size_x, size_y, rotate, flags);
- else {
- try {
- Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top, size_x, size_y, rotate, flags);
- } catch (...) {
- }
- }
-
-#ifdef DEBUG_TRACE
- CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering");
-#endif
-
- // Now output to real device
- HDC hMemDC = CreateCompatibleDC(dc);
- if (hMemDC == NULL) {
-#if defined(DEBUG) || defined(_DEBUG)
- char str[128];
- sprintf(str, "Error CreateCompatibleDC. Error code = %d", GetLastError());
- CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str);
-#else
- CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL);
-#endif
- }
-
- HGDIOBJ hOldBitmap = SelectObject(hMemDC, pContext->m_hBitmap);
-
-#ifdef DEBUG_TRACE
- CPDF_ModuleMgr::Get()->ReportError(999, "Ready for screen rendering");
-#endif
-
- BitBlt(dc, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY);
- SelectObject(hMemDC, hOldBitmap);
- DeleteDC(hMemDC);
-
-#ifdef DEBUG_TRACE
- CPDF_ModuleMgr::Get()->ReportError(999, "Finished screen rendering");
-#endif
-
-#endif
- if (bBackgroundAlphaNeeded)
- {
- if (pBitmap)
- delete pBitmap;
- pBitmap = NULL;
- }
- delete pContext;
- pPage->RemovePrivateData((void*)1);
-}
-#endif
-
-DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y,
- int size_x, int size_y, int rotate, int flags)
-{
- if (bitmap == NULL || page == NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
-
- CRenderContext* pContext = FX_NEW CRenderContext;
- pPage->SetPrivateData((void*)1, pContext, DropContext);
-#ifdef _SKIA_SUPPORT_
- pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
-
- if (flags & FPDF_REVERSE_BYTE_ORDER)
- ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
- else
- ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
-#else
- pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
-
- if (flags & FPDF_REVERSE_BYTE_ORDER)
- ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
- else
- ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
-#endif
- if (flags & FPDF_NO_CATCH)
- Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL);
- else {
- try {
- Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL);
- } catch (...) {
- }
- }
-
- delete pContext;
- pPage->RemovePrivateData((void*)1);
-}
-
-DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page)
-{
- if (!page) return;
- delete (CPDF_Page*)page;
-
-}
-
-DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document)
-{
- if (!document)
- return;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
- if (pParser == NULL)
- {
- delete pDoc;
- return;
- }
- delete pParser;
-// delete pDoc;
-}
-
-DLLEXPORT unsigned long STDCALL FPDF_GetLastError()
-{
- return GetLastError();
-}
-
-DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
- int rotate, int device_x, int device_y, double* page_x, double* page_y)
-{
- if (page == NULL || page_x == NULL || page_y == NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
- CPDF_Matrix page2device;
- pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate);
- CPDF_Matrix device2page;
- device2page.SetReverse(page2device);
-
- FX_FLOAT page_x_f, page_y_f;
- device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, page_y_f);
-
- *page_x = (page_x_f);
- *page_y = (page_y_f);
-}
-
-DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
- int rotate, double page_x, double page_y, int* device_x, int* device_y)
-{
- if (page == NULL || device_x == NULL || device_y == NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
- CPDF_Matrix page2device;
- pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate);
-
- FX_FLOAT device_x_f, device_y_f;
- page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, device_y_f);
-
- *device_x = FXSYS_round(device_x_f);
- *device_y = FXSYS_round(device_y_f);
-}
-
-DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha)
-{
- CFX_DIBitmap* pBitmap = FX_NEW CFX_DIBitmap;
- pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32);
- return pBitmap;
-}
-
-DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, int height, int format, void* first_scan, int stride)
-{
- FXDIB_Format fx_format;
- switch (format) {
- case FPDFBitmap_Gray:
- fx_format = FXDIB_8bppRgb;
- break;
- case FPDFBitmap_BGR:
- fx_format = FXDIB_Rgb;
- break;
- case FPDFBitmap_BGRx:
- fx_format = FXDIB_Rgb32;
- break;
- case FPDFBitmap_BGRA:
- fx_format = FXDIB_Argb;
- break;
- default:
- return NULL;
- }
- CFX_DIBitmap* pBitmap = FX_NEW CFX_DIBitmap;
- pBitmap->Create(width, height, fx_format, (FX_LPBYTE)first_scan, stride);
- return pBitmap;
-}
-
-DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, int left, int top, int width, int height,
- int red, int green, int blue, int alpha)
-{
- if (bitmap == NULL) return;
-#ifdef _SKIA_SUPPORT_
- CFX_SkiaDevice device;
-#else
- CFX_FxgeDevice device;
-#endif
- device.Attach((CFX_DIBitmap*)bitmap);
- if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) alpha = 255;
- FX_RECT rect(left, top, left+width, top+height);
- device.FillRect(&rect, FXARGB_MAKE(alpha, red, green, blue));
-}
-
-DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap)
-{
- if (bitmap == NULL) return NULL;
- return ((CFX_DIBitmap*)bitmap)->GetBuffer();
-}
-
-DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap)
-{
- if (bitmap == NULL) return 0;
- return ((CFX_DIBitmap*)bitmap)->GetWidth();
-}
-
-DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap)
-{
- if (bitmap == NULL) return 0;
- return ((CFX_DIBitmap*)bitmap)->GetHeight();
-}
-
-DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap)
-{
- if (bitmap == NULL) return 0;
- return ((CFX_DIBitmap*)bitmap)->GetPitch();
-}
-
-DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap)
-{
- if (bitmap == NULL) return;
- delete (CFX_DIBitmap*)bitmap;
-}
-
-void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
- int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause )
-{
-//#ifdef _LICENSED_BUILD_
- CPDF_Page* pPage = (CPDF_Page*)page;
- if (pPage == NULL) return;
-
- if (!pContext->m_pOptions)
- pContext->m_pOptions = new CPDF_RenderOptions;
-// CPDF_RenderOptions options;
- if (flags & FPDF_LCD_TEXT)
- pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE;
- else
- pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE;
- if (flags & FPDF_NO_NATIVETEXT)
- pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT;
- if (flags & FPDF_RENDER_LIMITEDIMAGECACHE)
- pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
- if (flags & FPDF_RENDER_FORCEHALFTONE)
- pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
- //Grayscale output
- if (flags & FPDF_GRAYSCALE)
- {
- pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
- pContext->m_pOptions->m_ForeColor = 0;
- pContext->m_pOptions->m_BackColor = 0xffffff;
- }
- const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
-
- pContext->m_pOptions->m_AddFlags = flags >> 8;
-
- pContext->m_pOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocument, usage);
-
-
- CFX_AffineMatrix matrix;
- pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
-
- FX_RECT clip;
- clip.left = start_x;
- clip.right = start_x + size_x;
- clip.top = start_y;
- clip.bottom = start_y + size_y;
- pContext->m_pDevice->SaveState();
- pContext->m_pDevice->SetClip_Rect(&clip);
-
- pContext->m_pContext = FX_NEW CPDF_RenderContext;
- pContext->m_pContext->Create(pPage);
- pContext->m_pContext->AppendObjectList(pPage, &matrix);
-
- if (flags & FPDF_ANNOT) {
- pContext->m_pAnnots = FX_NEW CPDF_AnnotList(pPage);
- FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY;
- pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext, bPrinting, &matrix, TRUE, NULL);
- }
-
- pContext->m_pRenderer = FX_NEW CPDF_ProgressiveRenderer;
- pContext->m_pRenderer->Start(pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions, pause);
- if (bNeedToRestore)
- {
- pContext->m_pDevice->RestoreState();
- }
-
-//#endif
-}
-
-DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double* width, double* height)
-{
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if(pDoc == NULL)
- return FALSE;
-
- CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
- if (pDict == NULL) return FALSE;
-
- CPDF_Page page;
- page.Load(pDoc, pDict);
- *width = page.GetPageWidth();
- *height = page.GetPageHeight();
-
- return TRUE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document)
-{
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if (!pDoc) return TRUE;
- CPDF_ViewerPreferences viewRef(pDoc);
- return viewRef.PrintScaling();
-}
-
-DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_BYTESTRING name)
-{
- if (document == NULL)
- return NULL;
- if (name == NULL || name[0] == 0)
- return NULL;
-
- CPDF_Document* pDoc = (CPDF_Document*)document;
- CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
- return name_tree.LookupNamedDest(pDoc, name);
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdfview.h"
+#include "../include/fsdk_rendercontext.h"
+#include "../include/fpdf_progressive.h"
+#include "../include/fpdf_ext.h"
+
+
+CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
+{
+ m_FileAccess = *pFileAccess;
+ m_BufferOffset = (FX_DWORD)-1;
+}
+
+FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch)
+{
+ if (pos >= m_FileAccess.m_FileLen) return FALSE;
+ if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_BufferOffset + 512) {
+ // Need to read from file access
+ m_BufferOffset = pos;
+ int size = 512;
+ if (pos + 512 > m_FileAccess.m_FileLen)
+ size = m_FileAccess.m_FileLen - pos;
+ if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, size))
+ return FALSE;
+ }
+ ch = m_Buffer[pos - m_BufferOffset];
+ return TRUE;
+}
+
+FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size)
+{
+ if (pos + size > m_FileAccess.m_FileLen) return FALSE;
+ return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size);
+}
+
+FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
+{
+ // m_FileAccess = *pFileAccess;
+ // m_BufferOffset = (FX_DWORD)-1;
+ if (offset + size > m_FileAccess.m_FileLen) return FALSE;
+ return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,(FX_LPBYTE) buffer, size);
+
+ // return FALSE;
+}
+
+//0 bit: FPDF_POLICY_MACHINETIME_ACCESS
+static FX_DWORD foxit_sandbox_policy = 0xFFFFFFFF;
+
+void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable)
+{
+ switch(policy)
+ {
+ case FPDF_POLICY_MACHINETIME_ACCESS:
+ {
+ if(enable)
+ foxit_sandbox_policy |= 0x01;
+ else
+ foxit_sandbox_policy &= 0xFFFFFFFE;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy)
+{
+ switch(policy)
+ {
+ case FPDF_POLICY_MACHINETIME_ACCESS:
+ {
+ if(foxit_sandbox_policy&0x01)
+ return TRUE;
+ else
+ return FALSE;
+ }
+ break;
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+
+#ifndef _T
+#define _T(x) x
+#endif
+
+#ifdef API5
+ CPDF_ModuleMgr* g_pModuleMgr = NULL;
+#else
+ CCodec_ModuleMgr* g_pCodecModule = NULL;
+#ifdef _FXSDK_OPENSOURCE_
+ FXMEM_FoxitMgr* g_pFoxitMgr = NULL;
+#endif
+#endif
+
+//extern CPDFSDK_FormFillApp* g_pFormFillApp;
+
+#if _FX_OS_ == _FX_LINUX_EMBEDDED_
+class CFontMapper : public IPDF_FontMapper
+{
+public:
+ CFontMapper();
+ virtual ~CFontMapper();
+
+ virtual FT_Face FindSubstFont(
+ CPDF_Document* pDoc, // [IN] The PDF document
+ const CFX_ByteString& face_name, // [IN] Original name
+ FX_BOOL bTrueType, // [IN] TrueType or Type1
+ FX_DWORD flags, // [IN] PDF font flags (see PDF Reference section 5.7.1)
+ int font_weight, // [IN] original font weight. 0 for not specified
+ int CharsetCP, // [IN] code page for charset (see Win32 GetACP())
+ FX_BOOL bVertical,
+ CPDF_SubstFont* pSubstFont // [OUT] Subst font data
+ );
+
+ FT_Face m_SysFace;
+};
+
+CFontMapper* g_pFontMapper = NULL;
+#endif // #if _FX_OS_ == _FX_LINUX_EMBEDDED_
+
+DLLEXPORT void STDCALL FPDF_InitLibrary(FX_LPVOID hInstance)
+{
+#ifdef API5
+ CPDF_ModuleMgr::Create();
+ g_pModuleMgr = CPDF_ModuleMgr::Get();
+ #if _FX_OS_ == _FX_WIN32_MOBILE_ || _FX_OS_ == _FX_LINUX_EMBEDDED_
+ g_pModuleMgr->InitEmbedded();
+ #ifdef _GB1_CMAPS_
+ g_pModuleMgr->LoadEmbeddedGB1CMaps();
+ #endif
+ #ifdef _GB1_CMAPS_4_
+ g_pModuleMgr->LoadEmbeddedGB1CMaps_4();
+ #endif
+ #ifdef _CNS1_CMAPS_
+ g_pModuleMgr->LoadEmbeddedCNS1CMaps();
+ #endif
+ #ifdef _JAPAN1_CMAPS_
+ g_pModuleMgr->LoadEmbeddedJapan1CMaps();
+ #endif
+ #ifdef _JAPAN1_CMAPS_6_
+ g_pModuleMgr->LoadEmbeddedJapan1CMaps_6();
+ #endif
+ #ifdef _KOREA1_CMAPS_
+ g_pModuleMgr->LoadEmbeddedKorea1CMaps();
+ #endif
+ #ifdef _JPX_DECODER_
+ g_pModuleMgr->InitJpxModule();
+ g_pModuleMgr->InitJbig2Module();
+ // g_pModuleMgr->InitIccModule();
+ #endif
+ #else
+ g_pModuleMgr->InitDesktop();
+ #endif
+#else
+#ifdef _FXSDK_OPENSOURCE_
+ g_pFoxitMgr = FXMEM_CreateMemoryMgr(1024 * 1024 * 32, TRUE);
+#endif
+ g_pCodecModule = CCodec_ModuleMgr::Create();
+
+ CFX_GEModule::Create();
+ CFX_GEModule::Get()->SetCodecModule(g_pCodecModule);
+
+ CPDF_ModuleMgr::Create();
+ CPDF_ModuleMgr::Get()->SetCodecModule(g_pCodecModule);
+ CPDF_ModuleMgr::Get()->InitPageModule();
+ CPDF_ModuleMgr::Get()->InitRenderModule();
+#ifdef FOXIT_CHROME_BUILD
+ CPDF_ModuleMgr * pModuleMgr = CPDF_ModuleMgr::Get();
+ if ( pModuleMgr )
+ {
+ pModuleMgr->LoadEmbeddedGB1CMaps();
+ pModuleMgr->LoadEmbeddedJapan1CMaps();
+ pModuleMgr->LoadEmbeddedCNS1CMaps();
+ pModuleMgr->LoadEmbeddedKorea1CMaps();
+ }
+#endif
+#endif
+
+#ifdef _WIN32
+ // Get module path
+ TCHAR app_path[MAX_PATH];
+ ::GetModuleFileName((HINSTANCE)hInstance, app_path, MAX_PATH);
+ size_t len = _tcslen(app_path);
+ for (size_t i = len; i >= 0; i --)
+ if (app_path[i] == '\\') {
+ app_path[i] = 0;
+ break;
+ }
+
+#ifdef _UNICODE
+ #ifndef _FXSDK_OPENSOURCE_
+ CPDF_ModuleMgr::Get()->SetModulePath(NULL, CFX_ByteString::FromUnicode(app_path));
+ #endif
+#else
+#ifndef _FXSDK_OPENSOURCE_
+ CPDF_ModuleMgr::Get()->SetModulePath(NULL, app_path);
+#endif
+#endif
+#endif
+}
+
+
+DLLEXPORT void STDCALL FPDF_DestroyLibrary()
+{
+
+#if _FX_OS_ == _FX_LINUX_EMBEDDED_
+ if (g_pFontMapper) delete g_pFontMapper;
+#endif
+#ifdef API5
+ g_pModuleMgr->Destroy();
+#else
+ CPDF_ModuleMgr::Destroy();
+ CFX_GEModule::Destroy();
+ g_pCodecModule->Destroy();
+#endif
+#ifndef _FXSDK_OPENSOURCE_
+ FXMEM_CollectAll(FXMEM_GetDefaultMgr());
+#else
+ FXMEM_DestroyFoxitMgr(g_pFoxitMgr);
+#endif
+}
+
+#ifndef _WIN32
+int g_LastError;
+void SetLastError(int err)
+{
+ g_LastError = err;
+}
+
+int GetLastError()
+{
+ return g_LastError;
+}
+#endif
+
+void ProcessParseError(FX_DWORD err_code)
+{
+ // Translate FPDFAPI error code to FPDFVIEW error code
+ switch (err_code) {
+ case PDFPARSE_ERROR_FILE:
+ err_code = FPDF_ERR_FILE;
+ break;
+ case PDFPARSE_ERROR_FORMAT:
+ err_code = FPDF_ERR_FORMAT;
+ break;
+ case PDFPARSE_ERROR_PASSWORD:
+ err_code = FPDF_ERR_PASSWORD;
+ break;
+ case PDFPARSE_ERROR_HANDLER:
+ err_code = FPDF_ERR_SECURITY;
+ break;
+ }
+ SetLastError(err_code);
+}
+
+DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable)
+{
+ return FSDK_SetSandBoxPolicy(policy, enable);
+}
+
+DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BYTESTRING password)
+{
+ CPDF_Parser* pParser = FX_NEW CPDF_Parser;
+ pParser->SetPassword(password);
+ try {
+ FX_DWORD err_code = pParser->StartParse((FX_LPCSTR)file_path);
+ if (err_code) {
+ delete pParser;
+ ProcessParseError(err_code);
+ return NULL;
+ }
+ }
+ catch (...) {
+ delete pParser;
+ SetLastError(FPDF_ERR_UNKNOWN);
+ return NULL;
+ }
+ return pParser->GetDocument();
+}
+
+extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code);
+
+class CMemFile: public IFX_FileRead, public CFX_Object
+{
+public:
+ CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {}
+
+ virtual void Release() {delete this;}
+ virtual FX_FILESIZE GetSize() {return m_size;}
+ virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
+ {
+ if(offset+size > (FX_DWORD)m_size) return FALSE;
+ FXSYS_memcpy(buffer, m_pBuf+offset, size);
+ return TRUE;
+ }
+private:
+ FX_BYTE* m_pBuf;
+ FX_FILESIZE m_size;
+};
+DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int size, FPDF_BYTESTRING password)
+{
+ CPDF_Parser* pParser = FX_NEW CPDF_Parser;
+ pParser->SetPassword(password);
+ try {
+ CMemFile* pMemFile = FX_NEW CMemFile((FX_BYTE*)data_buf, size);
+ FX_DWORD err_code = pParser->StartParse(pMemFile);
+ if (err_code) {
+ delete pParser;
+ ProcessParseError(err_code);
+ return NULL;
+ }
+ CPDF_Document * pDoc = NULL;
+ pDoc = pParser?pParser->GetDocument():NULL;
+ CheckUnSupportError(pDoc, err_code);
+ }
+ catch (...) {
+ delete pParser;
+ SetLastError(FPDF_ERR_UNKNOWN);
+ return NULL;
+ }
+ return pParser->GetDocument();
+}
+
+DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password)
+{
+ CPDF_Parser* pParser = FX_NEW CPDF_Parser;
+ pParser->SetPassword(password);
+ CPDF_CustomAccess* pFile = FX_NEW CPDF_CustomAccess(pFileAccess);
+ try {
+ FX_DWORD err_code = pParser->StartParse(pFile);
+ if (err_code) {
+ delete pParser;
+ ProcessParseError(err_code);
+ return NULL;
+ }
+ CPDF_Document * pDoc = NULL;
+ pDoc = pParser?pParser->GetDocument():NULL;
+ CheckUnSupportError(pDoc, err_code);
+ }
+ catch (...) {
+ delete pParser;
+ SetLastError(FPDF_ERR_UNKNOWN);
+ return NULL;
+ }
+ return pParser->GetDocument();
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, int* fileVersion)
+{
+ if(!doc||!fileVersion) return FALSE;
+ *fileVersion = 0;
+ CPDF_Document* pDoc = (CPDF_Document*)doc;
+ CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
+ if(!pParser)
+ return FALSE;
+ *fileVersion = pParser->GetFileVersion();
+ return TRUE;
+}
+
+// jabdelmalek: changed return type from FX_DWORD to build on Linux (and match header).
+DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document)
+{
+ if (document == NULL) return 0;
+ CPDF_Document*pDoc = (CPDF_Document*)document;
+ CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
+ CPDF_Dictionary* pDict = pParser->GetEncryptDict();
+ if (pDict == NULL) return (FX_DWORD)-1;
+
+ return pDict->GetInteger("P");
+}
+
+DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document)
+{
+ if (document == NULL) return 0;
+ return ((CPDF_Document*)document)->GetPageCount();
+}
+
+DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index)
+{
+ if (document == NULL) return NULL;
+ if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL;
+// CPDF_Parser* pParser = (CPDF_Parser*)document;
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ if (pDoc == NULL) return NULL;
+ CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
+ if (pDict == NULL) return NULL;
+ CPDF_Page* pPage = FX_NEW CPDF_Page;
+ pPage->Load(pDoc, pDict);
+ try {
+ pPage->ParseContent();
+ }
+ catch (...) {
+ delete pPage;
+ return NULL;
+ }
+
+// CheckUnSupportError(pDoc, 0);
+
+ return pPage;
+}
+
+DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page)
+{
+ if (!page)
+ return 0.0;
+ return ((CPDF_Page*)page)->GetPageWidth();
+}
+
+DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page)
+{
+ if (!page) return 0.0;
+ return ((CPDF_Page*)page)->GetPageHeight();
+}
+
+void DropContext(void* data)
+{
+ delete (CRenderContext*)data;
+}
+
+void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
+ int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause );
+void (*Func_RenderPage)(CRenderContext*, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
+ int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause ) = FPDF_RenderPage_Retail;
+
+#if defined(_DEBUG) || defined(DEBUG)
+#define DEBUG_TRACE
+#endif
+
+#if defined(_WIN32)
+DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
+ int rotate, int flags)
+{
+ if (page==NULL) return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+ CRenderContext* pContext = FX_NEW CRenderContext;
+ pPage->SetPrivateData((void*)1, pContext, DropContext);
+
+#ifndef _WIN32_WCE
+ CFX_DIBitmap* pBitmap = NULL;
+ FX_BOOL bBackgroundAlphaNeeded=FALSE;
+ bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded();
+ if (bBackgroundAlphaNeeded)
+ {
+
+ pBitmap = FX_NEW CFX_DIBitmap;
+ pBitmap->Create(size_x, size_y, FXDIB_Argb);
+ pBitmap->Clear(0x00ffffff);
+#ifdef _SKIA_SUPPORT_
+ pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
+ ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap);
+#else
+ pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
+ ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap);
+#endif
+ }
+ else
+ pContext->m_pDevice = FX_NEW CFX_WindowsDevice(dc);
+ if (flags & FPDF_NO_CATCH)
+ Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL);
+ else {
+ try {
+ Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL);
+ } catch (...) {
+ }
+ }
+ if (bBackgroundAlphaNeeded)
+ {
+ if (pBitmap)
+ {
+ CFX_WindowsDevice WinDC(dc);
+
+ if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER)
+ {
+ CFX_DIBitmap* pDst = FX_NEW CFX_DIBitmap;
+ pDst->Create(pBitmap->GetWidth(), pBitmap->GetHeight(),FXDIB_Rgb32);
+ FXSYS_memcpy(pDst->GetBuffer(), pBitmap->GetBuffer(), pBitmap->GetPitch()*pBitmap->GetHeight());
+// WinDC.SetDIBits(pDst,0,0);
+ WinDC.StretchDIBits(pDst,0,0,size_x*2,size_y*2);
+ delete pDst;
+ }
+ else
+ WinDC.SetDIBits(pBitmap,0,0);
+
+ }
+ }
+#else
+ // get clip region
+ RECT rect, cliprect;
+ rect.left = start_x;
+ rect.top = start_y;
+ rect.right = start_x + size_x;
+ rect.bottom = start_y + size_y;
+ GetClipBox(dc, &cliprect);
+ IntersectRect(&rect, &rect, &cliprect);
+ int width = rect.right - rect.left;
+ int height = rect.bottom - rect.top;
+
+#ifdef DEBUG_TRACE
+ {
+ char str[128];
+ sprintf(str, "Rendering DIB %d x %d", width, height);
+ CPDF_ModuleMgr::Get()->ReportError(999, str);
+ }
+#endif
+
+ // Create a DIB section
+ LPVOID pBuffer;
+ BITMAPINFOHEADER bmih;
+ FXSYS_memset(&bmih, 0, sizeof bmih);
+ bmih.biSize = sizeof bmih;
+ bmih.biBitCount = 24;
+ bmih.biHeight = -height;
+ bmih.biPlanes = 1;
+ bmih.biWidth = width;
+ pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, &pBuffer, NULL, 0);
+ if (pContext->m_hBitmap == NULL) {
+#if defined(DEBUG) || defined(_DEBUG)
+ char str[128];
+ sprintf(str, "Error CreateDIBSection: %d x %d, error code = %d", width, height, GetLastError());
+ CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str);
+#else
+ CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL);
+#endif
+ }
+ FXSYS_memset(pBuffer, 0xff, height*((width*3+3)/4*4));
+
+#ifdef DEBUG_TRACE
+ {
+ CPDF_ModuleMgr::Get()->ReportError(999, "DIBSection created");
+ }
+#endif
+
+ // Create a device with this external buffer
+ pContext->m_pBitmap = FX_NEW CFX_DIBitmap;
+ pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (FX_LPBYTE)pBuffer);
+ pContext->m_pDevice = FX_NEW CPDF_FxgeDevice;
+ ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap);
+
+#ifdef DEBUG_TRACE
+ CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering");
+#endif
+
+ // output to bitmap device
+ if (flags & FPDF_NO_CATCH)
+ Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top, size_x, size_y, rotate, flags);
+ else {
+ try {
+ Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top, size_x, size_y, rotate, flags);
+ } catch (...) {
+ }
+ }
+
+#ifdef DEBUG_TRACE
+ CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering");
+#endif
+
+ // Now output to real device
+ HDC hMemDC = CreateCompatibleDC(dc);
+ if (hMemDC == NULL) {
+#if defined(DEBUG) || defined(_DEBUG)
+ char str[128];
+ sprintf(str, "Error CreateCompatibleDC. Error code = %d", GetLastError());
+ CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str);
+#else
+ CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL);
+#endif
+ }
+
+ HGDIOBJ hOldBitmap = SelectObject(hMemDC, pContext->m_hBitmap);
+
+#ifdef DEBUG_TRACE
+ CPDF_ModuleMgr::Get()->ReportError(999, "Ready for screen rendering");
+#endif
+
+ BitBlt(dc, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY);
+ SelectObject(hMemDC, hOldBitmap);
+ DeleteDC(hMemDC);
+
+#ifdef DEBUG_TRACE
+ CPDF_ModuleMgr::Get()->ReportError(999, "Finished screen rendering");
+#endif
+
+#endif
+ if (bBackgroundAlphaNeeded)
+ {
+ if (pBitmap)
+ delete pBitmap;
+ pBitmap = NULL;
+ }
+ delete pContext;
+ pPage->RemovePrivateData((void*)1);
+}
+#endif
+
+DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y,
+ int size_x, int size_y, int rotate, int flags)
+{
+ if (bitmap == NULL || page == NULL) return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+
+ CRenderContext* pContext = FX_NEW CRenderContext;
+ pPage->SetPrivateData((void*)1, pContext, DropContext);
+#ifdef _SKIA_SUPPORT_
+ pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
+
+ if (flags & FPDF_REVERSE_BYTE_ORDER)
+ ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
+ else
+ ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
+#else
+ pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
+
+ if (flags & FPDF_REVERSE_BYTE_ORDER)
+ ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
+ else
+ ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
+#endif
+ if (flags & FPDF_NO_CATCH)
+ Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL);
+ else {
+ try {
+ Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL);
+ } catch (...) {
+ }
+ }
+
+ delete pContext;
+ pPage->RemovePrivateData((void*)1);
+}
+
+DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page)
+{
+ if (!page) return;
+ delete (CPDF_Page*)page;
+
+}
+
+DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document)
+{
+ if (!document)
+ return;
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
+ if (pParser == NULL)
+ {
+ delete pDoc;
+ return;
+ }
+ delete pParser;
+// delete pDoc;
+}
+
+DLLEXPORT unsigned long STDCALL FPDF_GetLastError()
+{
+ return GetLastError();
+}
+
+DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
+ int rotate, int device_x, int device_y, double* page_x, double* page_y)
+{
+ if (page == NULL || page_x == NULL || page_y == NULL) return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+ CPDF_Matrix page2device;
+ pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate);
+ CPDF_Matrix device2page;
+ device2page.SetReverse(page2device);
+
+ FX_FLOAT page_x_f, page_y_f;
+ device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, page_y_f);
+
+ *page_x = (page_x_f);
+ *page_y = (page_y_f);
+}
+
+DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
+ int rotate, double page_x, double page_y, int* device_x, int* device_y)
+{
+ if (page == NULL || device_x == NULL || device_y == NULL) return;
+ CPDF_Page* pPage = (CPDF_Page*)page;
+
+ CPDF_Matrix page2device;
+ pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate);
+
+ FX_FLOAT device_x_f, device_y_f;
+ page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, device_y_f);
+
+ *device_x = FXSYS_round(device_x_f);
+ *device_y = FXSYS_round(device_y_f);
+}
+
+DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha)
+{
+ CFX_DIBitmap* pBitmap = FX_NEW CFX_DIBitmap;
+ pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32);
+ return pBitmap;
+}
+
+DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, int height, int format, void* first_scan, int stride)
+{
+ FXDIB_Format fx_format;
+ switch (format) {
+ case FPDFBitmap_Gray:
+ fx_format = FXDIB_8bppRgb;
+ break;
+ case FPDFBitmap_BGR:
+ fx_format = FXDIB_Rgb;
+ break;
+ case FPDFBitmap_BGRx:
+ fx_format = FXDIB_Rgb32;
+ break;
+ case FPDFBitmap_BGRA:
+ fx_format = FXDIB_Argb;
+ break;
+ default:
+ return NULL;
+ }
+ CFX_DIBitmap* pBitmap = FX_NEW CFX_DIBitmap;
+ pBitmap->Create(width, height, fx_format, (FX_LPBYTE)first_scan, stride);
+ return pBitmap;
+}
+
+DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, int left, int top, int width, int height,
+ int red, int green, int blue, int alpha)
+{
+ if (bitmap == NULL) return;
+#ifdef _SKIA_SUPPORT_
+ CFX_SkiaDevice device;
+#else
+ CFX_FxgeDevice device;
+#endif
+ device.Attach((CFX_DIBitmap*)bitmap);
+ if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) alpha = 255;
+ FX_RECT rect(left, top, left+width, top+height);
+ device.FillRect(&rect, FXARGB_MAKE(alpha, red, green, blue));
+}
+
+DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap)
+{
+ if (bitmap == NULL) return NULL;
+ return ((CFX_DIBitmap*)bitmap)->GetBuffer();
+}
+
+DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap)
+{
+ if (bitmap == NULL) return 0;
+ return ((CFX_DIBitmap*)bitmap)->GetWidth();
+}
+
+DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap)
+{
+ if (bitmap == NULL) return 0;
+ return ((CFX_DIBitmap*)bitmap)->GetHeight();
+}
+
+DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap)
+{
+ if (bitmap == NULL) return 0;
+ return ((CFX_DIBitmap*)bitmap)->GetPitch();
+}
+
+DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap)
+{
+ if (bitmap == NULL) return;
+ delete (CFX_DIBitmap*)bitmap;
+}
+
+void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
+ int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause )
+{
+//#ifdef _LICENSED_BUILD_
+ CPDF_Page* pPage = (CPDF_Page*)page;
+ if (pPage == NULL) return;
+
+ if (!pContext->m_pOptions)
+ pContext->m_pOptions = new CPDF_RenderOptions;
+// CPDF_RenderOptions options;
+ if (flags & FPDF_LCD_TEXT)
+ pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE;
+ else
+ pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE;
+ if (flags & FPDF_NO_NATIVETEXT)
+ pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT;
+ if (flags & FPDF_RENDER_LIMITEDIMAGECACHE)
+ pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
+ if (flags & FPDF_RENDER_FORCEHALFTONE)
+ pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
+ //Grayscale output
+ if (flags & FPDF_GRAYSCALE)
+ {
+ pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
+ pContext->m_pOptions->m_ForeColor = 0;
+ pContext->m_pOptions->m_BackColor = 0xffffff;
+ }
+ const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
+
+ pContext->m_pOptions->m_AddFlags = flags >> 8;
+
+ pContext->m_pOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocument, usage);
+
+
+ CFX_AffineMatrix matrix;
+ pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
+
+ FX_RECT clip;
+ clip.left = start_x;
+ clip.right = start_x + size_x;
+ clip.top = start_y;
+ clip.bottom = start_y + size_y;
+ pContext->m_pDevice->SaveState();
+ pContext->m_pDevice->SetClip_Rect(&clip);
+
+ pContext->m_pContext = FX_NEW CPDF_RenderContext;
+ pContext->m_pContext->Create(pPage);
+ pContext->m_pContext->AppendObjectList(pPage, &matrix);
+
+ if (flags & FPDF_ANNOT) {
+ pContext->m_pAnnots = FX_NEW CPDF_AnnotList(pPage);
+ FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY;
+ pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext, bPrinting, &matrix, TRUE, NULL);
+ }
+
+ pContext->m_pRenderer = FX_NEW CPDF_ProgressiveRenderer;
+ pContext->m_pRenderer->Start(pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions, pause);
+ if (bNeedToRestore)
+ {
+ pContext->m_pDevice->RestoreState();
+ }
+
+//#endif
+}
+
+DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double* width, double* height)
+{
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ if(pDoc == NULL)
+ return FALSE;
+
+ CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
+ if (pDict == NULL) return FALSE;
+
+ CPDF_Page page;
+ page.Load(pDoc, pDict);
+ *width = page.GetPageWidth();
+ *height = page.GetPageHeight();
+
+ return TRUE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document)
+{
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ if (!pDoc) return TRUE;
+ CPDF_ViewerPreferences viewRef(pDoc);
+ return viewRef.PrintScaling();
+}
+
+DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_BYTESTRING name)
+{
+ if (document == NULL)
+ return NULL;
+ if (name == NULL || name[0] == 0)
+ return NULL;
+
+ CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
+ return name_tree.LookupNamedDest(pDoc, name);
+}
diff --git a/fpdfsdk/src/fsdk_actionhandler.cpp b/fpdfsdk/src/fsdk_actionhandler.cpp
index 2a3898cd9b..5ded984c63 100644
--- a/fpdfsdk/src/fsdk_actionhandler.cpp
+++ b/fpdfsdk/src/fsdk_actionhandler.cpp
@@ -1,850 +1,850 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fsdk_mgr.h"
-#include "../include/fsdk_actionhandler.h"
-#include "../include/javascript/IJavaScript.h"
-
-/* -------------------------- CBA_ActionHandler -------------------------- */
-
-CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi) :
- m_pEvi(pEvi),
- m_pFormActionHandler(NULL),
- m_pMediaActionHandler(NULL)
-{
- m_pFormActionHandler = new CPDFSDK_FormActionHandler;
-}
-
-CPDFSDK_ActionHandler::~CPDFSDK_ActionHandler()
-{
- if(m_pFormActionHandler)
- {
- delete m_pFormActionHandler;
- m_pFormActionHandler = NULL;
- }
-}
-
-void CPDFSDK_ActionHandler::SetFormActionHandler(CPDFSDK_FormActionHandler* pHandler)
-{
- ASSERT(pHandler != NULL);
- ASSERT(m_pFormActionHandler == NULL);
- m_pFormActionHandler = pHandler;
-}
-
-void CPDFSDK_ActionHandler::SetMediaActionHandler(CPDFSDK_MediaActionHandler* pHandler)
-{
- ASSERT(pHandler != NULL);
- ASSERT(m_pMediaActionHandler == NULL);
- m_pMediaActionHandler = pHandler;
-}
-
-void CPDFSDK_ActionHandler::Destroy()
-{
- delete this;
-}
-
-//document open
-FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, CPDFSDK_Document* pDocument
- /*CReader_Document* pDocument, CReader_DocView *pDocView*/)
-{
- CFX_PtrList list;
- return ExecuteDocumentOpenAction(action, pDocument, /*pDocView, */list);
-}
-
-//document open
-FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(const CPDF_Action& JsAction,CFX_WideString csJSName,
- CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
-{
- if (JsAction.GetType() == CPDF_Action::JavaScript)
- {
- CFX_WideString swJS = JsAction.GetJavaScript();
- if (!swJS.IsEmpty())
- {
- RunDocumentOpenJavaScript(pDocument, csJSName, swJS);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAction, CPDF_AAction::AActionType type,
- CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
- PDFSDK_FieldAction& data)
-{
- CPDFDoc_Environment* pEnv = pDocument->GetEnv();
- ASSERT(pEnv);
- if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript)
- {
- CFX_WideString swJS = JsAction.GetJavaScript();
- if (!swJS.IsEmpty())
- {
- RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_ActionHandler::DoAction_Page(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,
- CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
-{
- CFX_PtrList list;
- return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list);
-}
-
-FX_BOOL CPDFSDK_ActionHandler::DoAction_Document(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,
- CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
-{
- CFX_PtrList list;
- return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list);
-}
-
-FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark *pBookMark, const CPDF_Action& action, CPDF_AAction::AActionType type,
- CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
-{
- CFX_PtrList list;
- return this->ExecuteBookMark(action, pDocument,/* pDocView,*/ pBookMark, list);
-}
-
-FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, CPDF_AAction::AActionType type,
- CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/ CPDFSDK_Annot* pScreen)
-{
- CFX_PtrList list;
- return this->ExecuteScreenAction(action, type, pDocument,/* pDocView,*/ pScreen, list);
-}
-
-FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action,
- CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
-{
- CFX_PtrList list;
- return ExecuteLinkAction(action, pDocument,/* pDocView,*/ list);
-}
-
-FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type,
- CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/
- CPDF_FormField* pFormField, PDFSDK_FieldAction& data)
-{
- CFX_PtrList list;
- return ExecuteFieldAction(action, type, pDocument,/* pDocView,*/ pFormField, data, list);
-}
-
-FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(const CPDF_Action& action, CPDFSDK_Document* pDocument,
- /*CReader_DocView *pDocView,*/ CFX_PtrList& list)
-{
- ASSERT(pDocument != NULL);
-
- if (list.Find((CPDF_Dictionary*)action))
- return FALSE;
- list.AddTail((CPDF_Dictionary*)action);
-
- CPDFDoc_Environment* pEnv = pDocument->GetEnv();
- ASSERT(pEnv);
- if (action.GetType() == CPDF_Action::JavaScript)
- {
- if(pEnv->IsJSInitiated())
- {
- CFX_WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty())
- {
- RunDocumentOpenJavaScript(pDocument, L"", swJS);
- }
- }
- }
- else
- {
- DoAction_NoJs(action, pDocument/*, pDocView*/);
- }
-
-// if (!IsValidDocView(pDocument, pDocView))
-// return FALSE;
-
- for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
- {
- CPDF_Action subaction = action.GetSubAction(i);
- if (!ExecuteDocumentOpenAction(subaction, pDocument,/* pDocView,*/ list)) return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action, CPDFSDK_Document* pDocument,
- /*CReader_DocView* pDocView,*/ CFX_PtrList& list)
-{
- ASSERT(pDocument != NULL);
-
- if (list.Find((CPDF_Dictionary*)action))
- return FALSE;
- list.AddTail((CPDF_Dictionary*)action);
-
- CPDFDoc_Environment* pEnv = pDocument->GetEnv();
- ASSERT(pEnv);
- if (action.GetType() == CPDF_Action::JavaScript)
- {
- if(pEnv->IsJSInitiated())
- {
- CFX_WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty())
- {
- IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); //????
- ASSERT(pRuntime != NULL);
-
- pRuntime->SetReaderDocument(pDocument);
-
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
-
- pContext->OnLink_MouseUp(pDocument);
-
- CFX_WideString csInfo;
- FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
- if (!bRet)
- {
- //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
- }
-
- pRuntime->ReleaseContext(pContext);
- }
- }
- }
- else
- {
- DoAction_NoJs(action, pDocument/*, pDocView*/);
- }
-
-// if (!IsValidDocView(pDocument, pDocView))
-// return FALSE;
-
- for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
- {
- CPDF_Action subaction = action.GetSubAction(i);
- if (!ExecuteLinkAction(subaction, pDocument,/* pDocView,*/ list)) return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
- CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CFX_PtrList& list)
-{
- ASSERT(pDocument != NULL);
-
- if (list.Find((CPDF_Dictionary*)action))
- return FALSE;
- list.AddTail((CPDF_Dictionary*)action);
-
- CPDFDoc_Environment* pEnv = pDocument->GetEnv();
- ASSERT(pEnv);
- if (action.GetType() == CPDF_Action::JavaScript)
- {
- if(pEnv->IsJSInitiated())
- {
- CFX_WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty())
- {
- RunDocumentPageJavaScript(pDocument, type, swJS);
- }
- }
- }
- else
- {
- DoAction_NoJs(action, pDocument/*, pDocView*/);
- }
-
- if (!IsValidDocView(pDocument/*, pDocView*/))
- return FALSE;
-
- for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
- {
- CPDF_Action subaction = action.GetSubAction(i);
- if (!ExecuteDocumentPageAction(subaction, type, pDocument,/* pDocView,*/ list)) return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, CPDF_Dictionary* pFieldDict)
-{
- ASSERT(m_pEvi != NULL);
- ASSERT(pDocument != NULL);
- ASSERT(pFieldDict != NULL);
-
- if (1/*m_pApp->IsValidDocument(pDocument)*/)
- {
- CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
- ASSERT(pPDFInterForm != NULL);
-
- return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
- CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDF_FormField* pFormField,
- PDFSDK_FieldAction& data, CFX_PtrList& list)
-{
- ASSERT(pDocument != NULL);
-
- if (list.Find((CPDF_Dictionary*)action))
- return FALSE;
- list.AddTail((CPDF_Dictionary*)action);
-
- CPDFDoc_Environment* pEnv = pDocument->GetEnv();
- ASSERT(pEnv);
- if (action.GetType() == CPDF_Action::JavaScript)
- {
- if(pEnv->IsJSInitiated())
- {
- CFX_WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty())
- {
- RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
- if (!IsValidField(pDocument, pFormField->GetFieldDict()))
- return FALSE;
- }
- }
- }
- else
- {
- DoAction_NoJs(action, pDocument/*, pDocView*/);
-// if (!IsValidDocView(pDocument, pDocView))
-// return FALSE;
- }
-
- for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
- {
- CPDF_Action subaction = action.GetSubAction(i);
- if (!ExecuteFieldAction(subaction, type, pDocument,/* pDocView,*/ pFormField, data, list)) return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
- CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDFSDK_Annot* pScreen, CFX_PtrList& list)
-{
- ASSERT(pDocument != NULL);
-
- if (list.Find((CPDF_Dictionary*)action))
- return FALSE;
- list.AddTail((CPDF_Dictionary*)action);
-
- CPDFDoc_Environment* pEnv = pDocument->GetEnv();
- ASSERT(pEnv);
- if (action.GetType() == CPDF_Action::JavaScript)
- {
- if(pEnv->IsJSInitiated())
- {
- CFX_WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty())
- {
- IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->SetReaderDocument(pDocument);
-
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
-
- // switch (type)
- // {
- // case CPDF_AAction::CursorEnter:
- // pContext->OnScreen_MouseEnter(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // case CPDF_AAction::CursorExit:
- // pContext->OnScreen_MouseExit(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // case CPDF_AAction::ButtonDown:
- // pContext->OnScreen_MouseDown(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // case CPDF_AAction::ButtonUp:
- // pContext->OnScreen_MouseUp(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // case CPDF_AAction::GetFocus:
- // pContext->OnScreen_Focus(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // case CPDF_AAction::LoseFocus:
- // pContext->OnScreen_Blur(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // case CPDF_AAction::PageOpen:
- // pContext->OnScreen_Open(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // case CPDF_AAction::PageClose:
- // pContext->OnScreen_Close(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // case CPDF_AAction::PageVisible:
- // pContext->OnScreen_InView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // case CPDF_AAction::PageInvisible:
- // pContext->OnScreen_OutView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
- // break;
- // default:
- // ASSERT(FALSE);
- // break;
- // }
-
- CFX_WideString csInfo;
- FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
- if (!bRet)
- {
- //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
- }
-
- pRuntime->ReleaseContext(pContext);
- }
- }
- }
- else
- {
- DoAction_NoJs(action, pDocument/*, pDocView*/);
- }
-
-// if (!IsValidDocView(pDocument, pDocView))
-// return FALSE;
-
- for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
- {
- CPDF_Action subaction = action.GetSubAction(i);
- if (!ExecuteScreenAction(subaction, type, pDocument,/* pDocView,*/ pScreen, list)) return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSDK_Document* pDocument,
- /*CReader_DocView* pDocView,*/ CPDF_Bookmark* pBookmark, CFX_PtrList& list)
-{
- ASSERT(pDocument != NULL);
-
- if (list.Find((CPDF_Dictionary*)action))
- return FALSE;
- list.AddTail((CPDF_Dictionary*)action);
-
- CPDFDoc_Environment* pEnv = pDocument->GetEnv();
- ASSERT(pEnv);
- if (action.GetType() == CPDF_Action::JavaScript)
- {
- if(pEnv->IsJSInitiated())
- {
- CFX_WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty())
- {
- IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->SetReaderDocument(pDocument);
-
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
-
- pContext->OnBookmark_MouseUp(pBookmark);
-
- CFX_WideString csInfo;
- FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
- if (!bRet)
- {
- //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
- }
-
- pRuntime->ReleaseContext(pContext);
- }
- }
- }
- else
- {
- DoAction_NoJs(action, pDocument/*, pDocView*/);
- }
-
-// if (!IsValidDocView(pDocument, pDocView))
-// return FALSE;
-
- for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
- {
- CPDF_Action subaction = action.GetSubAction(i);
- if (!ExecuteBookMark(subaction, pDocument,/* pDocView,*/ pBookmark, list)) return FALSE;
- }
-
- return TRUE;
-}
-
-void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/)
-{
- ASSERT(pDocument != NULL);
-
- switch (action.GetType())
- {
- case CPDF_Action::GoTo:
- DoAction_GoTo(pDocument,/* pDocView,*/ action);
- break;
- case CPDF_Action::GoToR:
- DoAction_GoToR(pDocument, action);
- break;
- case CPDF_Action::GoToE:
- break;
- case CPDF_Action::Launch:
- DoAction_Launch(pDocument, action);
- break;
- case CPDF_Action::Thread:
- break;
- case CPDF_Action::URI:
- DoAction_URI(pDocument, action);
- break;
- case CPDF_Action::Sound:
- if (m_pMediaActionHandler)
- {
- m_pMediaActionHandler->DoAction_Sound(action, pDocument/*, pDocView*/);
- }
- break;
- case CPDF_Action::Movie:
- if (m_pMediaActionHandler)
- {
- m_pMediaActionHandler->DoAction_Movie(action, pDocument/*, pDocView*/);
- }
- break;
- case CPDF_Action::Hide:
- if (m_pFormActionHandler)
- {
- m_pFormActionHandler->DoAction_Hide(action, pDocument);
- }
- break;
- case CPDF_Action::Named:
- DoAction_Named(pDocument, action);
- break;
- case CPDF_Action::SubmitForm:
- if (m_pFormActionHandler)
- {
- m_pFormActionHandler->DoAction_SubmitForm(action, pDocument/*, pDocView*/);
- }
- break;
- case CPDF_Action::ResetForm:
- if (m_pFormActionHandler)
- {
- m_pFormActionHandler->DoAction_ResetForm(action, pDocument);
- }
- break;
- case CPDF_Action::ImportData:
- if (m_pFormActionHandler)
- {
- m_pFormActionHandler->DoAction_ImportData(action, pDocument/*, pDocView*/);
- }
- break;
- case CPDF_Action::JavaScript:
- ASSERT(FALSE);
- break;
- case CPDF_Action::SetOCGState:
- DoAction_SetOCGState(pDocument, /*pDocView,*/ action);
- break;
- case CPDF_Action::Rendition:
- if (m_pMediaActionHandler)
- {
- m_pMediaActionHandler->DoAction_Rendition(action, pDocument/*, pDocView*/);
- }
- break;
- case CPDF_Action::Trans:
- break;
- case CPDF_Action::GoTo3DView:
- break;
- default:
- break;
- }
-}
-
-FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/)
-{
- ASSERT(pDocument != NULL);
- //ASSERT(pDocView != NULL);
-
- //return pDocument->IsValidDocView(pDocView);
- return TRUE;
-}
-
-void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, /*CReader_DocView* pDocView,*/
- const CPDF_Action& action)
-{
- ASSERT(pDocument != NULL);
-// ASSERT(pDocView != NULL);
- ASSERT(action != NULL);
-
- CPDF_Document* pPDFDocument = pDocument->GetDocument();
- ASSERT(pPDFDocument != NULL);
- CPDFDoc_Environment* pApp = pDocument->GetEnv();
- ASSERT(pApp != NULL);
-
- CPDF_Dest MyDest = action.GetDest(pPDFDocument);
- int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
- int nFitType = MyDest.GetZoomMode();
- const CPDF_Array * pMyArray = (CPDF_Array*)MyDest.m_pObj;
- float* pPosAry = NULL;
- int sizeOfAry = 0;
- if (pMyArray != NULL)
- {
- pPosAry = new float[pMyArray->GetCount()];
- int j = 0;
- for (int i = 2; i < (int)pMyArray->GetCount(); i++)
- {
- pPosAry[j++] = pMyArray->GetFloat(i);
- }
- sizeOfAry = j;
- }
- pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
- if(pPosAry)
- delete[] pPosAry;
-}
-
-void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, const CPDF_Action& action)
-{
-
-}
-
-void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, const CPDF_Action& action)
-{
-
-}
-
-void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action)
-{
- ASSERT(pDocument != NULL);
- ASSERT(action != NULL);
-
- CPDFDoc_Environment* pApp = pDocument->GetEnv();
- ASSERT(pApp != NULL);
-
- CFX_ByteString sURI = action.GetURI(pDocument->GetDocument());
- pApp->FFI_DoURIAction(FX_LPCSTR(sURI));
-}
-
-void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action)
-{
- ASSERT(pDocument != NULL);
- ASSERT(action != NULL);
-
- CFX_ByteString csName = action.GetNamedAction();
- pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
-}
-
-
-void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ const CPDF_Action& action)
-{
-}
-
-void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, CPDF_AAction::AActionType type,
- PDFSDK_FieldAction& data, const CFX_WideString& script)
-{
- ASSERT(type != CPDF_AAction::Calculate);
- ASSERT(type != CPDF_AAction::Format);
-
- ASSERT(pDocument != NULL);
-
- IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->SetReaderDocument(pDocument);
-
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
-
- switch (type)
- {
- case CPDF_AAction::CursorEnter:
- pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
- break;
- case CPDF_AAction::CursorExit:
- pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
- break;
- case CPDF_AAction::ButtonDown:
- pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
- break;
- case CPDF_AAction::ButtonUp:
- pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
- break;
- case CPDF_AAction::GetFocus:
- pContext->OnField_Focus(data.bModifier, data.bShift, pFormField, data.sValue);
- break;
- case CPDF_AAction::LoseFocus:
- pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, data.sValue);
- break;
- case CPDF_AAction::KeyStroke:
- pContext->OnField_Keystroke(data.nCommitKey, data.sChange, data.sChangeEx, data.bKeyDown,
- data.bModifier, data.nSelEnd, data.nSelStart, data.bShift, pFormField, data.sValue,
- data.bWillCommit, data.bFieldFull, data.bRC);
- break;
- case CPDF_AAction::Validate:
- pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown, data.bModifier,
- data.bShift, pFormField, data.sValue, data.bRC);
- break;
- default:
- ASSERT(FALSE);
- break;
- }
-
- CFX_WideString csInfo;
- FX_BOOL bRet = pContext->RunScript(script, csInfo);
- if (!bRet)
- {
- //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
- }
-
- pRuntime->ReleaseContext(pContext);
-}
-
-void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(CPDFSDK_Document* pDocument, const CFX_WideString& sScriptName, const CFX_WideString& script)
-{
- ASSERT(pDocument != NULL);
-
- IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->SetReaderDocument(pDocument);
-
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
-
- pContext->OnDoc_Open(pDocument, sScriptName);
-
- CFX_WideString csInfo;
- FX_BOOL bRet = pContext->RunScript(script, csInfo);
- if (!bRet)
- {
- //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
- }
-
- pRuntime->ReleaseContext(pContext);
-}
-
-void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocument, CPDF_AAction::AActionType type, const CFX_WideString& script)
-{
- ASSERT(pDocument != NULL);
-
- IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->SetReaderDocument(pDocument);
-
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
-
- switch (type)
- {
- case CPDF_AAction::OpenPage:
- pContext->OnPage_Open(pDocument);
- break;
- case CPDF_AAction::ClosePage:
- pContext->OnPage_Close(pDocument);
- break;
- case CPDF_AAction::CloseDocument:
- pContext->OnDoc_WillClose(pDocument);
- break;
- case CPDF_AAction::SaveDocument:
- pContext->OnDoc_WillSave(pDocument);
- break;
- case CPDF_AAction::DocumentSaved:
- pContext->OnDoc_DidSave(pDocument);
- break;
- case CPDF_AAction::PrintDocument:
- pContext->OnDoc_WillPrint(pDocument);
- break;
- case CPDF_AAction::DocumentPrinted:
- pContext->OnDoc_DidPrint(pDocument);
- break;
- case CPDF_AAction::PageVisible:
- pContext->OnPage_InView(pDocument);
- break;
- case CPDF_AAction::PageInvisible:
- pContext->OnPage_OutView(pDocument);
- break;
- default:
- ASSERT(FALSE);
- break;
- }
-
- CFX_WideString csInfo;
- FX_BOOL bRet = pContext->RunScript(script, csInfo);
- if (!bRet)
- {
- //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
- }
-
- pRuntime->ReleaseContext(pContext);
-}
-
-
-FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- if (pInterForm->DoAction_Hide(action))
- {
- pDocument->SetChangeMark();
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- return pInterForm->DoAction_SubmitForm(action);
-}
-
-FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- if (pInterForm->DoAction_ResetForm(action))
- {
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(const CPDF_Action& action, CPDFSDK_Document* pDocument)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- if (pInterForm->DoAction_ImportData(action))
- {
- pDocument->SetChangeMark();
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(const CPDF_Action& action, CPDFSDK_Document* pDocument)
-{
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(const CPDF_Action& action, CPDFSDK_Document* pDocument)
-{
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(const CPDF_Action& action, CPDFSDK_Document* pDocument)
-{
- return FALSE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fsdk_mgr.h"
+#include "../include/fsdk_actionhandler.h"
+#include "../include/javascript/IJavaScript.h"
+
+/* -------------------------- CBA_ActionHandler -------------------------- */
+
+CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi) :
+ m_pEvi(pEvi),
+ m_pFormActionHandler(NULL),
+ m_pMediaActionHandler(NULL)
+{
+ m_pFormActionHandler = new CPDFSDK_FormActionHandler;
+}
+
+CPDFSDK_ActionHandler::~CPDFSDK_ActionHandler()
+{
+ if(m_pFormActionHandler)
+ {
+ delete m_pFormActionHandler;
+ m_pFormActionHandler = NULL;
+ }
+}
+
+void CPDFSDK_ActionHandler::SetFormActionHandler(CPDFSDK_FormActionHandler* pHandler)
+{
+ ASSERT(pHandler != NULL);
+ ASSERT(m_pFormActionHandler == NULL);
+ m_pFormActionHandler = pHandler;
+}
+
+void CPDFSDK_ActionHandler::SetMediaActionHandler(CPDFSDK_MediaActionHandler* pHandler)
+{
+ ASSERT(pHandler != NULL);
+ ASSERT(m_pMediaActionHandler == NULL);
+ m_pMediaActionHandler = pHandler;
+}
+
+void CPDFSDK_ActionHandler::Destroy()
+{
+ delete this;
+}
+
+//document open
+FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, CPDFSDK_Document* pDocument
+ /*CReader_Document* pDocument, CReader_DocView *pDocView*/)
+{
+ CFX_PtrList list;
+ return ExecuteDocumentOpenAction(action, pDocument, /*pDocView, */list);
+}
+
+//document open
+FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(const CPDF_Action& JsAction,CFX_WideString csJSName,
+ CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
+{
+ if (JsAction.GetType() == CPDF_Action::JavaScript)
+ {
+ CFX_WideString swJS = JsAction.GetJavaScript();
+ if (!swJS.IsEmpty())
+ {
+ RunDocumentOpenJavaScript(pDocument, csJSName, swJS);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAction, CPDF_AAction::AActionType type,
+ CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
+ PDFSDK_FieldAction& data)
+{
+ CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+ ASSERT(pEnv);
+ if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript)
+ {
+ CFX_WideString swJS = JsAction.GetJavaScript();
+ if (!swJS.IsEmpty())
+ {
+ RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::DoAction_Page(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,
+ CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
+{
+ CFX_PtrList list;
+ return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list);
+}
+
+FX_BOOL CPDFSDK_ActionHandler::DoAction_Document(const CPDF_Action& action, enum CPDF_AAction::AActionType eType,
+ CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
+{
+ CFX_PtrList list;
+ return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list);
+}
+
+FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark *pBookMark, const CPDF_Action& action, CPDF_AAction::AActionType type,
+ CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
+{
+ CFX_PtrList list;
+ return this->ExecuteBookMark(action, pDocument,/* pDocView,*/ pBookMark, list);
+}
+
+FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, CPDF_AAction::AActionType type,
+ CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/ CPDFSDK_Annot* pScreen)
+{
+ CFX_PtrList list;
+ return this->ExecuteScreenAction(action, type, pDocument,/* pDocView,*/ pScreen, list);
+}
+
+FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action,
+ CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/)
+{
+ CFX_PtrList list;
+ return ExecuteLinkAction(action, pDocument,/* pDocView,*/ list);
+}
+
+FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type,
+ CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/
+ CPDF_FormField* pFormField, PDFSDK_FieldAction& data)
+{
+ CFX_PtrList list;
+ return ExecuteFieldAction(action, type, pDocument,/* pDocView,*/ pFormField, data, list);
+}
+
+FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(const CPDF_Action& action, CPDFSDK_Document* pDocument,
+ /*CReader_DocView *pDocView,*/ CFX_PtrList& list)
+{
+ ASSERT(pDocument != NULL);
+
+ if (list.Find((CPDF_Dictionary*)action))
+ return FALSE;
+ list.AddTail((CPDF_Dictionary*)action);
+
+ CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+ ASSERT(pEnv);
+ if (action.GetType() == CPDF_Action::JavaScript)
+ {
+ if(pEnv->IsJSInitiated())
+ {
+ CFX_WideString swJS = action.GetJavaScript();
+ if (!swJS.IsEmpty())
+ {
+ RunDocumentOpenJavaScript(pDocument, L"", swJS);
+ }
+ }
+ }
+ else
+ {
+ DoAction_NoJs(action, pDocument/*, pDocView*/);
+ }
+
+// if (!IsValidDocView(pDocument, pDocView))
+// return FALSE;
+
+ for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+ {
+ CPDF_Action subaction = action.GetSubAction(i);
+ if (!ExecuteDocumentOpenAction(subaction, pDocument,/* pDocView,*/ list)) return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action, CPDFSDK_Document* pDocument,
+ /*CReader_DocView* pDocView,*/ CFX_PtrList& list)
+{
+ ASSERT(pDocument != NULL);
+
+ if (list.Find((CPDF_Dictionary*)action))
+ return FALSE;
+ list.AddTail((CPDF_Dictionary*)action);
+
+ CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+ ASSERT(pEnv);
+ if (action.GetType() == CPDF_Action::JavaScript)
+ {
+ if(pEnv->IsJSInitiated())
+ {
+ CFX_WideString swJS = action.GetJavaScript();
+ if (!swJS.IsEmpty())
+ {
+ IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); //????
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->SetReaderDocument(pDocument);
+
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+
+ pContext->OnLink_MouseUp(pDocument);
+
+ CFX_WideString csInfo;
+ FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
+ if (!bRet)
+ {
+ //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+ }
+
+ pRuntime->ReleaseContext(pContext);
+ }
+ }
+ }
+ else
+ {
+ DoAction_NoJs(action, pDocument/*, pDocView*/);
+ }
+
+// if (!IsValidDocView(pDocument, pDocView))
+// return FALSE;
+
+ for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+ {
+ CPDF_Action subaction = action.GetSubAction(i);
+ if (!ExecuteLinkAction(subaction, pDocument,/* pDocView,*/ list)) return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
+ CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CFX_PtrList& list)
+{
+ ASSERT(pDocument != NULL);
+
+ if (list.Find((CPDF_Dictionary*)action))
+ return FALSE;
+ list.AddTail((CPDF_Dictionary*)action);
+
+ CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+ ASSERT(pEnv);
+ if (action.GetType() == CPDF_Action::JavaScript)
+ {
+ if(pEnv->IsJSInitiated())
+ {
+ CFX_WideString swJS = action.GetJavaScript();
+ if (!swJS.IsEmpty())
+ {
+ RunDocumentPageJavaScript(pDocument, type, swJS);
+ }
+ }
+ }
+ else
+ {
+ DoAction_NoJs(action, pDocument/*, pDocView*/);
+ }
+
+ if (!IsValidDocView(pDocument/*, pDocView*/))
+ return FALSE;
+
+ for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+ {
+ CPDF_Action subaction = action.GetSubAction(i);
+ if (!ExecuteDocumentPageAction(subaction, type, pDocument,/* pDocView,*/ list)) return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, CPDF_Dictionary* pFieldDict)
+{
+ ASSERT(m_pEvi != NULL);
+ ASSERT(pDocument != NULL);
+ ASSERT(pFieldDict != NULL);
+
+ if (1/*m_pApp->IsValidDocument(pDocument)*/)
+ {
+ CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
+ ASSERT(pPDFInterForm != NULL);
+
+ return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
+ CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDF_FormField* pFormField,
+ PDFSDK_FieldAction& data, CFX_PtrList& list)
+{
+ ASSERT(pDocument != NULL);
+
+ if (list.Find((CPDF_Dictionary*)action))
+ return FALSE;
+ list.AddTail((CPDF_Dictionary*)action);
+
+ CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+ ASSERT(pEnv);
+ if (action.GetType() == CPDF_Action::JavaScript)
+ {
+ if(pEnv->IsJSInitiated())
+ {
+ CFX_WideString swJS = action.GetJavaScript();
+ if (!swJS.IsEmpty())
+ {
+ RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
+ if (!IsValidField(pDocument, pFormField->GetFieldDict()))
+ return FALSE;
+ }
+ }
+ }
+ else
+ {
+ DoAction_NoJs(action, pDocument/*, pDocView*/);
+// if (!IsValidDocView(pDocument, pDocView))
+// return FALSE;
+ }
+
+ for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+ {
+ CPDF_Action subaction = action.GetSubAction(i);
+ if (!ExecuteFieldAction(subaction, type, pDocument,/* pDocView,*/ pFormField, data, list)) return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CPDF_AAction::AActionType type,
+ CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDFSDK_Annot* pScreen, CFX_PtrList& list)
+{
+ ASSERT(pDocument != NULL);
+
+ if (list.Find((CPDF_Dictionary*)action))
+ return FALSE;
+ list.AddTail((CPDF_Dictionary*)action);
+
+ CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+ ASSERT(pEnv);
+ if (action.GetType() == CPDF_Action::JavaScript)
+ {
+ if(pEnv->IsJSInitiated())
+ {
+ CFX_WideString swJS = action.GetJavaScript();
+ if (!swJS.IsEmpty())
+ {
+ IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->SetReaderDocument(pDocument);
+
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+
+ // switch (type)
+ // {
+ // case CPDF_AAction::CursorEnter:
+ // pContext->OnScreen_MouseEnter(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // case CPDF_AAction::CursorExit:
+ // pContext->OnScreen_MouseExit(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // case CPDF_AAction::ButtonDown:
+ // pContext->OnScreen_MouseDown(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // case CPDF_AAction::ButtonUp:
+ // pContext->OnScreen_MouseUp(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // case CPDF_AAction::GetFocus:
+ // pContext->OnScreen_Focus(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // case CPDF_AAction::LoseFocus:
+ // pContext->OnScreen_Blur(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // case CPDF_AAction::PageOpen:
+ // pContext->OnScreen_Open(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // case CPDF_AAction::PageClose:
+ // pContext->OnScreen_Close(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // case CPDF_AAction::PageVisible:
+ // pContext->OnScreen_InView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // case CPDF_AAction::PageInvisible:
+ // pContext->OnScreen_OutView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
+ // break;
+ // default:
+ // ASSERT(FALSE);
+ // break;
+ // }
+
+ CFX_WideString csInfo;
+ FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
+ if (!bRet)
+ {
+ //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+ }
+
+ pRuntime->ReleaseContext(pContext);
+ }
+ }
+ }
+ else
+ {
+ DoAction_NoJs(action, pDocument/*, pDocView*/);
+ }
+
+// if (!IsValidDocView(pDocument, pDocView))
+// return FALSE;
+
+ for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+ {
+ CPDF_Action subaction = action.GetSubAction(i);
+ if (!ExecuteScreenAction(subaction, type, pDocument,/* pDocView,*/ pScreen, list)) return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSDK_Document* pDocument,
+ /*CReader_DocView* pDocView,*/ CPDF_Bookmark* pBookmark, CFX_PtrList& list)
+{
+ ASSERT(pDocument != NULL);
+
+ if (list.Find((CPDF_Dictionary*)action))
+ return FALSE;
+ list.AddTail((CPDF_Dictionary*)action);
+
+ CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+ ASSERT(pEnv);
+ if (action.GetType() == CPDF_Action::JavaScript)
+ {
+ if(pEnv->IsJSInitiated())
+ {
+ CFX_WideString swJS = action.GetJavaScript();
+ if (!swJS.IsEmpty())
+ {
+ IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->SetReaderDocument(pDocument);
+
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+
+ pContext->OnBookmark_MouseUp(pBookmark);
+
+ CFX_WideString csInfo;
+ FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
+ if (!bRet)
+ {
+ //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+ }
+
+ pRuntime->ReleaseContext(pContext);
+ }
+ }
+ }
+ else
+ {
+ DoAction_NoJs(action, pDocument/*, pDocView*/);
+ }
+
+// if (!IsValidDocView(pDocument, pDocView))
+// return FALSE;
+
+ for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
+ {
+ CPDF_Action subaction = action.GetSubAction(i);
+ if (!ExecuteBookMark(subaction, pDocument,/* pDocView,*/ pBookmark, list)) return FALSE;
+ }
+
+ return TRUE;
+}
+
+void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/)
+{
+ ASSERT(pDocument != NULL);
+
+ switch (action.GetType())
+ {
+ case CPDF_Action::GoTo:
+ DoAction_GoTo(pDocument,/* pDocView,*/ action);
+ break;
+ case CPDF_Action::GoToR:
+ DoAction_GoToR(pDocument, action);
+ break;
+ case CPDF_Action::GoToE:
+ break;
+ case CPDF_Action::Launch:
+ DoAction_Launch(pDocument, action);
+ break;
+ case CPDF_Action::Thread:
+ break;
+ case CPDF_Action::URI:
+ DoAction_URI(pDocument, action);
+ break;
+ case CPDF_Action::Sound:
+ if (m_pMediaActionHandler)
+ {
+ m_pMediaActionHandler->DoAction_Sound(action, pDocument/*, pDocView*/);
+ }
+ break;
+ case CPDF_Action::Movie:
+ if (m_pMediaActionHandler)
+ {
+ m_pMediaActionHandler->DoAction_Movie(action, pDocument/*, pDocView*/);
+ }
+ break;
+ case CPDF_Action::Hide:
+ if (m_pFormActionHandler)
+ {
+ m_pFormActionHandler->DoAction_Hide(action, pDocument);
+ }
+ break;
+ case CPDF_Action::Named:
+ DoAction_Named(pDocument, action);
+ break;
+ case CPDF_Action::SubmitForm:
+ if (m_pFormActionHandler)
+ {
+ m_pFormActionHandler->DoAction_SubmitForm(action, pDocument/*, pDocView*/);
+ }
+ break;
+ case CPDF_Action::ResetForm:
+ if (m_pFormActionHandler)
+ {
+ m_pFormActionHandler->DoAction_ResetForm(action, pDocument);
+ }
+ break;
+ case CPDF_Action::ImportData:
+ if (m_pFormActionHandler)
+ {
+ m_pFormActionHandler->DoAction_ImportData(action, pDocument/*, pDocView*/);
+ }
+ break;
+ case CPDF_Action::JavaScript:
+ ASSERT(FALSE);
+ break;
+ case CPDF_Action::SetOCGState:
+ DoAction_SetOCGState(pDocument, /*pDocView,*/ action);
+ break;
+ case CPDF_Action::Rendition:
+ if (m_pMediaActionHandler)
+ {
+ m_pMediaActionHandler->DoAction_Rendition(action, pDocument/*, pDocView*/);
+ }
+ break;
+ case CPDF_Action::Trans:
+ break;
+ case CPDF_Action::GoTo3DView:
+ break;
+ default:
+ break;
+ }
+}
+
+FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/)
+{
+ ASSERT(pDocument != NULL);
+ //ASSERT(pDocView != NULL);
+
+ //return pDocument->IsValidDocView(pDocView);
+ return TRUE;
+}
+
+void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, /*CReader_DocView* pDocView,*/
+ const CPDF_Action& action)
+{
+ ASSERT(pDocument != NULL);
+// ASSERT(pDocView != NULL);
+ ASSERT(action != NULL);
+
+ CPDF_Document* pPDFDocument = pDocument->GetDocument();
+ ASSERT(pPDFDocument != NULL);
+ CPDFDoc_Environment* pApp = pDocument->GetEnv();
+ ASSERT(pApp != NULL);
+
+ CPDF_Dest MyDest = action.GetDest(pPDFDocument);
+ int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
+ int nFitType = MyDest.GetZoomMode();
+ const CPDF_Array * pMyArray = (CPDF_Array*)MyDest.m_pObj;
+ float* pPosAry = NULL;
+ int sizeOfAry = 0;
+ if (pMyArray != NULL)
+ {
+ pPosAry = new float[pMyArray->GetCount()];
+ int j = 0;
+ for (int i = 2; i < (int)pMyArray->GetCount(); i++)
+ {
+ pPosAry[j++] = pMyArray->GetFloat(i);
+ }
+ sizeOfAry = j;
+ }
+ pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
+ if(pPosAry)
+ delete[] pPosAry;
+}
+
+void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, const CPDF_Action& action)
+{
+
+}
+
+void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, const CPDF_Action& action)
+{
+
+}
+
+void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action)
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(action != NULL);
+
+ CPDFDoc_Environment* pApp = pDocument->GetEnv();
+ ASSERT(pApp != NULL);
+
+ CFX_ByteString sURI = action.GetURI(pDocument->GetDocument());
+ pApp->FFI_DoURIAction(FX_LPCSTR(sURI));
+}
+
+void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action)
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(action != NULL);
+
+ CFX_ByteString csName = action.GetNamedAction();
+ pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
+}
+
+
+void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ const CPDF_Action& action)
+{
+}
+
+void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, CPDF_AAction::AActionType type,
+ PDFSDK_FieldAction& data, const CFX_WideString& script)
+{
+ ASSERT(type != CPDF_AAction::Calculate);
+ ASSERT(type != CPDF_AAction::Format);
+
+ ASSERT(pDocument != NULL);
+
+ IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->SetReaderDocument(pDocument);
+
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+
+ switch (type)
+ {
+ case CPDF_AAction::CursorEnter:
+ pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
+ break;
+ case CPDF_AAction::CursorExit:
+ pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
+ break;
+ case CPDF_AAction::ButtonDown:
+ pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
+ break;
+ case CPDF_AAction::ButtonUp:
+ pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
+ break;
+ case CPDF_AAction::GetFocus:
+ pContext->OnField_Focus(data.bModifier, data.bShift, pFormField, data.sValue);
+ break;
+ case CPDF_AAction::LoseFocus:
+ pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, data.sValue);
+ break;
+ case CPDF_AAction::KeyStroke:
+ pContext->OnField_Keystroke(data.nCommitKey, data.sChange, data.sChangeEx, data.bKeyDown,
+ data.bModifier, data.nSelEnd, data.nSelStart, data.bShift, pFormField, data.sValue,
+ data.bWillCommit, data.bFieldFull, data.bRC);
+ break;
+ case CPDF_AAction::Validate:
+ pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown, data.bModifier,
+ data.bShift, pFormField, data.sValue, data.bRC);
+ break;
+ default:
+ ASSERT(FALSE);
+ break;
+ }
+
+ CFX_WideString csInfo;
+ FX_BOOL bRet = pContext->RunScript(script, csInfo);
+ if (!bRet)
+ {
+ //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+ }
+
+ pRuntime->ReleaseContext(pContext);
+}
+
+void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(CPDFSDK_Document* pDocument, const CFX_WideString& sScriptName, const CFX_WideString& script)
+{
+ ASSERT(pDocument != NULL);
+
+ IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->SetReaderDocument(pDocument);
+
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+
+ pContext->OnDoc_Open(pDocument, sScriptName);
+
+ CFX_WideString csInfo;
+ FX_BOOL bRet = pContext->RunScript(script, csInfo);
+ if (!bRet)
+ {
+ //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+ }
+
+ pRuntime->ReleaseContext(pContext);
+}
+
+void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocument, CPDF_AAction::AActionType type, const CFX_WideString& script)
+{
+ ASSERT(pDocument != NULL);
+
+ IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->SetReaderDocument(pDocument);
+
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+
+ switch (type)
+ {
+ case CPDF_AAction::OpenPage:
+ pContext->OnPage_Open(pDocument);
+ break;
+ case CPDF_AAction::ClosePage:
+ pContext->OnPage_Close(pDocument);
+ break;
+ case CPDF_AAction::CloseDocument:
+ pContext->OnDoc_WillClose(pDocument);
+ break;
+ case CPDF_AAction::SaveDocument:
+ pContext->OnDoc_WillSave(pDocument);
+ break;
+ case CPDF_AAction::DocumentSaved:
+ pContext->OnDoc_DidSave(pDocument);
+ break;
+ case CPDF_AAction::PrintDocument:
+ pContext->OnDoc_WillPrint(pDocument);
+ break;
+ case CPDF_AAction::DocumentPrinted:
+ pContext->OnDoc_DidPrint(pDocument);
+ break;
+ case CPDF_AAction::PageVisible:
+ pContext->OnPage_InView(pDocument);
+ break;
+ case CPDF_AAction::PageInvisible:
+ pContext->OnPage_OutView(pDocument);
+ break;
+ default:
+ ASSERT(FALSE);
+ break;
+ }
+
+ CFX_WideString csInfo;
+ FX_BOOL bRet = pContext->RunScript(script, csInfo);
+ if (!bRet)
+ {
+ //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
+ }
+
+ pRuntime->ReleaseContext(pContext);
+}
+
+
+FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ if (pInterForm->DoAction_Hide(action))
+ {
+ pDocument->SetChangeMark();
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ return pInterForm->DoAction_SubmitForm(action);
+}
+
+FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ if (pInterForm->DoAction_ResetForm(action))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ if (pInterForm->DoAction_ImportData(action))
+ {
+ pDocument->SetChangeMark();
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(const CPDF_Action& action, CPDFSDK_Document* pDocument)
+{
+ return FALSE;
+}
+
diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp
index b2a24a8dde..9f208d34e2 100644
--- a/fpdfsdk/src/fsdk_annothandler.cpp
+++ b/fpdfsdk/src/fsdk_annothandler.cpp
@@ -1,945 +1,945 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fsdk_mgr.h"
-#include "../include/formfiller/FFL_FormFiller.h"
-#include "../include/fsdk_annothandler.h"
-
-
-CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp)
-{
- m_pApp = pApp;
-
- CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
- pHandler->SetFormFiller(m_pApp->GetIFormFiller());
- RegisterAnnotHandler(pHandler);
-}
-
-CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr()
-{
- for(int i=0; i<m_Handlers.GetSize(); i++)
- {
- IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
- delete pHandler;
- }
- m_Handlers.RemoveAll();
- m_mapType2Handler.RemoveAll();
-}
-
-void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler)
-{
- ASSERT(pAnnotHandler != NULL);
-
- ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL);
-
- m_Handlers.Add(pAnnotHandler);
- m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler);
-}
-
-void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler)
-{
- ASSERT(pAnnotHandler != NULL);
-
- m_mapType2Handler.RemoveKey(pAnnotHandler->GetType());
-
- for (int i=0, sz=m_Handlers.GetSize(); i<sz; i++)
- {
- if (m_Handlers.GetAt(i) == pAnnotHandler)
- {
- m_Handlers.RemoveAt(i);
- break;
- }
- }
-}
-
-CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_PageView *pPageView)
-{
- ASSERT(pAnnot != NULL);
- ASSERT(pPageView != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot->GetSubType()))
- {
- return pAnnotHandler->NewAnnot(pAnnot, pPageView);
- }
-
- return new CPDFSDK_Annot(pAnnot, pPageView);
-}
-
-void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
-
- pAnnot->GetPDFPage();
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- pAnnotHandler->OnRelease(pAnnot);
- pAnnotHandler->ReleaseAnnot(pAnnot);
- }
- else
- {
- delete (CPDFSDK_Annot*)pAnnot;
- }
-}
-
-void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
-
- CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
- ASSERT(pPDFAnnot != NULL);
- ASSERT(pPDFAnnot->m_pAnnotDict != NULL);
-
- CPDFSDK_DateTime curTime;
- pPDFAnnot->m_pAnnotDict->SetAtString("M", curTime.ToPDFDateTimeString());
- pPDFAnnot->m_pAnnotDict->SetAtNumber("F", (int)0);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- pAnnotHandler->OnCreate(pAnnot);
- }
-}
-
-void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- pAnnotHandler->OnLoad(pAnnot);
- }
-}
-
-IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(CPDFSDK_Annot* pAnnot) const
-{
- ASSERT(pAnnot != NULL);
-
- CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
- ASSERT(pPDFAnnot != NULL);
-
- return GetAnnotHandler(pPDFAnnot->GetSubType());
-}
-
-IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(const CFX_ByteString& sType) const
-{
- void* pRet = NULL;
- m_mapType2Handler.Lookup(sType, pRet);
- return (IPDFSDK_AnnotHandler*)pRet;
-}
-
-void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,FX_DWORD dwFlags)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
- }
- else
- {
- pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
- }
-}
-
-
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
- }
- return FALSE;
-}
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
- {
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
- }
- return FALSE;
- }
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
- }
- return FALSE;
-}
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
- }
- return FALSE;
-}
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->OnMouseWheel(pPageView, pAnnot,nFlags,zDelta, point);
- }
- return FALSE;
-}
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
- }
- return FALSE;
-}
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
- }
- return FALSE;
-}
-
-void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
- }
- return ;
-}
-
-void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
- }
- return;
-}
-
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags)
-{
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->OnChar(pAnnot,nChar, nFlags);
- }
- return FALSE;
-
-}
-
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
-{
-
- if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag))
- {
- CPDFSDK_PageView* pPage = pAnnot->GetPageView();
- CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
- if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab))
- {
- CPDFSDK_Annot* pNext = GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
-
- if(pNext && pNext != pFocusAnnot)
- {
- CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
- pDocument->SetFocusAnnot(pNext);
- return TRUE;
- }
- }
- }
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->OnKeyDown(pAnnot,nKeyCode, nFlag);
- }
- return FALSE;
-}
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
-{
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- if (pAnnotHandler->OnSetFocus(pAnnot, nFlag))
- {
- CPDFSDK_PageView* pPage = pAnnot->GetPageView();
- ASSERT(pPage != NULL);
-
- pPage->GetSDKDocument();
- // pDocument->SetTopmostAnnot(pAnnot);
-
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
-{
- ASSERT(pAnnot != NULL);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- if (pAnnotHandler->OnKillFocus(pAnnot, nFlag))
- {
- return TRUE;
- }
- else
- return FALSE;
- }
-
- return FALSE;
-}
-
-CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot);
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
- }
- return pAnnot->GetRect();
-}
-
-FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point)
-{
- ASSERT(pAnnot);
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- {
- if(pAnnotHandler->CanAnswer(pAnnot))
- return pAnnotHandler->HitTest(pPageView, pAnnot, point);
- }
- return FALSE;
-}
-
-CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext)
-{
- CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
-
- CPDFSDK_Annot* pNext = bNext ?
- ai.GetNextAnnot(pSDKAnnot) :
- ai.GetPrevAnnot(pSDKAnnot);
-
- return pNext;
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot);
- ASSERT(pAnnot->GetType() == "Widget");
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- if (!pWidget->IsVisible()) return FALSE;
-
- int nFieldFlags = pWidget->GetFieldFlags();
- if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) return FALSE;
- if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
- return TRUE;
- else
- {
- CPDF_Page* pPage = pWidget->GetPDFPage();
- ASSERT(pPage != NULL);
-
- CPDF_Document* pDocument = pPage->m_pDocument;
- ASSERT(pDocument != NULL);
-
- FX_DWORD dwPermissions = pDocument->GetUserPermissions();
- return (dwPermissions&FPDFPERM_FILL_FORM) ||
- (dwPermissions&FPDFPERM_ANNOT_FORM) ||
- (dwPermissions&FPDFPERM_ANNOT_FORM);
- }
- }
-
- return FALSE;
-}
-
-CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage)
-{
- ASSERT(pPage != NULL);
- pPage->GetPDFDocument();
-
- CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc();
- ASSERT(pSDKDoc);
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = NULL;
- if (CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(pInterForm->GetInterForm(), pAnnot->m_pAnnotDict))
- {
- pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
- pInterForm->AddMap(pCtrl, pWidget);
- CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
- if(pPDFInterForm && pPDFInterForm->NeedConstructAP())
- pWidget->ResetAppearance(NULL,FALSE);
- }
-
- return pWidget;
-}
-
-void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
-
- if (m_pFormFiller)
- m_pFormFiller->OnDelete(pAnnot);
-
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_FormControl* pCtrol = pWidget->GetFormControl();
- pInterForm->RemoveMap(pCtrol);
-
-
- delete pWidget;
-}
-
-
-void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, FX_DWORD dwFlags)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
- }
- else
- {
- if (m_pFormFiller)
- {
- m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
- }
- }
-}
-
-void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
- }
-
-
-}
-void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
- }
-
-}
-FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-
-}
-
-
-FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnChar(pAnnot,nChar, nFlags);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnKeyDown(pAnnot,nKeyCode, nFlag);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
-{
-
- return FALSE;
-}
-void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- m_pFormFiller->OnCreate(pAnnot);
- }
-}
-
-void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
-
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
-
- if (!pWidget->IsAppearanceValid())
- pWidget->ResetAppearance(NULL, FALSE);
-
- int nFieldType = pWidget->GetFieldType();
-
- if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX)
- {
- FX_BOOL bFormated = FALSE;
- CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
-
- if (bFormated && nFieldType == FIELDTYPE_COMBOBOX)
- {
- pWidget->ResetAppearance(sValue, FALSE);
- }
- }
-
-
- if (m_pFormFiller)
- m_pFormFiller->OnLoad(pAnnot);
-
- }
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnSetFocus(pAnnot,nFlag);
- }
-
- return TRUE;
-}
-FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->OnKillFocus(pAnnot,nFlag);
- }
-
- return TRUE;
-}
-
-CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
- CFX_ByteString sSubType = pAnnot->GetSubType();
-
- if (sSubType == BFFT_SIGNATURE)
- {
- }
- else
- {
- if (m_pFormFiller)
- return m_pFormFiller->GetViewBBox(pPageView, pAnnot);
-
- }
-
- return CPDF_Rect(0,0,0,0);
-}
-
-FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point)
-{
- ASSERT(pPageView);
- ASSERT(pAnnot);
-
- CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
- return rect.Contains(point.x, point.y);
-}
-
-//CReader_AnnotIteratorEx
-
-CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView,FX_BOOL bReverse,
- FX_BOOL bIgnoreTopmost/*=FALSE*/,
- FX_BOOL bCircle/*=FALSE*/,
- CFX_PtrArray *pList/*=NULL*/)
-{
- ASSERT(pPageView);
- m_bReverse=bReverse;
- m_bIgnoreTopmost= bIgnoreTopmost;
- m_bCircle=bCircle;
- m_pIteratorAnnotList.RemoveAll();
- InitIteratorAnnotList(pPageView,pList);
-}
-
-CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (const CPDFSDK_Annot* pCurrent)
-{
-
- int index=-1;
- int nCount=this->m_pIteratorAnnotList.GetSize();
- if(pCurrent){
- for(int i=0;i<nCount;i++){
- CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot *)m_pIteratorAnnotList.GetAt(i);
- if(pReaderAnnot ==pCurrent){
- index=i;
- break;
- }
- }
- }
- return NextAnnot(index);
-}
-CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (const CPDFSDK_Annot*pCurrent)
-{
-
- int index=-1;
- int nCount=this->m_pIteratorAnnotList.GetSize();
- if(pCurrent){
- for(int i=0;i<nCount;i++){
- CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
- if(pReaderAnnot ==pCurrent){
- index=i;
- break;
- }
- }
- }
- return PrevAnnot(index);
-}
-CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (int& index)
-{
-
- int nCount=m_pIteratorAnnotList.GetSize();
- if(nCount<=0) index=-1;
- else{
- if(index<0){
- index=0;
- }
- else{
- if(m_bCircle){
- index=( index <nCount-1) ? (index+1) :0;
- }
- else{
- index=( index <nCount-1) ? (index+1) :-1;
- }
-
- }
- }
- return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
-}
-
-
-CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (int& index)
-{
-
- int nCount=m_pIteratorAnnotList.GetSize();
- if(nCount<=0) index=-1;
- else{
- if(index<0){
- index=nCount-1;
- }
- else{
- if(m_bCircle){
- index = ( index >0) ? (index-1) :nCount-1;
- }
- else{
- index = ( index >0) ? (index-1) :-1;
- }
- }
- }
- return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
-}
-
-
-CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent)
-{
-
- return (m_bReverse) ? PrevAnnot(pCurrent):NextAnnot(pCurrent);
-
-}
-
-CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent)
-{
-
- return (m_bReverse) ? NextAnnot(pCurrent):PrevAnnot(pCurrent);
-}
-
-CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(int& index )
-{
-
- return (m_bReverse) ? PrevAnnot(index):NextAnnot(index);
-
-}
-
-CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index )
-{
-
- return (m_bReverse) ? NextAnnot(index):PrevAnnot(index);
-}
-
-
-void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray &arrayList, AI_COMPARE pCompare)
-{
- for (int i = 1; i < arrayList.GetSize(); i++)
- {
- if (pCompare((CPDFSDK_Annot*)(arrayList[i]) , (CPDFSDK_Annot*)(arrayList[i-1])) < 0)
- {
- int j = i-1;
- CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];
-
- do
- {
- arrayList[j + 1] = arrayList[j];
- } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);
-
- arrayList[j+1] = pTemp;
- }
- }
-}
-
-int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
-{
- if(p1->GetLayoutOrder() < p2->GetLayoutOrder())
- return -1;
- else if (p1->GetLayoutOrder() == p2->GetLayoutOrder())
- return 0;
- else
- return 1;
-}
-
-FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList(CPDFSDK_PageView* pPageView,CFX_PtrArray * pAnnotList)
-{
- ASSERT(pPageView);
-
-
-
- if(pAnnotList==NULL){
- pAnnotList=pPageView->GetAnnotList();
- }
-
- this->m_pIteratorAnnotList.RemoveAll();
- if(!pAnnotList) return FALSE;
-
- CPDFSDK_Annot * pTopMostAnnot= (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot();
-
-
- int nCount =pAnnotList->GetSize();
-
- for(int i = nCount- 1 ;i >= 0;i--)
- {
- CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)pAnnotList->GetAt(i);
- m_pIteratorAnnotList.Add(pReaderAnnot);
- }
-
- InsertSort(m_pIteratorAnnotList,&LyOrderCompare);
-
- if(pTopMostAnnot)
- {
- for(int i=0 ;i<nCount;i++)
- {
- CPDFSDK_Annot * pReaderAnnot = (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
- if(pReaderAnnot == pTopMostAnnot)
- {
- m_pIteratorAnnotList.RemoveAt(i);
- m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);
- break;
- }
- }
- }
-
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fsdk_mgr.h"
+#include "../include/formfiller/FFL_FormFiller.h"
+#include "../include/fsdk_annothandler.h"
+
+
+CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp)
+{
+ m_pApp = pApp;
+
+ CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
+ pHandler->SetFormFiller(m_pApp->GetIFormFiller());
+ RegisterAnnotHandler(pHandler);
+}
+
+CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr()
+{
+ for(int i=0; i<m_Handlers.GetSize(); i++)
+ {
+ IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
+ delete pHandler;
+ }
+ m_Handlers.RemoveAll();
+ m_mapType2Handler.RemoveAll();
+}
+
+void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler)
+{
+ ASSERT(pAnnotHandler != NULL);
+
+ ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL);
+
+ m_Handlers.Add(pAnnotHandler);
+ m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler);
+}
+
+void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler)
+{
+ ASSERT(pAnnotHandler != NULL);
+
+ m_mapType2Handler.RemoveKey(pAnnotHandler->GetType());
+
+ for (int i=0, sz=m_Handlers.GetSize(); i<sz; i++)
+ {
+ if (m_Handlers.GetAt(i) == pAnnotHandler)
+ {
+ m_Handlers.RemoveAt(i);
+ break;
+ }
+ }
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_PageView *pPageView)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pPageView != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot->GetSubType()))
+ {
+ return pAnnotHandler->NewAnnot(pAnnot, pPageView);
+ }
+
+ return new CPDFSDK_Annot(pAnnot, pPageView);
+}
+
+void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+
+ pAnnot->GetPDFPage();
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ pAnnotHandler->OnRelease(pAnnot);
+ pAnnotHandler->ReleaseAnnot(pAnnot);
+ }
+ else
+ {
+ delete (CPDFSDK_Annot*)pAnnot;
+ }
+}
+
+void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
+ ASSERT(pPDFAnnot != NULL);
+ ASSERT(pPDFAnnot->m_pAnnotDict != NULL);
+
+ CPDFSDK_DateTime curTime;
+ pPDFAnnot->m_pAnnotDict->SetAtString("M", curTime.ToPDFDateTimeString());
+ pPDFAnnot->m_pAnnotDict->SetAtNumber("F", (int)0);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ pAnnotHandler->OnCreate(pAnnot);
+ }
+}
+
+void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ pAnnotHandler->OnLoad(pAnnot);
+ }
+}
+
+IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(CPDFSDK_Annot* pAnnot) const
+{
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
+ ASSERT(pPDFAnnot != NULL);
+
+ return GetAnnotHandler(pPDFAnnot->GetSubType());
+}
+
+IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(const CFX_ByteString& sType) const
+{
+ void* pRet = NULL;
+ m_mapType2Handler.Lookup(sType, pRet);
+ return (IPDFSDK_AnnotHandler*)pRet;
+}
+
+void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,FX_DWORD dwFlags)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
+ }
+ else
+ {
+ pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+ }
+}
+
+
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
+ }
+ return FALSE;
+}
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+ {
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
+ }
+ return FALSE;
+ }
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
+ }
+ return FALSE;
+}
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
+ }
+ return FALSE;
+}
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->OnMouseWheel(pPageView, pAnnot,nFlags,zDelta, point);
+ }
+ return FALSE;
+}
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
+ }
+ return FALSE;
+}
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
+ }
+ return FALSE;
+}
+
+void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
+ }
+ return ;
+}
+
+void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
+ }
+ return;
+}
+
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags)
+{
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->OnChar(pAnnot,nChar, nFlags);
+ }
+ return FALSE;
+
+}
+
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
+{
+
+ if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag))
+ {
+ CPDFSDK_PageView* pPage = pAnnot->GetPageView();
+ CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
+ if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab))
+ {
+ CPDFSDK_Annot* pNext = GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
+
+ if(pNext && pNext != pFocusAnnot)
+ {
+ CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
+ pDocument->SetFocusAnnot(pNext);
+ return TRUE;
+ }
+ }
+ }
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->OnKeyDown(pAnnot,nKeyCode, nFlag);
+ }
+ return FALSE;
+}
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
+{
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ if (pAnnotHandler->OnSetFocus(pAnnot, nFlag))
+ {
+ CPDFSDK_PageView* pPage = pAnnot->GetPageView();
+ ASSERT(pPage != NULL);
+
+ pPage->GetSDKDocument();
+ // pDocument->SetTopmostAnnot(pAnnot);
+
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ if (pAnnotHandler->OnKillFocus(pAnnot, nFlag))
+ {
+ return TRUE;
+ }
+ else
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
+CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot);
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
+ }
+ return pAnnot->GetRect();
+}
+
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point)
+{
+ ASSERT(pAnnot);
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
+ {
+ if(pAnnotHandler->CanAnswer(pAnnot))
+ return pAnnotHandler->HitTest(pPageView, pAnnot, point);
+ }
+ return FALSE;
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext)
+{
+ CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
+
+ CPDFSDK_Annot* pNext = bNext ?
+ ai.GetNextAnnot(pSDKAnnot) :
+ ai.GetPrevAnnot(pSDKAnnot);
+
+ return pNext;
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot);
+ ASSERT(pAnnot->GetType() == "Widget");
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ if (!pWidget->IsVisible()) return FALSE;
+
+ int nFieldFlags = pWidget->GetFieldFlags();
+ if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) return FALSE;
+ if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
+ return TRUE;
+ else
+ {
+ CPDF_Page* pPage = pWidget->GetPDFPage();
+ ASSERT(pPage != NULL);
+
+ CPDF_Document* pDocument = pPage->m_pDocument;
+ ASSERT(pDocument != NULL);
+
+ FX_DWORD dwPermissions = pDocument->GetUserPermissions();
+ return (dwPermissions&FPDFPERM_FILL_FORM) ||
+ (dwPermissions&FPDFPERM_ANNOT_FORM) ||
+ (dwPermissions&FPDFPERM_ANNOT_FORM);
+ }
+ }
+
+ return FALSE;
+}
+
+CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage)
+{
+ ASSERT(pPage != NULL);
+ pPage->GetPDFDocument();
+
+ CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc();
+ ASSERT(pSDKDoc);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = NULL;
+ if (CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(pInterForm->GetInterForm(), pAnnot->m_pAnnotDict))
+ {
+ pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
+ pInterForm->AddMap(pCtrl, pWidget);
+ CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
+ if(pPDFInterForm && pPDFInterForm->NeedConstructAP())
+ pWidget->ResetAppearance(NULL,FALSE);
+ }
+
+ return pWidget;
+}
+
+void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+
+ if (m_pFormFiller)
+ m_pFormFiller->OnDelete(pAnnot);
+
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+ CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_FormControl* pCtrol = pWidget->GetFormControl();
+ pInterForm->RemoveMap(pCtrol);
+
+
+ delete pWidget;
+}
+
+
+void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, FX_DWORD dwFlags)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+ }
+ else
+ {
+ if (m_pFormFiller)
+ {
+ m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
+ }
+ }
+}
+
+void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
+ }
+
+
+}
+void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
+ }
+
+}
+FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+
+}
+
+
+FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnChar(pAnnot,nChar, nFlags);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnKeyDown(pAnnot,nKeyCode, nFlag);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
+{
+
+ return FALSE;
+}
+void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ m_pFormFiller->OnCreate(pAnnot);
+ }
+}
+
+void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+
+ if (!pWidget->IsAppearanceValid())
+ pWidget->ResetAppearance(NULL, FALSE);
+
+ int nFieldType = pWidget->GetFieldType();
+
+ if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX)
+ {
+ FX_BOOL bFormated = FALSE;
+ CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
+
+ if (bFormated && nFieldType == FIELDTYPE_COMBOBOX)
+ {
+ pWidget->ResetAppearance(sValue, FALSE);
+ }
+ }
+
+
+ if (m_pFormFiller)
+ m_pFormFiller->OnLoad(pAnnot);
+
+ }
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnSetFocus(pAnnot,nFlag);
+ }
+
+ return TRUE;
+}
+FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->OnKillFocus(pAnnot,nFlag);
+ }
+
+ return TRUE;
+}
+
+CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+ CFX_ByteString sSubType = pAnnot->GetSubType();
+
+ if (sSubType == BFFT_SIGNATURE)
+ {
+ }
+ else
+ {
+ if (m_pFormFiller)
+ return m_pFormFiller->GetViewBBox(pPageView, pAnnot);
+
+ }
+
+ return CPDF_Rect(0,0,0,0);
+}
+
+FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point)
+{
+ ASSERT(pPageView);
+ ASSERT(pAnnot);
+
+ CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
+ return rect.Contains(point.x, point.y);
+}
+
+//CReader_AnnotIteratorEx
+
+CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView,FX_BOOL bReverse,
+ FX_BOOL bIgnoreTopmost/*=FALSE*/,
+ FX_BOOL bCircle/*=FALSE*/,
+ CFX_PtrArray *pList/*=NULL*/)
+{
+ ASSERT(pPageView);
+ m_bReverse=bReverse;
+ m_bIgnoreTopmost= bIgnoreTopmost;
+ m_bCircle=bCircle;
+ m_pIteratorAnnotList.RemoveAll();
+ InitIteratorAnnotList(pPageView,pList);
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (const CPDFSDK_Annot* pCurrent)
+{
+
+ int index=-1;
+ int nCount=this->m_pIteratorAnnotList.GetSize();
+ if(pCurrent){
+ for(int i=0;i<nCount;i++){
+ CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot *)m_pIteratorAnnotList.GetAt(i);
+ if(pReaderAnnot ==pCurrent){
+ index=i;
+ break;
+ }
+ }
+ }
+ return NextAnnot(index);
+}
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (const CPDFSDK_Annot*pCurrent)
+{
+
+ int index=-1;
+ int nCount=this->m_pIteratorAnnotList.GetSize();
+ if(pCurrent){
+ for(int i=0;i<nCount;i++){
+ CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
+ if(pReaderAnnot ==pCurrent){
+ index=i;
+ break;
+ }
+ }
+ }
+ return PrevAnnot(index);
+}
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (int& index)
+{
+
+ int nCount=m_pIteratorAnnotList.GetSize();
+ if(nCount<=0) index=-1;
+ else{
+ if(index<0){
+ index=0;
+ }
+ else{
+ if(m_bCircle){
+ index=( index <nCount-1) ? (index+1) :0;
+ }
+ else{
+ index=( index <nCount-1) ? (index+1) :-1;
+ }
+
+ }
+ }
+ return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
+}
+
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (int& index)
+{
+
+ int nCount=m_pIteratorAnnotList.GetSize();
+ if(nCount<=0) index=-1;
+ else{
+ if(index<0){
+ index=nCount-1;
+ }
+ else{
+ if(m_bCircle){
+ index = ( index >0) ? (index-1) :nCount-1;
+ }
+ else{
+ index = ( index >0) ? (index-1) :-1;
+ }
+ }
+ }
+ return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
+}
+
+
+CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent)
+{
+
+ return (m_bReverse) ? PrevAnnot(pCurrent):NextAnnot(pCurrent);
+
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent)
+{
+
+ return (m_bReverse) ? NextAnnot(pCurrent):PrevAnnot(pCurrent);
+}
+
+CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(int& index )
+{
+
+ return (m_bReverse) ? PrevAnnot(index):NextAnnot(index);
+
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index )
+{
+
+ return (m_bReverse) ? NextAnnot(index):PrevAnnot(index);
+}
+
+
+void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray &arrayList, AI_COMPARE pCompare)
+{
+ for (int i = 1; i < arrayList.GetSize(); i++)
+ {
+ if (pCompare((CPDFSDK_Annot*)(arrayList[i]) , (CPDFSDK_Annot*)(arrayList[i-1])) < 0)
+ {
+ int j = i-1;
+ CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];
+
+ do
+ {
+ arrayList[j + 1] = arrayList[j];
+ } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);
+
+ arrayList[j+1] = pTemp;
+ }
+ }
+}
+
+int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
+{
+ if(p1->GetLayoutOrder() < p2->GetLayoutOrder())
+ return -1;
+ else if (p1->GetLayoutOrder() == p2->GetLayoutOrder())
+ return 0;
+ else
+ return 1;
+}
+
+FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList(CPDFSDK_PageView* pPageView,CFX_PtrArray * pAnnotList)
+{
+ ASSERT(pPageView);
+
+
+
+ if(pAnnotList==NULL){
+ pAnnotList=pPageView->GetAnnotList();
+ }
+
+ this->m_pIteratorAnnotList.RemoveAll();
+ if(!pAnnotList) return FALSE;
+
+ CPDFSDK_Annot * pTopMostAnnot= (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot();
+
+
+ int nCount =pAnnotList->GetSize();
+
+ for(int i = nCount- 1 ;i >= 0;i--)
+ {
+ CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)pAnnotList->GetAt(i);
+ m_pIteratorAnnotList.Add(pReaderAnnot);
+ }
+
+ InsertSort(m_pIteratorAnnotList,&LyOrderCompare);
+
+ if(pTopMostAnnot)
+ {
+ for(int i=0 ;i<nCount;i++)
+ {
+ CPDFSDK_Annot * pReaderAnnot = (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
+ if(pReaderAnnot == pTopMostAnnot)
+ {
+ m_pIteratorAnnotList.RemoveAt(i);
+ m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);
+ break;
+ }
+ }
+ }
+
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp
index ac36e3c3a6..c8e07358ba 100644
--- a/fpdfsdk/src/fsdk_baseannot.cpp
+++ b/fpdfsdk/src/fsdk_baseannot.cpp
@@ -1,1187 +1,1187 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fsdk_mgr.h"
-#include "../include/fsdk_baseannot.h"
-
-
-//---------------------------------------------------------------------------
-// CPDFSDK_DateTime
-//---------------------------------------------------------------------------
-int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, FX_BYTE tzminute)
-{
- return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60);
-}
-
-FX_BOOL _gAfxIsLeapYear(FX_SHORT year)
-{
- return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
-}
-
-FX_WORD _gAfxGetYearDays(FX_SHORT year)
-{
- return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365);
-}
-
-FX_BYTE _gAfxGetMonthDays(FX_SHORT year, FX_BYTE month)
-{
- FX_BYTE mDays;
- switch (month)
- {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- mDays = 31;
- break;
-
- case 4:
- case 6:
- case 9:
- case 11:
- mDays = 30;
- break;
-
- case 2:
- if (_gAfxIsLeapYear(year) == TRUE)
- mDays = 29;
- else
- mDays = 28;
- break;
-
- default:
- mDays = 0;
- break;
- }
-
- return mDays;
-}
-
-CPDFSDK_DateTime::CPDFSDK_DateTime()
-{
- ResetDateTime();
-}
-
-CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr)
-{
- ResetDateTime();
-
- FromPDFDateTimeString(dtStr);
-}
-
-CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime)
-{
- operator = (datetime);
-}
-
-CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st)
-{
- operator = (st) ;
-}
-
-
-void CPDFSDK_DateTime::ResetDateTime()
-{
- tzset();
-
- time_t curTime;
- time(&curTime);
- struct tm* newtime;
- //newtime = gmtime(&curTime);
- newtime = localtime(&curTime);
-
- dt.year = newtime->tm_year + 1900;
- dt.month = newtime->tm_mon + 1;
- dt.day = newtime->tm_mday;
- dt.hour = newtime->tm_hour;
- dt.minute = newtime->tm_min;
- dt.second = newtime->tm_sec;
-// dt.tzHour = _timezone / 3600 * -1;
-// dt.tzMinute = (abs(_timezone) % 3600) / 60;
-}
-
-CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const CPDFSDK_DateTime& datetime)
-{
- FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME));
- return *this;
-}
-
-CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const FX_SYSTEMTIME& st)
-{
- tzset();
-
- dt.year = (FX_SHORT)st.wYear;
- dt.month = (FX_BYTE)st.wMonth;
- dt.day = (FX_BYTE)st.wDay;
- dt.hour = (FX_BYTE)st.wHour;
- dt.minute = (FX_BYTE)st.wMinute;
- dt.second = (FX_BYTE)st.wSecond;
-// dt.tzHour = _timezone / 3600 * -1;
-// dt.tzMinute = (abs(_timezone) % 3600) / 60;
- return *this;
-}
-
-FX_BOOL CPDFSDK_DateTime::operator == (CPDFSDK_DateTime& datetime)
-{
- return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0);
-}
-
-FX_BOOL CPDFSDK_DateTime::operator != (CPDFSDK_DateTime& datetime)
-{
- return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0);
-}
-
-FX_BOOL CPDFSDK_DateTime::operator > (CPDFSDK_DateTime& datetime)
-{
- CPDFSDK_DateTime dt1 = ToGMT();
- CPDFSDK_DateTime dt2 = datetime.ToGMT();
- int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
- int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
- int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
- int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
-
- if (d1 > d3) return TRUE;
- if (d2 > d4) return TRUE;
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_DateTime::operator >= (CPDFSDK_DateTime& datetime)
-{
- CPDFSDK_DateTime dt1 = ToGMT();
- CPDFSDK_DateTime dt2 = datetime.ToGMT();
- int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
- int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
- int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
- int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
-
- if (d1 >= d3) return TRUE;
- if (d2 >= d4) return TRUE;
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_DateTime::operator < (CPDFSDK_DateTime& datetime)
-{
- CPDFSDK_DateTime dt1 = ToGMT();
- CPDFSDK_DateTime dt2 = datetime.ToGMT();
- int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
- int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
- int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
- int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
-
- if (d1 < d3) return TRUE;
- if (d2 < d4) return TRUE;
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_DateTime::operator <= (CPDFSDK_DateTime& datetime)
-{
- CPDFSDK_DateTime dt1 = ToGMT();
- CPDFSDK_DateTime dt2 = datetime.ToGMT();
- int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
- int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
- int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
- int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
-
- if (d1 <= d3) return TRUE;
- if (d2 <= d4) return TRUE;
- return FALSE;
-}
-
-CPDFSDK_DateTime::operator time_t()
-{
- struct tm newtime;
-
- newtime.tm_year = dt.year - 1900;
- newtime.tm_mon = dt.month - 1;
- newtime.tm_mday = dt.day;
- newtime.tm_hour = dt.hour;
- newtime.tm_min = dt.minute;
- newtime.tm_sec = dt.second;
-
- return mktime(&newtime);
-}
-
-CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(const CFX_ByteString& dtStr)
-{
- int strLength = dtStr.GetLength();
- if (strLength > 0)
- {
- int i = 0;
- int j, k;
- FX_CHAR ch;
- while (i < strLength)
- {
- ch = dtStr[i];
- if (ch >= '0' && ch <= '9') break;
- i ++;
- }
- if (i >= strLength) return *this;
-
- j = 0;
- k = 0;
- while (i < strLength && j < 4)
- {
- ch = dtStr[i];
- k = k * 10 + ch - '0';
- j ++;
- if (ch < '0' || ch > '9') break;
- i ++;
- }
- dt.year = (FX_SHORT)k;
- if (i >= strLength || j < 4) return *this;
-
- j = 0;
- k = 0;
- while (i < strLength && j < 2)
- {
- ch = dtStr[i];
- k = k * 10 + ch - '0';
- j ++;
- if (ch < '0' || ch > '9') break;
- i ++;
- }
- dt.month = (FX_BYTE)k;
- if (i >= strLength || j < 2) return *this;
-
- j = 0;
- k = 0;
- while (i < strLength && j < 2)
- {
- ch = dtStr[i];
- k = k * 10 + ch - '0';
- j ++;
- if (ch < '0' || ch > '9') break;
- i ++;
- }
- dt.day = (FX_BYTE)k;
- if (i >= strLength || j < 2) return *this;
-
- j = 0;
- k = 0;
- while (i < strLength && j < 2)
- {
- ch = dtStr[i];
- k = k * 10 + ch - '0';
- j ++;
- if (ch < '0' || ch > '9') break;
- i ++;
- }
- dt.hour = (FX_BYTE)k;
- if (i >= strLength || j < 2) return *this;
-
- j = 0;
- k = 0;
- while (i < strLength && j < 2)
- {
- ch = dtStr[i];
- k = k * 10 + ch - '0';
- j ++;
- if (ch < '0' || ch > '9') break;
- i ++;
- }
- dt.minute = (FX_BYTE)k;
- if (i >= strLength || j < 2) return *this;
-
- j = 0;
- k = 0;
- while (i < strLength && j < 2)
- {
- ch = dtStr[i];
- k = k * 10 + ch - '0';
- j ++;
- if (ch < '0' || ch > '9') break;
- i ++;
- }
- dt.second = (FX_BYTE)k;
- if (i >= strLength || j < 2) return *this;
-
- ch = dtStr[i ++];
- if (ch != '-' && ch != '+') return *this;
- if (ch == '-')
- dt.tzHour = -1;
- else
- dt.tzHour = 1;
- j = 0;
- k = 0;
- while (i < strLength && j < 2)
- {
- ch = dtStr[i];
- k = k * 10 + ch - '0';
- j ++;
- if (ch < '0' || ch > '9') break;
- i ++;
- }
- dt.tzHour *= (FX_CHAR)k;
- if (i >= strLength || j < 2) return *this;
-
- ch = dtStr[i ++];
- if (ch != '\'') return *this;
- j = 0;
- k = 0;
- while (i < strLength && j < 2)
- {
- ch = dtStr[i];
- k = k * 10 + ch - '0';
- j ++;
- if (ch < '0' || ch > '9') break;
- i ++;
- }
- dt.tzMinute = (FX_BYTE)k;
- if (i >= strLength || j < 2) return *this;
- }
-
- return *this;
-}
-
-CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString()
-{
- CFX_ByteString str1;
- str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
- if (dt.tzHour < 0)
- str1 += "-";
- else
- str1 += "+";
- CFX_ByteString str2;
- str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute);
- return str1 + str2;
-}
-
-CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString()
-{
- CFX_ByteString dtStr;
- char tempStr[32];
- sprintf(tempStr, "D:%04d%02d%02d%02d%02d%02d", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
- dtStr = CFX_ByteString(tempStr);
- if (dt.tzHour < 0)
- dtStr += CFX_ByteString("-");
- else
- dtStr += CFX_ByteString("+");
- sprintf(tempStr, "%02d'%02d'", abs(dt.tzHour), dt.tzMinute);
- dtStr += CFX_ByteString(tempStr);
- return dtStr;
-}
-
-void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st)
-{
- CPDFSDK_DateTime dt = *this;
- time_t t = (time_t)dt;
- struct tm* pTime = localtime(&t);
- if(pTime){
- st.wYear = (FX_WORD)pTime->tm_year + 1900;
- st.wMonth = (FX_WORD)pTime->tm_mon + 1;
- st.wDay = (FX_WORD)pTime->tm_mday;
- st.wDayOfWeek = (FX_WORD)pTime->tm_wday;
- st.wHour = (FX_WORD)pTime->tm_hour;
- st.wMinute = (FX_WORD)pTime->tm_min;
- st.wSecond = (FX_WORD)pTime->tm_sec;
- st.wMilliseconds = 0;
- }
-}
-
-CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT()
-{
- CPDFSDK_DateTime dt = *this;
- dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute));
- dt.dt.tzHour = 0;
- dt.dt.tzMinute = 0;
- return dt;
-}
-
-CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days)
-{
- if (days == 0) return *this;
-
- FX_SHORT y = dt.year, yy;
- FX_BYTE m = dt.month;
- FX_BYTE d = dt.day;
- int mdays, ydays, ldays;
-
- ldays = days;
- if (ldays > 0)
- {
- yy = y;
- if (((FX_WORD)m * 100 + d) > 300) yy ++;
- ydays = _gAfxGetYearDays(yy);
- while (ldays >= ydays)
- {
- y ++;
- ldays -= ydays;
- yy ++;
- mdays = _gAfxGetMonthDays(y, m);
- if (d > mdays)
- {
- m ++;
- d -= mdays;
- }
- ydays = _gAfxGetYearDays(yy);
- }
- mdays = _gAfxGetMonthDays(y, m) - d + 1;
- while (ldays >= mdays)
- {
- ldays -= mdays;
- m ++;
- d = 1;
- mdays = _gAfxGetMonthDays(y, m);
- }
- d += ldays;
- }
- else
- {
- ldays *= -1;
- yy = y;
- if (((FX_WORD)m * 100 + d) < 300) yy --;
- ydays = _gAfxGetYearDays(yy);
- while (ldays >= ydays)
- {
- y --;
- ldays -= ydays;
- yy --;
- mdays = _gAfxGetMonthDays(y, m);
- if (d > mdays)
- {
- m ++;
- d -= mdays;
- }
- ydays = _gAfxGetYearDays(yy);
- }
- while (ldays >= d)
- {
- ldays -= d;
- m --;
- mdays = _gAfxGetMonthDays(y, m);
- d = mdays;
- }
- d -= ldays;
- }
-
- dt.year = y;
- dt.month = m;
- dt.day = d;
-
- return *this;
-}
-
-CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds)
-{
- if (seconds == 0) return *this;
-
- int n;
- int days;
-
- n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds;
- if (n < 0)
- {
- days = (n - 86399) / 86400;
- n -= days * 86400;
- }
- else
- {
- days = n / 86400;
- n %= 86400;
- }
- dt.hour = (FX_BYTE)(n / 3600);
- dt.hour %= 24;
- n %= 3600;
- dt.minute = (FX_BYTE)(n / 60);
- dt.second = (FX_BYTE)(n % 60);
- if (days != 0) AddDays(days);
-
- return *this;
-}
-
-
-//---------------------------------------------------------------------------
-// CPDFSDK_Annot
-//---------------------------------------------------------------------------
-CPDFSDK_Annot::CPDFSDK_Annot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) :
-m_pAnnot(pAnnot),
-m_pPageView(pPageView),
-m_bSelected(FALSE),
-m_nTabOrder(-1)
-{
-}
-
-CPDFSDK_Annot::~CPDFSDK_Annot()
-{
- m_pAnnot = NULL;
- m_pPageView = NULL;
-}
-
-CPDF_Annot* CPDFSDK_Annot::GetPDFAnnot()
-{
- return m_pAnnot;
-}
-
-FX_DWORD CPDFSDK_Annot::GetFlags()
-{
- ASSERT(m_pAnnot != NULL);
-
- return m_pAnnot->GetFlags();
-}
-
-void CPDFSDK_Annot::SetPage(CPDFSDK_PageView* pPageView)
-{
- m_pPageView = pPageView;
-}
-
-CPDFSDK_PageView* CPDFSDK_Annot::GetPageView()
-{
- return m_pPageView;
-}
-
-FX_BOOL CPDFSDK_Annot::IsSelected()
-{
- return m_bSelected;
-}
-
-void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected)
-{
- m_bSelected = bSelected;
-}
-
-// Tab Order
-int CPDFSDK_Annot::GetTabOrder()
-{
- return m_nTabOrder;
-}
-
-void CPDFSDK_Annot::SetTabOrder(int iTabOrder)
-{
- m_nTabOrder = iTabOrder;
-}
-
-CPDF_Dictionary* CPDFSDK_Annot::GetAnnotDict() const
-{
- ASSERT(m_pAnnot != NULL);
-
- return m_pAnnot->m_pAnnotDict;
-}
-
-void CPDFSDK_Annot::SetRect(const CPDF_Rect& rect)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
- ASSERT(rect.right - rect.left >= GetMinWidth());
- ASSERT(rect.top - rect.bottom >= GetMinHeight());
-
- m_pAnnot->m_pAnnotDict->SetAtRect("Rect", rect);
-}
-
-CPDF_Rect CPDFSDK_Annot::GetRect() const
-{
- ASSERT(m_pAnnot != NULL);
-
- CPDF_Rect rect;
- m_pAnnot->GetRect(rect);
-
- return rect;
-}
-
-CFX_ByteString CPDFSDK_Annot::GetType() const
-{
- ASSERT(m_pAnnot != NULL);
-
- return m_pAnnot->GetSubType();
-}
-
-CFX_ByteString CPDFSDK_Annot::GetSubType() const
-{
- return "";
-}
-
-void CPDFSDK_Annot::ResetAppearance()
-{
- ASSERT(FALSE);
-}
-
-void CPDFSDK_Annot::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
- CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
-{
- ASSERT(m_pPageView != NULL);
- ASSERT(m_pAnnot != NULL);
-
- m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, mode, pOptions);
-}
-
-FX_BOOL CPDFSDK_Annot::IsAppearanceValid()
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- return m_pAnnot->m_pAnnotDict->GetDict("AP") != NULL;
-}
-
-FX_BOOL CPDFSDK_Annot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP");
- if (pAP == NULL) return FALSE;
-
- // Choose the right sub-ap
- const FX_CHAR* ap_entry = "N";
- if (mode == CPDF_Annot::Down)
- ap_entry = "D";
- else if (mode == CPDF_Annot::Rollover)
- ap_entry = "R";
- if (!pAP->KeyExist(ap_entry))
- ap_entry = "N";
-
- // Get the AP stream or subdirectory
- CPDF_Object* psub = pAP->GetElementValue(ap_entry);
- if (psub == NULL) return FALSE;
-
- return TRUE;
-}
-
-void CPDFSDK_Annot::DrawBorder(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
- const CPDF_RenderOptions* pOptions)
-{
- ASSERT(m_pAnnot != NULL);
- m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
-}
-
-void CPDFSDK_Annot::ClearCachedAP()
-{
- ASSERT(m_pAnnot != NULL);
- m_pAnnot->ClearCachedAP();
-}
-
-void CPDFSDK_Annot::SetContents(const CFX_WideString& sContents)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- if (sContents.IsEmpty())
- m_pAnnot->m_pAnnotDict->RemoveAt("Contents");
- else
- m_pAnnot->m_pAnnotDict->SetAtString("Contents", PDF_EncodeText(sContents));
-}
-
-CFX_WideString CPDFSDK_Annot::GetContents() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- return m_pAnnot->m_pAnnotDict->GetUnicodeText("Contents");
-}
-
-void CPDFSDK_Annot::SetAnnotName(const CFX_WideString& sName)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- if (sName.IsEmpty())
- m_pAnnot->m_pAnnotDict->RemoveAt("NM");
- else
- m_pAnnot->m_pAnnotDict->SetAtString("NM", PDF_EncodeText(sName));
-}
-
-CFX_WideString CPDFSDK_Annot::GetAnnotName() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- return m_pAnnot->m_pAnnotDict->GetUnicodeText("NM");
-}
-
-void CPDFSDK_Annot::SetModifiedDate(const FX_SYSTEMTIME& st)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDFSDK_DateTime dt(st);
- CFX_ByteString str = dt.ToPDFDateTimeString();
-
- if (str.IsEmpty())
- m_pAnnot->m_pAnnotDict->RemoveAt("M");
- else
- m_pAnnot->m_pAnnotDict->SetAtString("M", str);
-}
-
-FX_SYSTEMTIME CPDFSDK_Annot::GetModifiedDate() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- FX_SYSTEMTIME systime;
- CFX_ByteString str = m_pAnnot->m_pAnnotDict->GetString("M");
-
- CPDFSDK_DateTime dt(str);
- dt.ToSystemTime(systime);
-
- return systime;
-}
-
-void CPDFSDK_Annot::SetFlags(int nFlags)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- m_pAnnot->m_pAnnotDict->SetAtInteger("F", nFlags);
-}
-
-int CPDFSDK_Annot::GetFlags() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- return m_pAnnot->m_pAnnotDict->GetInteger("F");
-}
-
-void CPDFSDK_Annot::SetAppState(const CFX_ByteString& str)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- if (str.IsEmpty())
- m_pAnnot->m_pAnnotDict->RemoveAt("AS");
- else
- m_pAnnot->m_pAnnotDict->SetAtString("AS", str);
-}
-
-CFX_ByteString CPDFSDK_Annot::GetAppState() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- return m_pAnnot->m_pAnnotDict->GetString("AS");
-}
-
-void CPDFSDK_Annot::SetStructParent(int key)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- m_pAnnot->m_pAnnotDict->SetAtInteger("StructParent", key);
-}
-
-int CPDFSDK_Annot::GetStructParent() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- return m_pAnnot->m_pAnnotDict->GetInteger("StructParent");
-}
-
-//border
-void CPDFSDK_Annot::SetBorderWidth(int nWidth)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");
-
- if (pBorder)
- {
- pBorder->SetAt(2, FX_NEW CPDF_Number(nWidth));
- }
- else
- {
- CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
-
- if (!pBSDict)
- {
- pBSDict = FX_NEW CPDF_Dictionary;
- m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict);
- }
-
- pBSDict->SetAtInteger("W", nWidth);
- }
-}
-
-int CPDFSDK_Annot::GetBorderWidth() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");
-
- if (pBorder)
- {
- return pBorder->GetInteger(2);
- }
- else
- {
- CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
-
- if (pBSDict)
- {
- return pBSDict->GetInteger("W", 1);
- }
- }
- return 1;
-}
-
-void CPDFSDK_Annot::SetBorderStyle(int nStyle)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
- if (!pBSDict)
- {
- pBSDict = FX_NEW CPDF_Dictionary;
- m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict);
- }
-
- switch (nStyle)
- {
- case BBS_SOLID:
- pBSDict->SetAtName("S", "S");
- break;
- case BBS_DASH:
- pBSDict->SetAtName("S", "D");
- break;
- case BBS_BEVELED:
- pBSDict->SetAtName("S", "B");
- break;
- case BBS_INSET:
- pBSDict->SetAtName("S", "I");
- break;
- case BBS_UNDERLINE:
- pBSDict->SetAtName("S", "U");
- break;
- }
-}
-
-int CPDFSDK_Annot::GetBorderStyle() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
- if (pBSDict)
- {
- CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
- if (sBorderStyle == "S") return BBS_SOLID;
- if (sBorderStyle == "D") return BBS_DASH;
- if (sBorderStyle == "B") return BBS_BEVELED;
- if (sBorderStyle == "I") return BBS_INSET;
- if (sBorderStyle == "U") return BBS_UNDERLINE;
- }
-
- CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");
- if (pBorder)
- {
- if (pBorder->GetCount() >= 4)
- {
- CPDF_Array *pDP = pBorder->GetArray(3);
- if (pDP && pDP->GetCount() > 0)
- return BBS_DASH;
- }
- }
-
- return BBS_SOLID;
-}
-
-void CPDFSDK_Annot::SetBorderDash(const CFX_IntArray& array)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
- if (!pBSDict)
- {
- pBSDict = FX_NEW CPDF_Dictionary;
- m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict);
- }
-
- CPDF_Array* pArray = FX_NEW CPDF_Array;
- for (int i=0,sz=array.GetSize(); i<sz; i++)
- {
- pArray->AddInteger(array[i]);
- }
-
- pBSDict->SetAt("D", pArray);
-}
-
-void CPDFSDK_Annot::GetBorderDash(CFX_IntArray& array) const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Array* pDash = NULL;
-
- CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");
- if (pBorder)
- {
- pDash = pBorder->GetArray(3);
- }
- else
- {
- CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
- if (pBSDict)
- {
- pDash = pBSDict->GetArray("D");
- }
- }
-
- if (pDash)
- {
- for (int i=0,sz=pDash->GetCount(); i<sz; i++)
- {
- array.Add(pDash->GetInteger(i));
- }
- }
-}
-
-void CPDFSDK_Annot::SetColor(FX_COLORREF color)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Array* pArray = FX_NEW CPDF_Array;
- pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
- pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
- pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
- m_pAnnot->m_pAnnotDict->SetAt("C", pArray);
-}
-
-void CPDFSDK_Annot::RemoveColor()
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- m_pAnnot->m_pAnnotDict->RemoveAt("C") ;
-}
-
-FX_BOOL CPDFSDK_Annot::GetColor(FX_COLORREF& color) const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- if (CPDF_Array* pEntry = m_pAnnot->m_pAnnotDict->GetArray("C"))
- {
- int nCount = pEntry->GetCount();
- if (nCount == 1)
- {
- FX_FLOAT g = pEntry->GetNumber(0) * 255;
-
- color = FXSYS_RGB((int)g, (int)g, (int)g);
-
- return TRUE;
- }
- else if (nCount == 3)
- {
- FX_FLOAT r = pEntry->GetNumber(0) * 255;
- FX_FLOAT g = pEntry->GetNumber(1) * 255;
- FX_FLOAT b = pEntry->GetNumber(2) * 255;
-
- color = FXSYS_RGB((int)r, (int)g, (int)b);
-
- return TRUE;
- }
- else if (nCount == 4)
- {
- FX_FLOAT c = pEntry->GetNumber(0);
- FX_FLOAT m = pEntry->GetNumber(1);
- FX_FLOAT y = pEntry->GetNumber(2);
- FX_FLOAT k = pEntry->GetNumber(3);
-
- FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
- FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
- FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
-
- color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
-void CPDFSDK_Annot::WriteAppearance(const CFX_ByteString& sAPType, const CPDF_Rect& rcBBox,
- const CPDF_Matrix& matrix, const CFX_ByteString& sContents,
- const CFX_ByteString& sAPState)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP");
-
- if (!pAPDict)
- {
- pAPDict = FX_NEW CPDF_Dictionary;
- m_pAnnot->m_pAnnotDict->SetAt("AP", pAPDict);
- }
-
- CPDF_Stream* pStream = NULL;
- CPDF_Dictionary* pParentDict = NULL;
-
- if (sAPState.IsEmpty())
- {
- pParentDict = pAPDict;
- pStream = pAPDict->GetStream(sAPType);
- }
- else
- {
- CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
- if (!pAPTypeDict)
- {
- pAPTypeDict = FX_NEW CPDF_Dictionary;
- pAPDict->SetAt(sAPType, pAPTypeDict);
- }
-
- pParentDict = pAPTypeDict;
- pStream = pAPTypeDict->GetStream(sAPState);
- }
-
- if (!pStream)
- {
- ASSERT(m_pPageView != NULL);
- CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
- ASSERT(pDoc != NULL);
-
- pStream = FX_NEW CPDF_Stream(NULL, 0, NULL);
- FX_INT32 objnum = pDoc->AddIndirectObject(pStream);
- //pAPDict->SetAtReference(sAPType, pDoc, objnum);
- ASSERT(pParentDict != NULL);
- pParentDict->SetAtReference(sAPType, pDoc, objnum);
- }
-
- CPDF_Dictionary * pStreamDict = pStream->GetDict();
-
- if (!pStreamDict)
- {
- pStreamDict = FX_NEW CPDF_Dictionary;
- pStreamDict->SetAtName("Type", "XObject");
- pStreamDict->SetAtName("Subtype", "Form");
- pStreamDict->SetAtInteger("FormType", 1);
- pStream->InitStream(NULL,0,pStreamDict);
- }
-
- if (pStreamDict)
- {
- pStreamDict->SetAtMatrix("Matrix",matrix);
- pStreamDict->SetAtRect("BBox", rcBBox);
- }
-
- pStream->SetData((FX_BYTE*)(FX_LPCSTR)sContents, sContents.GetLength(), FALSE, FALSE);
-}
-
-#define BA_ANNOT_MINWIDTH 1
-#define BA_ANNOT_MINHEIGHT 1
-
-FX_FLOAT CPDFSDK_Annot::GetMinWidth() const
-{
- return BA_ANNOT_MINWIDTH;
-}
-
-FX_FLOAT CPDFSDK_Annot::GetMinHeight() const
-{
- return BA_ANNOT_MINHEIGHT;
-}
-
-FX_BOOL CPDFSDK_Annot::CreateFormFiller()
-{
- return TRUE;
-}
-FX_BOOL CPDFSDK_Annot::IsVisible() const
-{
- int nFlags = GetFlags();
- return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || (nFlags & ANNOTFLAG_NOVIEW));
-}
-
-CPDF_Action CPDFSDK_Annot::GetAction() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- return m_pAnnot->m_pAnnotDict->GetDict("A");
-}
-
-void CPDFSDK_Annot::SetAction(const CPDF_Action& action)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- ASSERT(action != NULL);
-
- if ((CPDF_Action&)action != m_pAnnot->m_pAnnotDict->GetDict("A"))
- {
- CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
- ASSERT(pDoc != NULL);
-
- if (action.m_pDict && (action.m_pDict->GetObjNum() == 0))
- pDoc->AddIndirectObject(action.m_pDict);
- m_pAnnot->m_pAnnotDict->SetAtReference("A", pDoc, action.m_pDict->GetObjNum());
- }
-}
-
-void CPDFSDK_Annot::RemoveAction()
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- m_pAnnot->m_pAnnotDict->RemoveAt("A");
-}
-
-CPDF_AAction CPDFSDK_Annot::GetAAction() const
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- return m_pAnnot->m_pAnnotDict->GetDict("AA");
-}
-
-void CPDFSDK_Annot::SetAAction(const CPDF_AAction& aa)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
- ASSERT(aa != NULL);
-
- if ((CPDF_AAction&)aa != m_pAnnot->m_pAnnotDict->GetDict("AA"))
- m_pAnnot->m_pAnnotDict->SetAt("AA", (CPDF_AAction&)aa);
-}
-
-void CPDFSDK_Annot::RemoveAAction()
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- m_pAnnot->m_pAnnotDict->RemoveAt("AA");
-}
-
-CPDF_Action CPDFSDK_Annot::GetAAction(CPDF_AAction::AActionType eAAT)
-{
- CPDF_AAction AAction = GetAAction();
-
- if (AAction.ActionExist(eAAT))
- {
- return AAction.GetAction(eAAT);
- }
- else if (eAAT == CPDF_AAction::ButtonUp)
- {
- return GetAction();
- }
-
- return NULL;
-}
-
-void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions)
-{
-
- m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
- m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
-
- return ;
-}
-
-CPDF_Page* CPDFSDK_Annot::GetPDFPage()
-{
- if(m_pPageView)
- return m_pPageView->GetPDFPage();
- return NULL;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fsdk_mgr.h"
+#include "../include/fsdk_baseannot.h"
+
+
+//---------------------------------------------------------------------------
+// CPDFSDK_DateTime
+//---------------------------------------------------------------------------
+int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, FX_BYTE tzminute)
+{
+ return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60);
+}
+
+FX_BOOL _gAfxIsLeapYear(FX_SHORT year)
+{
+ return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
+}
+
+FX_WORD _gAfxGetYearDays(FX_SHORT year)
+{
+ return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365);
+}
+
+FX_BYTE _gAfxGetMonthDays(FX_SHORT year, FX_BYTE month)
+{
+ FX_BYTE mDays;
+ switch (month)
+ {
+ case 1:
+ case 3:
+ case 5:
+ case 7:
+ case 8:
+ case 10:
+ case 12:
+ mDays = 31;
+ break;
+
+ case 4:
+ case 6:
+ case 9:
+ case 11:
+ mDays = 30;
+ break;
+
+ case 2:
+ if (_gAfxIsLeapYear(year) == TRUE)
+ mDays = 29;
+ else
+ mDays = 28;
+ break;
+
+ default:
+ mDays = 0;
+ break;
+ }
+
+ return mDays;
+}
+
+CPDFSDK_DateTime::CPDFSDK_DateTime()
+{
+ ResetDateTime();
+}
+
+CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr)
+{
+ ResetDateTime();
+
+ FromPDFDateTimeString(dtStr);
+}
+
+CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime)
+{
+ operator = (datetime);
+}
+
+CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st)
+{
+ operator = (st) ;
+}
+
+
+void CPDFSDK_DateTime::ResetDateTime()
+{
+ tzset();
+
+ time_t curTime;
+ time(&curTime);
+ struct tm* newtime;
+ //newtime = gmtime(&curTime);
+ newtime = localtime(&curTime);
+
+ dt.year = newtime->tm_year + 1900;
+ dt.month = newtime->tm_mon + 1;
+ dt.day = newtime->tm_mday;
+ dt.hour = newtime->tm_hour;
+ dt.minute = newtime->tm_min;
+ dt.second = newtime->tm_sec;
+// dt.tzHour = _timezone / 3600 * -1;
+// dt.tzMinute = (abs(_timezone) % 3600) / 60;
+}
+
+CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const CPDFSDK_DateTime& datetime)
+{
+ FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME));
+ return *this;
+}
+
+CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const FX_SYSTEMTIME& st)
+{
+ tzset();
+
+ dt.year = (FX_SHORT)st.wYear;
+ dt.month = (FX_BYTE)st.wMonth;
+ dt.day = (FX_BYTE)st.wDay;
+ dt.hour = (FX_BYTE)st.wHour;
+ dt.minute = (FX_BYTE)st.wMinute;
+ dt.second = (FX_BYTE)st.wSecond;
+// dt.tzHour = _timezone / 3600 * -1;
+// dt.tzMinute = (abs(_timezone) % 3600) / 60;
+ return *this;
+}
+
+FX_BOOL CPDFSDK_DateTime::operator == (CPDFSDK_DateTime& datetime)
+{
+ return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0);
+}
+
+FX_BOOL CPDFSDK_DateTime::operator != (CPDFSDK_DateTime& datetime)
+{
+ return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0);
+}
+
+FX_BOOL CPDFSDK_DateTime::operator > (CPDFSDK_DateTime& datetime)
+{
+ CPDFSDK_DateTime dt1 = ToGMT();
+ CPDFSDK_DateTime dt2 = datetime.ToGMT();
+ int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
+ int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
+ int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
+ int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
+
+ if (d1 > d3) return TRUE;
+ if (d2 > d4) return TRUE;
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_DateTime::operator >= (CPDFSDK_DateTime& datetime)
+{
+ CPDFSDK_DateTime dt1 = ToGMT();
+ CPDFSDK_DateTime dt2 = datetime.ToGMT();
+ int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
+ int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
+ int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
+ int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
+
+ if (d1 >= d3) return TRUE;
+ if (d2 >= d4) return TRUE;
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_DateTime::operator < (CPDFSDK_DateTime& datetime)
+{
+ CPDFSDK_DateTime dt1 = ToGMT();
+ CPDFSDK_DateTime dt2 = datetime.ToGMT();
+ int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
+ int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
+ int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
+ int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
+
+ if (d1 < d3) return TRUE;
+ if (d2 < d4) return TRUE;
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_DateTime::operator <= (CPDFSDK_DateTime& datetime)
+{
+ CPDFSDK_DateTime dt1 = ToGMT();
+ CPDFSDK_DateTime dt2 = datetime.ToGMT();
+ int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
+ int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
+ int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
+ int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
+
+ if (d1 <= d3) return TRUE;
+ if (d2 <= d4) return TRUE;
+ return FALSE;
+}
+
+CPDFSDK_DateTime::operator time_t()
+{
+ struct tm newtime;
+
+ newtime.tm_year = dt.year - 1900;
+ newtime.tm_mon = dt.month - 1;
+ newtime.tm_mday = dt.day;
+ newtime.tm_hour = dt.hour;
+ newtime.tm_min = dt.minute;
+ newtime.tm_sec = dt.second;
+
+ return mktime(&newtime);
+}
+
+CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(const CFX_ByteString& dtStr)
+{
+ int strLength = dtStr.GetLength();
+ if (strLength > 0)
+ {
+ int i = 0;
+ int j, k;
+ FX_CHAR ch;
+ while (i < strLength)
+ {
+ ch = dtStr[i];
+ if (ch >= '0' && ch <= '9') break;
+ i ++;
+ }
+ if (i >= strLength) return *this;
+
+ j = 0;
+ k = 0;
+ while (i < strLength && j < 4)
+ {
+ ch = dtStr[i];
+ k = k * 10 + ch - '0';
+ j ++;
+ if (ch < '0' || ch > '9') break;
+ i ++;
+ }
+ dt.year = (FX_SHORT)k;
+ if (i >= strLength || j < 4) return *this;
+
+ j = 0;
+ k = 0;
+ while (i < strLength && j < 2)
+ {
+ ch = dtStr[i];
+ k = k * 10 + ch - '0';
+ j ++;
+ if (ch < '0' || ch > '9') break;
+ i ++;
+ }
+ dt.month = (FX_BYTE)k;
+ if (i >= strLength || j < 2) return *this;
+
+ j = 0;
+ k = 0;
+ while (i < strLength && j < 2)
+ {
+ ch = dtStr[i];
+ k = k * 10 + ch - '0';
+ j ++;
+ if (ch < '0' || ch > '9') break;
+ i ++;
+ }
+ dt.day = (FX_BYTE)k;
+ if (i >= strLength || j < 2) return *this;
+
+ j = 0;
+ k = 0;
+ while (i < strLength && j < 2)
+ {
+ ch = dtStr[i];
+ k = k * 10 + ch - '0';
+ j ++;
+ if (ch < '0' || ch > '9') break;
+ i ++;
+ }
+ dt.hour = (FX_BYTE)k;
+ if (i >= strLength || j < 2) return *this;
+
+ j = 0;
+ k = 0;
+ while (i < strLength && j < 2)
+ {
+ ch = dtStr[i];
+ k = k * 10 + ch - '0';
+ j ++;
+ if (ch < '0' || ch > '9') break;
+ i ++;
+ }
+ dt.minute = (FX_BYTE)k;
+ if (i >= strLength || j < 2) return *this;
+
+ j = 0;
+ k = 0;
+ while (i < strLength && j < 2)
+ {
+ ch = dtStr[i];
+ k = k * 10 + ch - '0';
+ j ++;
+ if (ch < '0' || ch > '9') break;
+ i ++;
+ }
+ dt.second = (FX_BYTE)k;
+ if (i >= strLength || j < 2) return *this;
+
+ ch = dtStr[i ++];
+ if (ch != '-' && ch != '+') return *this;
+ if (ch == '-')
+ dt.tzHour = -1;
+ else
+ dt.tzHour = 1;
+ j = 0;
+ k = 0;
+ while (i < strLength && j < 2)
+ {
+ ch = dtStr[i];
+ k = k * 10 + ch - '0';
+ j ++;
+ if (ch < '0' || ch > '9') break;
+ i ++;
+ }
+ dt.tzHour *= (FX_CHAR)k;
+ if (i >= strLength || j < 2) return *this;
+
+ ch = dtStr[i ++];
+ if (ch != '\'') return *this;
+ j = 0;
+ k = 0;
+ while (i < strLength && j < 2)
+ {
+ ch = dtStr[i];
+ k = k * 10 + ch - '0';
+ j ++;
+ if (ch < '0' || ch > '9') break;
+ i ++;
+ }
+ dt.tzMinute = (FX_BYTE)k;
+ if (i >= strLength || j < 2) return *this;
+ }
+
+ return *this;
+}
+
+CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString()
+{
+ CFX_ByteString str1;
+ str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
+ if (dt.tzHour < 0)
+ str1 += "-";
+ else
+ str1 += "+";
+ CFX_ByteString str2;
+ str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute);
+ return str1 + str2;
+}
+
+CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString()
+{
+ CFX_ByteString dtStr;
+ char tempStr[32];
+ sprintf(tempStr, "D:%04d%02d%02d%02d%02d%02d", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
+ dtStr = CFX_ByteString(tempStr);
+ if (dt.tzHour < 0)
+ dtStr += CFX_ByteString("-");
+ else
+ dtStr += CFX_ByteString("+");
+ sprintf(tempStr, "%02d'%02d'", abs(dt.tzHour), dt.tzMinute);
+ dtStr += CFX_ByteString(tempStr);
+ return dtStr;
+}
+
+void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st)
+{
+ CPDFSDK_DateTime dt = *this;
+ time_t t = (time_t)dt;
+ struct tm* pTime = localtime(&t);
+ if(pTime){
+ st.wYear = (FX_WORD)pTime->tm_year + 1900;
+ st.wMonth = (FX_WORD)pTime->tm_mon + 1;
+ st.wDay = (FX_WORD)pTime->tm_mday;
+ st.wDayOfWeek = (FX_WORD)pTime->tm_wday;
+ st.wHour = (FX_WORD)pTime->tm_hour;
+ st.wMinute = (FX_WORD)pTime->tm_min;
+ st.wSecond = (FX_WORD)pTime->tm_sec;
+ st.wMilliseconds = 0;
+ }
+}
+
+CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT()
+{
+ CPDFSDK_DateTime dt = *this;
+ dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute));
+ dt.dt.tzHour = 0;
+ dt.dt.tzMinute = 0;
+ return dt;
+}
+
+CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days)
+{
+ if (days == 0) return *this;
+
+ FX_SHORT y = dt.year, yy;
+ FX_BYTE m = dt.month;
+ FX_BYTE d = dt.day;
+ int mdays, ydays, ldays;
+
+ ldays = days;
+ if (ldays > 0)
+ {
+ yy = y;
+ if (((FX_WORD)m * 100 + d) > 300) yy ++;
+ ydays = _gAfxGetYearDays(yy);
+ while (ldays >= ydays)
+ {
+ y ++;
+ ldays -= ydays;
+ yy ++;
+ mdays = _gAfxGetMonthDays(y, m);
+ if (d > mdays)
+ {
+ m ++;
+ d -= mdays;
+ }
+ ydays = _gAfxGetYearDays(yy);
+ }
+ mdays = _gAfxGetMonthDays(y, m) - d + 1;
+ while (ldays >= mdays)
+ {
+ ldays -= mdays;
+ m ++;
+ d = 1;
+ mdays = _gAfxGetMonthDays(y, m);
+ }
+ d += ldays;
+ }
+ else
+ {
+ ldays *= -1;
+ yy = y;
+ if (((FX_WORD)m * 100 + d) < 300) yy --;
+ ydays = _gAfxGetYearDays(yy);
+ while (ldays >= ydays)
+ {
+ y --;
+ ldays -= ydays;
+ yy --;
+ mdays = _gAfxGetMonthDays(y, m);
+ if (d > mdays)
+ {
+ m ++;
+ d -= mdays;
+ }
+ ydays = _gAfxGetYearDays(yy);
+ }
+ while (ldays >= d)
+ {
+ ldays -= d;
+ m --;
+ mdays = _gAfxGetMonthDays(y, m);
+ d = mdays;
+ }
+ d -= ldays;
+ }
+
+ dt.year = y;
+ dt.month = m;
+ dt.day = d;
+
+ return *this;
+}
+
+CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds)
+{
+ if (seconds == 0) return *this;
+
+ int n;
+ int days;
+
+ n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds;
+ if (n < 0)
+ {
+ days = (n - 86399) / 86400;
+ n -= days * 86400;
+ }
+ else
+ {
+ days = n / 86400;
+ n %= 86400;
+ }
+ dt.hour = (FX_BYTE)(n / 3600);
+ dt.hour %= 24;
+ n %= 3600;
+ dt.minute = (FX_BYTE)(n / 60);
+ dt.second = (FX_BYTE)(n % 60);
+ if (days != 0) AddDays(days);
+
+ return *this;
+}
+
+
+//---------------------------------------------------------------------------
+// CPDFSDK_Annot
+//---------------------------------------------------------------------------
+CPDFSDK_Annot::CPDFSDK_Annot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) :
+m_pAnnot(pAnnot),
+m_pPageView(pPageView),
+m_bSelected(FALSE),
+m_nTabOrder(-1)
+{
+}
+
+CPDFSDK_Annot::~CPDFSDK_Annot()
+{
+ m_pAnnot = NULL;
+ m_pPageView = NULL;
+}
+
+CPDF_Annot* CPDFSDK_Annot::GetPDFAnnot()
+{
+ return m_pAnnot;
+}
+
+FX_DWORD CPDFSDK_Annot::GetFlags()
+{
+ ASSERT(m_pAnnot != NULL);
+
+ return m_pAnnot->GetFlags();
+}
+
+void CPDFSDK_Annot::SetPage(CPDFSDK_PageView* pPageView)
+{
+ m_pPageView = pPageView;
+}
+
+CPDFSDK_PageView* CPDFSDK_Annot::GetPageView()
+{
+ return m_pPageView;
+}
+
+FX_BOOL CPDFSDK_Annot::IsSelected()
+{
+ return m_bSelected;
+}
+
+void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected)
+{
+ m_bSelected = bSelected;
+}
+
+// Tab Order
+int CPDFSDK_Annot::GetTabOrder()
+{
+ return m_nTabOrder;
+}
+
+void CPDFSDK_Annot::SetTabOrder(int iTabOrder)
+{
+ m_nTabOrder = iTabOrder;
+}
+
+CPDF_Dictionary* CPDFSDK_Annot::GetAnnotDict() const
+{
+ ASSERT(m_pAnnot != NULL);
+
+ return m_pAnnot->m_pAnnotDict;
+}
+
+void CPDFSDK_Annot::SetRect(const CPDF_Rect& rect)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+ ASSERT(rect.right - rect.left >= GetMinWidth());
+ ASSERT(rect.top - rect.bottom >= GetMinHeight());
+
+ m_pAnnot->m_pAnnotDict->SetAtRect("Rect", rect);
+}
+
+CPDF_Rect CPDFSDK_Annot::GetRect() const
+{
+ ASSERT(m_pAnnot != NULL);
+
+ CPDF_Rect rect;
+ m_pAnnot->GetRect(rect);
+
+ return rect;
+}
+
+CFX_ByteString CPDFSDK_Annot::GetType() const
+{
+ ASSERT(m_pAnnot != NULL);
+
+ return m_pAnnot->GetSubType();
+}
+
+CFX_ByteString CPDFSDK_Annot::GetSubType() const
+{
+ return "";
+}
+
+void CPDFSDK_Annot::ResetAppearance()
+{
+ ASSERT(FALSE);
+}
+
+void CPDFSDK_Annot::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
+ CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
+{
+ ASSERT(m_pPageView != NULL);
+ ASSERT(m_pAnnot != NULL);
+
+ m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, mode, pOptions);
+}
+
+FX_BOOL CPDFSDK_Annot::IsAppearanceValid()
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ return m_pAnnot->m_pAnnotDict->GetDict("AP") != NULL;
+}
+
+FX_BOOL CPDFSDK_Annot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP");
+ if (pAP == NULL) return FALSE;
+
+ // Choose the right sub-ap
+ const FX_CHAR* ap_entry = "N";
+ if (mode == CPDF_Annot::Down)
+ ap_entry = "D";
+ else if (mode == CPDF_Annot::Rollover)
+ ap_entry = "R";
+ if (!pAP->KeyExist(ap_entry))
+ ap_entry = "N";
+
+ // Get the AP stream or subdirectory
+ CPDF_Object* psub = pAP->GetElementValue(ap_entry);
+ if (psub == NULL) return FALSE;
+
+ return TRUE;
+}
+
+void CPDFSDK_Annot::DrawBorder(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
+ const CPDF_RenderOptions* pOptions)
+{
+ ASSERT(m_pAnnot != NULL);
+ m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
+}
+
+void CPDFSDK_Annot::ClearCachedAP()
+{
+ ASSERT(m_pAnnot != NULL);
+ m_pAnnot->ClearCachedAP();
+}
+
+void CPDFSDK_Annot::SetContents(const CFX_WideString& sContents)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ if (sContents.IsEmpty())
+ m_pAnnot->m_pAnnotDict->RemoveAt("Contents");
+ else
+ m_pAnnot->m_pAnnotDict->SetAtString("Contents", PDF_EncodeText(sContents));
+}
+
+CFX_WideString CPDFSDK_Annot::GetContents() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ return m_pAnnot->m_pAnnotDict->GetUnicodeText("Contents");
+}
+
+void CPDFSDK_Annot::SetAnnotName(const CFX_WideString& sName)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ if (sName.IsEmpty())
+ m_pAnnot->m_pAnnotDict->RemoveAt("NM");
+ else
+ m_pAnnot->m_pAnnotDict->SetAtString("NM", PDF_EncodeText(sName));
+}
+
+CFX_WideString CPDFSDK_Annot::GetAnnotName() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ return m_pAnnot->m_pAnnotDict->GetUnicodeText("NM");
+}
+
+void CPDFSDK_Annot::SetModifiedDate(const FX_SYSTEMTIME& st)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDFSDK_DateTime dt(st);
+ CFX_ByteString str = dt.ToPDFDateTimeString();
+
+ if (str.IsEmpty())
+ m_pAnnot->m_pAnnotDict->RemoveAt("M");
+ else
+ m_pAnnot->m_pAnnotDict->SetAtString("M", str);
+}
+
+FX_SYSTEMTIME CPDFSDK_Annot::GetModifiedDate() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ FX_SYSTEMTIME systime;
+ CFX_ByteString str = m_pAnnot->m_pAnnotDict->GetString("M");
+
+ CPDFSDK_DateTime dt(str);
+ dt.ToSystemTime(systime);
+
+ return systime;
+}
+
+void CPDFSDK_Annot::SetFlags(int nFlags)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ m_pAnnot->m_pAnnotDict->SetAtInteger("F", nFlags);
+}
+
+int CPDFSDK_Annot::GetFlags() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ return m_pAnnot->m_pAnnotDict->GetInteger("F");
+}
+
+void CPDFSDK_Annot::SetAppState(const CFX_ByteString& str)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ if (str.IsEmpty())
+ m_pAnnot->m_pAnnotDict->RemoveAt("AS");
+ else
+ m_pAnnot->m_pAnnotDict->SetAtString("AS", str);
+}
+
+CFX_ByteString CPDFSDK_Annot::GetAppState() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ return m_pAnnot->m_pAnnotDict->GetString("AS");
+}
+
+void CPDFSDK_Annot::SetStructParent(int key)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ m_pAnnot->m_pAnnotDict->SetAtInteger("StructParent", key);
+}
+
+int CPDFSDK_Annot::GetStructParent() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ return m_pAnnot->m_pAnnotDict->GetInteger("StructParent");
+}
+
+//border
+void CPDFSDK_Annot::SetBorderWidth(int nWidth)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");
+
+ if (pBorder)
+ {
+ pBorder->SetAt(2, FX_NEW CPDF_Number(nWidth));
+ }
+ else
+ {
+ CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
+
+ if (!pBSDict)
+ {
+ pBSDict = FX_NEW CPDF_Dictionary;
+ m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict);
+ }
+
+ pBSDict->SetAtInteger("W", nWidth);
+ }
+}
+
+int CPDFSDK_Annot::GetBorderWidth() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");
+
+ if (pBorder)
+ {
+ return pBorder->GetInteger(2);
+ }
+ else
+ {
+ CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
+
+ if (pBSDict)
+ {
+ return pBSDict->GetInteger("W", 1);
+ }
+ }
+ return 1;
+}
+
+void CPDFSDK_Annot::SetBorderStyle(int nStyle)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
+ if (!pBSDict)
+ {
+ pBSDict = FX_NEW CPDF_Dictionary;
+ m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict);
+ }
+
+ switch (nStyle)
+ {
+ case BBS_SOLID:
+ pBSDict->SetAtName("S", "S");
+ break;
+ case BBS_DASH:
+ pBSDict->SetAtName("S", "D");
+ break;
+ case BBS_BEVELED:
+ pBSDict->SetAtName("S", "B");
+ break;
+ case BBS_INSET:
+ pBSDict->SetAtName("S", "I");
+ break;
+ case BBS_UNDERLINE:
+ pBSDict->SetAtName("S", "U");
+ break;
+ }
+}
+
+int CPDFSDK_Annot::GetBorderStyle() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
+ if (pBSDict)
+ {
+ CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
+ if (sBorderStyle == "S") return BBS_SOLID;
+ if (sBorderStyle == "D") return BBS_DASH;
+ if (sBorderStyle == "B") return BBS_BEVELED;
+ if (sBorderStyle == "I") return BBS_INSET;
+ if (sBorderStyle == "U") return BBS_UNDERLINE;
+ }
+
+ CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");
+ if (pBorder)
+ {
+ if (pBorder->GetCount() >= 4)
+ {
+ CPDF_Array *pDP = pBorder->GetArray(3);
+ if (pDP && pDP->GetCount() > 0)
+ return BBS_DASH;
+ }
+ }
+
+ return BBS_SOLID;
+}
+
+void CPDFSDK_Annot::SetBorderDash(const CFX_IntArray& array)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
+ if (!pBSDict)
+ {
+ pBSDict = FX_NEW CPDF_Dictionary;
+ m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict);
+ }
+
+ CPDF_Array* pArray = FX_NEW CPDF_Array;
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ {
+ pArray->AddInteger(array[i]);
+ }
+
+ pBSDict->SetAt("D", pArray);
+}
+
+void CPDFSDK_Annot::GetBorderDash(CFX_IntArray& array) const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Array* pDash = NULL;
+
+ CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");
+ if (pBorder)
+ {
+ pDash = pBorder->GetArray(3);
+ }
+ else
+ {
+ CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
+ if (pBSDict)
+ {
+ pDash = pBSDict->GetArray("D");
+ }
+ }
+
+ if (pDash)
+ {
+ for (int i=0,sz=pDash->GetCount(); i<sz; i++)
+ {
+ array.Add(pDash->GetInteger(i));
+ }
+ }
+}
+
+void CPDFSDK_Annot::SetColor(FX_COLORREF color)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Array* pArray = FX_NEW CPDF_Array;
+ pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
+ pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
+ pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
+ m_pAnnot->m_pAnnotDict->SetAt("C", pArray);
+}
+
+void CPDFSDK_Annot::RemoveColor()
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ m_pAnnot->m_pAnnotDict->RemoveAt("C") ;
+}
+
+FX_BOOL CPDFSDK_Annot::GetColor(FX_COLORREF& color) const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ if (CPDF_Array* pEntry = m_pAnnot->m_pAnnotDict->GetArray("C"))
+ {
+ int nCount = pEntry->GetCount();
+ if (nCount == 1)
+ {
+ FX_FLOAT g = pEntry->GetNumber(0) * 255;
+
+ color = FXSYS_RGB((int)g, (int)g, (int)g);
+
+ return TRUE;
+ }
+ else if (nCount == 3)
+ {
+ FX_FLOAT r = pEntry->GetNumber(0) * 255;
+ FX_FLOAT g = pEntry->GetNumber(1) * 255;
+ FX_FLOAT b = pEntry->GetNumber(2) * 255;
+
+ color = FXSYS_RGB((int)r, (int)g, (int)b);
+
+ return TRUE;
+ }
+ else if (nCount == 4)
+ {
+ FX_FLOAT c = pEntry->GetNumber(0);
+ FX_FLOAT m = pEntry->GetNumber(1);
+ FX_FLOAT y = pEntry->GetNumber(2);
+ FX_FLOAT k = pEntry->GetNumber(3);
+
+ FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
+ FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
+ FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
+
+ color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+
+void CPDFSDK_Annot::WriteAppearance(const CFX_ByteString& sAPType, const CPDF_Rect& rcBBox,
+ const CPDF_Matrix& matrix, const CFX_ByteString& sContents,
+ const CFX_ByteString& sAPState)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP");
+
+ if (!pAPDict)
+ {
+ pAPDict = FX_NEW CPDF_Dictionary;
+ m_pAnnot->m_pAnnotDict->SetAt("AP", pAPDict);
+ }
+
+ CPDF_Stream* pStream = NULL;
+ CPDF_Dictionary* pParentDict = NULL;
+
+ if (sAPState.IsEmpty())
+ {
+ pParentDict = pAPDict;
+ pStream = pAPDict->GetStream(sAPType);
+ }
+ else
+ {
+ CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
+ if (!pAPTypeDict)
+ {
+ pAPTypeDict = FX_NEW CPDF_Dictionary;
+ pAPDict->SetAt(sAPType, pAPTypeDict);
+ }
+
+ pParentDict = pAPTypeDict;
+ pStream = pAPTypeDict->GetStream(sAPState);
+ }
+
+ if (!pStream)
+ {
+ ASSERT(m_pPageView != NULL);
+ CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
+ ASSERT(pDoc != NULL);
+
+ pStream = FX_NEW CPDF_Stream(NULL, 0, NULL);
+ FX_INT32 objnum = pDoc->AddIndirectObject(pStream);
+ //pAPDict->SetAtReference(sAPType, pDoc, objnum);
+ ASSERT(pParentDict != NULL);
+ pParentDict->SetAtReference(sAPType, pDoc, objnum);
+ }
+
+ CPDF_Dictionary * pStreamDict = pStream->GetDict();
+
+ if (!pStreamDict)
+ {
+ pStreamDict = FX_NEW CPDF_Dictionary;
+ pStreamDict->SetAtName("Type", "XObject");
+ pStreamDict->SetAtName("Subtype", "Form");
+ pStreamDict->SetAtInteger("FormType", 1);
+ pStream->InitStream(NULL,0,pStreamDict);
+ }
+
+ if (pStreamDict)
+ {
+ pStreamDict->SetAtMatrix("Matrix",matrix);
+ pStreamDict->SetAtRect("BBox", rcBBox);
+ }
+
+ pStream->SetData((FX_BYTE*)(FX_LPCSTR)sContents, sContents.GetLength(), FALSE, FALSE);
+}
+
+#define BA_ANNOT_MINWIDTH 1
+#define BA_ANNOT_MINHEIGHT 1
+
+FX_FLOAT CPDFSDK_Annot::GetMinWidth() const
+{
+ return BA_ANNOT_MINWIDTH;
+}
+
+FX_FLOAT CPDFSDK_Annot::GetMinHeight() const
+{
+ return BA_ANNOT_MINHEIGHT;
+}
+
+FX_BOOL CPDFSDK_Annot::CreateFormFiller()
+{
+ return TRUE;
+}
+FX_BOOL CPDFSDK_Annot::IsVisible() const
+{
+ int nFlags = GetFlags();
+ return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || (nFlags & ANNOTFLAG_NOVIEW));
+}
+
+CPDF_Action CPDFSDK_Annot::GetAction() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ return m_pAnnot->m_pAnnotDict->GetDict("A");
+}
+
+void CPDFSDK_Annot::SetAction(const CPDF_Action& action)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ ASSERT(action != NULL);
+
+ if ((CPDF_Action&)action != m_pAnnot->m_pAnnotDict->GetDict("A"))
+ {
+ CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
+ ASSERT(pDoc != NULL);
+
+ if (action.m_pDict && (action.m_pDict->GetObjNum() == 0))
+ pDoc->AddIndirectObject(action.m_pDict);
+ m_pAnnot->m_pAnnotDict->SetAtReference("A", pDoc, action.m_pDict->GetObjNum());
+ }
+}
+
+void CPDFSDK_Annot::RemoveAction()
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ m_pAnnot->m_pAnnotDict->RemoveAt("A");
+}
+
+CPDF_AAction CPDFSDK_Annot::GetAAction() const
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ return m_pAnnot->m_pAnnotDict->GetDict("AA");
+}
+
+void CPDFSDK_Annot::SetAAction(const CPDF_AAction& aa)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+ ASSERT(aa != NULL);
+
+ if ((CPDF_AAction&)aa != m_pAnnot->m_pAnnotDict->GetDict("AA"))
+ m_pAnnot->m_pAnnotDict->SetAt("AA", (CPDF_AAction&)aa);
+}
+
+void CPDFSDK_Annot::RemoveAAction()
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ m_pAnnot->m_pAnnotDict->RemoveAt("AA");
+}
+
+CPDF_Action CPDFSDK_Annot::GetAAction(CPDF_AAction::AActionType eAAT)
+{
+ CPDF_AAction AAction = GetAAction();
+
+ if (AAction.ActionExist(eAAT))
+ {
+ return AAction.GetAction(eAAT);
+ }
+ else if (eAAT == CPDF_AAction::ButtonUp)
+ {
+ return GetAction();
+ }
+
+ return NULL;
+}
+
+void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions)
+{
+
+ m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
+ m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+
+ return ;
+}
+
+CPDF_Page* CPDFSDK_Annot::GetPDFPage()
+{
+ if(m_pPageView)
+ return m_pPageView->GetPDFPage();
+ return NULL;
+}
+
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index 23d9ec9c47..ae3b6364d3 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -1,3111 +1,3111 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fsdk_mgr.h"
-#include "../include/fsdk_baseannot.h"
-#include "../include/fsdk_baseform.h"
-#include "../include/formfiller/FFL_FormFiller.h"
-#include "../include/fsdk_actionhandler.h"
-
-#include "../include/javascript/IJavaScript.h"
-
-//------------------------------------------------------------------------------------
-//* CPDFSDK_Widget
-//------------------------------------------------------------------------------------
-
-#define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01)
-#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
-
-CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) :
- CPDFSDK_Annot(pAnnot, pPageView),
- m_pInterForm(pInterForm),
- m_nAppAge(0),
- m_nValueAge(0)
-{
- ASSERT(m_pInterForm != NULL);
-}
-
-CPDFSDK_Widget::~CPDFSDK_Widget()
-{
-
-}
-
-FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP");
- if (pAP == NULL) return FALSE;
-
- // Choose the right sub-ap
- const FX_CHAR* ap_entry = "N";
- if (mode == CPDF_Annot::Down)
- ap_entry = "D";
- else if (mode == CPDF_Annot::Rollover)
- ap_entry = "R";
- if (!pAP->KeyExist(ap_entry))
- ap_entry = "N";
-
- // Get the AP stream or subdirectory
- CPDF_Object* psub = pAP->GetElementValue(ap_entry);
- if (psub == NULL) return FALSE;
-
- int nFieldType = GetFieldType();
- switch (nFieldType)
- {
- case FIELDTYPE_PUSHBUTTON:
- case FIELDTYPE_COMBOBOX:
- case FIELDTYPE_LISTBOX:
- case FIELDTYPE_TEXTFIELD:
- case FIELDTYPE_SIGNATURE:
- return psub->GetType() == PDFOBJ_STREAM;
- case FIELDTYPE_CHECKBOX:
- case FIELDTYPE_RADIOBUTTON:
- if (psub->GetType() == PDFOBJ_DICTIONARY)
- {
- CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;
-
- return pSubDict->GetStream(this->GetAppState()) != NULL;
- }
- else
- return FALSE;
- break;
- }
-
- return TRUE;
-}
-
-int CPDFSDK_Widget::GetFieldType() const
-{
- CPDF_FormField* pField = GetFormField();
- ASSERT(pField != NULL);
-
- return pField->GetFieldType();
-}
-
-int CPDFSDK_Widget::GetFieldFlags() const
-{
- CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
- ASSERT(pPDFInterForm != NULL);
-
- CPDF_FormControl* pFormControl = pPDFInterForm->GetControlByDict(m_pAnnot->m_pAnnotDict);
- CPDF_FormField* pFormField = pFormControl->GetField();
- return pFormField->GetFieldFlags();
-}
-
-CFX_ByteString CPDFSDK_Widget::GetSubType() const
-{
- int nType = GetFieldType();
-
- if (nType == FIELDTYPE_SIGNATURE)
- return BFFT_SIGNATURE;
- return CPDFSDK_Annot::GetSubType();
-}
-
-CPDF_FormField* CPDFSDK_Widget::GetFormField() const
-{
- ASSERT(m_pInterForm != NULL);
-
- CPDF_FormControl* pCtrl = GetFormControl();
- ASSERT(pCtrl != NULL);
-
- return pCtrl->GetField();
-}
-
-CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const
-{
- ASSERT(m_pInterForm != NULL);
-
- CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
- ASSERT(pPDFInterForm != NULL);
-
- return pPDFInterForm->GetControlByDict(GetAnnotDict());
-}
-static CPDF_Dictionary* BF_GetField(CPDF_Dictionary* pFieldDict, const FX_CHAR* name)
-{
- if (pFieldDict == NULL) return NULL;
- // First check the dictionary itself
- CPDF_Object* pAttr = pFieldDict->GetElementValue(name);
- if (pAttr) return pFieldDict;
-
- // Now we need to search from parents
- CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent");
- if (pParent == NULL) return NULL;
-
- return BF_GetField(pParent, name);
-}
-
-CPDF_FormControl* CPDFSDK_Widget::GetFormControl(CPDF_InterForm* pInterForm, CPDF_Dictionary* pAnnotDict)
-{
- ASSERT(pInterForm != NULL);
- ASSERT(pAnnotDict != NULL);
-
- CPDF_FormControl* pControl = pInterForm->GetControlByDict(pAnnotDict);
-
- return pControl;
-}
-
-int CPDFSDK_Widget::GetRotate() const
-{
- CPDF_FormControl* pCtrl = this->GetFormControl();
- ASSERT(pCtrl != NULL);
-
- return pCtrl->GetRotation() % 360;
-}
-
-FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const
-{
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- int iColorType = 0;
- color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType));
-
- return iColorType != COLORTYPE_TRANSPARENT;
-}
-
-FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const
-{
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- int iColorType = 0;
- color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType));
-
- return iColorType != COLORTYPE_TRANSPARENT;
-}
-
-FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const
-{
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
- if (da.HasColor())
- {
- FX_ARGB argb;
- int iColorType = COLORTYPE_TRANSPARENT;
- da.GetColor(argb, iColorType);
- color = FX_ARGBTOCOLORREF(argb);
-
- return iColorType != COLORTYPE_TRANSPARENT;
- }
-
- return FALSE;
-}
-
-FX_FLOAT CPDFSDK_Widget::GetFontSize() const
-{
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
- CFX_ByteString csFont = "";
- FX_FLOAT fFontSize = 0.0f;
- pDa.GetFont(csFont, fFontSize);
-
- return fFontSize;
-}
-
-int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- return pFormField->GetSelectedIndex(nIndex);
-}
-
-CFX_WideString CPDFSDK_Widget::GetValue() const
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- return pFormField->GetValue();
-}
-
-CFX_WideString CPDFSDK_Widget::GetDefaultValue() const
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- return pFormField->GetDefaultValue();
-}
-
-CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- return pFormField->GetOptionLabel(nIndex);
-}
-
-int CPDFSDK_Widget::CountOptions() const
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- return pFormField->CountOptions();
-}
-
-FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- return pFormField->IsItemSelected(nIndex);
-}
-
-int CPDFSDK_Widget::GetTopVisibleIndex() const
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- return pFormField->GetTopVisibleIndex();
-}
-
-FX_BOOL CPDFSDK_Widget::IsChecked() const
-{
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- return pFormCtrl->IsChecked();
-}
-
-int CPDFSDK_Widget::GetAlignment() const
-{
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- return pFormCtrl->GetControlAlignment();
-}
-
-int CPDFSDK_Widget::GetMaxLen() const
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- return pFormField->GetMaxLen();
-}
-
-void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify)
-{
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- CPDF_FormField* pFormField = pFormCtrl->GetField();
- ASSERT(pFormField != NULL);
-
- pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, bNotify);
-}
-
-void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify)
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- pFormField->SetValue(sValue, bNotify);
-}
-
-void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue)
-{
-}
-void CPDFSDK_Widget::SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify)
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- pFormField->SetItemSelection(index, bSelected, bNotify);
-}
-
-void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify)
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- pFormField->ClearSelection(bNotify);
-}
-
-void CPDFSDK_Widget::SetTopVisibleIndex(int index)
-{
-}
-
-void CPDFSDK_Widget::SetAppModified()
-{
- m_bAppModified = TRUE;
-}
-
-void CPDFSDK_Widget::ClearAppModified()
-{
- m_bAppModified = FALSE;
-}
-
-FX_BOOL CPDFSDK_Widget::IsAppModified() const
-{
- return m_bAppModified;
-}
-
-void CPDFSDK_Widget::ResetAppearance(FX_LPCWSTR sValue, FX_BOOL bValueChanged)
-{
- SetAppModified();
-
- m_nAppAge++;
- if (m_nAppAge > 999999)
- m_nAppAge = 0;
- if (bValueChanged)
- m_nValueAge++;
-
- int nFieldType = GetFieldType();
-
- switch (nFieldType)
- {
- case FIELDTYPE_PUSHBUTTON:
- ResetAppearance_PushButton();
- break;
- case FIELDTYPE_CHECKBOX:
- ResetAppearance_CheckBox();
- break;
- case FIELDTYPE_RADIOBUTTON:
- ResetAppearance_RadioButton();
- break;
- case FIELDTYPE_COMBOBOX:
- ResetAppearance_ComboBox(sValue);
- break;
- case FIELDTYPE_LISTBOX:
- ResetAppearance_ListBox();
- break;
- case FIELDTYPE_TEXTFIELD:
- ResetAppearance_TextField(sValue);
- break;
- }
-
- ASSERT(m_pAnnot != NULL);
- m_pAnnot->ClearCachedAP();
-}
-
-CFX_WideString CPDFSDK_Widget::OnFormat(int nCommitKey, FX_BOOL& bFormated)
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- ASSERT(m_pInterForm != NULL);
-
- return m_pInterForm->OnFormat(pFormField, nCommitKey, bFormated);
-
-}
-
-void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged)
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- ASSERT(m_pInterForm != NULL);
-
- m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged);
-}
-
-void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
- CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
-{
- int nFieldType = GetFieldType();
-
- if ((nFieldType == FIELDTYPE_CHECKBOX || nFieldType == FIELDTYPE_RADIOBUTTON) &&
- mode == CPDF_Annot::Normal &&
- !this->IsWidgetAppearanceValid(CPDF_Annot::Normal))
- {
- CFX_PathData pathData;
-
- CPDF_Rect rcAnnot = this->GetRect();
-
- pathData.AppendRect(rcAnnot.left, rcAnnot.bottom,
- rcAnnot.right, rcAnnot.top);
-
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = 0.0f;
-
- pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, FXFILL_ALTERNATE);
- }
- else
- {
- CPDFSDK_Annot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
- }
-}
-
-void CPDFSDK_Widget::UpdateField()
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- ASSERT(m_pInterForm != NULL);
- m_pInterForm->UpdateField(pFormField);
-}
-
-void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView)
-{
- ASSERT(m_pInterForm != NULL);
-
- int nFieldType = GetFieldType();
- if (m_pInterForm->IsNeedHighLight(nFieldType))
- {
-
-// if (nFieldType != FIELDTYPE_PUSHBUTTON)
-// {
- CPDF_Rect rc = GetRect();
- FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
- FX_BYTE alpha = m_pInterForm->GetHighlightAlpha();
-
- CFX_FloatRect rcDevice;
- ASSERT(m_pInterForm->GetDocument());
- CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
- if(!pEnv)
- return;
- CFX_AffineMatrix page2device;
- pPageView->GetCurrentMatrix(page2device);
- page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), rcDevice.left, rcDevice.bottom);
-// pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.left, rc.bottom, &rcDevice.left, &rcDevice.bottom);
-// pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.right, rc.top, &rcDevice.right, &rcDevice.top);
- page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), rcDevice.right, rcDevice.top);
-
- rcDevice.Normalize();
-
- FX_ARGB argb = ArgbEncode((int)alpha, color);
- FX_RECT rcDev((int)rcDevice.left,(int)rcDevice.top,(int)rcDevice.right,(int)rcDevice.bottom);
- pDevice->FillRect(&rcDev, argb);
- /* }*/
- }
-}
-
-void CPDFSDK_Widget::ResetAppearance_PushButton()
-{
- CPDF_FormControl* pControl = GetFormControl();
- ASSERT(pControl != NULL);
-
-
-
- CPDF_Rect rcWindow = GetRotatedRect();
-
- FX_INT32 nLayout = 0;
-
- switch (pControl->GetTextPosition())
- {
- case TEXTPOS_ICON:
- nLayout = PPBL_ICON;
- break;
- case TEXTPOS_BELOW:
- nLayout = PPBL_ICONTOPLABELBOTTOM;
- break;
- case TEXTPOS_ABOVE:
- nLayout = PPBL_LABELTOPICONBOTTOM;
- break;
- case TEXTPOS_RIGHT:
- nLayout = PPBL_ICONLEFTLABELRIGHT;
- break;
- case TEXTPOS_LEFT:
- nLayout = PPBL_LABELLEFTICONRIGHT;
- break;
- case TEXTPOS_OVERLAID:
- nLayout = PPBL_LABELOVERICON;
- break;
- default:
- nLayout = PPBL_LABEL;
- break;
- }
-
- CPWL_Color crBackground, crBorder;
-
- int iColorType;
- FX_FLOAT fc[4];
-
- pControl->GetOriginalBackgroundColor(iColorType, fc);
- if (iColorType > 0)
- crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- pControl->GetOriginalBorderColor(iColorType, fc);
- if (iColorType > 0)
- crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
- FX_INT32 nBorderStyle = 0;
- CPWL_Dash dsBorder(3,0,0);
- CPWL_Color crLeftTop,crRightBottom;
-
- switch (GetBorderStyle())
- {
- case BBS_DASH:
- nBorderStyle = PBS_DASH;
- dsBorder = CPWL_Dash(3, 3, 0);
- break;
- case BBS_BEVELED:
- nBorderStyle = PBS_BEVELED;
- fBorderWidth *= 2;
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
- crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
- break;
- case BBS_INSET:
- nBorderStyle = PBS_INSET;
- fBorderWidth *= 2;
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
- break;
- case BBS_UNDERLINE:
- nBorderStyle = PBS_UNDERLINED;
- break;
- default:
- nBorderStyle = PBS_SOLID;
- break;
- }
-
- CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);
-
- CPWL_Color crText(COLORTYPE_GRAY,0);
-
- FX_FLOAT fFontSize = 12.0f;
- CFX_ByteString csNameTag;
-
- CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
- if (da.HasColor())
- {
- da.GetColor(iColorType, fc);
- crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
- }
-
- if (da.HasFont())
- da.GetFont(csNameTag, fFontSize);
-
- CFX_WideString csWCaption;
- CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
-
- if (pControl->HasMKEntry("CA"))
- {
- csNormalCaption = pControl->GetNormalCaption();
- }
- if (pControl->HasMKEntry("RC"))
- {
- csRolloverCaption = pControl->GetRolloverCaption();
- }
- if (pControl->HasMKEntry("AC"))
- {
- csDownCaption = pControl->GetDownCaption();
- }
-
- CPDF_Stream* pNormalIcon = NULL;
- CPDF_Stream* pRolloverIcon = NULL;
- CPDF_Stream* pDownIcon = NULL;
-
- if (pControl->HasMKEntry("I"))
- {
- pNormalIcon = pControl->GetNormalIcon();
- }
- if (pControl->HasMKEntry("RI"))
- {
- pRolloverIcon = pControl->GetRolloverIcon();
- }
- if (pControl->HasMKEntry("IX"))
- {
- pDownIcon = pControl->GetDownIcon();
- }
-
- if (pNormalIcon)
- {
- if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict())
- {
- if (pImageDict->GetString("Name").IsEmpty())
- pImageDict->SetAtString("Name", "ImgA");
- }
- }
-
- if (pRolloverIcon)
- {
- if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict())
- {
- if (pImageDict->GetString("Name").IsEmpty())
- pImageDict->SetAtString("Name", "ImgB");
- }
- }
-
- if (pDownIcon)
- {
- if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict())
- {
- if (pImageDict->GetString("Name").IsEmpty())
- pImageDict->SetAtString("Name", "ImgC");
- }
- }
-
- CPDF_IconFit iconFit = pControl->GetIconFit();
-
-// ASSERT(this->m_pBaseForm != NULL);
- ASSERT(this->m_pInterForm != NULL);
- CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
- ASSERT(pDoc != NULL);
- CPDFDoc_Environment* pEnv = pDoc->GetEnv();
-
- CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
- FontMap.Initial();
-
- FontMap.SetAPType("N");
-
- CFX_ByteString csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
- CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
- if (pNormalIcon)
- AddImageToAppearance("N", pNormalIcon);
-
- CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
- if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle)
- {
- if (csRolloverCaption.IsEmpty() && !pRolloverIcon)
- {
- csRolloverCaption = csNormalCaption;
- pRolloverIcon = pNormalIcon;
- }
-
- FontMap.SetAPType("R");
-
- csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
- CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, nLayout);
-
- WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
- if (pRolloverIcon)
- AddImageToAppearance("R", pRolloverIcon);
-
- if (csDownCaption.IsEmpty() && !pDownIcon)
- {
- csDownCaption = csNormalCaption;
- pDownIcon = pNormalIcon;
- }
-
- switch (nBorderStyle)
- {
- case PBS_BEVELED:
- {
- CPWL_Color crTemp = crLeftTop;
- crLeftTop = crRightBottom;
- crRightBottom = crTemp;
- }
- break;
- case PBS_INSET:
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
- break;
- }
-
- FontMap.SetAPType("D");
-
- csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, CPWL_Utils::SubstractColor(crBackground,0.25f)) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
- CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
-
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
- if (pDownIcon)
- AddImageToAppearance("D", pDownIcon);
- }
- else
- {
- RemoveAppearance("D");
- RemoveAppearance("R");
- }
-}
-
-void CPDFSDK_Widget::ResetAppearance_CheckBox()
-{
- CPDF_FormControl* pControl = GetFormControl();
- ASSERT(pControl != NULL);
-
-
-
- CPWL_Color crBackground, crBorder, crText;
-
- int iColorType;
- FX_FLOAT fc[4];
-
- pControl->GetOriginalBackgroundColor(iColorType, fc);
- if (iColorType > 0)
- crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- pControl->GetOriginalBorderColor(iColorType, fc);
- if (iColorType > 0)
- crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
- FX_INT32 nBorderStyle = 0;
- CPWL_Dash dsBorder(3,0,0);
- CPWL_Color crLeftTop,crRightBottom;
-
- switch (GetBorderStyle())
- {
- case BBS_DASH:
- nBorderStyle = PBS_DASH;
- dsBorder = CPWL_Dash(3, 3, 0);
- break;
- case BBS_BEVELED:
- nBorderStyle = PBS_BEVELED;
- fBorderWidth *= 2;
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
- crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
- break;
- case BBS_INSET:
- nBorderStyle = PBS_INSET;
- fBorderWidth *= 2;
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
- break;
- case BBS_UNDERLINE:
- nBorderStyle = PBS_UNDERLINED;
- break;
- default:
- nBorderStyle = PBS_SOLID;
- break;
- }
-
- CPDF_Rect rcWindow = GetRotatedRect();
- CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);
-
- CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
- if (da.HasColor())
- {
- da.GetColor(iColorType, fc);
- crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
- }
-
- FX_INT32 nStyle = 0;
-
- CFX_WideString csWCaption = pControl->GetNormalCaption();
- if (csWCaption.GetLength() > 0)
- {
- switch (csWCaption[0])
- {
- case L'l':
- nStyle = PCS_CIRCLE;
- break;
- case L'8':
- nStyle = PCS_CROSS;
- break;
- case L'u':
- nStyle = PCS_DIAMOND;
- break;
- case L'n':
- nStyle = PCS_SQUARE;
- break;
- case L'H':
- nStyle = PCS_STAR;
- break;
- default: //L'4'
- nStyle = PCS_CHECK;
- break;
- }
- }
- else
- {
- nStyle = PCS_CHECK;
- }
-
- CFX_ByteString csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +
- CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
-
- CFX_ByteString csAP_N_OFF = csAP_N_ON;
-
- switch (nBorderStyle)
- {
- case PBS_BEVELED:
- {
- CPWL_Color crTemp = crLeftTop;
- crLeftTop = crRightBottom;
- crRightBottom = crTemp;
- }
- break;
- case PBS_INSET:
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
- break;
- }
-
- CFX_ByteString csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) +
- CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
-
- CFX_ByteString csAP_D_OFF = csAP_D_ON;
-
- csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
- csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
-
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
-
- CFX_ByteString csAS = GetAppState();
- if (csAS.IsEmpty())
- SetAppState("Off");
-}
-
-void CPDFSDK_Widget::ResetAppearance_RadioButton()
-{
- CPDF_FormControl* pControl = GetFormControl();
- ASSERT(pControl != NULL);
-
-
-
- CPWL_Color crBackground, crBorder, crText;
-
- int iColorType;
- FX_FLOAT fc[4];
-
- pControl->GetOriginalBackgroundColor(iColorType, fc);
- if (iColorType > 0)
- crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- pControl->GetOriginalBorderColor(iColorType, fc);
- if (iColorType > 0)
- crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
- FX_INT32 nBorderStyle = 0;
- CPWL_Dash dsBorder(3,0,0);
- CPWL_Color crLeftTop,crRightBottom;
-
- switch (GetBorderStyle())
- {
- case BBS_DASH:
- nBorderStyle = PBS_DASH;
- dsBorder = CPWL_Dash(3, 3, 0);
- break;
- case BBS_BEVELED:
- nBorderStyle = PBS_BEVELED;
- fBorderWidth *= 2;
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
- crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
- break;
- case BBS_INSET:
- nBorderStyle = PBS_INSET;
- fBorderWidth *= 2;
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
- break;
- case BBS_UNDERLINE:
- nBorderStyle = PBS_UNDERLINED;
- break;
- default:
- nBorderStyle = PBS_SOLID;
- break;
- }
-
- CPDF_Rect rcWindow = GetRotatedRect();
- CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
-
- CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
- if (da.HasColor())
- {
- da.GetColor(iColorType, fc);
- crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
- }
-
- FX_INT32 nStyle = 0;
-
- CFX_WideString csWCaption = pControl->GetNormalCaption();
- if (csWCaption.GetLength() > 0)
- {
- switch (csWCaption[0])
- {
- default: //L'l':
- nStyle = PCS_CIRCLE;
- break;
- case L'8':
- nStyle = PCS_CROSS;
- break;
- case L'u':
- nStyle = PCS_DIAMOND;
- break;
- case L'n':
- nStyle = PCS_SQUARE;
- break;
- case L'H':
- nStyle = PCS_STAR;
- break;
- case L'4':
- nStyle = PCS_CHECK;
- break;
- }
- }
- else
- {
- nStyle = PCS_CIRCLE;
- }
-
- CFX_ByteString csAP_N_ON;
-
- CPDF_Rect rcCenter = CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
-
- if (nStyle == PCS_CIRCLE)
- {
- if (nBorderStyle == PBS_BEVELED)
- {
- crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
- crRightBottom = CPWL_Utils::SubstractColor(crBackground,0.25f);
- }
- else if (nBorderStyle == PBS_INSET)
- {
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5f);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75f);
- }
-
- csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBackground) +
- CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
- }
- else
- {
- csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +
- CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
- }
-
- CFX_ByteString csAP_N_OFF = csAP_N_ON;
-
- switch (nBorderStyle)
- {
- case PBS_BEVELED:
- {
- CPWL_Color crTemp = crLeftTop;
- crLeftTop = crRightBottom;
- crRightBottom = crTemp;
- }
- break;
- case PBS_INSET:
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
- break;
- }
-
- CFX_ByteString csAP_D_ON;
-
- if (nStyle == PCS_CIRCLE)
- {
- CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground,0.25f);
- if (nBorderStyle == PBS_BEVELED)
- {
- crLeftTop = CPWL_Utils::SubstractColor(crBackground,0.25f);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
- crBK = crBackground;
- }
- else if (nBorderStyle == PBS_INSET)
- {
- crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
- }
-
- csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBK)
- + CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
- }
- else
- {
- csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) +
- CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
- }
-
- CFX_ByteString csAP_D_OFF = csAP_D_ON;
-
- csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
- csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
-
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
-
- CFX_ByteString csAS = GetAppState();
- if (csAS.IsEmpty())
- SetAppState("Off");
-}
-
-void CPDFSDK_Widget::ResetAppearance_ComboBox(FX_LPCWSTR sValue)
-{
- CPDF_FormControl* pControl = GetFormControl();
- ASSERT(pControl != NULL);
- CPDF_FormField* pField = pControl->GetField();
- ASSERT(pField != NULL);
-
- CFX_ByteTextBuf sBody, sLines;
-
- CPDF_Rect rcClient = GetClientRect();
- CPDF_Rect rcButton = rcClient;
- rcButton.left = rcButton.right - 13;
- rcButton.Normalize();
-
- if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
- {
- pEdit->EnableRefresh(FALSE);
-
- ASSERT(this->m_pInterForm != NULL);
- CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
- ASSERT(pDoc != NULL);
- CPDFDoc_Environment* pEnv = pDoc->GetEnv();
- CBA_FontMap FontMap(this,pEnv->GetSysHandler());
- FontMap.Initial();
- pEdit->SetFontMap(&FontMap);
-
- CPDF_Rect rcEdit = rcClient;
- rcEdit.right = rcButton.left;
- rcEdit.Normalize();
-
- pEdit->SetPlateRect(rcEdit);
- pEdit->SetAlignmentV(1);
-
- FX_FLOAT fFontSize = this->GetFontSize();
- if (IsFloatZero(fFontSize))
- pEdit->SetAutoFontSize(TRUE);
- else
- pEdit->SetFontSize(fFontSize);
-
- pEdit->Initialize();
-
- if (sValue)
- pEdit->SetText(sValue);
- else
- {
- FX_INT32 nCurSel = pField->GetSelectedIndex(0);
-
- if (nCurSel < 0)
- pEdit->SetText((FX_LPCWSTR)pField->GetValue());
- else
- pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(nCurSel));
- }
-
- CPDF_Rect rcContent = pEdit->GetContentRect();
-
- CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f));
- if (sEdit.GetLength() > 0)
- {
- sBody << "/Tx BMC\n" << "q\n";
- if (rcContent.Width() > rcEdit.Width() ||
- rcContent.Height() > rcEdit.Height())
- {
- sBody << rcEdit.left << " " << rcEdit.bottom << " "
- << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n";
- }
-
- CPWL_Color crText = GetTextPWLColor();
- sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";
- }
-
- IFX_Edit::DelEdit(pEdit);
- }
-
- sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
-
- CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
-}
-
-void CPDFSDK_Widget::ResetAppearance_ListBox()
-{
- CPDF_FormControl* pControl = GetFormControl();
- ASSERT(pControl != NULL);
- CPDF_FormField* pField = pControl->GetField();
- ASSERT(pField != NULL);
-
- CPDF_Rect rcClient = GetClientRect();
-
- CFX_ByteTextBuf sBody, sLines;
-
- if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
- {
- pEdit->EnableRefresh(FALSE);
-
-// ASSERT(this->m_pBaseForm != NULL);
- ASSERT(this->m_pInterForm != NULL);
- CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
- ASSERT(pDoc != NULL);
- CPDFDoc_Environment* pEnv = pDoc->GetEnv();
-
- CBA_FontMap FontMap(this,pEnv->GetSysHandler());
- FontMap.Initial();
- pEdit->SetFontMap(&FontMap);
-
- pEdit->SetPlateRect(CPDF_Rect(rcClient.left,0.0f,rcClient.right,0.0f));
-
- FX_FLOAT fFontSize = GetFontSize();
-
- if (IsFloatZero(fFontSize))
- pEdit->SetFontSize(12.0f);
- else
- pEdit->SetFontSize(fFontSize);
-
- pEdit->Initialize();
-
- CFX_ByteTextBuf sList;
- FX_FLOAT fy = rcClient.top;
-
- FX_INT32 nTop = pField->GetTopVisibleIndex();
- FX_INT32 nCount = pField->CountOptions();
- FX_INT32 nSelCount = pField->CountSelectedItems();
-
- for (FX_INT32 i=nTop; i<nCount; i++)
- {
- FX_BOOL bSelected = FALSE;
- for (FX_INT32 j=0; j<nSelCount; j++)
- {
- if (pField->GetSelectedIndex(j) == i)
- {
- bSelected = TRUE;
- break;
- }
- }
-
- pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(i));
-
- CPDF_Rect rcContent = pEdit->GetContentRect();
- FX_FLOAT fItemHeight = rcContent.Height();
-
- if (bSelected)
- {
- CPDF_Rect rcItem = CPDF_Rect(rcClient.left,fy-fItemHeight,rcClient.right,fy);
- sList << "q\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,0,51.0f/255.0f,113.0f/255.0f),TRUE)
- << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() << " " << rcItem.Height() << " re f\n" << "Q\n";
-
- sList << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY,1),TRUE) <<
- CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";
- }
- else
- {
- CPWL_Color crText = GetTextPWLColor();
- sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) <<
- CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";
- }
-
- fy -= fItemHeight;
- }
-
- if (sList.GetSize() > 0)
- {
- sBody << "/Tx BMC\n" << "q\n" << rcClient.left << " " << rcClient.bottom << " "
- << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
- sBody << sList << "Q\nEMC\n";
- }
-
- IFX_Edit::DelEdit(pEdit);
- }
-
- CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
-}
-
-void CPDFSDK_Widget::ResetAppearance_TextField(FX_LPCWSTR sValue)
-{
- CPDF_FormControl* pControl = GetFormControl();
- ASSERT(pControl != NULL);
- CPDF_FormField* pField = pControl->GetField();
- ASSERT(pField != NULL);
-
- CFX_ByteTextBuf sBody, sLines;
-
- if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
- {
- pEdit->EnableRefresh(FALSE);
-
-// ASSERT(this->m_pBaseForm != NULL);
- ASSERT(this->m_pInterForm != NULL);
- CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
- ASSERT(pDoc != NULL);
- CPDFDoc_Environment* pEnv = pDoc->GetEnv();
-
- CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
- FontMap.Initial();
- pEdit->SetFontMap(&FontMap);
-
- CPDF_Rect rcClient = GetClientRect();
- pEdit->SetPlateRect(rcClient);
- pEdit->SetAlignmentH(pControl->GetControlAlignment());
-
- FX_DWORD dwFieldFlags = pField->GetFieldFlags();
- FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;
-
- if (bMultiLine)
- {
- pEdit->SetMultiLine(TRUE);
- pEdit->SetAutoReturn(TRUE);
- }
- else
- {
- pEdit->SetAlignmentV(1);
- }
-
- FX_WORD subWord = 0;
- if ((dwFieldFlags >> 13) & 1)
- {
- subWord = '*';
- pEdit->SetPasswordChar(subWord);
- }
-
- int nMaxLen = pField->GetMaxLen();
- FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
- FX_FLOAT fFontSize = GetFontSize();
-
- if (nMaxLen > 0)
- {
- if (bCharArray)
- {
- pEdit->SetCharArray(nMaxLen);
-
- if (IsFloatZero(fFontSize))
- {
- fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetPDFFont(0),rcClient,nMaxLen);
- }
- }
- else
- {
- if (sValue)
- nMaxLen = wcslen((const wchar_t*)sValue);
- pEdit->SetLimitChar(nMaxLen);
- }
- }
-
- if (IsFloatZero(fFontSize))
- pEdit->SetAutoFontSize(TRUE);
- else
- pEdit->SetFontSize(fFontSize);
-
- pEdit->Initialize();
-
- if (sValue)
- pEdit->SetText(sValue);
- else
- pEdit->SetText((FX_LPCWSTR)pField->GetValue());
-
- CPDF_Rect rcContent = pEdit->GetContentRect();
-
- CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f),
- NULL,!bCharArray,subWord);
-
- if (sEdit.GetLength() > 0)
- {
- sBody << "/Tx BMC\n" << "q\n";
- if (rcContent.Width() > rcClient.Width() ||
- rcContent.Height() > rcClient.Height())
- {
- sBody << rcClient.left << " " << rcClient.bottom << " "
- << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
- }
- CPWL_Color crText = GetTextPWLColor();
- sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";
- }
-
- if (bCharArray)
- {
- switch (GetBorderStyle())
- {
- case BBS_SOLID:
- {
- CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);
- if (sColor.GetLength() > 0)
- {
- sLines << "q\n" << GetBorderWidth() << " w\n"
- << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE) << " 2 J 0 j\n";
-
- for (FX_INT32 i=1;i<nMaxLen;i++)
- {
- sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
- << rcClient.bottom << " m\n"
- << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
- << rcClient.top << " l S\n";
- }
-
- sLines << "Q\n";
- }
- }
- break;
- case BBS_DASH:
- {
- CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);
- if (sColor.GetLength() > 0)
- {
- CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
-
- sLines << "q\n" << GetBorderWidth() << " w\n"
- << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE)
- << "[" << dsBorder.nDash << " "
- << dsBorder.nGap << "] "
- << dsBorder.nPhase << " d\n";
-
- for (FX_INT32 i=1;i<nMaxLen;i++)
- {
- sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
- << rcClient.bottom << " m\n"
- << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
- << rcClient.top << " l S\n";
- }
-
- sLines << "Q\n";
- }
- }
- break;
- }
- }
-
- IFX_Edit::DelEdit(pEdit);
- }
-
- CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
-}
-
-CPDF_Rect CPDFSDK_Widget::GetClientRect() const
-{
- CPDF_Rect rcWindow = GetRotatedRect();
- FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
- switch (GetBorderStyle())
- {
- case BBS_BEVELED:
- case BBS_INSET:
- fBorderWidth *= 2.0f;
- break;
- }
-
- return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
-}
-
-CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const
-{
- CPDF_Rect rectAnnot = GetRect();
- FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
- FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
-
- CPDF_FormControl* pControl = GetFormControl();
- ASSERT(pControl != NULL);
-
- CPDF_Rect rcPDFWindow;
- switch(abs(pControl->GetRotation() % 360))
- {
- case 0:
- case 180:
- default:
- rcPDFWindow = CPDF_Rect(0, 0, fWidth, fHeight);
- break;
- case 90:
- case 270:
- rcPDFWindow = CPDF_Rect(0, 0, fHeight, fWidth);
- break;
- }
-
- return rcPDFWindow;
-}
-
-CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const
-{
- CPWL_Color crBackground = GetFillPWLColor();
- if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
- return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
- else
- return "";
-}
-
-CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const
-{
- CPDF_Rect rcWindow = GetRotatedRect();
- CPWL_Color crBorder = GetBorderPWLColor();
- CPWL_Color crBackground = GetFillPWLColor();
- CPWL_Color crLeftTop, crRightBottom;
-
- FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
- FX_INT32 nBorderStyle = 0;
- CPWL_Dash dsBorder(3,0,0);
-
- switch (GetBorderStyle())
- {
- case BBS_DASH:
- nBorderStyle = PBS_DASH;
- dsBorder = CPWL_Dash(3, 3, 0);
- break;
- case BBS_BEVELED:
- nBorderStyle = PBS_BEVELED;
- fBorderWidth *= 2;
- crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
- crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
- break;
- case BBS_INSET:
- nBorderStyle = PBS_INSET;
- fBorderWidth *= 2;
- crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
- crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
- break;
- case BBS_UNDERLINE:
- nBorderStyle = PBS_UNDERLINED;
- break;
- default:
- nBorderStyle = PBS_SOLID;
- break;
- }
-
- return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop,
- crRightBottom, nBorderStyle, dsBorder);
-}
-
-CPDF_Matrix CPDFSDK_Widget::GetMatrix() const
-{
- CPDF_Matrix mt;
- CPDF_FormControl* pControl = GetFormControl();
- ASSERT(pControl != NULL);
-
- CPDF_Rect rcAnnot = GetRect();
- FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;
- FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;
-
-
-
- switch (abs(pControl->GetRotation() % 360))
- {
- case 0:
- default:
- mt = CPDF_Matrix(1, 0, 0, 1, 0, 0);
- break;
- case 90:
- mt = CPDF_Matrix(0, 1, -1, 0, fWidth, 0);
- break;
- case 180:
- mt = CPDF_Matrix(-1, 0, 0, -1, fWidth, fHeight);
- break;
- case 270:
- mt = CPDF_Matrix(0, -1, 1, 0, 0, fHeight);
- break;
- }
-
- return mt;
-}
-
-CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const
-{
- CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
-
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
- if (da.HasColor())
- {
- FX_INT32 iColorType;
- FX_FLOAT fc[4];
- da.GetColor(iColorType, fc);
- crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
- }
-
- return crText;
-}
-
-CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const
-{
- CPWL_Color crBorder;
-
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- FX_INT32 iColorType;
- FX_FLOAT fc[4];
- pFormCtrl->GetOriginalBorderColor(iColorType, fc);
- if (iColorType > 0)
- crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- return crBorder;
-}
-
-CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const
-{
- CPWL_Color crFill;
-
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- FX_INT32 iColorType;
- FX_FLOAT fc[4];
- pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
- if (iColorType > 0)
- crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- return crFill;
-}
-
-void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage)
-{
- ASSERT(pImage != NULL);
-
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- CPDF_Document* pDoc = m_pPageView->GetPDFDocument();//pDocument->GetDocument();
- ASSERT(pDoc != NULL);
-
- CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP");
- ASSERT(pAPDict != NULL);
-
- CPDF_Stream* pStream = pAPDict->GetStream(sAPType);
- ASSERT(pStream != NULL);
-
- CPDF_Dictionary* pStreamDict = pStream->GetDict();
- ASSERT(pStreamDict != NULL);
-
- CFX_ByteString sImageAlias = "IMG";
-
- if (CPDF_Dictionary* pImageDict = pImage->GetDict())
- {
- sImageAlias = pImageDict->GetString("Name");
- if (sImageAlias.IsEmpty())
- sImageAlias = "IMG";
- }
-
- CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
- if (!pStreamResList)
- {
- pStreamResList = FX_NEW CPDF_Dictionary();
- pStreamDict->SetAt("Resources", pStreamResList);
- }
-
- if (pStreamResList)
- {
- CPDF_Dictionary* pXObject = FX_NEW CPDF_Dictionary;
- pXObject->SetAtReference(sImageAlias, pDoc, pImage);
- pStreamResList->SetAt("XObject", pXObject);
- }
-}
-
-void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType)
-{
- ASSERT(m_pAnnot != NULL);
- ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-
- if (CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP"))
- {
- pAPDict->RemoveAt(sAPType);
- }
-}
-
-FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView)
-{
- CPDF_Action action = GetAAction(type);
-
- if (action && action.GetType() != CPDF_Action::Unknown)
- {
- CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
- ASSERT(pDocument != NULL);
-
- CPDFDoc_Environment* pEnv = pDocument->GetEnv();
- ASSERT(pEnv != NULL);
-
- CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();/*(CPDFSDK_ActionHandler*)pApp->GetActionHandler();*/
- ASSERT(pActionHandler != NULL);
-
- return pActionHandler->DoAction_Field(action, type, pDocument, GetFormField(), data);
- }
-
- return FALSE;
-}
-
-CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT)
-{
- switch (eAAT)
- {
- case CPDF_AAction::CursorEnter:
- case CPDF_AAction::CursorExit:
- case CPDF_AAction::ButtonDown:
- case CPDF_AAction::ButtonUp:
- case CPDF_AAction::GetFocus:
- case CPDF_AAction::LoseFocus:
- case CPDF_AAction::PageOpen:
- case CPDF_AAction::PageClose:
- case CPDF_AAction::PageVisible:
- case CPDF_AAction::PageInvisible:
- return CPDFSDK_Annot::GetAAction(eAAT);
- case CPDF_AAction::KeyStroke:
- case CPDF_AAction::Format:
- case CPDF_AAction::Validate:
- case CPDF_AAction::Calculate:
- {
- CPDF_FormField* pField = this->GetFormField();
- ASSERT(pField != NULL);
-
- if (CPDF_AAction aa = pField->GetAdditionalAction())
- return aa.GetAction(eAAT);
- else
- return CPDFSDK_Annot::GetAAction(eAAT);
- }
- default:
- return NULL;
- }
-
- return NULL;
-}
-
-
-CFX_WideString CPDFSDK_Widget::GetAlternateName() const
-{
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- return pFormField->GetAlternateName();
-}
-
-FX_INT32 CPDFSDK_Widget::GetAppearanceAge() const
-{
- return m_nAppAge;
-}
-
-FX_INT32 CPDFSDK_Widget::GetValueAge() const
-{
- return m_nValueAge;
-}
-
-
-FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY)
-{
- CPDF_Annot* pAnnot = GetPDFAnnot();
- CFX_FloatRect annotRect;
- pAnnot->GetRect(annotRect);
- if(annotRect.Contains(pageX, pageY))
- {
- if (!IsVisible()) return FALSE;
-
- int nFieldFlags = GetFieldFlags();
- if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
- return FALSE;
-
- return TRUE;
- }
- return FALSE;
-}
-
-CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
- :m_pDocument(pDocument),
- m_pInterForm(NULL),
- m_bCalculate(TRUE),
- m_bBusy(FALSE)
-{
- ASSERT(m_pDocument != NULL);
- m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument(), FALSE);
- ASSERT(m_pInterForm != NULL);
- m_pInterForm->SetFormNotify(this);
-
- for(int i=0; i<6; i++)
- m_bNeedHightlight[i] = FALSE;
- m_iHighlightAlpha = 0;
-}
-
-CPDFSDK_InterForm::~CPDFSDK_InterForm()
-{
- ASSERT(m_pInterForm != NULL);
- delete m_pInterForm;
- m_pInterForm = NULL;
-
- m_Map.RemoveAll();
-}
-
-void CPDFSDK_InterForm::Destroy()
-{
- delete this;
-}
-
-CPDF_InterForm* CPDFSDK_InterForm::GetInterForm()
-{
- return m_pInterForm;
-}
-
-CPDFSDK_Document* CPDFSDK_InterForm::GetDocument()
-{
- return m_pDocument;
-}
-
-FX_BOOL CPDFSDK_InterForm::HighlightWidgets()
-{
- return FALSE;
-}
-
-CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL bNext) const
-{
- ASSERT(pWidget != NULL);
-
- CBA_AnnotIterator* pIterator = new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "");
- ASSERT(pIterator != NULL);
-
- CPDFSDK_Widget* pRet = NULL;
-
- if (bNext)
- pRet = (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);
- else
- pRet = (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
-
- pIterator->Release();
-
- return pRet;
-
-}
-
-CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const
-{
- if(!pControl || !m_pInterForm) return NULL;
-
- CPDFSDK_Widget* pWidget = NULL;
- m_Map.Lookup(pControl, pWidget);
-
- if (pWidget) return pWidget;
-
- CPDF_Dictionary* pControlDict = pControl->GetWidget();
- ASSERT(pControlDict != NULL);
-
- ASSERT(m_pDocument != NULL);
- CPDF_Document* pDocument = m_pDocument->GetDocument();
-
- CPDFSDK_PageView* pPage = NULL;
-
- if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P"))
- {
- int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
- if (nPageIndex >= 0)
- {
- pPage = m_pDocument->GetPageView(nPageIndex);
- }
- }
-
- if (!pPage)
- {
- int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
- if (nPageIndex >= 0)
- {
- pPage = m_pDocument->GetPageView(nPageIndex);
- }
- }
-
- if (pPage)
- return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
-
- return NULL;
-}
-
-void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets)
-{
- ASSERT(m_pInterForm != NULL);
-
- for (int i=0,sz=m_pInterForm->CountFields(sFieldName); i<sz; i++)
- {
- CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);
- ASSERT(pFormField != NULL);
-
- GetWidgets(pFormField, widgets);
- }
-}
-
-void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets)
-{
- ASSERT(pField != NULL);
-
- for (int i=0,isz=pField->CountControls(); i<isz; i++)
- {
- CPDF_FormControl* pFormCtrl = pField->GetControl(i);
- ASSERT(pFormCtrl != NULL);
-
- CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
-
- if (pWidget)
- widgets.Add(pWidget);
- }
-}
-
-int CPDFSDK_InterForm::GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const
-{
- ASSERT(pDocument != NULL);
- ASSERT(pAnnotDict != NULL);
-
- for (int i=0,sz=pDocument->GetPageCount(); i<sz; i++)
- {
- if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i))
- {
- if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots"))
- {
- for (int j=0,jsz=pAnnots->GetCount(); j<jsz; j++)
- {
- CPDF_Object* pDict = pAnnots->GetElementValue(j);
- if (pAnnotDict == pDict)
- {
- return i;
- }
- }
- }
- }
- }
-
- return -1;
-}
-
-void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget)
-{
- m_Map.SetAt(pControl, pWidget);
-}
-
-void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl)
-{
- m_Map.RemoveKey(pControl);
-}
-
-void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled)
-{
- m_bCalculate = bEnabled;
-}
-
-FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const
-{
- return m_bCalculate;
-}
-
-#ifdef _WIN32
-CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile)
-{
- ASSERT(m_pDocument != NULL);
- CPDF_Document* pDocument = m_pDocument->GetDocument();
- ASSERT(pDocument != NULL);
-
- CPDF_Stream* pRetStream = NULL;
-
- if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile))
- {
- int nWidth = pBmp->GetWidth();
- int nHeight = pBmp->GetHeight();
-
- CPDF_Image Image(pDocument);
- Image.SetImage(pBmp, FALSE);
- CPDF_Stream* pImageStream = Image.GetStream();
- if (pImageStream)
- {
- if (pImageStream->GetObjNum() == 0)
- pDocument->AddIndirectObject(pImageStream);
-
- CPDF_Dictionary* pStreamDict = new CPDF_Dictionary();
- pStreamDict->SetAtName("Subtype", "Form");
- pStreamDict->SetAtName("Name", "IMG");
- CPDF_Array* pMatrix = new CPDF_Array();
- pStreamDict->SetAt("Matrix", pMatrix);
- pMatrix->AddInteger(1);
- pMatrix->AddInteger(0);
- pMatrix->AddInteger(0);
- pMatrix->AddInteger(1);
- pMatrix->AddInteger(-nWidth / 2);
- pMatrix->AddInteger(-nHeight / 2);
- CPDF_Dictionary* pResource = new CPDF_Dictionary();
- pStreamDict->SetAt("Resources", pResource);
- CPDF_Dictionary* pXObject = new CPDF_Dictionary();
- pResource->SetAt("XObject", pXObject);
- pXObject->SetAtReference("Img", pDocument, pImageStream);
- CPDF_Array* pProcSet = new CPDF_Array();
- pResource->SetAt("ProcSet", pProcSet);
- pProcSet->AddName("PDF");
- pProcSet->AddName("ImageC");
- pStreamDict->SetAtName("Type", "XObject");
- CPDF_Array* pBBox = new CPDF_Array();
- pStreamDict->SetAt("BBox", pBBox);
- pBBox->AddInteger(0);
- pBBox->AddInteger(0);
- pBBox->AddInteger(nWidth);
- pBBox->AddInteger(nHeight);
- pStreamDict->SetAtInteger("FormType", 1);
-
- pRetStream = new CPDF_Stream(NULL, 0, NULL);
- CFX_ByteString csStream;
- csStream.Format("q\n%d 0 0 %d 0 0 cm\n/Img Do\nQ", nWidth, nHeight);
- pRetStream->InitStream((FX_BYTE*)(FX_LPCSTR)csStream, csStream.GetLength(), pStreamDict);
- pDocument->AddIndirectObject(pRetStream);
- }
-
- delete pBmp;
- }
-
- return pRetStream;
-}
-#endif
-
-void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField)
-{
- ASSERT(m_pDocument != NULL);
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv);
- if(!pEnv->IsJSInitiated())
- return;
-
- if (m_bBusy) return;
-
- m_bBusy = TRUE;
-
- if (this->IsCalculateEnabled())
- {
- IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->SetReaderDocument(m_pDocument);
-
- int nSize = m_pInterForm->CountFieldsInCalculationOrder();
- for (int i=0; i<nSize; i++)
- {
- if(CPDF_FormField* pField = m_pInterForm->GetFieldInCalculationOrder(i))
- {
-// ASSERT(pField != NULL);
- int nType = pField->GetFieldType();
- if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
- {
- CPDF_AAction aAction = pField->GetAdditionalAction();
- if (aAction && aAction.ActionExist(CPDF_AAction::Calculate))
- {
- CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate);
- if (action)
- {
- CFX_WideString csJS = action.GetJavaScript();
- if (!csJS.IsEmpty())
- {
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
-
- CFX_WideString sOldValue = pField->GetValue();
- CFX_WideString sValue = sOldValue;
- FX_BOOL bRC = TRUE;
- pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
-
- CFX_WideString sInfo;
- FX_BOOL bRet = pContext->RunScript(csJS, sInfo);
- pRuntime->ReleaseContext(pContext);
-
- if (bRet)
- {
- if (bRC)
- {
- if (sValue.Compare(sOldValue) != 0)
- pField->SetValue(sValue, TRUE);
- }
- }
- }
- }
- }
- }
- }
- }
-
-
- }
-
- m_bBusy = FALSE;
-}
-
-CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, int nCommitKey, FX_BOOL& bFormated)
-{
- ASSERT(m_pDocument != NULL);
- ASSERT(pFormField != NULL);
-
- CFX_WideString sValue = pFormField->GetValue();
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv);
- if(!pEnv->IsJSInitiated())
- {
- bFormated = FALSE;
- return sValue;
- }
-
- IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->SetReaderDocument(m_pDocument);
-
- if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)
- {
- if (pFormField->CountSelectedItems() > 0)
- {
- int index = pFormField->GetSelectedIndex(0);
- if (index >= 0)
- sValue = pFormField->GetOptionLabel(index);
- }
- }
-
- bFormated = FALSE;
-
- CPDF_AAction aAction = pFormField->GetAdditionalAction();
- if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format))
- {
- CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
- if (action)
- {
- CFX_WideString script = action.GetJavaScript();
- if (!script.IsEmpty())
- {
- CFX_WideString Value = sValue;
-
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
-
- pContext->OnField_Format(nCommitKey, pFormField, Value, TRUE);
-
- CFX_WideString sInfo;
- FX_BOOL bRet = pContext->RunScript(script, sInfo);
- pRuntime->ReleaseContext(pContext);
-
- if (bRet)
- {
- sValue = Value;
- bFormated = TRUE;
- }
- }
- }
- }
-
- return sValue;
-}
-
-void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, FX_LPCWSTR sValue, FX_BOOL bValueChanged)
-{
- ASSERT(pFormField != NULL);
-
- for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
- {
- CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
- ASSERT(pFormCtrl != NULL);
-
- ASSERT(m_pInterForm != NULL);
- if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
- pWidget->ResetAppearance(sValue, bValueChanged);
- }
-}
-
-void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField)
-{
- ASSERT(pFormField != NULL);
-
- for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
- {
- CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
- ASSERT(pFormCtrl != NULL);
-
- if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
- {
- CPDFDoc_Environment * pEnv = m_pDocument->GetEnv();
- CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();
-
- CPDF_Page * pPage = pWidget->GetPDFPage();
- CPDFSDK_PageView * pPageView = m_pDocument->GetPageView(pPage,FALSE);
-
- FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);
-
- pEnv->FFI_Invalidate(pPage,rcBBox.left, rcBBox.top, rcBBox.right, rcBBox.bottom);
- }
- }
-}
-
-void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)
-{
- ASSERT(pFormField != NULL);
-
- CPDF_AAction aAction = pFormField->GetAdditionalAction();
- if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke))
- {
- CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
- if (action)
- {
- ASSERT(m_pDocument != NULL);
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv != NULL);
-
- CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
- ASSERT(pActionHandler != NULL);
-
- PDFSDK_FieldAction fa;
- fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
- fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
- fa.sValue = csValue;
-
- pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
- m_pDocument, pFormField, fa);
- bRC = fa.bRC;
- }
- }
-}
-
-void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)
-{
- ASSERT(pFormField != NULL);
-
- CPDF_AAction aAction = pFormField->GetAdditionalAction();
- if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate))
- {
- CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
- if (action)
- {
- ASSERT(m_pDocument != NULL);
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv != NULL);
-
- CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
- ASSERT(pActionHandler != NULL);
-
- PDFSDK_FieldAction fa;
- fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
- fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
- fa.sValue = csValue;
-
- pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, m_pDocument, pFormField, fa);
- bRC = fa.bRC;
-
- }
- }
-}
-
-/* ----------------------------- action ----------------------------- */
-
-FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action)
-{
- ASSERT(action != NULL);
-
- CPDF_ActionFields af = action.GetWidgets();
- CFX_PtrArray fieldObjects;
- af.GetAllFields(fieldObjects);
- CFX_PtrArray widgetArray;
- CFX_PtrArray fields;
- GetFieldFromObjects(fieldObjects, fields);
-
- FX_BOOL bHide = action.GetHideStatus();
-
- FX_BOOL bChanged = FALSE;
-
- for (int i=0, sz=fields.GetSize(); i<sz; i++)
- {
- CPDF_FormField* pField = (CPDF_FormField*)fields[i];
- ASSERT(pField != NULL);
-
-
- for (int j=0,jsz=pField->CountControls(); j<jsz; j++)
- {
- CPDF_FormControl* pControl = pField->GetControl(j);
- ASSERT(pControl != NULL);
-
- if (CPDFSDK_Widget* pWidget = GetWidget(pControl))
- {
- int nFlags = pWidget->GetFlags();
- if (bHide)
- {
- nFlags &= (~ANNOTFLAG_INVISIBLE);
- nFlags &= (~ANNOTFLAG_NOVIEW);
- nFlags |= (ANNOTFLAG_HIDDEN);
- }
- else
- {
- nFlags &= (~ANNOTFLAG_INVISIBLE);
- nFlags &= (~ANNOTFLAG_HIDDEN);
- nFlags &= (~ANNOTFLAG_NOVIEW);
- }
- pWidget->SetFlags(nFlags);
-
- CPDFSDK_PageView* pPageView = pWidget->GetPageView();
- ASSERT(pPageView != NULL);
-
- pPageView->UpdateView(pWidget);
-
- bChanged = TRUE;
- }
- }
- }
-
- return bChanged;
-}
-
-FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action)
-{
- ASSERT(action != NULL);
- ASSERT(m_pInterForm != NULL);
-
- CFX_WideString sDestination = action.GetFilePath();
- if (sDestination.IsEmpty()) return FALSE;
-
- CPDF_Dictionary* pActionDict = action;
- if (pActionDict->KeyExist("Fields"))
- {
- CPDF_ActionFields af = action.GetWidgets();
- FX_DWORD dwFlags = action.GetFlags();
-
- CFX_PtrArray fieldObjects;
- af.GetAllFields(fieldObjects);
- CFX_PtrArray fields;
- GetFieldFromObjects(fieldObjects, fields);
-
- if (fields.GetSize() != 0)
- {
- FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01);
- if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))
- {
- return FALSE;
- }
- return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE);
- }
- else
- {
- if ( m_pInterForm->CheckRequiredFields())
- {
- return FALSE;
- }
-
- return SubmitForm(sDestination, FALSE);
- }
- }
- else
- {
- if ( m_pInterForm->CheckRequiredFields())
- {
- return FALSE;
- }
-
- return SubmitForm(sDestination, FALSE);
- }
-}
-
-FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields,
- FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncoded)
-{
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv != NULL);
-
- CFX_ByteTextBuf textBuf;
- ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
-
- FX_LPBYTE pBuffer = textBuf.GetBuffer();
- FX_STRSIZE nBufSize = textBuf.GetLength();
-
- if (bUrlEncoded)
- {
- if(!FDFToURLEncodedData(pBuffer, nBufSize))
- return FALSE;
- }
-
- pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)csDestination);
-
- if (bUrlEncoded && pBuffer)
- {
- FX_Free(pBuffer);
- pBuffer = NULL;
- }
-
- return TRUE;
-}
-
-void CPDFSDK_InterForm::DoFDFBuffer(CFX_ByteString sBuffer)
-{
- ASSERT(m_pDocument != NULL);
-
- if (CFDF_Document *pFDFDocument = CFDF_Document::ParseMemory((const unsigned char *)sBuffer.GetBuffer(sBuffer.GetLength()), sBuffer.GetLength()))
- {
- CPDF_Dictionary* pRootDic = pFDFDocument->GetRoot();
- if(pRootDic)
- {
- CPDF_Dictionary * pFDFDict=pRootDic->GetDict("FDF");
- if(pFDFDict)
- {
- CPDF_Dictionary * pJSDict = pFDFDict->GetDict("JavaScript");
- if(pJSDict)
- {
- CFX_WideString csJS;
-
- CPDF_Object* pJS = pJSDict->GetElementValue("Before");
- if (pJS != NULL)
- {
- int iType = pJS->GetType();
- if (iType == PDFOBJ_STRING)
- csJS = pJSDict->GetUnicodeText("Before");
- else if (iType == PDFOBJ_STREAM)
- csJS = pJS->GetUnicodeText();
- }
-
- }
- }
- }
- delete pFDFDocument;
- }
-
- sBuffer.ReleaseBuffer();
-}
-
-FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile)
-{
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(FX_LPBYTE& pBuf, FX_STRSIZE& nBufSize)
-{
- CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
- if (pFDF)
- {
- CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
- if (pMainDict == NULL) return FALSE;
-
- // Get fields
- CPDF_Array* pFields = pMainDict->GetArray("Fields");
- if (pFields == NULL) return FALSE;
-
- CFX_ByteTextBuf fdfEncodedData;
-
- for (FX_DWORD i = 0; i < pFields->GetCount(); i ++)
- {
- CPDF_Dictionary* pField = pFields->GetDict(i);
- if (pField == NULL) continue;
- CFX_WideString name;
- name = pField->GetUnicodeText("T");
- CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
- CFX_ByteString csBValue = pField->GetString("V");
- CFX_WideString csWValue = PDF_DecodeText(csBValue);
- CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
-
- fdfEncodedData = fdfEncodedData<<name_b.GetBuffer(name_b.GetLength());
- name_b.ReleaseBuffer();
- fdfEncodedData = fdfEncodedData<<"=";
- fdfEncodedData = fdfEncodedData<<csValue_b.GetBuffer(csValue_b.GetLength());
- csValue_b.ReleaseBuffer();
- if(i != pFields->GetCount()-1)
- fdfEncodedData = fdfEncodedData<<"&";
- }
-
- nBufSize = fdfEncodedData.GetLength();
- pBuf = FX_Alloc(FX_BYTE, nBufSize);
- if(!pBuf)
- return FALSE;
- FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
-
- }
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFFile(const CFX_WideString& sFDFFileName,
- const CFX_PtrArray& fields, FX_BOOL bIncludeOrExclude)
-{
- if (sFDFFileName.IsEmpty()) return FALSE;
- ASSERT(m_pDocument != NULL);
- ASSERT(m_pInterForm != NULL);
-
- CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);
- if (!pFDF) return FALSE;
- FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode()); // = FALSE;//
- delete pFDF;
-
- return bRet;
-}
-FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf)
-{
- ASSERT(m_pDocument != NULL);
- ASSERT(m_pInterForm != NULL);
-
- CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);
- if (!pFDF) return FALSE;
- FX_BOOL bRet = pFDF->WriteBuf(textBuf); // = FALSE;//
- delete pFDF;
-
- return bRet;
-}
-
-CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(const CFX_WideString& sFileExt)
-{
- CFX_WideString sFileName;
- return L"";
-}
-
-FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded)
-{
- if (sDestination.IsEmpty()) return FALSE;
-
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv != NULL);
-
- if(NULL == m_pDocument) return FALSE;
- CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
-
- if(NULL == m_pInterForm) return FALSE;
- CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);
- if (NULL == pFDFDoc) return FALSE;
-
- CFX_ByteTextBuf FdfBuffer;
- FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
- delete pFDFDoc;
- if (!bRet) return FALSE;
-
- FX_LPBYTE pBuffer = FdfBuffer.GetBuffer();
- FX_STRSIZE nBufSize = FdfBuffer.GetLength();
-
- if (bUrlEncoded)
- {
- if(!FDFToURLEncodedData(pBuffer, nBufSize))
- return FALSE;
- }
-
- pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)sDestination);
-
- if (bUrlEncoded && pBuffer)
- {
- FX_Free(pBuffer);
- pBuffer = NULL;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_InterForm::ExportFormToFDFFile(const CFX_WideString& sFDFFileName)
-{
- if (sFDFFileName.IsEmpty()) return FALSE;
-
- ASSERT(m_pInterForm != NULL);
- ASSERT(m_pDocument != NULL);
-
- CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
- if (!pFDF) return FALSE;
-
- FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode());
- delete pFDF;
-
- return bRet;
-}
-
-FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf)
-{
-
- ASSERT(m_pInterForm != NULL);
- ASSERT(m_pDocument != NULL);
-
- CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
- if (!pFDF) return FALSE;
-
- FX_BOOL bRet = pFDF->WriteBuf(textBuf);
- delete pFDF;
-
- return bRet;
-}
-
-FX_BOOL CPDFSDK_InterForm::ExportFormToTxtFile(const CFX_WideString& sTxtFileName)
-{
- ASSERT(m_pInterForm != NULL);
-
- CFX_WideString sFieldNames;
- CFX_WideString sFieldValues;
-
- int nSize = m_pInterForm->CountFields();
-
- if (nSize > 0)
- {
- for (int i=0; i<nSize; i++)
- {
- CPDF_FormField* pField = m_pInterForm->GetField(i);
- ASSERT(pField != NULL);
-
- if (i != 0)
- {
- sFieldNames += L"\t";
- sFieldValues += L"\t";
- }
- sFieldNames += pField->GetFullName();
- sFieldValues += pField->GetValue();
- }
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_InterForm::ImportFormFromTxtFile(const CFX_WideString& sTxtFileName)
-{
- ASSERT(m_pInterForm != NULL);
-
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action)
-{
- ASSERT(action != NULL);
-
- CPDF_Dictionary* pActionDict = action;
-
- if (pActionDict->KeyExist("Fields"))
- {
- CPDF_ActionFields af = action.GetWidgets();
- FX_DWORD dwFlags = action.GetFlags();
-
- CFX_PtrArray fieldObjects;
- af.GetAllFields(fieldObjects);
- CFX_PtrArray fields;
- GetFieldFromObjects(fieldObjects, fields);
-
- ASSERT(m_pInterForm != NULL);
-
- return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE);
- }
- else
- {
- ASSERT(m_pInterForm != NULL);
- return m_pInterForm->ResetForm(TRUE);
- }
-}
-
-FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action)
-{
- ASSERT(action != NULL);
-
- CFX_WideString sFilePath = action.GetFilePath();
- if (sFilePath.IsEmpty())
- return FALSE;
-
- if (!ImportFormFromFDFFile(sFilePath, TRUE))
- {
- return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPDFSDK_InterForm::ImportFormFromFDFFile(const CFX_WideString& csFDFFileName,
- FX_BOOL bNotify)
-{
- return FALSE;
-}
-
-void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, CFX_PtrArray& fields)
-{
- ASSERT(m_pInterForm != NULL);
-
- int iCount = objects.GetSize();
- for (int i = 0; i < iCount; i ++)
- {
- CPDF_Object* pObject = (CPDF_Object*)objects[i];
- if (pObject == NULL) continue;
-
- int iType = pObject->GetType();
- if (iType == PDFOBJ_STRING)
- {
- CFX_WideString csName = pObject->GetUnicodeText();
- CPDF_FormField* pField = m_pInterForm->GetField(0, csName);
- if (pField != NULL)
- fields.Add(pField);
- }
- else if (iType == PDFOBJ_DICTIONARY)
- {
- if (m_pInterForm->IsValidFormField(pObject))
- fields.Add(pObject);
- }
- }
-}
-
-/* ----------------------------- CPDF_FormNotify ----------------------------- */
-
-int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue)
-{
- ASSERT(pField != NULL);
-
- CPDF_FormField* pFormField = (CPDF_FormField*)pField;
-
- int nType = pFormField->GetFieldType();
- if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
- {
- FX_BOOL bRC = TRUE;
- OnKeyStrokeCommit(pFormField, csValue, bRC);
- if (bRC)
- {
- OnValidate(pFormField, csValue, bRC);
- if (bRC)
- return 1;
- else
- return -1;
- }
- else
- return -1;
- }
- else
- return 0;
-}
-
-int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField)
-{
- ASSERT(pField != NULL);
-
- CPDF_FormField* pFormField = (CPDF_FormField*)pField;
- int nType = pFormField->GetFieldType();
-
- if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
- {
- this->OnCalculate(pFormField);
- FX_BOOL bFormated = FALSE;
- CFX_WideString sValue = this->OnFormat(pFormField, 0, bFormated);
- if (bFormated)
- this->ResetFieldAppearance(pFormField, sValue, TRUE);
- else
- this->ResetFieldAppearance(pFormField, NULL, TRUE);
- this->UpdateField(pFormField);
- }
-
- return 0;
-}
-
-int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, CFX_WideString& csValue)
-{
- ASSERT(pField != NULL);
-
- CPDF_FormField* pFormField = (CPDF_FormField*)pField;
-
- int nType = pFormField->GetFieldType();
- if (nType == FIELDTYPE_LISTBOX)
- {
- FX_BOOL bRC = TRUE;
- OnKeyStrokeCommit(pFormField, csValue, bRC);
- if (bRC)
- {
- OnValidate(pFormField, csValue, bRC);
- if (bRC)
- return 1;
- else
- return -1;
- }
- else
- return -1;
- }
- else
- return 0;
-}
-
-int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField)
-{
- ASSERT(pField != NULL);
-
- CPDF_FormField* pFormField = (CPDF_FormField*)pField;
- int nType = pFormField->GetFieldType();
-
- if (nType == FIELDTYPE_LISTBOX)
- {
- this->OnCalculate(pFormField);
- this->ResetFieldAppearance(pFormField, NULL, TRUE);
- this->UpdateField(pFormField);
- }
-
- return 0;
-}
-
-int CPDFSDK_InterForm::AfterCheckedStatusChange(const CPDF_FormField* pField, const CFX_ByteArray& statusArray)
-{
- ASSERT(pField != NULL);
-
- CPDF_FormField* pFormField = (CPDF_FormField*)pField;
- int nType = pFormField->GetFieldType();
-
- if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON)
- {
- this->OnCalculate(pFormField);
- //this->ResetFieldAppearance(pFormField, NULL);
- this->UpdateField(pFormField);
- }
-
- return 0;
-}
-
-int CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm)
-{
- return 0;
-}
-
-int CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm)
-{
- this->OnCalculate(NULL);
-
- return 0;
-}
-
-int CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm)
-{
- return 0;
-}
-
-int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm)
-{
- this->OnCalculate(NULL);
-
- return 0;
-}
-
-FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType)
-{
- if(nFieldType <1 || nFieldType > 6)
- return FALSE;
- return m_bNeedHightlight[nFieldType-1];
-}
-
-void CPDFSDK_InterForm::RemoveAllHighLight()
-{
- memset((void*)m_bNeedHightlight, 0, 6*sizeof(FX_BOOL));
-}
-void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)
-{
- if(nFieldType <0 || nFieldType > 6) return;
- switch(nFieldType)
- {
- case 0:
- {
- for(int i=0; i<6; i++)
- {
- m_aHighlightColor[i] = clr;
- m_bNeedHightlight[i] = TRUE;
- }
- break;
- }
- default:
- {
- m_aHighlightColor[nFieldType-1] = clr;
- m_bNeedHightlight[nFieldType-1] = TRUE;
- break;
- }
- }
-
-}
-
-FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType)
-{
- if(nFieldType <0 || nFieldType >6) return FXSYS_RGB(255,255,255);
- if(nFieldType == 0)
- return m_aHighlightColor[0];
- else
- return m_aHighlightColor[nFieldType-1];
-}
-
-/* ------------------------- CBA_AnnotIterator ------------------------- */
-
-CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, const CFX_ByteString& sType, const CFX_ByteString& sSubType)
- :m_pPageView(pPageView),
- m_sType(sType),
- m_sSubType(sSubType),
- m_nTabs(BAI_STRUCTURE)
-{
- ASSERT(m_pPageView != NULL);
-
- CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();
- ASSERT(pPDFPage != NULL);
- ASSERT(pPDFPage->m_pFormDict != NULL);
-
- CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs");
-
- if (sTabs == "R")
- {
- m_nTabs = BAI_ROW;
- }
- else if (sTabs == "C")
- {
- m_nTabs = BAI_COLUMN;
- }
- else
- {
- m_nTabs = BAI_STRUCTURE;
- }
-
- GenerateResults();
-}
-
-CBA_AnnotIterator::~CBA_AnnotIterator()
-{
- m_Annots.RemoveAll();
-}
-
-CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot()
-{
- if (m_Annots.GetSize() > 0)
- return m_Annots[0];
-
- return NULL;
-}
-
-CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot()
-{
- if (m_Annots.GetSize() > 0)
- return m_Annots[m_Annots.GetSize() - 1];
-
- return NULL;
-}
-
-CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot)
-{
- for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
- {
- if (m_Annots[i] == pAnnot)
- {
- if (i+1 < sz)
- return m_Annots[i+1];
- else
- return m_Annots[0];
- }
- }
-
- return NULL;
-}
-
-CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot)
-{
- for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
- {
- if (m_Annots[i] == pAnnot)
- {
- if (i-1 >= 0)
- return m_Annots[i-1];
- else
- return m_Annots[sz-1];
- }
- }
-
- return NULL;
-}
-
-int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
-{
- ASSERT(p1 != NULL);
- ASSERT(p2 != NULL);
-
- CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
- CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
-
- if (rcAnnot1.left < rcAnnot2.left)
- return -1;
- if (rcAnnot1.left > rcAnnot2.left)
- return 1;
- return 0;
-}
-
-
-int CBA_AnnotIterator::CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
-{
- ASSERT(p1 != NULL);
- ASSERT(p2 != NULL);
-
- CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
- CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
-
- if (rcAnnot1.top < rcAnnot2.top)
- return -1;
- if (rcAnnot1.top > rcAnnot2.top)
- return 1;
- return 0;
-}
-
-void CBA_AnnotIterator::GenerateResults()
-{
- ASSERT(m_pPageView != NULL);
-
- switch (m_nTabs)
- {
- case BAI_STRUCTURE:
- {
- for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
- {
- CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
- ASSERT(pAnnot != NULL);
-
- if (pAnnot->GetType() == m_sType
- && pAnnot->GetSubType() == m_sSubType)
- m_Annots.Add(pAnnot);
- }
- }
- break;
- case BAI_ROW:
- {
- CPDFSDK_SortAnnots sa;
-
- {
-
- for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
- {
- CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
- ASSERT(pAnnot != NULL);
-
- if (pAnnot->GetType() == m_sType
- && pAnnot->GetSubType() == m_sSubType)
- sa.Add(pAnnot);
- }
- }
-
- if (sa.GetSize() > 0)
- {
- sa.Sort(CBA_AnnotIterator::CompareByLeft);
- }
-
- while (sa.GetSize() > 0)
- {
- int nLeftTopIndex = -1;
-
- {
- FX_FLOAT fTop = 0.0f;
-
- for (int i=sa.GetSize()-1; i>=0; i--)
- {
- CPDFSDK_Annot* pAnnot = sa.GetAt(i);
- ASSERT(pAnnot != NULL);
-
- CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
-
- if (rcAnnot.top > fTop)
- {
- nLeftTopIndex = i;
- fTop = rcAnnot.top;
- }
- }
- }
-
- if (nLeftTopIndex >= 0)
- {
- CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
- ASSERT(pLeftTopAnnot != NULL);
-
- CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
-
- m_Annots.Add(pLeftTopAnnot);
- sa.RemoveAt(nLeftTopIndex);
-
- CFX_ArrayTemplate<int> aSelect;
-
- {
- for (int i=0,sz=sa.GetSize(); i<sz; i++)
- {
- CPDFSDK_Annot* pAnnot = sa.GetAt(i);
- ASSERT(pAnnot != NULL);
-
- CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
-
- FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
-
- if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
- aSelect.Add(i);
- }
- }
-
- {
- for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
- {
- m_Annots.Add(sa[aSelect[i]]);
- }
- }
-
- {
- for (int i=aSelect.GetSize()-1; i>=0; i--)
- {
- sa.RemoveAt(aSelect[i]);
- }
- }
-
- aSelect.RemoveAll();
- }
- }
- sa.RemoveAll();
- }
- break;
- case BAI_COLUMN:
- {
- CPDFSDK_SortAnnots sa;
-
- {
- for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
- {
- CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
- ASSERT(pAnnot != NULL);
-
- if (pAnnot->GetType() == m_sType
- && pAnnot->GetSubType() == m_sSubType)
- sa.Add(pAnnot);
- }
- }
-
- if (sa.GetSize() > 0)
- {
- sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE);
- }
-
- while (sa.GetSize() > 0)
- {
- int nLeftTopIndex = -1;
-
- {
- FX_FLOAT fLeft = -1.0f;
-
- for (int i=sa.GetSize()-1; i>=0; i--)
- {
- CPDFSDK_Annot* pAnnot = sa.GetAt(i);
- ASSERT(pAnnot != NULL);
-
- CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
-
- if (fLeft < 0)
- {
- nLeftTopIndex = 0;
- fLeft = rcAnnot.left;
- }
- else if (rcAnnot.left < fLeft)
- {
- nLeftTopIndex = i;
- fLeft = rcAnnot.left;
- }
- }
- }
-
- if (nLeftTopIndex >= 0)
- {
- CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
- ASSERT(pLeftTopAnnot != NULL);
-
- CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
-
- m_Annots.Add(pLeftTopAnnot);
- sa.RemoveAt(nLeftTopIndex);
-
- CFX_ArrayTemplate<int> aSelect;
-
- {
- for (int i=0,sz=sa.GetSize(); i<sz; i++)
- {
- CPDFSDK_Annot* pAnnot = sa.GetAt(i);
- ASSERT(pAnnot != NULL);
-
- CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
-
- FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
-
- if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
- aSelect.Add(i);
- }
- }
-
- {
- for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
- {
- m_Annots.Add(sa[aSelect[i]]);
- }
- }
-
- {
- for (int i=aSelect.GetSize()-1; i>=0; i--)
- {
- sa.RemoveAt(aSelect[i]);
- }
- }
-
- aSelect.RemoveAll();
- }
- }
- sa.RemoveAll();
- }
- break;
- }
-}
-
-CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot)
-{
- ASSERT(pAnnot != NULL);
-
- CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
- ASSERT(pPDFAnnot != NULL);
-
- CPDF_Rect rcAnnot;
- pPDFAnnot->GetRect(rcAnnot);
-
- return rcAnnot;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fsdk_mgr.h"
+#include "../include/fsdk_baseannot.h"
+#include "../include/fsdk_baseform.h"
+#include "../include/formfiller/FFL_FormFiller.h"
+#include "../include/fsdk_actionhandler.h"
+
+#include "../include/javascript/IJavaScript.h"
+
+//------------------------------------------------------------------------------------
+//* CPDFSDK_Widget
+//------------------------------------------------------------------------------------
+
+#define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01)
+#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
+
+CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) :
+ CPDFSDK_Annot(pAnnot, pPageView),
+ m_pInterForm(pInterForm),
+ m_nAppAge(0),
+ m_nValueAge(0)
+{
+ ASSERT(m_pInterForm != NULL);
+}
+
+CPDFSDK_Widget::~CPDFSDK_Widget()
+{
+
+}
+
+FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP");
+ if (pAP == NULL) return FALSE;
+
+ // Choose the right sub-ap
+ const FX_CHAR* ap_entry = "N";
+ if (mode == CPDF_Annot::Down)
+ ap_entry = "D";
+ else if (mode == CPDF_Annot::Rollover)
+ ap_entry = "R";
+ if (!pAP->KeyExist(ap_entry))
+ ap_entry = "N";
+
+ // Get the AP stream or subdirectory
+ CPDF_Object* psub = pAP->GetElementValue(ap_entry);
+ if (psub == NULL) return FALSE;
+
+ int nFieldType = GetFieldType();
+ switch (nFieldType)
+ {
+ case FIELDTYPE_PUSHBUTTON:
+ case FIELDTYPE_COMBOBOX:
+ case FIELDTYPE_LISTBOX:
+ case FIELDTYPE_TEXTFIELD:
+ case FIELDTYPE_SIGNATURE:
+ return psub->GetType() == PDFOBJ_STREAM;
+ case FIELDTYPE_CHECKBOX:
+ case FIELDTYPE_RADIOBUTTON:
+ if (psub->GetType() == PDFOBJ_DICTIONARY)
+ {
+ CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;
+
+ return pSubDict->GetStream(this->GetAppState()) != NULL;
+ }
+ else
+ return FALSE;
+ break;
+ }
+
+ return TRUE;
+}
+
+int CPDFSDK_Widget::GetFieldType() const
+{
+ CPDF_FormField* pField = GetFormField();
+ ASSERT(pField != NULL);
+
+ return pField->GetFieldType();
+}
+
+int CPDFSDK_Widget::GetFieldFlags() const
+{
+ CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
+ ASSERT(pPDFInterForm != NULL);
+
+ CPDF_FormControl* pFormControl = pPDFInterForm->GetControlByDict(m_pAnnot->m_pAnnotDict);
+ CPDF_FormField* pFormField = pFormControl->GetField();
+ return pFormField->GetFieldFlags();
+}
+
+CFX_ByteString CPDFSDK_Widget::GetSubType() const
+{
+ int nType = GetFieldType();
+
+ if (nType == FIELDTYPE_SIGNATURE)
+ return BFFT_SIGNATURE;
+ return CPDFSDK_Annot::GetSubType();
+}
+
+CPDF_FormField* CPDFSDK_Widget::GetFormField() const
+{
+ ASSERT(m_pInterForm != NULL);
+
+ CPDF_FormControl* pCtrl = GetFormControl();
+ ASSERT(pCtrl != NULL);
+
+ return pCtrl->GetField();
+}
+
+CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const
+{
+ ASSERT(m_pInterForm != NULL);
+
+ CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
+ ASSERT(pPDFInterForm != NULL);
+
+ return pPDFInterForm->GetControlByDict(GetAnnotDict());
+}
+static CPDF_Dictionary* BF_GetField(CPDF_Dictionary* pFieldDict, const FX_CHAR* name)
+{
+ if (pFieldDict == NULL) return NULL;
+ // First check the dictionary itself
+ CPDF_Object* pAttr = pFieldDict->GetElementValue(name);
+ if (pAttr) return pFieldDict;
+
+ // Now we need to search from parents
+ CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent");
+ if (pParent == NULL) return NULL;
+
+ return BF_GetField(pParent, name);
+}
+
+CPDF_FormControl* CPDFSDK_Widget::GetFormControl(CPDF_InterForm* pInterForm, CPDF_Dictionary* pAnnotDict)
+{
+ ASSERT(pInterForm != NULL);
+ ASSERT(pAnnotDict != NULL);
+
+ CPDF_FormControl* pControl = pInterForm->GetControlByDict(pAnnotDict);
+
+ return pControl;
+}
+
+int CPDFSDK_Widget::GetRotate() const
+{
+ CPDF_FormControl* pCtrl = this->GetFormControl();
+ ASSERT(pCtrl != NULL);
+
+ return pCtrl->GetRotation() % 360;
+}
+
+FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const
+{
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ int iColorType = 0;
+ color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType));
+
+ return iColorType != COLORTYPE_TRANSPARENT;
+}
+
+FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const
+{
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ int iColorType = 0;
+ color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType));
+
+ return iColorType != COLORTYPE_TRANSPARENT;
+}
+
+FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const
+{
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
+ if (da.HasColor())
+ {
+ FX_ARGB argb;
+ int iColorType = COLORTYPE_TRANSPARENT;
+ da.GetColor(argb, iColorType);
+ color = FX_ARGBTOCOLORREF(argb);
+
+ return iColorType != COLORTYPE_TRANSPARENT;
+ }
+
+ return FALSE;
+}
+
+FX_FLOAT CPDFSDK_Widget::GetFontSize() const
+{
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
+ CFX_ByteString csFont = "";
+ FX_FLOAT fFontSize = 0.0f;
+ pDa.GetFont(csFont, fFontSize);
+
+ return fFontSize;
+}
+
+int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->GetSelectedIndex(nIndex);
+}
+
+CFX_WideString CPDFSDK_Widget::GetValue() const
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->GetValue();
+}
+
+CFX_WideString CPDFSDK_Widget::GetDefaultValue() const
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->GetDefaultValue();
+}
+
+CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->GetOptionLabel(nIndex);
+}
+
+int CPDFSDK_Widget::CountOptions() const
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->CountOptions();
+}
+
+FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->IsItemSelected(nIndex);
+}
+
+int CPDFSDK_Widget::GetTopVisibleIndex() const
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->GetTopVisibleIndex();
+}
+
+FX_BOOL CPDFSDK_Widget::IsChecked() const
+{
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ return pFormCtrl->IsChecked();
+}
+
+int CPDFSDK_Widget::GetAlignment() const
+{
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ return pFormCtrl->GetControlAlignment();
+}
+
+int CPDFSDK_Widget::GetMaxLen() const
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->GetMaxLen();
+}
+
+void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify)
+{
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ CPDF_FormField* pFormField = pFormCtrl->GetField();
+ ASSERT(pFormField != NULL);
+
+ pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, bNotify);
+}
+
+void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify)
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ pFormField->SetValue(sValue, bNotify);
+}
+
+void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue)
+{
+}
+void CPDFSDK_Widget::SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify)
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ pFormField->SetItemSelection(index, bSelected, bNotify);
+}
+
+void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify)
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ pFormField->ClearSelection(bNotify);
+}
+
+void CPDFSDK_Widget::SetTopVisibleIndex(int index)
+{
+}
+
+void CPDFSDK_Widget::SetAppModified()
+{
+ m_bAppModified = TRUE;
+}
+
+void CPDFSDK_Widget::ClearAppModified()
+{
+ m_bAppModified = FALSE;
+}
+
+FX_BOOL CPDFSDK_Widget::IsAppModified() const
+{
+ return m_bAppModified;
+}
+
+void CPDFSDK_Widget::ResetAppearance(FX_LPCWSTR sValue, FX_BOOL bValueChanged)
+{
+ SetAppModified();
+
+ m_nAppAge++;
+ if (m_nAppAge > 999999)
+ m_nAppAge = 0;
+ if (bValueChanged)
+ m_nValueAge++;
+
+ int nFieldType = GetFieldType();
+
+ switch (nFieldType)
+ {
+ case FIELDTYPE_PUSHBUTTON:
+ ResetAppearance_PushButton();
+ break;
+ case FIELDTYPE_CHECKBOX:
+ ResetAppearance_CheckBox();
+ break;
+ case FIELDTYPE_RADIOBUTTON:
+ ResetAppearance_RadioButton();
+ break;
+ case FIELDTYPE_COMBOBOX:
+ ResetAppearance_ComboBox(sValue);
+ break;
+ case FIELDTYPE_LISTBOX:
+ ResetAppearance_ListBox();
+ break;
+ case FIELDTYPE_TEXTFIELD:
+ ResetAppearance_TextField(sValue);
+ break;
+ }
+
+ ASSERT(m_pAnnot != NULL);
+ m_pAnnot->ClearCachedAP();
+}
+
+CFX_WideString CPDFSDK_Widget::OnFormat(int nCommitKey, FX_BOOL& bFormated)
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ ASSERT(m_pInterForm != NULL);
+
+ return m_pInterForm->OnFormat(pFormField, nCommitKey, bFormated);
+
+}
+
+void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged)
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ ASSERT(m_pInterForm != NULL);
+
+ m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged);
+}
+
+void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
+ CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
+{
+ int nFieldType = GetFieldType();
+
+ if ((nFieldType == FIELDTYPE_CHECKBOX || nFieldType == FIELDTYPE_RADIOBUTTON) &&
+ mode == CPDF_Annot::Normal &&
+ !this->IsWidgetAppearanceValid(CPDF_Annot::Normal))
+ {
+ CFX_PathData pathData;
+
+ CPDF_Rect rcAnnot = this->GetRect();
+
+ pathData.AppendRect(rcAnnot.left, rcAnnot.bottom,
+ rcAnnot.right, rcAnnot.top);
+
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = 0.0f;
+
+ pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, FXFILL_ALTERNATE);
+ }
+ else
+ {
+ CPDFSDK_Annot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
+ }
+}
+
+void CPDFSDK_Widget::UpdateField()
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ ASSERT(m_pInterForm != NULL);
+ m_pInterForm->UpdateField(pFormField);
+}
+
+void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView)
+{
+ ASSERT(m_pInterForm != NULL);
+
+ int nFieldType = GetFieldType();
+ if (m_pInterForm->IsNeedHighLight(nFieldType))
+ {
+
+// if (nFieldType != FIELDTYPE_PUSHBUTTON)
+// {
+ CPDF_Rect rc = GetRect();
+ FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
+ FX_BYTE alpha = m_pInterForm->GetHighlightAlpha();
+
+ CFX_FloatRect rcDevice;
+ ASSERT(m_pInterForm->GetDocument());
+ CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
+ if(!pEnv)
+ return;
+ CFX_AffineMatrix page2device;
+ pPageView->GetCurrentMatrix(page2device);
+ page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), rcDevice.left, rcDevice.bottom);
+// pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.left, rc.bottom, &rcDevice.left, &rcDevice.bottom);
+// pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.right, rc.top, &rcDevice.right, &rcDevice.top);
+ page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), rcDevice.right, rcDevice.top);
+
+ rcDevice.Normalize();
+
+ FX_ARGB argb = ArgbEncode((int)alpha, color);
+ FX_RECT rcDev((int)rcDevice.left,(int)rcDevice.top,(int)rcDevice.right,(int)rcDevice.bottom);
+ pDevice->FillRect(&rcDev, argb);
+ /* }*/
+ }
+}
+
+void CPDFSDK_Widget::ResetAppearance_PushButton()
+{
+ CPDF_FormControl* pControl = GetFormControl();
+ ASSERT(pControl != NULL);
+
+
+
+ CPDF_Rect rcWindow = GetRotatedRect();
+
+ FX_INT32 nLayout = 0;
+
+ switch (pControl->GetTextPosition())
+ {
+ case TEXTPOS_ICON:
+ nLayout = PPBL_ICON;
+ break;
+ case TEXTPOS_BELOW:
+ nLayout = PPBL_ICONTOPLABELBOTTOM;
+ break;
+ case TEXTPOS_ABOVE:
+ nLayout = PPBL_LABELTOPICONBOTTOM;
+ break;
+ case TEXTPOS_RIGHT:
+ nLayout = PPBL_ICONLEFTLABELRIGHT;
+ break;
+ case TEXTPOS_LEFT:
+ nLayout = PPBL_LABELLEFTICONRIGHT;
+ break;
+ case TEXTPOS_OVERLAID:
+ nLayout = PPBL_LABELOVERICON;
+ break;
+ default:
+ nLayout = PPBL_LABEL;
+ break;
+ }
+
+ CPWL_Color crBackground, crBorder;
+
+ int iColorType;
+ FX_FLOAT fc[4];
+
+ pControl->GetOriginalBackgroundColor(iColorType, fc);
+ if (iColorType > 0)
+ crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+
+ pControl->GetOriginalBorderColor(iColorType, fc);
+ if (iColorType > 0)
+ crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+
+ FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
+ FX_INT32 nBorderStyle = 0;
+ CPWL_Dash dsBorder(3,0,0);
+ CPWL_Color crLeftTop,crRightBottom;
+
+ switch (GetBorderStyle())
+ {
+ case BBS_DASH:
+ nBorderStyle = PBS_DASH;
+ dsBorder = CPWL_Dash(3, 3, 0);
+ break;
+ case BBS_BEVELED:
+ nBorderStyle = PBS_BEVELED;
+ fBorderWidth *= 2;
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
+ crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
+ break;
+ case BBS_INSET:
+ nBorderStyle = PBS_INSET;
+ fBorderWidth *= 2;
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
+ break;
+ case BBS_UNDERLINE:
+ nBorderStyle = PBS_UNDERLINED;
+ break;
+ default:
+ nBorderStyle = PBS_SOLID;
+ break;
+ }
+
+ CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);
+
+ CPWL_Color crText(COLORTYPE_GRAY,0);
+
+ FX_FLOAT fFontSize = 12.0f;
+ CFX_ByteString csNameTag;
+
+ CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
+ if (da.HasColor())
+ {
+ da.GetColor(iColorType, fc);
+ crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+ }
+
+ if (da.HasFont())
+ da.GetFont(csNameTag, fFontSize);
+
+ CFX_WideString csWCaption;
+ CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
+
+ if (pControl->HasMKEntry("CA"))
+ {
+ csNormalCaption = pControl->GetNormalCaption();
+ }
+ if (pControl->HasMKEntry("RC"))
+ {
+ csRolloverCaption = pControl->GetRolloverCaption();
+ }
+ if (pControl->HasMKEntry("AC"))
+ {
+ csDownCaption = pControl->GetDownCaption();
+ }
+
+ CPDF_Stream* pNormalIcon = NULL;
+ CPDF_Stream* pRolloverIcon = NULL;
+ CPDF_Stream* pDownIcon = NULL;
+
+ if (pControl->HasMKEntry("I"))
+ {
+ pNormalIcon = pControl->GetNormalIcon();
+ }
+ if (pControl->HasMKEntry("RI"))
+ {
+ pRolloverIcon = pControl->GetRolloverIcon();
+ }
+ if (pControl->HasMKEntry("IX"))
+ {
+ pDownIcon = pControl->GetDownIcon();
+ }
+
+ if (pNormalIcon)
+ {
+ if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict())
+ {
+ if (pImageDict->GetString("Name").IsEmpty())
+ pImageDict->SetAtString("Name", "ImgA");
+ }
+ }
+
+ if (pRolloverIcon)
+ {
+ if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict())
+ {
+ if (pImageDict->GetString("Name").IsEmpty())
+ pImageDict->SetAtString("Name", "ImgB");
+ }
+ }
+
+ if (pDownIcon)
+ {
+ if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict())
+ {
+ if (pImageDict->GetString("Name").IsEmpty())
+ pImageDict->SetAtString("Name", "ImgC");
+ }
+ }
+
+ CPDF_IconFit iconFit = pControl->GetIconFit();
+
+// ASSERT(this->m_pBaseForm != NULL);
+ ASSERT(this->m_pInterForm != NULL);
+ CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
+ ASSERT(pDoc != NULL);
+ CPDFDoc_Environment* pEnv = pDoc->GetEnv();
+
+ CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
+ FontMap.Initial();
+
+ FontMap.SetAPType("N");
+
+ CFX_ByteString csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
+ CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
+ CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
+
+ WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
+ if (pNormalIcon)
+ AddImageToAppearance("N", pNormalIcon);
+
+ CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
+ if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle)
+ {
+ if (csRolloverCaption.IsEmpty() && !pRolloverIcon)
+ {
+ csRolloverCaption = csNormalCaption;
+ pRolloverIcon = pNormalIcon;
+ }
+
+ FontMap.SetAPType("R");
+
+ csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
+ CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
+ CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, nLayout);
+
+ WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
+ if (pRolloverIcon)
+ AddImageToAppearance("R", pRolloverIcon);
+
+ if (csDownCaption.IsEmpty() && !pDownIcon)
+ {
+ csDownCaption = csNormalCaption;
+ pDownIcon = pNormalIcon;
+ }
+
+ switch (nBorderStyle)
+ {
+ case PBS_BEVELED:
+ {
+ CPWL_Color crTemp = crLeftTop;
+ crLeftTop = crRightBottom;
+ crRightBottom = crTemp;
+ }
+ break;
+ case PBS_INSET:
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
+ break;
+ }
+
+ FontMap.SetAPType("D");
+
+ csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, CPWL_Utils::SubstractColor(crBackground,0.25f)) +
+ CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
+ CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
+
+ WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
+ if (pDownIcon)
+ AddImageToAppearance("D", pDownIcon);
+ }
+ else
+ {
+ RemoveAppearance("D");
+ RemoveAppearance("R");
+ }
+}
+
+void CPDFSDK_Widget::ResetAppearance_CheckBox()
+{
+ CPDF_FormControl* pControl = GetFormControl();
+ ASSERT(pControl != NULL);
+
+
+
+ CPWL_Color crBackground, crBorder, crText;
+
+ int iColorType;
+ FX_FLOAT fc[4];
+
+ pControl->GetOriginalBackgroundColor(iColorType, fc);
+ if (iColorType > 0)
+ crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+
+ pControl->GetOriginalBorderColor(iColorType, fc);
+ if (iColorType > 0)
+ crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+
+ FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
+ FX_INT32 nBorderStyle = 0;
+ CPWL_Dash dsBorder(3,0,0);
+ CPWL_Color crLeftTop,crRightBottom;
+
+ switch (GetBorderStyle())
+ {
+ case BBS_DASH:
+ nBorderStyle = PBS_DASH;
+ dsBorder = CPWL_Dash(3, 3, 0);
+ break;
+ case BBS_BEVELED:
+ nBorderStyle = PBS_BEVELED;
+ fBorderWidth *= 2;
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
+ crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
+ break;
+ case BBS_INSET:
+ nBorderStyle = PBS_INSET;
+ fBorderWidth *= 2;
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
+ break;
+ case BBS_UNDERLINE:
+ nBorderStyle = PBS_UNDERLINED;
+ break;
+ default:
+ nBorderStyle = PBS_SOLID;
+ break;
+ }
+
+ CPDF_Rect rcWindow = GetRotatedRect();
+ CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);
+
+ CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
+ if (da.HasColor())
+ {
+ da.GetColor(iColorType, fc);
+ crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+ }
+
+ FX_INT32 nStyle = 0;
+
+ CFX_WideString csWCaption = pControl->GetNormalCaption();
+ if (csWCaption.GetLength() > 0)
+ {
+ switch (csWCaption[0])
+ {
+ case L'l':
+ nStyle = PCS_CIRCLE;
+ break;
+ case L'8':
+ nStyle = PCS_CROSS;
+ break;
+ case L'u':
+ nStyle = PCS_DIAMOND;
+ break;
+ case L'n':
+ nStyle = PCS_SQUARE;
+ break;
+ case L'H':
+ nStyle = PCS_STAR;
+ break;
+ default: //L'4'
+ nStyle = PCS_CHECK;
+ break;
+ }
+ }
+ else
+ {
+ nStyle = PCS_CHECK;
+ }
+
+ CFX_ByteString csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +
+ CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
+
+ CFX_ByteString csAP_N_OFF = csAP_N_ON;
+
+ switch (nBorderStyle)
+ {
+ case PBS_BEVELED:
+ {
+ CPWL_Color crTemp = crLeftTop;
+ crLeftTop = crRightBottom;
+ crRightBottom = crTemp;
+ }
+ break;
+ case PBS_INSET:
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
+ break;
+ }
+
+ CFX_ByteString csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) +
+ CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
+
+ CFX_ByteString csAP_D_OFF = csAP_D_ON;
+
+ csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
+ csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
+
+ WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());
+ WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
+
+ WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());
+ WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
+
+ CFX_ByteString csAS = GetAppState();
+ if (csAS.IsEmpty())
+ SetAppState("Off");
+}
+
+void CPDFSDK_Widget::ResetAppearance_RadioButton()
+{
+ CPDF_FormControl* pControl = GetFormControl();
+ ASSERT(pControl != NULL);
+
+
+
+ CPWL_Color crBackground, crBorder, crText;
+
+ int iColorType;
+ FX_FLOAT fc[4];
+
+ pControl->GetOriginalBackgroundColor(iColorType, fc);
+ if (iColorType > 0)
+ crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+
+ pControl->GetOriginalBorderColor(iColorType, fc);
+ if (iColorType > 0)
+ crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+
+ FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
+ FX_INT32 nBorderStyle = 0;
+ CPWL_Dash dsBorder(3,0,0);
+ CPWL_Color crLeftTop,crRightBottom;
+
+ switch (GetBorderStyle())
+ {
+ case BBS_DASH:
+ nBorderStyle = PBS_DASH;
+ dsBorder = CPWL_Dash(3, 3, 0);
+ break;
+ case BBS_BEVELED:
+ nBorderStyle = PBS_BEVELED;
+ fBorderWidth *= 2;
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
+ crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
+ break;
+ case BBS_INSET:
+ nBorderStyle = PBS_INSET;
+ fBorderWidth *= 2;
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
+ break;
+ case BBS_UNDERLINE:
+ nBorderStyle = PBS_UNDERLINED;
+ break;
+ default:
+ nBorderStyle = PBS_SOLID;
+ break;
+ }
+
+ CPDF_Rect rcWindow = GetRotatedRect();
+ CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
+
+ CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
+ if (da.HasColor())
+ {
+ da.GetColor(iColorType, fc);
+ crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+ }
+
+ FX_INT32 nStyle = 0;
+
+ CFX_WideString csWCaption = pControl->GetNormalCaption();
+ if (csWCaption.GetLength() > 0)
+ {
+ switch (csWCaption[0])
+ {
+ default: //L'l':
+ nStyle = PCS_CIRCLE;
+ break;
+ case L'8':
+ nStyle = PCS_CROSS;
+ break;
+ case L'u':
+ nStyle = PCS_DIAMOND;
+ break;
+ case L'n':
+ nStyle = PCS_SQUARE;
+ break;
+ case L'H':
+ nStyle = PCS_STAR;
+ break;
+ case L'4':
+ nStyle = PCS_CHECK;
+ break;
+ }
+ }
+ else
+ {
+ nStyle = PCS_CIRCLE;
+ }
+
+ CFX_ByteString csAP_N_ON;
+
+ CPDF_Rect rcCenter = CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
+
+ if (nStyle == PCS_CIRCLE)
+ {
+ if (nBorderStyle == PBS_BEVELED)
+ {
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
+ crRightBottom = CPWL_Utils::SubstractColor(crBackground,0.25f);
+ }
+ else if (nBorderStyle == PBS_INSET)
+ {
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5f);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75f);
+ }
+
+ csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBackground) +
+ CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
+ }
+ else
+ {
+ csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +
+ CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
+ }
+
+ CFX_ByteString csAP_N_OFF = csAP_N_ON;
+
+ switch (nBorderStyle)
+ {
+ case PBS_BEVELED:
+ {
+ CPWL_Color crTemp = crLeftTop;
+ crLeftTop = crRightBottom;
+ crRightBottom = crTemp;
+ }
+ break;
+ case PBS_INSET:
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
+ break;
+ }
+
+ CFX_ByteString csAP_D_ON;
+
+ if (nStyle == PCS_CIRCLE)
+ {
+ CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground,0.25f);
+ if (nBorderStyle == PBS_BEVELED)
+ {
+ crLeftTop = CPWL_Utils::SubstractColor(crBackground,0.25f);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
+ crBK = crBackground;
+ }
+ else if (nBorderStyle == PBS_INSET)
+ {
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
+ }
+
+ csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBK)
+ + CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
+ }
+ else
+ {
+ csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) +
+ CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
+ }
+
+ CFX_ByteString csAP_D_OFF = csAP_D_ON;
+
+ csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
+ csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
+
+ WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());
+ WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
+
+ WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());
+ WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
+
+ CFX_ByteString csAS = GetAppState();
+ if (csAS.IsEmpty())
+ SetAppState("Off");
+}
+
+void CPDFSDK_Widget::ResetAppearance_ComboBox(FX_LPCWSTR sValue)
+{
+ CPDF_FormControl* pControl = GetFormControl();
+ ASSERT(pControl != NULL);
+ CPDF_FormField* pField = pControl->GetField();
+ ASSERT(pField != NULL);
+
+ CFX_ByteTextBuf sBody, sLines;
+
+ CPDF_Rect rcClient = GetClientRect();
+ CPDF_Rect rcButton = rcClient;
+ rcButton.left = rcButton.right - 13;
+ rcButton.Normalize();
+
+ if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
+ {
+ pEdit->EnableRefresh(FALSE);
+
+ ASSERT(this->m_pInterForm != NULL);
+ CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
+ ASSERT(pDoc != NULL);
+ CPDFDoc_Environment* pEnv = pDoc->GetEnv();
+ CBA_FontMap FontMap(this,pEnv->GetSysHandler());
+ FontMap.Initial();
+ pEdit->SetFontMap(&FontMap);
+
+ CPDF_Rect rcEdit = rcClient;
+ rcEdit.right = rcButton.left;
+ rcEdit.Normalize();
+
+ pEdit->SetPlateRect(rcEdit);
+ pEdit->SetAlignmentV(1);
+
+ FX_FLOAT fFontSize = this->GetFontSize();
+ if (IsFloatZero(fFontSize))
+ pEdit->SetAutoFontSize(TRUE);
+ else
+ pEdit->SetFontSize(fFontSize);
+
+ pEdit->Initialize();
+
+ if (sValue)
+ pEdit->SetText(sValue);
+ else
+ {
+ FX_INT32 nCurSel = pField->GetSelectedIndex(0);
+
+ if (nCurSel < 0)
+ pEdit->SetText((FX_LPCWSTR)pField->GetValue());
+ else
+ pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(nCurSel));
+ }
+
+ CPDF_Rect rcContent = pEdit->GetContentRect();
+
+ CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f));
+ if (sEdit.GetLength() > 0)
+ {
+ sBody << "/Tx BMC\n" << "q\n";
+ if (rcContent.Width() > rcEdit.Width() ||
+ rcContent.Height() > rcEdit.Height())
+ {
+ sBody << rcEdit.left << " " << rcEdit.bottom << " "
+ << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n";
+ }
+
+ CPWL_Color crText = GetTextPWLColor();
+ sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";
+ }
+
+ IFX_Edit::DelEdit(pEdit);
+ }
+
+ sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
+
+ CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
+
+ WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
+}
+
+void CPDFSDK_Widget::ResetAppearance_ListBox()
+{
+ CPDF_FormControl* pControl = GetFormControl();
+ ASSERT(pControl != NULL);
+ CPDF_FormField* pField = pControl->GetField();
+ ASSERT(pField != NULL);
+
+ CPDF_Rect rcClient = GetClientRect();
+
+ CFX_ByteTextBuf sBody, sLines;
+
+ if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
+ {
+ pEdit->EnableRefresh(FALSE);
+
+// ASSERT(this->m_pBaseForm != NULL);
+ ASSERT(this->m_pInterForm != NULL);
+ CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
+ ASSERT(pDoc != NULL);
+ CPDFDoc_Environment* pEnv = pDoc->GetEnv();
+
+ CBA_FontMap FontMap(this,pEnv->GetSysHandler());
+ FontMap.Initial();
+ pEdit->SetFontMap(&FontMap);
+
+ pEdit->SetPlateRect(CPDF_Rect(rcClient.left,0.0f,rcClient.right,0.0f));
+
+ FX_FLOAT fFontSize = GetFontSize();
+
+ if (IsFloatZero(fFontSize))
+ pEdit->SetFontSize(12.0f);
+ else
+ pEdit->SetFontSize(fFontSize);
+
+ pEdit->Initialize();
+
+ CFX_ByteTextBuf sList;
+ FX_FLOAT fy = rcClient.top;
+
+ FX_INT32 nTop = pField->GetTopVisibleIndex();
+ FX_INT32 nCount = pField->CountOptions();
+ FX_INT32 nSelCount = pField->CountSelectedItems();
+
+ for (FX_INT32 i=nTop; i<nCount; i++)
+ {
+ FX_BOOL bSelected = FALSE;
+ for (FX_INT32 j=0; j<nSelCount; j++)
+ {
+ if (pField->GetSelectedIndex(j) == i)
+ {
+ bSelected = TRUE;
+ break;
+ }
+ }
+
+ pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(i));
+
+ CPDF_Rect rcContent = pEdit->GetContentRect();
+ FX_FLOAT fItemHeight = rcContent.Height();
+
+ if (bSelected)
+ {
+ CPDF_Rect rcItem = CPDF_Rect(rcClient.left,fy-fItemHeight,rcClient.right,fy);
+ sList << "q\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,0,51.0f/255.0f,113.0f/255.0f),TRUE)
+ << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() << " " << rcItem.Height() << " re f\n" << "Q\n";
+
+ sList << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY,1),TRUE) <<
+ CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";
+ }
+ else
+ {
+ CPWL_Color crText = GetTextPWLColor();
+ sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) <<
+ CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";
+ }
+
+ fy -= fItemHeight;
+ }
+
+ if (sList.GetSize() > 0)
+ {
+ sBody << "/Tx BMC\n" << "q\n" << rcClient.left << " " << rcClient.bottom << " "
+ << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
+ sBody << sList << "Q\nEMC\n";
+ }
+
+ IFX_Edit::DelEdit(pEdit);
+ }
+
+ CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
+
+ WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
+}
+
+void CPDFSDK_Widget::ResetAppearance_TextField(FX_LPCWSTR sValue)
+{
+ CPDF_FormControl* pControl = GetFormControl();
+ ASSERT(pControl != NULL);
+ CPDF_FormField* pField = pControl->GetField();
+ ASSERT(pField != NULL);
+
+ CFX_ByteTextBuf sBody, sLines;
+
+ if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
+ {
+ pEdit->EnableRefresh(FALSE);
+
+// ASSERT(this->m_pBaseForm != NULL);
+ ASSERT(this->m_pInterForm != NULL);
+ CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
+ ASSERT(pDoc != NULL);
+ CPDFDoc_Environment* pEnv = pDoc->GetEnv();
+
+ CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
+ FontMap.Initial();
+ pEdit->SetFontMap(&FontMap);
+
+ CPDF_Rect rcClient = GetClientRect();
+ pEdit->SetPlateRect(rcClient);
+ pEdit->SetAlignmentH(pControl->GetControlAlignment());
+
+ FX_DWORD dwFieldFlags = pField->GetFieldFlags();
+ FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;
+
+ if (bMultiLine)
+ {
+ pEdit->SetMultiLine(TRUE);
+ pEdit->SetAutoReturn(TRUE);
+ }
+ else
+ {
+ pEdit->SetAlignmentV(1);
+ }
+
+ FX_WORD subWord = 0;
+ if ((dwFieldFlags >> 13) & 1)
+ {
+ subWord = '*';
+ pEdit->SetPasswordChar(subWord);
+ }
+
+ int nMaxLen = pField->GetMaxLen();
+ FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
+ FX_FLOAT fFontSize = GetFontSize();
+
+ if (nMaxLen > 0)
+ {
+ if (bCharArray)
+ {
+ pEdit->SetCharArray(nMaxLen);
+
+ if (IsFloatZero(fFontSize))
+ {
+ fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetPDFFont(0),rcClient,nMaxLen);
+ }
+ }
+ else
+ {
+ if (sValue)
+ nMaxLen = wcslen((const wchar_t*)sValue);
+ pEdit->SetLimitChar(nMaxLen);
+ }
+ }
+
+ if (IsFloatZero(fFontSize))
+ pEdit->SetAutoFontSize(TRUE);
+ else
+ pEdit->SetFontSize(fFontSize);
+
+ pEdit->Initialize();
+
+ if (sValue)
+ pEdit->SetText(sValue);
+ else
+ pEdit->SetText((FX_LPCWSTR)pField->GetValue());
+
+ CPDF_Rect rcContent = pEdit->GetContentRect();
+
+ CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f),
+ NULL,!bCharArray,subWord);
+
+ if (sEdit.GetLength() > 0)
+ {
+ sBody << "/Tx BMC\n" << "q\n";
+ if (rcContent.Width() > rcClient.Width() ||
+ rcContent.Height() > rcClient.Height())
+ {
+ sBody << rcClient.left << " " << rcClient.bottom << " "
+ << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
+ }
+ CPWL_Color crText = GetTextPWLColor();
+ sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";
+ }
+
+ if (bCharArray)
+ {
+ switch (GetBorderStyle())
+ {
+ case BBS_SOLID:
+ {
+ CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sLines << "q\n" << GetBorderWidth() << " w\n"
+ << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE) << " 2 J 0 j\n";
+
+ for (FX_INT32 i=1;i<nMaxLen;i++)
+ {
+ sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
+ << rcClient.bottom << " m\n"
+ << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
+ << rcClient.top << " l S\n";
+ }
+
+ sLines << "Q\n";
+ }
+ }
+ break;
+ case BBS_DASH:
+ {
+ CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
+
+ sLines << "q\n" << GetBorderWidth() << " w\n"
+ << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE)
+ << "[" << dsBorder.nDash << " "
+ << dsBorder.nGap << "] "
+ << dsBorder.nPhase << " d\n";
+
+ for (FX_INT32 i=1;i<nMaxLen;i++)
+ {
+ sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
+ << rcClient.bottom << " m\n"
+ << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
+ << rcClient.top << " l S\n";
+ }
+
+ sLines << "Q\n";
+ }
+ }
+ break;
+ }
+ }
+
+ IFX_Edit::DelEdit(pEdit);
+ }
+
+ CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
+ WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
+}
+
+CPDF_Rect CPDFSDK_Widget::GetClientRect() const
+{
+ CPDF_Rect rcWindow = GetRotatedRect();
+ FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
+ switch (GetBorderStyle())
+ {
+ case BBS_BEVELED:
+ case BBS_INSET:
+ fBorderWidth *= 2.0f;
+ break;
+ }
+
+ return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
+}
+
+CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const
+{
+ CPDF_Rect rectAnnot = GetRect();
+ FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
+ FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
+
+ CPDF_FormControl* pControl = GetFormControl();
+ ASSERT(pControl != NULL);
+
+ CPDF_Rect rcPDFWindow;
+ switch(abs(pControl->GetRotation() % 360))
+ {
+ case 0:
+ case 180:
+ default:
+ rcPDFWindow = CPDF_Rect(0, 0, fWidth, fHeight);
+ break;
+ case 90:
+ case 270:
+ rcPDFWindow = CPDF_Rect(0, 0, fHeight, fWidth);
+ break;
+ }
+
+ return rcPDFWindow;
+}
+
+CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const
+{
+ CPWL_Color crBackground = GetFillPWLColor();
+ if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
+ return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
+ else
+ return "";
+}
+
+CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const
+{
+ CPDF_Rect rcWindow = GetRotatedRect();
+ CPWL_Color crBorder = GetBorderPWLColor();
+ CPWL_Color crBackground = GetFillPWLColor();
+ CPWL_Color crLeftTop, crRightBottom;
+
+ FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
+ FX_INT32 nBorderStyle = 0;
+ CPWL_Dash dsBorder(3,0,0);
+
+ switch (GetBorderStyle())
+ {
+ case BBS_DASH:
+ nBorderStyle = PBS_DASH;
+ dsBorder = CPWL_Dash(3, 3, 0);
+ break;
+ case BBS_BEVELED:
+ nBorderStyle = PBS_BEVELED;
+ fBorderWidth *= 2;
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
+ crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
+ break;
+ case BBS_INSET:
+ nBorderStyle = PBS_INSET;
+ fBorderWidth *= 2;
+ crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
+ crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
+ break;
+ case BBS_UNDERLINE:
+ nBorderStyle = PBS_UNDERLINED;
+ break;
+ default:
+ nBorderStyle = PBS_SOLID;
+ break;
+ }
+
+ return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop,
+ crRightBottom, nBorderStyle, dsBorder);
+}
+
+CPDF_Matrix CPDFSDK_Widget::GetMatrix() const
+{
+ CPDF_Matrix mt;
+ CPDF_FormControl* pControl = GetFormControl();
+ ASSERT(pControl != NULL);
+
+ CPDF_Rect rcAnnot = GetRect();
+ FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;
+ FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;
+
+
+
+ switch (abs(pControl->GetRotation() % 360))
+ {
+ case 0:
+ default:
+ mt = CPDF_Matrix(1, 0, 0, 1, 0, 0);
+ break;
+ case 90:
+ mt = CPDF_Matrix(0, 1, -1, 0, fWidth, 0);
+ break;
+ case 180:
+ mt = CPDF_Matrix(-1, 0, 0, -1, fWidth, fHeight);
+ break;
+ case 270:
+ mt = CPDF_Matrix(0, -1, 1, 0, 0, fHeight);
+ break;
+ }
+
+ return mt;
+}
+
+CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const
+{
+ CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
+
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
+ if (da.HasColor())
+ {
+ FX_INT32 iColorType;
+ FX_FLOAT fc[4];
+ da.GetColor(iColorType, fc);
+ crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+ }
+
+ return crText;
+}
+
+CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const
+{
+ CPWL_Color crBorder;
+
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ FX_INT32 iColorType;
+ FX_FLOAT fc[4];
+ pFormCtrl->GetOriginalBorderColor(iColorType, fc);
+ if (iColorType > 0)
+ crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+
+ return crBorder;
+}
+
+CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const
+{
+ CPWL_Color crFill;
+
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ FX_INT32 iColorType;
+ FX_FLOAT fc[4];
+ pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
+ if (iColorType > 0)
+ crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
+
+ return crFill;
+}
+
+void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage)
+{
+ ASSERT(pImage != NULL);
+
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ CPDF_Document* pDoc = m_pPageView->GetPDFDocument();//pDocument->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP");
+ ASSERT(pAPDict != NULL);
+
+ CPDF_Stream* pStream = pAPDict->GetStream(sAPType);
+ ASSERT(pStream != NULL);
+
+ CPDF_Dictionary* pStreamDict = pStream->GetDict();
+ ASSERT(pStreamDict != NULL);
+
+ CFX_ByteString sImageAlias = "IMG";
+
+ if (CPDF_Dictionary* pImageDict = pImage->GetDict())
+ {
+ sImageAlias = pImageDict->GetString("Name");
+ if (sImageAlias.IsEmpty())
+ sImageAlias = "IMG";
+ }
+
+ CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
+ if (!pStreamResList)
+ {
+ pStreamResList = FX_NEW CPDF_Dictionary();
+ pStreamDict->SetAt("Resources", pStreamResList);
+ }
+
+ if (pStreamResList)
+ {
+ CPDF_Dictionary* pXObject = FX_NEW CPDF_Dictionary;
+ pXObject->SetAtReference(sImageAlias, pDoc, pImage);
+ pStreamResList->SetAt("XObject", pXObject);
+ }
+}
+
+void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType)
+{
+ ASSERT(m_pAnnot != NULL);
+ ASSERT(m_pAnnot->m_pAnnotDict != NULL);
+
+ if (CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP"))
+ {
+ pAPDict->RemoveAt(sAPType);
+ }
+}
+
+FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView)
+{
+ CPDF_Action action = GetAAction(type);
+
+ if (action && action.GetType() != CPDF_Action::Unknown)
+ {
+ CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
+ ASSERT(pDocument != NULL);
+
+ CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+ ASSERT(pEnv != NULL);
+
+ CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();/*(CPDFSDK_ActionHandler*)pApp->GetActionHandler();*/
+ ASSERT(pActionHandler != NULL);
+
+ return pActionHandler->DoAction_Field(action, type, pDocument, GetFormField(), data);
+ }
+
+ return FALSE;
+}
+
+CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT)
+{
+ switch (eAAT)
+ {
+ case CPDF_AAction::CursorEnter:
+ case CPDF_AAction::CursorExit:
+ case CPDF_AAction::ButtonDown:
+ case CPDF_AAction::ButtonUp:
+ case CPDF_AAction::GetFocus:
+ case CPDF_AAction::LoseFocus:
+ case CPDF_AAction::PageOpen:
+ case CPDF_AAction::PageClose:
+ case CPDF_AAction::PageVisible:
+ case CPDF_AAction::PageInvisible:
+ return CPDFSDK_Annot::GetAAction(eAAT);
+ case CPDF_AAction::KeyStroke:
+ case CPDF_AAction::Format:
+ case CPDF_AAction::Validate:
+ case CPDF_AAction::Calculate:
+ {
+ CPDF_FormField* pField = this->GetFormField();
+ ASSERT(pField != NULL);
+
+ if (CPDF_AAction aa = pField->GetAdditionalAction())
+ return aa.GetAction(eAAT);
+ else
+ return CPDFSDK_Annot::GetAAction(eAAT);
+ }
+ default:
+ return NULL;
+ }
+
+ return NULL;
+}
+
+
+CFX_WideString CPDFSDK_Widget::GetAlternateName() const
+{
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->GetAlternateName();
+}
+
+FX_INT32 CPDFSDK_Widget::GetAppearanceAge() const
+{
+ return m_nAppAge;
+}
+
+FX_INT32 CPDFSDK_Widget::GetValueAge() const
+{
+ return m_nValueAge;
+}
+
+
+FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY)
+{
+ CPDF_Annot* pAnnot = GetPDFAnnot();
+ CFX_FloatRect annotRect;
+ pAnnot->GetRect(annotRect);
+ if(annotRect.Contains(pageX, pageY))
+ {
+ if (!IsVisible()) return FALSE;
+
+ int nFieldFlags = GetFieldFlags();
+ if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
+ return FALSE;
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
+CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
+ :m_pDocument(pDocument),
+ m_pInterForm(NULL),
+ m_bCalculate(TRUE),
+ m_bBusy(FALSE)
+{
+ ASSERT(m_pDocument != NULL);
+ m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument(), FALSE);
+ ASSERT(m_pInterForm != NULL);
+ m_pInterForm->SetFormNotify(this);
+
+ for(int i=0; i<6; i++)
+ m_bNeedHightlight[i] = FALSE;
+ m_iHighlightAlpha = 0;
+}
+
+CPDFSDK_InterForm::~CPDFSDK_InterForm()
+{
+ ASSERT(m_pInterForm != NULL);
+ delete m_pInterForm;
+ m_pInterForm = NULL;
+
+ m_Map.RemoveAll();
+}
+
+void CPDFSDK_InterForm::Destroy()
+{
+ delete this;
+}
+
+CPDF_InterForm* CPDFSDK_InterForm::GetInterForm()
+{
+ return m_pInterForm;
+}
+
+CPDFSDK_Document* CPDFSDK_InterForm::GetDocument()
+{
+ return m_pDocument;
+}
+
+FX_BOOL CPDFSDK_InterForm::HighlightWidgets()
+{
+ return FALSE;
+}
+
+CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL bNext) const
+{
+ ASSERT(pWidget != NULL);
+
+ CBA_AnnotIterator* pIterator = new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "");
+ ASSERT(pIterator != NULL);
+
+ CPDFSDK_Widget* pRet = NULL;
+
+ if (bNext)
+ pRet = (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);
+ else
+ pRet = (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
+
+ pIterator->Release();
+
+ return pRet;
+
+}
+
+CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const
+{
+ if(!pControl || !m_pInterForm) return NULL;
+
+ CPDFSDK_Widget* pWidget = NULL;
+ m_Map.Lookup(pControl, pWidget);
+
+ if (pWidget) return pWidget;
+
+ CPDF_Dictionary* pControlDict = pControl->GetWidget();
+ ASSERT(pControlDict != NULL);
+
+ ASSERT(m_pDocument != NULL);
+ CPDF_Document* pDocument = m_pDocument->GetDocument();
+
+ CPDFSDK_PageView* pPage = NULL;
+
+ if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P"))
+ {
+ int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
+ if (nPageIndex >= 0)
+ {
+ pPage = m_pDocument->GetPageView(nPageIndex);
+ }
+ }
+
+ if (!pPage)
+ {
+ int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
+ if (nPageIndex >= 0)
+ {
+ pPage = m_pDocument->GetPageView(nPageIndex);
+ }
+ }
+
+ if (pPage)
+ return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
+
+ return NULL;
+}
+
+void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets)
+{
+ ASSERT(m_pInterForm != NULL);
+
+ for (int i=0,sz=m_pInterForm->CountFields(sFieldName); i<sz; i++)
+ {
+ CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);
+ ASSERT(pFormField != NULL);
+
+ GetWidgets(pFormField, widgets);
+ }
+}
+
+void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets)
+{
+ ASSERT(pField != NULL);
+
+ for (int i=0,isz=pField->CountControls(); i<isz; i++)
+ {
+ CPDF_FormControl* pFormCtrl = pField->GetControl(i);
+ ASSERT(pFormCtrl != NULL);
+
+ CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
+
+ if (pWidget)
+ widgets.Add(pWidget);
+ }
+}
+
+int CPDFSDK_InterForm::GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(pAnnotDict != NULL);
+
+ for (int i=0,sz=pDocument->GetPageCount(); i<sz; i++)
+ {
+ if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i))
+ {
+ if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots"))
+ {
+ for (int j=0,jsz=pAnnots->GetCount(); j<jsz; j++)
+ {
+ CPDF_Object* pDict = pAnnots->GetElementValue(j);
+ if (pAnnotDict == pDict)
+ {
+ return i;
+ }
+ }
+ }
+ }
+ }
+
+ return -1;
+}
+
+void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget)
+{
+ m_Map.SetAt(pControl, pWidget);
+}
+
+void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl)
+{
+ m_Map.RemoveKey(pControl);
+}
+
+void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled)
+{
+ m_bCalculate = bEnabled;
+}
+
+FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const
+{
+ return m_bCalculate;
+}
+
+#ifdef _WIN32
+CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile)
+{
+ ASSERT(m_pDocument != NULL);
+ CPDF_Document* pDocument = m_pDocument->GetDocument();
+ ASSERT(pDocument != NULL);
+
+ CPDF_Stream* pRetStream = NULL;
+
+ if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile))
+ {
+ int nWidth = pBmp->GetWidth();
+ int nHeight = pBmp->GetHeight();
+
+ CPDF_Image Image(pDocument);
+ Image.SetImage(pBmp, FALSE);
+ CPDF_Stream* pImageStream = Image.GetStream();
+ if (pImageStream)
+ {
+ if (pImageStream->GetObjNum() == 0)
+ pDocument->AddIndirectObject(pImageStream);
+
+ CPDF_Dictionary* pStreamDict = new CPDF_Dictionary();
+ pStreamDict->SetAtName("Subtype", "Form");
+ pStreamDict->SetAtName("Name", "IMG");
+ CPDF_Array* pMatrix = new CPDF_Array();
+ pStreamDict->SetAt("Matrix", pMatrix);
+ pMatrix->AddInteger(1);
+ pMatrix->AddInteger(0);
+ pMatrix->AddInteger(0);
+ pMatrix->AddInteger(1);
+ pMatrix->AddInteger(-nWidth / 2);
+ pMatrix->AddInteger(-nHeight / 2);
+ CPDF_Dictionary* pResource = new CPDF_Dictionary();
+ pStreamDict->SetAt("Resources", pResource);
+ CPDF_Dictionary* pXObject = new CPDF_Dictionary();
+ pResource->SetAt("XObject", pXObject);
+ pXObject->SetAtReference("Img", pDocument, pImageStream);
+ CPDF_Array* pProcSet = new CPDF_Array();
+ pResource->SetAt("ProcSet", pProcSet);
+ pProcSet->AddName("PDF");
+ pProcSet->AddName("ImageC");
+ pStreamDict->SetAtName("Type", "XObject");
+ CPDF_Array* pBBox = new CPDF_Array();
+ pStreamDict->SetAt("BBox", pBBox);
+ pBBox->AddInteger(0);
+ pBBox->AddInteger(0);
+ pBBox->AddInteger(nWidth);
+ pBBox->AddInteger(nHeight);
+ pStreamDict->SetAtInteger("FormType", 1);
+
+ pRetStream = new CPDF_Stream(NULL, 0, NULL);
+ CFX_ByteString csStream;
+ csStream.Format("q\n%d 0 0 %d 0 0 cm\n/Img Do\nQ", nWidth, nHeight);
+ pRetStream->InitStream((FX_BYTE*)(FX_LPCSTR)csStream, csStream.GetLength(), pStreamDict);
+ pDocument->AddIndirectObject(pRetStream);
+ }
+
+ delete pBmp;
+ }
+
+ return pRetStream;
+}
+#endif
+
+void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField)
+{
+ ASSERT(m_pDocument != NULL);
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv);
+ if(!pEnv->IsJSInitiated())
+ return;
+
+ if (m_bBusy) return;
+
+ m_bBusy = TRUE;
+
+ if (this->IsCalculateEnabled())
+ {
+ IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->SetReaderDocument(m_pDocument);
+
+ int nSize = m_pInterForm->CountFieldsInCalculationOrder();
+ for (int i=0; i<nSize; i++)
+ {
+ if(CPDF_FormField* pField = m_pInterForm->GetFieldInCalculationOrder(i))
+ {
+// ASSERT(pField != NULL);
+ int nType = pField->GetFieldType();
+ if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
+ {
+ CPDF_AAction aAction = pField->GetAdditionalAction();
+ if (aAction && aAction.ActionExist(CPDF_AAction::Calculate))
+ {
+ CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate);
+ if (action)
+ {
+ CFX_WideString csJS = action.GetJavaScript();
+ if (!csJS.IsEmpty())
+ {
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+
+ CFX_WideString sOldValue = pField->GetValue();
+ CFX_WideString sValue = sOldValue;
+ FX_BOOL bRC = TRUE;
+ pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
+
+ CFX_WideString sInfo;
+ FX_BOOL bRet = pContext->RunScript(csJS, sInfo);
+ pRuntime->ReleaseContext(pContext);
+
+ if (bRet)
+ {
+ if (bRC)
+ {
+ if (sValue.Compare(sOldValue) != 0)
+ pField->SetValue(sValue, TRUE);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ }
+
+ m_bBusy = FALSE;
+}
+
+CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, int nCommitKey, FX_BOOL& bFormated)
+{
+ ASSERT(m_pDocument != NULL);
+ ASSERT(pFormField != NULL);
+
+ CFX_WideString sValue = pFormField->GetValue();
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv);
+ if(!pEnv->IsJSInitiated())
+ {
+ bFormated = FALSE;
+ return sValue;
+ }
+
+ IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->SetReaderDocument(m_pDocument);
+
+ if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)
+ {
+ if (pFormField->CountSelectedItems() > 0)
+ {
+ int index = pFormField->GetSelectedIndex(0);
+ if (index >= 0)
+ sValue = pFormField->GetOptionLabel(index);
+ }
+ }
+
+ bFormated = FALSE;
+
+ CPDF_AAction aAction = pFormField->GetAdditionalAction();
+ if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format))
+ {
+ CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
+ if (action)
+ {
+ CFX_WideString script = action.GetJavaScript();
+ if (!script.IsEmpty())
+ {
+ CFX_WideString Value = sValue;
+
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+
+ pContext->OnField_Format(nCommitKey, pFormField, Value, TRUE);
+
+ CFX_WideString sInfo;
+ FX_BOOL bRet = pContext->RunScript(script, sInfo);
+ pRuntime->ReleaseContext(pContext);
+
+ if (bRet)
+ {
+ sValue = Value;
+ bFormated = TRUE;
+ }
+ }
+ }
+ }
+
+ return sValue;
+}
+
+void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, FX_LPCWSTR sValue, FX_BOOL bValueChanged)
+{
+ ASSERT(pFormField != NULL);
+
+ for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
+ {
+ CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
+ ASSERT(pFormCtrl != NULL);
+
+ ASSERT(m_pInterForm != NULL);
+ if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
+ pWidget->ResetAppearance(sValue, bValueChanged);
+ }
+}
+
+void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField)
+{
+ ASSERT(pFormField != NULL);
+
+ for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
+ {
+ CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
+ ASSERT(pFormCtrl != NULL);
+
+ if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
+ {
+ CPDFDoc_Environment * pEnv = m_pDocument->GetEnv();
+ CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();
+
+ CPDF_Page * pPage = pWidget->GetPDFPage();
+ CPDFSDK_PageView * pPageView = m_pDocument->GetPageView(pPage,FALSE);
+
+ FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);
+
+ pEnv->FFI_Invalidate(pPage,rcBBox.left, rcBBox.top, rcBBox.right, rcBBox.bottom);
+ }
+ }
+}
+
+void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)
+{
+ ASSERT(pFormField != NULL);
+
+ CPDF_AAction aAction = pFormField->GetAdditionalAction();
+ if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke))
+ {
+ CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
+ if (action)
+ {
+ ASSERT(m_pDocument != NULL);
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv != NULL);
+
+ CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
+ ASSERT(pActionHandler != NULL);
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
+ fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
+ fa.sValue = csValue;
+
+ pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
+ m_pDocument, pFormField, fa);
+ bRC = fa.bRC;
+ }
+ }
+}
+
+void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)
+{
+ ASSERT(pFormField != NULL);
+
+ CPDF_AAction aAction = pFormField->GetAdditionalAction();
+ if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate))
+ {
+ CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
+ if (action)
+ {
+ ASSERT(m_pDocument != NULL);
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv != NULL);
+
+ CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
+ ASSERT(pActionHandler != NULL);
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
+ fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
+ fa.sValue = csValue;
+
+ pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, m_pDocument, pFormField, fa);
+ bRC = fa.bRC;
+
+ }
+ }
+}
+
+/* ----------------------------- action ----------------------------- */
+
+FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action)
+{
+ ASSERT(action != NULL);
+
+ CPDF_ActionFields af = action.GetWidgets();
+ CFX_PtrArray fieldObjects;
+ af.GetAllFields(fieldObjects);
+ CFX_PtrArray widgetArray;
+ CFX_PtrArray fields;
+ GetFieldFromObjects(fieldObjects, fields);
+
+ FX_BOOL bHide = action.GetHideStatus();
+
+ FX_BOOL bChanged = FALSE;
+
+ for (int i=0, sz=fields.GetSize(); i<sz; i++)
+ {
+ CPDF_FormField* pField = (CPDF_FormField*)fields[i];
+ ASSERT(pField != NULL);
+
+
+ for (int j=0,jsz=pField->CountControls(); j<jsz; j++)
+ {
+ CPDF_FormControl* pControl = pField->GetControl(j);
+ ASSERT(pControl != NULL);
+
+ if (CPDFSDK_Widget* pWidget = GetWidget(pControl))
+ {
+ int nFlags = pWidget->GetFlags();
+ if (bHide)
+ {
+ nFlags &= (~ANNOTFLAG_INVISIBLE);
+ nFlags &= (~ANNOTFLAG_NOVIEW);
+ nFlags |= (ANNOTFLAG_HIDDEN);
+ }
+ else
+ {
+ nFlags &= (~ANNOTFLAG_INVISIBLE);
+ nFlags &= (~ANNOTFLAG_HIDDEN);
+ nFlags &= (~ANNOTFLAG_NOVIEW);
+ }
+ pWidget->SetFlags(nFlags);
+
+ CPDFSDK_PageView* pPageView = pWidget->GetPageView();
+ ASSERT(pPageView != NULL);
+
+ pPageView->UpdateView(pWidget);
+
+ bChanged = TRUE;
+ }
+ }
+ }
+
+ return bChanged;
+}
+
+FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action)
+{
+ ASSERT(action != NULL);
+ ASSERT(m_pInterForm != NULL);
+
+ CFX_WideString sDestination = action.GetFilePath();
+ if (sDestination.IsEmpty()) return FALSE;
+
+ CPDF_Dictionary* pActionDict = action;
+ if (pActionDict->KeyExist("Fields"))
+ {
+ CPDF_ActionFields af = action.GetWidgets();
+ FX_DWORD dwFlags = action.GetFlags();
+
+ CFX_PtrArray fieldObjects;
+ af.GetAllFields(fieldObjects);
+ CFX_PtrArray fields;
+ GetFieldFromObjects(fieldObjects, fields);
+
+ if (fields.GetSize() != 0)
+ {
+ FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01);
+ if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))
+ {
+ return FALSE;
+ }
+ return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE);
+ }
+ else
+ {
+ if ( m_pInterForm->CheckRequiredFields())
+ {
+ return FALSE;
+ }
+
+ return SubmitForm(sDestination, FALSE);
+ }
+ }
+ else
+ {
+ if ( m_pInterForm->CheckRequiredFields())
+ {
+ return FALSE;
+ }
+
+ return SubmitForm(sDestination, FALSE);
+ }
+}
+
+FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields,
+ FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncoded)
+{
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv != NULL);
+
+ CFX_ByteTextBuf textBuf;
+ ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
+
+ FX_LPBYTE pBuffer = textBuf.GetBuffer();
+ FX_STRSIZE nBufSize = textBuf.GetLength();
+
+ if (bUrlEncoded)
+ {
+ if(!FDFToURLEncodedData(pBuffer, nBufSize))
+ return FALSE;
+ }
+
+ pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)csDestination);
+
+ if (bUrlEncoded && pBuffer)
+ {
+ FX_Free(pBuffer);
+ pBuffer = NULL;
+ }
+
+ return TRUE;
+}
+
+void CPDFSDK_InterForm::DoFDFBuffer(CFX_ByteString sBuffer)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (CFDF_Document *pFDFDocument = CFDF_Document::ParseMemory((const unsigned char *)sBuffer.GetBuffer(sBuffer.GetLength()), sBuffer.GetLength()))
+ {
+ CPDF_Dictionary* pRootDic = pFDFDocument->GetRoot();
+ if(pRootDic)
+ {
+ CPDF_Dictionary * pFDFDict=pRootDic->GetDict("FDF");
+ if(pFDFDict)
+ {
+ CPDF_Dictionary * pJSDict = pFDFDict->GetDict("JavaScript");
+ if(pJSDict)
+ {
+ CFX_WideString csJS;
+
+ CPDF_Object* pJS = pJSDict->GetElementValue("Before");
+ if (pJS != NULL)
+ {
+ int iType = pJS->GetType();
+ if (iType == PDFOBJ_STRING)
+ csJS = pJSDict->GetUnicodeText("Before");
+ else if (iType == PDFOBJ_STREAM)
+ csJS = pJS->GetUnicodeText();
+ }
+
+ }
+ }
+ }
+ delete pFDFDocument;
+ }
+
+ sBuffer.ReleaseBuffer();
+}
+
+FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile)
+{
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(FX_LPBYTE& pBuf, FX_STRSIZE& nBufSize)
+{
+ CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
+ if (pFDF)
+ {
+ CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
+ if (pMainDict == NULL) return FALSE;
+
+ // Get fields
+ CPDF_Array* pFields = pMainDict->GetArray("Fields");
+ if (pFields == NULL) return FALSE;
+
+ CFX_ByteTextBuf fdfEncodedData;
+
+ for (FX_DWORD i = 0; i < pFields->GetCount(); i ++)
+ {
+ CPDF_Dictionary* pField = pFields->GetDict(i);
+ if (pField == NULL) continue;
+ CFX_WideString name;
+ name = pField->GetUnicodeText("T");
+ CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
+ CFX_ByteString csBValue = pField->GetString("V");
+ CFX_WideString csWValue = PDF_DecodeText(csBValue);
+ CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
+
+ fdfEncodedData = fdfEncodedData<<name_b.GetBuffer(name_b.GetLength());
+ name_b.ReleaseBuffer();
+ fdfEncodedData = fdfEncodedData<<"=";
+ fdfEncodedData = fdfEncodedData<<csValue_b.GetBuffer(csValue_b.GetLength());
+ csValue_b.ReleaseBuffer();
+ if(i != pFields->GetCount()-1)
+ fdfEncodedData = fdfEncodedData<<"&";
+ }
+
+ nBufSize = fdfEncodedData.GetLength();
+ pBuf = FX_Alloc(FX_BYTE, nBufSize);
+ if(!pBuf)
+ return FALSE;
+ FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
+
+ }
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFFile(const CFX_WideString& sFDFFileName,
+ const CFX_PtrArray& fields, FX_BOOL bIncludeOrExclude)
+{
+ if (sFDFFileName.IsEmpty()) return FALSE;
+ ASSERT(m_pDocument != NULL);
+ ASSERT(m_pInterForm != NULL);
+
+ CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);
+ if (!pFDF) return FALSE;
+ FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode()); // = FALSE;//
+ delete pFDF;
+
+ return bRet;
+}
+FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf)
+{
+ ASSERT(m_pDocument != NULL);
+ ASSERT(m_pInterForm != NULL);
+
+ CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);
+ if (!pFDF) return FALSE;
+ FX_BOOL bRet = pFDF->WriteBuf(textBuf); // = FALSE;//
+ delete pFDF;
+
+ return bRet;
+}
+
+CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(const CFX_WideString& sFileExt)
+{
+ CFX_WideString sFileName;
+ return L"";
+}
+
+FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded)
+{
+ if (sDestination.IsEmpty()) return FALSE;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv != NULL);
+
+ if(NULL == m_pDocument) return FALSE;
+ CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
+
+ if(NULL == m_pInterForm) return FALSE;
+ CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);
+ if (NULL == pFDFDoc) return FALSE;
+
+ CFX_ByteTextBuf FdfBuffer;
+ FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
+ delete pFDFDoc;
+ if (!bRet) return FALSE;
+
+ FX_LPBYTE pBuffer = FdfBuffer.GetBuffer();
+ FX_STRSIZE nBufSize = FdfBuffer.GetLength();
+
+ if (bUrlEncoded)
+ {
+ if(!FDFToURLEncodedData(pBuffer, nBufSize))
+ return FALSE;
+ }
+
+ pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)sDestination);
+
+ if (bUrlEncoded && pBuffer)
+ {
+ FX_Free(pBuffer);
+ pBuffer = NULL;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_InterForm::ExportFormToFDFFile(const CFX_WideString& sFDFFileName)
+{
+ if (sFDFFileName.IsEmpty()) return FALSE;
+
+ ASSERT(m_pInterForm != NULL);
+ ASSERT(m_pDocument != NULL);
+
+ CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
+ if (!pFDF) return FALSE;
+
+ FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode());
+ delete pFDF;
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf)
+{
+
+ ASSERT(m_pInterForm != NULL);
+ ASSERT(m_pDocument != NULL);
+
+ CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
+ if (!pFDF) return FALSE;
+
+ FX_BOOL bRet = pFDF->WriteBuf(textBuf);
+ delete pFDF;
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_InterForm::ExportFormToTxtFile(const CFX_WideString& sTxtFileName)
+{
+ ASSERT(m_pInterForm != NULL);
+
+ CFX_WideString sFieldNames;
+ CFX_WideString sFieldValues;
+
+ int nSize = m_pInterForm->CountFields();
+
+ if (nSize > 0)
+ {
+ for (int i=0; i<nSize; i++)
+ {
+ CPDF_FormField* pField = m_pInterForm->GetField(i);
+ ASSERT(pField != NULL);
+
+ if (i != 0)
+ {
+ sFieldNames += L"\t";
+ sFieldValues += L"\t";
+ }
+ sFieldNames += pField->GetFullName();
+ sFieldValues += pField->GetValue();
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_InterForm::ImportFormFromTxtFile(const CFX_WideString& sTxtFileName)
+{
+ ASSERT(m_pInterForm != NULL);
+
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action)
+{
+ ASSERT(action != NULL);
+
+ CPDF_Dictionary* pActionDict = action;
+
+ if (pActionDict->KeyExist("Fields"))
+ {
+ CPDF_ActionFields af = action.GetWidgets();
+ FX_DWORD dwFlags = action.GetFlags();
+
+ CFX_PtrArray fieldObjects;
+ af.GetAllFields(fieldObjects);
+ CFX_PtrArray fields;
+ GetFieldFromObjects(fieldObjects, fields);
+
+ ASSERT(m_pInterForm != NULL);
+
+ return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE);
+ }
+ else
+ {
+ ASSERT(m_pInterForm != NULL);
+ return m_pInterForm->ResetForm(TRUE);
+ }
+}
+
+FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action)
+{
+ ASSERT(action != NULL);
+
+ CFX_WideString sFilePath = action.GetFilePath();
+ if (sFilePath.IsEmpty())
+ return FALSE;
+
+ if (!ImportFormFromFDFFile(sFilePath, TRUE))
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_InterForm::ImportFormFromFDFFile(const CFX_WideString& csFDFFileName,
+ FX_BOOL bNotify)
+{
+ return FALSE;
+}
+
+void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, CFX_PtrArray& fields)
+{
+ ASSERT(m_pInterForm != NULL);
+
+ int iCount = objects.GetSize();
+ for (int i = 0; i < iCount; i ++)
+ {
+ CPDF_Object* pObject = (CPDF_Object*)objects[i];
+ if (pObject == NULL) continue;
+
+ int iType = pObject->GetType();
+ if (iType == PDFOBJ_STRING)
+ {
+ CFX_WideString csName = pObject->GetUnicodeText();
+ CPDF_FormField* pField = m_pInterForm->GetField(0, csName);
+ if (pField != NULL)
+ fields.Add(pField);
+ }
+ else if (iType == PDFOBJ_DICTIONARY)
+ {
+ if (m_pInterForm->IsValidFormField(pObject))
+ fields.Add(pObject);
+ }
+ }
+}
+
+/* ----------------------------- CPDF_FormNotify ----------------------------- */
+
+int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue)
+{
+ ASSERT(pField != NULL);
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+
+ int nType = pFormField->GetFieldType();
+ if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
+ {
+ FX_BOOL bRC = TRUE;
+ OnKeyStrokeCommit(pFormField, csValue, bRC);
+ if (bRC)
+ {
+ OnValidate(pFormField, csValue, bRC);
+ if (bRC)
+ return 1;
+ else
+ return -1;
+ }
+ else
+ return -1;
+ }
+ else
+ return 0;
+}
+
+int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField)
+{
+ ASSERT(pField != NULL);
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+ int nType = pFormField->GetFieldType();
+
+ if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
+ {
+ this->OnCalculate(pFormField);
+ FX_BOOL bFormated = FALSE;
+ CFX_WideString sValue = this->OnFormat(pFormField, 0, bFormated);
+ if (bFormated)
+ this->ResetFieldAppearance(pFormField, sValue, TRUE);
+ else
+ this->ResetFieldAppearance(pFormField, NULL, TRUE);
+ this->UpdateField(pFormField);
+ }
+
+ return 0;
+}
+
+int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, CFX_WideString& csValue)
+{
+ ASSERT(pField != NULL);
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+
+ int nType = pFormField->GetFieldType();
+ if (nType == FIELDTYPE_LISTBOX)
+ {
+ FX_BOOL bRC = TRUE;
+ OnKeyStrokeCommit(pFormField, csValue, bRC);
+ if (bRC)
+ {
+ OnValidate(pFormField, csValue, bRC);
+ if (bRC)
+ return 1;
+ else
+ return -1;
+ }
+ else
+ return -1;
+ }
+ else
+ return 0;
+}
+
+int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField)
+{
+ ASSERT(pField != NULL);
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+ int nType = pFormField->GetFieldType();
+
+ if (nType == FIELDTYPE_LISTBOX)
+ {
+ this->OnCalculate(pFormField);
+ this->ResetFieldAppearance(pFormField, NULL, TRUE);
+ this->UpdateField(pFormField);
+ }
+
+ return 0;
+}
+
+int CPDFSDK_InterForm::AfterCheckedStatusChange(const CPDF_FormField* pField, const CFX_ByteArray& statusArray)
+{
+ ASSERT(pField != NULL);
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+ int nType = pFormField->GetFieldType();
+
+ if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON)
+ {
+ this->OnCalculate(pFormField);
+ //this->ResetFieldAppearance(pFormField, NULL);
+ this->UpdateField(pFormField);
+ }
+
+ return 0;
+}
+
+int CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm)
+{
+ return 0;
+}
+
+int CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm)
+{
+ this->OnCalculate(NULL);
+
+ return 0;
+}
+
+int CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm)
+{
+ return 0;
+}
+
+int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm)
+{
+ this->OnCalculate(NULL);
+
+ return 0;
+}
+
+FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType)
+{
+ if(nFieldType <1 || nFieldType > 6)
+ return FALSE;
+ return m_bNeedHightlight[nFieldType-1];
+}
+
+void CPDFSDK_InterForm::RemoveAllHighLight()
+{
+ memset((void*)m_bNeedHightlight, 0, 6*sizeof(FX_BOOL));
+}
+void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)
+{
+ if(nFieldType <0 || nFieldType > 6) return;
+ switch(nFieldType)
+ {
+ case 0:
+ {
+ for(int i=0; i<6; i++)
+ {
+ m_aHighlightColor[i] = clr;
+ m_bNeedHightlight[i] = TRUE;
+ }
+ break;
+ }
+ default:
+ {
+ m_aHighlightColor[nFieldType-1] = clr;
+ m_bNeedHightlight[nFieldType-1] = TRUE;
+ break;
+ }
+ }
+
+}
+
+FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType)
+{
+ if(nFieldType <0 || nFieldType >6) return FXSYS_RGB(255,255,255);
+ if(nFieldType == 0)
+ return m_aHighlightColor[0];
+ else
+ return m_aHighlightColor[nFieldType-1];
+}
+
+/* ------------------------- CBA_AnnotIterator ------------------------- */
+
+CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, const CFX_ByteString& sType, const CFX_ByteString& sSubType)
+ :m_pPageView(pPageView),
+ m_sType(sType),
+ m_sSubType(sSubType),
+ m_nTabs(BAI_STRUCTURE)
+{
+ ASSERT(m_pPageView != NULL);
+
+ CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();
+ ASSERT(pPDFPage != NULL);
+ ASSERT(pPDFPage->m_pFormDict != NULL);
+
+ CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs");
+
+ if (sTabs == "R")
+ {
+ m_nTabs = BAI_ROW;
+ }
+ else if (sTabs == "C")
+ {
+ m_nTabs = BAI_COLUMN;
+ }
+ else
+ {
+ m_nTabs = BAI_STRUCTURE;
+ }
+
+ GenerateResults();
+}
+
+CBA_AnnotIterator::~CBA_AnnotIterator()
+{
+ m_Annots.RemoveAll();
+}
+
+CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot()
+{
+ if (m_Annots.GetSize() > 0)
+ return m_Annots[0];
+
+ return NULL;
+}
+
+CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot()
+{
+ if (m_Annots.GetSize() > 0)
+ return m_Annots[m_Annots.GetSize() - 1];
+
+ return NULL;
+}
+
+CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot)
+{
+ for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
+ {
+ if (m_Annots[i] == pAnnot)
+ {
+ if (i+1 < sz)
+ return m_Annots[i+1];
+ else
+ return m_Annots[0];
+ }
+ }
+
+ return NULL;
+}
+
+CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot)
+{
+ for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
+ {
+ if (m_Annots[i] == pAnnot)
+ {
+ if (i-1 >= 0)
+ return m_Annots[i-1];
+ else
+ return m_Annots[sz-1];
+ }
+ }
+
+ return NULL;
+}
+
+int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
+{
+ ASSERT(p1 != NULL);
+ ASSERT(p2 != NULL);
+
+ CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
+ CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
+
+ if (rcAnnot1.left < rcAnnot2.left)
+ return -1;
+ if (rcAnnot1.left > rcAnnot2.left)
+ return 1;
+ return 0;
+}
+
+
+int CBA_AnnotIterator::CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
+{
+ ASSERT(p1 != NULL);
+ ASSERT(p2 != NULL);
+
+ CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
+ CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
+
+ if (rcAnnot1.top < rcAnnot2.top)
+ return -1;
+ if (rcAnnot1.top > rcAnnot2.top)
+ return 1;
+ return 0;
+}
+
+void CBA_AnnotIterator::GenerateResults()
+{
+ ASSERT(m_pPageView != NULL);
+
+ switch (m_nTabs)
+ {
+ case BAI_STRUCTURE:
+ {
+ for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
+ {
+ CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
+ ASSERT(pAnnot != NULL);
+
+ if (pAnnot->GetType() == m_sType
+ && pAnnot->GetSubType() == m_sSubType)
+ m_Annots.Add(pAnnot);
+ }
+ }
+ break;
+ case BAI_ROW:
+ {
+ CPDFSDK_SortAnnots sa;
+
+ {
+
+ for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
+ {
+ CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
+ ASSERT(pAnnot != NULL);
+
+ if (pAnnot->GetType() == m_sType
+ && pAnnot->GetSubType() == m_sSubType)
+ sa.Add(pAnnot);
+ }
+ }
+
+ if (sa.GetSize() > 0)
+ {
+ sa.Sort(CBA_AnnotIterator::CompareByLeft);
+ }
+
+ while (sa.GetSize() > 0)
+ {
+ int nLeftTopIndex = -1;
+
+ {
+ FX_FLOAT fTop = 0.0f;
+
+ for (int i=sa.GetSize()-1; i>=0; i--)
+ {
+ CPDFSDK_Annot* pAnnot = sa.GetAt(i);
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
+
+ if (rcAnnot.top > fTop)
+ {
+ nLeftTopIndex = i;
+ fTop = rcAnnot.top;
+ }
+ }
+ }
+
+ if (nLeftTopIndex >= 0)
+ {
+ CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
+ ASSERT(pLeftTopAnnot != NULL);
+
+ CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
+
+ m_Annots.Add(pLeftTopAnnot);
+ sa.RemoveAt(nLeftTopIndex);
+
+ CFX_ArrayTemplate<int> aSelect;
+
+ {
+ for (int i=0,sz=sa.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Annot* pAnnot = sa.GetAt(i);
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
+
+ FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
+
+ if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
+ aSelect.Add(i);
+ }
+ }
+
+ {
+ for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
+ {
+ m_Annots.Add(sa[aSelect[i]]);
+ }
+ }
+
+ {
+ for (int i=aSelect.GetSize()-1; i>=0; i--)
+ {
+ sa.RemoveAt(aSelect[i]);
+ }
+ }
+
+ aSelect.RemoveAll();
+ }
+ }
+ sa.RemoveAll();
+ }
+ break;
+ case BAI_COLUMN:
+ {
+ CPDFSDK_SortAnnots sa;
+
+ {
+ for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
+ {
+ CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
+ ASSERT(pAnnot != NULL);
+
+ if (pAnnot->GetType() == m_sType
+ && pAnnot->GetSubType() == m_sSubType)
+ sa.Add(pAnnot);
+ }
+ }
+
+ if (sa.GetSize() > 0)
+ {
+ sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE);
+ }
+
+ while (sa.GetSize() > 0)
+ {
+ int nLeftTopIndex = -1;
+
+ {
+ FX_FLOAT fLeft = -1.0f;
+
+ for (int i=sa.GetSize()-1; i>=0; i--)
+ {
+ CPDFSDK_Annot* pAnnot = sa.GetAt(i);
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
+
+ if (fLeft < 0)
+ {
+ nLeftTopIndex = 0;
+ fLeft = rcAnnot.left;
+ }
+ else if (rcAnnot.left < fLeft)
+ {
+ nLeftTopIndex = i;
+ fLeft = rcAnnot.left;
+ }
+ }
+ }
+
+ if (nLeftTopIndex >= 0)
+ {
+ CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
+ ASSERT(pLeftTopAnnot != NULL);
+
+ CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
+
+ m_Annots.Add(pLeftTopAnnot);
+ sa.RemoveAt(nLeftTopIndex);
+
+ CFX_ArrayTemplate<int> aSelect;
+
+ {
+ for (int i=0,sz=sa.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Annot* pAnnot = sa.GetAt(i);
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
+
+ FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
+
+ if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
+ aSelect.Add(i);
+ }
+ }
+
+ {
+ for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
+ {
+ m_Annots.Add(sa[aSelect[i]]);
+ }
+ }
+
+ {
+ for (int i=aSelect.GetSize()-1; i>=0; i--)
+ {
+ sa.RemoveAt(aSelect[i]);
+ }
+ }
+
+ aSelect.RemoveAll();
+ }
+ }
+ sa.RemoveAll();
+ }
+ break;
+ }
+}
+
+CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+
+ CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
+ ASSERT(pPDFAnnot != NULL);
+
+ CPDF_Rect rcAnnot;
+ pPDFAnnot->GetRect(rcAnnot);
+
+ return rcAnnot;
+}
+
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index 9a11927fab..9052c37d02 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -1,1055 +1,1055 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_define.h"
-#include "../include/fsdk_mgr.h"
-#include "../include/fpdf_ext.h"
-#include "../include/formfiller/FFL_FormFiller.h"
-#include "../include/javascript/IJavaScript.h"
-
-#if _FX_OS_ == _FX_ANDROID_
-#include "time.h"
-#else
-#include <ctime>
-#endif
-
-//extern CPDFDoc_Environment* g_pFormFillApp;
-class CFX_SystemHandler:public IFX_SystemHandler
-{
-public:
- CFX_SystemHandler(CPDFDoc_Environment* pEnv):m_pEnv(pEnv),m_nCharSet(-1) {}
-public:
- virtual void InvalidateRect(FX_HWND hWnd, FX_RECT rect) ;
- virtual void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect);
-
- virtual FX_BOOL IsSelectionImplemented();
-
- virtual CFX_WideString GetClipboardText(FX_HWND hWnd){return L"";}
- virtual FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) {return FALSE;}
-
- virtual void ClientToScreen(FX_HWND hWnd, FX_INT32& x, FX_INT32& y) {}
- virtual void ScreenToClient(FX_HWND hWnd, FX_INT32& x, FX_INT32& y) {}
-
- /*cursor style
- FXCT_ARROW
- FXCT_NESW
- FXCT_NWSE
- FXCT_VBEAM
- FXCT_HBEAM
- FXCT_HAND
- */
- virtual void SetCursor(FX_INT32 nCursorType);
-
- virtual FX_HMENU CreatePopupMenu() {return NULL;}
- virtual FX_BOOL AppendMenuItem(FX_HMENU hMenu, FX_INT32 nIDNewItem, CFX_WideString string) {return FALSE;}
- virtual FX_BOOL EnableMenuItem(FX_HMENU hMenu, FX_INT32 nIDItem, FX_BOOL bEnabled) {return FALSE;}
- virtual FX_INT32 TrackPopupMenu(FX_HMENU hMenu, FX_INT32 x, FX_INT32 y, FX_HWND hParent) {return -1;}
- virtual void DestroyMenu(FX_HMENU hMenu) {}
-
- virtual CFX_ByteString GetNativeTrueTypeFont(FX_INT32 nCharset);
- virtual FX_BOOL FindNativeTrueTypeFont(FX_INT32 nCharset, CFX_ByteString sFontFaceName);
- virtual CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, FX_BYTE nCharset);
-
- virtual FX_INT32 SetTimer(FX_INT32 uElapse, TimerCallback lpTimerFunc) ;
- virtual void KillTimer(FX_INT32 nID) ;
-
-
- virtual FX_BOOL IsSHIFTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsSHIFTKeyDown(nFlag);}
- virtual FX_BOOL IsCTRLKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsCTRLKeyDown(nFlag);}
- virtual FX_BOOL IsALTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsALTKeyDown(nFlag);}
- virtual FX_BOOL IsINSERTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsINSERTKeyDown(nFlag);}
-
- virtual FX_SYSTEMTIME GetLocalTime();
-
- virtual FX_INT32 GetCharSet() {return m_nCharSet;}
- virtual void SetCharSet(FX_INT32 nCharSet) {m_nCharSet = nCharSet;}
-private:
- CPDFDoc_Environment* m_pEnv;
- int m_nCharSet;
-};
-
-void CFX_SystemHandler::SetCursor(FX_INT32 nCursorType)
-{
-
- m_pEnv->FFI_SetCursor(nCursorType);
-}
-
-void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect)
-{
- //g_pFormFillApp->FFI_Invalidate();
- CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd;
- CPDF_Page* pPage = NULL;
- CPDFSDK_PageView* pPageView = NULL;
- pPageView = pSDKAnnot->GetPageView();
- pPage = pSDKAnnot->GetPDFPage();
- if(!pPage || !pPageView)
- return;
- CPDF_Matrix page2device;
- pPageView->GetCurrentMatrix(page2device);
- CPDF_Matrix device2page;
- device2page.SetReverse(page2device);
- FX_FLOAT left, top, right,bottom;
- device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top);
- device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, bottom);
-// m_pEnv->FFI_DeviceToPage(pPage, rect.left, rect.top, (double*)&left, (double*)&top);
-// m_pEnv->FFI_DeviceToPage(pPage, rect.right, rect.bottom, (double*)&right, (double*)&bottom);
- CPDF_Rect rcPDF(left, bottom, right, top);
- rcPDF.Normalize();
-
- m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, rcPDF.bottom);
-}
-void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect)
-{
- CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller;
- if(pFFL)
- {
- CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom);
- CPDF_Point righttop = CPDF_Point(rect.right, rect.top);
- CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom);
- CPDF_Point ptB = pFFL->PWLtoFFL(righttop);
-
-
- CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot();
- ASSERT(pAnnot);
- CPDF_Page* pPage = pAnnot->GetPDFPage();
- ASSERT(pPage);
- m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y);
- }
-
-}
-
-FX_BOOL CFX_SystemHandler::IsSelectionImplemented()
-{
- if(m_pEnv)
- {
- FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo();
- if(pInfo && pInfo->FFI_OutputSelectedRect)
- return TRUE;
- }
- return FALSE;
-}
-
-CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(FX_INT32 nCharset)
-{
- return "";
-}
-
-FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(FX_INT32 nCharset, CFX_ByteString sFontFaceName)
-{
- CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
-// FXFT_Face nFace = pFontMgr->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);
-// FXFT_Face nFace = pFontMgr->m_pBuiltinMapper->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);
-
- if(pFontMgr)
- {
- CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper;
- if(pFontMapper)
- {
- int nSize = pFontMapper->m_InstalledTTFonts.GetSize();
- if(nSize ==0)
- {
- pFontMapper->LoadInstalledFonts();
- nSize = pFontMapper->m_InstalledTTFonts.GetSize();
- }
-
- for(int i=0; i<nSize; i++)
- {
- if(pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName))
- return TRUE;
- }
- }
-
- }
-
- return FALSE;
-// pFontMgr->m_FaceMap.Lookup(sFontFaceName,pFont);
-// return (pFont!=NULL);
-}
-
-static int CharSet2CP(int charset)
-{
- if(charset == 128)
- return 932;
- else if(charset == 134)
- return 936;
- else if(charset == 129)
- return 949;
- else if(charset == 136)
- return 950;
- return 0;
-}
-CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName,
- FX_BYTE nCharset)
-{
- if(pDoc)
- {
- CFX_Font* pFXFont = new CFX_Font();
- pFXFont->LoadSubst(sFontFaceName,TRUE,0,0,0,CharSet2CP(nCharset),FALSE);
- CPDF_Font* pFont = pDoc->AddFont(pFXFont,nCharset,FALSE);
- delete pFXFont;
- return pFont;
- }
-
- return NULL;
-}
-
-
-FX_INT32 CFX_SystemHandler::SetTimer(FX_INT32 uElapse, TimerCallback lpTimerFunc)
-{
- return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc);
-}
-void CFX_SystemHandler::KillTimer(FX_INT32 nID)
-{
- m_pEnv->FFI_KillTimer(nID);
-}
-
-FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime()
-{
- return m_pEnv->FFI_GetLocalTime();
-}
-
-
-CJS_RuntimeFactory* GetJSRuntimeFactory()
-{
- static CJS_RuntimeFactory s_JSRuntimeFactory;
- return &s_JSRuntimeFactory;
-}
-
-CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document * pDoc):m_pInfo(NULL),m_pIFormFiller(NULL),
- m_pAnnotHandlerMgr(NULL),m_pActionHandler(NULL),m_pJSRuntime(NULL),
- m_pSDKDoc(NULL), m_pPDFDoc(pDoc)
-{
-
- m_pSysHandler = NULL;
- m_pSysHandler = new CFX_SystemHandler(this);
-
-
- m_pJSRuntimeFactory = NULL;
- m_pJSRuntimeFactory = GetJSRuntimeFactory();
- m_pJSRuntimeFactory->AddRef();
-}
-
-CPDFDoc_Environment::~CPDFDoc_Environment()
-{
-
- if ( m_pIFormFiller )
- {
- delete m_pIFormFiller;
- m_pIFormFiller = NULL;
- }
- if(m_pJSRuntime && m_pJSRuntimeFactory)
- m_pJSRuntimeFactory->DeleteJSRuntime(m_pJSRuntime);
- m_pJSRuntimeFactory->Release();
-
- if(m_pSysHandler)
- {
- delete m_pSysHandler;
- m_pSysHandler = NULL;
- }
-
- if(m_pAnnotHandlerMgr)
- {
- delete m_pAnnotHandlerMgr;
- m_pAnnotHandlerMgr = NULL;
- }
- if(m_pActionHandler)
- {
- delete m_pActionHandler;
- m_pActionHandler = NULL;
- }
-
-
-}
-
-
-IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()
-{
- if(!IsJSInitiated())
- return NULL;
- assert(m_pJSRuntimeFactory);
- if(!m_pJSRuntime)
- m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this);
- return m_pJSRuntime;
-}
-
-CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr()
-{
- if(!m_pAnnotHandlerMgr)
- m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this);
- return m_pAnnotHandlerMgr;
-}
-
-CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander()
-{
- if(!m_pActionHandler)
- m_pActionHandler = new CPDFSDK_ActionHandler(this);
- return m_pActionHandler;
-}
-
-int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo)
-{
- m_pInfo = pFFinfo;
- return TRUE;
-}
-
-CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc()
-{
- return m_pSDKDoc;
-}
-
-CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller()
-{
- if(!m_pIFormFiller)
- m_pIFormFiller = new CFFL_IFormFiller(this);
- return m_pIFormFiller;
-}
-
-FX_BOOL CPDFDoc_Environment::IsJSInitiated()
-{
- if(m_pInfo)
- {
- if(m_pInfo->m_pJsPlatform)
- return TRUE;
- else
- return FALSE;
- }
- return FALSE;
-}
-
-CPDFSDK_Document::CPDFSDK_Document(CPDF_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),
- m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE)
-{
- m_pFocusAnnot = NULL;
-}
-
-CPDFSDK_Document::~CPDFSDK_Document()
-{
- m_pageMap.RemoveAll();
- if(m_pInterForm)
- {
- m_pInterForm->Destroy();
- m_pInterForm = NULL;
- }
- if(m_pOccontent)
- {
- delete m_pOccontent;
- m_pOccontent = NULL;
- }
-}
-
-void CPDFSDK_Document::InitPageView()
-{
- int nCount = m_pDoc->GetPageCount();
- for(int i=0; i<nCount; i++)
- {
- // To do
-// CPDF_Dictionary* pDic = m_pDoc->GetPage(i);
-// m_pageMap.SetAt(pDic, pPageView);
- }
-}
-
-void CPDFSDK_Document::AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView)
-{
- m_pageMap.SetAt(pPDFPage, pPageView);
-}
-
-CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew)
-{
- CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
- if(pPageView != NULL)
- return pPageView;
- if(ReNew)
- {
- pPageView = new CPDFSDK_PageView(this,pPDFPage);
- m_pageMap.SetAt(pPDFPage, pPageView);
- //Delay to load all the annotations, to avoid endless loop.
- pPageView->LoadFXAnnots();
- }
- return pPageView;
-
-}
-
-CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
-{
- CPDF_Page * pPage = (CPDF_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
- if(pPage)
- return this->GetPageView(pPage, TRUE);
- return NULL;
-}
-
-CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
-{
- CPDFSDK_PageView * pTempPageView = NULL;
- CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
- if(!pTempPage)
- return NULL;
-
- m_pageMap.Lookup(pTempPage, pTempPageView);
-
- ASSERT(pTempPageView != NULL);
-
- return pTempPageView;
-}
-
-void CPDFSDK_Document:: ProcJavascriptFun()
-{
- CPDF_Document* pPDFDoc = this->GetDocument();
- CPDF_DocJSActions docJS(pPDFDoc);
- int iCount = docJS.CountJSActions();
- if (iCount < 1) return;
- for (int i = 0; i < iCount; i ++)
- {
- CFX_ByteString csJSName;
- CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
- if(m_pEnv->GetActionHander())
- m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
- }
-
-}
-
-FX_BOOL CPDFSDK_Document::ProcOpenAction()
-{
- if(!m_pDoc) return FALSE;
-
- CPDF_Dictionary* pRoot = m_pDoc->GetRoot();
- if (!pRoot) return FALSE;
- CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");//
- if(!pOpenAction) pOpenAction = pRoot->GetArray("OpenAction");//
- if(!pOpenAction) return FALSE;
-
- if(pOpenAction->GetType()==PDFOBJ_ARRAY)
- {
- }
- else if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
- {
- CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
- CPDF_Action Action = pDict;
-
- if(m_pEnv->GetActionHander())
- m_pEnv->GetActionHander()->DoAction_DocOpen(Action,this);
- }
- else
- {
- return FALSE;
- }
- return TRUE;
-}
-
-CPDF_OCContext* CPDFSDK_Document::GetOCContext()
-{
- if(!m_pOccontent)
- m_pOccontent = new CPDF_OCContext(m_pDoc);
- return m_pOccontent;
-}
-
-void CPDFSDK_Document::ReMovePageView(CPDF_Page* pPDFPage)
-{
- CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
- if(pPageView)
- {
- delete pPageView;
- m_pageMap.RemoveKey(pPDFPage);
- }
-}
-
-CPDF_Page * CPDFSDK_Document::GetPage(int nIndex)
-{
- CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
- if(!pTempPage)
- return NULL;
- return pTempPage;
-}
-
-CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
-{
- if(!m_pInterForm)
- m_pInterForm = new CPDFSDK_InterForm(this);
- return m_pInterForm;
-}
-
-void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
-{
-
- FX_POSITION pos = m_pageMap.GetStartPosition();
- CPDF_Page * pPage = NULL;
- CPDFSDK_PageView * pPageView = NULL;
- while(pos)
- {
- m_pageMap.GetNextAssoc(pos, pPage, pPageView);
-
- if(pPageView != pSender)
- {
- pPageView->UpdateView(pAnnot);
- }
- }
-}
-
-CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
-{
- return this->m_pFocusAnnot;
-}
-
-FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
-{
-
- if(m_pFocusAnnot==pAnnot) return TRUE;
-
- if(m_pFocusAnnot)
- {
- if(!this->KillFocusAnnot(nFlag) ) return FALSE;
- }
- CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
- if(pAnnot && pPageView->IsValid())
- {
- CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
-
- if(pAnnotHandler&&!m_pFocusAnnot)
- {
- if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
- return FALSE;
- if(!m_pFocusAnnot)
- {
- this->m_pFocusAnnot=pAnnot;
- return TRUE;
- }
- }
- }
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
-{
- if(m_pFocusAnnot)
- {
- CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
- if(pAnnotHandler)
- {
- CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
- m_pFocusAnnot = NULL;
- if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
- {
-
- if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
- int nFieldType = pWidget->GetFieldType();
- if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
- m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
- }
-
- if(!m_pFocusAnnot)
- return TRUE;
- }
- else
- {
- m_pFocusAnnot = pFocusAnnot;
- }
- }
- }
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
-{
- if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
- {
- return FALSE;
- }
-
- CPDF_Page * pTempPage = NULL;
- for ( int i = nCount-1; i >= 0; i-- )
- {
- pTempPage = GetPage(nStart+i);
- if ( pTempPage != NULL )
- {
- ReMovePageView(pTempPage);
- }
- }
- return TRUE;
-}
-
-void CPDFSDK_Document::OnCloseDocument()
-{
- KillFocusAnnot();
-}
-
-FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
-{
- FX_DWORD dwPermissions = m_pDoc->GetUserPermissions();
- return dwPermissions&nFlag;
-}
-
-IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
-{
- ASSERT(m_pEnv!=NULL);
- return m_pEnv->GetJSRuntime();
-}
-
-CFX_WideString CPDFSDK_Document::GetPath()
-{
- ASSERT(m_pEnv != NULL);
- return m_pEnv->JS_docGetFilePath();
-}
-
-
-CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page):m_pSDKDoc(pSDKDoc),m_page(page)
-{
- CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
- if(pInterForm)
- {
- CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
- pPDFInterForm->FixPageFields(page);
- }
-
- m_fxAnnotArray.RemoveAll();
-
- m_bEnterWidget = FALSE;
- m_bExitWidget = FALSE;
- m_bOnWidget = FALSE;
- m_CaptureWidget = NULL;
- m_bValid = FALSE;
-}
-
-CPDFSDK_PageView::~CPDFSDK_PageView()
-{
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- int nAnnotCount = m_fxAnnotArray.GetSize();
- for (int i=0; i<nAnnotCount; i++)
- {
- CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
- //if there is a focused annot on the page, we should kill the focus first.
- if(pAnnot == m_pSDKDoc->GetFocusAnnot())
- KillFocusAnnot();
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr);
- pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
- }
- m_fxAnnotArray.RemoveAll();
- if(m_pAnnotList)
- {
- delete m_pAnnotList;
- m_pAnnotList = NULL;
- }
-}
-
-void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions)
-{
- m_curMatrix = *pUser2Device;
-
- // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- CPDFSDK_AnnotIterator annotIterator(this, TRUE);
- CPDFSDK_Annot * pSDKAnnot=NULL;
- int index=-1;
- while((pSDKAnnot = annotIterator.Next(index)))
- {
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr);
- pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
- }
-
-}
-
-CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
-{
-
- int nCount = m_pAnnotList->Count();
- for(int i = 0 ; i<nCount; i++)
- {
- CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
- CFX_FloatRect annotRect;
- pAnnot->GetRect(annotRect);
- if(annotRect.Contains(pageX, pageY))
- return pAnnot;
- }
- return NULL;
-}
-
-CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
-{
-
- int nCount = m_pAnnotList->Count();
- for(int i = 0 ; i<nCount; i++)
- {
- CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
- if(pAnnot->GetSubType() == "Widget")
- {
- CFX_FloatRect annotRect;
- pAnnot->GetRect(annotRect);
- if(annotRect.Contains(pageX, pageY))
- return pAnnot;
- }
- }
- return NULL;
-}
-
-CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
-{
-
- CPDFSDK_AnnotIterator annotIterator(this, FALSE);
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
- CPDFSDK_Annot* pSDKAnnot = NULL;
- int index = -1;
- while((pSDKAnnot = annotIterator.Next(index)))
- {
- CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
- if(rc.Contains(pageX, pageY))
- return pSDKAnnot;
- }
-
- return NULL;
-}
-
-CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
-{
-
- CPDFSDK_AnnotIterator annotIterator(this, FALSE);
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
- CPDFSDK_Annot* pSDKAnnot = NULL;
- int index = -1;
- while((pSDKAnnot = annotIterator.Next(index)))
- {
- if(pSDKAnnot->GetType() == "Widget")
- {
- pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
- CPDF_Point point(pageX, pageY);
- if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
-// if(rc.Contains(pageX, pageY))
- return pSDKAnnot;
- }
- }
-
- return NULL;
-}
-
-
-FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
-{
- CPDF_Dictionary* pAnnotDic = pAnnot->m_pAnnotDict;
- if(pAnnotDic)
- return pAnnotDic->KeyExist("AS");
- return FALSE;
-}
-
-CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
-{
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- ASSERT(pEnv);
- CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
-
- CPDFSDK_Annot* pSDKAnnot =NULL;
-
- if(pAnnotHandler)
- {
- pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
- }
- if(!pSDKAnnot)
- return NULL;
-
- m_fxAnnotArray.Add(pSDKAnnot);
-
- if(pAnnotHandler)
- {
- pAnnotHandler->Annot_OnCreate(pSDKAnnot);
-
- }
-
- return pSDKAnnot;
-}
-
-CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
-{
- if(pDict)
- return this->AddAnnot(pDict->GetString("Subtype"),pDict);
- return NULL;
-}
-
-CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict)
-{
- return NULL;
-}
-
-FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
-{
- return FALSE;
-}
-
-CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
-{
- if(m_page)
- {
- return m_page->m_pDocument;
- }
- return NULL;
-}
-
-int CPDFSDK_PageView::CountAnnots()
-{
- return m_pAnnotList->Count();
-}
-
-CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
-{
- int nCount = m_fxAnnotArray.GetSize();
- if ( nIndex < 0 || nIndex >= nCount )
- {
- return NULL;
- }
-
- return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
-}
-
-CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
-{
- int nCount = m_fxAnnotArray.GetSize();
- for(int i=0; i<nCount; i++)
- {
- CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
- if(pDict==pAnnot->GetPDFAnnot()->m_pAnnotDict)
- return pAnnot;
- }
- return NULL;
-}
-
-FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
-{
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- ASSERT(pEnv);
- CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
- if(!pFXAnnot)
- {
- KillFocusAnnot(nFlag);
- }
- else
- {
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr);
-
- FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
- if(bRet)
- {
- SetFocusAnnot(pFXAnnot);
- }
- return bRet;
- }
- return FALSE;
-}
-
-
-FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
-{
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- ASSERT(pEnv);
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr);
- CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
- CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
- FX_BOOL bRet = FALSE;
- if(pFocusAnnot && pFocusAnnot != pFXAnnot)
- {
- //Last focus Annot gets a chance to handle the event.
- bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
- }
- if(pFXAnnot && !bRet)
- {
- bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
- return bRet;
- }
- return bRet;
-}
-
-FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
-{
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr);
- if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
- {
- if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
- {
- m_bExitWidget = TRUE;
- m_bEnterWidget = FALSE;
- pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
- }
- m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
- m_bOnWidget = TRUE;
- if(!m_bEnterWidget)
- {
- m_bEnterWidget = TRUE;
- m_bExitWidget = FALSE;
- pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
- }
- pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
- return TRUE;
- }
- else
- {
- if(m_bOnWidget)
- {
- m_bOnWidget = FALSE;
- m_bExitWidget = TRUE;
- m_bEnterWidget = FALSE;
- if(m_CaptureWidget)
- {
- pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
- m_CaptureWidget = NULL;
- }
- }
- return FALSE;
- }
-
- return FALSE;;
-}
-
-FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
-{
- if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
- {
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr);
- return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
- }
- return FALSE;
-
-}
-
-FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
-{
- if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
- {
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr);
- return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
-{
- if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
- {
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr);
- return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
- }
- return FALSE;
-}
-
-FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
-{
-// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
-// {
-// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
-// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
-// }
- return FALSE;
-}
-
-extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
-
-void CPDFSDK_PageView::LoadFXAnnots()
-{
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
-
- FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
- //Disable the default AP construction.
- CPDF_InterForm::EnableUpdateAP(FALSE);
- m_pAnnotList = new CPDF_AnnotList(m_page);
- CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
- int nCount = m_pAnnotList->Count();
- for(int i=0; i<nCount; i++)
- {
- CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
- CPDF_Document * pDoc = this->GetPDFDocument();
-
- CheckUnSupportAnnot(pDoc, pPDFAnnot);
-
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr != NULL);
- if(pAnnotHandlerMgr)
- {
- CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
- if(!pAnnot)
- continue;
- m_fxAnnotArray.Add(pAnnot);
-
- pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
- }
-
- }
-}
-
-void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
-{
- for(int i=0; i<rects.GetSize(); i++)
- {
- CPDF_Rect rc = rects.GetAt(i);
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
- }
-}
-
-void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
-{
- CPDF_Rect rcWindow;
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
-// CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
-
- rcWindow = pAnnot->GetRect();//pAnnotHandler->Annot_OnGetViewBBox(this,pAnnot);
- pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
-
-}
-
-int CPDFSDK_PageView::GetPageIndex()
-{
- if(m_page)
- {
- CPDF_Dictionary* pDic = m_page->m_pFormDict;
- CPDF_Document* pDoc = m_pSDKDoc->GetDocument();
- if(pDoc && pDic)
- {
- return pDoc->GetPageIndex(pDic->GetObjNum());
- }
- }
- return -1;
-}
-
-FX_BOOL CPDFSDK_PageView::IsValidAnnot(FX_LPVOID p)
-{
- if (p == NULL) return FALSE;
- int iCount = m_pAnnotList->Count();
- for (int i = 0; i < iCount; i++)
- {
- if (m_pAnnotList->GetAt(i) == p)
- return TRUE;
- }
- return FALSE;
-}
-
-
-CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
-{
- CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
- if(!pFocusAnnot)
- return NULL;
-
- for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
- {
- CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
- if(pAnnot == pFocusAnnot)
- return pAnnot;
- }
- return NULL;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fsdk_mgr.h"
+#include "../include/fpdf_ext.h"
+#include "../include/formfiller/FFL_FormFiller.h"
+#include "../include/javascript/IJavaScript.h"
+
+#if _FX_OS_ == _FX_ANDROID_
+#include "time.h"
+#else
+#include <ctime>
+#endif
+
+//extern CPDFDoc_Environment* g_pFormFillApp;
+class CFX_SystemHandler:public IFX_SystemHandler
+{
+public:
+ CFX_SystemHandler(CPDFDoc_Environment* pEnv):m_pEnv(pEnv),m_nCharSet(-1) {}
+public:
+ virtual void InvalidateRect(FX_HWND hWnd, FX_RECT rect) ;
+ virtual void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect);
+
+ virtual FX_BOOL IsSelectionImplemented();
+
+ virtual CFX_WideString GetClipboardText(FX_HWND hWnd){return L"";}
+ virtual FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) {return FALSE;}
+
+ virtual void ClientToScreen(FX_HWND hWnd, FX_INT32& x, FX_INT32& y) {}
+ virtual void ScreenToClient(FX_HWND hWnd, FX_INT32& x, FX_INT32& y) {}
+
+ /*cursor style
+ FXCT_ARROW
+ FXCT_NESW
+ FXCT_NWSE
+ FXCT_VBEAM
+ FXCT_HBEAM
+ FXCT_HAND
+ */
+ virtual void SetCursor(FX_INT32 nCursorType);
+
+ virtual FX_HMENU CreatePopupMenu() {return NULL;}
+ virtual FX_BOOL AppendMenuItem(FX_HMENU hMenu, FX_INT32 nIDNewItem, CFX_WideString string) {return FALSE;}
+ virtual FX_BOOL EnableMenuItem(FX_HMENU hMenu, FX_INT32 nIDItem, FX_BOOL bEnabled) {return FALSE;}
+ virtual FX_INT32 TrackPopupMenu(FX_HMENU hMenu, FX_INT32 x, FX_INT32 y, FX_HWND hParent) {return -1;}
+ virtual void DestroyMenu(FX_HMENU hMenu) {}
+
+ virtual CFX_ByteString GetNativeTrueTypeFont(FX_INT32 nCharset);
+ virtual FX_BOOL FindNativeTrueTypeFont(FX_INT32 nCharset, CFX_ByteString sFontFaceName);
+ virtual CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, FX_BYTE nCharset);
+
+ virtual FX_INT32 SetTimer(FX_INT32 uElapse, TimerCallback lpTimerFunc) ;
+ virtual void KillTimer(FX_INT32 nID) ;
+
+
+ virtual FX_BOOL IsSHIFTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsSHIFTKeyDown(nFlag);}
+ virtual FX_BOOL IsCTRLKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsCTRLKeyDown(nFlag);}
+ virtual FX_BOOL IsALTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsALTKeyDown(nFlag);}
+ virtual FX_BOOL IsINSERTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsINSERTKeyDown(nFlag);}
+
+ virtual FX_SYSTEMTIME GetLocalTime();
+
+ virtual FX_INT32 GetCharSet() {return m_nCharSet;}
+ virtual void SetCharSet(FX_INT32 nCharSet) {m_nCharSet = nCharSet;}
+private:
+ CPDFDoc_Environment* m_pEnv;
+ int m_nCharSet;
+};
+
+void CFX_SystemHandler::SetCursor(FX_INT32 nCursorType)
+{
+
+ m_pEnv->FFI_SetCursor(nCursorType);
+}
+
+void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect)
+{
+ //g_pFormFillApp->FFI_Invalidate();
+ CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd;
+ CPDF_Page* pPage = NULL;
+ CPDFSDK_PageView* pPageView = NULL;
+ pPageView = pSDKAnnot->GetPageView();
+ pPage = pSDKAnnot->GetPDFPage();
+ if(!pPage || !pPageView)
+ return;
+ CPDF_Matrix page2device;
+ pPageView->GetCurrentMatrix(page2device);
+ CPDF_Matrix device2page;
+ device2page.SetReverse(page2device);
+ FX_FLOAT left, top, right,bottom;
+ device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top);
+ device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, bottom);
+// m_pEnv->FFI_DeviceToPage(pPage, rect.left, rect.top, (double*)&left, (double*)&top);
+// m_pEnv->FFI_DeviceToPage(pPage, rect.right, rect.bottom, (double*)&right, (double*)&bottom);
+ CPDF_Rect rcPDF(left, bottom, right, top);
+ rcPDF.Normalize();
+
+ m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, rcPDF.bottom);
+}
+void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect)
+{
+ CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller;
+ if(pFFL)
+ {
+ CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom);
+ CPDF_Point righttop = CPDF_Point(rect.right, rect.top);
+ CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom);
+ CPDF_Point ptB = pFFL->PWLtoFFL(righttop);
+
+
+ CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot();
+ ASSERT(pAnnot);
+ CPDF_Page* pPage = pAnnot->GetPDFPage();
+ ASSERT(pPage);
+ m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y);
+ }
+
+}
+
+FX_BOOL CFX_SystemHandler::IsSelectionImplemented()
+{
+ if(m_pEnv)
+ {
+ FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo();
+ if(pInfo && pInfo->FFI_OutputSelectedRect)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(FX_INT32 nCharset)
+{
+ return "";
+}
+
+FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(FX_INT32 nCharset, CFX_ByteString sFontFaceName)
+{
+ CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
+// FXFT_Face nFace = pFontMgr->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);
+// FXFT_Face nFace = pFontMgr->m_pBuiltinMapper->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);
+
+ if(pFontMgr)
+ {
+ CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper;
+ if(pFontMapper)
+ {
+ int nSize = pFontMapper->m_InstalledTTFonts.GetSize();
+ if(nSize ==0)
+ {
+ pFontMapper->LoadInstalledFonts();
+ nSize = pFontMapper->m_InstalledTTFonts.GetSize();
+ }
+
+ for(int i=0; i<nSize; i++)
+ {
+ if(pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName))
+ return TRUE;
+ }
+ }
+
+ }
+
+ return FALSE;
+// pFontMgr->m_FaceMap.Lookup(sFontFaceName,pFont);
+// return (pFont!=NULL);
+}
+
+static int CharSet2CP(int charset)
+{
+ if(charset == 128)
+ return 932;
+ else if(charset == 134)
+ return 936;
+ else if(charset == 129)
+ return 949;
+ else if(charset == 136)
+ return 950;
+ return 0;
+}
+CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName,
+ FX_BYTE nCharset)
+{
+ if(pDoc)
+ {
+ CFX_Font* pFXFont = new CFX_Font();
+ pFXFont->LoadSubst(sFontFaceName,TRUE,0,0,0,CharSet2CP(nCharset),FALSE);
+ CPDF_Font* pFont = pDoc->AddFont(pFXFont,nCharset,FALSE);
+ delete pFXFont;
+ return pFont;
+ }
+
+ return NULL;
+}
+
+
+FX_INT32 CFX_SystemHandler::SetTimer(FX_INT32 uElapse, TimerCallback lpTimerFunc)
+{
+ return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc);
+}
+void CFX_SystemHandler::KillTimer(FX_INT32 nID)
+{
+ m_pEnv->FFI_KillTimer(nID);
+}
+
+FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime()
+{
+ return m_pEnv->FFI_GetLocalTime();
+}
+
+
+CJS_RuntimeFactory* GetJSRuntimeFactory()
+{
+ static CJS_RuntimeFactory s_JSRuntimeFactory;
+ return &s_JSRuntimeFactory;
+}
+
+CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document * pDoc):m_pInfo(NULL),m_pIFormFiller(NULL),
+ m_pAnnotHandlerMgr(NULL),m_pActionHandler(NULL),m_pJSRuntime(NULL),
+ m_pSDKDoc(NULL), m_pPDFDoc(pDoc)
+{
+
+ m_pSysHandler = NULL;
+ m_pSysHandler = new CFX_SystemHandler(this);
+
+
+ m_pJSRuntimeFactory = NULL;
+ m_pJSRuntimeFactory = GetJSRuntimeFactory();
+ m_pJSRuntimeFactory->AddRef();
+}
+
+CPDFDoc_Environment::~CPDFDoc_Environment()
+{
+
+ if ( m_pIFormFiller )
+ {
+ delete m_pIFormFiller;
+ m_pIFormFiller = NULL;
+ }
+ if(m_pJSRuntime && m_pJSRuntimeFactory)
+ m_pJSRuntimeFactory->DeleteJSRuntime(m_pJSRuntime);
+ m_pJSRuntimeFactory->Release();
+
+ if(m_pSysHandler)
+ {
+ delete m_pSysHandler;
+ m_pSysHandler = NULL;
+ }
+
+ if(m_pAnnotHandlerMgr)
+ {
+ delete m_pAnnotHandlerMgr;
+ m_pAnnotHandlerMgr = NULL;
+ }
+ if(m_pActionHandler)
+ {
+ delete m_pActionHandler;
+ m_pActionHandler = NULL;
+ }
+
+
+}
+
+
+IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()
+{
+ if(!IsJSInitiated())
+ return NULL;
+ assert(m_pJSRuntimeFactory);
+ if(!m_pJSRuntime)
+ m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this);
+ return m_pJSRuntime;
+}
+
+CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr()
+{
+ if(!m_pAnnotHandlerMgr)
+ m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this);
+ return m_pAnnotHandlerMgr;
+}
+
+CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander()
+{
+ if(!m_pActionHandler)
+ m_pActionHandler = new CPDFSDK_ActionHandler(this);
+ return m_pActionHandler;
+}
+
+int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo)
+{
+ m_pInfo = pFFinfo;
+ return TRUE;
+}
+
+CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc()
+{
+ return m_pSDKDoc;
+}
+
+CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller()
+{
+ if(!m_pIFormFiller)
+ m_pIFormFiller = new CFFL_IFormFiller(this);
+ return m_pIFormFiller;
+}
+
+FX_BOOL CPDFDoc_Environment::IsJSInitiated()
+{
+ if(m_pInfo)
+ {
+ if(m_pInfo->m_pJsPlatform)
+ return TRUE;
+ else
+ return FALSE;
+ }
+ return FALSE;
+}
+
+CPDFSDK_Document::CPDFSDK_Document(CPDF_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),
+ m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE)
+{
+ m_pFocusAnnot = NULL;
+}
+
+CPDFSDK_Document::~CPDFSDK_Document()
+{
+ m_pageMap.RemoveAll();
+ if(m_pInterForm)
+ {
+ m_pInterForm->Destroy();
+ m_pInterForm = NULL;
+ }
+ if(m_pOccontent)
+ {
+ delete m_pOccontent;
+ m_pOccontent = NULL;
+ }
+}
+
+void CPDFSDK_Document::InitPageView()
+{
+ int nCount = m_pDoc->GetPageCount();
+ for(int i=0; i<nCount; i++)
+ {
+ // To do
+// CPDF_Dictionary* pDic = m_pDoc->GetPage(i);
+// m_pageMap.SetAt(pDic, pPageView);
+ }
+}
+
+void CPDFSDK_Document::AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView)
+{
+ m_pageMap.SetAt(pPDFPage, pPageView);
+}
+
+CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew)
+{
+ CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
+ if(pPageView != NULL)
+ return pPageView;
+ if(ReNew)
+ {
+ pPageView = new CPDFSDK_PageView(this,pPDFPage);
+ m_pageMap.SetAt(pPDFPage, pPageView);
+ //Delay to load all the annotations, to avoid endless loop.
+ pPageView->LoadFXAnnots();
+ }
+ return pPageView;
+
+}
+
+CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
+{
+ CPDF_Page * pPage = (CPDF_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
+ if(pPage)
+ return this->GetPageView(pPage, TRUE);
+ return NULL;
+}
+
+CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
+{
+ CPDFSDK_PageView * pTempPageView = NULL;
+ CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
+ if(!pTempPage)
+ return NULL;
+
+ m_pageMap.Lookup(pTempPage, pTempPageView);
+
+ ASSERT(pTempPageView != NULL);
+
+ return pTempPageView;
+}
+
+void CPDFSDK_Document:: ProcJavascriptFun()
+{
+ CPDF_Document* pPDFDoc = this->GetDocument();
+ CPDF_DocJSActions docJS(pPDFDoc);
+ int iCount = docJS.CountJSActions();
+ if (iCount < 1) return;
+ for (int i = 0; i < iCount; i ++)
+ {
+ CFX_ByteString csJSName;
+ CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
+ if(m_pEnv->GetActionHander())
+ m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
+ }
+
+}
+
+FX_BOOL CPDFSDK_Document::ProcOpenAction()
+{
+ if(!m_pDoc) return FALSE;
+
+ CPDF_Dictionary* pRoot = m_pDoc->GetRoot();
+ if (!pRoot) return FALSE;
+ CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");//
+ if(!pOpenAction) pOpenAction = pRoot->GetArray("OpenAction");//
+ if(!pOpenAction) return FALSE;
+
+ if(pOpenAction->GetType()==PDFOBJ_ARRAY)
+ {
+ }
+ else if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
+ {
+ CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
+ CPDF_Action Action = pDict;
+
+ if(m_pEnv->GetActionHander())
+ m_pEnv->GetActionHander()->DoAction_DocOpen(Action,this);
+ }
+ else
+ {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+CPDF_OCContext* CPDFSDK_Document::GetOCContext()
+{
+ if(!m_pOccontent)
+ m_pOccontent = new CPDF_OCContext(m_pDoc);
+ return m_pOccontent;
+}
+
+void CPDFSDK_Document::ReMovePageView(CPDF_Page* pPDFPage)
+{
+ CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
+ if(pPageView)
+ {
+ delete pPageView;
+ m_pageMap.RemoveKey(pPDFPage);
+ }
+}
+
+CPDF_Page * CPDFSDK_Document::GetPage(int nIndex)
+{
+ CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
+ if(!pTempPage)
+ return NULL;
+ return pTempPage;
+}
+
+CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
+{
+ if(!m_pInterForm)
+ m_pInterForm = new CPDFSDK_InterForm(this);
+ return m_pInterForm;
+}
+
+void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
+{
+
+ FX_POSITION pos = m_pageMap.GetStartPosition();
+ CPDF_Page * pPage = NULL;
+ CPDFSDK_PageView * pPageView = NULL;
+ while(pos)
+ {
+ m_pageMap.GetNextAssoc(pos, pPage, pPageView);
+
+ if(pPageView != pSender)
+ {
+ pPageView->UpdateView(pAnnot);
+ }
+ }
+}
+
+CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
+{
+ return this->m_pFocusAnnot;
+}
+
+FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
+{
+
+ if(m_pFocusAnnot==pAnnot) return TRUE;
+
+ if(m_pFocusAnnot)
+ {
+ if(!this->KillFocusAnnot(nFlag) ) return FALSE;
+ }
+ CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
+ if(pAnnot && pPageView->IsValid())
+ {
+ CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
+
+ if(pAnnotHandler&&!m_pFocusAnnot)
+ {
+ if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
+ return FALSE;
+ if(!m_pFocusAnnot)
+ {
+ this->m_pFocusAnnot=pAnnot;
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
+{
+ if(m_pFocusAnnot)
+ {
+ CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
+ if(pAnnotHandler)
+ {
+ CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
+ m_pFocusAnnot = NULL;
+ if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
+ {
+
+ if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
+ int nFieldType = pWidget->GetFieldType();
+ if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
+ m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
+ }
+
+ if(!m_pFocusAnnot)
+ return TRUE;
+ }
+ else
+ {
+ m_pFocusAnnot = pFocusAnnot;
+ }
+ }
+ }
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
+{
+ if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
+ {
+ return FALSE;
+ }
+
+ CPDF_Page * pTempPage = NULL;
+ for ( int i = nCount-1; i >= 0; i-- )
+ {
+ pTempPage = GetPage(nStart+i);
+ if ( pTempPage != NULL )
+ {
+ ReMovePageView(pTempPage);
+ }
+ }
+ return TRUE;
+}
+
+void CPDFSDK_Document::OnCloseDocument()
+{
+ KillFocusAnnot();
+}
+
+FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
+{
+ FX_DWORD dwPermissions = m_pDoc->GetUserPermissions();
+ return dwPermissions&nFlag;
+}
+
+IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
+{
+ ASSERT(m_pEnv!=NULL);
+ return m_pEnv->GetJSRuntime();
+}
+
+CFX_WideString CPDFSDK_Document::GetPath()
+{
+ ASSERT(m_pEnv != NULL);
+ return m_pEnv->JS_docGetFilePath();
+}
+
+
+CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page):m_pSDKDoc(pSDKDoc),m_page(page)
+{
+ CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
+ if(pInterForm)
+ {
+ CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
+ pPDFInterForm->FixPageFields(page);
+ }
+
+ m_fxAnnotArray.RemoveAll();
+
+ m_bEnterWidget = FALSE;
+ m_bExitWidget = FALSE;
+ m_bOnWidget = FALSE;
+ m_CaptureWidget = NULL;
+ m_bValid = FALSE;
+}
+
+CPDFSDK_PageView::~CPDFSDK_PageView()
+{
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ int nAnnotCount = m_fxAnnotArray.GetSize();
+ for (int i=0; i<nAnnotCount; i++)
+ {
+ CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
+ //if there is a focused annot on the page, we should kill the focus first.
+ if(pAnnot == m_pSDKDoc->GetFocusAnnot())
+ KillFocusAnnot();
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+ pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
+ }
+ m_fxAnnotArray.RemoveAll();
+ if(m_pAnnotList)
+ {
+ delete m_pAnnotList;
+ m_pAnnotList = NULL;
+ }
+}
+
+void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions)
+{
+ m_curMatrix = *pUser2Device;
+
+ // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ CPDFSDK_AnnotIterator annotIterator(this, TRUE);
+ CPDFSDK_Annot * pSDKAnnot=NULL;
+ int index=-1;
+ while((pSDKAnnot = annotIterator.Next(index)))
+ {
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+ pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
+ }
+
+}
+
+CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
+{
+
+ int nCount = m_pAnnotList->Count();
+ for(int i = 0 ; i<nCount; i++)
+ {
+ CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
+ CFX_FloatRect annotRect;
+ pAnnot->GetRect(annotRect);
+ if(annotRect.Contains(pageX, pageY))
+ return pAnnot;
+ }
+ return NULL;
+}
+
+CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
+{
+
+ int nCount = m_pAnnotList->Count();
+ for(int i = 0 ; i<nCount; i++)
+ {
+ CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
+ if(pAnnot->GetSubType() == "Widget")
+ {
+ CFX_FloatRect annotRect;
+ pAnnot->GetRect(annotRect);
+ if(annotRect.Contains(pageX, pageY))
+ return pAnnot;
+ }
+ }
+ return NULL;
+}
+
+CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
+{
+
+ CPDFSDK_AnnotIterator annotIterator(this, FALSE);
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
+ CPDFSDK_Annot* pSDKAnnot = NULL;
+ int index = -1;
+ while((pSDKAnnot = annotIterator.Next(index)))
+ {
+ CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
+ if(rc.Contains(pageX, pageY))
+ return pSDKAnnot;
+ }
+
+ return NULL;
+}
+
+CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
+{
+
+ CPDFSDK_AnnotIterator annotIterator(this, FALSE);
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
+ CPDFSDK_Annot* pSDKAnnot = NULL;
+ int index = -1;
+ while((pSDKAnnot = annotIterator.Next(index)))
+ {
+ if(pSDKAnnot->GetType() == "Widget")
+ {
+ pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
+ CPDF_Point point(pageX, pageY);
+ if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
+// if(rc.Contains(pageX, pageY))
+ return pSDKAnnot;
+ }
+ }
+
+ return NULL;
+}
+
+
+FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
+{
+ CPDF_Dictionary* pAnnotDic = pAnnot->m_pAnnotDict;
+ if(pAnnotDic)
+ return pAnnotDic->KeyExist("AS");
+ return FALSE;
+}
+
+CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
+{
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ ASSERT(pEnv);
+ CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
+
+ CPDFSDK_Annot* pSDKAnnot =NULL;
+
+ if(pAnnotHandler)
+ {
+ pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
+ }
+ if(!pSDKAnnot)
+ return NULL;
+
+ m_fxAnnotArray.Add(pSDKAnnot);
+
+ if(pAnnotHandler)
+ {
+ pAnnotHandler->Annot_OnCreate(pSDKAnnot);
+
+ }
+
+ return pSDKAnnot;
+}
+
+CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
+{
+ if(pDict)
+ return this->AddAnnot(pDict->GetString("Subtype"),pDict);
+ return NULL;
+}
+
+CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict)
+{
+ return NULL;
+}
+
+FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
+{
+ return FALSE;
+}
+
+CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
+{
+ if(m_page)
+ {
+ return m_page->m_pDocument;
+ }
+ return NULL;
+}
+
+int CPDFSDK_PageView::CountAnnots()
+{
+ return m_pAnnotList->Count();
+}
+
+CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
+{
+ int nCount = m_fxAnnotArray.GetSize();
+ if ( nIndex < 0 || nIndex >= nCount )
+ {
+ return NULL;
+ }
+
+ return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
+}
+
+CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
+{
+ int nCount = m_fxAnnotArray.GetSize();
+ for(int i=0; i<nCount; i++)
+ {
+ CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
+ if(pDict==pAnnot->GetPDFAnnot()->m_pAnnotDict)
+ return pAnnot;
+ }
+ return NULL;
+}
+
+FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
+{
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ ASSERT(pEnv);
+ CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
+ if(!pFXAnnot)
+ {
+ KillFocusAnnot(nFlag);
+ }
+ else
+ {
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+
+ FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
+ if(bRet)
+ {
+ SetFocusAnnot(pFXAnnot);
+ }
+ return bRet;
+ }
+ return FALSE;
+}
+
+
+FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
+{
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ ASSERT(pEnv);
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+ CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
+ CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
+ FX_BOOL bRet = FALSE;
+ if(pFocusAnnot && pFocusAnnot != pFXAnnot)
+ {
+ //Last focus Annot gets a chance to handle the event.
+ bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
+ }
+ if(pFXAnnot && !bRet)
+ {
+ bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
+ return bRet;
+ }
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
+{
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+ if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
+ {
+ if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
+ {
+ m_bExitWidget = TRUE;
+ m_bEnterWidget = FALSE;
+ pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
+ }
+ m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
+ m_bOnWidget = TRUE;
+ if(!m_bEnterWidget)
+ {
+ m_bEnterWidget = TRUE;
+ m_bExitWidget = FALSE;
+ pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
+ }
+ pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
+ return TRUE;
+ }
+ else
+ {
+ if(m_bOnWidget)
+ {
+ m_bOnWidget = FALSE;
+ m_bExitWidget = TRUE;
+ m_bEnterWidget = FALSE;
+ if(m_CaptureWidget)
+ {
+ pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
+ m_CaptureWidget = NULL;
+ }
+ }
+ return FALSE;
+ }
+
+ return FALSE;;
+}
+
+FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
+{
+ if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
+ {
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+ return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
+ }
+ return FALSE;
+
+}
+
+FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
+{
+ if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
+ {
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+ return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
+{
+ if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
+ {
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+ return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
+ }
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
+{
+// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
+// {
+// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
+// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
+// }
+ return FALSE;
+}
+
+extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
+
+void CPDFSDK_PageView::LoadFXAnnots()
+{
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+
+ FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
+ //Disable the default AP construction.
+ CPDF_InterForm::EnableUpdateAP(FALSE);
+ m_pAnnotList = new CPDF_AnnotList(m_page);
+ CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
+ int nCount = m_pAnnotList->Count();
+ for(int i=0; i<nCount; i++)
+ {
+ CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
+ CPDF_Document * pDoc = this->GetPDFDocument();
+
+ CheckUnSupportAnnot(pDoc, pPDFAnnot);
+
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr != NULL);
+ if(pAnnotHandlerMgr)
+ {
+ CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
+ if(!pAnnot)
+ continue;
+ m_fxAnnotArray.Add(pAnnot);
+
+ pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
+ }
+
+ }
+}
+
+void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
+{
+ for(int i=0; i<rects.GetSize(); i++)
+ {
+ CPDF_Rect rc = rects.GetAt(i);
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
+ }
+}
+
+void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
+{
+ CPDF_Rect rcWindow;
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+// CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
+
+ rcWindow = pAnnot->GetRect();//pAnnotHandler->Annot_OnGetViewBBox(this,pAnnot);
+ pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
+
+}
+
+int CPDFSDK_PageView::GetPageIndex()
+{
+ if(m_page)
+ {
+ CPDF_Dictionary* pDic = m_page->m_pFormDict;
+ CPDF_Document* pDoc = m_pSDKDoc->GetDocument();
+ if(pDoc && pDic)
+ {
+ return pDoc->GetPageIndex(pDic->GetObjNum());
+ }
+ }
+ return -1;
+}
+
+FX_BOOL CPDFSDK_PageView::IsValidAnnot(FX_LPVOID p)
+{
+ if (p == NULL) return FALSE;
+ int iCount = m_pAnnotList->Count();
+ for (int i = 0; i < iCount; i++)
+ {
+ if (m_pAnnotList->GetAt(i) == p)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
+{
+ CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
+ if(!pFocusAnnot)
+ return NULL;
+
+ for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
+ {
+ CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
+ if(pAnnot == pFocusAnnot)
+ return pAnnot;
+ }
+ return NULL;
+}
+
diff --git a/fpdfsdk/src/fsdk_rendercontext.cpp b/fpdfsdk/src/fsdk_rendercontext.cpp
index 55382e160e..89c6179254 100644
--- a/fpdfsdk/src/fsdk_rendercontext.cpp
+++ b/fpdfsdk/src/fsdk_rendercontext.cpp
@@ -1,49 +1,49 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../include/fsdk_rendercontext.h"
-
-void CRenderContext::Clear()
-{
- m_pDevice = NULL;
- m_pContext = NULL;
- m_pRenderer = NULL;
- m_pAnnots = NULL;
- m_pOptions = NULL;
-#ifdef _WIN32_WCE
- m_pBitmap = NULL;
- m_hBitmap = NULL;
-#endif
-}
-
-CRenderContext::~CRenderContext()
-{
- if (m_pRenderer) delete m_pRenderer;
- if (m_pContext) delete m_pContext;
- if (m_pDevice) delete m_pDevice;
- if (m_pAnnots) delete m_pAnnots;
- if (m_pOptions->m_pOCContext) delete m_pOptions->m_pOCContext;
- if (m_pOptions) delete m_pOptions;
-#ifdef _WIN32_WCE
- if (m_pBitmap) delete m_pBitmap;
- if (m_hBitmap) DeleteObject(m_hBitmap);
-#endif
-}
-
-IFSDK_PAUSE_Adapter::IFSDK_PAUSE_Adapter(IFSDK_PAUSE* IPause )
-{
- m_IPause = IPause;
-}
-
-FX_BOOL IFSDK_PAUSE_Adapter::NeedToPauseNow()
-{
- if (m_IPause->NeedToPauseNow)
- {
- return m_IPause->NeedToPauseNow(m_IPause);
- }else{
- return FALSE;
- }
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_rendercontext.h"
+
+void CRenderContext::Clear()
+{
+ m_pDevice = NULL;
+ m_pContext = NULL;
+ m_pRenderer = NULL;
+ m_pAnnots = NULL;
+ m_pOptions = NULL;
+#ifdef _WIN32_WCE
+ m_pBitmap = NULL;
+ m_hBitmap = NULL;
+#endif
+}
+
+CRenderContext::~CRenderContext()
+{
+ if (m_pRenderer) delete m_pRenderer;
+ if (m_pContext) delete m_pContext;
+ if (m_pDevice) delete m_pDevice;
+ if (m_pAnnots) delete m_pAnnots;
+ if (m_pOptions->m_pOCContext) delete m_pOptions->m_pOCContext;
+ if (m_pOptions) delete m_pOptions;
+#ifdef _WIN32_WCE
+ if (m_pBitmap) delete m_pBitmap;
+ if (m_hBitmap) DeleteObject(m_hBitmap);
+#endif
+}
+
+IFSDK_PAUSE_Adapter::IFSDK_PAUSE_Adapter(IFSDK_PAUSE* IPause )
+{
+ m_IPause = IPause;
+}
+
+FX_BOOL IFSDK_PAUSE_Adapter::NeedToPauseNow()
+{
+ if (m_IPause->NeedToPauseNow)
+ {
+ return m_IPause->NeedToPauseNow(m_IPause);
+ }else{
+ return FALSE;
+ }
+}
diff --git a/fpdfsdk/src/fxedit/fxet_ap.cpp b/fpdfsdk/src/fxedit/fxet_ap.cpp
index 9730d37a45..92e5bfc1dd 100644
--- a/fpdfsdk/src/fxedit/fxet_ap.cpp
+++ b/fpdfsdk/src/fxedit/fxet_ap.cpp
@@ -1,225 +1,225 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/fxedit/fxet_stub.h"
-#include "../../include/fxedit/fx_edit.h"
-#include "../../include/fxedit/fxet_edit.h"
-
-CFX_ByteString GetPDFWordString(IFX_Edit_FontMap * pFontMap, FX_INT32 nFontIndex, FX_WORD Word, FX_WORD SubWord)
-{
- ASSERT (pFontMap != NULL);
-
- CFX_ByteString sWord;
-
- if (CPDF_Font * pPDFFont = pFontMap->GetPDFFont(nFontIndex))
- {
- if (SubWord > 0)
- {
- Word = SubWord;
- }
- else
- {
- FX_DWORD dwCharCode = -1;
-
- if (pPDFFont->IsUnicodeCompatible())
- dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
- else
- dwCharCode = pFontMap->CharCodeFromUnicode(nFontIndex, Word);
-
- if (dwCharCode > 0 )
- {
- pPDFFont->AppendChar(sWord, dwCharCode);
- return sWord;
- }
- }
-
- pPDFFont->AppendChar(sWord, Word);
- }
-
- return sWord;
-}
-
-static CFX_ByteString GetWordRenderString(const CFX_ByteString & strWords)
-{
- if (strWords.GetLength() > 0)
- return PDF_EncodeString(strWords) + " Tj\n";
-
- return "";
-}
-
-static CFX_ByteString GetFontSetString(IFX_Edit_FontMap * pFontMap, FX_INT32 nFontIndex, FX_FLOAT fFontSize)
-{
- CFX_ByteTextBuf sRet;
-
- if (pFontMap)
- {
- CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
-
- if (sFontAlias.GetLength() > 0 && fFontSize > 0 )
- sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
- }
-
- return sRet.GetByteString();
-}
-
-CFX_ByteString IFX_Edit::GetEditAppearanceStream(IFX_Edit* pEdit, const CPDF_Point & ptOffset,
- const CPVT_WordRange * pRange /* = NULL*/, FX_BOOL bContinuous/* = TRUE*/, FX_WORD SubWord/* = 0*/)
-{
- CFX_ByteTextBuf sEditStream, sWords;
-
- CPDF_Point ptOld(0.0f,0.0f),ptNew(0.0f,0.0f);
- FX_INT32 nCurFontIndex = -1;
-
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- if (pRange)
- pIterator->SetAt(pRange->BeginPos);
- else
- pIterator->SetAt(0);
-
- CPVT_WordPlace oldplace;
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
-
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- if (bContinuous)
- {
- if (place.LineCmp(oldplace) != 0)
- {
- if (sWords.GetSize() > 0)
- {
- sEditStream << GetWordRenderString(sWords.GetByteString());
- sWords.Clear();
- }
-
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y);
- }
- else
- {
- CPVT_Line line;
- pIterator->GetLine(line);
- ptNew = CPDF_Point(line.ptLine.x + ptOffset.x, line.ptLine.y + ptOffset.y);
- }
-
- if (ptNew.x != ptOld.x || ptNew.y != ptOld.y)
- {
- sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y << " Td\n";
-
- ptOld = ptNew;
- }
- }
-
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- if (word.nFontIndex != nCurFontIndex)
- {
- if (sWords.GetSize() > 0)
- {
- sEditStream << GetWordRenderString(sWords.GetByteString());
- sWords.Clear();
- }
- sEditStream << GetFontSetString(pEdit->GetFontMap(),word.nFontIndex,word.fFontSize);
- nCurFontIndex = word.nFontIndex;
- }
-
- sWords << GetPDFWordString(pEdit->GetFontMap(),nCurFontIndex,word.Word,SubWord);
- }
-
- oldplace = place;
- }
- else
- {
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y);
-
- if (ptNew.x != ptOld.x || ptNew.y != ptOld.y)
- {
- sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y << " Td\n";
- ptOld = ptNew;
- }
-
- if (word.nFontIndex != nCurFontIndex)
- {
- sEditStream << GetFontSetString(pEdit->GetFontMap(),word.nFontIndex,word.fFontSize);
- nCurFontIndex = word.nFontIndex;
- }
-
- sEditStream << GetWordRenderString(GetPDFWordString(pEdit->GetFontMap(),nCurFontIndex,word.Word,SubWord));
- }
- }
- }
-
- if (sWords.GetSize() > 0)
- {
- sEditStream << GetWordRenderString(sWords.GetByteString());
- sWords.Clear();
- }
- }
-
- CFX_ByteTextBuf sAppStream;
- if (sEditStream.GetSize() > 0)
- {
- FX_INT32 nHorzScale = pEdit->GetHorzScale();
- if (nHorzScale != 100)
- {
- sAppStream << nHorzScale << " Tz\n";
- }
-
- FX_FLOAT fCharSpace = pEdit->GetCharSpace();
- if (!FX_EDIT_IsFloatZero(fCharSpace))
- {
- sAppStream << fCharSpace << " Tc\n";
- }
-
- sAppStream << sEditStream;
- }
-
- return sAppStream.GetByteString();
-}
-
-CFX_ByteString IFX_Edit::GetSelectAppearanceStream(IFX_Edit* pEdit, const CPDF_Point & ptOffset,
- const CPVT_WordRange * pRange /*= NULL*/)
-{
- CFX_ByteTextBuf sRet;
-
- if (pRange && pRange->IsExist())
- {
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- pIterator->SetAt(pRange->BeginPos);
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
-
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- CPVT_Word word;
- CPVT_Line line;
- if (pIterator->GetWord(word) && pIterator->GetLine(line))
- {
- //CPDF_Rect rcWordSel = CPDF_Rect(word.ptWord.x,line.ptLine.y + line.fLineDescent,
- // word.ptWord.x+word.fWidth,line.ptLine.y + line.fLineAscent);
-
- sRet << word.ptWord.x + ptOffset.x << " " << line.ptLine.y + line.fLineDescent
- << " " << word.fWidth << " " << line.fLineAscent - line.fLineDescent << " re\nf\n";
- }
- }
- }
- }
-
- return sRet.GetByteString();
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fxedit/fxet_stub.h"
+#include "../../include/fxedit/fx_edit.h"
+#include "../../include/fxedit/fxet_edit.h"
+
+CFX_ByteString GetPDFWordString(IFX_Edit_FontMap * pFontMap, FX_INT32 nFontIndex, FX_WORD Word, FX_WORD SubWord)
+{
+ ASSERT (pFontMap != NULL);
+
+ CFX_ByteString sWord;
+
+ if (CPDF_Font * pPDFFont = pFontMap->GetPDFFont(nFontIndex))
+ {
+ if (SubWord > 0)
+ {
+ Word = SubWord;
+ }
+ else
+ {
+ FX_DWORD dwCharCode = -1;
+
+ if (pPDFFont->IsUnicodeCompatible())
+ dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
+ else
+ dwCharCode = pFontMap->CharCodeFromUnicode(nFontIndex, Word);
+
+ if (dwCharCode > 0 )
+ {
+ pPDFFont->AppendChar(sWord, dwCharCode);
+ return sWord;
+ }
+ }
+
+ pPDFFont->AppendChar(sWord, Word);
+ }
+
+ return sWord;
+}
+
+static CFX_ByteString GetWordRenderString(const CFX_ByteString & strWords)
+{
+ if (strWords.GetLength() > 0)
+ return PDF_EncodeString(strWords) + " Tj\n";
+
+ return "";
+}
+
+static CFX_ByteString GetFontSetString(IFX_Edit_FontMap * pFontMap, FX_INT32 nFontIndex, FX_FLOAT fFontSize)
+{
+ CFX_ByteTextBuf sRet;
+
+ if (pFontMap)
+ {
+ CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
+
+ if (sFontAlias.GetLength() > 0 && fFontSize > 0 )
+ sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
+ }
+
+ return sRet.GetByteString();
+}
+
+CFX_ByteString IFX_Edit::GetEditAppearanceStream(IFX_Edit* pEdit, const CPDF_Point & ptOffset,
+ const CPVT_WordRange * pRange /* = NULL*/, FX_BOOL bContinuous/* = TRUE*/, FX_WORD SubWord/* = 0*/)
+{
+ CFX_ByteTextBuf sEditStream, sWords;
+
+ CPDF_Point ptOld(0.0f,0.0f),ptNew(0.0f,0.0f);
+ FX_INT32 nCurFontIndex = -1;
+
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ if (pRange)
+ pIterator->SetAt(pRange->BeginPos);
+ else
+ pIterator->SetAt(0);
+
+ CPVT_WordPlace oldplace;
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ if (bContinuous)
+ {
+ if (place.LineCmp(oldplace) != 0)
+ {
+ if (sWords.GetSize() > 0)
+ {
+ sEditStream << GetWordRenderString(sWords.GetByteString());
+ sWords.Clear();
+ }
+
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y);
+ }
+ else
+ {
+ CPVT_Line line;
+ pIterator->GetLine(line);
+ ptNew = CPDF_Point(line.ptLine.x + ptOffset.x, line.ptLine.y + ptOffset.y);
+ }
+
+ if (ptNew.x != ptOld.x || ptNew.y != ptOld.y)
+ {
+ sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y << " Td\n";
+
+ ptOld = ptNew;
+ }
+ }
+
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ if (word.nFontIndex != nCurFontIndex)
+ {
+ if (sWords.GetSize() > 0)
+ {
+ sEditStream << GetWordRenderString(sWords.GetByteString());
+ sWords.Clear();
+ }
+ sEditStream << GetFontSetString(pEdit->GetFontMap(),word.nFontIndex,word.fFontSize);
+ nCurFontIndex = word.nFontIndex;
+ }
+
+ sWords << GetPDFWordString(pEdit->GetFontMap(),nCurFontIndex,word.Word,SubWord);
+ }
+
+ oldplace = place;
+ }
+ else
+ {
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y);
+
+ if (ptNew.x != ptOld.x || ptNew.y != ptOld.y)
+ {
+ sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y << " Td\n";
+ ptOld = ptNew;
+ }
+
+ if (word.nFontIndex != nCurFontIndex)
+ {
+ sEditStream << GetFontSetString(pEdit->GetFontMap(),word.nFontIndex,word.fFontSize);
+ nCurFontIndex = word.nFontIndex;
+ }
+
+ sEditStream << GetWordRenderString(GetPDFWordString(pEdit->GetFontMap(),nCurFontIndex,word.Word,SubWord));
+ }
+ }
+ }
+
+ if (sWords.GetSize() > 0)
+ {
+ sEditStream << GetWordRenderString(sWords.GetByteString());
+ sWords.Clear();
+ }
+ }
+
+ CFX_ByteTextBuf sAppStream;
+ if (sEditStream.GetSize() > 0)
+ {
+ FX_INT32 nHorzScale = pEdit->GetHorzScale();
+ if (nHorzScale != 100)
+ {
+ sAppStream << nHorzScale << " Tz\n";
+ }
+
+ FX_FLOAT fCharSpace = pEdit->GetCharSpace();
+ if (!FX_EDIT_IsFloatZero(fCharSpace))
+ {
+ sAppStream << fCharSpace << " Tc\n";
+ }
+
+ sAppStream << sEditStream;
+ }
+
+ return sAppStream.GetByteString();
+}
+
+CFX_ByteString IFX_Edit::GetSelectAppearanceStream(IFX_Edit* pEdit, const CPDF_Point & ptOffset,
+ const CPVT_WordRange * pRange /*= NULL*/)
+{
+ CFX_ByteTextBuf sRet;
+
+ if (pRange && pRange->IsExist())
+ {
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ pIterator->SetAt(pRange->BeginPos);
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ CPVT_Word word;
+ CPVT_Line line;
+ if (pIterator->GetWord(word) && pIterator->GetLine(line))
+ {
+ //CPDF_Rect rcWordSel = CPDF_Rect(word.ptWord.x,line.ptLine.y + line.fLineDescent,
+ // word.ptWord.x+word.fWidth,line.ptLine.y + line.fLineAscent);
+
+ sRet << word.ptWord.x + ptOffset.x << " " << line.ptLine.y + line.fLineDescent
+ << " " << word.fWidth << " " << line.fLineAscent - line.fLineDescent << " re\nf\n";
+ }
+ }
+ }
+ }
+
+ return sRet.GetByteString();
+}
+
diff --git a/fpdfsdk/src/fxedit/fxet_edit.cpp b/fpdfsdk/src/fxedit/fxet_edit.cpp
index 5a6d4d804e..efc7acdca5 100644
--- a/fpdfsdk/src/fxedit/fxet_edit.cpp
+++ b/fpdfsdk/src/fxedit/fxet_edit.cpp
@@ -1,3610 +1,3610 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/fxedit/fxet_stub.h"
-#include "../../include/fxedit/fxet_edit.h"
-
-#define FX_EDIT_UNDO_MAXITEM 10000
-
-/* ---------------------------- CFX_Edit_Iterator ---------------------------- */
-
-CFX_Edit_Iterator::CFX_Edit_Iterator(CFX_Edit * pEdit,IPDF_VariableText_Iterator * pVTIterator) :
- m_pEdit(pEdit),
- m_pVTIterator(pVTIterator)
-{
-}
-
-CFX_Edit_Iterator::~CFX_Edit_Iterator()
-{
-}
-
-FX_BOOL CFX_Edit_Iterator::NextWord()
-{
- ASSERT(m_pVTIterator != NULL);
-
- return m_pVTIterator->NextWord();
-}
-
-FX_BOOL CFX_Edit_Iterator::NextLine()
-{
- ASSERT(m_pVTIterator != NULL);
-
- return m_pVTIterator->NextLine();
-}
-
-FX_BOOL CFX_Edit_Iterator::NextSection()
-{
- ASSERT(m_pVTIterator != NULL);
-
- return m_pVTIterator->NextSection();
-}
-
-FX_BOOL CFX_Edit_Iterator::PrevWord()
-{
- ASSERT(m_pVTIterator != NULL);
-
- return m_pVTIterator->PrevWord();
-}
-
-FX_BOOL CFX_Edit_Iterator::PrevLine()
-{
- ASSERT(m_pVTIterator != NULL);
-
- return m_pVTIterator->PrevLine();
-}
-
-FX_BOOL CFX_Edit_Iterator::PrevSection()
-{
- ASSERT(m_pVTIterator != NULL);
-
- return m_pVTIterator->PrevSection();
-}
-
-FX_BOOL CFX_Edit_Iterator::GetWord(CPVT_Word & word) const
-{
- ASSERT(m_pEdit != NULL);
- ASSERT(m_pVTIterator != NULL);
-
- if (m_pVTIterator->GetWord(word))
- {
- word.ptWord = m_pEdit->VTToEdit(word.ptWord);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit_Iterator::GetLine(CPVT_Line & line) const
-{
- ASSERT(m_pEdit != NULL);
- ASSERT(m_pVTIterator != NULL);
-
- if (m_pVTIterator->GetLine(line))
- {
- line.ptLine = m_pEdit->VTToEdit(line.ptLine);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit_Iterator::GetSection(CPVT_Section & section) const
-{
- ASSERT(m_pEdit != NULL);
- ASSERT(m_pVTIterator != NULL);
-
- if (m_pVTIterator->GetSection(section))
- {
- section.rcSection = m_pEdit->VTToEdit(section.rcSection);
- return TRUE;
- }
-
- return FALSE;
-}
-
-void CFX_Edit_Iterator::SetAt(FX_INT32 nWordIndex)
-{
- ASSERT(m_pVTIterator != NULL);
-
- m_pVTIterator->SetAt(nWordIndex);
-}
-
-void CFX_Edit_Iterator::SetAt(const CPVT_WordPlace & place)
-{
- ASSERT(m_pVTIterator != NULL);
-
- m_pVTIterator->SetAt(place);
-}
-
-const CPVT_WordPlace & CFX_Edit_Iterator::GetAt() const
-{
- ASSERT(m_pVTIterator != NULL);
-
- return m_pVTIterator->GetAt();
-}
-
-IFX_Edit* CFX_Edit_Iterator::GetEdit() const
-{
- return m_pEdit;
-}
-
-/* --------------------------- CFX_Edit_Provider ------------------------------- */
-
-CFX_Edit_Provider::CFX_Edit_Provider(IFX_Edit_FontMap * pFontMap) : m_pFontMap(pFontMap)
-{
- ASSERT(m_pFontMap != NULL);
-}
-
-CFX_Edit_Provider::~CFX_Edit_Provider()
-{
-}
-
-IFX_Edit_FontMap* CFX_Edit_Provider::GetFontMap()
-{
- return m_pFontMap;
-}
-
-FX_INT32 CFX_Edit_Provider::GetCharWidth(FX_INT32 nFontIndex, FX_WORD word, FX_INT32 nWordStyle)
-{
- if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
- {
- FX_DWORD charcode = word;
-
- if (pPDFFont->IsUnicodeCompatible())
- charcode = pPDFFont->CharCodeFromUnicode(word);
- else
- charcode = m_pFontMap->CharCodeFromUnicode(nFontIndex, word);
-
- if (charcode != -1)
- return pPDFFont->GetCharWidthF(charcode);
- }
-
- return 0;
-}
-
-FX_INT32 CFX_Edit_Provider::GetTypeAscent(FX_INT32 nFontIndex)
-{
- if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
- return pPDFFont->GetTypeAscent();
-
- return 0;
-}
-
-FX_INT32 CFX_Edit_Provider::GetTypeDescent(FX_INT32 nFontIndex)
-{
- if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
- return pPDFFont->GetTypeDescent();
-
- return 0;
-}
-
-FX_INT32 CFX_Edit_Provider::GetWordFontIndex(FX_WORD word, FX_INT32 charset, FX_INT32 nFontIndex)
-{
- return m_pFontMap->GetWordFontIndex(word,charset,nFontIndex);
-}
-
-FX_INT32 CFX_Edit_Provider::GetDefaultFontIndex()
-{
- return 0;
-}
-
-FX_BOOL CFX_Edit_Provider::IsLatinWord(FX_WORD word)
-{
- return FX_EDIT_ISLATINWORD(word);
-}
-
-/* --------------------------------- CFX_Edit_Refresh --------------------------------- */
-
-CFX_Edit_Refresh::CFX_Edit_Refresh()
-{
-}
-
-CFX_Edit_Refresh::~CFX_Edit_Refresh()
-{
-}
-
-void CFX_Edit_Refresh::BeginRefresh()
-{
- m_RefreshRects.Empty();
- m_OldLineRects = m_NewLineRects;
-}
-
-void CFX_Edit_Refresh::Push(const CPVT_WordRange & linerange,const CPDF_Rect & rect)
-{
- m_NewLineRects.Add(linerange,rect);
-}
-
-void CFX_Edit_Refresh::NoAnalyse()
-{
- {
- for (FX_INT32 i = 0, sz = m_OldLineRects.GetSize(); i < sz; i++)
- if (CFX_Edit_LineRect * pOldRect = m_OldLineRects.GetAt(i))
- m_RefreshRects.Add(pOldRect->m_rcLine);
- }
-
- {
- for (FX_INT32 i = 0, sz = m_NewLineRects.GetSize(); i < sz; i++)
- if (CFX_Edit_LineRect * pNewRect = m_NewLineRects.GetAt(i))
- m_RefreshRects.Add(pNewRect->m_rcLine);
- }
-}
-
-void CFX_Edit_Refresh::Analyse(FX_INT32 nAlignment)
-{
- FX_BOOL bLineTopChanged = FALSE;
- CPDF_Rect rcResult;
- FX_FLOAT fWidthDiff;
-
- FX_INT32 szMax = FX_EDIT_MAX(m_OldLineRects.GetSize(),m_NewLineRects.GetSize());
- FX_INT32 i = 0;
-
- while (i < szMax)
- {
- CFX_Edit_LineRect * pOldRect = m_OldLineRects.GetAt(i);
- CFX_Edit_LineRect * pNewRect = m_NewLineRects.GetAt(i);
-
- if (pOldRect)
- {
- if (pNewRect)
- {
- if (bLineTopChanged)
- {
- rcResult = pOldRect->m_rcLine;
- rcResult.Union(pNewRect->m_rcLine);
- m_RefreshRects.Add(rcResult);
- }
- else
- {
- if (*pNewRect != *pOldRect)
- {
- if (!pNewRect->IsSameTop(*pOldRect) || !pNewRect->IsSameHeight(*pOldRect))
- {
- bLineTopChanged = TRUE;
- continue;
- }
-
- if (nAlignment == 0)
- {
- if (pNewRect->m_wrLine.BeginPos != pOldRect->m_wrLine.BeginPos)
- {
- rcResult = pOldRect->m_rcLine;
- rcResult.Union(pNewRect->m_rcLine);
- m_RefreshRects.Add(rcResult);
- }
- else
- {
- if (!pNewRect->IsSameLeft(*pOldRect))
- {
- rcResult = pOldRect->m_rcLine;
- rcResult.Union(pNewRect->m_rcLine);
- }
- else
- {
- fWidthDiff = pNewRect->m_rcLine.Width() - pOldRect->m_rcLine.Width();
- rcResult = pNewRect->m_rcLine;
- if (fWidthDiff > 0.0f)
- rcResult.left = rcResult.right - fWidthDiff;
- else
- {
- rcResult.left = rcResult.right;
- rcResult.right += (-fWidthDiff);
- }
- }
- m_RefreshRects.Add(rcResult);
- }
- }
- else
- {
- rcResult = pOldRect->m_rcLine;
- rcResult.Union(pNewRect->m_rcLine);
- m_RefreshRects.Add(rcResult);
- }
- }
- else
- {
- //don't need to do anything
- }
- }
- }
- else
- {
- m_RefreshRects.Add(pOldRect->m_rcLine);
- }
- }
- else
- {
- if (pNewRect)
- {
- m_RefreshRects.Add(pNewRect->m_rcLine);
- }
- else
- {
- //error
- }
- }
- i++;
- }
-}
-
-void CFX_Edit_Refresh::AddRefresh(const CPDF_Rect & rect)
-{
- m_RefreshRects.Add(rect);
-}
-
-const CFX_Edit_RectArray * CFX_Edit_Refresh::GetRefreshRects() const
-{
- return &m_RefreshRects;
-}
-
-void CFX_Edit_Refresh::EndRefresh()
-{
- m_RefreshRects.Empty();
-}
-
-/* ------------------------------------- CFX_Edit_Undo ------------------------------------- */
-
-CFX_Edit_Undo::CFX_Edit_Undo(FX_INT32 nBufsize) : m_nCurUndoPos(0),
- m_nBufSize(nBufsize),
- m_bModified(FALSE),
- m_bVirgin(TRUE),
- m_bWorking(FALSE)
-{
-}
-
-CFX_Edit_Undo::~CFX_Edit_Undo()
-{
- Reset();
-}
-
-FX_BOOL CFX_Edit_Undo::CanUndo() const
-{
- return m_nCurUndoPos > 0;
-}
-
-void CFX_Edit_Undo::Undo()
-{
- m_bWorking = TRUE;
-
- if (m_nCurUndoPos > 0)
- {
- IFX_Edit_UndoItem * pItem = m_UndoItemStack.GetAt(m_nCurUndoPos-1);
- ASSERT(pItem != NULL);
-
- pItem->Undo();
-
- m_nCurUndoPos--;
- m_bModified = (m_nCurUndoPos != 0);
- }
-
- m_bWorking = FALSE;
-}
-
-FX_BOOL CFX_Edit_Undo::CanRedo() const
-{
- return m_nCurUndoPos < m_UndoItemStack.GetSize();
-}
-
-void CFX_Edit_Undo::Redo()
-{
- m_bWorking = TRUE;
-
- FX_INT32 nStackSize = m_UndoItemStack.GetSize();
-
- if (m_nCurUndoPos < nStackSize)
- {
- IFX_Edit_UndoItem * pItem = m_UndoItemStack.GetAt(m_nCurUndoPos);
- ASSERT(pItem != NULL);
-
- pItem->Redo();
-
- m_nCurUndoPos++;
- m_bModified = (m_nCurUndoPos != 0);
- }
-
- m_bWorking = FALSE;
-}
-
-FX_BOOL CFX_Edit_Undo::IsWorking() const
-{
- return m_bWorking;
-}
-
-void CFX_Edit_Undo::AddItem(IFX_Edit_UndoItem* pItem)
-{
- ASSERT(!m_bWorking);
- ASSERT(pItem != NULL);
- ASSERT(m_nBufSize > 1);
-
- if (m_nCurUndoPos < m_UndoItemStack.GetSize())
- RemoveTails();
-
- if (m_UndoItemStack.GetSize() >= m_nBufSize)
- {
- RemoveHeads();
- m_bVirgin = FALSE;
- }
-
- m_UndoItemStack.Add(pItem);
- m_nCurUndoPos = m_UndoItemStack.GetSize();
-
- m_bModified = (m_nCurUndoPos != 0);
-}
-
-FX_BOOL CFX_Edit_Undo::IsModified() const
-{
- if (m_bVirgin)
- return m_bModified;
- else
- return TRUE;
-}
-
-IFX_Edit_UndoItem* CFX_Edit_Undo::GetItem(FX_INT32 nIndex)
-{
- if (nIndex>=0 && nIndex < m_UndoItemStack.GetSize())
- return m_UndoItemStack.GetAt(nIndex);
-
- return NULL;
-}
-
-void CFX_Edit_Undo::RemoveHeads()
-{
- ASSERT(m_UndoItemStack.GetSize() > 1);
-
- IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(0);
- ASSERT(pItem != NULL);
-
- pItem->Release();
- m_UndoItemStack.RemoveAt(0);
-}
-
-void CFX_Edit_Undo::RemoveTails()
-{
- for (FX_INT32 i = m_UndoItemStack.GetSize()-1; i >= m_nCurUndoPos; i--)
- {
- IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(i);
- ASSERT(pItem != NULL);
-
- pItem->Release();
- m_UndoItemStack.RemoveAt(i);
- }
-}
-
-void CFX_Edit_Undo::Reset()
-{
- for (FX_INT32 i=0, sz=m_UndoItemStack.GetSize(); i < sz; i++)
- {
- IFX_Edit_UndoItem * pItem = m_UndoItemStack.GetAt(i);
- ASSERT(pItem != NULL);
-
- pItem->Release();
- }
- m_nCurUndoPos = 0;
- m_UndoItemStack.RemoveAll();
-}
-
-/* -------------------------------- CFX_Edit_GroupUndoItem -------------------------------- */
-
-CFX_Edit_GroupUndoItem::CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle) : m_sTitle(sTitle)
-{
-}
-
-CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem()
-{
- for (int i=0,sz=m_Items.GetSize(); i<sz; i++)
- {
- CFX_Edit_UndoItem* pUndoItem = m_Items[i];
- ASSERT(pUndoItem != NULL);
-
- pUndoItem->Release();
- }
-
- m_Items.RemoveAll();
-}
-
-void CFX_Edit_GroupUndoItem::AddUndoItem(CFX_Edit_UndoItem* pUndoItem)
-{
- ASSERT(pUndoItem != NULL);
-
- pUndoItem->SetFirst(FALSE);
- pUndoItem->SetLast(FALSE);
-
- m_Items.Add(pUndoItem);
-
- if (m_sTitle.IsEmpty())
- m_sTitle = pUndoItem->GetUndoTitle();
-}
-
-void CFX_Edit_GroupUndoItem::UpdateItems()
-{
- if (m_Items.GetSize() > 0)
- {
- CFX_Edit_UndoItem* pFirstItem = m_Items[0];
- ASSERT(pFirstItem != NULL);
- pFirstItem->SetFirst(TRUE);
-
- CFX_Edit_UndoItem* pLastItem = m_Items[m_Items.GetSize() - 1];
- ASSERT(pLastItem != NULL);
- pLastItem->SetLast(TRUE);
- }
-}
-
-void CFX_Edit_GroupUndoItem::Undo()
-{
- for (int i=m_Items.GetSize()-1; i>=0; i--)
- {
- CFX_Edit_UndoItem* pUndoItem = m_Items[i];
- ASSERT(pUndoItem != NULL);
-
- pUndoItem->Undo();
- }
-}
-
-void CFX_Edit_GroupUndoItem::Redo()
-{
- for (int i=0,sz=m_Items.GetSize(); i<sz; i++)
- {
- CFX_Edit_UndoItem* pUndoItem = m_Items[i];
- ASSERT(pUndoItem != NULL);
-
- pUndoItem->Redo();
- }
-}
-
-CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle()
-{
- return m_sTitle;
-}
-
-void CFX_Edit_GroupUndoItem::Release()
-{
- delete this;
-}
-
-/* ------------------------------------- CFX_Edit_UndoItem derived classes ------------------------------------- */
-
-CFXEU_InsertWord::CFXEU_InsertWord(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
- FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps)
- : m_pEdit(pEdit), m_wpOld(wpOldPlace), m_wpNew(wpNewPlace), m_Word(word), m_nCharset(charset), m_WordProps()
-{
- if (pWordProps)
- m_WordProps = *pWordProps;
-}
-
-CFXEU_InsertWord::~CFXEU_InsertWord()
-{
-}
-
-void CFXEU_InsertWord::Redo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpOld);
- m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,TRUE);
- }
-}
-
-void CFXEU_InsertWord::Undo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpNew);
- m_pEdit->Backspace(FALSE,TRUE);
- }
-}
-
-/* -------------------------------------------------------------------------- */
-
-CFXEU_InsertReturn::CFXEU_InsertReturn(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
- const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps) :
- m_pEdit(pEdit),
- m_wpOld(wpOldPlace),
- m_wpNew(wpNewPlace),
- m_SecProps(),
- m_WordProps()
-{
- if (pSecProps)
- m_SecProps = *pSecProps;
- if (pWordProps)
- m_WordProps = *pWordProps;
-}
-
-CFXEU_InsertReturn::~CFXEU_InsertReturn()
-{
-}
-
-void CFXEU_InsertReturn::Redo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpOld);
- m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,TRUE);
- }
-}
-
-void CFXEU_InsertReturn::Undo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpNew);
- m_pEdit->Backspace(FALSE,TRUE);
- }
-}
-
-/* -------------------------------------------------------------------------- */
-//CFXEU_Backspace
-
-CFXEU_Backspace::CFXEU_Backspace(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
- FX_WORD word, FX_INT32 charset,
- const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps) :
- m_pEdit(pEdit),
- m_wpOld(wpOldPlace),
- m_wpNew(wpNewPlace),
- m_Word(word),
- m_nCharset(charset),
- m_SecProps(SecProps),
- m_WordProps(WordProps)
-{
-}
-
-CFXEU_Backspace::~CFXEU_Backspace()
-{
-}
-
-void CFXEU_Backspace::Redo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpOld);
- m_pEdit->Backspace(FALSE,TRUE);
- }
-}
-
-void CFXEU_Backspace::Undo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpNew);
- if (m_wpNew.SecCmp(m_wpOld) != 0)
- {
- m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,TRUE);
- }
- else
- {
- m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,TRUE);
- }
- }
-}
-
-/* -------------------------------------------------------------------------- */
-//CFXEU_Delete
-
-CFXEU_Delete::CFXEU_Delete(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
- FX_WORD word, FX_INT32 charset,
- const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps, FX_BOOL bSecEnd) :
- m_pEdit(pEdit),
- m_wpOld(wpOldPlace),
- m_wpNew(wpNewPlace),
- m_Word(word),
- m_nCharset(charset),
- m_SecProps(SecProps),
- m_WordProps(WordProps),
- m_bSecEnd(bSecEnd)
-{
-}
-
-CFXEU_Delete::~CFXEU_Delete()
-{
-}
-
-void CFXEU_Delete::Redo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpOld);
- m_pEdit->Delete(FALSE,TRUE);
- }
-}
-
-void CFXEU_Delete::Undo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpNew);
- if (m_bSecEnd)
- {
- m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,TRUE);
- }
- else
- {
- m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,TRUE);
- }
- }
-}
-
-/* -------------------------------------------------------------------------- */
-//CFXEU_Clear
-
-CFXEU_Clear::CFXEU_Clear(CFX_Edit * pEdit, const CPVT_WordRange & wrSel, const CFX_WideString & swText) :
- m_pEdit(pEdit),
- m_wrSel(wrSel),
- m_swText(swText)
-{
-}
-
-CFXEU_Clear::~CFXEU_Clear()
-{
-}
-
-void CFXEU_Clear::Redo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos);
- m_pEdit->Clear(FALSE,TRUE);
- }
-}
-
-void CFXEU_Clear::Undo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wrSel.BeginPos);
- m_pEdit->InsertText(m_swText, DEFAULT_CHARSET, NULL,NULL,FALSE,TRUE);
- m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos);
- }
-}
-
-/* -------------------------------------------------------------------------- */
-//CFXEU_ClearRich
-
-CFXEU_ClearRich::CFXEU_ClearRich(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
- const CPVT_WordRange & wrSel, FX_WORD word, FX_INT32 charset,
- const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps) :
- m_pEdit(pEdit),
- m_wpOld(wpOldPlace),
- m_wpNew(wpNewPlace),
- m_wrSel(wrSel),
- m_Word(word),
- m_nCharset(charset),
- m_SecProps(SecProps),
- m_WordProps(WordProps)
-{
-}
-
-CFXEU_ClearRich::~CFXEU_ClearRich()
-{
-}
-
-void CFXEU_ClearRich::Redo()
-{
- if (m_pEdit && IsLast())
- {
- m_pEdit->SelectNone();
- m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos);
- m_pEdit->Clear(FALSE,TRUE);
- }
-}
-
-void CFXEU_ClearRich::Undo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpOld);
- if (m_wpNew.SecCmp(m_wpOld) != 0)
- {
- m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,FALSE);
- }
- else
- {
- m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,FALSE);
- }
-
- if (IsFirst())
- {
- m_pEdit->PaintInsertText(m_wrSel.BeginPos,m_wrSel.EndPos);
- m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos);
- }
- }
-}
-/* -------------------------------------------------------------------------- */
-//CFXEU_InsertText
-
-CFXEU_InsertText::CFXEU_InsertText(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
- const CFX_WideString & swText, FX_INT32 charset,
- const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps) :
- m_pEdit(pEdit),
- m_wpOld(wpOldPlace),
- m_wpNew(wpNewPlace),
- m_swText(swText),
- m_nCharset(charset),
- m_SecProps(),
- m_WordProps()
-{
- if (pSecProps)
- m_SecProps = *pSecProps;
- if (pWordProps)
- m_WordProps = *pWordProps;
-}
-
-CFXEU_InsertText::~CFXEU_InsertText()
-{
-}
-
-void CFXEU_InsertText::Redo()
-{
- if (m_pEdit && IsLast())
- {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpOld);
- m_pEdit->InsertText(m_swText, m_nCharset,&m_SecProps, &m_WordProps,FALSE,TRUE);
- }
-}
-
-void CFXEU_InsertText::Undo()
-{
- if (m_pEdit)
- {
- m_pEdit->SelectNone();
- m_pEdit->SetSel(m_wpOld,m_wpNew);
- m_pEdit->Clear(FALSE,TRUE);
- }
-}
-
-/* -------------------------------------------------------------------------- */
-
-CFXEU_SetSecProps::CFXEU_SetSecProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep,
- const CPVT_SecProps & oldsecprops, const CPVT_WordProps & oldwordprops,
- const CPVT_SecProps & newsecprops, const CPVT_WordProps & newwordprops, const CPVT_WordRange & range)
- : m_pEdit(pEdit),
- m_wpPlace(place),
- m_eProps(ep),
- m_OldSecProps(oldsecprops),
- m_NewSecProps(newsecprops),
- m_OldWordProps(oldwordprops),
- m_NewWordProps(newwordprops),
- m_wrPlace(range)
-{
-}
-
-CFXEU_SetSecProps::~CFXEU_SetSecProps()
-{
-}
-
-void CFXEU_SetSecProps::Redo()
-{
- if (m_pEdit)
- {
- m_pEdit->SetSecProps(m_eProps,m_wpPlace,&m_NewSecProps,&m_NewWordProps,m_wrPlace,FALSE);
- if (IsLast())
- {
- m_pEdit->SelectNone();
- m_pEdit->PaintSetProps(m_eProps,m_wrPlace);
- m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos);
- }
- }
-}
-
-void CFXEU_SetSecProps::Undo()
-{
- if (m_pEdit)
- {
- m_pEdit->SetSecProps(m_eProps,m_wpPlace,&m_OldSecProps,&m_OldWordProps,m_wrPlace,FALSE);
- if (IsFirst())
- {
- m_pEdit->SelectNone();
- m_pEdit->PaintSetProps(m_eProps,m_wrPlace);
- m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos);
- }
- }
-}
-
-/* -------------------------------------------------------------------------- */
-
-CFXEU_SetWordProps::CFXEU_SetWordProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep,
- const CPVT_WordProps & oldprops, const CPVT_WordProps & newprops, const CPVT_WordRange & range)
- : m_pEdit(pEdit),
- m_wpPlace(place),
- m_eProps(ep),
- m_OldWordProps(oldprops),
- m_NewWordProps(newprops),
- m_wrPlace(range)
-{
-}
-
-CFXEU_SetWordProps::~CFXEU_SetWordProps()
-{
-}
-
-void CFXEU_SetWordProps::Redo()
-{
- if (m_pEdit)
- {
- m_pEdit->SetWordProps(m_eProps,m_wpPlace,&m_NewWordProps,m_wrPlace,FALSE);
- if (IsLast())
- {
- m_pEdit->SelectNone();
- m_pEdit->PaintSetProps(m_eProps,m_wrPlace);
- m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos);
- }
- }
-}
-
-void CFXEU_SetWordProps::Undo()
-{
- if (m_pEdit)
- {
- m_pEdit->SetWordProps(m_eProps,m_wpPlace,&m_OldWordProps,m_wrPlace,FALSE);
- if (IsFirst())
- {
- m_pEdit->SelectNone();
- m_pEdit->PaintSetProps(m_eProps,m_wrPlace);
- m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos);
- }
- }
-}
-
-/* ------------------------------------- CFX_Edit ------------------------------------- */
-
-CFX_Edit::CFX_Edit(IPDF_VariableText * pVT) :
- m_pVT(pVT),
- m_pNotify(NULL),
- m_pOprNotify(NULL),
- m_wpCaret(-1,-1,-1),
- m_wpOldCaret(-1,-1,-1),
- m_ptScrollPos(0,0),
- m_ptRefreshScrollPos(0,0),
- m_bEnableScroll(FALSE),
- m_bEnableOverflow(FALSE),
- m_pVTProvide(NULL),
- m_pIterator(NULL),
- m_SelState(),
- m_ptCaret(0.0f,0.0f),
- m_Undo(FX_EDIT_UNDO_MAXITEM),
- m_nAlignment(0),
- m_bNotifyFlag(FALSE),
- m_bEnableRefresh(TRUE),
- m_rcOldContent(0.0f,0.0f,0.0f,0.0f),
- m_bEnableUndo(TRUE),
- m_bNotify(TRUE),
- m_bOprNotify(FALSE),
- m_pGroupUndoItem(NULL)
-{
- ASSERT(pVT != NULL);
-}
-
-CFX_Edit::~CFX_Edit()
-{
- if (m_pVTProvide)
- {
- delete m_pVTProvide;
- m_pVTProvide = NULL;
- }
-
- if (m_pIterator)
- {
- delete m_pIterator;
- m_pIterator = NULL;
- }
-
- ASSERT(m_pGroupUndoItem == NULL);
-}
-
-// public methods
-
-void CFX_Edit::Initialize()
-{
- m_pVT->Initialize();
- SetCaret(m_pVT->GetBeginWordPlace());
- SetCaretOrigin();
-}
-
-void CFX_Edit::SetFontMap(IFX_Edit_FontMap * pFontMap)
-{
- if (m_pVTProvide)
- delete m_pVTProvide;
-
- m_pVT->SetProvider(m_pVTProvide = new CFX_Edit_Provider(pFontMap));
-}
-
-void CFX_Edit::SetVTProvider(IPDF_VariableText_Provider* pProvider)
-{
- m_pVT->SetProvider(pProvider);
-}
-
-void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify)
-{
- m_pNotify = pNotify;
-}
-
-void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify)
-{
- m_pOprNotify = pOprNotify;
-}
-
-IFX_Edit_Iterator * CFX_Edit::GetIterator()
-{
- if (!m_pIterator)
- m_pIterator = new CFX_Edit_Iterator(this,m_pVT->GetIterator());
-
- return m_pIterator;
-}
-
-IPDF_VariableText * CFX_Edit::GetVariableText()
-{
- return m_pVT;
-}
-
-IFX_Edit_FontMap* CFX_Edit::GetFontMap()
-{
- if (m_pVTProvide)
- return m_pVTProvide->GetFontMap();
-
- return NULL;
-}
-
-void CFX_Edit::SetPlateRect(const CPDF_Rect & rect, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetPlateRect(rect);
- m_ptScrollPos = CPDF_Point(rect.left,rect.top);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetAlignmentH(FX_INT32 nFormat/* =0 */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetAlignment(nFormat);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetAlignmentV(FX_INT32 nFormat/* =0 */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_nAlignment = nFormat;
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetPasswordChar(FX_WORD wSubWord/* ='*' */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetPasswordChar(wSubWord);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetLimitChar(FX_INT32 nLimitChar/* =0 */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetLimitChar(nLimitChar);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetCharArray(FX_INT32 nCharArray/* =0 */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetCharArray(nCharArray);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetCharSpace(FX_FLOAT fCharSpace/* =0.0f */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetCharSpace(fCharSpace);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetHorzScale(FX_INT32 nHorzScale/* =100 */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetHorzScale(nHorzScale);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetMultiLine(FX_BOOL bMultiLine/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetMultiLine(bMultiLine);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetAutoReturn(FX_BOOL bAuto/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetAutoReturn(bAuto);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetLineLeading(FX_FLOAT fLineLeading/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetLineLeading(fLineLeading);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetAutoFontSize(FX_BOOL bAuto/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetAutoFontSize(bAuto);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetFontSize(FX_FLOAT fFontSize, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetFontSize(fFontSize);
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetAutoScroll(FX_BOOL bAuto/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_bEnableScroll = bAuto;
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetTextOverflow(FX_BOOL bAllowed /*= FALSE*/, FX_BOOL bPaint/* = TRUE*/)
-{
- m_bEnableOverflow = bAllowed;
- if (bPaint) Paint();
-}
-
-void CFX_Edit::SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar)
-{
- if (m_pVT->IsValid())
- {
- if (nStartChar == 0 && nEndChar < 0)
- {
- SelectAll();
- }
- else if (nStartChar < 0)
- {
- this->SelectNone();
- }
- else
- {
- if (nStartChar < nEndChar)
- {
- SetSel(m_pVT->WordIndexToWordPlace(nStartChar),m_pVT->WordIndexToWordPlace(nEndChar));
- }
- else
- {
- SetSel(m_pVT->WordIndexToWordPlace(nEndChar),m_pVT->WordIndexToWordPlace(nStartChar));
- }
- }
- }
-}
-
-void CFX_Edit::SetSel(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)
-{
- if (m_pVT->IsValid())
- {
- SelectNone();
-
- m_SelState.Set(begin,end);
-
- SetCaret(m_SelState.EndPos);
-
- if (m_SelState.IsExist())
- {
- ScrollToCaret();
- CPVT_WordRange wr(m_SelState.BeginPos,m_SelState.EndPos);
- Refresh(RP_OPTIONAL,&wr);
- SetCaretInfo();
- }
- else
- {
- ScrollToCaret();
- SetCaretInfo();
- }
- }
-}
-
-void CFX_Edit::GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
-{
- nStartChar = -1;
- nEndChar = -1;
-
- if (m_pVT->IsValid())
- {
- if (m_SelState.IsExist())
- {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)<0)
- {
- nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
- nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
- }
- else
- {
- nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
- nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
- }
- }
- else
- {
- nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
- nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
- }
- }
-}
-
-FX_INT32 CFX_Edit::GetCaret() const
-{
- if (m_pVT->IsValid())
- return m_pVT->WordPlaceToWordIndex(m_wpCaret);
-
- return -1;
-}
-
-CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const
-{
- return m_wpCaret;
-}
-
-CFX_WideString CFX_Edit::GetText() const
-{
- CFX_WideString swRet;
-
- if (m_pVT->IsValid())
- {
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- FX_BOOL bRich = m_pVT->IsRichText();
-
- pIterator->SetAt(0);
-
- CPVT_Word wordinfo;
- CPVT_WordPlace oldplace = pIterator->GetAt();
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
-
- if (pIterator->GetWord(wordinfo))
- {
- if (bRich)
- {
- swRet += wordinfo.Word;
- }
- else
- {
- swRet += wordinfo.Word;
- }
- }
-
- if (oldplace.SecCmp(place) != 0)
- {
- swRet += 0x0D;
- swRet += 0x0A;
- }
-
- oldplace = place;
- }
- }
- }
-
- return swRet;
-}
-
-CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange & range) const
-{
- CFX_WideString swRet;
-
- if (m_pVT->IsValid())
- {
- FX_BOOL bRich = m_pVT->IsRichText();
-
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- CPVT_WordRange wrTemp = range;
- m_pVT->UpdateWordPlace(wrTemp.BeginPos);
- m_pVT->UpdateWordPlace(wrTemp.EndPos);
- pIterator->SetAt(wrTemp.BeginPos);
-
- CPVT_Word wordinfo;
- CPVT_WordPlace oldplace = wrTemp.BeginPos;
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (place.WordCmp(wrTemp.EndPos) > 0)break;
-
- if (pIterator->GetWord(wordinfo))
- {
- if (bRich)
- {
- swRet += wordinfo.Word;
- }
- else
- {
- swRet += wordinfo.Word;
- }
- }
-
- if (oldplace.SecCmp(place) != 0)
- {
- swRet += 0x0D;
- swRet += 0x0A;
- }
-
- oldplace = place;
- }
- }
- }
-
- return swRet;
-}
-
-CFX_WideString CFX_Edit::GetSelText() const
-{
- return GetRangeText(m_SelState.ConvertToWordRange());
-}
-
-FX_INT32 CFX_Edit::GetTotalWords() const
-{
- return m_pVT->GetTotalWords();
-}
-
-FX_INT32 CFX_Edit::GetTotalLines() const
-{
- FX_INT32 nLines = 0;
-
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- pIterator->SetAt(0);
- while (pIterator->NextLine())
- nLines++;
- }
-
- return nLines+1;
-}
-
-CPVT_WordRange CFX_Edit::GetSelectWordRange() const
-{
- return m_SelState.ConvertToWordRange();
-}
-
-CPVT_WordRange CFX_Edit::CombineWordRange(const CPVT_WordRange & wr1, const CPVT_WordRange & wr2)
-{
- CPVT_WordRange wrRet;
-
- if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0)
- {
- wrRet.BeginPos = wr1.BeginPos;
- }
- else
- {
- wrRet.BeginPos = wr2.BeginPos;
- }
-
- if (wr1.EndPos.WordCmp(wr2.EndPos) < 0)
- {
- wrRet.EndPos = wr2.EndPos;
- }
- else
- {
- wrRet.EndPos = wr1.EndPos;
- }
-
- return wrRet;
-}
-
-FX_BOOL CFX_Edit::IsRichText() const
-{
- return m_pVT->IsRichText();
-}
-
-void CFX_Edit::SetRichText(FX_BOOL bRichText/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pVT->SetRichText(bRichText);
- if (bPaint) Paint();
-}
-
-FX_BOOL CFX_Edit::SetRichFontIndex(FX_INT32 nFontIndex)
-{
- CPVT_WordProps WordProps;
- WordProps.nFontIndex = nFontIndex;
- return SetRichTextProps(EP_FONTINDEX,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichFontSize(FX_FLOAT fFontSize)
-{
- CPVT_WordProps WordProps;
- WordProps.fFontSize = fFontSize;
- return SetRichTextProps(EP_FONTSIZE,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichTextColor(FX_COLORREF dwColor)
-{
- CPVT_WordProps WordProps;
- WordProps.dwWordColor = dwColor;
- return SetRichTextProps(EP_WORDCOLOR,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichTextScript(FX_INT32 nScriptType)
-{
- CPVT_WordProps WordProps;
- WordProps.nScriptType = nScriptType;
- return SetRichTextProps(EP_SCRIPTTYPE,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichTextBold(FX_BOOL bBold)
-{
- CPVT_WordProps WordProps;
- if (bBold)
- WordProps.nWordStyle |= PVTWORD_STYLE_BOLD;
- return SetRichTextProps(EP_BOLD,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichTextItalic(FX_BOOL bItalic)
-{
- CPVT_WordProps WordProps;
- if (bItalic)
- WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC;
- return SetRichTextProps(EP_ITALIC,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichTextUnderline(FX_BOOL bUnderline)
-{
- CPVT_WordProps WordProps;
- if (bUnderline)
- WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE;
- return SetRichTextProps(EP_UNDERLINE,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichTextCrossout(FX_BOOL bCrossout)
-{
- CPVT_WordProps WordProps;
- if (bCrossout)
- WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT;
- return SetRichTextProps(EP_CROSSOUT,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichTextCharSpace(FX_FLOAT fCharSpace)
-{
- CPVT_WordProps WordProps;
- WordProps.fCharSpace = fCharSpace;
- return SetRichTextProps(EP_CHARSPACE,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichTextHorzScale(FX_INT32 nHorzScale /*= 100*/)
-{
- CPVT_WordProps WordProps;
- WordProps.nHorzScale = nHorzScale;
- return SetRichTextProps(EP_HORZSCALE,NULL,&WordProps);
-}
-
-FX_BOOL CFX_Edit::SetRichTextLineLeading(FX_FLOAT fLineLeading)
-{
- CPVT_SecProps SecProps;
- SecProps.fLineLeading = fLineLeading;
- return SetRichTextProps(EP_LINELEADING,&SecProps,NULL);
-}
-
-FX_BOOL CFX_Edit::SetRichTextLineIndent(FX_FLOAT fLineIndent)
-{
- CPVT_SecProps SecProps;
- SecProps.fLineIndent = fLineIndent;
- return SetRichTextProps(EP_LINEINDENT,&SecProps,NULL);
-}
-
-FX_BOOL CFX_Edit::SetRichTextAlignment(FX_INT32 nAlignment)
-{
- CPVT_SecProps SecProps;
- SecProps.nAlignment = nAlignment;
- return SetRichTextProps(EP_ALIGNMENT,&SecProps,NULL);
-}
-
-FX_BOOL CFX_Edit::SetRichTextProps(EDIT_PROPS_E eProps, const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps)
-{
- FX_BOOL bSet = FALSE;
- FX_BOOL bSet1,bSet2;
- if (m_pVT->IsValid() && m_pVT->IsRichText())
- {
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange();
-
- m_pVT->UpdateWordPlace(wrTemp.BeginPos);
- m_pVT->UpdateWordPlace(wrTemp.EndPos);
- pIterator->SetAt(wrTemp.BeginPos);
-
- BeginGroupUndo(L"");;
-
- bSet = SetSecProps(eProps,wrTemp.BeginPos,pSecProps,pWordProps,wrTemp,TRUE);
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (place.WordCmp(wrTemp.EndPos) > 0) break;
- bSet1 = SetSecProps(eProps,place,pSecProps,pWordProps,wrTemp,TRUE);
- bSet2 = SetWordProps(eProps,place,pWordProps,wrTemp,TRUE);
-
- if (!bSet)
- bSet = (bSet1 || bSet2);
- }
-
- EndGroupUndo();
-
- if (bSet)
- {
- PaintSetProps(eProps,wrTemp);
- }
- }
- }
-
- return bSet;
-}
-
-void CFX_Edit::PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange & wr)
-{
- switch(eProps)
- {
- case EP_LINELEADING:
- case EP_LINEINDENT:
- case EP_ALIGNMENT:
- RearrangePart(wr);
- ScrollToCaret();
- Refresh(RP_ANALYSE);
- SetCaretOrigin();
- SetCaretInfo();
- break;
- case EP_WORDCOLOR:
- case EP_UNDERLINE:
- case EP_CROSSOUT:
- Refresh(RP_OPTIONAL,&wr);
- break;
- case EP_FONTINDEX:
- case EP_FONTSIZE:
- case EP_SCRIPTTYPE:
- case EP_CHARSPACE:
- case EP_HORZSCALE:
- case EP_BOLD:
- case EP_ITALIC:
- RearrangePart(wr);
- ScrollToCaret();
-
- CPVT_WordRange wrRefresh(m_pVT->GetSectionBeginPlace(wr.BeginPos),
- m_pVT->GetSectionEndPlace(wr.EndPos));
- Refresh(RP_ANALYSE,&wrRefresh);
-
- SetCaretOrigin();
- SetCaretInfo();
- break;
- }
-}
-
-FX_BOOL CFX_Edit::SetSecProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place,
- const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps,
- const CPVT_WordRange & wr, FX_BOOL bAddUndo)
-{
- if (m_pVT->IsValid() && m_pVT->IsRichText())
- {
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- FX_BOOL bSet = FALSE;
- CPVT_Section secinfo;
- CPVT_Section OldSecinfo;
-
- CPVT_WordPlace oldplace = pIterator->GetAt();
-
- if (eProps == EP_LINELEADING || eProps == EP_LINEINDENT || eProps == EP_ALIGNMENT)
- {
- if (pSecProps)
- {
- pIterator->SetAt(place);
- if (pIterator->GetSection(secinfo))
- {
- if (bAddUndo) OldSecinfo = secinfo;
-
- switch(eProps)
- {
- case EP_LINELEADING:
- if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineLeading,pSecProps->fLineLeading))
- {
- secinfo.SecProps.fLineLeading = pSecProps->fLineLeading;
- bSet = TRUE;
- }
- break;
- case EP_LINEINDENT:
- if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineIndent,pSecProps->fLineIndent))
- {
- secinfo.SecProps.fLineIndent = pSecProps->fLineIndent;
- bSet = TRUE;
- }
- break;
- case EP_ALIGNMENT:
- if (secinfo.SecProps.nAlignment != pSecProps->nAlignment)
- {
- secinfo.SecProps.nAlignment = pSecProps->nAlignment;
- bSet = TRUE;
- }
- break;
- default:
- break;
- }
- }
- }
- }
- else
- {
- if (pWordProps && place == m_pVT->GetSectionBeginPlace(place))
- {
- pIterator->SetAt(place);
- if (pIterator->GetSection(secinfo))
- {
- if (bAddUndo) OldSecinfo = secinfo;
-
- switch(eProps)
- {
- case EP_FONTINDEX:
- if (secinfo.WordProps.nFontIndex != pWordProps->nFontIndex)
- {
- secinfo.WordProps.nFontIndex = pWordProps->nFontIndex;
- bSet = TRUE;
- }
- break;
- case EP_FONTSIZE:
- if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fFontSize,pWordProps->fFontSize))
- {
- secinfo.WordProps.fFontSize = pWordProps->fFontSize;
- bSet = TRUE;
- }
- break;
- case EP_WORDCOLOR:
- if (secinfo.WordProps.dwWordColor != pWordProps->dwWordColor)
- {
- secinfo.WordProps.dwWordColor = pWordProps->dwWordColor;
- bSet = TRUE;
- }
- break;
- case EP_SCRIPTTYPE:
- if (secinfo.WordProps.nScriptType != pWordProps->nScriptType)
- {
- secinfo.WordProps.nScriptType = pWordProps->nScriptType;
- bSet = TRUE;
- }
- break;
- case EP_CHARSPACE:
- if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fCharSpace,pWordProps->fCharSpace))
- {
- secinfo.WordProps.fCharSpace = pWordProps->fCharSpace;
- bSet = TRUE;
- }
- break;
- case EP_HORZSCALE:
- if (secinfo.WordProps.nHorzScale != pWordProps->nHorzScale)
- {
- secinfo.WordProps.nHorzScale = pWordProps->nHorzScale;
- bSet = TRUE;
- }
- break;
- case EP_UNDERLINE:
- if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE)
- {
- if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == 0)
- {
- secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE;
- bSet = TRUE;
- }
- }
- else
- {
- if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != 0)
- {
- secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE;
- bSet = TRUE;
- }
- }
- break;
- case EP_CROSSOUT:
- if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT)
- {
- if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == 0)
- {
- secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT;
- bSet = TRUE;
- }
- }
- else
- {
- if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != 0)
- {
- secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT;
- bSet = TRUE;
- }
- }
- break;
- case EP_BOLD:
- if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD)
- {
- if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0)
- {
- secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD;
- bSet = TRUE;
- }
- }
- else
- {
- if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0)
- {
- secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD;
- bSet = TRUE;
- }
- }
- break;
- case EP_ITALIC:
- if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC)
- {
- if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0)
- {
- secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC;
- bSet = TRUE;
- }
- }
- else
- {
- if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0)
- {
- secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC;
- bSet = TRUE;
- }
- }
- break;
- default:
- break;
- }
- }
- }
- }
-
- if (bSet)
- {
- pIterator->SetSection(secinfo);
-
- if (bAddUndo && m_bEnableUndo)
- {
- AddEditUndoItem(new CFXEU_SetSecProps
- (this,place,eProps,OldSecinfo.SecProps,OldSecinfo.WordProps,secinfo.SecProps,secinfo.WordProps,wr));
- }
- }
-
- pIterator->SetAt(oldplace);
-
- return bSet;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::SetWordProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place,
- const CPVT_WordProps * pWordProps, const CPVT_WordRange & wr, FX_BOOL bAddUndo)
-{
- if (m_pVT->IsValid() && m_pVT->IsRichText())
- {
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- FX_BOOL bSet = FALSE;
- CPVT_Word wordinfo;
- CPVT_Word OldWordinfo;
-
- CPVT_WordPlace oldplace = pIterator->GetAt();
-
- if (pWordProps)
- {
- pIterator->SetAt(place);
- if (pIterator->GetWord(wordinfo))
- {
- if (bAddUndo) OldWordinfo = wordinfo;
-
- switch(eProps)
- {
- case EP_FONTINDEX:
- if (wordinfo.WordProps.nFontIndex != pWordProps->nFontIndex)
- {
- if (IFX_Edit_FontMap* pFontMap = this->GetFontMap())
- {
- wordinfo.WordProps.nFontIndex = pFontMap->GetWordFontIndex(wordinfo.Word,wordinfo.nCharset,pWordProps->nFontIndex);
- }
- bSet = TRUE;
- }
- break;
- case EP_FONTSIZE:
- if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fFontSize,pWordProps->fFontSize))
- {
- wordinfo.WordProps.fFontSize = pWordProps->fFontSize;
- bSet = TRUE;
- }
- break;
- case EP_WORDCOLOR:
- if (wordinfo.WordProps.dwWordColor != pWordProps->dwWordColor)
- {
- wordinfo.WordProps.dwWordColor = pWordProps->dwWordColor;
- bSet = TRUE;
- }
- break;
- case EP_SCRIPTTYPE:
- if (wordinfo.WordProps.nScriptType != pWordProps->nScriptType)
- {
- wordinfo.WordProps.nScriptType = pWordProps->nScriptType;
- bSet = TRUE;
- }
- break;
- case EP_CHARSPACE:
- if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fCharSpace,pWordProps->fCharSpace))
- {
- wordinfo.WordProps.fCharSpace = pWordProps->fCharSpace;
- bSet = TRUE;
- }
- break;
- case EP_HORZSCALE:
- if (wordinfo.WordProps.nHorzScale != pWordProps->nHorzScale)
- {
- wordinfo.WordProps.nHorzScale = pWordProps->nHorzScale;
- bSet = TRUE;
- }
- break;
- case EP_UNDERLINE:
- if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE)
- {
- if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == 0)
- {
- wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE;
- bSet = TRUE;
- }
- }
- else
- {
- if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != 0)
- {
- wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE;
- bSet = TRUE;
- }
- }
- break;
- case EP_CROSSOUT:
- if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT)
- {
- if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == 0)
- {
- wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT;
- bSet = TRUE;
- }
- }
- else
- {
- if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != 0)
- {
- wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT;
- bSet = TRUE;
- }
- }
- break;
- case EP_BOLD:
- if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD)
- {
- if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0)
- {
- wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD;
- bSet = TRUE;
- }
- }
- else
- {
- if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0)
- {
- wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD;
- bSet = TRUE;
- }
- }
- break;
- case EP_ITALIC:
- if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC)
- {
- if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0)
- {
- wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC;
- bSet = TRUE;
- }
- }
- else
- {
- if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0)
- {
- wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC;
- bSet = TRUE;
- }
- }
- break;
- default:
- break;
- }
- }
- }
-
- if (bSet)
- {
- pIterator->SetWord(wordinfo);
-
- if (bAddUndo && m_bEnableUndo)
- {
- AddEditUndoItem(new CFXEU_SetWordProps
- (this,place,eProps,OldWordinfo.WordProps,wordinfo.WordProps,wr));
- }
- }
-
- pIterator->SetAt(oldplace);
- return bSet;
- }
- }
-
- return FALSE;
-}
-
-void CFX_Edit::SetText(FX_LPCWSTR text,FX_INT32 charset /*= DEFAULT_CHARSET*/,
- const CPVT_SecProps * pSecProps /*= NULL*/,const CPVT_WordProps * pWordProps /*= NULL*/)
-{
- SetText(text,charset,pSecProps,pWordProps,TRUE,TRUE);
-}
-
-FX_BOOL CFX_Edit::InsertWord(FX_WORD word, FX_INT32 charset /*= DEFAULT_CHARSET*/, const CPVT_WordProps * pWordProps /*= NULL*/)
-{
- return InsertWord(word,charset,pWordProps,TRUE,TRUE);
-}
-
-FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps * pSecProps /*= NULL*/,const CPVT_WordProps * pWordProps /*= NULL*/)
-{
- return InsertReturn(pSecProps,pWordProps,TRUE,TRUE);
-}
-
-FX_BOOL CFX_Edit::Backspace()
-{
- return Backspace(TRUE,TRUE);
-}
-
-FX_BOOL CFX_Edit::Delete()
-{
- return Delete(TRUE,TRUE);
-}
-
-FX_BOOL CFX_Edit::Clear()
-{
- return Clear(TRUE,TRUE);
-}
-
-FX_BOOL CFX_Edit::InsertText(FX_LPCWSTR text, FX_INT32 charset /*= DEFAULT_CHARSET*/,
- const CPVT_SecProps * pSecProps /*= NULL*/,const CPVT_WordProps * pWordProps /*= NULL*/)
-{
- return InsertText(text,charset,pSecProps,pWordProps,TRUE,TRUE);
-}
-
-FX_FLOAT CFX_Edit::GetFontSize() const
-{
- return m_pVT->GetFontSize();
-}
-
-FX_WORD CFX_Edit::GetPasswordChar() const
-{
- return m_pVT->GetPasswordChar();
-}
-
-FX_INT32 CFX_Edit::GetCharArray() const
-{
- return m_pVT->GetCharArray();
-}
-
-CPDF_Rect CFX_Edit::GetPlateRect() const
-{
- return m_pVT->GetPlateRect();
-}
-
-CPDF_Rect CFX_Edit::GetContentRect() const
-{
- return VTToEdit(m_pVT->GetContentRect());
-}
-
-FX_INT32 CFX_Edit::GetHorzScale() const
-{
- return m_pVT->GetHorzScale();
-}
-
-FX_FLOAT CFX_Edit::GetCharSpace() const
-{
- return m_pVT->GetCharSpace();
-}
-
-// inner methods
-
-CPVT_WordRange CFX_Edit::GetWholeWordRange() const
-{
- if (m_pVT->IsValid())
- return CPVT_WordRange(m_pVT->GetBeginWordPlace(),m_pVT->GetEndWordPlace());
-
- return CPVT_WordRange();
-}
-
-CPVT_WordRange CFX_Edit::GetVisibleWordRange() const
-{
- if (m_bEnableOverflow) return GetWholeWordRange();
-
- if (m_pVT->IsValid())
- {
- CPDF_Rect rcPlate = m_pVT->GetPlateRect();
-
- CPVT_WordPlace place1 = m_pVT->SearchWordPlace(EditToVT(CPDF_Point(rcPlate.left,rcPlate.top)));
- CPVT_WordPlace place2 = m_pVT->SearchWordPlace(EditToVT(CPDF_Point(rcPlate.right,rcPlate.bottom)));
-
- return CPVT_WordRange(place1,place2);
- }
-
- return CPVT_WordRange();
-}
-
-CPVT_WordPlace CFX_Edit::SearchWordPlace(const CPDF_Point& point) const
-{
- if (m_pVT->IsValid())
- {
- return m_pVT->SearchWordPlace(EditToVT(point));
- }
-
- return CPVT_WordPlace();
-}
-
-void CFX_Edit::Paint()
-{
- if (m_pVT->IsValid())
- {
- RearrangeAll();
- ScrollToCaret();
- Refresh(RP_NOANALYSE);
- SetCaretOrigin();
- SetCaretInfo();
- }
-}
-
-void CFX_Edit::RearrangeAll()
-{
- if (m_pVT->IsValid())
- {
- m_pVT->UpdateWordPlace(m_wpCaret);
- m_pVT->RearrangeAll();
- m_pVT->UpdateWordPlace(m_wpCaret);
- SetScrollInfo();
- SetContentChanged();
- }
-}
-
-void CFX_Edit::RearrangePart(const CPVT_WordRange & range)
-{
- if (m_pVT->IsValid())
- {
- m_pVT->UpdateWordPlace(m_wpCaret);
- m_pVT->RearrangePart(range);
- m_pVT->UpdateWordPlace(m_wpCaret);
- SetScrollInfo();
- SetContentChanged();
- }
-}
-
-void CFX_Edit::SetContentChanged()
-{
- if (m_bNotify && m_pNotify)
- {
- CPDF_Rect rcContent = m_pVT->GetContentRect();
- if (rcContent.Width() != m_rcOldContent.Width() ||
- rcContent.Height() != m_rcOldContent.Height())
- {
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- m_pNotify->IOnContentChange(rcContent);
- m_bNotifyFlag = FALSE;
- }
- m_rcOldContent = rcContent;
- }
- }
-}
-
-void CFX_Edit::SelectAll()
-{
- if (m_pVT->IsValid())
- {
- m_SelState = GetWholeWordRange();
- SetCaret(m_SelState.EndPos);
-
- ScrollToCaret();
- CPVT_WordRange wrVisible = GetVisibleWordRange();
- Refresh(RP_OPTIONAL,&wrVisible);
- SetCaretInfo();
- }
-}
-
-void CFX_Edit::SelectNone()
-{
- if (m_pVT->IsValid())
- {
- if (m_SelState.IsExist())
- {
- CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange();
- m_SelState.Default();
- Refresh(RP_OPTIONAL,&wrTemp);
- }
- }
-}
-
-FX_BOOL CFX_Edit::IsSelected() const
-{
- return m_SelState.IsExist();
-}
-
-CPDF_Point CFX_Edit::VTToEdit(const CPDF_Point & point) const
-{
- CPDF_Rect rcContent = m_pVT->GetContentRect();
- CPDF_Rect rcPlate = m_pVT->GetPlateRect();
-
- FX_FLOAT fPadding = 0.0f;
-
- switch (m_nAlignment)
- {
- case 0:
- fPadding = 0.0f;
- break;
- case 1:
- fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f;
- break;
- case 2:
- fPadding = rcPlate.Height() - rcContent.Height();
- break;
- }
-
- return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left),
- point.y - (m_ptScrollPos.y + fPadding - rcPlate.top));
-}
-
-CPDF_Point CFX_Edit::EditToVT(const CPDF_Point & point) const
-{
- CPDF_Rect rcContent = m_pVT->GetContentRect();
- CPDF_Rect rcPlate = m_pVT->GetPlateRect();
-
- FX_FLOAT fPadding = 0.0f;
-
- switch (m_nAlignment)
- {
- case 0:
- fPadding = 0.0f;
- break;
- case 1:
- fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f;
- break;
- case 2:
- fPadding = rcPlate.Height() - rcContent.Height();
- break;
- }
-
- return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left),
- point.y + (m_ptScrollPos.y + fPadding - rcPlate.top));
-}
-
-CPDF_Rect CFX_Edit::VTToEdit(const CPDF_Rect & rect) const
-{
- CPDF_Point ptLeftBottom = VTToEdit(CPDF_Point(rect.left,rect.bottom));
- CPDF_Point ptRightTop = VTToEdit(CPDF_Point(rect.right,rect.top));
-
- return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y);
-}
-
-CPDF_Rect CFX_Edit::EditToVT(const CPDF_Rect & rect) const
-{
- CPDF_Point ptLeftBottom = EditToVT(CPDF_Point(rect.left,rect.bottom));
- CPDF_Point ptRightTop = EditToVT(CPDF_Point(rect.right,rect.top));
-
- return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y);
-}
-
-void CFX_Edit::SetScrollInfo()
-{
- if (m_bNotify && m_pNotify)
- {
- CPDF_Rect rcPlate = m_pVT->GetPlateRect();
- CPDF_Rect rcContent = m_pVT->GetContentRect();
-
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- m_pNotify->IOnSetScrollInfoX(rcPlate.left, rcPlate.right,
- rcContent.left, rcContent.right, rcPlate.Width() / 3, rcPlate.Width());
-
- m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top,
- rcContent.bottom, rcContent.top, rcPlate.Height() / 3, rcPlate.Height());
- m_bNotifyFlag = FALSE;
- }
- }
-}
-
-void CFX_Edit::SetScrollPosX(FX_FLOAT fx)
-{
- if (!m_bEnableScroll) return;
-
- if (m_pVT->IsValid())
- {
- if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x,fx))
- {
- m_ptScrollPos.x = fx;
- Refresh(RP_NOANALYSE);
-
- if (m_bNotify && m_pNotify)
- {
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- m_pNotify->IOnSetScrollPosX(fx);
- m_bNotifyFlag = FALSE;
- }
- }
- }
- }
-}
-
-void CFX_Edit::SetScrollPosY(FX_FLOAT fy)
-{
- if (!m_bEnableScroll) return;
-
- if (m_pVT->IsValid())
- {
- if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y,fy))
- {
- m_ptScrollPos.y = fy;
- Refresh(RP_NOANALYSE);
-
- if (m_bNotify && m_pNotify)
- {
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- m_pNotify->IOnSetScrollPosY(fy);
- m_bNotifyFlag = FALSE;
- }
- }
- }
- }
-}
-
-void CFX_Edit::SetScrollPos(const CPDF_Point & point)
-{
- SetScrollPosX(point.x);
- SetScrollPosY(point.y);
- SetScrollLimit();
- SetCaretInfo();
-}
-
-CPDF_Point CFX_Edit::GetScrollPos() const
-{
- return m_ptScrollPos;
-}
-
-void CFX_Edit::SetScrollLimit()
-{
- if (m_pVT->IsValid())
- {
- CPDF_Rect rcContent = m_pVT->GetContentRect();
- CPDF_Rect rcPlate = m_pVT->GetPlateRect();
-
- if (rcPlate.Width() > rcContent.Width())
- {
- SetScrollPosX(rcPlate.left);
- }
- else
- {
- if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.x, rcContent.left))
- {
- SetScrollPosX(rcContent.left);
- }
- else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.x, rcContent.right - rcPlate.Width()))
- {
- SetScrollPosX(rcContent.right - rcPlate.Width());
- }
- }
-
- if (rcPlate.Height() > rcContent.Height())
- {
- SetScrollPosY(rcPlate.top);
- }
- else
- {
- if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.y, rcContent.bottom + rcPlate.Height()))
- {
- SetScrollPosY(rcContent.bottom + rcPlate.Height());
- }
- else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.y, rcContent.top))
- {
- SetScrollPosY(rcContent.top);
- }
- }
- }
-}
-
-void CFX_Edit::ScrollToCaret()
-{
- SetScrollLimit();
-
- if (m_pVT->IsValid())
- {
- CPDF_Point ptHead(0,0);
- CPDF_Point ptFoot(0,0);
-
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- pIterator->SetAt(m_wpCaret);
-
- CPVT_Word word;
- CPVT_Line line;
- if (pIterator->GetWord(word))
- {
- ptHead.x = word.ptWord.x + word.fWidth;
- ptHead.y = word.ptWord.y + word.fAscent;
- ptFoot.x = word.ptWord.x + word.fWidth;
- ptFoot.y = word.ptWord.y + word.fDescent;
- }
- else if (pIterator->GetLine(line))
- {
- ptHead.x = line.ptLine.x;
- ptHead.y = line.ptLine.y + line.fLineAscent;
- ptFoot.x = line.ptLine.x;
- ptFoot.y = line.ptLine.y + line.fLineDescent;
- }
- }
-
- CPDF_Point ptHeadEdit = VTToEdit(ptHead);
- CPDF_Point ptFootEdit = VTToEdit(ptFoot);
-
- CPDF_Rect rcPlate = m_pVT->GetPlateRect();
-
- if (!FX_EDIT_IsFloatEqual(rcPlate.left,rcPlate.right))
- {
- if (FX_EDIT_IsFloatSmaller(ptHeadEdit.x, rcPlate.left) ||
- FX_EDIT_IsFloatEqual(ptHeadEdit.x, rcPlate.left))
- {
- SetScrollPosX(ptHead.x);
- }
- else if (FX_EDIT_IsFloatBigger(ptHeadEdit.x, rcPlate.right))
- {
- SetScrollPosX(ptHead.x - rcPlate.Width());
- }
- }
-
- if (!FX_EDIT_IsFloatEqual(rcPlate.top,rcPlate.bottom))
- {
- if (FX_EDIT_IsFloatSmaller(ptFootEdit.y, rcPlate.bottom) ||
- FX_EDIT_IsFloatEqual(ptFootEdit.y, rcPlate.bottom))
- {
- if (FX_EDIT_IsFloatSmaller(ptHeadEdit.y, rcPlate.top))
- {
- SetScrollPosY(ptFoot.y + rcPlate.Height());
- }
- }
- else if (FX_EDIT_IsFloatBigger(ptHeadEdit.y, rcPlate.top))
- {
- if (FX_EDIT_IsFloatBigger(ptFootEdit.y, rcPlate.bottom))
- {
- SetScrollPosY(ptHead.y);
- }
- }
- }
- }
-}
-
-void CFX_Edit::Refresh(REFRESH_PLAN_E ePlan,const CPVT_WordRange * pRange1,const CPVT_WordRange * pRange2)
-{
- if (m_bEnableRefresh && m_pVT->IsValid())
- {
- m_Refresh.BeginRefresh();
- RefreshPushLineRects(GetVisibleWordRange());
-
-// if (!FX_EDIT_IsFloatEqual(m_ptRefreshScrollPos.x,m_ptScrollPos.x) ||
-// !FX_EDIT_IsFloatEqual(m_ptRefreshScrollPos.y,m_ptScrollPos.y))
-// {
- m_Refresh.NoAnalyse();
- m_ptRefreshScrollPos = m_ptScrollPos;
-// }
-// else
-// {
-// switch (ePlan)
-// {
-// case RP_ANALYSE:
-// m_Refresh.Analyse(m_pVT->GetAlignment());
-//
-// if (pRange1) RefreshPushRandomRects(*pRange1);
-// if (pRange2) RefreshPushRandomRects(*pRange2);
-// break;
-// case RP_NOANALYSE:
-// m_Refresh.NoAnalyse();
-// break;
-// case RP_OPTIONAL:
-// if (pRange1) RefreshPushRandomRects(*pRange1);
-// if (pRange2) RefreshPushRandomRects(*pRange2);
-// break;
-// }
-// }
-
- if (m_bNotify && m_pNotify)
- {
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- if (const CFX_Edit_RectArray * pRects = m_Refresh.GetRefreshRects())
- {
- for (FX_INT32 i = 0, sz = pRects->GetSize(); i < sz; i++)
- m_pNotify->IOnInvalidateRect(pRects->GetAt(i));
- }
- m_bNotifyFlag = FALSE;
- }
- }
-
- m_Refresh.EndRefresh();
- }
-}
-
-void CFX_Edit::RefreshPushLineRects(const CPVT_WordRange & wr)
-{
- if (m_pVT->IsValid())
- {
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- CPVT_WordPlace wpBegin = wr.BeginPos;
- m_pVT->UpdateWordPlace(wpBegin);
- CPVT_WordPlace wpEnd = wr.EndPos;
- m_pVT->UpdateWordPlace(wpEnd);
- pIterator->SetAt(wpBegin);
-
- CPVT_Line lineinfo;
- do
- {
- if (!pIterator->GetLine(lineinfo))break;
- if (lineinfo.lineplace.LineCmp(wpEnd) > 0)break;
-
- CPDF_Rect rcLine(lineinfo.ptLine.x,
- lineinfo.ptLine.y + lineinfo.fLineDescent,
- lineinfo.ptLine.x + lineinfo.fLineWidth,
- lineinfo.ptLine.y + lineinfo.fLineAscent);
-
- m_Refresh.Push(CPVT_WordRange(lineinfo.lineplace,lineinfo.lineEnd),VTToEdit(rcLine));
-
- }while (pIterator->NextLine());
- }
- }
-}
-
-void CFX_Edit::RefreshPushRandomRects(const CPVT_WordRange & wr)
-{
- if (m_pVT->IsValid())
- {
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- CPVT_WordRange wrTemp = wr;
-
- m_pVT->UpdateWordPlace(wrTemp.BeginPos);
- m_pVT->UpdateWordPlace(wrTemp.EndPos);
- pIterator->SetAt(wrTemp.BeginPos);
-
- CPVT_Word wordinfo;
- CPVT_Line lineinfo;
- CPVT_WordPlace place;
-
- while (pIterator->NextWord())
- {
- place = pIterator->GetAt();
- if (place.WordCmp(wrTemp.EndPos) > 0) break;
-
- pIterator->GetWord(wordinfo);
- pIterator->GetLine(lineinfo);
-
- if (place.LineCmp(wrTemp.BeginPos) == 0 || place.LineCmp(wrTemp.EndPos) == 0)
- {
- CPDF_Rect rcWord(wordinfo.ptWord.x,
- lineinfo.ptLine.y + lineinfo.fLineDescent,
- wordinfo.ptWord.x + wordinfo.fWidth,
- lineinfo.ptLine.y + lineinfo.fLineAscent);
-
- m_Refresh.AddRefresh(VTToEdit(rcWord));
- }
- else
- {
- CPDF_Rect rcLine(lineinfo.ptLine.x,
- lineinfo.ptLine.y + lineinfo.fLineDescent,
- lineinfo.ptLine.x + lineinfo.fLineWidth,
- lineinfo.ptLine.y + lineinfo.fLineAscent);
-
- m_Refresh.AddRefresh(VTToEdit(rcLine));
-
- pIterator->NextLine();
- }
- }
- }
- }
-}
-
-void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr)
-{
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- CPVT_WordRange wrTemp = wr;
-
- m_pVT->UpdateWordPlace(wrTemp.BeginPos);
- m_pVT->UpdateWordPlace(wrTemp.EndPos);
- pIterator->SetAt(wrTemp.BeginPos);
-
- CPVT_Word wordinfo;
- CPVT_Line lineinfo;
- CPVT_WordPlace place;
-
- while (pIterator->NextWord())
- {
- place = pIterator->GetAt();
- if (place.WordCmp(wrTemp.EndPos) > 0) break;
-
- pIterator->GetWord(wordinfo);
- pIterator->GetLine(lineinfo);
-
- if (place.LineCmp(wrTemp.BeginPos) == 0 || place.LineCmp(wrTemp.EndPos) == 0)
- {
- CPDF_Rect rcWord(wordinfo.ptWord.x,
- lineinfo.ptLine.y + lineinfo.fLineDescent,
- wordinfo.ptWord.x + wordinfo.fWidth,
- lineinfo.ptLine.y + lineinfo.fLineAscent);
-
- if (m_bNotify && m_pNotify)
- {
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- CPDF_Rect rcRefresh = VTToEdit(rcWord);
- m_pNotify->IOnInvalidateRect(&rcRefresh);
- m_bNotifyFlag = FALSE;
- }
- }
- }
- else
- {
- CPDF_Rect rcLine(lineinfo.ptLine.x,
- lineinfo.ptLine.y + lineinfo.fLineDescent,
- lineinfo.ptLine.x + lineinfo.fLineWidth,
- lineinfo.ptLine.y + lineinfo.fLineAscent);
-
- if (m_bNotify && m_pNotify)
- {
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- CPDF_Rect rcRefresh = VTToEdit(rcLine);
- m_pNotify->IOnInvalidateRect(&rcRefresh);
- m_bNotifyFlag = FALSE;
- }
- }
-
- pIterator->NextLine();
- }
- }
- }
-}
-
-void CFX_Edit::SetCaret(const CPVT_WordPlace & place)
-{
- m_wpOldCaret = m_wpCaret;
- m_wpCaret = place;
-}
-
-void CFX_Edit::SetCaretInfo()
-{
- if (m_bNotify && m_pNotify)
- {
- if (!m_bNotifyFlag)
- {
- CPDF_Point ptHead(0.0f,0.0f),ptFoot(0.0f,0.0f);
-
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- pIterator->SetAt(m_wpCaret);
- CPVT_Word word;
- CPVT_Line line;
- if (pIterator->GetWord(word))
- {
- ptHead.x = word.ptWord.x + word.fWidth;
- ptHead.y = word.ptWord.y + word.fAscent;
- ptFoot.x = word.ptWord.x + word.fWidth;
- ptFoot.y = word.ptWord.y + word.fDescent;
- }
- else if (pIterator->GetLine(line))
- {
- ptHead.x = line.ptLine.x;
- ptHead.y = line.ptLine.y + line.fLineAscent;
- ptFoot.x = line.ptLine.x;
- ptFoot.y = line.ptLine.y + line.fLineDescent;
- }
- }
-
- m_bNotifyFlag = TRUE;
- m_pNotify->IOnSetCaret(!m_SelState.IsExist(),VTToEdit(ptHead),VTToEdit(ptFoot), m_wpCaret);
- m_bNotifyFlag = FALSE;
- }
- }
-
- SetCaretChange();
-}
-
-void CFX_Edit::SetCaretChange()
-{
- if (this->m_wpCaret == this->m_wpOldCaret) return;
-
- if (m_bNotify && m_pVT->IsRichText() && m_pNotify)
- {
- CPVT_SecProps SecProps;
- CPVT_WordProps WordProps;
-
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- pIterator->SetAt(m_wpCaret);
- CPVT_Word word;
- CPVT_Section section;
-
- if (pIterator->GetSection(section))
- {
- SecProps = section.SecProps;
- WordProps = section.WordProps;
- }
-
- if (pIterator->GetWord(word))
- {
- WordProps = word.WordProps;
- }
- }
-
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- m_pNotify->IOnCaretChange(SecProps,WordProps);
- m_bNotifyFlag = FALSE;
- }
- }
-}
-
-void CFX_Edit::SetCaret(FX_INT32 nPos)
-{
- if (m_pVT->IsValid())
- {
- SelectNone();
- SetCaret(m_pVT->WordIndexToWordPlace(nPos));
- m_SelState.Set(m_wpCaret,m_wpCaret);
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
-}
-
-void CFX_Edit::OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl)
-{
- if (m_pVT->IsValid())
- {
- SelectNone();
- SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
- m_SelState.Set(m_wpCaret,m_wpCaret);
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
-}
-
-void CFX_Edit::OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl)
-{
- if (m_pVT->IsValid())
- {
- SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
-
- if (m_wpCaret != m_wpOldCaret)
- {
- m_SelState.SetEndPos(m_wpCaret);
-
- ScrollToCaret();
- CPVT_WordRange wr(m_wpOldCaret,m_wpCaret);
- Refresh(RP_OPTIONAL,&wr);
- SetCaretOrigin();
- SetCaretInfo();
- }
- }
-}
-
-void CFX_Edit::OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- if (m_pVT->IsValid())
- {
- SetCaret(m_pVT->GetUpWordPlace(m_wpCaret,m_ptCaret));
-
- if (bShift)
- {
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret,m_wpCaret);
-
- if (m_wpOldCaret != m_wpCaret)
- {
- ScrollToCaret();
- CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
- Refresh(RP_OPTIONAL, &wr);
- SetCaretInfo();
- }
- }
- else
- {
- SelectNone();
-
- ScrollToCaret();
- SetCaretInfo();
- }
- }
-}
-
-void CFX_Edit::OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- if (m_pVT->IsValid())
- {
- SetCaret(m_pVT->GetDownWordPlace(m_wpCaret,m_ptCaret));
-
- if (bShift)
- {
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret,m_wpCaret);
-
- if (m_wpOldCaret != m_wpCaret)
- {
- ScrollToCaret();
- CPVT_WordRange wr(m_wpOldCaret,m_wpCaret);
- Refresh(RP_OPTIONAL, &wr);
- SetCaretInfo();
- }
- }
- else
- {
- SelectNone();
-
- ScrollToCaret();
- SetCaretInfo();
- }
- }
-}
-
-void CFX_Edit::OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- if (m_pVT->IsValid())
- {
- if (bShift)
- {
- if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
- m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret))
- SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
-
- SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
-
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret, m_wpCaret);
-
- if (m_wpOldCaret != m_wpCaret)
- {
- ScrollToCaret();
- CPVT_WordRange wr(m_wpOldCaret,m_wpCaret);
- Refresh(RP_OPTIONAL,&wr);
- SetCaretInfo();
- }
- }
- else
- {
- if (m_SelState.IsExist())
- {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)<0)
- SetCaret(m_SelState.BeginPos);
- else
- SetCaret(m_SelState.EndPos);
-
- SelectNone();
- ScrollToCaret();
- SetCaretInfo();
- }
- else
- {
- if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
- m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret))
- SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
-
- SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
- }
- }
-}
-
-void CFX_Edit::OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- if (m_pVT->IsValid())
- {
- if (bShift)
- {
- SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
-
- if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
- m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret))
- SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
-
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret,m_wpCaret);
-
- if (m_wpOldCaret != m_wpCaret)
- {
- ScrollToCaret();
- CPVT_WordRange wr(m_wpOldCaret,m_wpCaret);
- Refresh(RP_OPTIONAL,&wr);
- SetCaretInfo();
- }
- }
- else
- {
- if (m_SelState.IsExist())
- {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)>0)
- SetCaret(m_SelState.BeginPos);
- else
- SetCaret(m_SelState.EndPos);
-
- SelectNone();
- ScrollToCaret();
- SetCaretInfo();
- }
- else
- {
- SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
-
- if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
- m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret))
- SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
- }
- }
-}
-
-void CFX_Edit::OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- if (m_pVT->IsValid())
- {
- if (bShift)
- {
- if (bCtrl)
- SetCaret(m_pVT->GetBeginWordPlace());
- else
- SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret));
-
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret,m_wpCaret);
-
- ScrollToCaret();
- CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
- Refresh(RP_OPTIONAL, &wr);
- SetCaretInfo();
- }
- else
- {
- if (m_SelState.IsExist())
- {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)<0)
- SetCaret(m_SelState.BeginPos);
- else
- SetCaret(m_SelState.EndPos);
-
- SelectNone();
- ScrollToCaret();
- SetCaretInfo();
- }
- else
- {
- if (bCtrl)
- SetCaret(m_pVT->GetBeginWordPlace());
- else
- SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret));
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
- }
- }
-}
-
-void CFX_Edit::OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- if (m_pVT->IsValid())
- {
- if (bShift)
- {
- if (bCtrl)
- SetCaret(m_pVT->GetEndWordPlace());
- else
- SetCaret(m_pVT->GetLineEndPlace(m_wpCaret));
-
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret, m_wpCaret);
-
- ScrollToCaret();
- CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
- Refresh(RP_OPTIONAL, &wr);
- SetCaretInfo();
- }
- else
- {
- if (m_SelState.IsExist())
- {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)>0)
- SetCaret(m_SelState.BeginPos);
- else
- SetCaret(m_SelState.EndPos);
-
- SelectNone();
- ScrollToCaret();
- SetCaretInfo();
- }
- else
- {
- if (bCtrl)
- SetCaret(m_pVT->GetEndWordPlace());
- else
- SetCaret(m_pVT->GetLineEndPlace(m_wpCaret));
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
- }
- }
-}
-
-void CFX_Edit::SetText(FX_LPCWSTR text,FX_INT32 charset,
- const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps, FX_BOOL bAddUndo, FX_BOOL bPaint)
-{
- Empty();
- DoInsertText(CPVT_WordPlace(0,0,-1), text, charset, pSecProps, pWordProps);
- if (bPaint) Paint();
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnSetText(m_wpCaret, m_wpOldCaret);
- //if (bAddUndo)
-}
-
-FX_BOOL CFX_Edit::InsertWord(FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps, FX_BOOL bAddUndo, FX_BOOL bPaint)
-{
- if (IsTextOverflow()) return FALSE;
-
- if (m_pVT->IsValid())
- {
- m_pVT->UpdateWordPlace(m_wpCaret);
-
- SetCaret(m_pVT->InsertWord(m_wpCaret,word,GetCharSetFromUnicode(word, charset),pWordProps));
- m_SelState.Set(m_wpCaret,m_wpCaret);
-
- if (m_wpCaret != m_wpOldCaret)
- {
- if (bAddUndo && m_bEnableUndo)
- {
- AddEditUndoItem(new CFXEU_InsertWord(this,m_wpOldCaret,m_wpCaret,word,charset,pWordProps));
- }
-
- if (bPaint)
- PaintInsertText(m_wpOldCaret, m_wpCaret);
-
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnInsertWord(m_wpCaret, m_wpOldCaret);
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,
- FX_BOOL bAddUndo, FX_BOOL bPaint)
-{
- if (IsTextOverflow()) return FALSE;
-
- if (m_pVT->IsValid())
- {
- m_pVT->UpdateWordPlace(m_wpCaret);
- SetCaret(m_pVT->InsertSection(m_wpCaret,pSecProps,pWordProps));
- m_SelState.Set(m_wpCaret,m_wpCaret);
-
- if (m_wpCaret != m_wpOldCaret)
- {
- if (bAddUndo && m_bEnableUndo)
- {
- AddEditUndoItem(new CFXEU_InsertReturn(this,m_wpOldCaret,m_wpCaret,pSecProps,pWordProps));
- }
-
- if (bPaint)
- {
- RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret));
- ScrollToCaret();
- CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos);
- Refresh(RP_ANALYSE, &wr);
- SetCaretOrigin();
- SetCaretInfo();
- }
-
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnInsertReturn(m_wpCaret, m_wpOldCaret);
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint)
-{
- if (m_pVT->IsValid())
- {
- if (m_wpCaret == m_pVT->GetBeginWordPlace()) return FALSE;
-
- CPVT_Section section;
- CPVT_Word word;
-
- if (bAddUndo)
- {
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- pIterator->SetAt(m_wpCaret);
- pIterator->GetSection(section);
- pIterator->GetWord(word);
- }
- }
-
- m_pVT->UpdateWordPlace(m_wpCaret);
- SetCaret(m_pVT->BackSpaceWord(m_wpCaret));
- m_SelState.Set(m_wpCaret,m_wpCaret);
-
- if (m_wpCaret != m_wpOldCaret)
- {
- if (bAddUndo && m_bEnableUndo)
- {
- if (m_wpCaret.SecCmp(m_wpOldCaret) != 0)
- AddEditUndoItem(new CFXEU_Backspace(this,m_wpOldCaret,m_wpCaret,word.Word,word.nCharset,
- section.SecProps,section.WordProps));
- else
- AddEditUndoItem(new CFXEU_Backspace(this,m_wpOldCaret,m_wpCaret,word.Word,word.nCharset,
- section.SecProps,word.WordProps));
- }
-
- if (bPaint)
- {
- RearrangePart(CPVT_WordRange(m_wpCaret,m_wpOldCaret));
- ScrollToCaret();
-
- CPVT_WordRange wr;
- if (m_wpCaret.SecCmp(m_wpOldCaret) !=0)
- wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret),GetVisibleWordRange().EndPos);
- else if (m_wpCaret.LineCmp(m_wpOldCaret) !=0)
- wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret),m_pVT->GetSectionEndPlace(m_wpCaret));
- else
- wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret),m_pVT->GetSectionEndPlace(m_wpCaret));
-
- Refresh(RP_ANALYSE, &wr);
-
- SetCaretOrigin();
- SetCaretInfo();
- }
-
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnBackSpace(m_wpCaret, m_wpOldCaret);
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::Delete(FX_BOOL bAddUndo, FX_BOOL bPaint)
-{
- if (m_pVT->IsValid())
- {
- if (m_wpCaret == m_pVT->GetEndWordPlace()) return FALSE;
-
- CPVT_Section section;
- CPVT_Word word;
-
- if (bAddUndo)
- {
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret));
- pIterator->GetSection(section);
- pIterator->GetWord(word);
- }
- }
-
- m_pVT->UpdateWordPlace(m_wpCaret);
- FX_BOOL bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret));
-
- SetCaret(m_pVT->DeleteWord(m_wpCaret));
- m_SelState.Set(m_wpCaret,m_wpCaret);
-
- if (bAddUndo && m_bEnableUndo)
- {
- if (bSecEnd)
- AddEditUndoItem(new CFXEU_Delete(this,m_wpOldCaret,m_wpCaret,word.Word,word.nCharset,
- section.SecProps,section.WordProps,bSecEnd));
- else
- AddEditUndoItem(new CFXEU_Delete(this,m_wpOldCaret,m_wpCaret,word.Word,word.nCharset,
- section.SecProps,word.WordProps,bSecEnd));
- }
-
- if (bPaint)
- {
- RearrangePart(CPVT_WordRange(m_wpOldCaret,m_wpCaret));
- ScrollToCaret();
-
- CPVT_WordRange wr;
- if (bSecEnd)
- wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret),GetVisibleWordRange().EndPos);
- else if (m_wpCaret.LineCmp(m_wpOldCaret) !=0)
- wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret),m_pVT->GetSectionEndPlace(m_wpCaret));
- else
- wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret),m_pVT->GetSectionEndPlace(m_wpCaret));
-
- Refresh(RP_ANALYSE, &wr);
-
- SetCaretOrigin();
- SetCaretInfo();
- }
-
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnDelete(m_wpCaret, m_wpOldCaret);
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::Empty()
-{
- if (m_pVT->IsValid())
- {
- m_pVT->DeleteWords(GetWholeWordRange());
- SetCaret(m_pVT->GetBeginWordPlace());
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::Clear(FX_BOOL bAddUndo, FX_BOOL bPaint)
-{
- if (m_pVT->IsValid())
- {
- if (m_SelState.IsExist())
- {
- CPVT_WordRange range = m_SelState.ConvertToWordRange();
-
- if (bAddUndo && m_bEnableUndo)
- {
- if (m_pVT->IsRichText())
- {
- BeginGroupUndo(L"");
-
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- pIterator->SetAt(range.EndPos);
-
- CPVT_Word wordinfo;
- CPVT_Section secinfo;
- do
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (place.WordCmp(range.BeginPos) <= 0)break;
-
- CPVT_WordPlace oldplace = m_pVT->GetPrevWordPlace(place);
-
- if (oldplace.SecCmp(place) != 0)
- {
- if (pIterator->GetSection(secinfo))
- {
- AddEditUndoItem(new CFXEU_ClearRich(this,oldplace,place,range,wordinfo.Word,
- wordinfo.nCharset,secinfo.SecProps,secinfo.WordProps));
- }
- }
- else
- {
- if (pIterator->GetWord(wordinfo))
- {
- oldplace = m_pVT->AjustLineHeader(oldplace,TRUE);
- place = m_pVT->AjustLineHeader(place,TRUE);
-
- AddEditUndoItem(new CFXEU_ClearRich(this,oldplace,place,range,wordinfo.Word,
- wordinfo.nCharset,secinfo.SecProps,wordinfo.WordProps));
- }
- }
- }while (pIterator->PrevWord());
- }
- EndGroupUndo();
- }
- else
- {
- AddEditUndoItem(new CFXEU_Clear(this,range,GetSelText()));
- }
- }
-
- SelectNone();
- SetCaret(m_pVT->DeleteWords(range));
- m_SelState.Set(m_wpCaret,m_wpCaret);
-
- if (bPaint)
- {
- RearrangePart(range);
- ScrollToCaret();
-
- CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos);
- Refresh(RP_ANALYSE, &wr);
-
- SetCaretOrigin();
- SetCaretInfo();
- }
-
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret);
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::InsertText(FX_LPCWSTR text, FX_INT32 charset,
- const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps, FX_BOOL bAddUndo, FX_BOOL bPaint)
-{
- if (IsTextOverflow()) return FALSE;
-
- m_pVT->UpdateWordPlace(m_wpCaret);
- SetCaret(DoInsertText(m_wpCaret, text, charset, pSecProps, pWordProps));
- m_SelState.Set(m_wpCaret,m_wpCaret);
-
- if (m_wpCaret != m_wpOldCaret)
- {
- if (bAddUndo && m_bEnableUndo)
- {
- AddEditUndoItem(new CFXEU_InsertText(this,m_wpOldCaret,m_wpCaret,text,charset,pSecProps,pWordProps));
- }
-
- if (bPaint)
- PaintInsertText(m_wpOldCaret, m_wpCaret);
-
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret);
-
- return TRUE;
- }
- return FALSE;
-}
-
-void CFX_Edit::PaintInsertText(const CPVT_WordPlace & wpOld, const CPVT_WordPlace & wpNew)
-{
- if (m_pVT->IsValid())
- {
- RearrangePart(CPVT_WordRange(wpOld,wpNew));
- ScrollToCaret();
-
- CPVT_WordRange wr;
- if (m_wpCaret.LineCmp(wpOld) !=0)
- wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(wpOld),m_pVT->GetSectionEndPlace(wpNew));
- else
- wr = CPVT_WordRange(wpOld,m_pVT->GetSectionEndPlace(wpNew));
- Refresh(RP_ANALYSE, &wr);
- SetCaretOrigin();
- SetCaretInfo();
- }
-}
-
-FX_BOOL CFX_Edit::Redo()
-{
- if (m_bEnableUndo)
- {
- if (m_Undo.CanRedo())
- {
- m_Undo.Redo();
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::Undo()
-{
- if (m_bEnableUndo)
- {
- if (m_Undo.CanUndo())
- {
- m_Undo.Undo();
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-void CFX_Edit::SetCaretOrigin()
-{
- if (m_pVT->IsValid())
- {
- if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
- {
- pIterator->SetAt(m_wpCaret);
- CPVT_Word word;
- CPVT_Line line;
- if (pIterator->GetWord(word))
- {
- m_ptCaret.x = word.ptWord.x + word.fWidth;
- m_ptCaret.y = word.ptWord.y;
- }
- else if (pIterator->GetLine(line))
- {
- m_ptCaret.x = line.ptLine.x;
- m_ptCaret.y = line.ptLine.y;
- }
- }
- }
-}
-
-FX_INT32 CFX_Edit::WordPlaceToWordIndex(const CPVT_WordPlace & place) const
-{
- if (m_pVT->IsValid())
- return m_pVT->WordPlaceToWordIndex(place);
-
- return -1;
-}
-
-CPVT_WordPlace CFX_Edit::WordIndexToWordPlace(FX_INT32 index) const
-{
- if (m_pVT->IsValid())
- return m_pVT->WordIndexToWordPlace(index);
-
- return CPVT_WordPlace();
-}
-
-FX_BOOL CFX_Edit::IsTextFull() const
-{
- FX_INT32 nTotalWords = m_pVT->GetTotalWords();
- FX_INT32 nLimitChar = m_pVT->GetLimitChar();
- FX_INT32 nCharArray = m_pVT->GetCharArray();
-
- return IsTextOverflow() || (nLimitChar>0 && nTotalWords >= nLimitChar)
- || (nCharArray>0 && nTotalWords >= nCharArray);
-}
-
-FX_BOOL CFX_Edit::IsTextOverflow() const
-{
- if (!m_bEnableScroll && !m_bEnableOverflow)
- {
- CPDF_Rect rcPlate = m_pVT->GetPlateRect();
- CPDF_Rect rcContent = m_pVT->GetContentRect();
-
- if (m_pVT->IsMultiLine() && GetTotalLines() > 1)
- {
- if (FX_EDIT_IsFloatBigger(rcContent.Height(),rcPlate.Height())) return TRUE;
- }
-
- if (FX_EDIT_IsFloatBigger(rcContent.Width(),rcPlate.Width())) return TRUE;
- }
-
- return FALSE;
-}
-
-CPVT_WordPlace CFX_Edit::GetLineBeginPlace(const CPVT_WordPlace & place) const
-{
- return m_pVT->GetLineBeginPlace(place);
-}
-
-CPVT_WordPlace CFX_Edit::GetLineEndPlace(const CPVT_WordPlace & place) const
-{
- return m_pVT->GetLineEndPlace(place);
-}
-
-CPVT_WordPlace CFX_Edit::GetSectionBeginPlace(const CPVT_WordPlace & place) const
-{
- return m_pVT->GetSectionBeginPlace(place);
-}
-
-CPVT_WordPlace CFX_Edit::GetSectionEndPlace(const CPVT_WordPlace & place) const
-{
- return m_pVT->GetSectionEndPlace(place);
-}
-
-FX_BOOL CFX_Edit::CanUndo() const
-{
- if (m_bEnableUndo)
- {
- return m_Undo.CanUndo();
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::CanRedo() const
-{
- if (m_bEnableUndo)
- {
- return m_Undo.CanRedo();
- }
-
- return FALSE;
-}
-
-FX_BOOL CFX_Edit::IsModified() const
-{
- if (m_bEnableUndo)
- {
- return m_Undo.IsModified();
- }
-
- return FALSE;
-}
-
-void CFX_Edit::EnableRefresh(FX_BOOL bRefresh)
-{
- m_bEnableRefresh = bRefresh;
-}
-
-void CFX_Edit::EnableUndo(FX_BOOL bUndo)
-{
- this->m_bEnableUndo = bUndo;
-}
-
-void CFX_Edit::EnableNotify(FX_BOOL bNotify)
-{
- this->m_bNotify = bNotify;
-}
-
-void CFX_Edit::EnableOprNotify(FX_BOOL bNotify)
-{
- this->m_bOprNotify = bNotify;
-}
-
-FX_FLOAT CFX_Edit::GetLineTop(const CPVT_WordPlace& place) const
-{
- if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator())
- {
- CPVT_WordPlace wpOld = pIterator->GetAt();
-
- pIterator->SetAt(place);
- CPVT_Line line;
- pIterator->GetLine(line);
-
- pIterator->SetAt(wpOld);
-
- return line.ptLine.y + line.fLineAscent;
- }
-
- return 0.0f;
-}
-
-FX_FLOAT CFX_Edit::GetLineBottom(const CPVT_WordPlace& place) const
-{
- if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator())
- {
- CPVT_WordPlace wpOld = pIterator->GetAt();
-
- pIterator->SetAt(place);
- CPVT_Line line;
- pIterator->GetLine(line);
-
- pIterator->SetAt(wpOld);
-
- return line.ptLine.y + line.fLineDescent;
- }
-
- return 0.0f;
-}
-
-CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, FX_LPCWSTR text, FX_INT32 charset,
- const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps)
-{
- CPVT_WordPlace wp = place;
-
- if (m_pVT->IsValid())
- {
- CFX_WideString sText = text;
-
- for (FX_INT32 i = 0, sz = sText.GetLength(); i < sz; i++)
- {
- FX_WORD word = sText[i];
- switch (word)
- {
- case 0x0D:
- wp = m_pVT->InsertSection(wp,pSecProps,pWordProps);
- if (sText[i+1] == 0x0A)
- i++;
- break;
- case 0x0A:
- wp = m_pVT->InsertSection(wp,pSecProps,pWordProps);
- if (sText[i+1] == 0x0D)
- i++;
- break;
- case 0x09:
- word = 0x20;
- default:
- wp = m_pVT->InsertWord(wp,word,GetCharSetFromUnicode(word, charset),pWordProps);
- break;
- }
- }
- }
-
- return wp;
-}
-
-FX_INT32 CFX_Edit::GetCharSetFromUnicode(FX_WORD word, FX_INT32 nOldCharset)
-{
- if (IFX_Edit_FontMap* pFontMap = this->GetFontMap())
- return pFontMap->CharSetFromUnicode(word, nOldCharset);
- else
- return nOldCharset;
-}
-
-void CFX_Edit::BeginGroupUndo(const CFX_WideString& sTitle)
-{
- ASSERT(m_pGroupUndoItem == NULL);
-
- m_pGroupUndoItem = new CFX_Edit_GroupUndoItem(sTitle);
-}
-
-void CFX_Edit::EndGroupUndo()
-{
- ASSERT(m_pGroupUndoItem != NULL);
-
- m_pGroupUndoItem->UpdateItems();
- m_Undo.AddItem(m_pGroupUndoItem);
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnAddUndo(m_pGroupUndoItem);
- m_pGroupUndoItem = NULL;
-}
-
-void CFX_Edit::AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem)
-{
- if (m_pGroupUndoItem)
- m_pGroupUndoItem->AddUndoItem(pEditUndoItem);
- else
- {
- m_Undo.AddItem(pEditUndoItem);
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnAddUndo(pEditUndoItem);
- }
-}
-
-void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem)
-{
- m_Undo.AddItem(pUndoItem);
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnAddUndo(pUndoItem);
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fxedit/fxet_stub.h"
+#include "../../include/fxedit/fxet_edit.h"
+
+#define FX_EDIT_UNDO_MAXITEM 10000
+
+/* ---------------------------- CFX_Edit_Iterator ---------------------------- */
+
+CFX_Edit_Iterator::CFX_Edit_Iterator(CFX_Edit * pEdit,IPDF_VariableText_Iterator * pVTIterator) :
+ m_pEdit(pEdit),
+ m_pVTIterator(pVTIterator)
+{
+}
+
+CFX_Edit_Iterator::~CFX_Edit_Iterator()
+{
+}
+
+FX_BOOL CFX_Edit_Iterator::NextWord()
+{
+ ASSERT(m_pVTIterator != NULL);
+
+ return m_pVTIterator->NextWord();
+}
+
+FX_BOOL CFX_Edit_Iterator::NextLine()
+{
+ ASSERT(m_pVTIterator != NULL);
+
+ return m_pVTIterator->NextLine();
+}
+
+FX_BOOL CFX_Edit_Iterator::NextSection()
+{
+ ASSERT(m_pVTIterator != NULL);
+
+ return m_pVTIterator->NextSection();
+}
+
+FX_BOOL CFX_Edit_Iterator::PrevWord()
+{
+ ASSERT(m_pVTIterator != NULL);
+
+ return m_pVTIterator->PrevWord();
+}
+
+FX_BOOL CFX_Edit_Iterator::PrevLine()
+{
+ ASSERT(m_pVTIterator != NULL);
+
+ return m_pVTIterator->PrevLine();
+}
+
+FX_BOOL CFX_Edit_Iterator::PrevSection()
+{
+ ASSERT(m_pVTIterator != NULL);
+
+ return m_pVTIterator->PrevSection();
+}
+
+FX_BOOL CFX_Edit_Iterator::GetWord(CPVT_Word & word) const
+{
+ ASSERT(m_pEdit != NULL);
+ ASSERT(m_pVTIterator != NULL);
+
+ if (m_pVTIterator->GetWord(word))
+ {
+ word.ptWord = m_pEdit->VTToEdit(word.ptWord);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit_Iterator::GetLine(CPVT_Line & line) const
+{
+ ASSERT(m_pEdit != NULL);
+ ASSERT(m_pVTIterator != NULL);
+
+ if (m_pVTIterator->GetLine(line))
+ {
+ line.ptLine = m_pEdit->VTToEdit(line.ptLine);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit_Iterator::GetSection(CPVT_Section & section) const
+{
+ ASSERT(m_pEdit != NULL);
+ ASSERT(m_pVTIterator != NULL);
+
+ if (m_pVTIterator->GetSection(section))
+ {
+ section.rcSection = m_pEdit->VTToEdit(section.rcSection);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void CFX_Edit_Iterator::SetAt(FX_INT32 nWordIndex)
+{
+ ASSERT(m_pVTIterator != NULL);
+
+ m_pVTIterator->SetAt(nWordIndex);
+}
+
+void CFX_Edit_Iterator::SetAt(const CPVT_WordPlace & place)
+{
+ ASSERT(m_pVTIterator != NULL);
+
+ m_pVTIterator->SetAt(place);
+}
+
+const CPVT_WordPlace & CFX_Edit_Iterator::GetAt() const
+{
+ ASSERT(m_pVTIterator != NULL);
+
+ return m_pVTIterator->GetAt();
+}
+
+IFX_Edit* CFX_Edit_Iterator::GetEdit() const
+{
+ return m_pEdit;
+}
+
+/* --------------------------- CFX_Edit_Provider ------------------------------- */
+
+CFX_Edit_Provider::CFX_Edit_Provider(IFX_Edit_FontMap * pFontMap) : m_pFontMap(pFontMap)
+{
+ ASSERT(m_pFontMap != NULL);
+}
+
+CFX_Edit_Provider::~CFX_Edit_Provider()
+{
+}
+
+IFX_Edit_FontMap* CFX_Edit_Provider::GetFontMap()
+{
+ return m_pFontMap;
+}
+
+FX_INT32 CFX_Edit_Provider::GetCharWidth(FX_INT32 nFontIndex, FX_WORD word, FX_INT32 nWordStyle)
+{
+ if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
+ {
+ FX_DWORD charcode = word;
+
+ if (pPDFFont->IsUnicodeCompatible())
+ charcode = pPDFFont->CharCodeFromUnicode(word);
+ else
+ charcode = m_pFontMap->CharCodeFromUnicode(nFontIndex, word);
+
+ if (charcode != -1)
+ return pPDFFont->GetCharWidthF(charcode);
+ }
+
+ return 0;
+}
+
+FX_INT32 CFX_Edit_Provider::GetTypeAscent(FX_INT32 nFontIndex)
+{
+ if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
+ return pPDFFont->GetTypeAscent();
+
+ return 0;
+}
+
+FX_INT32 CFX_Edit_Provider::GetTypeDescent(FX_INT32 nFontIndex)
+{
+ if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
+ return pPDFFont->GetTypeDescent();
+
+ return 0;
+}
+
+FX_INT32 CFX_Edit_Provider::GetWordFontIndex(FX_WORD word, FX_INT32 charset, FX_INT32 nFontIndex)
+{
+ return m_pFontMap->GetWordFontIndex(word,charset,nFontIndex);
+}
+
+FX_INT32 CFX_Edit_Provider::GetDefaultFontIndex()
+{
+ return 0;
+}
+
+FX_BOOL CFX_Edit_Provider::IsLatinWord(FX_WORD word)
+{
+ return FX_EDIT_ISLATINWORD(word);
+}
+
+/* --------------------------------- CFX_Edit_Refresh --------------------------------- */
+
+CFX_Edit_Refresh::CFX_Edit_Refresh()
+{
+}
+
+CFX_Edit_Refresh::~CFX_Edit_Refresh()
+{
+}
+
+void CFX_Edit_Refresh::BeginRefresh()
+{
+ m_RefreshRects.Empty();
+ m_OldLineRects = m_NewLineRects;
+}
+
+void CFX_Edit_Refresh::Push(const CPVT_WordRange & linerange,const CPDF_Rect & rect)
+{
+ m_NewLineRects.Add(linerange,rect);
+}
+
+void CFX_Edit_Refresh::NoAnalyse()
+{
+ {
+ for (FX_INT32 i = 0, sz = m_OldLineRects.GetSize(); i < sz; i++)
+ if (CFX_Edit_LineRect * pOldRect = m_OldLineRects.GetAt(i))
+ m_RefreshRects.Add(pOldRect->m_rcLine);
+ }
+
+ {
+ for (FX_INT32 i = 0, sz = m_NewLineRects.GetSize(); i < sz; i++)
+ if (CFX_Edit_LineRect * pNewRect = m_NewLineRects.GetAt(i))
+ m_RefreshRects.Add(pNewRect->m_rcLine);
+ }
+}
+
+void CFX_Edit_Refresh::Analyse(FX_INT32 nAlignment)
+{
+ FX_BOOL bLineTopChanged = FALSE;
+ CPDF_Rect rcResult;
+ FX_FLOAT fWidthDiff;
+
+ FX_INT32 szMax = FX_EDIT_MAX(m_OldLineRects.GetSize(),m_NewLineRects.GetSize());
+ FX_INT32 i = 0;
+
+ while (i < szMax)
+ {
+ CFX_Edit_LineRect * pOldRect = m_OldLineRects.GetAt(i);
+ CFX_Edit_LineRect * pNewRect = m_NewLineRects.GetAt(i);
+
+ if (pOldRect)
+ {
+ if (pNewRect)
+ {
+ if (bLineTopChanged)
+ {
+ rcResult = pOldRect->m_rcLine;
+ rcResult.Union(pNewRect->m_rcLine);
+ m_RefreshRects.Add(rcResult);
+ }
+ else
+ {
+ if (*pNewRect != *pOldRect)
+ {
+ if (!pNewRect->IsSameTop(*pOldRect) || !pNewRect->IsSameHeight(*pOldRect))
+ {
+ bLineTopChanged = TRUE;
+ continue;
+ }
+
+ if (nAlignment == 0)
+ {
+ if (pNewRect->m_wrLine.BeginPos != pOldRect->m_wrLine.BeginPos)
+ {
+ rcResult = pOldRect->m_rcLine;
+ rcResult.Union(pNewRect->m_rcLine);
+ m_RefreshRects.Add(rcResult);
+ }
+ else
+ {
+ if (!pNewRect->IsSameLeft(*pOldRect))
+ {
+ rcResult = pOldRect->m_rcLine;
+ rcResult.Union(pNewRect->m_rcLine);
+ }
+ else
+ {
+ fWidthDiff = pNewRect->m_rcLine.Width() - pOldRect->m_rcLine.Width();
+ rcResult = pNewRect->m_rcLine;
+ if (fWidthDiff > 0.0f)
+ rcResult.left = rcResult.right - fWidthDiff;
+ else
+ {
+ rcResult.left = rcResult.right;
+ rcResult.right += (-fWidthDiff);
+ }
+ }
+ m_RefreshRects.Add(rcResult);
+ }
+ }
+ else
+ {
+ rcResult = pOldRect->m_rcLine;
+ rcResult.Union(pNewRect->m_rcLine);
+ m_RefreshRects.Add(rcResult);
+ }
+ }
+ else
+ {
+ //don't need to do anything
+ }
+ }
+ }
+ else
+ {
+ m_RefreshRects.Add(pOldRect->m_rcLine);
+ }
+ }
+ else
+ {
+ if (pNewRect)
+ {
+ m_RefreshRects.Add(pNewRect->m_rcLine);
+ }
+ else
+ {
+ //error
+ }
+ }
+ i++;
+ }
+}
+
+void CFX_Edit_Refresh::AddRefresh(const CPDF_Rect & rect)
+{
+ m_RefreshRects.Add(rect);
+}
+
+const CFX_Edit_RectArray * CFX_Edit_Refresh::GetRefreshRects() const
+{
+ return &m_RefreshRects;
+}
+
+void CFX_Edit_Refresh::EndRefresh()
+{
+ m_RefreshRects.Empty();
+}
+
+/* ------------------------------------- CFX_Edit_Undo ------------------------------------- */
+
+CFX_Edit_Undo::CFX_Edit_Undo(FX_INT32 nBufsize) : m_nCurUndoPos(0),
+ m_nBufSize(nBufsize),
+ m_bModified(FALSE),
+ m_bVirgin(TRUE),
+ m_bWorking(FALSE)
+{
+}
+
+CFX_Edit_Undo::~CFX_Edit_Undo()
+{
+ Reset();
+}
+
+FX_BOOL CFX_Edit_Undo::CanUndo() const
+{
+ return m_nCurUndoPos > 0;
+}
+
+void CFX_Edit_Undo::Undo()
+{
+ m_bWorking = TRUE;
+
+ if (m_nCurUndoPos > 0)
+ {
+ IFX_Edit_UndoItem * pItem = m_UndoItemStack.GetAt(m_nCurUndoPos-1);
+ ASSERT(pItem != NULL);
+
+ pItem->Undo();
+
+ m_nCurUndoPos--;
+ m_bModified = (m_nCurUndoPos != 0);
+ }
+
+ m_bWorking = FALSE;
+}
+
+FX_BOOL CFX_Edit_Undo::CanRedo() const
+{
+ return m_nCurUndoPos < m_UndoItemStack.GetSize();
+}
+
+void CFX_Edit_Undo::Redo()
+{
+ m_bWorking = TRUE;
+
+ FX_INT32 nStackSize = m_UndoItemStack.GetSize();
+
+ if (m_nCurUndoPos < nStackSize)
+ {
+ IFX_Edit_UndoItem * pItem = m_UndoItemStack.GetAt(m_nCurUndoPos);
+ ASSERT(pItem != NULL);
+
+ pItem->Redo();
+
+ m_nCurUndoPos++;
+ m_bModified = (m_nCurUndoPos != 0);
+ }
+
+ m_bWorking = FALSE;
+}
+
+FX_BOOL CFX_Edit_Undo::IsWorking() const
+{
+ return m_bWorking;
+}
+
+void CFX_Edit_Undo::AddItem(IFX_Edit_UndoItem* pItem)
+{
+ ASSERT(!m_bWorking);
+ ASSERT(pItem != NULL);
+ ASSERT(m_nBufSize > 1);
+
+ if (m_nCurUndoPos < m_UndoItemStack.GetSize())
+ RemoveTails();
+
+ if (m_UndoItemStack.GetSize() >= m_nBufSize)
+ {
+ RemoveHeads();
+ m_bVirgin = FALSE;
+ }
+
+ m_UndoItemStack.Add(pItem);
+ m_nCurUndoPos = m_UndoItemStack.GetSize();
+
+ m_bModified = (m_nCurUndoPos != 0);
+}
+
+FX_BOOL CFX_Edit_Undo::IsModified() const
+{
+ if (m_bVirgin)
+ return m_bModified;
+ else
+ return TRUE;
+}
+
+IFX_Edit_UndoItem* CFX_Edit_Undo::GetItem(FX_INT32 nIndex)
+{
+ if (nIndex>=0 && nIndex < m_UndoItemStack.GetSize())
+ return m_UndoItemStack.GetAt(nIndex);
+
+ return NULL;
+}
+
+void CFX_Edit_Undo::RemoveHeads()
+{
+ ASSERT(m_UndoItemStack.GetSize() > 1);
+
+ IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(0);
+ ASSERT(pItem != NULL);
+
+ pItem->Release();
+ m_UndoItemStack.RemoveAt(0);
+}
+
+void CFX_Edit_Undo::RemoveTails()
+{
+ for (FX_INT32 i = m_UndoItemStack.GetSize()-1; i >= m_nCurUndoPos; i--)
+ {
+ IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(i);
+ ASSERT(pItem != NULL);
+
+ pItem->Release();
+ m_UndoItemStack.RemoveAt(i);
+ }
+}
+
+void CFX_Edit_Undo::Reset()
+{
+ for (FX_INT32 i=0, sz=m_UndoItemStack.GetSize(); i < sz; i++)
+ {
+ IFX_Edit_UndoItem * pItem = m_UndoItemStack.GetAt(i);
+ ASSERT(pItem != NULL);
+
+ pItem->Release();
+ }
+ m_nCurUndoPos = 0;
+ m_UndoItemStack.RemoveAll();
+}
+
+/* -------------------------------- CFX_Edit_GroupUndoItem -------------------------------- */
+
+CFX_Edit_GroupUndoItem::CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle) : m_sTitle(sTitle)
+{
+}
+
+CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem()
+{
+ for (int i=0,sz=m_Items.GetSize(); i<sz; i++)
+ {
+ CFX_Edit_UndoItem* pUndoItem = m_Items[i];
+ ASSERT(pUndoItem != NULL);
+
+ pUndoItem->Release();
+ }
+
+ m_Items.RemoveAll();
+}
+
+void CFX_Edit_GroupUndoItem::AddUndoItem(CFX_Edit_UndoItem* pUndoItem)
+{
+ ASSERT(pUndoItem != NULL);
+
+ pUndoItem->SetFirst(FALSE);
+ pUndoItem->SetLast(FALSE);
+
+ m_Items.Add(pUndoItem);
+
+ if (m_sTitle.IsEmpty())
+ m_sTitle = pUndoItem->GetUndoTitle();
+}
+
+void CFX_Edit_GroupUndoItem::UpdateItems()
+{
+ if (m_Items.GetSize() > 0)
+ {
+ CFX_Edit_UndoItem* pFirstItem = m_Items[0];
+ ASSERT(pFirstItem != NULL);
+ pFirstItem->SetFirst(TRUE);
+
+ CFX_Edit_UndoItem* pLastItem = m_Items[m_Items.GetSize() - 1];
+ ASSERT(pLastItem != NULL);
+ pLastItem->SetLast(TRUE);
+ }
+}
+
+void CFX_Edit_GroupUndoItem::Undo()
+{
+ for (int i=m_Items.GetSize()-1; i>=0; i--)
+ {
+ CFX_Edit_UndoItem* pUndoItem = m_Items[i];
+ ASSERT(pUndoItem != NULL);
+
+ pUndoItem->Undo();
+ }
+}
+
+void CFX_Edit_GroupUndoItem::Redo()
+{
+ for (int i=0,sz=m_Items.GetSize(); i<sz; i++)
+ {
+ CFX_Edit_UndoItem* pUndoItem = m_Items[i];
+ ASSERT(pUndoItem != NULL);
+
+ pUndoItem->Redo();
+ }
+}
+
+CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle()
+{
+ return m_sTitle;
+}
+
+void CFX_Edit_GroupUndoItem::Release()
+{
+ delete this;
+}
+
+/* ------------------------------------- CFX_Edit_UndoItem derived classes ------------------------------------- */
+
+CFXEU_InsertWord::CFXEU_InsertWord(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
+ FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps)
+ : m_pEdit(pEdit), m_wpOld(wpOldPlace), m_wpNew(wpNewPlace), m_Word(word), m_nCharset(charset), m_WordProps()
+{
+ if (pWordProps)
+ m_WordProps = *pWordProps;
+}
+
+CFXEU_InsertWord::~CFXEU_InsertWord()
+{
+}
+
+void CFXEU_InsertWord::Redo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpOld);
+ m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,TRUE);
+ }
+}
+
+void CFXEU_InsertWord::Undo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpNew);
+ m_pEdit->Backspace(FALSE,TRUE);
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+
+CFXEU_InsertReturn::CFXEU_InsertReturn(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
+ const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps) :
+ m_pEdit(pEdit),
+ m_wpOld(wpOldPlace),
+ m_wpNew(wpNewPlace),
+ m_SecProps(),
+ m_WordProps()
+{
+ if (pSecProps)
+ m_SecProps = *pSecProps;
+ if (pWordProps)
+ m_WordProps = *pWordProps;
+}
+
+CFXEU_InsertReturn::~CFXEU_InsertReturn()
+{
+}
+
+void CFXEU_InsertReturn::Redo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpOld);
+ m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,TRUE);
+ }
+}
+
+void CFXEU_InsertReturn::Undo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpNew);
+ m_pEdit->Backspace(FALSE,TRUE);
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+//CFXEU_Backspace
+
+CFXEU_Backspace::CFXEU_Backspace(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
+ FX_WORD word, FX_INT32 charset,
+ const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps) :
+ m_pEdit(pEdit),
+ m_wpOld(wpOldPlace),
+ m_wpNew(wpNewPlace),
+ m_Word(word),
+ m_nCharset(charset),
+ m_SecProps(SecProps),
+ m_WordProps(WordProps)
+{
+}
+
+CFXEU_Backspace::~CFXEU_Backspace()
+{
+}
+
+void CFXEU_Backspace::Redo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpOld);
+ m_pEdit->Backspace(FALSE,TRUE);
+ }
+}
+
+void CFXEU_Backspace::Undo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpNew);
+ if (m_wpNew.SecCmp(m_wpOld) != 0)
+ {
+ m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,TRUE);
+ }
+ else
+ {
+ m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,TRUE);
+ }
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+//CFXEU_Delete
+
+CFXEU_Delete::CFXEU_Delete(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
+ FX_WORD word, FX_INT32 charset,
+ const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps, FX_BOOL bSecEnd) :
+ m_pEdit(pEdit),
+ m_wpOld(wpOldPlace),
+ m_wpNew(wpNewPlace),
+ m_Word(word),
+ m_nCharset(charset),
+ m_SecProps(SecProps),
+ m_WordProps(WordProps),
+ m_bSecEnd(bSecEnd)
+{
+}
+
+CFXEU_Delete::~CFXEU_Delete()
+{
+}
+
+void CFXEU_Delete::Redo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpOld);
+ m_pEdit->Delete(FALSE,TRUE);
+ }
+}
+
+void CFXEU_Delete::Undo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpNew);
+ if (m_bSecEnd)
+ {
+ m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,TRUE);
+ }
+ else
+ {
+ m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,TRUE);
+ }
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+//CFXEU_Clear
+
+CFXEU_Clear::CFXEU_Clear(CFX_Edit * pEdit, const CPVT_WordRange & wrSel, const CFX_WideString & swText) :
+ m_pEdit(pEdit),
+ m_wrSel(wrSel),
+ m_swText(swText)
+{
+}
+
+CFXEU_Clear::~CFXEU_Clear()
+{
+}
+
+void CFXEU_Clear::Redo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos);
+ m_pEdit->Clear(FALSE,TRUE);
+ }
+}
+
+void CFXEU_Clear::Undo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wrSel.BeginPos);
+ m_pEdit->InsertText(m_swText, DEFAULT_CHARSET, NULL,NULL,FALSE,TRUE);
+ m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos);
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+//CFXEU_ClearRich
+
+CFXEU_ClearRich::CFXEU_ClearRich(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
+ const CPVT_WordRange & wrSel, FX_WORD word, FX_INT32 charset,
+ const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps) :
+ m_pEdit(pEdit),
+ m_wpOld(wpOldPlace),
+ m_wpNew(wpNewPlace),
+ m_wrSel(wrSel),
+ m_Word(word),
+ m_nCharset(charset),
+ m_SecProps(SecProps),
+ m_WordProps(WordProps)
+{
+}
+
+CFXEU_ClearRich::~CFXEU_ClearRich()
+{
+}
+
+void CFXEU_ClearRich::Redo()
+{
+ if (m_pEdit && IsLast())
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos);
+ m_pEdit->Clear(FALSE,TRUE);
+ }
+}
+
+void CFXEU_ClearRich::Undo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpOld);
+ if (m_wpNew.SecCmp(m_wpOld) != 0)
+ {
+ m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,FALSE);
+ }
+ else
+ {
+ m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,FALSE);
+ }
+
+ if (IsFirst())
+ {
+ m_pEdit->PaintInsertText(m_wrSel.BeginPos,m_wrSel.EndPos);
+ m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos);
+ }
+ }
+}
+/* -------------------------------------------------------------------------- */
+//CFXEU_InsertText
+
+CFXEU_InsertText::CFXEU_InsertText(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
+ const CFX_WideString & swText, FX_INT32 charset,
+ const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps) :
+ m_pEdit(pEdit),
+ m_wpOld(wpOldPlace),
+ m_wpNew(wpNewPlace),
+ m_swText(swText),
+ m_nCharset(charset),
+ m_SecProps(),
+ m_WordProps()
+{
+ if (pSecProps)
+ m_SecProps = *pSecProps;
+ if (pWordProps)
+ m_WordProps = *pWordProps;
+}
+
+CFXEU_InsertText::~CFXEU_InsertText()
+{
+}
+
+void CFXEU_InsertText::Redo()
+{
+ if (m_pEdit && IsLast())
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpOld);
+ m_pEdit->InsertText(m_swText, m_nCharset,&m_SecProps, &m_WordProps,FALSE,TRUE);
+ }
+}
+
+void CFXEU_InsertText::Undo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->SetSel(m_wpOld,m_wpNew);
+ m_pEdit->Clear(FALSE,TRUE);
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+
+CFXEU_SetSecProps::CFXEU_SetSecProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep,
+ const CPVT_SecProps & oldsecprops, const CPVT_WordProps & oldwordprops,
+ const CPVT_SecProps & newsecprops, const CPVT_WordProps & newwordprops, const CPVT_WordRange & range)
+ : m_pEdit(pEdit),
+ m_wpPlace(place),
+ m_eProps(ep),
+ m_OldSecProps(oldsecprops),
+ m_NewSecProps(newsecprops),
+ m_OldWordProps(oldwordprops),
+ m_NewWordProps(newwordprops),
+ m_wrPlace(range)
+{
+}
+
+CFXEU_SetSecProps::~CFXEU_SetSecProps()
+{
+}
+
+void CFXEU_SetSecProps::Redo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SetSecProps(m_eProps,m_wpPlace,&m_NewSecProps,&m_NewWordProps,m_wrPlace,FALSE);
+ if (IsLast())
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->PaintSetProps(m_eProps,m_wrPlace);
+ m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos);
+ }
+ }
+}
+
+void CFXEU_SetSecProps::Undo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SetSecProps(m_eProps,m_wpPlace,&m_OldSecProps,&m_OldWordProps,m_wrPlace,FALSE);
+ if (IsFirst())
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->PaintSetProps(m_eProps,m_wrPlace);
+ m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos);
+ }
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+
+CFXEU_SetWordProps::CFXEU_SetWordProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep,
+ const CPVT_WordProps & oldprops, const CPVT_WordProps & newprops, const CPVT_WordRange & range)
+ : m_pEdit(pEdit),
+ m_wpPlace(place),
+ m_eProps(ep),
+ m_OldWordProps(oldprops),
+ m_NewWordProps(newprops),
+ m_wrPlace(range)
+{
+}
+
+CFXEU_SetWordProps::~CFXEU_SetWordProps()
+{
+}
+
+void CFXEU_SetWordProps::Redo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SetWordProps(m_eProps,m_wpPlace,&m_NewWordProps,m_wrPlace,FALSE);
+ if (IsLast())
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->PaintSetProps(m_eProps,m_wrPlace);
+ m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos);
+ }
+ }
+}
+
+void CFXEU_SetWordProps::Undo()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SetWordProps(m_eProps,m_wpPlace,&m_OldWordProps,m_wrPlace,FALSE);
+ if (IsFirst())
+ {
+ m_pEdit->SelectNone();
+ m_pEdit->PaintSetProps(m_eProps,m_wrPlace);
+ m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos);
+ }
+ }
+}
+
+/* ------------------------------------- CFX_Edit ------------------------------------- */
+
+CFX_Edit::CFX_Edit(IPDF_VariableText * pVT) :
+ m_pVT(pVT),
+ m_pNotify(NULL),
+ m_pOprNotify(NULL),
+ m_wpCaret(-1,-1,-1),
+ m_wpOldCaret(-1,-1,-1),
+ m_ptScrollPos(0,0),
+ m_ptRefreshScrollPos(0,0),
+ m_bEnableScroll(FALSE),
+ m_bEnableOverflow(FALSE),
+ m_pVTProvide(NULL),
+ m_pIterator(NULL),
+ m_SelState(),
+ m_ptCaret(0.0f,0.0f),
+ m_Undo(FX_EDIT_UNDO_MAXITEM),
+ m_nAlignment(0),
+ m_bNotifyFlag(FALSE),
+ m_bEnableRefresh(TRUE),
+ m_rcOldContent(0.0f,0.0f,0.0f,0.0f),
+ m_bEnableUndo(TRUE),
+ m_bNotify(TRUE),
+ m_bOprNotify(FALSE),
+ m_pGroupUndoItem(NULL)
+{
+ ASSERT(pVT != NULL);
+}
+
+CFX_Edit::~CFX_Edit()
+{
+ if (m_pVTProvide)
+ {
+ delete m_pVTProvide;
+ m_pVTProvide = NULL;
+ }
+
+ if (m_pIterator)
+ {
+ delete m_pIterator;
+ m_pIterator = NULL;
+ }
+
+ ASSERT(m_pGroupUndoItem == NULL);
+}
+
+// public methods
+
+void CFX_Edit::Initialize()
+{
+ m_pVT->Initialize();
+ SetCaret(m_pVT->GetBeginWordPlace());
+ SetCaretOrigin();
+}
+
+void CFX_Edit::SetFontMap(IFX_Edit_FontMap * pFontMap)
+{
+ if (m_pVTProvide)
+ delete m_pVTProvide;
+
+ m_pVT->SetProvider(m_pVTProvide = new CFX_Edit_Provider(pFontMap));
+}
+
+void CFX_Edit::SetVTProvider(IPDF_VariableText_Provider* pProvider)
+{
+ m_pVT->SetProvider(pProvider);
+}
+
+void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify)
+{
+ m_pNotify = pNotify;
+}
+
+void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify)
+{
+ m_pOprNotify = pOprNotify;
+}
+
+IFX_Edit_Iterator * CFX_Edit::GetIterator()
+{
+ if (!m_pIterator)
+ m_pIterator = new CFX_Edit_Iterator(this,m_pVT->GetIterator());
+
+ return m_pIterator;
+}
+
+IPDF_VariableText * CFX_Edit::GetVariableText()
+{
+ return m_pVT;
+}
+
+IFX_Edit_FontMap* CFX_Edit::GetFontMap()
+{
+ if (m_pVTProvide)
+ return m_pVTProvide->GetFontMap();
+
+ return NULL;
+}
+
+void CFX_Edit::SetPlateRect(const CPDF_Rect & rect, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetPlateRect(rect);
+ m_ptScrollPos = CPDF_Point(rect.left,rect.top);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetAlignmentH(FX_INT32 nFormat/* =0 */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetAlignment(nFormat);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetAlignmentV(FX_INT32 nFormat/* =0 */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_nAlignment = nFormat;
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetPasswordChar(FX_WORD wSubWord/* ='*' */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetPasswordChar(wSubWord);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetLimitChar(FX_INT32 nLimitChar/* =0 */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetLimitChar(nLimitChar);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetCharArray(FX_INT32 nCharArray/* =0 */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetCharArray(nCharArray);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetCharSpace(FX_FLOAT fCharSpace/* =0.0f */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetCharSpace(fCharSpace);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetHorzScale(FX_INT32 nHorzScale/* =100 */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetHorzScale(nHorzScale);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetMultiLine(FX_BOOL bMultiLine/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetMultiLine(bMultiLine);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetAutoReturn(FX_BOOL bAuto/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetAutoReturn(bAuto);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetLineLeading(FX_FLOAT fLineLeading/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetLineLeading(fLineLeading);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetAutoFontSize(FX_BOOL bAuto/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetAutoFontSize(bAuto);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetFontSize(FX_FLOAT fFontSize, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetFontSize(fFontSize);
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetAutoScroll(FX_BOOL bAuto/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_bEnableScroll = bAuto;
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetTextOverflow(FX_BOOL bAllowed /*= FALSE*/, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_bEnableOverflow = bAllowed;
+ if (bPaint) Paint();
+}
+
+void CFX_Edit::SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar)
+{
+ if (m_pVT->IsValid())
+ {
+ if (nStartChar == 0 && nEndChar < 0)
+ {
+ SelectAll();
+ }
+ else if (nStartChar < 0)
+ {
+ this->SelectNone();
+ }
+ else
+ {
+ if (nStartChar < nEndChar)
+ {
+ SetSel(m_pVT->WordIndexToWordPlace(nStartChar),m_pVT->WordIndexToWordPlace(nEndChar));
+ }
+ else
+ {
+ SetSel(m_pVT->WordIndexToWordPlace(nEndChar),m_pVT->WordIndexToWordPlace(nStartChar));
+ }
+ }
+ }
+}
+
+void CFX_Edit::SetSel(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)
+{
+ if (m_pVT->IsValid())
+ {
+ SelectNone();
+
+ m_SelState.Set(begin,end);
+
+ SetCaret(m_SelState.EndPos);
+
+ if (m_SelState.IsExist())
+ {
+ ScrollToCaret();
+ CPVT_WordRange wr(m_SelState.BeginPos,m_SelState.EndPos);
+ Refresh(RP_OPTIONAL,&wr);
+ SetCaretInfo();
+ }
+ else
+ {
+ ScrollToCaret();
+ SetCaretInfo();
+ }
+ }
+}
+
+void CFX_Edit::GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
+{
+ nStartChar = -1;
+ nEndChar = -1;
+
+ if (m_pVT->IsValid())
+ {
+ if (m_SelState.IsExist())
+ {
+ if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)<0)
+ {
+ nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
+ nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
+ }
+ else
+ {
+ nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
+ nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
+ }
+ }
+ else
+ {
+ nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
+ nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
+ }
+ }
+}
+
+FX_INT32 CFX_Edit::GetCaret() const
+{
+ if (m_pVT->IsValid())
+ return m_pVT->WordPlaceToWordIndex(m_wpCaret);
+
+ return -1;
+}
+
+CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const
+{
+ return m_wpCaret;
+}
+
+CFX_WideString CFX_Edit::GetText() const
+{
+ CFX_WideString swRet;
+
+ if (m_pVT->IsValid())
+ {
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ FX_BOOL bRich = m_pVT->IsRichText();
+
+ pIterator->SetAt(0);
+
+ CPVT_Word wordinfo;
+ CPVT_WordPlace oldplace = pIterator->GetAt();
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+
+ if (pIterator->GetWord(wordinfo))
+ {
+ if (bRich)
+ {
+ swRet += wordinfo.Word;
+ }
+ else
+ {
+ swRet += wordinfo.Word;
+ }
+ }
+
+ if (oldplace.SecCmp(place) != 0)
+ {
+ swRet += 0x0D;
+ swRet += 0x0A;
+ }
+
+ oldplace = place;
+ }
+ }
+ }
+
+ return swRet;
+}
+
+CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange & range) const
+{
+ CFX_WideString swRet;
+
+ if (m_pVT->IsValid())
+ {
+ FX_BOOL bRich = m_pVT->IsRichText();
+
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ CPVT_WordRange wrTemp = range;
+ m_pVT->UpdateWordPlace(wrTemp.BeginPos);
+ m_pVT->UpdateWordPlace(wrTemp.EndPos);
+ pIterator->SetAt(wrTemp.BeginPos);
+
+ CPVT_Word wordinfo;
+ CPVT_WordPlace oldplace = wrTemp.BeginPos;
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (place.WordCmp(wrTemp.EndPos) > 0)break;
+
+ if (pIterator->GetWord(wordinfo))
+ {
+ if (bRich)
+ {
+ swRet += wordinfo.Word;
+ }
+ else
+ {
+ swRet += wordinfo.Word;
+ }
+ }
+
+ if (oldplace.SecCmp(place) != 0)
+ {
+ swRet += 0x0D;
+ swRet += 0x0A;
+ }
+
+ oldplace = place;
+ }
+ }
+ }
+
+ return swRet;
+}
+
+CFX_WideString CFX_Edit::GetSelText() const
+{
+ return GetRangeText(m_SelState.ConvertToWordRange());
+}
+
+FX_INT32 CFX_Edit::GetTotalWords() const
+{
+ return m_pVT->GetTotalWords();
+}
+
+FX_INT32 CFX_Edit::GetTotalLines() const
+{
+ FX_INT32 nLines = 0;
+
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ pIterator->SetAt(0);
+ while (pIterator->NextLine())
+ nLines++;
+ }
+
+ return nLines+1;
+}
+
+CPVT_WordRange CFX_Edit::GetSelectWordRange() const
+{
+ return m_SelState.ConvertToWordRange();
+}
+
+CPVT_WordRange CFX_Edit::CombineWordRange(const CPVT_WordRange & wr1, const CPVT_WordRange & wr2)
+{
+ CPVT_WordRange wrRet;
+
+ if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0)
+ {
+ wrRet.BeginPos = wr1.BeginPos;
+ }
+ else
+ {
+ wrRet.BeginPos = wr2.BeginPos;
+ }
+
+ if (wr1.EndPos.WordCmp(wr2.EndPos) < 0)
+ {
+ wrRet.EndPos = wr2.EndPos;
+ }
+ else
+ {
+ wrRet.EndPos = wr1.EndPos;
+ }
+
+ return wrRet;
+}
+
+FX_BOOL CFX_Edit::IsRichText() const
+{
+ return m_pVT->IsRichText();
+}
+
+void CFX_Edit::SetRichText(FX_BOOL bRichText/* =TRUE */, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pVT->SetRichText(bRichText);
+ if (bPaint) Paint();
+}
+
+FX_BOOL CFX_Edit::SetRichFontIndex(FX_INT32 nFontIndex)
+{
+ CPVT_WordProps WordProps;
+ WordProps.nFontIndex = nFontIndex;
+ return SetRichTextProps(EP_FONTINDEX,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichFontSize(FX_FLOAT fFontSize)
+{
+ CPVT_WordProps WordProps;
+ WordProps.fFontSize = fFontSize;
+ return SetRichTextProps(EP_FONTSIZE,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichTextColor(FX_COLORREF dwColor)
+{
+ CPVT_WordProps WordProps;
+ WordProps.dwWordColor = dwColor;
+ return SetRichTextProps(EP_WORDCOLOR,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichTextScript(FX_INT32 nScriptType)
+{
+ CPVT_WordProps WordProps;
+ WordProps.nScriptType = nScriptType;
+ return SetRichTextProps(EP_SCRIPTTYPE,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichTextBold(FX_BOOL bBold)
+{
+ CPVT_WordProps WordProps;
+ if (bBold)
+ WordProps.nWordStyle |= PVTWORD_STYLE_BOLD;
+ return SetRichTextProps(EP_BOLD,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichTextItalic(FX_BOOL bItalic)
+{
+ CPVT_WordProps WordProps;
+ if (bItalic)
+ WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC;
+ return SetRichTextProps(EP_ITALIC,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichTextUnderline(FX_BOOL bUnderline)
+{
+ CPVT_WordProps WordProps;
+ if (bUnderline)
+ WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE;
+ return SetRichTextProps(EP_UNDERLINE,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichTextCrossout(FX_BOOL bCrossout)
+{
+ CPVT_WordProps WordProps;
+ if (bCrossout)
+ WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT;
+ return SetRichTextProps(EP_CROSSOUT,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichTextCharSpace(FX_FLOAT fCharSpace)
+{
+ CPVT_WordProps WordProps;
+ WordProps.fCharSpace = fCharSpace;
+ return SetRichTextProps(EP_CHARSPACE,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichTextHorzScale(FX_INT32 nHorzScale /*= 100*/)
+{
+ CPVT_WordProps WordProps;
+ WordProps.nHorzScale = nHorzScale;
+ return SetRichTextProps(EP_HORZSCALE,NULL,&WordProps);
+}
+
+FX_BOOL CFX_Edit::SetRichTextLineLeading(FX_FLOAT fLineLeading)
+{
+ CPVT_SecProps SecProps;
+ SecProps.fLineLeading = fLineLeading;
+ return SetRichTextProps(EP_LINELEADING,&SecProps,NULL);
+}
+
+FX_BOOL CFX_Edit::SetRichTextLineIndent(FX_FLOAT fLineIndent)
+{
+ CPVT_SecProps SecProps;
+ SecProps.fLineIndent = fLineIndent;
+ return SetRichTextProps(EP_LINEINDENT,&SecProps,NULL);
+}
+
+FX_BOOL CFX_Edit::SetRichTextAlignment(FX_INT32 nAlignment)
+{
+ CPVT_SecProps SecProps;
+ SecProps.nAlignment = nAlignment;
+ return SetRichTextProps(EP_ALIGNMENT,&SecProps,NULL);
+}
+
+FX_BOOL CFX_Edit::SetRichTextProps(EDIT_PROPS_E eProps, const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps)
+{
+ FX_BOOL bSet = FALSE;
+ FX_BOOL bSet1,bSet2;
+ if (m_pVT->IsValid() && m_pVT->IsRichText())
+ {
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange();
+
+ m_pVT->UpdateWordPlace(wrTemp.BeginPos);
+ m_pVT->UpdateWordPlace(wrTemp.EndPos);
+ pIterator->SetAt(wrTemp.BeginPos);
+
+ BeginGroupUndo(L"");;
+
+ bSet = SetSecProps(eProps,wrTemp.BeginPos,pSecProps,pWordProps,wrTemp,TRUE);
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (place.WordCmp(wrTemp.EndPos) > 0) break;
+ bSet1 = SetSecProps(eProps,place,pSecProps,pWordProps,wrTemp,TRUE);
+ bSet2 = SetWordProps(eProps,place,pWordProps,wrTemp,TRUE);
+
+ if (!bSet)
+ bSet = (bSet1 || bSet2);
+ }
+
+ EndGroupUndo();
+
+ if (bSet)
+ {
+ PaintSetProps(eProps,wrTemp);
+ }
+ }
+ }
+
+ return bSet;
+}
+
+void CFX_Edit::PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange & wr)
+{
+ switch(eProps)
+ {
+ case EP_LINELEADING:
+ case EP_LINEINDENT:
+ case EP_ALIGNMENT:
+ RearrangePart(wr);
+ ScrollToCaret();
+ Refresh(RP_ANALYSE);
+ SetCaretOrigin();
+ SetCaretInfo();
+ break;
+ case EP_WORDCOLOR:
+ case EP_UNDERLINE:
+ case EP_CROSSOUT:
+ Refresh(RP_OPTIONAL,&wr);
+ break;
+ case EP_FONTINDEX:
+ case EP_FONTSIZE:
+ case EP_SCRIPTTYPE:
+ case EP_CHARSPACE:
+ case EP_HORZSCALE:
+ case EP_BOLD:
+ case EP_ITALIC:
+ RearrangePart(wr);
+ ScrollToCaret();
+
+ CPVT_WordRange wrRefresh(m_pVT->GetSectionBeginPlace(wr.BeginPos),
+ m_pVT->GetSectionEndPlace(wr.EndPos));
+ Refresh(RP_ANALYSE,&wrRefresh);
+
+ SetCaretOrigin();
+ SetCaretInfo();
+ break;
+ }
+}
+
+FX_BOOL CFX_Edit::SetSecProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place,
+ const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps,
+ const CPVT_WordRange & wr, FX_BOOL bAddUndo)
+{
+ if (m_pVT->IsValid() && m_pVT->IsRichText())
+ {
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ FX_BOOL bSet = FALSE;
+ CPVT_Section secinfo;
+ CPVT_Section OldSecinfo;
+
+ CPVT_WordPlace oldplace = pIterator->GetAt();
+
+ if (eProps == EP_LINELEADING || eProps == EP_LINEINDENT || eProps == EP_ALIGNMENT)
+ {
+ if (pSecProps)
+ {
+ pIterator->SetAt(place);
+ if (pIterator->GetSection(secinfo))
+ {
+ if (bAddUndo) OldSecinfo = secinfo;
+
+ switch(eProps)
+ {
+ case EP_LINELEADING:
+ if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineLeading,pSecProps->fLineLeading))
+ {
+ secinfo.SecProps.fLineLeading = pSecProps->fLineLeading;
+ bSet = TRUE;
+ }
+ break;
+ case EP_LINEINDENT:
+ if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineIndent,pSecProps->fLineIndent))
+ {
+ secinfo.SecProps.fLineIndent = pSecProps->fLineIndent;
+ bSet = TRUE;
+ }
+ break;
+ case EP_ALIGNMENT:
+ if (secinfo.SecProps.nAlignment != pSecProps->nAlignment)
+ {
+ secinfo.SecProps.nAlignment = pSecProps->nAlignment;
+ bSet = TRUE;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ if (pWordProps && place == m_pVT->GetSectionBeginPlace(place))
+ {
+ pIterator->SetAt(place);
+ if (pIterator->GetSection(secinfo))
+ {
+ if (bAddUndo) OldSecinfo = secinfo;
+
+ switch(eProps)
+ {
+ case EP_FONTINDEX:
+ if (secinfo.WordProps.nFontIndex != pWordProps->nFontIndex)
+ {
+ secinfo.WordProps.nFontIndex = pWordProps->nFontIndex;
+ bSet = TRUE;
+ }
+ break;
+ case EP_FONTSIZE:
+ if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fFontSize,pWordProps->fFontSize))
+ {
+ secinfo.WordProps.fFontSize = pWordProps->fFontSize;
+ bSet = TRUE;
+ }
+ break;
+ case EP_WORDCOLOR:
+ if (secinfo.WordProps.dwWordColor != pWordProps->dwWordColor)
+ {
+ secinfo.WordProps.dwWordColor = pWordProps->dwWordColor;
+ bSet = TRUE;
+ }
+ break;
+ case EP_SCRIPTTYPE:
+ if (secinfo.WordProps.nScriptType != pWordProps->nScriptType)
+ {
+ secinfo.WordProps.nScriptType = pWordProps->nScriptType;
+ bSet = TRUE;
+ }
+ break;
+ case EP_CHARSPACE:
+ if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fCharSpace,pWordProps->fCharSpace))
+ {
+ secinfo.WordProps.fCharSpace = pWordProps->fCharSpace;
+ bSet = TRUE;
+ }
+ break;
+ case EP_HORZSCALE:
+ if (secinfo.WordProps.nHorzScale != pWordProps->nHorzScale)
+ {
+ secinfo.WordProps.nHorzScale = pWordProps->nHorzScale;
+ bSet = TRUE;
+ }
+ break;
+ case EP_UNDERLINE:
+ if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE)
+ {
+ if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == 0)
+ {
+ secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE;
+ bSet = TRUE;
+ }
+ }
+ else
+ {
+ if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != 0)
+ {
+ secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE;
+ bSet = TRUE;
+ }
+ }
+ break;
+ case EP_CROSSOUT:
+ if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT)
+ {
+ if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == 0)
+ {
+ secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT;
+ bSet = TRUE;
+ }
+ }
+ else
+ {
+ if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != 0)
+ {
+ secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT;
+ bSet = TRUE;
+ }
+ }
+ break;
+ case EP_BOLD:
+ if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD)
+ {
+ if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0)
+ {
+ secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD;
+ bSet = TRUE;
+ }
+ }
+ else
+ {
+ if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0)
+ {
+ secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD;
+ bSet = TRUE;
+ }
+ }
+ break;
+ case EP_ITALIC:
+ if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC)
+ {
+ if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0)
+ {
+ secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC;
+ bSet = TRUE;
+ }
+ }
+ else
+ {
+ if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0)
+ {
+ secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC;
+ bSet = TRUE;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+
+ if (bSet)
+ {
+ pIterator->SetSection(secinfo);
+
+ if (bAddUndo && m_bEnableUndo)
+ {
+ AddEditUndoItem(new CFXEU_SetSecProps
+ (this,place,eProps,OldSecinfo.SecProps,OldSecinfo.WordProps,secinfo.SecProps,secinfo.WordProps,wr));
+ }
+ }
+
+ pIterator->SetAt(oldplace);
+
+ return bSet;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::SetWordProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place,
+ const CPVT_WordProps * pWordProps, const CPVT_WordRange & wr, FX_BOOL bAddUndo)
+{
+ if (m_pVT->IsValid() && m_pVT->IsRichText())
+ {
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ FX_BOOL bSet = FALSE;
+ CPVT_Word wordinfo;
+ CPVT_Word OldWordinfo;
+
+ CPVT_WordPlace oldplace = pIterator->GetAt();
+
+ if (pWordProps)
+ {
+ pIterator->SetAt(place);
+ if (pIterator->GetWord(wordinfo))
+ {
+ if (bAddUndo) OldWordinfo = wordinfo;
+
+ switch(eProps)
+ {
+ case EP_FONTINDEX:
+ if (wordinfo.WordProps.nFontIndex != pWordProps->nFontIndex)
+ {
+ if (IFX_Edit_FontMap* pFontMap = this->GetFontMap())
+ {
+ wordinfo.WordProps.nFontIndex = pFontMap->GetWordFontIndex(wordinfo.Word,wordinfo.nCharset,pWordProps->nFontIndex);
+ }
+ bSet = TRUE;
+ }
+ break;
+ case EP_FONTSIZE:
+ if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fFontSize,pWordProps->fFontSize))
+ {
+ wordinfo.WordProps.fFontSize = pWordProps->fFontSize;
+ bSet = TRUE;
+ }
+ break;
+ case EP_WORDCOLOR:
+ if (wordinfo.WordProps.dwWordColor != pWordProps->dwWordColor)
+ {
+ wordinfo.WordProps.dwWordColor = pWordProps->dwWordColor;
+ bSet = TRUE;
+ }
+ break;
+ case EP_SCRIPTTYPE:
+ if (wordinfo.WordProps.nScriptType != pWordProps->nScriptType)
+ {
+ wordinfo.WordProps.nScriptType = pWordProps->nScriptType;
+ bSet = TRUE;
+ }
+ break;
+ case EP_CHARSPACE:
+ if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fCharSpace,pWordProps->fCharSpace))
+ {
+ wordinfo.WordProps.fCharSpace = pWordProps->fCharSpace;
+ bSet = TRUE;
+ }
+ break;
+ case EP_HORZSCALE:
+ if (wordinfo.WordProps.nHorzScale != pWordProps->nHorzScale)
+ {
+ wordinfo.WordProps.nHorzScale = pWordProps->nHorzScale;
+ bSet = TRUE;
+ }
+ break;
+ case EP_UNDERLINE:
+ if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE)
+ {
+ if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == 0)
+ {
+ wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE;
+ bSet = TRUE;
+ }
+ }
+ else
+ {
+ if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != 0)
+ {
+ wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE;
+ bSet = TRUE;
+ }
+ }
+ break;
+ case EP_CROSSOUT:
+ if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT)
+ {
+ if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == 0)
+ {
+ wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT;
+ bSet = TRUE;
+ }
+ }
+ else
+ {
+ if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != 0)
+ {
+ wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT;
+ bSet = TRUE;
+ }
+ }
+ break;
+ case EP_BOLD:
+ if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD)
+ {
+ if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0)
+ {
+ wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD;
+ bSet = TRUE;
+ }
+ }
+ else
+ {
+ if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0)
+ {
+ wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD;
+ bSet = TRUE;
+ }
+ }
+ break;
+ case EP_ITALIC:
+ if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC)
+ {
+ if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0)
+ {
+ wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC;
+ bSet = TRUE;
+ }
+ }
+ else
+ {
+ if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0)
+ {
+ wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC;
+ bSet = TRUE;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ if (bSet)
+ {
+ pIterator->SetWord(wordinfo);
+
+ if (bAddUndo && m_bEnableUndo)
+ {
+ AddEditUndoItem(new CFXEU_SetWordProps
+ (this,place,eProps,OldWordinfo.WordProps,wordinfo.WordProps,wr));
+ }
+ }
+
+ pIterator->SetAt(oldplace);
+ return bSet;
+ }
+ }
+
+ return FALSE;
+}
+
+void CFX_Edit::SetText(FX_LPCWSTR text,FX_INT32 charset /*= DEFAULT_CHARSET*/,
+ const CPVT_SecProps * pSecProps /*= NULL*/,const CPVT_WordProps * pWordProps /*= NULL*/)
+{
+ SetText(text,charset,pSecProps,pWordProps,TRUE,TRUE);
+}
+
+FX_BOOL CFX_Edit::InsertWord(FX_WORD word, FX_INT32 charset /*= DEFAULT_CHARSET*/, const CPVT_WordProps * pWordProps /*= NULL*/)
+{
+ return InsertWord(word,charset,pWordProps,TRUE,TRUE);
+}
+
+FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps * pSecProps /*= NULL*/,const CPVT_WordProps * pWordProps /*= NULL*/)
+{
+ return InsertReturn(pSecProps,pWordProps,TRUE,TRUE);
+}
+
+FX_BOOL CFX_Edit::Backspace()
+{
+ return Backspace(TRUE,TRUE);
+}
+
+FX_BOOL CFX_Edit::Delete()
+{
+ return Delete(TRUE,TRUE);
+}
+
+FX_BOOL CFX_Edit::Clear()
+{
+ return Clear(TRUE,TRUE);
+}
+
+FX_BOOL CFX_Edit::InsertText(FX_LPCWSTR text, FX_INT32 charset /*= DEFAULT_CHARSET*/,
+ const CPVT_SecProps * pSecProps /*= NULL*/,const CPVT_WordProps * pWordProps /*= NULL*/)
+{
+ return InsertText(text,charset,pSecProps,pWordProps,TRUE,TRUE);
+}
+
+FX_FLOAT CFX_Edit::GetFontSize() const
+{
+ return m_pVT->GetFontSize();
+}
+
+FX_WORD CFX_Edit::GetPasswordChar() const
+{
+ return m_pVT->GetPasswordChar();
+}
+
+FX_INT32 CFX_Edit::GetCharArray() const
+{
+ return m_pVT->GetCharArray();
+}
+
+CPDF_Rect CFX_Edit::GetPlateRect() const
+{
+ return m_pVT->GetPlateRect();
+}
+
+CPDF_Rect CFX_Edit::GetContentRect() const
+{
+ return VTToEdit(m_pVT->GetContentRect());
+}
+
+FX_INT32 CFX_Edit::GetHorzScale() const
+{
+ return m_pVT->GetHorzScale();
+}
+
+FX_FLOAT CFX_Edit::GetCharSpace() const
+{
+ return m_pVT->GetCharSpace();
+}
+
+// inner methods
+
+CPVT_WordRange CFX_Edit::GetWholeWordRange() const
+{
+ if (m_pVT->IsValid())
+ return CPVT_WordRange(m_pVT->GetBeginWordPlace(),m_pVT->GetEndWordPlace());
+
+ return CPVT_WordRange();
+}
+
+CPVT_WordRange CFX_Edit::GetVisibleWordRange() const
+{
+ if (m_bEnableOverflow) return GetWholeWordRange();
+
+ if (m_pVT->IsValid())
+ {
+ CPDF_Rect rcPlate = m_pVT->GetPlateRect();
+
+ CPVT_WordPlace place1 = m_pVT->SearchWordPlace(EditToVT(CPDF_Point(rcPlate.left,rcPlate.top)));
+ CPVT_WordPlace place2 = m_pVT->SearchWordPlace(EditToVT(CPDF_Point(rcPlate.right,rcPlate.bottom)));
+
+ return CPVT_WordRange(place1,place2);
+ }
+
+ return CPVT_WordRange();
+}
+
+CPVT_WordPlace CFX_Edit::SearchWordPlace(const CPDF_Point& point) const
+{
+ if (m_pVT->IsValid())
+ {
+ return m_pVT->SearchWordPlace(EditToVT(point));
+ }
+
+ return CPVT_WordPlace();
+}
+
+void CFX_Edit::Paint()
+{
+ if (m_pVT->IsValid())
+ {
+ RearrangeAll();
+ ScrollToCaret();
+ Refresh(RP_NOANALYSE);
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+}
+
+void CFX_Edit::RearrangeAll()
+{
+ if (m_pVT->IsValid())
+ {
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ m_pVT->RearrangeAll();
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ SetScrollInfo();
+ SetContentChanged();
+ }
+}
+
+void CFX_Edit::RearrangePart(const CPVT_WordRange & range)
+{
+ if (m_pVT->IsValid())
+ {
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ m_pVT->RearrangePart(range);
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ SetScrollInfo();
+ SetContentChanged();
+ }
+}
+
+void CFX_Edit::SetContentChanged()
+{
+ if (m_bNotify && m_pNotify)
+ {
+ CPDF_Rect rcContent = m_pVT->GetContentRect();
+ if (rcContent.Width() != m_rcOldContent.Width() ||
+ rcContent.Height() != m_rcOldContent.Height())
+ {
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ m_pNotify->IOnContentChange(rcContent);
+ m_bNotifyFlag = FALSE;
+ }
+ m_rcOldContent = rcContent;
+ }
+ }
+}
+
+void CFX_Edit::SelectAll()
+{
+ if (m_pVT->IsValid())
+ {
+ m_SelState = GetWholeWordRange();
+ SetCaret(m_SelState.EndPos);
+
+ ScrollToCaret();
+ CPVT_WordRange wrVisible = GetVisibleWordRange();
+ Refresh(RP_OPTIONAL,&wrVisible);
+ SetCaretInfo();
+ }
+}
+
+void CFX_Edit::SelectNone()
+{
+ if (m_pVT->IsValid())
+ {
+ if (m_SelState.IsExist())
+ {
+ CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange();
+ m_SelState.Default();
+ Refresh(RP_OPTIONAL,&wrTemp);
+ }
+ }
+}
+
+FX_BOOL CFX_Edit::IsSelected() const
+{
+ return m_SelState.IsExist();
+}
+
+CPDF_Point CFX_Edit::VTToEdit(const CPDF_Point & point) const
+{
+ CPDF_Rect rcContent = m_pVT->GetContentRect();
+ CPDF_Rect rcPlate = m_pVT->GetPlateRect();
+
+ FX_FLOAT fPadding = 0.0f;
+
+ switch (m_nAlignment)
+ {
+ case 0:
+ fPadding = 0.0f;
+ break;
+ case 1:
+ fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f;
+ break;
+ case 2:
+ fPadding = rcPlate.Height() - rcContent.Height();
+ break;
+ }
+
+ return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left),
+ point.y - (m_ptScrollPos.y + fPadding - rcPlate.top));
+}
+
+CPDF_Point CFX_Edit::EditToVT(const CPDF_Point & point) const
+{
+ CPDF_Rect rcContent = m_pVT->GetContentRect();
+ CPDF_Rect rcPlate = m_pVT->GetPlateRect();
+
+ FX_FLOAT fPadding = 0.0f;
+
+ switch (m_nAlignment)
+ {
+ case 0:
+ fPadding = 0.0f;
+ break;
+ case 1:
+ fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f;
+ break;
+ case 2:
+ fPadding = rcPlate.Height() - rcContent.Height();
+ break;
+ }
+
+ return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left),
+ point.y + (m_ptScrollPos.y + fPadding - rcPlate.top));
+}
+
+CPDF_Rect CFX_Edit::VTToEdit(const CPDF_Rect & rect) const
+{
+ CPDF_Point ptLeftBottom = VTToEdit(CPDF_Point(rect.left,rect.bottom));
+ CPDF_Point ptRightTop = VTToEdit(CPDF_Point(rect.right,rect.top));
+
+ return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y);
+}
+
+CPDF_Rect CFX_Edit::EditToVT(const CPDF_Rect & rect) const
+{
+ CPDF_Point ptLeftBottom = EditToVT(CPDF_Point(rect.left,rect.bottom));
+ CPDF_Point ptRightTop = EditToVT(CPDF_Point(rect.right,rect.top));
+
+ return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y);
+}
+
+void CFX_Edit::SetScrollInfo()
+{
+ if (m_bNotify && m_pNotify)
+ {
+ CPDF_Rect rcPlate = m_pVT->GetPlateRect();
+ CPDF_Rect rcContent = m_pVT->GetContentRect();
+
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ m_pNotify->IOnSetScrollInfoX(rcPlate.left, rcPlate.right,
+ rcContent.left, rcContent.right, rcPlate.Width() / 3, rcPlate.Width());
+
+ m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top,
+ rcContent.bottom, rcContent.top, rcPlate.Height() / 3, rcPlate.Height());
+ m_bNotifyFlag = FALSE;
+ }
+ }
+}
+
+void CFX_Edit::SetScrollPosX(FX_FLOAT fx)
+{
+ if (!m_bEnableScroll) return;
+
+ if (m_pVT->IsValid())
+ {
+ if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x,fx))
+ {
+ m_ptScrollPos.x = fx;
+ Refresh(RP_NOANALYSE);
+
+ if (m_bNotify && m_pNotify)
+ {
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ m_pNotify->IOnSetScrollPosX(fx);
+ m_bNotifyFlag = FALSE;
+ }
+ }
+ }
+ }
+}
+
+void CFX_Edit::SetScrollPosY(FX_FLOAT fy)
+{
+ if (!m_bEnableScroll) return;
+
+ if (m_pVT->IsValid())
+ {
+ if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y,fy))
+ {
+ m_ptScrollPos.y = fy;
+ Refresh(RP_NOANALYSE);
+
+ if (m_bNotify && m_pNotify)
+ {
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ m_pNotify->IOnSetScrollPosY(fy);
+ m_bNotifyFlag = FALSE;
+ }
+ }
+ }
+ }
+}
+
+void CFX_Edit::SetScrollPos(const CPDF_Point & point)
+{
+ SetScrollPosX(point.x);
+ SetScrollPosY(point.y);
+ SetScrollLimit();
+ SetCaretInfo();
+}
+
+CPDF_Point CFX_Edit::GetScrollPos() const
+{
+ return m_ptScrollPos;
+}
+
+void CFX_Edit::SetScrollLimit()
+{
+ if (m_pVT->IsValid())
+ {
+ CPDF_Rect rcContent = m_pVT->GetContentRect();
+ CPDF_Rect rcPlate = m_pVT->GetPlateRect();
+
+ if (rcPlate.Width() > rcContent.Width())
+ {
+ SetScrollPosX(rcPlate.left);
+ }
+ else
+ {
+ if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.x, rcContent.left))
+ {
+ SetScrollPosX(rcContent.left);
+ }
+ else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.x, rcContent.right - rcPlate.Width()))
+ {
+ SetScrollPosX(rcContent.right - rcPlate.Width());
+ }
+ }
+
+ if (rcPlate.Height() > rcContent.Height())
+ {
+ SetScrollPosY(rcPlate.top);
+ }
+ else
+ {
+ if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.y, rcContent.bottom + rcPlate.Height()))
+ {
+ SetScrollPosY(rcContent.bottom + rcPlate.Height());
+ }
+ else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.y, rcContent.top))
+ {
+ SetScrollPosY(rcContent.top);
+ }
+ }
+ }
+}
+
+void CFX_Edit::ScrollToCaret()
+{
+ SetScrollLimit();
+
+ if (m_pVT->IsValid())
+ {
+ CPDF_Point ptHead(0,0);
+ CPDF_Point ptFoot(0,0);
+
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ pIterator->SetAt(m_wpCaret);
+
+ CPVT_Word word;
+ CPVT_Line line;
+ if (pIterator->GetWord(word))
+ {
+ ptHead.x = word.ptWord.x + word.fWidth;
+ ptHead.y = word.ptWord.y + word.fAscent;
+ ptFoot.x = word.ptWord.x + word.fWidth;
+ ptFoot.y = word.ptWord.y + word.fDescent;
+ }
+ else if (pIterator->GetLine(line))
+ {
+ ptHead.x = line.ptLine.x;
+ ptHead.y = line.ptLine.y + line.fLineAscent;
+ ptFoot.x = line.ptLine.x;
+ ptFoot.y = line.ptLine.y + line.fLineDescent;
+ }
+ }
+
+ CPDF_Point ptHeadEdit = VTToEdit(ptHead);
+ CPDF_Point ptFootEdit = VTToEdit(ptFoot);
+
+ CPDF_Rect rcPlate = m_pVT->GetPlateRect();
+
+ if (!FX_EDIT_IsFloatEqual(rcPlate.left,rcPlate.right))
+ {
+ if (FX_EDIT_IsFloatSmaller(ptHeadEdit.x, rcPlate.left) ||
+ FX_EDIT_IsFloatEqual(ptHeadEdit.x, rcPlate.left))
+ {
+ SetScrollPosX(ptHead.x);
+ }
+ else if (FX_EDIT_IsFloatBigger(ptHeadEdit.x, rcPlate.right))
+ {
+ SetScrollPosX(ptHead.x - rcPlate.Width());
+ }
+ }
+
+ if (!FX_EDIT_IsFloatEqual(rcPlate.top,rcPlate.bottom))
+ {
+ if (FX_EDIT_IsFloatSmaller(ptFootEdit.y, rcPlate.bottom) ||
+ FX_EDIT_IsFloatEqual(ptFootEdit.y, rcPlate.bottom))
+ {
+ if (FX_EDIT_IsFloatSmaller(ptHeadEdit.y, rcPlate.top))
+ {
+ SetScrollPosY(ptFoot.y + rcPlate.Height());
+ }
+ }
+ else if (FX_EDIT_IsFloatBigger(ptHeadEdit.y, rcPlate.top))
+ {
+ if (FX_EDIT_IsFloatBigger(ptFootEdit.y, rcPlate.bottom))
+ {
+ SetScrollPosY(ptHead.y);
+ }
+ }
+ }
+ }
+}
+
+void CFX_Edit::Refresh(REFRESH_PLAN_E ePlan,const CPVT_WordRange * pRange1,const CPVT_WordRange * pRange2)
+{
+ if (m_bEnableRefresh && m_pVT->IsValid())
+ {
+ m_Refresh.BeginRefresh();
+ RefreshPushLineRects(GetVisibleWordRange());
+
+// if (!FX_EDIT_IsFloatEqual(m_ptRefreshScrollPos.x,m_ptScrollPos.x) ||
+// !FX_EDIT_IsFloatEqual(m_ptRefreshScrollPos.y,m_ptScrollPos.y))
+// {
+ m_Refresh.NoAnalyse();
+ m_ptRefreshScrollPos = m_ptScrollPos;
+// }
+// else
+// {
+// switch (ePlan)
+// {
+// case RP_ANALYSE:
+// m_Refresh.Analyse(m_pVT->GetAlignment());
+//
+// if (pRange1) RefreshPushRandomRects(*pRange1);
+// if (pRange2) RefreshPushRandomRects(*pRange2);
+// break;
+// case RP_NOANALYSE:
+// m_Refresh.NoAnalyse();
+// break;
+// case RP_OPTIONAL:
+// if (pRange1) RefreshPushRandomRects(*pRange1);
+// if (pRange2) RefreshPushRandomRects(*pRange2);
+// break;
+// }
+// }
+
+ if (m_bNotify && m_pNotify)
+ {
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ if (const CFX_Edit_RectArray * pRects = m_Refresh.GetRefreshRects())
+ {
+ for (FX_INT32 i = 0, sz = pRects->GetSize(); i < sz; i++)
+ m_pNotify->IOnInvalidateRect(pRects->GetAt(i));
+ }
+ m_bNotifyFlag = FALSE;
+ }
+ }
+
+ m_Refresh.EndRefresh();
+ }
+}
+
+void CFX_Edit::RefreshPushLineRects(const CPVT_WordRange & wr)
+{
+ if (m_pVT->IsValid())
+ {
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ CPVT_WordPlace wpBegin = wr.BeginPos;
+ m_pVT->UpdateWordPlace(wpBegin);
+ CPVT_WordPlace wpEnd = wr.EndPos;
+ m_pVT->UpdateWordPlace(wpEnd);
+ pIterator->SetAt(wpBegin);
+
+ CPVT_Line lineinfo;
+ do
+ {
+ if (!pIterator->GetLine(lineinfo))break;
+ if (lineinfo.lineplace.LineCmp(wpEnd) > 0)break;
+
+ CPDF_Rect rcLine(lineinfo.ptLine.x,
+ lineinfo.ptLine.y + lineinfo.fLineDescent,
+ lineinfo.ptLine.x + lineinfo.fLineWidth,
+ lineinfo.ptLine.y + lineinfo.fLineAscent);
+
+ m_Refresh.Push(CPVT_WordRange(lineinfo.lineplace,lineinfo.lineEnd),VTToEdit(rcLine));
+
+ }while (pIterator->NextLine());
+ }
+ }
+}
+
+void CFX_Edit::RefreshPushRandomRects(const CPVT_WordRange & wr)
+{
+ if (m_pVT->IsValid())
+ {
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ CPVT_WordRange wrTemp = wr;
+
+ m_pVT->UpdateWordPlace(wrTemp.BeginPos);
+ m_pVT->UpdateWordPlace(wrTemp.EndPos);
+ pIterator->SetAt(wrTemp.BeginPos);
+
+ CPVT_Word wordinfo;
+ CPVT_Line lineinfo;
+ CPVT_WordPlace place;
+
+ while (pIterator->NextWord())
+ {
+ place = pIterator->GetAt();
+ if (place.WordCmp(wrTemp.EndPos) > 0) break;
+
+ pIterator->GetWord(wordinfo);
+ pIterator->GetLine(lineinfo);
+
+ if (place.LineCmp(wrTemp.BeginPos) == 0 || place.LineCmp(wrTemp.EndPos) == 0)
+ {
+ CPDF_Rect rcWord(wordinfo.ptWord.x,
+ lineinfo.ptLine.y + lineinfo.fLineDescent,
+ wordinfo.ptWord.x + wordinfo.fWidth,
+ lineinfo.ptLine.y + lineinfo.fLineAscent);
+
+ m_Refresh.AddRefresh(VTToEdit(rcWord));
+ }
+ else
+ {
+ CPDF_Rect rcLine(lineinfo.ptLine.x,
+ lineinfo.ptLine.y + lineinfo.fLineDescent,
+ lineinfo.ptLine.x + lineinfo.fLineWidth,
+ lineinfo.ptLine.y + lineinfo.fLineAscent);
+
+ m_Refresh.AddRefresh(VTToEdit(rcLine));
+
+ pIterator->NextLine();
+ }
+ }
+ }
+ }
+}
+
+void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr)
+{
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ CPVT_WordRange wrTemp = wr;
+
+ m_pVT->UpdateWordPlace(wrTemp.BeginPos);
+ m_pVT->UpdateWordPlace(wrTemp.EndPos);
+ pIterator->SetAt(wrTemp.BeginPos);
+
+ CPVT_Word wordinfo;
+ CPVT_Line lineinfo;
+ CPVT_WordPlace place;
+
+ while (pIterator->NextWord())
+ {
+ place = pIterator->GetAt();
+ if (place.WordCmp(wrTemp.EndPos) > 0) break;
+
+ pIterator->GetWord(wordinfo);
+ pIterator->GetLine(lineinfo);
+
+ if (place.LineCmp(wrTemp.BeginPos) == 0 || place.LineCmp(wrTemp.EndPos) == 0)
+ {
+ CPDF_Rect rcWord(wordinfo.ptWord.x,
+ lineinfo.ptLine.y + lineinfo.fLineDescent,
+ wordinfo.ptWord.x + wordinfo.fWidth,
+ lineinfo.ptLine.y + lineinfo.fLineAscent);
+
+ if (m_bNotify && m_pNotify)
+ {
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ CPDF_Rect rcRefresh = VTToEdit(rcWord);
+ m_pNotify->IOnInvalidateRect(&rcRefresh);
+ m_bNotifyFlag = FALSE;
+ }
+ }
+ }
+ else
+ {
+ CPDF_Rect rcLine(lineinfo.ptLine.x,
+ lineinfo.ptLine.y + lineinfo.fLineDescent,
+ lineinfo.ptLine.x + lineinfo.fLineWidth,
+ lineinfo.ptLine.y + lineinfo.fLineAscent);
+
+ if (m_bNotify && m_pNotify)
+ {
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ CPDF_Rect rcRefresh = VTToEdit(rcLine);
+ m_pNotify->IOnInvalidateRect(&rcRefresh);
+ m_bNotifyFlag = FALSE;
+ }
+ }
+
+ pIterator->NextLine();
+ }
+ }
+ }
+}
+
+void CFX_Edit::SetCaret(const CPVT_WordPlace & place)
+{
+ m_wpOldCaret = m_wpCaret;
+ m_wpCaret = place;
+}
+
+void CFX_Edit::SetCaretInfo()
+{
+ if (m_bNotify && m_pNotify)
+ {
+ if (!m_bNotifyFlag)
+ {
+ CPDF_Point ptHead(0.0f,0.0f),ptFoot(0.0f,0.0f);
+
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ pIterator->SetAt(m_wpCaret);
+ CPVT_Word word;
+ CPVT_Line line;
+ if (pIterator->GetWord(word))
+ {
+ ptHead.x = word.ptWord.x + word.fWidth;
+ ptHead.y = word.ptWord.y + word.fAscent;
+ ptFoot.x = word.ptWord.x + word.fWidth;
+ ptFoot.y = word.ptWord.y + word.fDescent;
+ }
+ else if (pIterator->GetLine(line))
+ {
+ ptHead.x = line.ptLine.x;
+ ptHead.y = line.ptLine.y + line.fLineAscent;
+ ptFoot.x = line.ptLine.x;
+ ptFoot.y = line.ptLine.y + line.fLineDescent;
+ }
+ }
+
+ m_bNotifyFlag = TRUE;
+ m_pNotify->IOnSetCaret(!m_SelState.IsExist(),VTToEdit(ptHead),VTToEdit(ptFoot), m_wpCaret);
+ m_bNotifyFlag = FALSE;
+ }
+ }
+
+ SetCaretChange();
+}
+
+void CFX_Edit::SetCaretChange()
+{
+ if (this->m_wpCaret == this->m_wpOldCaret) return;
+
+ if (m_bNotify && m_pVT->IsRichText() && m_pNotify)
+ {
+ CPVT_SecProps SecProps;
+ CPVT_WordProps WordProps;
+
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ pIterator->SetAt(m_wpCaret);
+ CPVT_Word word;
+ CPVT_Section section;
+
+ if (pIterator->GetSection(section))
+ {
+ SecProps = section.SecProps;
+ WordProps = section.WordProps;
+ }
+
+ if (pIterator->GetWord(word))
+ {
+ WordProps = word.WordProps;
+ }
+ }
+
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ m_pNotify->IOnCaretChange(SecProps,WordProps);
+ m_bNotifyFlag = FALSE;
+ }
+ }
+}
+
+void CFX_Edit::SetCaret(FX_INT32 nPos)
+{
+ if (m_pVT->IsValid())
+ {
+ SelectNone();
+ SetCaret(m_pVT->WordIndexToWordPlace(nPos));
+ m_SelState.Set(m_wpCaret,m_wpCaret);
+
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+}
+
+void CFX_Edit::OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ if (m_pVT->IsValid())
+ {
+ SelectNone();
+ SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
+ m_SelState.Set(m_wpCaret,m_wpCaret);
+
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+}
+
+void CFX_Edit::OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ if (m_pVT->IsValid())
+ {
+ SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
+
+ if (m_wpCaret != m_wpOldCaret)
+ {
+ m_SelState.SetEndPos(m_wpCaret);
+
+ ScrollToCaret();
+ CPVT_WordRange wr(m_wpOldCaret,m_wpCaret);
+ Refresh(RP_OPTIONAL,&wr);
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+ }
+}
+
+void CFX_Edit::OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ if (m_pVT->IsValid())
+ {
+ SetCaret(m_pVT->GetUpWordPlace(m_wpCaret,m_ptCaret));
+
+ if (bShift)
+ {
+ if (m_SelState.IsExist())
+ m_SelState.SetEndPos(m_wpCaret);
+ else
+ m_SelState.Set(m_wpOldCaret,m_wpCaret);
+
+ if (m_wpOldCaret != m_wpCaret)
+ {
+ ScrollToCaret();
+ CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
+ Refresh(RP_OPTIONAL, &wr);
+ SetCaretInfo();
+ }
+ }
+ else
+ {
+ SelectNone();
+
+ ScrollToCaret();
+ SetCaretInfo();
+ }
+ }
+}
+
+void CFX_Edit::OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ if (m_pVT->IsValid())
+ {
+ SetCaret(m_pVT->GetDownWordPlace(m_wpCaret,m_ptCaret));
+
+ if (bShift)
+ {
+ if (m_SelState.IsExist())
+ m_SelState.SetEndPos(m_wpCaret);
+ else
+ m_SelState.Set(m_wpOldCaret,m_wpCaret);
+
+ if (m_wpOldCaret != m_wpCaret)
+ {
+ ScrollToCaret();
+ CPVT_WordRange wr(m_wpOldCaret,m_wpCaret);
+ Refresh(RP_OPTIONAL, &wr);
+ SetCaretInfo();
+ }
+ }
+ else
+ {
+ SelectNone();
+
+ ScrollToCaret();
+ SetCaretInfo();
+ }
+ }
+}
+
+void CFX_Edit::OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ if (m_pVT->IsValid())
+ {
+ if (bShift)
+ {
+ if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
+ m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret))
+ SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
+
+ SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
+
+ if (m_SelState.IsExist())
+ m_SelState.SetEndPos(m_wpCaret);
+ else
+ m_SelState.Set(m_wpOldCaret, m_wpCaret);
+
+ if (m_wpOldCaret != m_wpCaret)
+ {
+ ScrollToCaret();
+ CPVT_WordRange wr(m_wpOldCaret,m_wpCaret);
+ Refresh(RP_OPTIONAL,&wr);
+ SetCaretInfo();
+ }
+ }
+ else
+ {
+ if (m_SelState.IsExist())
+ {
+ if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)<0)
+ SetCaret(m_SelState.BeginPos);
+ else
+ SetCaret(m_SelState.EndPos);
+
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
+ }
+ else
+ {
+ if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
+ m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret))
+ SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
+
+ SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
+
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+ }
+ }
+}
+
+void CFX_Edit::OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ if (m_pVT->IsValid())
+ {
+ if (bShift)
+ {
+ SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
+
+ if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
+ m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret))
+ SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
+
+ if (m_SelState.IsExist())
+ m_SelState.SetEndPos(m_wpCaret);
+ else
+ m_SelState.Set(m_wpOldCaret,m_wpCaret);
+
+ if (m_wpOldCaret != m_wpCaret)
+ {
+ ScrollToCaret();
+ CPVT_WordRange wr(m_wpOldCaret,m_wpCaret);
+ Refresh(RP_OPTIONAL,&wr);
+ SetCaretInfo();
+ }
+ }
+ else
+ {
+ if (m_SelState.IsExist())
+ {
+ if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)>0)
+ SetCaret(m_SelState.BeginPos);
+ else
+ SetCaret(m_SelState.EndPos);
+
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
+ }
+ else
+ {
+ SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
+
+ if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
+ m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret))
+ SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
+
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+ }
+ }
+}
+
+void CFX_Edit::OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ if (m_pVT->IsValid())
+ {
+ if (bShift)
+ {
+ if (bCtrl)
+ SetCaret(m_pVT->GetBeginWordPlace());
+ else
+ SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret));
+
+ if (m_SelState.IsExist())
+ m_SelState.SetEndPos(m_wpCaret);
+ else
+ m_SelState.Set(m_wpOldCaret,m_wpCaret);
+
+ ScrollToCaret();
+ CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
+ Refresh(RP_OPTIONAL, &wr);
+ SetCaretInfo();
+ }
+ else
+ {
+ if (m_SelState.IsExist())
+ {
+ if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)<0)
+ SetCaret(m_SelState.BeginPos);
+ else
+ SetCaret(m_SelState.EndPos);
+
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
+ }
+ else
+ {
+ if (bCtrl)
+ SetCaret(m_pVT->GetBeginWordPlace());
+ else
+ SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret));
+
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+ }
+ }
+}
+
+void CFX_Edit::OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ if (m_pVT->IsValid())
+ {
+ if (bShift)
+ {
+ if (bCtrl)
+ SetCaret(m_pVT->GetEndWordPlace());
+ else
+ SetCaret(m_pVT->GetLineEndPlace(m_wpCaret));
+
+ if (m_SelState.IsExist())
+ m_SelState.SetEndPos(m_wpCaret);
+ else
+ m_SelState.Set(m_wpOldCaret, m_wpCaret);
+
+ ScrollToCaret();
+ CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
+ Refresh(RP_OPTIONAL, &wr);
+ SetCaretInfo();
+ }
+ else
+ {
+ if (m_SelState.IsExist())
+ {
+ if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)>0)
+ SetCaret(m_SelState.BeginPos);
+ else
+ SetCaret(m_SelState.EndPos);
+
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
+ }
+ else
+ {
+ if (bCtrl)
+ SetCaret(m_pVT->GetEndWordPlace());
+ else
+ SetCaret(m_pVT->GetLineEndPlace(m_wpCaret));
+
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+ }
+ }
+}
+
+void CFX_Edit::SetText(FX_LPCWSTR text,FX_INT32 charset,
+ const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps, FX_BOOL bAddUndo, FX_BOOL bPaint)
+{
+ Empty();
+ DoInsertText(CPVT_WordPlace(0,0,-1), text, charset, pSecProps, pWordProps);
+ if (bPaint) Paint();
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnSetText(m_wpCaret, m_wpOldCaret);
+ //if (bAddUndo)
+}
+
+FX_BOOL CFX_Edit::InsertWord(FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps, FX_BOOL bAddUndo, FX_BOOL bPaint)
+{
+ if (IsTextOverflow()) return FALSE;
+
+ if (m_pVT->IsValid())
+ {
+ m_pVT->UpdateWordPlace(m_wpCaret);
+
+ SetCaret(m_pVT->InsertWord(m_wpCaret,word,GetCharSetFromUnicode(word, charset),pWordProps));
+ m_SelState.Set(m_wpCaret,m_wpCaret);
+
+ if (m_wpCaret != m_wpOldCaret)
+ {
+ if (bAddUndo && m_bEnableUndo)
+ {
+ AddEditUndoItem(new CFXEU_InsertWord(this,m_wpOldCaret,m_wpCaret,word,charset,pWordProps));
+ }
+
+ if (bPaint)
+ PaintInsertText(m_wpOldCaret, m_wpCaret);
+
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnInsertWord(m_wpCaret, m_wpOldCaret);
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,
+ FX_BOOL bAddUndo, FX_BOOL bPaint)
+{
+ if (IsTextOverflow()) return FALSE;
+
+ if (m_pVT->IsValid())
+ {
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ SetCaret(m_pVT->InsertSection(m_wpCaret,pSecProps,pWordProps));
+ m_SelState.Set(m_wpCaret,m_wpCaret);
+
+ if (m_wpCaret != m_wpOldCaret)
+ {
+ if (bAddUndo && m_bEnableUndo)
+ {
+ AddEditUndoItem(new CFXEU_InsertReturn(this,m_wpOldCaret,m_wpCaret,pSecProps,pWordProps));
+ }
+
+ if (bPaint)
+ {
+ RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret));
+ ScrollToCaret();
+ CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos);
+ Refresh(RP_ANALYSE, &wr);
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnInsertReturn(m_wpCaret, m_wpOldCaret);
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint)
+{
+ if (m_pVT->IsValid())
+ {
+ if (m_wpCaret == m_pVT->GetBeginWordPlace()) return FALSE;
+
+ CPVT_Section section;
+ CPVT_Word word;
+
+ if (bAddUndo)
+ {
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ pIterator->SetAt(m_wpCaret);
+ pIterator->GetSection(section);
+ pIterator->GetWord(word);
+ }
+ }
+
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ SetCaret(m_pVT->BackSpaceWord(m_wpCaret));
+ m_SelState.Set(m_wpCaret,m_wpCaret);
+
+ if (m_wpCaret != m_wpOldCaret)
+ {
+ if (bAddUndo && m_bEnableUndo)
+ {
+ if (m_wpCaret.SecCmp(m_wpOldCaret) != 0)
+ AddEditUndoItem(new CFXEU_Backspace(this,m_wpOldCaret,m_wpCaret,word.Word,word.nCharset,
+ section.SecProps,section.WordProps));
+ else
+ AddEditUndoItem(new CFXEU_Backspace(this,m_wpOldCaret,m_wpCaret,word.Word,word.nCharset,
+ section.SecProps,word.WordProps));
+ }
+
+ if (bPaint)
+ {
+ RearrangePart(CPVT_WordRange(m_wpCaret,m_wpOldCaret));
+ ScrollToCaret();
+
+ CPVT_WordRange wr;
+ if (m_wpCaret.SecCmp(m_wpOldCaret) !=0)
+ wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret),GetVisibleWordRange().EndPos);
+ else if (m_wpCaret.LineCmp(m_wpOldCaret) !=0)
+ wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret),m_pVT->GetSectionEndPlace(m_wpCaret));
+ else
+ wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret),m_pVT->GetSectionEndPlace(m_wpCaret));
+
+ Refresh(RP_ANALYSE, &wr);
+
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnBackSpace(m_wpCaret, m_wpOldCaret);
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::Delete(FX_BOOL bAddUndo, FX_BOOL bPaint)
+{
+ if (m_pVT->IsValid())
+ {
+ if (m_wpCaret == m_pVT->GetEndWordPlace()) return FALSE;
+
+ CPVT_Section section;
+ CPVT_Word word;
+
+ if (bAddUndo)
+ {
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret));
+ pIterator->GetSection(section);
+ pIterator->GetWord(word);
+ }
+ }
+
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ FX_BOOL bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret));
+
+ SetCaret(m_pVT->DeleteWord(m_wpCaret));
+ m_SelState.Set(m_wpCaret,m_wpCaret);
+
+ if (bAddUndo && m_bEnableUndo)
+ {
+ if (bSecEnd)
+ AddEditUndoItem(new CFXEU_Delete(this,m_wpOldCaret,m_wpCaret,word.Word,word.nCharset,
+ section.SecProps,section.WordProps,bSecEnd));
+ else
+ AddEditUndoItem(new CFXEU_Delete(this,m_wpOldCaret,m_wpCaret,word.Word,word.nCharset,
+ section.SecProps,word.WordProps,bSecEnd));
+ }
+
+ if (bPaint)
+ {
+ RearrangePart(CPVT_WordRange(m_wpOldCaret,m_wpCaret));
+ ScrollToCaret();
+
+ CPVT_WordRange wr;
+ if (bSecEnd)
+ wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret),GetVisibleWordRange().EndPos);
+ else if (m_wpCaret.LineCmp(m_wpOldCaret) !=0)
+ wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret),m_pVT->GetSectionEndPlace(m_wpCaret));
+ else
+ wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret),m_pVT->GetSectionEndPlace(m_wpCaret));
+
+ Refresh(RP_ANALYSE, &wr);
+
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnDelete(m_wpCaret, m_wpOldCaret);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::Empty()
+{
+ if (m_pVT->IsValid())
+ {
+ m_pVT->DeleteWords(GetWholeWordRange());
+ SetCaret(m_pVT->GetBeginWordPlace());
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::Clear(FX_BOOL bAddUndo, FX_BOOL bPaint)
+{
+ if (m_pVT->IsValid())
+ {
+ if (m_SelState.IsExist())
+ {
+ CPVT_WordRange range = m_SelState.ConvertToWordRange();
+
+ if (bAddUndo && m_bEnableUndo)
+ {
+ if (m_pVT->IsRichText())
+ {
+ BeginGroupUndo(L"");
+
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ pIterator->SetAt(range.EndPos);
+
+ CPVT_Word wordinfo;
+ CPVT_Section secinfo;
+ do
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (place.WordCmp(range.BeginPos) <= 0)break;
+
+ CPVT_WordPlace oldplace = m_pVT->GetPrevWordPlace(place);
+
+ if (oldplace.SecCmp(place) != 0)
+ {
+ if (pIterator->GetSection(secinfo))
+ {
+ AddEditUndoItem(new CFXEU_ClearRich(this,oldplace,place,range,wordinfo.Word,
+ wordinfo.nCharset,secinfo.SecProps,secinfo.WordProps));
+ }
+ }
+ else
+ {
+ if (pIterator->GetWord(wordinfo))
+ {
+ oldplace = m_pVT->AjustLineHeader(oldplace,TRUE);
+ place = m_pVT->AjustLineHeader(place,TRUE);
+
+ AddEditUndoItem(new CFXEU_ClearRich(this,oldplace,place,range,wordinfo.Word,
+ wordinfo.nCharset,secinfo.SecProps,wordinfo.WordProps));
+ }
+ }
+ }while (pIterator->PrevWord());
+ }
+ EndGroupUndo();
+ }
+ else
+ {
+ AddEditUndoItem(new CFXEU_Clear(this,range,GetSelText()));
+ }
+ }
+
+ SelectNone();
+ SetCaret(m_pVT->DeleteWords(range));
+ m_SelState.Set(m_wpCaret,m_wpCaret);
+
+ if (bPaint)
+ {
+ RearrangePart(range);
+ ScrollToCaret();
+
+ CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos);
+ Refresh(RP_ANALYSE, &wr);
+
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret);
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::InsertText(FX_LPCWSTR text, FX_INT32 charset,
+ const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps, FX_BOOL bAddUndo, FX_BOOL bPaint)
+{
+ if (IsTextOverflow()) return FALSE;
+
+ m_pVT->UpdateWordPlace(m_wpCaret);
+ SetCaret(DoInsertText(m_wpCaret, text, charset, pSecProps, pWordProps));
+ m_SelState.Set(m_wpCaret,m_wpCaret);
+
+ if (m_wpCaret != m_wpOldCaret)
+ {
+ if (bAddUndo && m_bEnableUndo)
+ {
+ AddEditUndoItem(new CFXEU_InsertText(this,m_wpOldCaret,m_wpCaret,text,charset,pSecProps,pWordProps));
+ }
+
+ if (bPaint)
+ PaintInsertText(m_wpOldCaret, m_wpCaret);
+
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret);
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void CFX_Edit::PaintInsertText(const CPVT_WordPlace & wpOld, const CPVT_WordPlace & wpNew)
+{
+ if (m_pVT->IsValid())
+ {
+ RearrangePart(CPVT_WordRange(wpOld,wpNew));
+ ScrollToCaret();
+
+ CPVT_WordRange wr;
+ if (m_wpCaret.LineCmp(wpOld) !=0)
+ wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(wpOld),m_pVT->GetSectionEndPlace(wpNew));
+ else
+ wr = CPVT_WordRange(wpOld,m_pVT->GetSectionEndPlace(wpNew));
+ Refresh(RP_ANALYSE, &wr);
+ SetCaretOrigin();
+ SetCaretInfo();
+ }
+}
+
+FX_BOOL CFX_Edit::Redo()
+{
+ if (m_bEnableUndo)
+ {
+ if (m_Undo.CanRedo())
+ {
+ m_Undo.Redo();
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::Undo()
+{
+ if (m_bEnableUndo)
+ {
+ if (m_Undo.CanUndo())
+ {
+ m_Undo.Undo();
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+void CFX_Edit::SetCaretOrigin()
+{
+ if (m_pVT->IsValid())
+ {
+ if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator())
+ {
+ pIterator->SetAt(m_wpCaret);
+ CPVT_Word word;
+ CPVT_Line line;
+ if (pIterator->GetWord(word))
+ {
+ m_ptCaret.x = word.ptWord.x + word.fWidth;
+ m_ptCaret.y = word.ptWord.y;
+ }
+ else if (pIterator->GetLine(line))
+ {
+ m_ptCaret.x = line.ptLine.x;
+ m_ptCaret.y = line.ptLine.y;
+ }
+ }
+ }
+}
+
+FX_INT32 CFX_Edit::WordPlaceToWordIndex(const CPVT_WordPlace & place) const
+{
+ if (m_pVT->IsValid())
+ return m_pVT->WordPlaceToWordIndex(place);
+
+ return -1;
+}
+
+CPVT_WordPlace CFX_Edit::WordIndexToWordPlace(FX_INT32 index) const
+{
+ if (m_pVT->IsValid())
+ return m_pVT->WordIndexToWordPlace(index);
+
+ return CPVT_WordPlace();
+}
+
+FX_BOOL CFX_Edit::IsTextFull() const
+{
+ FX_INT32 nTotalWords = m_pVT->GetTotalWords();
+ FX_INT32 nLimitChar = m_pVT->GetLimitChar();
+ FX_INT32 nCharArray = m_pVT->GetCharArray();
+
+ return IsTextOverflow() || (nLimitChar>0 && nTotalWords >= nLimitChar)
+ || (nCharArray>0 && nTotalWords >= nCharArray);
+}
+
+FX_BOOL CFX_Edit::IsTextOverflow() const
+{
+ if (!m_bEnableScroll && !m_bEnableOverflow)
+ {
+ CPDF_Rect rcPlate = m_pVT->GetPlateRect();
+ CPDF_Rect rcContent = m_pVT->GetContentRect();
+
+ if (m_pVT->IsMultiLine() && GetTotalLines() > 1)
+ {
+ if (FX_EDIT_IsFloatBigger(rcContent.Height(),rcPlate.Height())) return TRUE;
+ }
+
+ if (FX_EDIT_IsFloatBigger(rcContent.Width(),rcPlate.Width())) return TRUE;
+ }
+
+ return FALSE;
+}
+
+CPVT_WordPlace CFX_Edit::GetLineBeginPlace(const CPVT_WordPlace & place) const
+{
+ return m_pVT->GetLineBeginPlace(place);
+}
+
+CPVT_WordPlace CFX_Edit::GetLineEndPlace(const CPVT_WordPlace & place) const
+{
+ return m_pVT->GetLineEndPlace(place);
+}
+
+CPVT_WordPlace CFX_Edit::GetSectionBeginPlace(const CPVT_WordPlace & place) const
+{
+ return m_pVT->GetSectionBeginPlace(place);
+}
+
+CPVT_WordPlace CFX_Edit::GetSectionEndPlace(const CPVT_WordPlace & place) const
+{
+ return m_pVT->GetSectionEndPlace(place);
+}
+
+FX_BOOL CFX_Edit::CanUndo() const
+{
+ if (m_bEnableUndo)
+ {
+ return m_Undo.CanUndo();
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::CanRedo() const
+{
+ if (m_bEnableUndo)
+ {
+ return m_Undo.CanRedo();
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CFX_Edit::IsModified() const
+{
+ if (m_bEnableUndo)
+ {
+ return m_Undo.IsModified();
+ }
+
+ return FALSE;
+}
+
+void CFX_Edit::EnableRefresh(FX_BOOL bRefresh)
+{
+ m_bEnableRefresh = bRefresh;
+}
+
+void CFX_Edit::EnableUndo(FX_BOOL bUndo)
+{
+ this->m_bEnableUndo = bUndo;
+}
+
+void CFX_Edit::EnableNotify(FX_BOOL bNotify)
+{
+ this->m_bNotify = bNotify;
+}
+
+void CFX_Edit::EnableOprNotify(FX_BOOL bNotify)
+{
+ this->m_bOprNotify = bNotify;
+}
+
+FX_FLOAT CFX_Edit::GetLineTop(const CPVT_WordPlace& place) const
+{
+ if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator())
+ {
+ CPVT_WordPlace wpOld = pIterator->GetAt();
+
+ pIterator->SetAt(place);
+ CPVT_Line line;
+ pIterator->GetLine(line);
+
+ pIterator->SetAt(wpOld);
+
+ return line.ptLine.y + line.fLineAscent;
+ }
+
+ return 0.0f;
+}
+
+FX_FLOAT CFX_Edit::GetLineBottom(const CPVT_WordPlace& place) const
+{
+ if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator())
+ {
+ CPVT_WordPlace wpOld = pIterator->GetAt();
+
+ pIterator->SetAt(place);
+ CPVT_Line line;
+ pIterator->GetLine(line);
+
+ pIterator->SetAt(wpOld);
+
+ return line.ptLine.y + line.fLineDescent;
+ }
+
+ return 0.0f;
+}
+
+CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, FX_LPCWSTR text, FX_INT32 charset,
+ const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps)
+{
+ CPVT_WordPlace wp = place;
+
+ if (m_pVT->IsValid())
+ {
+ CFX_WideString sText = text;
+
+ for (FX_INT32 i = 0, sz = sText.GetLength(); i < sz; i++)
+ {
+ FX_WORD word = sText[i];
+ switch (word)
+ {
+ case 0x0D:
+ wp = m_pVT->InsertSection(wp,pSecProps,pWordProps);
+ if (sText[i+1] == 0x0A)
+ i++;
+ break;
+ case 0x0A:
+ wp = m_pVT->InsertSection(wp,pSecProps,pWordProps);
+ if (sText[i+1] == 0x0D)
+ i++;
+ break;
+ case 0x09:
+ word = 0x20;
+ default:
+ wp = m_pVT->InsertWord(wp,word,GetCharSetFromUnicode(word, charset),pWordProps);
+ break;
+ }
+ }
+ }
+
+ return wp;
+}
+
+FX_INT32 CFX_Edit::GetCharSetFromUnicode(FX_WORD word, FX_INT32 nOldCharset)
+{
+ if (IFX_Edit_FontMap* pFontMap = this->GetFontMap())
+ return pFontMap->CharSetFromUnicode(word, nOldCharset);
+ else
+ return nOldCharset;
+}
+
+void CFX_Edit::BeginGroupUndo(const CFX_WideString& sTitle)
+{
+ ASSERT(m_pGroupUndoItem == NULL);
+
+ m_pGroupUndoItem = new CFX_Edit_GroupUndoItem(sTitle);
+}
+
+void CFX_Edit::EndGroupUndo()
+{
+ ASSERT(m_pGroupUndoItem != NULL);
+
+ m_pGroupUndoItem->UpdateItems();
+ m_Undo.AddItem(m_pGroupUndoItem);
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnAddUndo(m_pGroupUndoItem);
+ m_pGroupUndoItem = NULL;
+}
+
+void CFX_Edit::AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem)
+{
+ if (m_pGroupUndoItem)
+ m_pGroupUndoItem->AddUndoItem(pEditUndoItem);
+ else
+ {
+ m_Undo.AddItem(pEditUndoItem);
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnAddUndo(pEditUndoItem);
+ }
+}
+
+void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem)
+{
+ m_Undo.AddItem(pUndoItem);
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnAddUndo(pUndoItem);
+}
+
diff --git a/fpdfsdk/src/fxedit/fxet_list.cpp b/fpdfsdk/src/fxedit/fxet_list.cpp
index dd70e0c7d4..63aee1b253 100644
--- a/fpdfsdk/src/fxedit/fxet_list.cpp
+++ b/fpdfsdk/src/fxedit/fxet_list.cpp
@@ -1,1012 +1,1012 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/fxedit/fxet_stub.h"
-#include "../../include/fxedit/fxet_edit.h"
-#include "../../include/fxedit/fxet_list.h"
-
-/* ------------------------------- CFX_ListItem ---------------------------------- */
-
-CFX_ListItem::CFX_ListItem() : m_pEdit(NULL),
- m_bSelected(FALSE),
- m_bCaret(FALSE),
- m_rcListItem(0.0f,0.0f,0.0f,0.0f)
-{
- m_pEdit = IFX_Edit::NewEdit();
- ASSERT(m_pEdit != NULL);
-
- m_pEdit->SetAlignmentV(1);
- m_pEdit->Initialize();
-}
-
-CFX_ListItem::~CFX_ListItem()
-{
- IFX_Edit::DelEdit(m_pEdit);
-}
-
-void CFX_ListItem::SetFontMap(IFX_Edit_FontMap * pFontMap)
-{
- if (m_pEdit)
- m_pEdit->SetFontMap(pFontMap);
-}
-
-IFX_Edit* CFX_ListItem::GetEdit() const
-{
- return m_pEdit;
-}
-
-IFX_Edit_Iterator* CFX_ListItem::GetIterator() const
-{
- if (m_pEdit)
- return m_pEdit->GetIterator();
-
- return NULL;
-}
-
-void CFX_ListItem::SetRect(const CLST_Rect & rect)
-{
- m_rcListItem = rect;
-}
-
-CLST_Rect CFX_ListItem::GetRect() const
-{
- return m_rcListItem;
-}
-
-FX_BOOL CFX_ListItem::IsSelected() const
-{
- return m_bSelected;
-}
-
-void CFX_ListItem::SetSelect(FX_BOOL bSelected)
-{
- m_bSelected = bSelected;
-}
-
-FX_BOOL CFX_ListItem::IsCaret() const
-{
- return m_bCaret;
-}
-
-void CFX_ListItem::SetCaret(FX_BOOL bCaret)
-{
- m_bCaret = bCaret;
-}
-
-void CFX_ListItem::SetText(FX_LPCWSTR text)
-{
- if (m_pEdit)
- m_pEdit->SetText(text);
-}
-
-void CFX_ListItem::SetFontSize(FX_FLOAT fFontSize)
-{
- if (m_pEdit)
- m_pEdit->SetFontSize(fFontSize);
-}
-
-FX_FLOAT CFX_ListItem::GetItemHeight() const
-{
- if (m_pEdit)
- return m_pEdit->GetContentRect().Height();
-
- return 0.0f;
-}
-
-FX_WORD CFX_ListItem::GetFirstChar() const
-{
- CPVT_Word word;
-
- if (IFX_Edit_Iterator* pIterator = GetIterator())
- {
- pIterator->SetAt(1);
- pIterator->GetWord(word);
- }
-
- return word.Word;
-}
-
-CFX_WideString CFX_ListItem::GetText() const
-{
- if (m_pEdit)
- return m_pEdit->GetText();
-
- return L"";
-}
-
-/* ------------------------------------ CFX_List --------------------------------- */
-
-CFX_List::CFX_List() : m_pFontMap(NULL), m_fFontSize(0.0f), m_bMultiple(FALSE)
-{
-}
-
-CFX_List::~CFX_List()
-{
- Empty();
-}
-
-void CFX_List::Empty()
-{
- for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++)
- delete m_aListItems.GetAt(i);
-
- m_aListItems.RemoveAll();
-}
-
-void CFX_List::SetFontMap(IFX_Edit_FontMap * pFontMap)
-{
- m_pFontMap = pFontMap;
-}
-
-void CFX_List::SetFontSize(FX_FLOAT fFontSize)
-{
- m_fFontSize = fFontSize;
-}
-
-void CFX_List::AddItem(FX_LPCWSTR str)
-{
- if (CFX_ListItem * pListItem = new CFX_ListItem())
- {
- pListItem->SetFontMap(m_pFontMap);
- pListItem->SetFontSize(m_fFontSize);
- pListItem->SetText(str);
- m_aListItems.Add(pListItem);
- }
-}
-
-void CFX_List::ReArrange(FX_INT32 nItemIndex)
-{
- FX_FLOAT fPosY = 0.0f;
-
- if (CFX_ListItem * pPrevItem = m_aListItems.GetAt(nItemIndex - 1))
- fPosY = pPrevItem->GetRect().bottom;
-
- for (FX_INT32 i=nItemIndex,sz=m_aListItems.GetSize(); i<sz; i++)
- {
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(i))
- {
- FX_FLOAT fListItemHeight = pListItem->GetItemHeight();
- pListItem->SetRect(CLST_Rect(0.0f,fPosY,0.0f,fPosY + fListItemHeight));
- fPosY += fListItemHeight;
- }
- }
-
- SetContentRect(CLST_Rect(0.0f,0.0f,0.0f,fPosY));
-}
-
-IFX_Edit * CFX_List::GetItemEdit(FX_INT32 nIndex) const
-{
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex))
- {
- return pListItem->GetEdit();
- }
-
- return NULL;
-}
-
-FX_INT32 CFX_List::GetCount() const
-{
- return m_aListItems.GetSize();
-}
-
-CPDF_Rect CFX_List::GetPlateRect() const
-{
- return CFX_ListContainer::GetPlateRect();
-}
-
-CPDF_Rect CFX_List::GetContentRect() const
-{
- return InnerToOuter(CFX_ListContainer::GetContentRect());
-}
-
-FX_FLOAT CFX_List::GetFontSize() const
-{
- return m_fFontSize;
-}
-
-FX_INT32 CFX_List::GetItemIndex(const CPDF_Point & point) const
-{
- CPDF_Point pt = OuterToInner(point);
-
- FX_BOOL bFirst = TRUE;
- FX_BOOL bLast = TRUE;
-
- for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++)
- {
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(i))
- {
- CLST_Rect rcListItem = pListItem->GetRect();
-
- if (FX_EDIT_IsFloatBigger(pt.y, rcListItem.top))
- {
- bFirst = FALSE;
- }
-
- if (FX_EDIT_IsFloatSmaller(pt.y, rcListItem.bottom))
- {
- bLast = FALSE;
- }
-
- if (pt.y >= rcListItem.top && pt.y < rcListItem.bottom)
- {
- return i;
- }
- }
- }
-
- if (bFirst) return 0;
- if (bLast) return m_aListItems.GetSize()-1;
-
- return -1;
-}
-
-FX_FLOAT CFX_List::GetFirstHeight() const
-{
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(0))
- {
- return pListItem->GetItemHeight();
- }
-
- return 1.0f;
-}
-
-FX_INT32 CFX_List::GetFirstSelected() const
-{
- for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++)
- {
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(i))
- {
- if (pListItem->IsSelected())
- return i;
- }
- }
- return -1;
-}
-
-FX_INT32 CFX_List::GetLastSelected() const
-{
- for (FX_INT32 i=m_aListItems.GetSize()-1; i>=0; i--)
- {
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(i))
- {
- if (pListItem->IsSelected())
- return i;
- }
- }
- return -1;
-}
-
-FX_WCHAR CFX_List::Toupper(FX_WCHAR c) const
-{
- if ( (c >= 'a') && (c <= 'z') )
- c = c - ('a' - 'A');
- return c;
-}
-
-FX_INT32 CFX_List::FindNext(FX_INT32 nIndex,FX_WCHAR nChar) const
-{
- FX_INT32 nCircleIndex = nIndex;
-
- for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++)
- {
- nCircleIndex ++;
- if (nCircleIndex >= sz) nCircleIndex = 0;
-
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(nCircleIndex))
- {
- if (Toupper(pListItem->GetFirstChar()) == Toupper(nChar))
- return nCircleIndex;
- }
- }
-
- return nCircleIndex;
-}
-
-CPDF_Rect CFX_List::GetItemRect(FX_INT32 nIndex) const
-{
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex))
- {
- CPDF_Rect rcItem = pListItem->GetRect();
- rcItem.left = 0.0f;
- rcItem.right = GetPlateRect().Width();
- return InnerToOuter(rcItem);
- }
-
- return CPDF_Rect();
-}
-
-FX_BOOL CFX_List::IsItemSelected(FX_INT32 nIndex) const
-{
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex))
- {
- return pListItem->IsSelected();
- }
-
- return FALSE;
-}
-
-void CFX_List::SetItemSelect(FX_INT32 nItemIndex, FX_BOOL bSelected)
-{
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(nItemIndex))
- {
- pListItem->SetSelect(bSelected);
- }
-}
-
-void CFX_List::SetItemCaret(FX_INT32 nItemIndex, FX_BOOL bCaret)
-{
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(nItemIndex))
- {
- pListItem->SetCaret(bCaret);
- }
-}
-
-void CFX_List::SetMultipleSel(FX_BOOL bMultiple)
-{
- m_bMultiple = bMultiple;
-}
-
-FX_BOOL CFX_List::IsMultipleSel() const
-{
- return m_bMultiple;
-}
-
-FX_BOOL CFX_List::IsValid(FX_INT32 nItemIndex) const
-{
- return nItemIndex >= 0 && nItemIndex < m_aListItems.GetSize();
-}
-
-CFX_WideString CFX_List::GetItemText(FX_INT32 nIndex) const
-{
- if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex))
- {
- return pListItem->GetText();
- }
-
- return L"";
-}
-
-/* ------------------------------------ CPLST_Select ---------------------------------- */
-
-CPLST_Select::CPLST_Select()
-{
-}
-
-CPLST_Select::~CPLST_Select()
-{
- for (FX_INT32 i=0,sz=m_aItems.GetSize(); i<sz; i++)
- delete m_aItems.GetAt(i);
-
- m_aItems.RemoveAll();
-}
-
-void CPLST_Select::Add(FX_INT32 nItemIndex)
-{
- FX_INT32 nIndex = Find(nItemIndex);
-
- if (nIndex < 0)
- m_aItems.Add(new CPLST_Select_Item(nItemIndex,1));
- else
- {
- if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex))
- {
- pItem->nState = 1;
- }
- }
-}
-
-void CPLST_Select::Add(FX_INT32 nBeginIndex, FX_INT32 nEndIndex)
-{
- if (nBeginIndex > nEndIndex)
- {
- FX_INT32 nTemp = nEndIndex;
- nEndIndex = nBeginIndex;
- nBeginIndex = nTemp;
- }
-
- for (FX_INT32 i=nBeginIndex; i<=nEndIndex; i++) Add(i);
-}
-
-void CPLST_Select::Sub(FX_INT32 nItemIndex)
-{
- for (FX_INT32 i=m_aItems.GetSize()-1; i>=0; i--)
- {
- if (CPLST_Select_Item * pItem = m_aItems.GetAt(i))
- if (pItem->nItemIndex == nItemIndex)
- pItem->nState = -1;
- }
-}
-
-void CPLST_Select::Sub(FX_INT32 nBeginIndex, FX_INT32 nEndIndex)
-{
- if (nBeginIndex > nEndIndex)
- {
- FX_INT32 nTemp = nEndIndex;
- nEndIndex = nBeginIndex;
- nBeginIndex = nTemp;
- }
-
- for (FX_INT32 i=nBeginIndex; i<=nEndIndex; i++) Sub(i);
-}
-
-FX_INT32 CPLST_Select::Find(FX_INT32 nItemIndex) const
-{
- for (FX_INT32 i=0,sz=m_aItems.GetSize(); i<sz; i++)
- {
- if (CPLST_Select_Item * pItem = m_aItems.GetAt(i))
- {
- if (pItem->nItemIndex == nItemIndex)
- return i;
- }
- }
-
- return -1;
-}
-
-FX_BOOL CPLST_Select::IsExist(FX_INT32 nItemIndex) const
-{
- return Find(nItemIndex) >= 0;
-}
-
-FX_INT32 CPLST_Select::GetCount() const
-{
- return m_aItems.GetSize();
-}
-
-FX_INT32 CPLST_Select::GetItemIndex(FX_INT32 nIndex) const
-{
- if (nIndex >= 0 && nIndex < m_aItems.GetSize())
- if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex))
- return pItem->nItemIndex;
-
- return -1;
-}
-
-FX_INT32 CPLST_Select::GetState(FX_INT32 nIndex) const
-{
- if (nIndex >= 0 && nIndex < m_aItems.GetSize())
- if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex))
- return pItem->nState;
-
- return 0;
-}
-
-void CPLST_Select::DeselectAll()
-{
- for (FX_INT32 i=0,sz=m_aItems.GetSize(); i<sz; i++)
- {
- if (CPLST_Select_Item * pItem = m_aItems.GetAt(i))
- {
- pItem->nState = -1;
- }
- }
-}
-
-void CPLST_Select::Done()
-{
- for (FX_INT32 i=m_aItems.GetSize()-1; i>=0; i--)
- {
- if (CPLST_Select_Item * pItem = m_aItems.GetAt(i))
- {
- if (pItem->nState == -1)
- {
- delete pItem;
- m_aItems.RemoveAt(i);
- }
- else
- {
- pItem->nState = 0;
- }
- }
- }
-}
-
-/* ------------------------------------ CFX_ListCtrl --------------------------------- */
-
-CFX_ListCtrl::CFX_ListCtrl() : m_pNotify(NULL),
- m_ptScrollPos(0.0f,0.0f),
- m_nSelItem(-1),
- m_nFootIndex(-1),
- m_bCtrlSel(FALSE),
- m_nCaretIndex(-1),
- m_bNotifyFlag(FALSE)
-{
-}
-
-CFX_ListCtrl::~CFX_ListCtrl()
-{
-}
-
-void CFX_ListCtrl::SetNotify(IFX_List_Notify * pNotify)
-{
- m_pNotify = pNotify;
-}
-
-CPDF_Point CFX_ListCtrl::InToOut(const CPDF_Point & point) const
-{
- CPDF_Rect rcPlate = GetPlateRect();
-
- return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left),
- point.y - (m_ptScrollPos.y - rcPlate.top));
-}
-
-CPDF_Point CFX_ListCtrl::OutToIn(const CPDF_Point & point) const
-{
- CPDF_Rect rcPlate = GetPlateRect();
-
- return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left),
- point.y + (m_ptScrollPos.y - rcPlate.top));
-}
-
-CPDF_Rect CFX_ListCtrl::InToOut(const CPDF_Rect & rect) const
-{
- CPDF_Point ptLeftBottom = InToOut(CPDF_Point(rect.left,rect.bottom));
- CPDF_Point ptRightTop = InToOut(CPDF_Point(rect.right,rect.top));
-
- return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y);
-}
-
-CPDF_Rect CFX_ListCtrl::OutToIn(const CPDF_Rect & rect) const
-{
- CPDF_Point ptLeftBottom = OutToIn(CPDF_Point(rect.left,rect.bottom));
- CPDF_Point ptRightTop = OutToIn(CPDF_Point(rect.right,rect.top));
-
- return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y);
-}
-
-void CFX_ListCtrl::OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl)
-{
- FX_INT32 nHitIndex = this->GetItemIndex(point);
-
- if (IsMultipleSel())
- {
- if (bCtrl)
- {
- if (IsItemSelected(nHitIndex))
- {
- m_aSelItems.Sub(nHitIndex);
- SelectItems();
- m_bCtrlSel = FALSE;
- }
- else
- {
- m_aSelItems.Add(nHitIndex);
- SelectItems();
- m_bCtrlSel = TRUE;
- }
-
- m_nFootIndex = nHitIndex;
- }
- else if (bShift)
- {
- m_aSelItems.DeselectAll();
- m_aSelItems.Add(m_nFootIndex,nHitIndex);
- SelectItems();
- }
- else
- {
- m_aSelItems.DeselectAll();
- m_aSelItems.Add(nHitIndex);
- SelectItems();
-
- m_nFootIndex = nHitIndex;
- }
-
- SetCaret(nHitIndex);
- }
- else
- {
- SetSingleSelect(nHitIndex);
- }
-
- if (!this->IsItemVisible(nHitIndex))
- this->ScrollToListItem(nHitIndex);
-}
-
-void CFX_ListCtrl::OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl)
-{
- FX_INT32 nHitIndex = this->GetItemIndex(point);
-
- if (IsMultipleSel())
- {
- if (bCtrl)
- {
- if (m_bCtrlSel)
- m_aSelItems.Add(m_nFootIndex,nHitIndex);
- else
- m_aSelItems.Sub(m_nFootIndex,nHitIndex);
-
- SelectItems();
- }
- else
- {
- m_aSelItems.DeselectAll();
- m_aSelItems.Add(m_nFootIndex,nHitIndex);
- SelectItems();
- }
-
- SetCaret(nHitIndex);
- }
- else
- {
- SetSingleSelect(nHitIndex);
- }
-
- if (!this->IsItemVisible(nHitIndex))
- this->ScrollToListItem(nHitIndex);
-}
-
-void CFX_ListCtrl::OnVK(FX_INT32 nItemIndex,FX_BOOL bShift,FX_BOOL bCtrl)
-{
- if (IsMultipleSel())
- {
- if (nItemIndex >= 0 && nItemIndex < GetCount())
- {
- if (bCtrl)
- {
- }
- else if (bShift)
- {
- m_aSelItems.DeselectAll();
- m_aSelItems.Add(m_nFootIndex,nItemIndex);
- SelectItems();
- }
- else
- {
- m_aSelItems.DeselectAll();
- m_aSelItems.Add(nItemIndex);
- SelectItems();
- m_nFootIndex = nItemIndex;
- }
-
- SetCaret(nItemIndex);
- }
- }
- else
- {
- SetSingleSelect(nItemIndex);
- }
-
- if (!this->IsItemVisible(nItemIndex))
- this->ScrollToListItem(nItemIndex);
-}
-
-void CFX_ListCtrl::OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- OnVK(IsMultipleSel() ? GetCaret()-1 : GetSelect()-1, bShift, bCtrl);
-}
-
-void CFX_ListCtrl::OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- OnVK(IsMultipleSel() ? GetCaret()+1 : GetSelect()+1, bShift, bCtrl);
-}
-
-void CFX_ListCtrl::OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- OnVK(0, bShift, bCtrl);
-}
-
-void CFX_ListCtrl::OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- OnVK(GetCount()-1, bShift, bCtrl);
-}
-
-void CFX_ListCtrl::OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- OnVK(0, bShift, bCtrl);
-}
-
-void CFX_ListCtrl::OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl)
-{
- OnVK(GetCount()-1, bShift, bCtrl);
-}
-
-FX_BOOL CFX_ListCtrl::OnChar(FX_WORD nChar,FX_BOOL bShift,FX_BOOL bCtrl)
-{
- FX_INT32 nIndex = GetLastSelected();
- FX_INT32 nFindIndex = FindNext(nIndex,nChar);
-
- if (nFindIndex != nIndex)
- {
- OnVK(nFindIndex, bShift, bCtrl);
- return TRUE;
- }
- return FALSE;
-}
-
-/* -------- inner methods ------- */
-
-void CFX_ListCtrl::SetPlateRect(const CPDF_Rect & rect)
-{
- CFX_ListContainer::SetPlateRect(rect);
- m_ptScrollPos.x = rect.left;
- SetScrollPos(CPDF_Point(rect.left,rect.top));
- ReArrange(0);
- InvalidateItem(-1);
-}
-
-CPDF_Rect CFX_ListCtrl::GetItemRect(FX_INT32 nIndex) const
-{
- return InToOut(CFX_List::GetItemRect(nIndex));
-}
-
-void CFX_ListCtrl::AddString(FX_LPCWSTR string)
-{
- AddItem(string);
- ReArrange(GetCount() - 1);
-}
-
-void CFX_ListCtrl::SetMultipleSelect(FX_INT32 nItemIndex, FX_BOOL bSelected)
-{
- if (!IsValid(nItemIndex)) return;
-
- if (bSelected != this->IsItemSelected(nItemIndex))
- {
- if (bSelected)
- {
- SetItemSelect(nItemIndex,TRUE);
- InvalidateItem(nItemIndex);
- }
- else
- {
- SetItemSelect(nItemIndex,FALSE);
- InvalidateItem(nItemIndex);
- }
- }
-}
-
-void CFX_ListCtrl::SetSingleSelect(FX_INT32 nItemIndex)
-{
- if (!IsValid(nItemIndex)) return;
-
- if (m_nSelItem != nItemIndex)
- {
- if (m_nSelItem >= 0)
- {
- SetItemSelect(m_nSelItem,FALSE);
- InvalidateItem(m_nSelItem);
- }
-
- SetItemSelect(nItemIndex,TRUE);
- InvalidateItem(nItemIndex);
- m_nSelItem = nItemIndex;
- }
-}
-
-void CFX_ListCtrl::SetCaret(FX_INT32 nItemIndex)
-{
- if (!IsValid(nItemIndex)) return;
-
- if (this->IsMultipleSel())
- {
- FX_INT32 nOldIndex = m_nCaretIndex;
-
- if (nOldIndex != nItemIndex)
- {
- m_nCaretIndex = nItemIndex;
-
- SetItemCaret(nOldIndex, FALSE);
- SetItemCaret(nItemIndex,TRUE);
-
- InvalidateItem(nOldIndex);
- InvalidateItem(nItemIndex);
- }
- }
-}
-
-void CFX_ListCtrl::InvalidateItem(FX_INT32 nItemIndex)
-{
- if (m_pNotify)
- {
- if (nItemIndex == -1)
- {
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- CPDF_Rect rcRefresh = GetPlateRect();
- m_pNotify->IOnInvalidateRect(&rcRefresh);
- m_bNotifyFlag = FALSE;
- }
- }
- else
- {
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- CPDF_Rect rcRefresh = GetItemRect(nItemIndex);
- rcRefresh.left -= 1.0f;
- rcRefresh.right += 1.0f;
- rcRefresh.bottom -= 1.0f;
- rcRefresh.top += 1.0f;
-
- m_pNotify->IOnInvalidateRect(&rcRefresh);
- m_bNotifyFlag = FALSE;
- }
- }
- }
-}
-
-void CFX_ListCtrl::SelectItems()
-{
- for (FX_INT32 i=0,sz=m_aSelItems.GetCount(); i<sz; i++)
- {
- FX_INT32 nItemIndex = m_aSelItems.GetItemIndex(i);
- FX_INT32 nState = m_aSelItems.GetState(i);
-
- switch(nState)
- {
- case 1:
- SetMultipleSelect(nItemIndex, TRUE);
- break;
- case -1:
- SetMultipleSelect(nItemIndex, FALSE);
- break;
- }
- }
-
- m_aSelItems.Done();
-}
-
-void CFX_ListCtrl::Select(FX_INT32 nItemIndex)
-{
- if (!IsValid(nItemIndex)) return;
-
- if (this->IsMultipleSel())
- {
- m_aSelItems.Add(nItemIndex);
- SelectItems();
- }
- else
- SetSingleSelect(nItemIndex);
-}
-
-FX_BOOL CFX_ListCtrl::IsItemVisible(FX_INT32 nItemIndex) const
-{
- CPDF_Rect rcPlate = this->GetPlateRect();
- CPDF_Rect rcItem = this->GetItemRect(nItemIndex);
-
- return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top;
-}
-
-void CFX_ListCtrl::ScrollToListItem(FX_INT32 nItemIndex)
-{
- if (!IsValid(nItemIndex)) return;
-
- CPDF_Rect rcPlate = this->GetPlateRect();
- CPDF_Rect rcItem = CFX_List::GetItemRect(nItemIndex);
- CPDF_Rect rcItemCtrl = GetItemRect(nItemIndex);
-
- if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom))
- {
- if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top))
- {
- SetScrollPosY(rcItem.bottom + rcPlate.Height());
- }
- }
- else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top))
- {
- if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom))
- {
- SetScrollPosY(rcItem.top);
- }
- }
-}
-
-void CFX_ListCtrl::SetScrollInfo()
-{
- if (m_pNotify)
- {
- CPDF_Rect rcPlate = GetPlateRect();
- CPDF_Rect rcContent = CFX_List::GetContentRect();
-
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top,
- rcContent.bottom, rcContent.top, GetFirstHeight(), rcPlate.Height());
- m_bNotifyFlag = FALSE;
- }
- }
-}
-
-void CFX_ListCtrl::SetScrollPos(const CPDF_Point & point)
-{
- SetScrollPosY(point.y);
-}
-
-void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy)
-{
- if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y,fy))
- {
- CPDF_Rect rcPlate = this->GetPlateRect();
- CPDF_Rect rcContent = CFX_List::GetContentRect();
-
- if (rcPlate.Height() > rcContent.Height())
- {
- fy = rcPlate.top;
- }
- else
- {
- if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcContent.bottom))
- {
- fy = rcContent.bottom + rcPlate.Height();
- }
- else if (FX_EDIT_IsFloatBigger(fy, rcContent.top))
- {
- fy = rcContent.top;
- }
- }
-
- m_ptScrollPos.y = fy;
- InvalidateItem(-1);
-
- if (m_pNotify)
- {
- if (!m_bNotifyFlag)
- {
- m_bNotifyFlag = TRUE;
- m_pNotify->IOnSetScrollPosY(fy);
- m_bNotifyFlag = FALSE;
- }
- }
- }
-}
-
-CPDF_Rect CFX_ListCtrl::GetContentRect() const
-{
- return InToOut(CFX_List::GetContentRect());
-}
-
-void CFX_ListCtrl::ReArrange(FX_INT32 nItemIndex)
-{
- CFX_List::ReArrange(nItemIndex);
- SetScrollInfo();
-}
-
-void CFX_ListCtrl::SetTopItem(FX_INT32 nIndex)
-{
- if (IsValid(nIndex))
- {
- this->GetPlateRect();
- CPDF_Rect rcItem = CFX_List::GetItemRect(nIndex);
- SetScrollPosY(rcItem.top);
- }
-}
-
-FX_INT32 CFX_ListCtrl::GetTopItem() const
-{
- FX_INT32 nItemIndex = this->GetItemIndex(this->GetBTPoint());
-
- if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1))
- nItemIndex += 1;
-
- return nItemIndex;
-}
-
-void CFX_ListCtrl::Empty()
-{
- CFX_List::Empty();
- InvalidateItem(-1);
-}
-
-void CFX_ListCtrl::Cancel()
-{
- m_aSelItems.DeselectAll();
-}
-
-FX_INT32 CFX_ListCtrl::GetItemIndex(const CPDF_Point & point) const
-{
- return CFX_List::GetItemIndex(OutToIn(point));
-}
-
-CFX_WideString CFX_ListCtrl::GetText() const
-{
- if (this->IsMultipleSel())
- return this->GetItemText(this->m_nCaretIndex);
- else
- return this->GetItemText(this->m_nSelItem);
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fxedit/fxet_stub.h"
+#include "../../include/fxedit/fxet_edit.h"
+#include "../../include/fxedit/fxet_list.h"
+
+/* ------------------------------- CFX_ListItem ---------------------------------- */
+
+CFX_ListItem::CFX_ListItem() : m_pEdit(NULL),
+ m_bSelected(FALSE),
+ m_bCaret(FALSE),
+ m_rcListItem(0.0f,0.0f,0.0f,0.0f)
+{
+ m_pEdit = IFX_Edit::NewEdit();
+ ASSERT(m_pEdit != NULL);
+
+ m_pEdit->SetAlignmentV(1);
+ m_pEdit->Initialize();
+}
+
+CFX_ListItem::~CFX_ListItem()
+{
+ IFX_Edit::DelEdit(m_pEdit);
+}
+
+void CFX_ListItem::SetFontMap(IFX_Edit_FontMap * pFontMap)
+{
+ if (m_pEdit)
+ m_pEdit->SetFontMap(pFontMap);
+}
+
+IFX_Edit* CFX_ListItem::GetEdit() const
+{
+ return m_pEdit;
+}
+
+IFX_Edit_Iterator* CFX_ListItem::GetIterator() const
+{
+ if (m_pEdit)
+ return m_pEdit->GetIterator();
+
+ return NULL;
+}
+
+void CFX_ListItem::SetRect(const CLST_Rect & rect)
+{
+ m_rcListItem = rect;
+}
+
+CLST_Rect CFX_ListItem::GetRect() const
+{
+ return m_rcListItem;
+}
+
+FX_BOOL CFX_ListItem::IsSelected() const
+{
+ return m_bSelected;
+}
+
+void CFX_ListItem::SetSelect(FX_BOOL bSelected)
+{
+ m_bSelected = bSelected;
+}
+
+FX_BOOL CFX_ListItem::IsCaret() const
+{
+ return m_bCaret;
+}
+
+void CFX_ListItem::SetCaret(FX_BOOL bCaret)
+{
+ m_bCaret = bCaret;
+}
+
+void CFX_ListItem::SetText(FX_LPCWSTR text)
+{
+ if (m_pEdit)
+ m_pEdit->SetText(text);
+}
+
+void CFX_ListItem::SetFontSize(FX_FLOAT fFontSize)
+{
+ if (m_pEdit)
+ m_pEdit->SetFontSize(fFontSize);
+}
+
+FX_FLOAT CFX_ListItem::GetItemHeight() const
+{
+ if (m_pEdit)
+ return m_pEdit->GetContentRect().Height();
+
+ return 0.0f;
+}
+
+FX_WORD CFX_ListItem::GetFirstChar() const
+{
+ CPVT_Word word;
+
+ if (IFX_Edit_Iterator* pIterator = GetIterator())
+ {
+ pIterator->SetAt(1);
+ pIterator->GetWord(word);
+ }
+
+ return word.Word;
+}
+
+CFX_WideString CFX_ListItem::GetText() const
+{
+ if (m_pEdit)
+ return m_pEdit->GetText();
+
+ return L"";
+}
+
+/* ------------------------------------ CFX_List --------------------------------- */
+
+CFX_List::CFX_List() : m_pFontMap(NULL), m_fFontSize(0.0f), m_bMultiple(FALSE)
+{
+}
+
+CFX_List::~CFX_List()
+{
+ Empty();
+}
+
+void CFX_List::Empty()
+{
+ for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++)
+ delete m_aListItems.GetAt(i);
+
+ m_aListItems.RemoveAll();
+}
+
+void CFX_List::SetFontMap(IFX_Edit_FontMap * pFontMap)
+{
+ m_pFontMap = pFontMap;
+}
+
+void CFX_List::SetFontSize(FX_FLOAT fFontSize)
+{
+ m_fFontSize = fFontSize;
+}
+
+void CFX_List::AddItem(FX_LPCWSTR str)
+{
+ if (CFX_ListItem * pListItem = new CFX_ListItem())
+ {
+ pListItem->SetFontMap(m_pFontMap);
+ pListItem->SetFontSize(m_fFontSize);
+ pListItem->SetText(str);
+ m_aListItems.Add(pListItem);
+ }
+}
+
+void CFX_List::ReArrange(FX_INT32 nItemIndex)
+{
+ FX_FLOAT fPosY = 0.0f;
+
+ if (CFX_ListItem * pPrevItem = m_aListItems.GetAt(nItemIndex - 1))
+ fPosY = pPrevItem->GetRect().bottom;
+
+ for (FX_INT32 i=nItemIndex,sz=m_aListItems.GetSize(); i<sz; i++)
+ {
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(i))
+ {
+ FX_FLOAT fListItemHeight = pListItem->GetItemHeight();
+ pListItem->SetRect(CLST_Rect(0.0f,fPosY,0.0f,fPosY + fListItemHeight));
+ fPosY += fListItemHeight;
+ }
+ }
+
+ SetContentRect(CLST_Rect(0.0f,0.0f,0.0f,fPosY));
+}
+
+IFX_Edit * CFX_List::GetItemEdit(FX_INT32 nIndex) const
+{
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex))
+ {
+ return pListItem->GetEdit();
+ }
+
+ return NULL;
+}
+
+FX_INT32 CFX_List::GetCount() const
+{
+ return m_aListItems.GetSize();
+}
+
+CPDF_Rect CFX_List::GetPlateRect() const
+{
+ return CFX_ListContainer::GetPlateRect();
+}
+
+CPDF_Rect CFX_List::GetContentRect() const
+{
+ return InnerToOuter(CFX_ListContainer::GetContentRect());
+}
+
+FX_FLOAT CFX_List::GetFontSize() const
+{
+ return m_fFontSize;
+}
+
+FX_INT32 CFX_List::GetItemIndex(const CPDF_Point & point) const
+{
+ CPDF_Point pt = OuterToInner(point);
+
+ FX_BOOL bFirst = TRUE;
+ FX_BOOL bLast = TRUE;
+
+ for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++)
+ {
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(i))
+ {
+ CLST_Rect rcListItem = pListItem->GetRect();
+
+ if (FX_EDIT_IsFloatBigger(pt.y, rcListItem.top))
+ {
+ bFirst = FALSE;
+ }
+
+ if (FX_EDIT_IsFloatSmaller(pt.y, rcListItem.bottom))
+ {
+ bLast = FALSE;
+ }
+
+ if (pt.y >= rcListItem.top && pt.y < rcListItem.bottom)
+ {
+ return i;
+ }
+ }
+ }
+
+ if (bFirst) return 0;
+ if (bLast) return m_aListItems.GetSize()-1;
+
+ return -1;
+}
+
+FX_FLOAT CFX_List::GetFirstHeight() const
+{
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(0))
+ {
+ return pListItem->GetItemHeight();
+ }
+
+ return 1.0f;
+}
+
+FX_INT32 CFX_List::GetFirstSelected() const
+{
+ for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++)
+ {
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(i))
+ {
+ if (pListItem->IsSelected())
+ return i;
+ }
+ }
+ return -1;
+}
+
+FX_INT32 CFX_List::GetLastSelected() const
+{
+ for (FX_INT32 i=m_aListItems.GetSize()-1; i>=0; i--)
+ {
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(i))
+ {
+ if (pListItem->IsSelected())
+ return i;
+ }
+ }
+ return -1;
+}
+
+FX_WCHAR CFX_List::Toupper(FX_WCHAR c) const
+{
+ if ( (c >= 'a') && (c <= 'z') )
+ c = c - ('a' - 'A');
+ return c;
+}
+
+FX_INT32 CFX_List::FindNext(FX_INT32 nIndex,FX_WCHAR nChar) const
+{
+ FX_INT32 nCircleIndex = nIndex;
+
+ for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++)
+ {
+ nCircleIndex ++;
+ if (nCircleIndex >= sz) nCircleIndex = 0;
+
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(nCircleIndex))
+ {
+ if (Toupper(pListItem->GetFirstChar()) == Toupper(nChar))
+ return nCircleIndex;
+ }
+ }
+
+ return nCircleIndex;
+}
+
+CPDF_Rect CFX_List::GetItemRect(FX_INT32 nIndex) const
+{
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex))
+ {
+ CPDF_Rect rcItem = pListItem->GetRect();
+ rcItem.left = 0.0f;
+ rcItem.right = GetPlateRect().Width();
+ return InnerToOuter(rcItem);
+ }
+
+ return CPDF_Rect();
+}
+
+FX_BOOL CFX_List::IsItemSelected(FX_INT32 nIndex) const
+{
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex))
+ {
+ return pListItem->IsSelected();
+ }
+
+ return FALSE;
+}
+
+void CFX_List::SetItemSelect(FX_INT32 nItemIndex, FX_BOOL bSelected)
+{
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(nItemIndex))
+ {
+ pListItem->SetSelect(bSelected);
+ }
+}
+
+void CFX_List::SetItemCaret(FX_INT32 nItemIndex, FX_BOOL bCaret)
+{
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(nItemIndex))
+ {
+ pListItem->SetCaret(bCaret);
+ }
+}
+
+void CFX_List::SetMultipleSel(FX_BOOL bMultiple)
+{
+ m_bMultiple = bMultiple;
+}
+
+FX_BOOL CFX_List::IsMultipleSel() const
+{
+ return m_bMultiple;
+}
+
+FX_BOOL CFX_List::IsValid(FX_INT32 nItemIndex) const
+{
+ return nItemIndex >= 0 && nItemIndex < m_aListItems.GetSize();
+}
+
+CFX_WideString CFX_List::GetItemText(FX_INT32 nIndex) const
+{
+ if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex))
+ {
+ return pListItem->GetText();
+ }
+
+ return L"";
+}
+
+/* ------------------------------------ CPLST_Select ---------------------------------- */
+
+CPLST_Select::CPLST_Select()
+{
+}
+
+CPLST_Select::~CPLST_Select()
+{
+ for (FX_INT32 i=0,sz=m_aItems.GetSize(); i<sz; i++)
+ delete m_aItems.GetAt(i);
+
+ m_aItems.RemoveAll();
+}
+
+void CPLST_Select::Add(FX_INT32 nItemIndex)
+{
+ FX_INT32 nIndex = Find(nItemIndex);
+
+ if (nIndex < 0)
+ m_aItems.Add(new CPLST_Select_Item(nItemIndex,1));
+ else
+ {
+ if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex))
+ {
+ pItem->nState = 1;
+ }
+ }
+}
+
+void CPLST_Select::Add(FX_INT32 nBeginIndex, FX_INT32 nEndIndex)
+{
+ if (nBeginIndex > nEndIndex)
+ {
+ FX_INT32 nTemp = nEndIndex;
+ nEndIndex = nBeginIndex;
+ nBeginIndex = nTemp;
+ }
+
+ for (FX_INT32 i=nBeginIndex; i<=nEndIndex; i++) Add(i);
+}
+
+void CPLST_Select::Sub(FX_INT32 nItemIndex)
+{
+ for (FX_INT32 i=m_aItems.GetSize()-1; i>=0; i--)
+ {
+ if (CPLST_Select_Item * pItem = m_aItems.GetAt(i))
+ if (pItem->nItemIndex == nItemIndex)
+ pItem->nState = -1;
+ }
+}
+
+void CPLST_Select::Sub(FX_INT32 nBeginIndex, FX_INT32 nEndIndex)
+{
+ if (nBeginIndex > nEndIndex)
+ {
+ FX_INT32 nTemp = nEndIndex;
+ nEndIndex = nBeginIndex;
+ nBeginIndex = nTemp;
+ }
+
+ for (FX_INT32 i=nBeginIndex; i<=nEndIndex; i++) Sub(i);
+}
+
+FX_INT32 CPLST_Select::Find(FX_INT32 nItemIndex) const
+{
+ for (FX_INT32 i=0,sz=m_aItems.GetSize(); i<sz; i++)
+ {
+ if (CPLST_Select_Item * pItem = m_aItems.GetAt(i))
+ {
+ if (pItem->nItemIndex == nItemIndex)
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+FX_BOOL CPLST_Select::IsExist(FX_INT32 nItemIndex) const
+{
+ return Find(nItemIndex) >= 0;
+}
+
+FX_INT32 CPLST_Select::GetCount() const
+{
+ return m_aItems.GetSize();
+}
+
+FX_INT32 CPLST_Select::GetItemIndex(FX_INT32 nIndex) const
+{
+ if (nIndex >= 0 && nIndex < m_aItems.GetSize())
+ if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex))
+ return pItem->nItemIndex;
+
+ return -1;
+}
+
+FX_INT32 CPLST_Select::GetState(FX_INT32 nIndex) const
+{
+ if (nIndex >= 0 && nIndex < m_aItems.GetSize())
+ if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex))
+ return pItem->nState;
+
+ return 0;
+}
+
+void CPLST_Select::DeselectAll()
+{
+ for (FX_INT32 i=0,sz=m_aItems.GetSize(); i<sz; i++)
+ {
+ if (CPLST_Select_Item * pItem = m_aItems.GetAt(i))
+ {
+ pItem->nState = -1;
+ }
+ }
+}
+
+void CPLST_Select::Done()
+{
+ for (FX_INT32 i=m_aItems.GetSize()-1; i>=0; i--)
+ {
+ if (CPLST_Select_Item * pItem = m_aItems.GetAt(i))
+ {
+ if (pItem->nState == -1)
+ {
+ delete pItem;
+ m_aItems.RemoveAt(i);
+ }
+ else
+ {
+ pItem->nState = 0;
+ }
+ }
+ }
+}
+
+/* ------------------------------------ CFX_ListCtrl --------------------------------- */
+
+CFX_ListCtrl::CFX_ListCtrl() : m_pNotify(NULL),
+ m_ptScrollPos(0.0f,0.0f),
+ m_nSelItem(-1),
+ m_nFootIndex(-1),
+ m_bCtrlSel(FALSE),
+ m_nCaretIndex(-1),
+ m_bNotifyFlag(FALSE)
+{
+}
+
+CFX_ListCtrl::~CFX_ListCtrl()
+{
+}
+
+void CFX_ListCtrl::SetNotify(IFX_List_Notify * pNotify)
+{
+ m_pNotify = pNotify;
+}
+
+CPDF_Point CFX_ListCtrl::InToOut(const CPDF_Point & point) const
+{
+ CPDF_Rect rcPlate = GetPlateRect();
+
+ return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left),
+ point.y - (m_ptScrollPos.y - rcPlate.top));
+}
+
+CPDF_Point CFX_ListCtrl::OutToIn(const CPDF_Point & point) const
+{
+ CPDF_Rect rcPlate = GetPlateRect();
+
+ return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left),
+ point.y + (m_ptScrollPos.y - rcPlate.top));
+}
+
+CPDF_Rect CFX_ListCtrl::InToOut(const CPDF_Rect & rect) const
+{
+ CPDF_Point ptLeftBottom = InToOut(CPDF_Point(rect.left,rect.bottom));
+ CPDF_Point ptRightTop = InToOut(CPDF_Point(rect.right,rect.top));
+
+ return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y);
+}
+
+CPDF_Rect CFX_ListCtrl::OutToIn(const CPDF_Rect & rect) const
+{
+ CPDF_Point ptLeftBottom = OutToIn(CPDF_Point(rect.left,rect.bottom));
+ CPDF_Point ptRightTop = OutToIn(CPDF_Point(rect.right,rect.top));
+
+ return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y);
+}
+
+void CFX_ListCtrl::OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ FX_INT32 nHitIndex = this->GetItemIndex(point);
+
+ if (IsMultipleSel())
+ {
+ if (bCtrl)
+ {
+ if (IsItemSelected(nHitIndex))
+ {
+ m_aSelItems.Sub(nHitIndex);
+ SelectItems();
+ m_bCtrlSel = FALSE;
+ }
+ else
+ {
+ m_aSelItems.Add(nHitIndex);
+ SelectItems();
+ m_bCtrlSel = TRUE;
+ }
+
+ m_nFootIndex = nHitIndex;
+ }
+ else if (bShift)
+ {
+ m_aSelItems.DeselectAll();
+ m_aSelItems.Add(m_nFootIndex,nHitIndex);
+ SelectItems();
+ }
+ else
+ {
+ m_aSelItems.DeselectAll();
+ m_aSelItems.Add(nHitIndex);
+ SelectItems();
+
+ m_nFootIndex = nHitIndex;
+ }
+
+ SetCaret(nHitIndex);
+ }
+ else
+ {
+ SetSingleSelect(nHitIndex);
+ }
+
+ if (!this->IsItemVisible(nHitIndex))
+ this->ScrollToListItem(nHitIndex);
+}
+
+void CFX_ListCtrl::OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ FX_INT32 nHitIndex = this->GetItemIndex(point);
+
+ if (IsMultipleSel())
+ {
+ if (bCtrl)
+ {
+ if (m_bCtrlSel)
+ m_aSelItems.Add(m_nFootIndex,nHitIndex);
+ else
+ m_aSelItems.Sub(m_nFootIndex,nHitIndex);
+
+ SelectItems();
+ }
+ else
+ {
+ m_aSelItems.DeselectAll();
+ m_aSelItems.Add(m_nFootIndex,nHitIndex);
+ SelectItems();
+ }
+
+ SetCaret(nHitIndex);
+ }
+ else
+ {
+ SetSingleSelect(nHitIndex);
+ }
+
+ if (!this->IsItemVisible(nHitIndex))
+ this->ScrollToListItem(nHitIndex);
+}
+
+void CFX_ListCtrl::OnVK(FX_INT32 nItemIndex,FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ if (IsMultipleSel())
+ {
+ if (nItemIndex >= 0 && nItemIndex < GetCount())
+ {
+ if (bCtrl)
+ {
+ }
+ else if (bShift)
+ {
+ m_aSelItems.DeselectAll();
+ m_aSelItems.Add(m_nFootIndex,nItemIndex);
+ SelectItems();
+ }
+ else
+ {
+ m_aSelItems.DeselectAll();
+ m_aSelItems.Add(nItemIndex);
+ SelectItems();
+ m_nFootIndex = nItemIndex;
+ }
+
+ SetCaret(nItemIndex);
+ }
+ }
+ else
+ {
+ SetSingleSelect(nItemIndex);
+ }
+
+ if (!this->IsItemVisible(nItemIndex))
+ this->ScrollToListItem(nItemIndex);
+}
+
+void CFX_ListCtrl::OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ OnVK(IsMultipleSel() ? GetCaret()-1 : GetSelect()-1, bShift, bCtrl);
+}
+
+void CFX_ListCtrl::OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ OnVK(IsMultipleSel() ? GetCaret()+1 : GetSelect()+1, bShift, bCtrl);
+}
+
+void CFX_ListCtrl::OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ OnVK(0, bShift, bCtrl);
+}
+
+void CFX_ListCtrl::OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ OnVK(GetCount()-1, bShift, bCtrl);
+}
+
+void CFX_ListCtrl::OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ OnVK(0, bShift, bCtrl);
+}
+
+void CFX_ListCtrl::OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ OnVK(GetCount()-1, bShift, bCtrl);
+}
+
+FX_BOOL CFX_ListCtrl::OnChar(FX_WORD nChar,FX_BOOL bShift,FX_BOOL bCtrl)
+{
+ FX_INT32 nIndex = GetLastSelected();
+ FX_INT32 nFindIndex = FindNext(nIndex,nChar);
+
+ if (nFindIndex != nIndex)
+ {
+ OnVK(nFindIndex, bShift, bCtrl);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/* -------- inner methods ------- */
+
+void CFX_ListCtrl::SetPlateRect(const CPDF_Rect & rect)
+{
+ CFX_ListContainer::SetPlateRect(rect);
+ m_ptScrollPos.x = rect.left;
+ SetScrollPos(CPDF_Point(rect.left,rect.top));
+ ReArrange(0);
+ InvalidateItem(-1);
+}
+
+CPDF_Rect CFX_ListCtrl::GetItemRect(FX_INT32 nIndex) const
+{
+ return InToOut(CFX_List::GetItemRect(nIndex));
+}
+
+void CFX_ListCtrl::AddString(FX_LPCWSTR string)
+{
+ AddItem(string);
+ ReArrange(GetCount() - 1);
+}
+
+void CFX_ListCtrl::SetMultipleSelect(FX_INT32 nItemIndex, FX_BOOL bSelected)
+{
+ if (!IsValid(nItemIndex)) return;
+
+ if (bSelected != this->IsItemSelected(nItemIndex))
+ {
+ if (bSelected)
+ {
+ SetItemSelect(nItemIndex,TRUE);
+ InvalidateItem(nItemIndex);
+ }
+ else
+ {
+ SetItemSelect(nItemIndex,FALSE);
+ InvalidateItem(nItemIndex);
+ }
+ }
+}
+
+void CFX_ListCtrl::SetSingleSelect(FX_INT32 nItemIndex)
+{
+ if (!IsValid(nItemIndex)) return;
+
+ if (m_nSelItem != nItemIndex)
+ {
+ if (m_nSelItem >= 0)
+ {
+ SetItemSelect(m_nSelItem,FALSE);
+ InvalidateItem(m_nSelItem);
+ }
+
+ SetItemSelect(nItemIndex,TRUE);
+ InvalidateItem(nItemIndex);
+ m_nSelItem = nItemIndex;
+ }
+}
+
+void CFX_ListCtrl::SetCaret(FX_INT32 nItemIndex)
+{
+ if (!IsValid(nItemIndex)) return;
+
+ if (this->IsMultipleSel())
+ {
+ FX_INT32 nOldIndex = m_nCaretIndex;
+
+ if (nOldIndex != nItemIndex)
+ {
+ m_nCaretIndex = nItemIndex;
+
+ SetItemCaret(nOldIndex, FALSE);
+ SetItemCaret(nItemIndex,TRUE);
+
+ InvalidateItem(nOldIndex);
+ InvalidateItem(nItemIndex);
+ }
+ }
+}
+
+void CFX_ListCtrl::InvalidateItem(FX_INT32 nItemIndex)
+{
+ if (m_pNotify)
+ {
+ if (nItemIndex == -1)
+ {
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ CPDF_Rect rcRefresh = GetPlateRect();
+ m_pNotify->IOnInvalidateRect(&rcRefresh);
+ m_bNotifyFlag = FALSE;
+ }
+ }
+ else
+ {
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ CPDF_Rect rcRefresh = GetItemRect(nItemIndex);
+ rcRefresh.left -= 1.0f;
+ rcRefresh.right += 1.0f;
+ rcRefresh.bottom -= 1.0f;
+ rcRefresh.top += 1.0f;
+
+ m_pNotify->IOnInvalidateRect(&rcRefresh);
+ m_bNotifyFlag = FALSE;
+ }
+ }
+ }
+}
+
+void CFX_ListCtrl::SelectItems()
+{
+ for (FX_INT32 i=0,sz=m_aSelItems.GetCount(); i<sz; i++)
+ {
+ FX_INT32 nItemIndex = m_aSelItems.GetItemIndex(i);
+ FX_INT32 nState = m_aSelItems.GetState(i);
+
+ switch(nState)
+ {
+ case 1:
+ SetMultipleSelect(nItemIndex, TRUE);
+ break;
+ case -1:
+ SetMultipleSelect(nItemIndex, FALSE);
+ break;
+ }
+ }
+
+ m_aSelItems.Done();
+}
+
+void CFX_ListCtrl::Select(FX_INT32 nItemIndex)
+{
+ if (!IsValid(nItemIndex)) return;
+
+ if (this->IsMultipleSel())
+ {
+ m_aSelItems.Add(nItemIndex);
+ SelectItems();
+ }
+ else
+ SetSingleSelect(nItemIndex);
+}
+
+FX_BOOL CFX_ListCtrl::IsItemVisible(FX_INT32 nItemIndex) const
+{
+ CPDF_Rect rcPlate = this->GetPlateRect();
+ CPDF_Rect rcItem = this->GetItemRect(nItemIndex);
+
+ return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top;
+}
+
+void CFX_ListCtrl::ScrollToListItem(FX_INT32 nItemIndex)
+{
+ if (!IsValid(nItemIndex)) return;
+
+ CPDF_Rect rcPlate = this->GetPlateRect();
+ CPDF_Rect rcItem = CFX_List::GetItemRect(nItemIndex);
+ CPDF_Rect rcItemCtrl = GetItemRect(nItemIndex);
+
+ if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom))
+ {
+ if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top))
+ {
+ SetScrollPosY(rcItem.bottom + rcPlate.Height());
+ }
+ }
+ else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top))
+ {
+ if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom))
+ {
+ SetScrollPosY(rcItem.top);
+ }
+ }
+}
+
+void CFX_ListCtrl::SetScrollInfo()
+{
+ if (m_pNotify)
+ {
+ CPDF_Rect rcPlate = GetPlateRect();
+ CPDF_Rect rcContent = CFX_List::GetContentRect();
+
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top,
+ rcContent.bottom, rcContent.top, GetFirstHeight(), rcPlate.Height());
+ m_bNotifyFlag = FALSE;
+ }
+ }
+}
+
+void CFX_ListCtrl::SetScrollPos(const CPDF_Point & point)
+{
+ SetScrollPosY(point.y);
+}
+
+void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy)
+{
+ if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y,fy))
+ {
+ CPDF_Rect rcPlate = this->GetPlateRect();
+ CPDF_Rect rcContent = CFX_List::GetContentRect();
+
+ if (rcPlate.Height() > rcContent.Height())
+ {
+ fy = rcPlate.top;
+ }
+ else
+ {
+ if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcContent.bottom))
+ {
+ fy = rcContent.bottom + rcPlate.Height();
+ }
+ else if (FX_EDIT_IsFloatBigger(fy, rcContent.top))
+ {
+ fy = rcContent.top;
+ }
+ }
+
+ m_ptScrollPos.y = fy;
+ InvalidateItem(-1);
+
+ if (m_pNotify)
+ {
+ if (!m_bNotifyFlag)
+ {
+ m_bNotifyFlag = TRUE;
+ m_pNotify->IOnSetScrollPosY(fy);
+ m_bNotifyFlag = FALSE;
+ }
+ }
+ }
+}
+
+CPDF_Rect CFX_ListCtrl::GetContentRect() const
+{
+ return InToOut(CFX_List::GetContentRect());
+}
+
+void CFX_ListCtrl::ReArrange(FX_INT32 nItemIndex)
+{
+ CFX_List::ReArrange(nItemIndex);
+ SetScrollInfo();
+}
+
+void CFX_ListCtrl::SetTopItem(FX_INT32 nIndex)
+{
+ if (IsValid(nIndex))
+ {
+ this->GetPlateRect();
+ CPDF_Rect rcItem = CFX_List::GetItemRect(nIndex);
+ SetScrollPosY(rcItem.top);
+ }
+}
+
+FX_INT32 CFX_ListCtrl::GetTopItem() const
+{
+ FX_INT32 nItemIndex = this->GetItemIndex(this->GetBTPoint());
+
+ if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1))
+ nItemIndex += 1;
+
+ return nItemIndex;
+}
+
+void CFX_ListCtrl::Empty()
+{
+ CFX_List::Empty();
+ InvalidateItem(-1);
+}
+
+void CFX_ListCtrl::Cancel()
+{
+ m_aSelItems.DeselectAll();
+}
+
+FX_INT32 CFX_ListCtrl::GetItemIndex(const CPDF_Point & point) const
+{
+ return CFX_List::GetItemIndex(OutToIn(point));
+}
+
+CFX_WideString CFX_ListCtrl::GetText() const
+{
+ if (this->IsMultipleSel())
+ return this->GetItemText(this->m_nCaretIndex);
+ else
+ return this->GetItemText(this->m_nSelItem);
+}
+
diff --git a/fpdfsdk/src/fxedit/fxet_module.cpp b/fpdfsdk/src/fxedit/fxet_module.cpp
index b13af89833..9ca7f2eb32 100644
--- a/fpdfsdk/src/fxedit/fxet_module.cpp
+++ b/fpdfsdk/src/fxedit/fxet_module.cpp
@@ -1,46 +1,46 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/fxedit/fxet_stub.h"
-#include "../../include/fxedit/fxet_edit.h"
-#include "../../include/fxedit/fxet_list.h"
-
-/* ---------------------- IFX_Edit ---------------------- */
-
-IFX_Edit* IFX_Edit::NewEdit()
-{
- if (IPDF_VariableText * pVT = IPDF_VariableText::NewVariableText())
- {
- return new CFX_Edit(pVT);
- }
-
- return NULL;
-}
-
-void IFX_Edit::DelEdit(IFX_Edit* pEdit)
-{
- ASSERT(pEdit != NULL);
-
- IPDF_VariableText::DelVariableText(pEdit->GetVariableText());
-
- delete (CFX_Edit*)pEdit;
-}
-
-
-/* ---------------------- IFX_List ---------------------- */
-
-IFX_List* IFX_List::NewList()
-{
- return new CFX_ListCtrl();
-}
-
-void IFX_List::DelList(IFX_List* pList)
-{
- ASSERT(pList != NULL);
-
- delete (CFX_ListCtrl*)pList;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fxedit/fxet_stub.h"
+#include "../../include/fxedit/fxet_edit.h"
+#include "../../include/fxedit/fxet_list.h"
+
+/* ---------------------- IFX_Edit ---------------------- */
+
+IFX_Edit* IFX_Edit::NewEdit()
+{
+ if (IPDF_VariableText * pVT = IPDF_VariableText::NewVariableText())
+ {
+ return new CFX_Edit(pVT);
+ }
+
+ return NULL;
+}
+
+void IFX_Edit::DelEdit(IFX_Edit* pEdit)
+{
+ ASSERT(pEdit != NULL);
+
+ IPDF_VariableText::DelVariableText(pEdit->GetVariableText());
+
+ delete (CFX_Edit*)pEdit;
+}
+
+
+/* ---------------------- IFX_List ---------------------- */
+
+IFX_List* IFX_List::NewList()
+{
+ return new CFX_ListCtrl();
+}
+
+void IFX_List::DelList(IFX_List* pList)
+{
+ ASSERT(pList != NULL);
+
+ delete (CFX_ListCtrl*)pList;
+}
+
diff --git a/fpdfsdk/src/fxedit/fxet_pageobjs.cpp b/fpdfsdk/src/fxedit/fxet_pageobjs.cpp
index 99520619ad..33d57edc4e 100644
--- a/fpdfsdk/src/fxedit/fxet_pageobjs.cpp
+++ b/fpdfsdk/src/fxedit/fxet_pageobjs.cpp
@@ -1,687 +1,687 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/fxedit/fxet_stub.h"
-#include "../../include/fxedit/fx_edit.h"
-#include "../../include/fxedit/fxet_edit.h"
-
-#define FX_EDIT_UNDERLINEHALFWIDTH 0.5f
-#define FX_EDIT_CROSSOUTHALFWIDTH 0.5f
-
-extern CFX_ByteString GetPDFWordString(IFX_Edit_FontMap * pFontMap, FX_INT32 nFontIndex, FX_WORD Word, FX_WORD SubWord);
-
-CPDF_Rect GetUnderLineRect(const CPVT_Word& word)
-{
- return CPDF_Rect(word.ptWord.x, word.ptWord.y + word.fDescent * 0.5f,
- word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent * 0.25f);
-}
-
-CPDF_Rect GetCrossoutRect(const CPVT_Word& word)
-{
- return CPDF_Rect(word.ptWord.x, word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f + word.fDescent * 0.25f,
- word.ptWord.x + word.fWidth, word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f);
-}
-
-static void DrawTextString(CFX_RenderDevice* pDevice, const CPDF_Point& pt, CPDF_Font* pFont, FX_FLOAT fFontSize, CPDF_Matrix* pUser2Device,
- const CFX_ByteString& str, FX_ARGB crTextFill, FX_ARGB crTextStroke, FX_INT32 nHorzScale)
-{
- FX_FLOAT x = pt.x, y = pt.y;
- pUser2Device->Transform(x, y);
-
- if (pFont)
- {
- if (nHorzScale != 100)
- {
- CPDF_Matrix mt(nHorzScale/100.0f,0,0,1,0,0);
- mt.Concat(*pUser2Device);
-
- CPDF_RenderOptions ro;
- ro.m_Flags = RENDER_CLEARTYPE;
- ro.m_ColorMode = RENDER_COLOR_NORMAL;
-
- if (crTextStroke != 0)
- {
- CPDF_Point pt1(0,0), pt2(1,0);
- pUser2Device->Transform(pt1.x, pt1.y);
- pUser2Device->Transform(pt2.x, pt2.y);
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y));
-
- CPDF_TextRenderer::DrawTextString(pDevice,x, y, pFont, fFontSize, &mt, str, crTextFill, crTextStroke, &gsd, &ro);
- }
- else
- CPDF_TextRenderer::DrawTextString(pDevice,x, y, pFont, fFontSize, &mt, str, crTextFill, 0, NULL, &ro);
- }
- else
- {
- CPDF_RenderOptions ro;
- ro.m_Flags = RENDER_CLEARTYPE;
- ro.m_ColorMode = RENDER_COLOR_NORMAL;
-
- if (crTextStroke != 0)
- {
- CPDF_Point pt1(0,0), pt2(1,0);
- pUser2Device->Transform(pt1.x, pt1.y);
- pUser2Device->Transform(pt2.x, pt2.y);
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y));
-
- CPDF_TextRenderer::DrawTextString(pDevice,x, y, pFont, fFontSize, pUser2Device, str, crTextFill, crTextStroke, &gsd, &ro);
- }
- else
- CPDF_TextRenderer::DrawTextString(pDevice,x, y, pFont, fFontSize, pUser2Device, str, crTextFill, 0, NULL, &ro);
- }
- }
-}
-
-void IFX_Edit::DrawUnderline(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit, FX_COLORREF color,
- const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange)
-{
- pDevice->SaveState();
-
- if (!rcClip.IsEmpty())
- {
- CPDF_Rect rcTemp = rcClip;
- pUser2Device->TransformRect(rcTemp);
- FX_RECT rcDevClip;
- rcDevClip.left = (FX_INT32)rcTemp.left;
- rcDevClip.right = (FX_INT32)rcTemp.right;
- rcDevClip.top = (FX_INT32)rcTemp.top;
- rcDevClip.bottom = (FX_INT32)rcTemp.bottom;
- pDevice->SetClip_Rect(&rcDevClip);
- }
-
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- if (pEdit->GetFontMap())
- {
- if (pRange)
- pIterator->SetAt(pRange->BeginPos);
- else
- pIterator->SetAt(0);
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- CFX_PathData pathUnderline;
- CPDF_Rect rcUnderline = GetUnderLineRect(word);
- rcUnderline.left += ptOffset.x;
- rcUnderline.right += ptOffset.x;
- rcUnderline.top += ptOffset.y;
- rcUnderline.bottom += ptOffset.y;
- pathUnderline.AppendRect(rcUnderline.left, rcUnderline.bottom, rcUnderline.right, rcUnderline.top);
-
- pDevice->DrawPath(&pathUnderline, pUser2Device, NULL, color, 0, FXFILL_WINDING);
- }
- }
- }
- }
-
- pDevice->RestoreState();
-}
-
-void IFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit, FX_COLORREF crTextFill, FX_COLORREF crTextStroke,
- const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, IFX_SystemHandler* pSystemHandler, void* pFFLData)
-{
-
- FX_BOOL bContinuous = pEdit->GetCharArray() == 0;
- if (pEdit->GetCharSpace() > 0.0f)
- bContinuous = FALSE;
-
- FX_WORD SubWord = pEdit->GetPasswordChar();
- FX_FLOAT fFontSize = pEdit->GetFontSize();
- CPVT_WordRange wrSelect = pEdit->GetSelectWordRange();
- FX_INT32 nHorzScale = pEdit->GetHorzScale();
-
- FX_COLORREF crCurFill = crTextFill;
- FX_COLORREF crOldFill = crCurFill;
-
- FX_BOOL bSelect = FALSE;
- const FX_COLORREF crWhite = ArgbEncode(255,255,255,255);
- const FX_COLORREF crSelBK = ArgbEncode(255,0,51,113);
-
- CFX_ByteTextBuf sTextBuf;
- FX_INT32 nFontIndex = -1;
- CPDF_Point ptBT(0.0f,0.0f);
-
- pDevice->SaveState();
-
- if (!rcClip.IsEmpty())
- {
- CPDF_Rect rcTemp = rcClip;
- pUser2Device->TransformRect(rcTemp);
- FX_RECT rcDevClip;
- rcDevClip.left = (FX_INT32)rcTemp.left;
- rcDevClip.right = (FX_INT32)rcTemp.right;
- rcDevClip.top = (FX_INT32)rcTemp.top;
- rcDevClip.bottom = (FX_INT32)rcTemp.bottom;
- pDevice->SetClip_Rect(&rcDevClip);
- }
-
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap())
- {
- if (pRange)
- pIterator->SetAt(pRange->BeginPos);
- else
- pIterator->SetAt(0);
-
- CPVT_WordPlace oldplace;
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- if (wrSelect.IsExist())
- {
- bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && place.WordCmp(wrSelect.EndPos) <= 0;
- if (bSelect)
- {
- crCurFill = crWhite;
- }
- else
- {
- crCurFill = crTextFill;
- }
- }
- if(pSystemHandler && pSystemHandler->IsSelectionImplemented())
- {
- crCurFill = crTextFill;
- crOldFill = crCurFill;
- }
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
-
- if (bSelect)
- {
-
- CPVT_Line line;
- pIterator->GetLine(line);
-
- if(pSystemHandler && pSystemHandler->IsSelectionImplemented())
- {
- CPDF_Rect rc(word.ptWord.x,line.ptLine.y + line.fLineDescent,
- word.ptWord.x+word.fWidth,line.ptLine.y + line.fLineAscent);
- rc.Intersect(rcClip);
- //CFX_Edit* pEt = (CFX_Edit*)pEdit;
- //CPDF_Rect rcEdit = pEt->VTToEdit(rc);
- pSystemHandler->OutputSelectedRect(pFFLData,rc);
- }
- else
- {
- CFX_PathData pathSelBK;
- pathSelBK.AppendRect(word.ptWord.x,line.ptLine.y + line.fLineDescent,
- word.ptWord.x+word.fWidth,line.ptLine.y + line.fLineAscent);
-
- pDevice->DrawPath(&pathSelBK, pUser2Device, NULL, crSelBK, 0, FXFILL_WINDING);
- }
- }
-
- if (bContinuous)
- {
- if (place.LineCmp(oldplace) != 0 || word.nFontIndex != nFontIndex ||
- crOldFill != crCurFill)
- {
- if (sTextBuf.GetLength() > 0)
- {
- DrawTextString(pDevice, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), pFontMap->GetPDFFont(nFontIndex),
- fFontSize, pUser2Device, sTextBuf.GetByteString(), crOldFill, crTextStroke, nHorzScale);
-
- sTextBuf.Clear();
- }
- nFontIndex = word.nFontIndex;
- ptBT = word.ptWord;
- crOldFill = crCurFill;
- }
-
- sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, SubWord);
- }
- else
- {
- DrawTextString(pDevice,CPDF_Point(word.ptWord.x+ptOffset.x, word.ptWord.y+ptOffset.y), pFontMap->GetPDFFont(word.nFontIndex),
- fFontSize, pUser2Device, GetPDFWordString(pFontMap, word.nFontIndex, word.Word, SubWord), crCurFill, crTextStroke, nHorzScale);
-
- }
- oldplace = place;
-
-
- }
- }
-
- if (sTextBuf.GetLength() > 0)
- {
- DrawTextString(pDevice, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), pFontMap->GetPDFFont(nFontIndex),
- fFontSize, pUser2Device, sTextBuf.GetByteString(), crOldFill, crTextStroke, nHorzScale);
- }
- }
- }
-
- pDevice->RestoreState();
-}
-
-void IFX_Edit::DrawRichEdit(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit,
- const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange)
-{
- //FX_FLOAT fFontSize = pEdit->GetFontSize();
- CPVT_WordRange wrSelect = pEdit->GetSelectWordRange();
-
- FX_COLORREF crCurText = ArgbEncode(255, 0,0,0);
- FX_COLORREF crOld = crCurText;
- FX_BOOL bSelect = FALSE;
- const FX_COLORREF crWhite = ArgbEncode(255,255,255,255);
- const FX_COLORREF crSelBK = ArgbEncode(255,0,51,113);
-
- CFX_ByteTextBuf sTextBuf;
- CPVT_WordProps wp;
- CPDF_Point ptBT(0.0f,0.0f);
-
- pDevice->SaveState();
-
- if (!rcClip.IsEmpty())
- {
- CPDF_Rect rcTemp = rcClip;
- pUser2Device->TransformRect(rcTemp);
- FX_RECT rcDevClip;
- rcDevClip.left = (FX_INT32)rcTemp.left;
- rcDevClip.right = (FX_INT32)rcTemp.right;
- rcDevClip.top = (FX_INT32)rcTemp.top;
- rcDevClip.bottom = (FX_INT32)rcTemp.bottom;
- pDevice->SetClip_Rect(&rcDevClip);
- }
-
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap())
- {
- if (pRange)
- pIterator->SetAt(pRange->BeginPos);
- else
- pIterator->SetAt(0);
-
- CPVT_WordPlace oldplace;
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- word.WordProps.fFontSize = word.fFontSize;
-
- crCurText = ArgbEncode(255,word.WordProps.dwWordColor);
-
- if (wrSelect.IsExist())
- {
- bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && place.WordCmp(wrSelect.EndPos) <= 0;
- if (bSelect)
- {
- crCurText = crWhite;
- }
- }
-
- if (bSelect)
- {
- CPVT_Line line;
- pIterator->GetLine(line);
-
- CFX_PathData pathSelBK;
- pathSelBK.AppendRect(word.ptWord.x + ptOffset.x,
- line.ptLine.y + line.fLineDescent + ptOffset.y,
- word.ptWord.x+word.fWidth + ptOffset.x,
- line.ptLine.y + line.fLineAscent + ptOffset.y);
-
- pDevice->DrawPath(&pathSelBK, pUser2Device, NULL, crSelBK, 0, FXFILL_WINDING);
- }
-
- if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || word.WordProps.nHorzScale != 100 ||
- FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 ||
- crOld != crCurText)
- {
- if (sTextBuf.GetLength() > 0)
- {
- DrawTextString(pDevice, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), pFontMap->GetPDFFont(wp.nFontIndex),
- wp.fFontSize, pUser2Device, sTextBuf.GetByteString(), crOld, 0, wp.nHorzScale);
-
- sTextBuf.Clear();
- }
- wp = word.WordProps;
- ptBT = word.ptWord;
- crOld = crCurText;
- }
-
- sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, word.Word, 0);
-
- if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE)
- {
- CFX_PathData pathUnderline;
- CPDF_Rect rcUnderline = GetUnderLineRect(word);
- pathUnderline.AppendRect(rcUnderline.left, rcUnderline.bottom, rcUnderline.right, rcUnderline.top);
-
- pDevice->DrawPath(&pathUnderline, pUser2Device, NULL, crCurText, 0, FXFILL_WINDING);
- }
-
- if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT)
- {
- CFX_PathData pathCrossout;
- CPDF_Rect rcCrossout = GetCrossoutRect(word);
- pathCrossout.AppendRect(rcCrossout.left, rcCrossout.bottom, rcCrossout.right, rcCrossout.top);
-
- pDevice->DrawPath(&pathCrossout, pUser2Device, NULL, crCurText, 0, FXFILL_WINDING);
- }
-
- oldplace = place;
- }
- }
-
- if (sTextBuf.GetLength() > 0)
- {
- DrawTextString(pDevice, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), pFontMap->GetPDFFont(wp.nFontIndex),
- wp.fFontSize, pUser2Device, sTextBuf.GetByteString(), crOld, 0, wp.nHorzScale);
- }
- }
- }
-
- pDevice->RestoreState();
-}
-
-static void AddLineToPageObjects(CPDF_PageObjects* pPageObjs, FX_COLORREF crStroke,
- const CPDF_Point& pt1, const CPDF_Point& pt2)
-{
- CPDF_PathObject* pPathObj = new CPDF_PathObject;
- CPDF_PathData* pPathData = pPathObj->m_Path.GetModify();
-
- pPathData->SetPointCount(2);
- pPathData->SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
- pPathData->SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
-
- FX_FLOAT rgb[3];
- rgb[0] = FXARGB_R(crStroke) / 255.0f;
- rgb[1] = FXARGB_G(crStroke) / 255.0f;
- rgb[2] = FXARGB_B(crStroke) / 255.0f;
- pPathObj->m_ColorState.SetStrokeColor(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3);
-
- CFX_GraphStateData* pData = pPathObj->m_GraphState.GetModify();
- pData->m_LineWidth = 1;
-
- pPageObjs->InsertObject(pPageObjs->GetLastObjectPosition(),pPathObj);
-}
-
-static void AddRectToPageObjects(CPDF_PageObjects* pPageObjs, FX_COLORREF crFill, const CPDF_Rect& rcFill)
-{
- CPDF_PathObject* pPathObj = new CPDF_PathObject;
- CPDF_PathData* pPathData = pPathObj->m_Path.GetModify();
- pPathData->AppendRect(rcFill.left,rcFill.bottom,rcFill.right,rcFill.top);
-
- FX_FLOAT rgb[3];
- rgb[0] = FXARGB_R(crFill) / 255.0f ;
- rgb[1] = FXARGB_G(crFill) / 255.0f;
- rgb[2] = FXARGB_B(crFill) / 255.0f;
- pPathObj->m_ColorState.SetFillColor(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3);
-
- pPathObj->m_FillType = FXFILL_ALTERNATE;
- pPathObj->m_bStroke = FALSE;
-
- pPageObjs->InsertObject(pPageObjs->GetLastObjectPosition(),pPathObj);
-}
-
-static CPDF_TextObject* AddTextObjToPageObjects(CPDF_PageObjects* pPageObjs, FX_COLORREF crText,
- CPDF_Font* pFont, FX_FLOAT fFontSize, FX_FLOAT fCharSpace, FX_INT32 nHorzScale,
- const CPDF_Point& point, const CFX_ByteString& text)
-{
- CPDF_TextObject* pTxtObj = new CPDF_TextObject;
-
- CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify();
- pTextStateData->m_pFont = pFont;
- pTextStateData->m_FontSize = fFontSize;
- pTextStateData->m_CharSpace = fCharSpace;
- pTextStateData->m_WordSpace = 0;
- pTextStateData->m_TextMode = 0;
- pTextStateData->m_Matrix[0] = nHorzScale / 100.0f;
- pTextStateData->m_Matrix[1] = 0;
- pTextStateData->m_Matrix[2] = 0;
- pTextStateData->m_Matrix[3] = 1;
-
- FX_FLOAT rgb[3];
- rgb[0] = FXARGB_R(crText) / 255.0f ;
- rgb[1] = FXARGB_G(crText) / 255.0f;
- rgb[2] = FXARGB_B(crText) / 255.0f;
- pTxtObj->m_ColorState.SetFillColor(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB),rgb, 3);
- pTxtObj->m_ColorState.SetStrokeColor(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB),rgb, 3);
-
- pTxtObj->SetPosition(point.x,point.y);
- pTxtObj->SetText(text);
-
- pPageObjs->InsertObject(pPageObjs->GetLastObjectPosition(),pTxtObj);
-
- return pTxtObj;
-}
-
-/*
-List of currently supported standard fonts:
-Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique
-Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique
-Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
-Symbol, ZapfDingbats
-*/
-
-const char* g_sFXEDITStandardFontName[] = {"Courier", "Courier-Bold", "Courier-BoldOblique", "Courier-Oblique",
- "Helvetica", "Helvetica-Bold", "Helvetica-BoldOblique", "Helvetica-Oblique",
- "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",
- "Symbol", "ZapfDingbats"};
-
-static FX_BOOL FX_EDIT_IsStandardFont(const CFX_ByteString& sFontName)
-{
- for (FX_INT32 i=0; i<14; i++)
- {
- if (sFontName == g_sFXEDITStandardFontName[i])
- return TRUE;
- }
-
- return FALSE;
-}
-
-void IFX_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects, IFX_Edit* pEdit,
- const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, FX_COLORREF crText, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray)
-{
- FX_FLOAT fFontSize = pEdit->GetFontSize();
-
- FX_INT32 nOldFontIndex = -1;
-
- CFX_ByteTextBuf sTextBuf;
- CPDF_Point ptBT(0.0f,0.0f);
-
- ObjArray.RemoveAll();
-
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap())
- {
- if (pRange)
- pIterator->SetAt(pRange->BeginPos);
- else
- pIterator->SetAt(0);
-
- CPVT_WordPlace oldplace;
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- if (place.LineCmp(oldplace) != 0 || nOldFontIndex != word.nFontIndex)
- {
- if (sTextBuf.GetLength() > 0)
- {
- ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, 0.0f, 100,
- CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString()));
-
- sTextBuf.Clear();
- }
-
- ptBT = word.ptWord;
- nOldFontIndex = word.nFontIndex;
- }
-
- sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, 0);
- oldplace = place;
- }
- }
-
- if (sTextBuf.GetLength() > 0)
- {
- ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, 0.0f, 100,
- CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString()));
- }
- }
- }
-}
-
-void IFX_Edit::GenerateRichPageObjects(CPDF_PageObjects* pPageObjects, IFX_Edit* pEdit,
- const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray)
-{
-
-
- FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0);
- FX_COLORREF crOld = crCurText;
-
-
- CFX_ByteTextBuf sTextBuf;
- CPVT_WordProps wp;
- CPDF_Point ptBT(0.0f,0.0f);
-
- ObjArray.RemoveAll();
-
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap())
- {
- if (pRange)
- pIterator->SetAt(pRange->BeginPos);
- else
- pIterator->SetAt(0);
-
- CPVT_WordPlace oldplace;
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- word.WordProps.fFontSize = word.fFontSize;
-
- crCurText = ArgbEncode(255,word.WordProps.dwWordColor);
-
- if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || word.WordProps.nHorzScale != 100 ||
- FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 ||
- crOld != crCurText)
- {
- if (sTextBuf.GetLength() > 0)
- {
- ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, wp.fCharSpace, wp.nHorzScale,
- CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString()));
-
- sTextBuf.Clear();
- }
-
- wp = word.WordProps;
- ptBT = word.ptWord;
- crOld = crCurText;
-
- }
-
- sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, word.Word, 0);
-
- if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE)
- {/*
- AddLineToPageObjects(pPageObjects, crCurText,
- CPDF_Point(word.ptWord.x, word.ptWord.y + word.fDescent * 0.4f),
- CPDF_Point(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent * 0.4f));
-*/
- CPDF_Rect rcUnderline = GetUnderLineRect(word);
- rcUnderline.left += ptOffset.x;
- rcUnderline.right += ptOffset.x;
- rcUnderline.top += ptOffset.y;
- rcUnderline.bottom += ptOffset.y;
-
- AddRectToPageObjects(pPageObjects, crCurText, rcUnderline);
- }
-
- if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT)
- {
- CPDF_Rect rcCrossout = GetCrossoutRect(word);
- rcCrossout.left += ptOffset.x;
- rcCrossout.right += ptOffset.x;
- rcCrossout.top += ptOffset.y;
- rcCrossout.bottom += ptOffset.y;
-
- AddRectToPageObjects(pPageObjects, crCurText, rcCrossout);
- }
-
- oldplace = place;
- }
- }
-
- if (sTextBuf.GetLength() > 0)
- {
- ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, wp.fCharSpace, wp.nHorzScale,
- CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString()));
- }
- }
- }
-}
-
-void IFX_Edit::GenerateUnderlineObjects(CPDF_PageObjects* pPageObjects, IFX_Edit* pEdit,
- const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, FX_COLORREF color)
-{
-
-
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- if (pEdit->GetFontMap())
- {
- if (pRange)
- pIterator->SetAt(pRange->BeginPos);
- else
- pIterator->SetAt(0);
-
- CPVT_WordPlace oldplace;
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- CPDF_Rect rcUnderline = GetUnderLineRect(word);
- rcUnderline.left += ptOffset.x;
- rcUnderline.right += ptOffset.x;
- rcUnderline.top += ptOffset.y;
- rcUnderline.bottom += ptOffset.y;
- AddRectToPageObjects(pPageObjects, color, rcUnderline);
- }
- }
- }
- }
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fxedit/fxet_stub.h"
+#include "../../include/fxedit/fx_edit.h"
+#include "../../include/fxedit/fxet_edit.h"
+
+#define FX_EDIT_UNDERLINEHALFWIDTH 0.5f
+#define FX_EDIT_CROSSOUTHALFWIDTH 0.5f
+
+extern CFX_ByteString GetPDFWordString(IFX_Edit_FontMap * pFontMap, FX_INT32 nFontIndex, FX_WORD Word, FX_WORD SubWord);
+
+CPDF_Rect GetUnderLineRect(const CPVT_Word& word)
+{
+ return CPDF_Rect(word.ptWord.x, word.ptWord.y + word.fDescent * 0.5f,
+ word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent * 0.25f);
+}
+
+CPDF_Rect GetCrossoutRect(const CPVT_Word& word)
+{
+ return CPDF_Rect(word.ptWord.x, word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f + word.fDescent * 0.25f,
+ word.ptWord.x + word.fWidth, word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f);
+}
+
+static void DrawTextString(CFX_RenderDevice* pDevice, const CPDF_Point& pt, CPDF_Font* pFont, FX_FLOAT fFontSize, CPDF_Matrix* pUser2Device,
+ const CFX_ByteString& str, FX_ARGB crTextFill, FX_ARGB crTextStroke, FX_INT32 nHorzScale)
+{
+ FX_FLOAT x = pt.x, y = pt.y;
+ pUser2Device->Transform(x, y);
+
+ if (pFont)
+ {
+ if (nHorzScale != 100)
+ {
+ CPDF_Matrix mt(nHorzScale/100.0f,0,0,1,0,0);
+ mt.Concat(*pUser2Device);
+
+ CPDF_RenderOptions ro;
+ ro.m_Flags = RENDER_CLEARTYPE;
+ ro.m_ColorMode = RENDER_COLOR_NORMAL;
+
+ if (crTextStroke != 0)
+ {
+ CPDF_Point pt1(0,0), pt2(1,0);
+ pUser2Device->Transform(pt1.x, pt1.y);
+ pUser2Device->Transform(pt2.x, pt2.y);
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y));
+
+ CPDF_TextRenderer::DrawTextString(pDevice,x, y, pFont, fFontSize, &mt, str, crTextFill, crTextStroke, &gsd, &ro);
+ }
+ else
+ CPDF_TextRenderer::DrawTextString(pDevice,x, y, pFont, fFontSize, &mt, str, crTextFill, 0, NULL, &ro);
+ }
+ else
+ {
+ CPDF_RenderOptions ro;
+ ro.m_Flags = RENDER_CLEARTYPE;
+ ro.m_ColorMode = RENDER_COLOR_NORMAL;
+
+ if (crTextStroke != 0)
+ {
+ CPDF_Point pt1(0,0), pt2(1,0);
+ pUser2Device->Transform(pt1.x, pt1.y);
+ pUser2Device->Transform(pt2.x, pt2.y);
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y));
+
+ CPDF_TextRenderer::DrawTextString(pDevice,x, y, pFont, fFontSize, pUser2Device, str, crTextFill, crTextStroke, &gsd, &ro);
+ }
+ else
+ CPDF_TextRenderer::DrawTextString(pDevice,x, y, pFont, fFontSize, pUser2Device, str, crTextFill, 0, NULL, &ro);
+ }
+ }
+}
+
+void IFX_Edit::DrawUnderline(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit, FX_COLORREF color,
+ const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange)
+{
+ pDevice->SaveState();
+
+ if (!rcClip.IsEmpty())
+ {
+ CPDF_Rect rcTemp = rcClip;
+ pUser2Device->TransformRect(rcTemp);
+ FX_RECT rcDevClip;
+ rcDevClip.left = (FX_INT32)rcTemp.left;
+ rcDevClip.right = (FX_INT32)rcTemp.right;
+ rcDevClip.top = (FX_INT32)rcTemp.top;
+ rcDevClip.bottom = (FX_INT32)rcTemp.bottom;
+ pDevice->SetClip_Rect(&rcDevClip);
+ }
+
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ if (pEdit->GetFontMap())
+ {
+ if (pRange)
+ pIterator->SetAt(pRange->BeginPos);
+ else
+ pIterator->SetAt(0);
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ CFX_PathData pathUnderline;
+ CPDF_Rect rcUnderline = GetUnderLineRect(word);
+ rcUnderline.left += ptOffset.x;
+ rcUnderline.right += ptOffset.x;
+ rcUnderline.top += ptOffset.y;
+ rcUnderline.bottom += ptOffset.y;
+ pathUnderline.AppendRect(rcUnderline.left, rcUnderline.bottom, rcUnderline.right, rcUnderline.top);
+
+ pDevice->DrawPath(&pathUnderline, pUser2Device, NULL, color, 0, FXFILL_WINDING);
+ }
+ }
+ }
+ }
+
+ pDevice->RestoreState();
+}
+
+void IFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit, FX_COLORREF crTextFill, FX_COLORREF crTextStroke,
+ const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, IFX_SystemHandler* pSystemHandler, void* pFFLData)
+{
+
+ FX_BOOL bContinuous = pEdit->GetCharArray() == 0;
+ if (pEdit->GetCharSpace() > 0.0f)
+ bContinuous = FALSE;
+
+ FX_WORD SubWord = pEdit->GetPasswordChar();
+ FX_FLOAT fFontSize = pEdit->GetFontSize();
+ CPVT_WordRange wrSelect = pEdit->GetSelectWordRange();
+ FX_INT32 nHorzScale = pEdit->GetHorzScale();
+
+ FX_COLORREF crCurFill = crTextFill;
+ FX_COLORREF crOldFill = crCurFill;
+
+ FX_BOOL bSelect = FALSE;
+ const FX_COLORREF crWhite = ArgbEncode(255,255,255,255);
+ const FX_COLORREF crSelBK = ArgbEncode(255,0,51,113);
+
+ CFX_ByteTextBuf sTextBuf;
+ FX_INT32 nFontIndex = -1;
+ CPDF_Point ptBT(0.0f,0.0f);
+
+ pDevice->SaveState();
+
+ if (!rcClip.IsEmpty())
+ {
+ CPDF_Rect rcTemp = rcClip;
+ pUser2Device->TransformRect(rcTemp);
+ FX_RECT rcDevClip;
+ rcDevClip.left = (FX_INT32)rcTemp.left;
+ rcDevClip.right = (FX_INT32)rcTemp.right;
+ rcDevClip.top = (FX_INT32)rcTemp.top;
+ rcDevClip.bottom = (FX_INT32)rcTemp.bottom;
+ pDevice->SetClip_Rect(&rcDevClip);
+ }
+
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap())
+ {
+ if (pRange)
+ pIterator->SetAt(pRange->BeginPos);
+ else
+ pIterator->SetAt(0);
+
+ CPVT_WordPlace oldplace;
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ if (wrSelect.IsExist())
+ {
+ bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && place.WordCmp(wrSelect.EndPos) <= 0;
+ if (bSelect)
+ {
+ crCurFill = crWhite;
+ }
+ else
+ {
+ crCurFill = crTextFill;
+ }
+ }
+ if(pSystemHandler && pSystemHandler->IsSelectionImplemented())
+ {
+ crCurFill = crTextFill;
+ crOldFill = crCurFill;
+ }
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+
+ if (bSelect)
+ {
+
+ CPVT_Line line;
+ pIterator->GetLine(line);
+
+ if(pSystemHandler && pSystemHandler->IsSelectionImplemented())
+ {
+ CPDF_Rect rc(word.ptWord.x,line.ptLine.y + line.fLineDescent,
+ word.ptWord.x+word.fWidth,line.ptLine.y + line.fLineAscent);
+ rc.Intersect(rcClip);
+ //CFX_Edit* pEt = (CFX_Edit*)pEdit;
+ //CPDF_Rect rcEdit = pEt->VTToEdit(rc);
+ pSystemHandler->OutputSelectedRect(pFFLData,rc);
+ }
+ else
+ {
+ CFX_PathData pathSelBK;
+ pathSelBK.AppendRect(word.ptWord.x,line.ptLine.y + line.fLineDescent,
+ word.ptWord.x+word.fWidth,line.ptLine.y + line.fLineAscent);
+
+ pDevice->DrawPath(&pathSelBK, pUser2Device, NULL, crSelBK, 0, FXFILL_WINDING);
+ }
+ }
+
+ if (bContinuous)
+ {
+ if (place.LineCmp(oldplace) != 0 || word.nFontIndex != nFontIndex ||
+ crOldFill != crCurFill)
+ {
+ if (sTextBuf.GetLength() > 0)
+ {
+ DrawTextString(pDevice, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), pFontMap->GetPDFFont(nFontIndex),
+ fFontSize, pUser2Device, sTextBuf.GetByteString(), crOldFill, crTextStroke, nHorzScale);
+
+ sTextBuf.Clear();
+ }
+ nFontIndex = word.nFontIndex;
+ ptBT = word.ptWord;
+ crOldFill = crCurFill;
+ }
+
+ sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, SubWord);
+ }
+ else
+ {
+ DrawTextString(pDevice,CPDF_Point(word.ptWord.x+ptOffset.x, word.ptWord.y+ptOffset.y), pFontMap->GetPDFFont(word.nFontIndex),
+ fFontSize, pUser2Device, GetPDFWordString(pFontMap, word.nFontIndex, word.Word, SubWord), crCurFill, crTextStroke, nHorzScale);
+
+ }
+ oldplace = place;
+
+
+ }
+ }
+
+ if (sTextBuf.GetLength() > 0)
+ {
+ DrawTextString(pDevice, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), pFontMap->GetPDFFont(nFontIndex),
+ fFontSize, pUser2Device, sTextBuf.GetByteString(), crOldFill, crTextStroke, nHorzScale);
+ }
+ }
+ }
+
+ pDevice->RestoreState();
+}
+
+void IFX_Edit::DrawRichEdit(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit,
+ const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange)
+{
+ //FX_FLOAT fFontSize = pEdit->GetFontSize();
+ CPVT_WordRange wrSelect = pEdit->GetSelectWordRange();
+
+ FX_COLORREF crCurText = ArgbEncode(255, 0,0,0);
+ FX_COLORREF crOld = crCurText;
+ FX_BOOL bSelect = FALSE;
+ const FX_COLORREF crWhite = ArgbEncode(255,255,255,255);
+ const FX_COLORREF crSelBK = ArgbEncode(255,0,51,113);
+
+ CFX_ByteTextBuf sTextBuf;
+ CPVT_WordProps wp;
+ CPDF_Point ptBT(0.0f,0.0f);
+
+ pDevice->SaveState();
+
+ if (!rcClip.IsEmpty())
+ {
+ CPDF_Rect rcTemp = rcClip;
+ pUser2Device->TransformRect(rcTemp);
+ FX_RECT rcDevClip;
+ rcDevClip.left = (FX_INT32)rcTemp.left;
+ rcDevClip.right = (FX_INT32)rcTemp.right;
+ rcDevClip.top = (FX_INT32)rcTemp.top;
+ rcDevClip.bottom = (FX_INT32)rcTemp.bottom;
+ pDevice->SetClip_Rect(&rcDevClip);
+ }
+
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap())
+ {
+ if (pRange)
+ pIterator->SetAt(pRange->BeginPos);
+ else
+ pIterator->SetAt(0);
+
+ CPVT_WordPlace oldplace;
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ word.WordProps.fFontSize = word.fFontSize;
+
+ crCurText = ArgbEncode(255,word.WordProps.dwWordColor);
+
+ if (wrSelect.IsExist())
+ {
+ bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && place.WordCmp(wrSelect.EndPos) <= 0;
+ if (bSelect)
+ {
+ crCurText = crWhite;
+ }
+ }
+
+ if (bSelect)
+ {
+ CPVT_Line line;
+ pIterator->GetLine(line);
+
+ CFX_PathData pathSelBK;
+ pathSelBK.AppendRect(word.ptWord.x + ptOffset.x,
+ line.ptLine.y + line.fLineDescent + ptOffset.y,
+ word.ptWord.x+word.fWidth + ptOffset.x,
+ line.ptLine.y + line.fLineAscent + ptOffset.y);
+
+ pDevice->DrawPath(&pathSelBK, pUser2Device, NULL, crSelBK, 0, FXFILL_WINDING);
+ }
+
+ if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || word.WordProps.nHorzScale != 100 ||
+ FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 ||
+ crOld != crCurText)
+ {
+ if (sTextBuf.GetLength() > 0)
+ {
+ DrawTextString(pDevice, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), pFontMap->GetPDFFont(wp.nFontIndex),
+ wp.fFontSize, pUser2Device, sTextBuf.GetByteString(), crOld, 0, wp.nHorzScale);
+
+ sTextBuf.Clear();
+ }
+ wp = word.WordProps;
+ ptBT = word.ptWord;
+ crOld = crCurText;
+ }
+
+ sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, word.Word, 0);
+
+ if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE)
+ {
+ CFX_PathData pathUnderline;
+ CPDF_Rect rcUnderline = GetUnderLineRect(word);
+ pathUnderline.AppendRect(rcUnderline.left, rcUnderline.bottom, rcUnderline.right, rcUnderline.top);
+
+ pDevice->DrawPath(&pathUnderline, pUser2Device, NULL, crCurText, 0, FXFILL_WINDING);
+ }
+
+ if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT)
+ {
+ CFX_PathData pathCrossout;
+ CPDF_Rect rcCrossout = GetCrossoutRect(word);
+ pathCrossout.AppendRect(rcCrossout.left, rcCrossout.bottom, rcCrossout.right, rcCrossout.top);
+
+ pDevice->DrawPath(&pathCrossout, pUser2Device, NULL, crCurText, 0, FXFILL_WINDING);
+ }
+
+ oldplace = place;
+ }
+ }
+
+ if (sTextBuf.GetLength() > 0)
+ {
+ DrawTextString(pDevice, CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), pFontMap->GetPDFFont(wp.nFontIndex),
+ wp.fFontSize, pUser2Device, sTextBuf.GetByteString(), crOld, 0, wp.nHorzScale);
+ }
+ }
+ }
+
+ pDevice->RestoreState();
+}
+
+static void AddLineToPageObjects(CPDF_PageObjects* pPageObjs, FX_COLORREF crStroke,
+ const CPDF_Point& pt1, const CPDF_Point& pt2)
+{
+ CPDF_PathObject* pPathObj = new CPDF_PathObject;
+ CPDF_PathData* pPathData = pPathObj->m_Path.GetModify();
+
+ pPathData->SetPointCount(2);
+ pPathData->SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
+ pPathData->SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
+
+ FX_FLOAT rgb[3];
+ rgb[0] = FXARGB_R(crStroke) / 255.0f;
+ rgb[1] = FXARGB_G(crStroke) / 255.0f;
+ rgb[2] = FXARGB_B(crStroke) / 255.0f;
+ pPathObj->m_ColorState.SetStrokeColor(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3);
+
+ CFX_GraphStateData* pData = pPathObj->m_GraphState.GetModify();
+ pData->m_LineWidth = 1;
+
+ pPageObjs->InsertObject(pPageObjs->GetLastObjectPosition(),pPathObj);
+}
+
+static void AddRectToPageObjects(CPDF_PageObjects* pPageObjs, FX_COLORREF crFill, const CPDF_Rect& rcFill)
+{
+ CPDF_PathObject* pPathObj = new CPDF_PathObject;
+ CPDF_PathData* pPathData = pPathObj->m_Path.GetModify();
+ pPathData->AppendRect(rcFill.left,rcFill.bottom,rcFill.right,rcFill.top);
+
+ FX_FLOAT rgb[3];
+ rgb[0] = FXARGB_R(crFill) / 255.0f ;
+ rgb[1] = FXARGB_G(crFill) / 255.0f;
+ rgb[2] = FXARGB_B(crFill) / 255.0f;
+ pPathObj->m_ColorState.SetFillColor(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3);
+
+ pPathObj->m_FillType = FXFILL_ALTERNATE;
+ pPathObj->m_bStroke = FALSE;
+
+ pPageObjs->InsertObject(pPageObjs->GetLastObjectPosition(),pPathObj);
+}
+
+static CPDF_TextObject* AddTextObjToPageObjects(CPDF_PageObjects* pPageObjs, FX_COLORREF crText,
+ CPDF_Font* pFont, FX_FLOAT fFontSize, FX_FLOAT fCharSpace, FX_INT32 nHorzScale,
+ const CPDF_Point& point, const CFX_ByteString& text)
+{
+ CPDF_TextObject* pTxtObj = new CPDF_TextObject;
+
+ CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify();
+ pTextStateData->m_pFont = pFont;
+ pTextStateData->m_FontSize = fFontSize;
+ pTextStateData->m_CharSpace = fCharSpace;
+ pTextStateData->m_WordSpace = 0;
+ pTextStateData->m_TextMode = 0;
+ pTextStateData->m_Matrix[0] = nHorzScale / 100.0f;
+ pTextStateData->m_Matrix[1] = 0;
+ pTextStateData->m_Matrix[2] = 0;
+ pTextStateData->m_Matrix[3] = 1;
+
+ FX_FLOAT rgb[3];
+ rgb[0] = FXARGB_R(crText) / 255.0f ;
+ rgb[1] = FXARGB_G(crText) / 255.0f;
+ rgb[2] = FXARGB_B(crText) / 255.0f;
+ pTxtObj->m_ColorState.SetFillColor(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB),rgb, 3);
+ pTxtObj->m_ColorState.SetStrokeColor(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB),rgb, 3);
+
+ pTxtObj->SetPosition(point.x,point.y);
+ pTxtObj->SetText(text);
+
+ pPageObjs->InsertObject(pPageObjs->GetLastObjectPosition(),pTxtObj);
+
+ return pTxtObj;
+}
+
+/*
+List of currently supported standard fonts:
+Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique
+Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique
+Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
+Symbol, ZapfDingbats
+*/
+
+const char* g_sFXEDITStandardFontName[] = {"Courier", "Courier-Bold", "Courier-BoldOblique", "Courier-Oblique",
+ "Helvetica", "Helvetica-Bold", "Helvetica-BoldOblique", "Helvetica-Oblique",
+ "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",
+ "Symbol", "ZapfDingbats"};
+
+static FX_BOOL FX_EDIT_IsStandardFont(const CFX_ByteString& sFontName)
+{
+ for (FX_INT32 i=0; i<14; i++)
+ {
+ if (sFontName == g_sFXEDITStandardFontName[i])
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void IFX_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects, IFX_Edit* pEdit,
+ const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, FX_COLORREF crText, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray)
+{
+ FX_FLOAT fFontSize = pEdit->GetFontSize();
+
+ FX_INT32 nOldFontIndex = -1;
+
+ CFX_ByteTextBuf sTextBuf;
+ CPDF_Point ptBT(0.0f,0.0f);
+
+ ObjArray.RemoveAll();
+
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap())
+ {
+ if (pRange)
+ pIterator->SetAt(pRange->BeginPos);
+ else
+ pIterator->SetAt(0);
+
+ CPVT_WordPlace oldplace;
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ if (place.LineCmp(oldplace) != 0 || nOldFontIndex != word.nFontIndex)
+ {
+ if (sTextBuf.GetLength() > 0)
+ {
+ ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, 0.0f, 100,
+ CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString()));
+
+ sTextBuf.Clear();
+ }
+
+ ptBT = word.ptWord;
+ nOldFontIndex = word.nFontIndex;
+ }
+
+ sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, 0);
+ oldplace = place;
+ }
+ }
+
+ if (sTextBuf.GetLength() > 0)
+ {
+ ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, 0.0f, 100,
+ CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString()));
+ }
+ }
+ }
+}
+
+void IFX_Edit::GenerateRichPageObjects(CPDF_PageObjects* pPageObjects, IFX_Edit* pEdit,
+ const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray)
+{
+
+
+ FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0);
+ FX_COLORREF crOld = crCurText;
+
+
+ CFX_ByteTextBuf sTextBuf;
+ CPVT_WordProps wp;
+ CPDF_Point ptBT(0.0f,0.0f);
+
+ ObjArray.RemoveAll();
+
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ if (IFX_Edit_FontMap* pFontMap = pEdit->GetFontMap())
+ {
+ if (pRange)
+ pIterator->SetAt(pRange->BeginPos);
+ else
+ pIterator->SetAt(0);
+
+ CPVT_WordPlace oldplace;
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ word.WordProps.fFontSize = word.fFontSize;
+
+ crCurText = ArgbEncode(255,word.WordProps.dwWordColor);
+
+ if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || word.WordProps.nHorzScale != 100 ||
+ FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 ||
+ crOld != crCurText)
+ {
+ if (sTextBuf.GetLength() > 0)
+ {
+ ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, wp.fCharSpace, wp.nHorzScale,
+ CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString()));
+
+ sTextBuf.Clear();
+ }
+
+ wp = word.WordProps;
+ ptBT = word.ptWord;
+ crOld = crCurText;
+
+ }
+
+ sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, word.Word, 0);
+
+ if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE)
+ {/*
+ AddLineToPageObjects(pPageObjects, crCurText,
+ CPDF_Point(word.ptWord.x, word.ptWord.y + word.fDescent * 0.4f),
+ CPDF_Point(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent * 0.4f));
+*/
+ CPDF_Rect rcUnderline = GetUnderLineRect(word);
+ rcUnderline.left += ptOffset.x;
+ rcUnderline.right += ptOffset.x;
+ rcUnderline.top += ptOffset.y;
+ rcUnderline.bottom += ptOffset.y;
+
+ AddRectToPageObjects(pPageObjects, crCurText, rcUnderline);
+ }
+
+ if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT)
+ {
+ CPDF_Rect rcCrossout = GetCrossoutRect(word);
+ rcCrossout.left += ptOffset.x;
+ rcCrossout.right += ptOffset.x;
+ rcCrossout.top += ptOffset.y;
+ rcCrossout.bottom += ptOffset.y;
+
+ AddRectToPageObjects(pPageObjects, crCurText, rcCrossout);
+ }
+
+ oldplace = place;
+ }
+ }
+
+ if (sTextBuf.GetLength() > 0)
+ {
+ ObjArray.Add(AddTextObjToPageObjects(pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, wp.fCharSpace, wp.nHorzScale,
+ CPDF_Point(ptBT.x+ptOffset.x, ptBT.y+ptOffset.y), sTextBuf.GetByteString()));
+ }
+ }
+ }
+}
+
+void IFX_Edit::GenerateUnderlineObjects(CPDF_PageObjects* pPageObjects, IFX_Edit* pEdit,
+ const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, FX_COLORREF color)
+{
+
+
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ if (pEdit->GetFontMap())
+ {
+ if (pRange)
+ pIterator->SetAt(pRange->BeginPos);
+ else
+ pIterator->SetAt(0);
+
+ CPVT_WordPlace oldplace;
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ CPDF_Rect rcUnderline = GetUnderLineRect(word);
+ rcUnderline.left += ptOffset.x;
+ rcUnderline.right += ptOffset.x;
+ rcUnderline.top += ptOffset.y;
+ rcUnderline.bottom += ptOffset.y;
+ AddRectToPageObjects(pPageObjects, color, rcUnderline);
+ }
+ }
+ }
+ }
+}
+
diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp
index 09b8f8e1a0..278cd7eab8 100644
--- a/fpdfsdk/src/javascript/Consts.cpp
+++ b/fpdfsdk/src/javascript/Consts.cpp
@@ -1,247 +1,247 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Consts.h"
-
-/* ------------------------------ border ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Border)
- JS_STATIC_CONST_ENTRY_STRING(s, solid)
- JS_STATIC_CONST_ENTRY_STRING(b, beveled)
- JS_STATIC_CONST_ENTRY_STRING(d, dashed)
- JS_STATIC_CONST_ENTRY_STRING(i, inset)
- JS_STATIC_CONST_ENTRY_STRING(u, underline)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Border,border)
-
-/* ------------------------------ display ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Display)
- JS_STATIC_CONST_ENTRY_NUMBER(visible, 0)
- JS_STATIC_CONST_ENTRY_NUMBER(hidden, 1)
- JS_STATIC_CONST_ENTRY_NUMBER(noPrint, 2)
- JS_STATIC_CONST_ENTRY_NUMBER(noView, 3)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Display,display)
-
-/* ------------------------------ font ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Font)
- JS_STATIC_CONST_ENTRY_STRING(Times, Times-Roman)
- JS_STATIC_CONST_ENTRY_STRING(TimesB, Times-Bold)
- JS_STATIC_CONST_ENTRY_STRING(TimesI, Times-Italic)
- JS_STATIC_CONST_ENTRY_STRING(TimesBI, Times-BoldItalic)
- JS_STATIC_CONST_ENTRY_STRING(Helv, Helvetica)
- JS_STATIC_CONST_ENTRY_STRING(HelvB, Helvetica-Bold)
- JS_STATIC_CONST_ENTRY_STRING(HelvI, Helvetica-Oblique)
- JS_STATIC_CONST_ENTRY_STRING(HelvBI, Helvetica-BoldOblique)
- JS_STATIC_CONST_ENTRY_STRING(Cour, Courier)
- JS_STATIC_CONST_ENTRY_STRING(CourB, Courier-Bold)
- JS_STATIC_CONST_ENTRY_STRING(CourI, Courier-Oblique)
- JS_STATIC_CONST_ENTRY_STRING(CourBI, Courier-BoldOblique)
- JS_STATIC_CONST_ENTRY_STRING(Symbol, Symbol)
- JS_STATIC_CONST_ENTRY_STRING(ZapfD, ZapfDingbats)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Font,font)
-
-/* ------------------------------ highlight ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Highlight)
- JS_STATIC_CONST_ENTRY_STRING(n, none)
- JS_STATIC_CONST_ENTRY_STRING(i, invert)
- JS_STATIC_CONST_ENTRY_STRING(p, push)
- JS_STATIC_CONST_ENTRY_STRING(o, outline)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Highlight,highlight)
-
-/* ------------------------------ position ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Position)
- JS_STATIC_CONST_ENTRY_NUMBER(textOnly, 0)
- JS_STATIC_CONST_ENTRY_NUMBER(iconOnly, 1)
- JS_STATIC_CONST_ENTRY_NUMBER(iconTextV, 2)
- JS_STATIC_CONST_ENTRY_NUMBER(textIconV, 3)
- JS_STATIC_CONST_ENTRY_NUMBER(iconTextH, 4)
- JS_STATIC_CONST_ENTRY_NUMBER(textIconH, 5)
- JS_STATIC_CONST_ENTRY_NUMBER(overlay, 6)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Position,position)
-
-/* ------------------------------ scaleHow ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_ScaleHow)
- JS_STATIC_CONST_ENTRY_NUMBER(proportional, 0)
- JS_STATIC_CONST_ENTRY_NUMBER(anamorphic, 1)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_ScaleHow,scaleHow)
-
-/* ------------------------------ scaleWhen ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_ScaleWhen)
- JS_STATIC_CONST_ENTRY_NUMBER(always, 0)
- JS_STATIC_CONST_ENTRY_NUMBER(never, 1)
- JS_STATIC_CONST_ENTRY_NUMBER(tooBig, 2)
- JS_STATIC_CONST_ENTRY_NUMBER(tooSmall, 3)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_ScaleWhen,scaleWhen)
-
-/* ------------------------------ style ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Style)
- JS_STATIC_CONST_ENTRY_STRING(ch, check)
- JS_STATIC_CONST_ENTRY_STRING(cr, cross)
- JS_STATIC_CONST_ENTRY_STRING(di, diamond)
- JS_STATIC_CONST_ENTRY_STRING(ci, circle)
- JS_STATIC_CONST_ENTRY_STRING(st, star)
- JS_STATIC_CONST_ENTRY_STRING(sq, square)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Style,style)
-
-
-/* ------------------------------ zoomtype ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Zoomtype)
- JS_STATIC_CONST_ENTRY_STRING(none, NoVary)
- JS_STATIC_CONST_ENTRY_STRING(fitP, FitPage)
- JS_STATIC_CONST_ENTRY_STRING(fitW, FitWidth)
- JS_STATIC_CONST_ENTRY_STRING(fitH, FitHeight)
- JS_STATIC_CONST_ENTRY_STRING(fitV, FitVisibleWidth)
- JS_STATIC_CONST_ENTRY_STRING(pref, Preferred)
- JS_STATIC_CONST_ENTRY_STRING(refW, ReflowWidth)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype,zoomtype)
-
-/* ------------------------------ CJS_GlobalConsts ------------------------------ */
-
-int CJS_GlobalConsts::Init(IJS_Runtime* pRuntime)
-{
- DEFINE_GLOBAL_CONST(pRuntime, IDS_GREATER_THAN , Invalid value: must be greater than or equal to %s.);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_GT_AND_LT,Invalid value: must be greater than or equal to %s and less than or equal to %s.);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_LESS_THAN,Invalid value: must be less than or equal to %s.);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_MONTH,** Invalid **);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_DATE,Invalid date/time: please ensure that the date/time exists. Field);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_VALUE,The value entered does not match the format of the field);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_AM,am);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_PM,pm);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_MONTH_INFO,January[1]February[2]March[3]April[4]May[5]June[6]July[7]August[8]September[9]October[10]November[11]December[12]Sept[9]Jan[1]Feb[2]Mar[3]Apr[4]Jun[6]Jul[7]Aug[8]Sep[9]Oct[10]Nov[11]Dec[12]);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_STARTUP_CONSOLE_MSG, ** ^_^ **);
-
- return 0;
-}
-
-/* ------------------------------ CJS_GlobalArrays ------------------------------ */
-
-int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime)
-{
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_ENTRY_DOT_SEP";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d*\\.?\\d*"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_COMMIT_DOT_SEP";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */
- (FX_LPCWSTR)L"[+-]?\\.\\d+", /* -.1 */
- (FX_LPCWSTR)L"[+-]?\\d+\\." /* -1. */
- };
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_ENTRY_COMMA_SEP";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d*,?\\d*"};
-
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_COMMIT_COMMA_SEP";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */
- (FX_LPCWSTR)L"[+-]?[.,]\\d+", /* -,1 */
- (FX_LPCWSTR)L"[+-]?\\d+[.,]" /* -1, */
- };
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP_ENTRY";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,5}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP_COMMIT";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{5}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP4_ENTRY";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,5}(\\.|[- ])?\\d{0,4}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP4_COMMIT";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{5}(\\.|[- ])?\\d{4}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_PHONE_ENTRY";
- FX_LPCWSTR ArrayContent[] = {
- (FX_LPCWSTR)L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 555-1234 */
- (FX_LPCWSTR)L"\\(\\d{0,3}", /* (408 */
- (FX_LPCWSTR)L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) 555-1234 */
- /* (allow the addition of parens as an afterthought) */
- (FX_LPCWSTR)L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 */
- (FX_LPCWSTR)L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 */
- (FX_LPCWSTR)L"011(\\.|[- \\d])*" /* international */
- };
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_PHONE_COMMIT";
- FX_LPCWSTR ArrayContent[] = {
- (FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */
- (FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */
- (FX_LPCWSTR)L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */
- (FX_LPCWSTR)L"011(\\.|[- \\d])*" /* international */
- };
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_SSN_ENTRY";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_SSN_COMMIT";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- return 0;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Consts.h"
+
+/* ------------------------------ border ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Border)
+ JS_STATIC_CONST_ENTRY_STRING(s, solid)
+ JS_STATIC_CONST_ENTRY_STRING(b, beveled)
+ JS_STATIC_CONST_ENTRY_STRING(d, dashed)
+ JS_STATIC_CONST_ENTRY_STRING(i, inset)
+ JS_STATIC_CONST_ENTRY_STRING(u, underline)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Border,border)
+
+/* ------------------------------ display ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Display)
+ JS_STATIC_CONST_ENTRY_NUMBER(visible, 0)
+ JS_STATIC_CONST_ENTRY_NUMBER(hidden, 1)
+ JS_STATIC_CONST_ENTRY_NUMBER(noPrint, 2)
+ JS_STATIC_CONST_ENTRY_NUMBER(noView, 3)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Display,display)
+
+/* ------------------------------ font ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Font)
+ JS_STATIC_CONST_ENTRY_STRING(Times, Times-Roman)
+ JS_STATIC_CONST_ENTRY_STRING(TimesB, Times-Bold)
+ JS_STATIC_CONST_ENTRY_STRING(TimesI, Times-Italic)
+ JS_STATIC_CONST_ENTRY_STRING(TimesBI, Times-BoldItalic)
+ JS_STATIC_CONST_ENTRY_STRING(Helv, Helvetica)
+ JS_STATIC_CONST_ENTRY_STRING(HelvB, Helvetica-Bold)
+ JS_STATIC_CONST_ENTRY_STRING(HelvI, Helvetica-Oblique)
+ JS_STATIC_CONST_ENTRY_STRING(HelvBI, Helvetica-BoldOblique)
+ JS_STATIC_CONST_ENTRY_STRING(Cour, Courier)
+ JS_STATIC_CONST_ENTRY_STRING(CourB, Courier-Bold)
+ JS_STATIC_CONST_ENTRY_STRING(CourI, Courier-Oblique)
+ JS_STATIC_CONST_ENTRY_STRING(CourBI, Courier-BoldOblique)
+ JS_STATIC_CONST_ENTRY_STRING(Symbol, Symbol)
+ JS_STATIC_CONST_ENTRY_STRING(ZapfD, ZapfDingbats)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Font,font)
+
+/* ------------------------------ highlight ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Highlight)
+ JS_STATIC_CONST_ENTRY_STRING(n, none)
+ JS_STATIC_CONST_ENTRY_STRING(i, invert)
+ JS_STATIC_CONST_ENTRY_STRING(p, push)
+ JS_STATIC_CONST_ENTRY_STRING(o, outline)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Highlight,highlight)
+
+/* ------------------------------ position ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Position)
+ JS_STATIC_CONST_ENTRY_NUMBER(textOnly, 0)
+ JS_STATIC_CONST_ENTRY_NUMBER(iconOnly, 1)
+ JS_STATIC_CONST_ENTRY_NUMBER(iconTextV, 2)
+ JS_STATIC_CONST_ENTRY_NUMBER(textIconV, 3)
+ JS_STATIC_CONST_ENTRY_NUMBER(iconTextH, 4)
+ JS_STATIC_CONST_ENTRY_NUMBER(textIconH, 5)
+ JS_STATIC_CONST_ENTRY_NUMBER(overlay, 6)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Position,position)
+
+/* ------------------------------ scaleHow ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_ScaleHow)
+ JS_STATIC_CONST_ENTRY_NUMBER(proportional, 0)
+ JS_STATIC_CONST_ENTRY_NUMBER(anamorphic, 1)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_ScaleHow,scaleHow)
+
+/* ------------------------------ scaleWhen ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_ScaleWhen)
+ JS_STATIC_CONST_ENTRY_NUMBER(always, 0)
+ JS_STATIC_CONST_ENTRY_NUMBER(never, 1)
+ JS_STATIC_CONST_ENTRY_NUMBER(tooBig, 2)
+ JS_STATIC_CONST_ENTRY_NUMBER(tooSmall, 3)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_ScaleWhen,scaleWhen)
+
+/* ------------------------------ style ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Style)
+ JS_STATIC_CONST_ENTRY_STRING(ch, check)
+ JS_STATIC_CONST_ENTRY_STRING(cr, cross)
+ JS_STATIC_CONST_ENTRY_STRING(di, diamond)
+ JS_STATIC_CONST_ENTRY_STRING(ci, circle)
+ JS_STATIC_CONST_ENTRY_STRING(st, star)
+ JS_STATIC_CONST_ENTRY_STRING(sq, square)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Style,style)
+
+
+/* ------------------------------ zoomtype ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Zoomtype)
+ JS_STATIC_CONST_ENTRY_STRING(none, NoVary)
+ JS_STATIC_CONST_ENTRY_STRING(fitP, FitPage)
+ JS_STATIC_CONST_ENTRY_STRING(fitW, FitWidth)
+ JS_STATIC_CONST_ENTRY_STRING(fitH, FitHeight)
+ JS_STATIC_CONST_ENTRY_STRING(fitV, FitVisibleWidth)
+ JS_STATIC_CONST_ENTRY_STRING(pref, Preferred)
+ JS_STATIC_CONST_ENTRY_STRING(refW, ReflowWidth)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype,zoomtype)
+
+/* ------------------------------ CJS_GlobalConsts ------------------------------ */
+
+int CJS_GlobalConsts::Init(IJS_Runtime* pRuntime)
+{
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_GREATER_THAN , Invalid value: must be greater than or equal to %s.);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_GT_AND_LT,Invalid value: must be greater than or equal to %s and less than or equal to %s.);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_LESS_THAN,Invalid value: must be less than or equal to %s.);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_MONTH,** Invalid **);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_DATE,Invalid date/time: please ensure that the date/time exists. Field);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_VALUE,The value entered does not match the format of the field);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_AM,am);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_PM,pm);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_MONTH_INFO,January[1]February[2]March[3]April[4]May[5]June[6]July[7]August[8]September[9]October[10]November[11]December[12]Sept[9]Jan[1]Feb[2]Mar[3]Apr[4]Jun[6]Jul[7]Aug[8]Sep[9]Oct[10]Nov[11]Dec[12]);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_STARTUP_CONSOLE_MSG, ** ^_^ **);
+
+ return 0;
+}
+
+/* ------------------------------ CJS_GlobalArrays ------------------------------ */
+
+int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime)
+{
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_ENTRY_DOT_SEP";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d*\\.?\\d*"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_COMMIT_DOT_SEP";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */
+ (FX_LPCWSTR)L"[+-]?\\.\\d+", /* -.1 */
+ (FX_LPCWSTR)L"[+-]?\\d+\\." /* -1. */
+ };
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_ENTRY_COMMA_SEP";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d*,?\\d*"};
+
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_COMMIT_COMMA_SEP";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */
+ (FX_LPCWSTR)L"[+-]?[.,]\\d+", /* -,1 */
+ (FX_LPCWSTR)L"[+-]?\\d+[.,]" /* -1, */
+ };
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP_ENTRY";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,5}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP_COMMIT";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{5}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP4_ENTRY";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,5}(\\.|[- ])?\\d{0,4}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP4_COMMIT";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{5}(\\.|[- ])?\\d{4}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_PHONE_ENTRY";
+ FX_LPCWSTR ArrayContent[] = {
+ (FX_LPCWSTR)L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 555-1234 */
+ (FX_LPCWSTR)L"\\(\\d{0,3}", /* (408 */
+ (FX_LPCWSTR)L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) 555-1234 */
+ /* (allow the addition of parens as an afterthought) */
+ (FX_LPCWSTR)L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 */
+ (FX_LPCWSTR)L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 */
+ (FX_LPCWSTR)L"011(\\.|[- \\d])*" /* international */
+ };
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_PHONE_COMMIT";
+ FX_LPCWSTR ArrayContent[] = {
+ (FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */
+ (FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */
+ (FX_LPCWSTR)L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */
+ (FX_LPCWSTR)L"011(\\.|[- \\d])*" /* international */
+ };
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_SSN_ENTRY";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_SSN_COMMIT";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ return 0;
+}
+
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index ec930b810d..0a6acfaea7 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -1,2527 +1,2527 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/app.h"
-#include "../../include/javascript/Field.h"
-#include "../../include/javascript/Icon.h"
-#include "../../include/javascript/Field.h"
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)
-END_JS_STATIC_METHOD()
-
-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;
-}
-
-/* ---------------------- Document ---------------------- */
-
-#define MINWIDTH 5.0f
-#define MINHEIGHT 5.0f
-
-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)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Document)
- JS_STATIC_METHOD_ENTRY(addAnnot,0)
- JS_STATIC_METHOD_ENTRY(addField, 4)
- JS_STATIC_METHOD_ENTRY(addLink, 0)
- JS_STATIC_METHOD_ENTRY(addIcon, 0)
- JS_STATIC_METHOD_ENTRY(calculateNow, 0)
- JS_STATIC_METHOD_ENTRY(closeDoc, 0)
- JS_STATIC_METHOD_ENTRY(createDataObject, 0)
- JS_STATIC_METHOD_ENTRY(deletePages, 2)
- JS_STATIC_METHOD_ENTRY(exportAsText, 3)
- JS_STATIC_METHOD_ENTRY(exportAsFDF, 6)
- JS_STATIC_METHOD_ENTRY(exportAsXFDF, 5)
- JS_STATIC_METHOD_ENTRY(extractPages, 3)
- JS_STATIC_METHOD_ENTRY(getAnnot, 0)
- JS_STATIC_METHOD_ENTRY(getAnnots, 2)
- JS_STATIC_METHOD_ENTRY(getAnnot3D, 2)
- JS_STATIC_METHOD_ENTRY(getAnnots3D, 1)
- JS_STATIC_METHOD_ENTRY(getField, 1)
- JS_STATIC_METHOD_ENTRY(getIcon, 0)
- JS_STATIC_METHOD_ENTRY(getLinks, 0)
- JS_STATIC_METHOD_ENTRY(getNthFieldName, 1)
- JS_STATIC_METHOD_ENTRY(getOCGs, 0)
- JS_STATIC_METHOD_ENTRY(getPageBox, 0)
- JS_STATIC_METHOD_ENTRY(getPageNthWord, 3)
- JS_STATIC_METHOD_ENTRY(getPageNthWordQuads, 2)
- JS_STATIC_METHOD_ENTRY(getPageNumWords, 1)
- JS_STATIC_METHOD_ENTRY(getPrintParams, 0)
- JS_STATIC_METHOD_ENTRY(getURL, 2)
- JS_STATIC_METHOD_ENTRY(importAnFDF, 1)
- JS_STATIC_METHOD_ENTRY(importAnXFDF, 1)
- JS_STATIC_METHOD_ENTRY(importTextData, 2)
- JS_STATIC_METHOD_ENTRY(insertPages, 4)
- JS_STATIC_METHOD_ENTRY(mailForm, 6)
- JS_STATIC_METHOD_ENTRY(print, 9)
- JS_STATIC_METHOD_ENTRY(removeField, 1)
- JS_STATIC_METHOD_ENTRY(replacePages, 4)
- JS_STATIC_METHOD_ENTRY(resetForm, 1)
- JS_STATIC_METHOD_ENTRY(removeIcon, 0)
- JS_STATIC_METHOD_ENTRY(saveAs, 5)
- JS_STATIC_METHOD_ENTRY(submitForm, 23)
- JS_STATIC_METHOD_ENTRY(mailDoc, 0)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Document, Document)
-
-FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- Document* pDoc = (Document*)GetEmbedObject();
- ASSERT(pDoc != NULL);
-
- pDoc->AttachDoc(pContext->GetReaderDocument());
- pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
- return TRUE;
-};
-
-/* --------------------------------- Document --------------------------------- */
-
-Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
- m_cwBaseURL(L""),
- m_pIconTree(NULL),
- m_pDocument(NULL),
- m_bDelay(FALSE),
- m_isolate(NULL)
-{
-}
-
-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);
-
- }
- }
-
- m_DelayData.RemoveAll();
- m_DelayAnnotData.RemoveAll();
-}
-
-//the total number of fileds in document.
-FX_BOOL Document::numFields(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting()) return FALSE;
-
- ASSERT(m_pDocument != NULL);
-
- CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- vp << (int)pPDFForm->CountFields();
-
- return TRUE;
-}
-
-FX_BOOL Document::dirty(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsGetting())
- {
- if (m_pDocument->GetChangeMark())
- vp << true;
- else
- vp << false;
- }
- else
- {
- bool bChanged = false;
-
- vp >> bChanged;
-
- if (bChanged)
- m_pDocument->SetChangeMark();
- else
- m_pDocument->ClearChangeMark();
- }
-
- return TRUE;
-}
-
-FX_BOOL Document::ADBE(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsGetting())
- {
- vp.SetNull();
- }
- else
- {
- }
-
- return TRUE;
-}
-
-FX_BOOL Document::pageNum(OBJ_PROP_PARAMS)
-{
- 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(!pEnv)
- return FALSE;
-
- 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)
-{
- return TRUE;
-}
-
-FX_BOOL Document::addAnnot(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::addField(OBJ_METHOD_PARAMS)
-{
- //Doesn't support.
- return TRUE;
-}
-
-//exports form fields as a tab-delimited text file to a local hard disk.
-//comment: need reader support
-//note : watch the third parameter:cPath, for what case it can be safely saved?
-//int CPDFSDK_InterForm::ExportAsText(FX_BOOL bNoPassword,StringArray aFields,String cPath);
-//return value, int the index of the parameters illegal, the index is based on 1.
-
-FX_BOOL Document::exportAsText(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- return TRUE;
-}
-
-//exports form fields as a fdf file to the local hard drive
-//comment: need reader supports
-//note:the last parameter hasn't been confirmed.because the previous one blocks the way.
-//int CPDFSDK_Document::ExportAsFDF(FX_BOOL bAllFields,BOOL bNoPassword,StringArray aFields,FX_BOOL bFlags,String cPath,FX_BOOL bAnnotations);
-
-FX_BOOL Document::exportAsFDF(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- FX_BOOL bAllFields = params.size() > 0 ? (FX_BOOL)params[0] : FALSE;
- FX_BOOL bNoPassWord = params.size() > 1 ? (FX_BOOL)params[1] : TRUE;
- FX_BOOL bWhole = params.size() > 2 ? (params[2].GetType() == VT_null) : TRUE;
- CJS_Array arrayFileds(isolate);
- if (!bWhole)
- arrayFileds.Attach(params[2]);
- //FX_BOOL bFlags = params.size() > 3 ? (FX_BOOL)params[3] : FALSE;
- CFX_WideString swFilePath = params.size() > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";
-
- if (swFilePath.IsEmpty())
- {
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- swFilePath = pEnv->JS_fieldBrowse();
- if(swFilePath.IsEmpty())
- return TRUE;
- }
- else
- {
- swFilePath = app::PDFPathToSysPath(swFilePath);
- }
-
- m_pDocument->SetFocusAnnot(NULL);
-
- CPDFSDK_InterForm* pInterForm= (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- CFX_PtrArray aFields;
-
- if (bWhole)
- {
- for (int j=0,jsz=pPDFForm->CountFields(); j<jsz; j++)
- {
- aFields.Add(pPDFForm->GetField(j));
- }
- }
- else
- {
- for (int i=0,isz=arrayFileds.GetLength(); i<isz; i++)
- {
- CJS_Value valName(isolate);
- arrayFileds.GetElement(i,valName);
- CFX_WideString swName = valName.operator CFX_WideString();
-
- for (int j=0, jsz=pPDFForm->CountFields(swName); j<jsz; j++)
- {
- aFields.Add(pPDFForm->GetField(j, swName));
- }
- }
- }
-
- CFX_PtrArray fields;
-
- for (int i=0,sz=aFields.GetSize(); i<sz; i++)
- {
- CPDF_FormField* pField = (CPDF_FormField*)aFields[i];
-
- if (!bAllFields)
- if (pField->GetValue() == L"")
- continue;
-
- if (bNoPassWord)
- if (pField->GetFieldFlags() & 0x2000)
- continue;
-
- fields.Add((void*)pField);
- }
-
- return pInterForm->ExportFieldsToFDFFile(swFilePath, fields, TRUE);
-}
-
-//exports form fields an XFDF file to the local hard drive
-//comment: need reder supports
-//note:the last parameter can't be test
-//int CPDFSDK_Document::ExportAsXFDF(FX_BOOL bAllFields,FX_BOOL bNoPassWord,StringArray aFields,String cPath,FX_BOOL bAnnoatations);
-
-FX_BOOL Document::exportAsXFDF(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- return TRUE;
-}
-
-//Maps a field object in PDF document to a JavaScript variable
-//comment:
-//note: the paremter cName, this is clue how to treat if the cName is not a valiable filed name in this document
-
-FX_BOOL Document::getField(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- ASSERT(m_pDocument != NULL);
-
- if (params.size() < 1) return FALSE;
-
- CFX_WideString wideName = params[0].operator CFX_WideString();
-
- CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- if (pPDFForm->CountFields(wideName) <= 0)
- {
- vRet.SetNull();
- return TRUE;
- }
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
-
- CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj);
- ASSERT(pJSField != NULL);
-
- Field * pField = (Field *)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
-
- pField->AttachField(this, wideName);
- vRet = pJSField;
-
- return TRUE;
-}
-
-//Gets the name of the nth field in the document
-//comment:
-//note: the parameter nIndex, if it is not available
-
-FX_BOOL Document::getNthFieldName(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nIndex = params.size() > 0 ? (int)params[0] : -1;
- if (nIndex == -1) return FALSE;
-
- CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- CPDF_FormField* pField = pPDFForm->GetField(nIndex);
- if (!pField)
- return FALSE;
-
- vRet = pField->GetFullName();
- return TRUE;
-}
-
-//imports the specified fdf file.
-//comments: need reader suppport
-//note:once the cpath is illigl then a file dialog box pops up in order to ask user to chooose the file
-//int CPDFSDK_Document::importAnFDF(String cPath);
-
-FX_BOOL Document::importAnFDF(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
-
-
- CFX_WideString swPath;
-
- if (params.size() > 0)
- swPath = params[0];
-
- if (swPath.IsEmpty())
- {
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- swPath = pEnv->JS_fieldBrowse();
- if(swPath.IsEmpty())
- return TRUE;
- }
- else
- {
- swPath = app::PDFPathToSysPath(swPath);
- }
-
- m_pDocument->SetFocusAnnot(NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- if (!pInterForm->ImportFormFromFDFFile(swPath, TRUE))
- return FALSE;
-
- m_pDocument->SetChangeMark();
-// CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
-// ASSERT(pEnv != NULL);
-// IUndo* pUndo = IUndo::GetUndo(pEnv);
-// ASSERT(pUndo != NULL);
-// pUndo->Reset(m_pDocument);
-
- return TRUE;
-}
-
-//imports and specified XFDF file containing XML form data
-//comment: need reader supports
-//note: same as up
-//int CPDFSDK_Document::importAnFDF(String cPath)
-
-FX_BOOL Document::importAnXFDF(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
-
- return TRUE;
-}
-
-//imports and specified text file
-//commnet: need reader supports
-//note: same as up,when nRow is not rational,adobe is dumb for it.
-//int CPDFSDK_Document::importTextData(String cPath,int nRow);
-
-FX_BOOL Document::importTextData(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
-
- return TRUE;
-}
-
-//exports the form data and mails the resulting fdf file as an attachment to all recipients.
-//comment: need reader supports
-//note:
-//int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string cbcc,string cSubject,string cms);
-
-FX_BOOL Document::mailForm(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- int iLength = params.size();
-
- FX_BOOL bUI = iLength > 0 ? (FX_BOOL)params[0] : TRUE;
- CFX_WideString cTo = iLength > 1 ? (FX_LPCWSTR)params[1].operator CFX_WideString() : (FX_LPCWSTR)L"";
- CFX_WideString cCc = iLength > 2 ? (FX_LPCWSTR)params[2].operator CFX_WideString() : (FX_LPCWSTR)L"";
- CFX_WideString cBcc = iLength > 3 ? (FX_LPCWSTR)params[3].operator CFX_WideString() : (FX_LPCWSTR)L"";
- CFX_WideString cSubject = iLength > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";
- CFX_WideString cMsg = iLength > 5 ? (FX_LPCWSTR)params[5].operator CFX_WideString() : (FX_LPCWSTR)L"";
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- 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);
-
- pRuntime->BeginBlock();
- pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
- pRuntime->EndBlock();
- return TRUE;
-}
-
-FX_BOOL Document::print(OBJ_METHOD_PARAMS)
-{
- 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 = (JSFXObject)params[8];
- {
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"))
- {
- if (CJS_Object* pJSObj = (CJS_Object*)params[8])
- {
- 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];
- if(nlength >= 2)
- nStart = (int)params[1];
- if(nlength >= 3)
- nEnd = (int)params[2];
- if(nlength >= 4)
- bSilent = params[3];
- if(nlength >= 5)
- bShrinkToFit = params[4];
- if(nlength >= 6)
- bPrintAsImage = params[5];
- if(nlength >= 7)
- bReverse = params[6];
- if(nlength >= 8)
- bAnnotations = params[7];
- }
-
- 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.
-//comment:
-//note: if the filed name is not retional, adobe is dumb for it.
-
-FX_BOOL Document::removeField(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE;
-
- if (params.size() < 1)
- return TRUE;
-
- CFX_WideString sFieldName = params[0].operator CFX_WideString();
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray widgets;
- pInterForm->GetWidgets(sFieldName, widgets);
-
- int nSize = widgets.GetSize();
-
- 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;
-
- CFX_RectArray aRefresh;
- aRefresh.Add(rcAnnot);
-
- CPDF_Page* pPage = pWidget->GetPDFPage();
- ASSERT(pPage != NULL);
-
- CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
- pPageView->DeleteAnnot(pWidget);
-
- pPageView->UpdateRects(aRefresh);
- }
- m_pDocument->SetChangeMark();
- }
-
- return TRUE;
-}
-
-//reset filed values within a document.
-//comment:
-//note: if the fields names r not rational, aodbe is dumb for it.
-
-FX_BOOL Document::resetForm(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- 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);
-
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- v8::Isolate* isolate = GetIsolate(cc);
- CJS_Array aName(isolate);
-
- if (params.size() > 0)
- {
- switch (params[0].GetType())
- {
- default:
- aName.Attach(params[0]);
- break;
- case VT_string:
- aName.SetElement(0,params[0]);
- break;
- }
-
- 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.operator CFX_WideString();
-
- 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();
-
- }
- }
- else
- {
- pPDFForm->ResetForm(TRUE);
- m_pDocument->SetChangeMark();
-
- }
-
- return TRUE;
-}
-
-
-FX_BOOL Document::saveAs(OBJ_METHOD_PARAMS)
-{
-
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
-// m_pDocument->DoSaveAs();
-
- return TRUE;
-}
-
-
-FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
-// if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- int nSize = params.size();
- if (nSize < 1) 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].operator CFX_WideString();
- if (nSize > 1)
- bFDF = params[1];
- if (nSize > 2)
- bEmpty = params[2];
- if (nSize > 3)
- aFields.Attach(params[3]);
- }
- else if (v.GetType() == VT_object)
- {
- JSObject pObj = (JSObject)params[0];
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cURL");
- if (!pValue.IsEmpty())
- strURL = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
- pValue = JS_GetObjectElement(isolate,pObj, L"bFDF");
- bFDF = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));
- pValue = JS_GetObjectElement(isolate,pObj, L"bEmpty");
- bEmpty = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));
- pValue = JS_GetObjectElement(isolate,pObj,L"aFields");
- aFields.Attach(CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue)));
- }
-
- 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.operator CFX_WideString();
-
- 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;
-}
-
-CPDFSDK_Document * Document::GetReaderDoc()
-{
- return m_pDocument;
-}
-
-FX_BOOL Document::ExtractFileName(CPDFSDK_Document *pDoc,CFX_ByteString &strFileName)
-{
- return FALSE;
-}
-
-FX_BOOL Document::ExtractFolderName(CPDFSDK_Document *pDoc,CFX_ByteString &strFolderName)
-{
- return FALSE;
-}
-
-FX_BOOL Document::bookmarkRoot(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::mailDoc(OBJ_METHOD_PARAMS)
-{
- 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"";
-
-
- bUI = params.size()>=1?static_cast<FX_BOOL>(params[0]):TRUE;
- cTo = params.size()>=2?(const wchar_t*)params[1].operator CFX_WideString():L"";
- cCc = params.size()>=3?(const wchar_t*)params[2].operator CFX_WideString():L"";
- cBcc = params.size()>=4?(const wchar_t*)params[3].operator CFX_WideString():L"";
- cSubject = params.size()>=5?(const wchar_t*)params[4].operator CFX_WideString():L"";
- cMsg = params.size()>=6?(const wchar_t*)params[5].operator CFX_WideString():L"";
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if(params.size()>=1 && params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
- bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cTo");
- cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
- cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
- cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
- cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
- cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- }
-
- 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, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
- pRuntime->EndBlock();
-
- return TRUE;
-}
-
-FX_BOOL Document::author(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- 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;
-
- CFX_WideString csAuthor;
- vp >> csAuthor;
- pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));
- m_pDocument->SetChangeMark();
- return TRUE;
- }
-}
-
-FX_BOOL Document::info(OBJ_PROP_PARAMS)
-{
- 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.IsSetting())
- {
- 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);
- JS_PutObjectString(isolate,pObj, L"Title", cwTitle);
- JS_PutObjectString(isolate,pObj, L"Subject", cwSubject);
- JS_PutObjectString(isolate,pObj, L"Keywords", cwKeywords);
- JS_PutObjectString(isolate,pObj, L"Creator", cwCreator);
- JS_PutObjectString(isolate,pObj, L"Producer", cwProducer);
- JS_PutObjectString(isolate,pObj, L"CreationDate", cwCreationDate);
- JS_PutObjectString(isolate,pObj, L"ModDate", cwModDate);
- JS_PutObjectString(isolate,pObj, L"Trapped", cwTrapped);
-
-// 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);
- if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )
- JS_PutObjectString(isolate,pObj, wsKey, pValueObj->GetUnicodeText());
- if(pValueObj->GetType()==PDFOBJ_NUMBER)
- JS_PutObjectNumber(isolate,pObj, wsKey, (float)pValueObj->GetNumber());
- if(pValueObj->GetType()==PDFOBJ_BOOLEAN)
- JS_PutObjectBoolean(isolate,pObj, wsKey, (bool)pValueObj->GetInteger());
- }
-
- vp << pObj;
- return TRUE;
- }
- else
- {
- return TRUE;
- }
-}
-
-FX_BOOL Document::creationDate(OBJ_PROP_PARAMS)
-{
- 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;
-
- CFX_WideString csCreationDate;
- vp >> csCreationDate;
- pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));
- m_pDocument->SetChangeMark();
-
- return TRUE;
- }
-}
-
-FX_BOOL Document::creator(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- 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(OBJ_PROP_PARAMS)
-{
- 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
- {
- for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
- {
- if (CJS_DelayData* pData = m_DelayData.GetAt(i))
- {
- Field::DoDelay(m_pDocument, pData);
- delete m_DelayData.GetAt(i);
- }
- }
- m_DelayData.RemoveAll();
- }
-
- return TRUE;
- }
-}
-
-FX_BOOL Document::keywords(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)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;
- }
-}
-
-FX_BOOL Document::modDate(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- 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(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)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;
- }
-}
-
-FX_BOOL Document::subject(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)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;
- }
-}
-
-FX_BOOL Document::title(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
- return FALSE;
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- 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(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- ASSERT(m_pDocument != NULL);
- vp << m_pDocument->GetPageCount();
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-FX_BOOL Document::external(OBJ_PROP_PARAMS)
-{
- //In Chrome case,should always return true.
- vp << TRUE;
- return TRUE;
-}
-
-FX_BOOL Document::filesize(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- ASSERT(m_pDocument != NULL);
-
-// CFile file(m_pDocument->GetPath(), CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone);
-// vp << (double)file.GetLength();
-// file.Close();
-
- if ( m_pDocument->GetPath().IsEmpty() == FALSE)
- {
- CFX_ByteString bsStr = CFX_ByteString::FromUnicode( m_pDocument->GetPath() );
- FILE * pFile = NULL;
- pFile = fopen( bsStr.GetBuffer( bsStr.GetLength() ), "rb" );
- if ( pFile )
- {
- fseek( pFile, 0, SEEK_END );
- long lSize = ftell( pFile );
- fclose( pFile );
- pFile = NULL;
-
- vp << (FX_INT32)(lSize);
- return TRUE;
- }
- }
-
- vp << 0;
- return TRUE;
-}
-
-FX_BOOL Document::mouseX(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::mouseY(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::baseURL(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << m_cwBaseURL;
- return TRUE;
- }
- else
- {
- vp >> m_cwBaseURL;
- return TRUE;
- }
-}
-
-FX_BOOL Document::calculate(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != 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;
-
- pInterForm->EnableCalculate(bCalculate);
- }
-
- return TRUE;
-}
-
-FX_BOOL Document::documentFileName(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())
- return FALSE;
-
- CFX_WideString wsFilePath = m_pDocument->GetPath();
-
- FX_INT32 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)
-{
- wchar_t* pFrom = NULL;
- int iLenth = cbFrom.GetLength();
- wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));
- memset(pResult, 0, (iLenth+1));
- pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);
-
- for (int i = 0; i < iLenth; i++)
- {
- pResult[i] = *(pFrom + iLenth - i - 1);
- }
-
- cbFrom.ReleaseBuffer();
- CFX_WideString cbRet = CFX_WideString(pResult);
- free(pResult);
- pResult = NULL;
- return cbRet;
-}
-
-CFX_WideString Document::CutString(CFX_WideString cbFrom)
-{
- wchar_t* pFrom = NULL;
- int iLenth = cbFrom.GetLength();
- wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));
- memset(pResult, 0, (iLenth+1));
- pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);
-
- for (int i = 0; i < iLenth; i++)
- {
- if (pFrom[i] == L'\\' || pFrom[i] == L'/')
- break;
- pResult[i] = pFrom[i];
- }
-
- cbFrom.ReleaseBuffer();
- CFX_WideString cbRet = CFX_WideString(pResult);
- free(pResult);
- pResult = NULL;
- return cbRet;
-}
-
-FX_BOOL Document::path(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting()) return FALSE;
-
- vp << app::SysPathToPDFPath(m_pDocument->GetPath());
-
- return TRUE;
-}
-
-FX_BOOL Document::pageWindowRect(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::layout(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::addLink(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::closeDoc(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
-
-
-
-
- return TRUE;
-}
-
-FX_BOOL Document::getPageBox(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-
-FX_BOOL Document::getAnnot(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::getAnnots(OBJ_METHOD_PARAMS)
-{
- vRet.SetNull();
- return TRUE;
-}
-
-FX_BOOL Document::getAnnot3D(OBJ_METHOD_PARAMS)
-{
- vRet.SetNull();
- return TRUE;
-}
-
-FX_BOOL Document::getAnnots3D(OBJ_METHOD_PARAMS)
-{
- vRet = VT_undefined;
- return TRUE;
-}
-
-FX_BOOL Document::getOCGs(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::getLinks(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect)
-{
- 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 (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;
-
- 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;
-}
-
-int IconTree::GetLength()
-{
- 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;
- }
- else
- return NULL;
-}
-
-void IconTree::DeleteIconElement(CFX_WideString swIconName)
-{
- IconElement* pTemp = m_pHead;
- int iLoopCount = m_iLength;
- for (int i = 0; i < iLoopCount - 1; i++)
- {
- if (pTemp == m_pEnd)
- break;
-
- if (m_pHead->IconName == swIconName)
- {
- m_pHead = m_pHead->NextIcon;
- delete pTemp;
- m_iLength--;
- pTemp = m_pHead;
- }
- if (pTemp->NextIcon->IconName == swIconName)
- {
- if (pTemp->NextIcon == m_pEnd)
- {
- m_pEnd = pTemp;
- delete pTemp->NextIcon;
- m_iLength--;
- pTemp->NextIcon = NULL;
- }
- else
- {
- IconElement* pElement = pTemp->NextIcon;
- pTemp->NextIcon = pTemp->NextIcon->NextIcon;
- delete pElement;
- m_iLength--;
- pElement = NULL;
- }
-
- continue;
- }
-
- pTemp = pTemp->NextIcon;
- }
-}
-
-FX_BOOL Document::addIcon(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 2)return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CFX_WideString swIconName = params[0].operator CFX_WideString();
-
- JSFXObject pJSIcon = (JSFXObject)params[1];
- if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) return FALSE;
-
- CJS_EmbedObj* pEmbedObj = ((CJS_Object*)params[1])->GetEmbedObject();
- if (!pEmbedObj)return FALSE;
- 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;
-}
-
-FX_BOOL Document::icons(OBJ_PROP_PARAMS)
-{
- if (vp.IsSetting())
- return FALSE;
-
- if (!m_pIconTree)
- {
- vp.SetNull();
- return TRUE;
- }
-
- CJS_Array Icons(m_isolate);
- IconElement* pIconElement = NULL;
- int iIconTreeLength = m_pIconTree->GetLength();
-
- CJS_Context* pContext = (CJS_Context *)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
- 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;
-
- CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
- if (!pJS_Icon) 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));
- }
-
- vp << Icons;
- return TRUE;
-}
-
-FX_BOOL Document::getIcon(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 1)return FALSE;
- if(!m_pIconTree)
- return FALSE;
- CFX_WideString swIconName = params[0].operator CFX_WideString();
- int iIconCounts = m_pIconTree->GetLength();
-
- CJS_Context* pContext = (CJS_Context *)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
- 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;
-
- CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
- if (!pJS_Icon) return FALSE;
-
- Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
- if (!pIcon)return FALSE;
-
- pIcon->SetIconName(swIconName);
- pIcon->SetStream(pRetIcon->GetStream());
- vRet = pJS_Icon;
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL Document::removeIcon(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 1)return FALSE;
- if(!m_pIconTree)
- return FALSE;
- CFX_WideString swIconName = params[0].operator CFX_WideString();
-#ifndef FOXIT_CHROME_BUILD
- m_pIconTree->DeleteIconElement(swIconName);
-#endif
- return TRUE;
-}
-
-FX_BOOL Document::createDataObject(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- CFX_WideString swName = L"";
- CFX_ByteString sbName = "";
- CFX_WideString swValue = L"";
- CFX_WideString swMIMEType = L"";
- CFX_WideString swCryptFilter = L"";
- CFX_ByteString sbFileValue = "";
-
- int iParamSize = params.size();
- for (int i = 0; i < iParamSize; i++)
- {
- if (i == 0)
- swName = params[0];
- if (i == 1)
- swValue = params[1];
- if (i == 2)
- swMIMEType = params[2];
- if (i == 3)
- swCryptFilter = params[4];
- }
-
- FILE* pFile = NULL;
-
- //CFileStatus fileStatus;
- const int BUFSIZE = 17;
- FX_BYTE buf[BUFSIZE];
- FX_BYTE *pBuffer = NULL;
- char* pBuf = NULL;
- int nFileSize = 0;
- sbFileValue = CFX_ByteString::FromUnicode(swValue);
- sbName = CFX_ByteString::FromUnicode(swName);
- int iBufLength = sbFileValue.GetLength();
- pBuf = (char*)malloc(sizeof(char) * iBufLength);
- pBuf = sbFileValue.GetBuffer(iBufLength);
-
- if ( NULL == (pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "wb+" )) )
- {
- return FALSE;
- }
-
- fwrite( pBuf, sizeof(char), iBufLength, pFile );
- fclose( pFile );
- pFile = NULL;
-
- pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "rb+" );
- fseek( pFile, 0, SEEK_END );
- nFileSize = ftell( pFile );
-
- pBuffer = new FX_BYTE[nFileSize];
- fseek( pFile, 0, SEEK_SET );
- size_t s = fread( pBuffer, sizeof(char), nFileSize, pFile );
- if(s == 0)
- {
- delete[] pBuffer;
- return FALSE;
- }
-
- CRYPT_MD5Generate(pBuffer, nFileSize, buf);
- buf[BUFSIZE - 1] = 0;
- CFX_WideString csCheckSum((FX_LPCWSTR)buf, 16);
- delete[] pBuffer;
-
- return TRUE;
-}
-
-FX_BOOL Document::media(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::calculateNow(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- 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;
-}
-
-FX_BOOL Document::Collab(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS)
-{
- //if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
- int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0;
- bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true;
-
- CPDF_Document* pDocument = m_pDocument->GetDocument();
- if (!pDocument) return FALSE;
-
- if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
- {
- //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
- if (!pPageDict) return FALSE;
-
- CPDF_Page page;
- page.Load(pDocument, pPageDict);
- page.StartParse();
- page.ParseContent();
-
- FX_POSITION pos = page.GetFirstObjectPosition();
-
- int nWords = 0;
-
- CFX_WideString swRet;
-
- 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;
- }
-
- nWords += nObjWords;
- }
- }
- }
-
- if (bStrip)
- {
- swRet.TrimLeft();
- swRet.TrimRight();
- }
-
- vRet = swRet;
- return TRUE;
-}
-
-FX_BOOL Document::getPageNthWordQuads(OBJ_METHOD_PARAMS)
-{
- //if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- return FALSE;
-}
-
-FX_BOOL Document::getPageNumWords(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
-
- CPDF_Document* pDocument = m_pDocument->GetDocument();
- ASSERT(pDocument != NULL);
-
- if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
- {
- //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
- if (!pPageDict) return FALSE;
-
- CPDF_Page page;
- page.Load(pDocument, pPageDict);
- page.StartParse();
- page.ParseContent();
-
- FX_POSITION pos = page.GetFirstObjectPosition();
-
- 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);
- }
- }
- }
-
- vRet = nWords;
-
- return TRUE;
-}
-
-FX_BOOL Document::getPrintParams(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
- JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"));
- //not implemented yet.
- vRet = pRetObj;
-
- return TRUE;
-}
-
-#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
-
-int Document::CountWords(CPDF_TextObject* pTextObj)
-{
- if (!pTextObj) return 0;
-
- int nWords = 0;
-
- CPDF_Font* pFont = pTextObj->GetFont();
- if (!pFont) return 0;
-
- FX_BOOL bIsLatin = FALSE;
-
- 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);
-
- FX_WORD unicode = 0;
- if (swUnicode.GetLength() > 0)
- unicode = swUnicode[0];
-
- if (ISLATINWORD(unicode) && bIsLatin)
- continue;
-
- bIsLatin = ISLATINWORD(unicode);
- if (unicode != 0x20)
- nWords++;
- }
-
- return nWords;
-}
-
-CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex)
-{
- ASSERT(pTextObj != NULL);
-
- CFX_WideString swRet;
-
- CPDF_Font* pFont = pTextObj->GetFont();
- if (!pFont) return L"";
-
- int nWords = 0;
- FX_BOOL bIsLatin = FALSE;
-
- 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);
-
- FX_WORD unicode = 0;
- if (swUnicode.GetLength() > 0)
- unicode = swUnicode[0];
-
- if (ISLATINWORD(unicode) && bIsLatin)
- {
- }
- else
- {
- bIsLatin = ISLATINWORD(unicode);
- if (unicode != 0x20)
- nWords++;
- }
-
- if (nWords-1 == nWordIndex)
- swRet += unicode;
- }
-
- return swRet;
-}
-
-FX_BOOL Document::zoom(OBJ_PROP_PARAMS)
-{
-
- return TRUE;
-}
-
-/**
-(none, NoVary)
-(fitP, FitPage)
-(fitW, FitWidth)
-(fitH, FitHeight)
-(fitV, FitVisibleWidth)
-(pref, Preferred)
-(refW, ReflowWidth)
-*/
-
-FX_BOOL Document::zoomType(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::deletePages(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- v8::Isolate* isolate = GetIsolate(cc);
-// if (pEnv->GetAppName().Compare(PHANTOM) != 0)
-// return TRUE;
-
- //if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
-
- int iSize = params.size();
-
- int nStart = 0;
- int nEnd = 0;
-
- if (iSize < 1)
- {
- }
- else if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
- nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
- nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
- }
- else
- {
- nStart = (int)params[0];
- }
- }
- else
- {
- nStart = (int)params[0];
- nEnd = (int)params[1];
- }
-
- int nTotal = m_pDocument->GetPageCount();
-
- if (nStart < 0) nStart = 0;
- if (nStart >= nTotal) nStart = nTotal - 1;
-
- if (nEnd < 0) nEnd = 0;
- if (nEnd >= nTotal) nEnd = nTotal - 1;
-
- if (nEnd < nStart) nEnd = nStart;
-
-
-
-#ifndef FOXIT_CHROME_BUILD
- return m_pDocument->DeletePages(nStart, nEnd - nStart + 1);
-#else
- return TRUE;
-#endif
-}
-
-FX_BOOL Document::extractPages(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT)) return FALSE;
-
- int iSize = params.size();
-
- int nTotal = m_pDocument->GetPageCount();
- int nStart = 0;
- int nEnd = nTotal - 1;
-
- CFX_WideString swFilePath;
-
- if (iSize < 1)
- {
- }
- else if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
- nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
- nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
- swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
- }
- else
- {
- nStart = (int)params[0];
- }
- }
- else if (iSize == 2)
- {
- nStart = (int)params[0];
- nEnd = (int)params[1];
- }
- else
- {
- nStart = (int)params[0];
- nEnd = (int)params[1];
- swFilePath = params[2].operator CFX_WideString();
- }
-
- if (nEnd < nStart)
- nEnd = nStart;
-
- CPDF_Document *pNewDoc = new CPDF_Document;
- pNewDoc->CreateNewDoc();
-
- CFX_WordArray array;
- for (int i=nStart; i<=nEnd; i++)
- array.Add(i);
-
-// m_pDocument->ExtractPages(array, pNewDoc);
-
- if (swFilePath.IsEmpty())
- {
-
- }
- else
- {
- swFilePath = app::PDFPathToSysPath(swFilePath);
- CPDF_Creator PDFCreater(pNewDoc);
- PDFCreater.Create(swFilePath);
- delete pNewDoc;
-// pEnv->OpenDocument(swFilePath);
- vRet.SetNull();
- }
-
- return TRUE;
-}
-
-FX_BOOL Document::insertPages(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
-
- int iSize = params.size();
-
- int nStart = 0;
- int nEnd = 0;
- int nPage = 0;
-
- CFX_WideString swFilePath;
-
- if (iSize < 1)
- {
- }
- else if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");
- nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
- swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
- nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
- nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
- }
- else
- {
- nPage = (int)params[0];
- }
- }
- else
- {
- nPage = (int)params[0];
-
- if (iSize >= 2)
- swFilePath = params[1].operator CFX_WideString();
-
- if (iSize >= 3)
- nStart = (int)params[2];
-
- if (iSize >= 4)
- nEnd = (int)params[3];
- }
-
- nPage++;
-
- if (nPage < 0)
- nPage = 0;
-
- if (nPage > m_pDocument->GetPageCount())
- nPage = m_pDocument->GetPageCount();
-
- if (swFilePath.IsEmpty()) return FALSE;
-
- swFilePath = app::PDFPathToSysPath(swFilePath);
-
- CPDF_Parser pdfParser;
- pdfParser.StartParse(swFilePath, FALSE);
- CPDF_Document* pSrcDoc = pdfParser.GetDocument();
-
- if (!pSrcDoc)
- {
- pdfParser.CloseParser();
- return FALSE;
- }
-
- int nTotal = pSrcDoc->GetPageCount();
-
- if (nStart < 0) nStart = 0;
- if (nStart >= nTotal) nStart = nTotal - 1;
-
- if (nEnd < 0) nEnd = 0;
- if (nEnd >= nTotal) nEnd = nTotal - 1;
-
- if (nEnd < nStart) nEnd = nStart;
-
- CFX_WordArray array;
- for (int i=nStart; i<=nEnd; i++)
- array.Add(i);
-
-// m_pDocument->InsertPages(nPage, pSrcDoc, array);
-
- pdfParser.CloseParser();
-
- return TRUE;
-}
-
-FX_BOOL Document::replacePages(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
-
- int iSize = params.size();
-
- int nStart = -1;
- int nEnd = -1;
- int nPage = 0;
-
- CFX_WideString swFilePath;
-
- if (iSize < 1)
- {
- }
- else if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");
- nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
- swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
- nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
- nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
- }
- else
- {
- nPage = (int)params[0];
- }
- }
- else
- {
- nPage = (int)params[0];
-
- if (iSize >= 2)
- swFilePath = params[1].operator CFX_WideString();
-
- if (iSize >= 3)
- nStart = (int)params[2];
-
- if (iSize >= 4)
- nEnd = (int)params[3];
- }
-
- if (nPage < 0)
- nPage = 0;
-
- if (nPage >= m_pDocument->GetPageCount())
- nPage = m_pDocument->GetPageCount() - 1;
-
- if (swFilePath.IsEmpty()) return FALSE;
-
- swFilePath = app::PDFPathToSysPath(swFilePath);
-
- CPDF_Parser pdfParser;
- pdfParser.StartParse(swFilePath, FALSE);
- CPDF_Document* pSrcDoc = pdfParser.GetDocument();
-
- if (!pSrcDoc)
- {
- pdfParser.CloseParser();
- return FALSE;
- }
-
- int nTotal = pSrcDoc->GetPageCount();
-
- if (nStart < 0)
- {
- if (nEnd < 0)
- {
- nStart = 0;
- nEnd = nTotal - 1;
- }
- else
- {
- nStart = 0;
- }
- }
- else
- {
- if (nEnd < 0)
- {
- nEnd = nStart;
- }
- else
- {
- if (nStart >= nTotal) nStart = nTotal - 1;
- if (nEnd >= nTotal) nEnd = nTotal - 1;
-
- if (nEnd < nStart) nEnd = nStart;
- }
- }
-
- CFX_WordArray array;
- for (int i=nStart; i<=nEnd; i++)
- array.Add(i);
-
-// m_pDocument->ReplacePages(nPage, pSrcDoc, array);
-
- pdfParser.CloseParser();
-
- return TRUE;
-}
-
-FX_BOOL Document::getURL(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
-
- return TRUE;
-}
-
-void Document::AddDelayData(CJS_DelayData* pData)
-{
- m_DelayData.Add(pData);
-}
-
-void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex)
-{
- CFX_DWordArray DelArray;
-
- 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)
- {
- Field::DoDelay(m_pDocument, pData);
- delete pData;
- m_DelayData.SetAt(i, NULL);
- DelArray.Add(i);
- }
- }
- }
-
- for (int j=DelArray.GetSize()-1; j>=0; j--)
- {
- m_DelayData.RemoveAt(DelArray[j]);
- }
-}
-
-void Document::AddDelayAnnotData(CJS_AnnotObj *pData)
-{
- m_DelayAnnotData.Add(pData);
-}
-
-void Document::DoAnnotDelay()
-{
- CFX_DWordArray DelArray;
-
- for (int j=DelArray.GetSize()-1; j>=0; j--)
- {
- m_DelayData.RemoveAt(DelArray[j]);
- }
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/app.h"
+#include "../../include/javascript/Field.h"
+#include "../../include/javascript/Icon.h"
+#include "../../include/javascript/Field.h"
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+
+BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)
+END_JS_STATIC_METHOD()
+
+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;
+}
+
+/* ---------------------- Document ---------------------- */
+
+#define MINWIDTH 5.0f
+#define MINHEIGHT 5.0f
+
+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)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Document)
+ JS_STATIC_METHOD_ENTRY(addAnnot,0)
+ JS_STATIC_METHOD_ENTRY(addField, 4)
+ JS_STATIC_METHOD_ENTRY(addLink, 0)
+ JS_STATIC_METHOD_ENTRY(addIcon, 0)
+ JS_STATIC_METHOD_ENTRY(calculateNow, 0)
+ JS_STATIC_METHOD_ENTRY(closeDoc, 0)
+ JS_STATIC_METHOD_ENTRY(createDataObject, 0)
+ JS_STATIC_METHOD_ENTRY(deletePages, 2)
+ JS_STATIC_METHOD_ENTRY(exportAsText, 3)
+ JS_STATIC_METHOD_ENTRY(exportAsFDF, 6)
+ JS_STATIC_METHOD_ENTRY(exportAsXFDF, 5)
+ JS_STATIC_METHOD_ENTRY(extractPages, 3)
+ JS_STATIC_METHOD_ENTRY(getAnnot, 0)
+ JS_STATIC_METHOD_ENTRY(getAnnots, 2)
+ JS_STATIC_METHOD_ENTRY(getAnnot3D, 2)
+ JS_STATIC_METHOD_ENTRY(getAnnots3D, 1)
+ JS_STATIC_METHOD_ENTRY(getField, 1)
+ JS_STATIC_METHOD_ENTRY(getIcon, 0)
+ JS_STATIC_METHOD_ENTRY(getLinks, 0)
+ JS_STATIC_METHOD_ENTRY(getNthFieldName, 1)
+ JS_STATIC_METHOD_ENTRY(getOCGs, 0)
+ JS_STATIC_METHOD_ENTRY(getPageBox, 0)
+ JS_STATIC_METHOD_ENTRY(getPageNthWord, 3)
+ JS_STATIC_METHOD_ENTRY(getPageNthWordQuads, 2)
+ JS_STATIC_METHOD_ENTRY(getPageNumWords, 1)
+ JS_STATIC_METHOD_ENTRY(getPrintParams, 0)
+ JS_STATIC_METHOD_ENTRY(getURL, 2)
+ JS_STATIC_METHOD_ENTRY(importAnFDF, 1)
+ JS_STATIC_METHOD_ENTRY(importAnXFDF, 1)
+ JS_STATIC_METHOD_ENTRY(importTextData, 2)
+ JS_STATIC_METHOD_ENTRY(insertPages, 4)
+ JS_STATIC_METHOD_ENTRY(mailForm, 6)
+ JS_STATIC_METHOD_ENTRY(print, 9)
+ JS_STATIC_METHOD_ENTRY(removeField, 1)
+ JS_STATIC_METHOD_ENTRY(replacePages, 4)
+ JS_STATIC_METHOD_ENTRY(resetForm, 1)
+ JS_STATIC_METHOD_ENTRY(removeIcon, 0)
+ JS_STATIC_METHOD_ENTRY(saveAs, 5)
+ JS_STATIC_METHOD_ENTRY(submitForm, 23)
+ JS_STATIC_METHOD_ENTRY(mailDoc, 0)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Document, Document)
+
+FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ Document* pDoc = (Document*)GetEmbedObject();
+ ASSERT(pDoc != NULL);
+
+ pDoc->AttachDoc(pContext->GetReaderDocument());
+ pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
+ return TRUE;
+};
+
+/* --------------------------------- Document --------------------------------- */
+
+Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
+ m_cwBaseURL(L""),
+ m_pIconTree(NULL),
+ m_pDocument(NULL),
+ m_bDelay(FALSE),
+ m_isolate(NULL)
+{
+}
+
+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);
+
+ }
+ }
+
+ m_DelayData.RemoveAll();
+ m_DelayAnnotData.RemoveAll();
+}
+
+//the total number of fileds in document.
+FX_BOOL Document::numFields(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting()) return FALSE;
+
+ ASSERT(m_pDocument != NULL);
+
+ CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ vp << (int)pPDFForm->CountFields();
+
+ return TRUE;
+}
+
+FX_BOOL Document::dirty(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsGetting())
+ {
+ if (m_pDocument->GetChangeMark())
+ vp << true;
+ else
+ vp << false;
+ }
+ else
+ {
+ bool bChanged = false;
+
+ vp >> bChanged;
+
+ if (bChanged)
+ m_pDocument->SetChangeMark();
+ else
+ m_pDocument->ClearChangeMark();
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Document::ADBE(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsGetting())
+ {
+ vp.SetNull();
+ }
+ else
+ {
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Document::pageNum(OBJ_PROP_PARAMS)
+{
+ 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(!pEnv)
+ return FALSE;
+
+ 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)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::addAnnot(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::addField(OBJ_METHOD_PARAMS)
+{
+ //Doesn't support.
+ return TRUE;
+}
+
+//exports form fields as a tab-delimited text file to a local hard disk.
+//comment: need reader support
+//note : watch the third parameter:cPath, for what case it can be safely saved?
+//int CPDFSDK_InterForm::ExportAsText(FX_BOOL bNoPassword,StringArray aFields,String cPath);
+//return value, int the index of the parameters illegal, the index is based on 1.
+
+FX_BOOL Document::exportAsText(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ return TRUE;
+}
+
+//exports form fields as a fdf file to the local hard drive
+//comment: need reader supports
+//note:the last parameter hasn't been confirmed.because the previous one blocks the way.
+//int CPDFSDK_Document::ExportAsFDF(FX_BOOL bAllFields,BOOL bNoPassword,StringArray aFields,FX_BOOL bFlags,String cPath,FX_BOOL bAnnotations);
+
+FX_BOOL Document::exportAsFDF(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ FX_BOOL bAllFields = params.size() > 0 ? (FX_BOOL)params[0] : FALSE;
+ FX_BOOL bNoPassWord = params.size() > 1 ? (FX_BOOL)params[1] : TRUE;
+ FX_BOOL bWhole = params.size() > 2 ? (params[2].GetType() == VT_null) : TRUE;
+ CJS_Array arrayFileds(isolate);
+ if (!bWhole)
+ arrayFileds.Attach(params[2]);
+ //FX_BOOL bFlags = params.size() > 3 ? (FX_BOOL)params[3] : FALSE;
+ CFX_WideString swFilePath = params.size() > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";
+
+ if (swFilePath.IsEmpty())
+ {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ swFilePath = pEnv->JS_fieldBrowse();
+ if(swFilePath.IsEmpty())
+ return TRUE;
+ }
+ else
+ {
+ swFilePath = app::PDFPathToSysPath(swFilePath);
+ }
+
+ m_pDocument->SetFocusAnnot(NULL);
+
+ CPDFSDK_InterForm* pInterForm= (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ CFX_PtrArray aFields;
+
+ if (bWhole)
+ {
+ for (int j=0,jsz=pPDFForm->CountFields(); j<jsz; j++)
+ {
+ aFields.Add(pPDFForm->GetField(j));
+ }
+ }
+ else
+ {
+ for (int i=0,isz=arrayFileds.GetLength(); i<isz; i++)
+ {
+ CJS_Value valName(isolate);
+ arrayFileds.GetElement(i,valName);
+ CFX_WideString swName = valName.operator CFX_WideString();
+
+ for (int j=0, jsz=pPDFForm->CountFields(swName); j<jsz; j++)
+ {
+ aFields.Add(pPDFForm->GetField(j, swName));
+ }
+ }
+ }
+
+ CFX_PtrArray fields;
+
+ for (int i=0,sz=aFields.GetSize(); i<sz; i++)
+ {
+ CPDF_FormField* pField = (CPDF_FormField*)aFields[i];
+
+ if (!bAllFields)
+ if (pField->GetValue() == L"")
+ continue;
+
+ if (bNoPassWord)
+ if (pField->GetFieldFlags() & 0x2000)
+ continue;
+
+ fields.Add((void*)pField);
+ }
+
+ return pInterForm->ExportFieldsToFDFFile(swFilePath, fields, TRUE);
+}
+
+//exports form fields an XFDF file to the local hard drive
+//comment: need reder supports
+//note:the last parameter can't be test
+//int CPDFSDK_Document::ExportAsXFDF(FX_BOOL bAllFields,FX_BOOL bNoPassWord,StringArray aFields,String cPath,FX_BOOL bAnnoatations);
+
+FX_BOOL Document::exportAsXFDF(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ return TRUE;
+}
+
+//Maps a field object in PDF document to a JavaScript variable
+//comment:
+//note: the paremter cName, this is clue how to treat if the cName is not a valiable filed name in this document
+
+FX_BOOL Document::getField(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ ASSERT(m_pDocument != NULL);
+
+ if (params.size() < 1) return FALSE;
+
+ CFX_WideString wideName = params[0].operator CFX_WideString();
+
+ CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ if (pPDFForm->CountFields(wideName) <= 0)
+ {
+ vRet.SetNull();
+ return TRUE;
+ }
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
+
+ CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj);
+ ASSERT(pJSField != NULL);
+
+ Field * pField = (Field *)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
+
+ pField->AttachField(this, wideName);
+ vRet = pJSField;
+
+ return TRUE;
+}
+
+//Gets the name of the nth field in the document
+//comment:
+//note: the parameter nIndex, if it is not available
+
+FX_BOOL Document::getNthFieldName(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nIndex = params.size() > 0 ? (int)params[0] : -1;
+ if (nIndex == -1) return FALSE;
+
+ CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ CPDF_FormField* pField = pPDFForm->GetField(nIndex);
+ if (!pField)
+ return FALSE;
+
+ vRet = pField->GetFullName();
+ return TRUE;
+}
+
+//imports the specified fdf file.
+//comments: need reader suppport
+//note:once the cpath is illigl then a file dialog box pops up in order to ask user to chooose the file
+//int CPDFSDK_Document::importAnFDF(String cPath);
+
+FX_BOOL Document::importAnFDF(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+
+
+ CFX_WideString swPath;
+
+ if (params.size() > 0)
+ swPath = params[0];
+
+ if (swPath.IsEmpty())
+ {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ swPath = pEnv->JS_fieldBrowse();
+ if(swPath.IsEmpty())
+ return TRUE;
+ }
+ else
+ {
+ swPath = app::PDFPathToSysPath(swPath);
+ }
+
+ m_pDocument->SetFocusAnnot(NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ if (!pInterForm->ImportFormFromFDFFile(swPath, TRUE))
+ return FALSE;
+
+ m_pDocument->SetChangeMark();
+// CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+// ASSERT(pEnv != NULL);
+// IUndo* pUndo = IUndo::GetUndo(pEnv);
+// ASSERT(pUndo != NULL);
+// pUndo->Reset(m_pDocument);
+
+ return TRUE;
+}
+
+//imports and specified XFDF file containing XML form data
+//comment: need reader supports
+//note: same as up
+//int CPDFSDK_Document::importAnFDF(String cPath)
+
+FX_BOOL Document::importAnXFDF(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+
+ return TRUE;
+}
+
+//imports and specified text file
+//commnet: need reader supports
+//note: same as up,when nRow is not rational,adobe is dumb for it.
+//int CPDFSDK_Document::importTextData(String cPath,int nRow);
+
+FX_BOOL Document::importTextData(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+
+ return TRUE;
+}
+
+//exports the form data and mails the resulting fdf file as an attachment to all recipients.
+//comment: need reader supports
+//note:
+//int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string cbcc,string cSubject,string cms);
+
+FX_BOOL Document::mailForm(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ int iLength = params.size();
+
+ FX_BOOL bUI = iLength > 0 ? (FX_BOOL)params[0] : TRUE;
+ CFX_WideString cTo = iLength > 1 ? (FX_LPCWSTR)params[1].operator CFX_WideString() : (FX_LPCWSTR)L"";
+ CFX_WideString cCc = iLength > 2 ? (FX_LPCWSTR)params[2].operator CFX_WideString() : (FX_LPCWSTR)L"";
+ CFX_WideString cBcc = iLength > 3 ? (FX_LPCWSTR)params[3].operator CFX_WideString() : (FX_LPCWSTR)L"";
+ CFX_WideString cSubject = iLength > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";
+ CFX_WideString cMsg = iLength > 5 ? (FX_LPCWSTR)params[5].operator CFX_WideString() : (FX_LPCWSTR)L"";
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ 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);
+
+ pRuntime->BeginBlock();
+ pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+ pRuntime->EndBlock();
+ return TRUE;
+}
+
+FX_BOOL Document::print(OBJ_METHOD_PARAMS)
+{
+ 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 = (JSFXObject)params[8];
+ {
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"))
+ {
+ if (CJS_Object* pJSObj = (CJS_Object*)params[8])
+ {
+ 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];
+ if(nlength >= 2)
+ nStart = (int)params[1];
+ if(nlength >= 3)
+ nEnd = (int)params[2];
+ if(nlength >= 4)
+ bSilent = params[3];
+ if(nlength >= 5)
+ bShrinkToFit = params[4];
+ if(nlength >= 6)
+ bPrintAsImage = params[5];
+ if(nlength >= 7)
+ bReverse = params[6];
+ if(nlength >= 8)
+ bAnnotations = params[7];
+ }
+
+ 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.
+//comment:
+//note: if the filed name is not retional, adobe is dumb for it.
+
+FX_BOOL Document::removeField(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE;
+
+ if (params.size() < 1)
+ return TRUE;
+
+ CFX_WideString sFieldName = params[0].operator CFX_WideString();
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray widgets;
+ pInterForm->GetWidgets(sFieldName, widgets);
+
+ int nSize = widgets.GetSize();
+
+ 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;
+
+ CFX_RectArray aRefresh;
+ aRefresh.Add(rcAnnot);
+
+ CPDF_Page* pPage = pWidget->GetPDFPage();
+ ASSERT(pPage != NULL);
+
+ CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
+ pPageView->DeleteAnnot(pWidget);
+
+ pPageView->UpdateRects(aRefresh);
+ }
+ m_pDocument->SetChangeMark();
+ }
+
+ return TRUE;
+}
+
+//reset filed values within a document.
+//comment:
+//note: if the fields names r not rational, aodbe is dumb for it.
+
+FX_BOOL Document::resetForm(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ 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);
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ v8::Isolate* isolate = GetIsolate(cc);
+ CJS_Array aName(isolate);
+
+ if (params.size() > 0)
+ {
+ switch (params[0].GetType())
+ {
+ default:
+ aName.Attach(params[0]);
+ break;
+ case VT_string:
+ aName.SetElement(0,params[0]);
+ break;
+ }
+
+ 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.operator CFX_WideString();
+
+ 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();
+
+ }
+ }
+ else
+ {
+ pPDFForm->ResetForm(TRUE);
+ m_pDocument->SetChangeMark();
+
+ }
+
+ return TRUE;
+}
+
+
+FX_BOOL Document::saveAs(OBJ_METHOD_PARAMS)
+{
+
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+// m_pDocument->DoSaveAs();
+
+ return TRUE;
+}
+
+
+FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+// if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ int nSize = params.size();
+ if (nSize < 1) 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].operator CFX_WideString();
+ if (nSize > 1)
+ bFDF = params[1];
+ if (nSize > 2)
+ bEmpty = params[2];
+ if (nSize > 3)
+ aFields.Attach(params[3]);
+ }
+ else if (v.GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject)params[0];
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cURL");
+ if (!pValue.IsEmpty())
+ strURL = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+ pValue = JS_GetObjectElement(isolate,pObj, L"bFDF");
+ bFDF = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));
+ pValue = JS_GetObjectElement(isolate,pObj, L"bEmpty");
+ bEmpty = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));
+ pValue = JS_GetObjectElement(isolate,pObj,L"aFields");
+ aFields.Attach(CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue)));
+ }
+
+ 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.operator CFX_WideString();
+
+ 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;
+}
+
+CPDFSDK_Document * Document::GetReaderDoc()
+{
+ return m_pDocument;
+}
+
+FX_BOOL Document::ExtractFileName(CPDFSDK_Document *pDoc,CFX_ByteString &strFileName)
+{
+ return FALSE;
+}
+
+FX_BOOL Document::ExtractFolderName(CPDFSDK_Document *pDoc,CFX_ByteString &strFolderName)
+{
+ return FALSE;
+}
+
+FX_BOOL Document::bookmarkRoot(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::mailDoc(OBJ_METHOD_PARAMS)
+{
+ 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"";
+
+
+ bUI = params.size()>=1?static_cast<FX_BOOL>(params[0]):TRUE;
+ cTo = params.size()>=2?(const wchar_t*)params[1].operator CFX_WideString():L"";
+ cCc = params.size()>=3?(const wchar_t*)params[2].operator CFX_WideString():L"";
+ cBcc = params.size()>=4?(const wchar_t*)params[3].operator CFX_WideString():L"";
+ cSubject = params.size()>=5?(const wchar_t*)params[4].operator CFX_WideString():L"";
+ cMsg = params.size()>=6?(const wchar_t*)params[5].operator CFX_WideString():L"";
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if(params.size()>=1 && params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
+ bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cTo");
+ cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
+ cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
+ cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
+ cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
+ cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ }
+
+ 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, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+ pRuntime->EndBlock();
+
+ return TRUE;
+}
+
+FX_BOOL Document::author(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ 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;
+
+ CFX_WideString csAuthor;
+ vp >> csAuthor;
+ pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::info(OBJ_PROP_PARAMS)
+{
+ 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.IsSetting())
+ {
+ 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);
+ JS_PutObjectString(isolate,pObj, L"Title", cwTitle);
+ JS_PutObjectString(isolate,pObj, L"Subject", cwSubject);
+ JS_PutObjectString(isolate,pObj, L"Keywords", cwKeywords);
+ JS_PutObjectString(isolate,pObj, L"Creator", cwCreator);
+ JS_PutObjectString(isolate,pObj, L"Producer", cwProducer);
+ JS_PutObjectString(isolate,pObj, L"CreationDate", cwCreationDate);
+ JS_PutObjectString(isolate,pObj, L"ModDate", cwModDate);
+ JS_PutObjectString(isolate,pObj, L"Trapped", cwTrapped);
+
+// 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);
+ if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )
+ JS_PutObjectString(isolate,pObj, wsKey, pValueObj->GetUnicodeText());
+ if(pValueObj->GetType()==PDFOBJ_NUMBER)
+ JS_PutObjectNumber(isolate,pObj, wsKey, (float)pValueObj->GetNumber());
+ if(pValueObj->GetType()==PDFOBJ_BOOLEAN)
+ JS_PutObjectBoolean(isolate,pObj, wsKey, (bool)pValueObj->GetInteger());
+ }
+
+ vp << pObj;
+ return TRUE;
+ }
+ else
+ {
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::creationDate(OBJ_PROP_PARAMS)
+{
+ 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;
+
+ CFX_WideString csCreationDate;
+ vp >> csCreationDate;
+ pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));
+ m_pDocument->SetChangeMark();
+
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::creator(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ 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(OBJ_PROP_PARAMS)
+{
+ 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
+ {
+ for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
+ {
+ if (CJS_DelayData* pData = m_DelayData.GetAt(i))
+ {
+ Field::DoDelay(m_pDocument, pData);
+ delete m_DelayData.GetAt(i);
+ }
+ }
+ m_DelayData.RemoveAll();
+ }
+
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::keywords(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)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;
+ }
+}
+
+FX_BOOL Document::modDate(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ 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(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)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;
+ }
+}
+
+FX_BOOL Document::subject(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)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;
+ }
+}
+
+FX_BOOL Document::title(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
+ return FALSE;
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ 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(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ ASSERT(m_pDocument != NULL);
+ vp << m_pDocument->GetPageCount();
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+FX_BOOL Document::external(OBJ_PROP_PARAMS)
+{
+ //In Chrome case,should always return true.
+ vp << TRUE;
+ return TRUE;
+}
+
+FX_BOOL Document::filesize(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ ASSERT(m_pDocument != NULL);
+
+// CFile file(m_pDocument->GetPath(), CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone);
+// vp << (double)file.GetLength();
+// file.Close();
+
+ if ( m_pDocument->GetPath().IsEmpty() == FALSE)
+ {
+ CFX_ByteString bsStr = CFX_ByteString::FromUnicode( m_pDocument->GetPath() );
+ FILE * pFile = NULL;
+ pFile = fopen( bsStr.GetBuffer( bsStr.GetLength() ), "rb" );
+ if ( pFile )
+ {
+ fseek( pFile, 0, SEEK_END );
+ long lSize = ftell( pFile );
+ fclose( pFile );
+ pFile = NULL;
+
+ vp << (FX_INT32)(lSize);
+ return TRUE;
+ }
+ }
+
+ vp << 0;
+ return TRUE;
+}
+
+FX_BOOL Document::mouseX(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::mouseY(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::baseURL(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << m_cwBaseURL;
+ return TRUE;
+ }
+ else
+ {
+ vp >> m_cwBaseURL;
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::calculate(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != 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;
+
+ pInterForm->EnableCalculate(bCalculate);
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Document::documentFileName(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())
+ return FALSE;
+
+ CFX_WideString wsFilePath = m_pDocument->GetPath();
+
+ FX_INT32 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)
+{
+ wchar_t* pFrom = NULL;
+ int iLenth = cbFrom.GetLength();
+ wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));
+ memset(pResult, 0, (iLenth+1));
+ pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);
+
+ for (int i = 0; i < iLenth; i++)
+ {
+ pResult[i] = *(pFrom + iLenth - i - 1);
+ }
+
+ cbFrom.ReleaseBuffer();
+ CFX_WideString cbRet = CFX_WideString(pResult);
+ free(pResult);
+ pResult = NULL;
+ return cbRet;
+}
+
+CFX_WideString Document::CutString(CFX_WideString cbFrom)
+{
+ wchar_t* pFrom = NULL;
+ int iLenth = cbFrom.GetLength();
+ wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));
+ memset(pResult, 0, (iLenth+1));
+ pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);
+
+ for (int i = 0; i < iLenth; i++)
+ {
+ if (pFrom[i] == L'\\' || pFrom[i] == L'/')
+ break;
+ pResult[i] = pFrom[i];
+ }
+
+ cbFrom.ReleaseBuffer();
+ CFX_WideString cbRet = CFX_WideString(pResult);
+ free(pResult);
+ pResult = NULL;
+ return cbRet;
+}
+
+FX_BOOL Document::path(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting()) return FALSE;
+
+ vp << app::SysPathToPDFPath(m_pDocument->GetPath());
+
+ return TRUE;
+}
+
+FX_BOOL Document::pageWindowRect(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::layout(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::addLink(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::closeDoc(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+
+
+
+
+ return TRUE;
+}
+
+FX_BOOL Document::getPageBox(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+
+FX_BOOL Document::getAnnot(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::getAnnots(OBJ_METHOD_PARAMS)
+{
+ vRet.SetNull();
+ return TRUE;
+}
+
+FX_BOOL Document::getAnnot3D(OBJ_METHOD_PARAMS)
+{
+ vRet.SetNull();
+ return TRUE;
+}
+
+FX_BOOL Document::getAnnots3D(OBJ_METHOD_PARAMS)
+{
+ vRet = VT_undefined;
+ return TRUE;
+}
+
+FX_BOOL Document::getOCGs(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::getLinks(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect)
+{
+ 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 (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;
+
+ 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;
+}
+
+int IconTree::GetLength()
+{
+ 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;
+ }
+ else
+ return NULL;
+}
+
+void IconTree::DeleteIconElement(CFX_WideString swIconName)
+{
+ IconElement* pTemp = m_pHead;
+ int iLoopCount = m_iLength;
+ for (int i = 0; i < iLoopCount - 1; i++)
+ {
+ if (pTemp == m_pEnd)
+ break;
+
+ if (m_pHead->IconName == swIconName)
+ {
+ m_pHead = m_pHead->NextIcon;
+ delete pTemp;
+ m_iLength--;
+ pTemp = m_pHead;
+ }
+ if (pTemp->NextIcon->IconName == swIconName)
+ {
+ if (pTemp->NextIcon == m_pEnd)
+ {
+ m_pEnd = pTemp;
+ delete pTemp->NextIcon;
+ m_iLength--;
+ pTemp->NextIcon = NULL;
+ }
+ else
+ {
+ IconElement* pElement = pTemp->NextIcon;
+ pTemp->NextIcon = pTemp->NextIcon->NextIcon;
+ delete pElement;
+ m_iLength--;
+ pElement = NULL;
+ }
+
+ continue;
+ }
+
+ pTemp = pTemp->NextIcon;
+ }
+}
+
+FX_BOOL Document::addIcon(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 2)return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CFX_WideString swIconName = params[0].operator CFX_WideString();
+
+ JSFXObject pJSIcon = (JSFXObject)params[1];
+ if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) return FALSE;
+
+ CJS_EmbedObj* pEmbedObj = ((CJS_Object*)params[1])->GetEmbedObject();
+ if (!pEmbedObj)return FALSE;
+ 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;
+}
+
+FX_BOOL Document::icons(OBJ_PROP_PARAMS)
+{
+ if (vp.IsSetting())
+ return FALSE;
+
+ if (!m_pIconTree)
+ {
+ vp.SetNull();
+ return TRUE;
+ }
+
+ CJS_Array Icons(m_isolate);
+ IconElement* pIconElement = NULL;
+ int iIconTreeLength = m_pIconTree->GetLength();
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+
+ 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;
+
+ CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
+ if (!pJS_Icon) 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));
+ }
+
+ vp << Icons;
+ return TRUE;
+}
+
+FX_BOOL Document::getIcon(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 1)return FALSE;
+ if(!m_pIconTree)
+ return FALSE;
+ CFX_WideString swIconName = params[0].operator CFX_WideString();
+ int iIconCounts = m_pIconTree->GetLength();
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+
+ 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;
+
+ CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
+ if (!pJS_Icon) return FALSE;
+
+ Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+ if (!pIcon)return FALSE;
+
+ pIcon->SetIconName(swIconName);
+ pIcon->SetStream(pRetIcon->GetStream());
+ vRet = pJS_Icon;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL Document::removeIcon(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 1)return FALSE;
+ if(!m_pIconTree)
+ return FALSE;
+ CFX_WideString swIconName = params[0].operator CFX_WideString();
+#ifndef FOXIT_CHROME_BUILD
+ m_pIconTree->DeleteIconElement(swIconName);
+#endif
+ return TRUE;
+}
+
+FX_BOOL Document::createDataObject(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ CFX_WideString swName = L"";
+ CFX_ByteString sbName = "";
+ CFX_WideString swValue = L"";
+ CFX_WideString swMIMEType = L"";
+ CFX_WideString swCryptFilter = L"";
+ CFX_ByteString sbFileValue = "";
+
+ int iParamSize = params.size();
+ for (int i = 0; i < iParamSize; i++)
+ {
+ if (i == 0)
+ swName = params[0];
+ if (i == 1)
+ swValue = params[1];
+ if (i == 2)
+ swMIMEType = params[2];
+ if (i == 3)
+ swCryptFilter = params[4];
+ }
+
+ FILE* pFile = NULL;
+
+ //CFileStatus fileStatus;
+ const int BUFSIZE = 17;
+ FX_BYTE buf[BUFSIZE];
+ FX_BYTE *pBuffer = NULL;
+ char* pBuf = NULL;
+ int nFileSize = 0;
+ sbFileValue = CFX_ByteString::FromUnicode(swValue);
+ sbName = CFX_ByteString::FromUnicode(swName);
+ int iBufLength = sbFileValue.GetLength();
+ pBuf = (char*)malloc(sizeof(char) * iBufLength);
+ pBuf = sbFileValue.GetBuffer(iBufLength);
+
+ if ( NULL == (pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "wb+" )) )
+ {
+ return FALSE;
+ }
+
+ fwrite( pBuf, sizeof(char), iBufLength, pFile );
+ fclose( pFile );
+ pFile = NULL;
+
+ pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "rb+" );
+ fseek( pFile, 0, SEEK_END );
+ nFileSize = ftell( pFile );
+
+ pBuffer = new FX_BYTE[nFileSize];
+ fseek( pFile, 0, SEEK_SET );
+ size_t s = fread( pBuffer, sizeof(char), nFileSize, pFile );
+ if(s == 0)
+ {
+ delete[] pBuffer;
+ return FALSE;
+ }
+
+ CRYPT_MD5Generate(pBuffer, nFileSize, buf);
+ buf[BUFSIZE - 1] = 0;
+ CFX_WideString csCheckSum((FX_LPCWSTR)buf, 16);
+ delete[] pBuffer;
+
+ return TRUE;
+}
+
+FX_BOOL Document::media(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::calculateNow(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ 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;
+}
+
+FX_BOOL Document::Collab(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS)
+{
+ //if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
+ int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0;
+ bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true;
+
+ CPDF_Document* pDocument = m_pDocument->GetDocument();
+ if (!pDocument) return FALSE;
+
+ if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
+ {
+ //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
+ if (!pPageDict) return FALSE;
+
+ CPDF_Page page;
+ page.Load(pDocument, pPageDict);
+ page.StartParse();
+ page.ParseContent();
+
+ FX_POSITION pos = page.GetFirstObjectPosition();
+
+ int nWords = 0;
+
+ CFX_WideString swRet;
+
+ 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;
+ }
+
+ nWords += nObjWords;
+ }
+ }
+ }
+
+ if (bStrip)
+ {
+ swRet.TrimLeft();
+ swRet.TrimRight();
+ }
+
+ vRet = swRet;
+ return TRUE;
+}
+
+FX_BOOL Document::getPageNthWordQuads(OBJ_METHOD_PARAMS)
+{
+ //if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ return FALSE;
+}
+
+FX_BOOL Document::getPageNumWords(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
+
+ CPDF_Document* pDocument = m_pDocument->GetDocument();
+ ASSERT(pDocument != NULL);
+
+ if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
+ {
+ //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
+ if (!pPageDict) return FALSE;
+
+ CPDF_Page page;
+ page.Load(pDocument, pPageDict);
+ page.StartParse();
+ page.ParseContent();
+
+ FX_POSITION pos = page.GetFirstObjectPosition();
+
+ 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);
+ }
+ }
+ }
+
+ vRet = nWords;
+
+ return TRUE;
+}
+
+FX_BOOL Document::getPrintParams(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+ JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"));
+ //not implemented yet.
+ vRet = pRetObj;
+
+ return TRUE;
+}
+
+#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
+
+int Document::CountWords(CPDF_TextObject* pTextObj)
+{
+ if (!pTextObj) return 0;
+
+ int nWords = 0;
+
+ CPDF_Font* pFont = pTextObj->GetFont();
+ if (!pFont) return 0;
+
+ FX_BOOL bIsLatin = FALSE;
+
+ 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);
+
+ FX_WORD unicode = 0;
+ if (swUnicode.GetLength() > 0)
+ unicode = swUnicode[0];
+
+ if (ISLATINWORD(unicode) && bIsLatin)
+ continue;
+
+ bIsLatin = ISLATINWORD(unicode);
+ if (unicode != 0x20)
+ nWords++;
+ }
+
+ return nWords;
+}
+
+CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex)
+{
+ ASSERT(pTextObj != NULL);
+
+ CFX_WideString swRet;
+
+ CPDF_Font* pFont = pTextObj->GetFont();
+ if (!pFont) return L"";
+
+ int nWords = 0;
+ FX_BOOL bIsLatin = FALSE;
+
+ 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);
+
+ FX_WORD unicode = 0;
+ if (swUnicode.GetLength() > 0)
+ unicode = swUnicode[0];
+
+ if (ISLATINWORD(unicode) && bIsLatin)
+ {
+ }
+ else
+ {
+ bIsLatin = ISLATINWORD(unicode);
+ if (unicode != 0x20)
+ nWords++;
+ }
+
+ if (nWords-1 == nWordIndex)
+ swRet += unicode;
+ }
+
+ return swRet;
+}
+
+FX_BOOL Document::zoom(OBJ_PROP_PARAMS)
+{
+
+ return TRUE;
+}
+
+/**
+(none, NoVary)
+(fitP, FitPage)
+(fitW, FitWidth)
+(fitH, FitHeight)
+(fitV, FitVisibleWidth)
+(pref, Preferred)
+(refW, ReflowWidth)
+*/
+
+FX_BOOL Document::zoomType(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::deletePages(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ v8::Isolate* isolate = GetIsolate(cc);
+// if (pEnv->GetAppName().Compare(PHANTOM) != 0)
+// return TRUE;
+
+ //if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
+
+ int iSize = params.size();
+
+ int nStart = 0;
+ int nEnd = 0;
+
+ if (iSize < 1)
+ {
+ }
+ else if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
+ nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
+ nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+ }
+ else
+ {
+ nStart = (int)params[0];
+ }
+ }
+ else
+ {
+ nStart = (int)params[0];
+ nEnd = (int)params[1];
+ }
+
+ int nTotal = m_pDocument->GetPageCount();
+
+ if (nStart < 0) nStart = 0;
+ if (nStart >= nTotal) nStart = nTotal - 1;
+
+ if (nEnd < 0) nEnd = 0;
+ if (nEnd >= nTotal) nEnd = nTotal - 1;
+
+ if (nEnd < nStart) nEnd = nStart;
+
+
+
+#ifndef FOXIT_CHROME_BUILD
+ return m_pDocument->DeletePages(nStart, nEnd - nStart + 1);
+#else
+ return TRUE;
+#endif
+}
+
+FX_BOOL Document::extractPages(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT)) return FALSE;
+
+ int iSize = params.size();
+
+ int nTotal = m_pDocument->GetPageCount();
+ int nStart = 0;
+ int nEnd = nTotal - 1;
+
+ CFX_WideString swFilePath;
+
+ if (iSize < 1)
+ {
+ }
+ else if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
+ nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
+ nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
+ swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+ }
+ else
+ {
+ nStart = (int)params[0];
+ }
+ }
+ else if (iSize == 2)
+ {
+ nStart = (int)params[0];
+ nEnd = (int)params[1];
+ }
+ else
+ {
+ nStart = (int)params[0];
+ nEnd = (int)params[1];
+ swFilePath = params[2].operator CFX_WideString();
+ }
+
+ if (nEnd < nStart)
+ nEnd = nStart;
+
+ CPDF_Document *pNewDoc = new CPDF_Document;
+ pNewDoc->CreateNewDoc();
+
+ CFX_WordArray array;
+ for (int i=nStart; i<=nEnd; i++)
+ array.Add(i);
+
+// m_pDocument->ExtractPages(array, pNewDoc);
+
+ if (swFilePath.IsEmpty())
+ {
+
+ }
+ else
+ {
+ swFilePath = app::PDFPathToSysPath(swFilePath);
+ CPDF_Creator PDFCreater(pNewDoc);
+ PDFCreater.Create(swFilePath);
+ delete pNewDoc;
+// pEnv->OpenDocument(swFilePath);
+ vRet.SetNull();
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Document::insertPages(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
+
+ int iSize = params.size();
+
+ int nStart = 0;
+ int nEnd = 0;
+ int nPage = 0;
+
+ CFX_WideString swFilePath;
+
+ if (iSize < 1)
+ {
+ }
+ else if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");
+ nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
+ swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
+ nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
+ nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+ }
+ else
+ {
+ nPage = (int)params[0];
+ }
+ }
+ else
+ {
+ nPage = (int)params[0];
+
+ if (iSize >= 2)
+ swFilePath = params[1].operator CFX_WideString();
+
+ if (iSize >= 3)
+ nStart = (int)params[2];
+
+ if (iSize >= 4)
+ nEnd = (int)params[3];
+ }
+
+ nPage++;
+
+ if (nPage < 0)
+ nPage = 0;
+
+ if (nPage > m_pDocument->GetPageCount())
+ nPage = m_pDocument->GetPageCount();
+
+ if (swFilePath.IsEmpty()) return FALSE;
+
+ swFilePath = app::PDFPathToSysPath(swFilePath);
+
+ CPDF_Parser pdfParser;
+ pdfParser.StartParse(swFilePath, FALSE);
+ CPDF_Document* pSrcDoc = pdfParser.GetDocument();
+
+ if (!pSrcDoc)
+ {
+ pdfParser.CloseParser();
+ return FALSE;
+ }
+
+ int nTotal = pSrcDoc->GetPageCount();
+
+ if (nStart < 0) nStart = 0;
+ if (nStart >= nTotal) nStart = nTotal - 1;
+
+ if (nEnd < 0) nEnd = 0;
+ if (nEnd >= nTotal) nEnd = nTotal - 1;
+
+ if (nEnd < nStart) nEnd = nStart;
+
+ CFX_WordArray array;
+ for (int i=nStart; i<=nEnd; i++)
+ array.Add(i);
+
+// m_pDocument->InsertPages(nPage, pSrcDoc, array);
+
+ pdfParser.CloseParser();
+
+ return TRUE;
+}
+
+FX_BOOL Document::replacePages(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
+
+ int iSize = params.size();
+
+ int nStart = -1;
+ int nEnd = -1;
+ int nPage = 0;
+
+ CFX_WideString swFilePath;
+
+ if (iSize < 1)
+ {
+ }
+ else if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");
+ nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
+ swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
+ nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
+ nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+ }
+ else
+ {
+ nPage = (int)params[0];
+ }
+ }
+ else
+ {
+ nPage = (int)params[0];
+
+ if (iSize >= 2)
+ swFilePath = params[1].operator CFX_WideString();
+
+ if (iSize >= 3)
+ nStart = (int)params[2];
+
+ if (iSize >= 4)
+ nEnd = (int)params[3];
+ }
+
+ if (nPage < 0)
+ nPage = 0;
+
+ if (nPage >= m_pDocument->GetPageCount())
+ nPage = m_pDocument->GetPageCount() - 1;
+
+ if (swFilePath.IsEmpty()) return FALSE;
+
+ swFilePath = app::PDFPathToSysPath(swFilePath);
+
+ CPDF_Parser pdfParser;
+ pdfParser.StartParse(swFilePath, FALSE);
+ CPDF_Document* pSrcDoc = pdfParser.GetDocument();
+
+ if (!pSrcDoc)
+ {
+ pdfParser.CloseParser();
+ return FALSE;
+ }
+
+ int nTotal = pSrcDoc->GetPageCount();
+
+ if (nStart < 0)
+ {
+ if (nEnd < 0)
+ {
+ nStart = 0;
+ nEnd = nTotal - 1;
+ }
+ else
+ {
+ nStart = 0;
+ }
+ }
+ else
+ {
+ if (nEnd < 0)
+ {
+ nEnd = nStart;
+ }
+ else
+ {
+ if (nStart >= nTotal) nStart = nTotal - 1;
+ if (nEnd >= nTotal) nEnd = nTotal - 1;
+
+ if (nEnd < nStart) nEnd = nStart;
+ }
+ }
+
+ CFX_WordArray array;
+ for (int i=nStart; i<=nEnd; i++)
+ array.Add(i);
+
+// m_pDocument->ReplacePages(nPage, pSrcDoc, array);
+
+ pdfParser.CloseParser();
+
+ return TRUE;
+}
+
+FX_BOOL Document::getURL(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+
+ return TRUE;
+}
+
+void Document::AddDelayData(CJS_DelayData* pData)
+{
+ m_DelayData.Add(pData);
+}
+
+void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex)
+{
+ CFX_DWordArray DelArray;
+
+ 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)
+ {
+ Field::DoDelay(m_pDocument, pData);
+ delete pData;
+ m_DelayData.SetAt(i, NULL);
+ DelArray.Add(i);
+ }
+ }
+ }
+
+ for (int j=DelArray.GetSize()-1; j>=0; j--)
+ {
+ m_DelayData.RemoveAt(DelArray[j]);
+ }
+}
+
+void Document::AddDelayAnnotData(CJS_AnnotObj *pData)
+{
+ m_DelayAnnotData.Add(pData);
+}
+
+void Document::DoAnnotDelay()
+{
+ CFX_DWordArray DelArray;
+
+ for (int j=DelArray.GetSize()-1; j>=0; j--)
+ {
+ m_DelayData.RemoveAt(DelArray[j]);
+ }
+}
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index 44a744f1d1..f5f9bf0539 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -1,4128 +1,4128 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Field.h"
-#include "../../include/javascript/JS_EventHandler.h"
-//#include "../include/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/color.h"
-#include "../../include/javascript/PublicMethods.h"
-#include "../../include/javascript/Icon.h"
-
-
-/* ---------------------- Field ---------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Field)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Field)
- JS_STATIC_PROP_ENTRY(alignment)
- JS_STATIC_PROP_ENTRY(borderStyle)
- JS_STATIC_PROP_ENTRY(buttonAlignX)
- JS_STATIC_PROP_ENTRY(buttonAlignY)
- JS_STATIC_PROP_ENTRY(buttonFitBounds)
- JS_STATIC_PROP_ENTRY(buttonPosition)
- JS_STATIC_PROP_ENTRY(buttonScaleHow)
- JS_STATIC_PROP_ENTRY(buttonScaleWhen)
- JS_STATIC_PROP_ENTRY(calcOrderIndex)
- JS_STATIC_PROP_ENTRY(charLimit)
- JS_STATIC_PROP_ENTRY(comb)
- JS_STATIC_PROP_ENTRY(commitOnSelChange)
- JS_STATIC_PROP_ENTRY(currentValueIndices)
- JS_STATIC_PROP_ENTRY(defaultStyle)
- JS_STATIC_PROP_ENTRY(defaultValue)
- JS_STATIC_PROP_ENTRY(doNotScroll)
- JS_STATIC_PROP_ENTRY(doNotSpellCheck)
- JS_STATIC_PROP_ENTRY(delay)
- JS_STATIC_PROP_ENTRY(display)
- JS_STATIC_PROP_ENTRY(doc)
- JS_STATIC_PROP_ENTRY(editable)
- JS_STATIC_PROP_ENTRY(exportValues)
- JS_STATIC_PROP_ENTRY(hidden)
- JS_STATIC_PROP_ENTRY(fileSelect)
- JS_STATIC_PROP_ENTRY(fillColor)
- JS_STATIC_PROP_ENTRY(lineWidth)
- JS_STATIC_PROP_ENTRY(highlight)
- JS_STATIC_PROP_ENTRY(multiline)
- JS_STATIC_PROP_ENTRY(multipleSelection)
- JS_STATIC_PROP_ENTRY(name)
- JS_STATIC_PROP_ENTRY(numItems)
- JS_STATIC_PROP_ENTRY(page)
- JS_STATIC_PROP_ENTRY(password)
- JS_STATIC_PROP_ENTRY(print)
- JS_STATIC_PROP_ENTRY(radiosInUnison)
- JS_STATIC_PROP_ENTRY(readonly)
- JS_STATIC_PROP_ENTRY(rect)
- JS_STATIC_PROP_ENTRY(required)
- JS_STATIC_PROP_ENTRY(richText)
- JS_STATIC_PROP_ENTRY(richValue)
- JS_STATIC_PROP_ENTRY(rotation)
- JS_STATIC_PROP_ENTRY(strokeColor)
- JS_STATIC_PROP_ENTRY(style)
- JS_STATIC_PROP_ENTRY(submitName)
- JS_STATIC_PROP_ENTRY(textColor)
- JS_STATIC_PROP_ENTRY(textFont)
- JS_STATIC_PROP_ENTRY(textSize)
- JS_STATIC_PROP_ENTRY(type)
- JS_STATIC_PROP_ENTRY(userName)
- JS_STATIC_PROP_ENTRY(value)
- JS_STATIC_PROP_ENTRY(valueAsString)
- JS_STATIC_PROP_ENTRY(source)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Field)
- JS_STATIC_METHOD_ENTRY(browseForFileToSubmit, 0)
- JS_STATIC_METHOD_ENTRY(buttonGetCaption, 1)
- JS_STATIC_METHOD_ENTRY(buttonGetIcon, 1)
- JS_STATIC_METHOD_ENTRY(buttonImportIcon, 0)
- JS_STATIC_METHOD_ENTRY(buttonSetCaption, 2)
- JS_STATIC_METHOD_ENTRY(buttonSetIcon, 2)
- JS_STATIC_METHOD_ENTRY(checkThisBox, 2)
- JS_STATIC_METHOD_ENTRY(clearItems, 0)
- JS_STATIC_METHOD_ENTRY(defaultIsChecked, 2)
- JS_STATIC_METHOD_ENTRY(deleteItemAt, 1)
- JS_STATIC_METHOD_ENTRY(getArray , 0)
- JS_STATIC_METHOD_ENTRY(getItemAt, 0)
- JS_STATIC_METHOD_ENTRY(getLock, 0)
- JS_STATIC_METHOD_ENTRY(insertItemAt, 0)
- JS_STATIC_METHOD_ENTRY(isBoxChecked, 1)
- JS_STATIC_METHOD_ENTRY(isDefaultChecked, 1)
- JS_STATIC_METHOD_ENTRY(setAction, 2)
- JS_STATIC_METHOD_ENTRY(setFocus, 0)
- JS_STATIC_METHOD_ENTRY(setItems, 1)
- JS_STATIC_METHOD_ENTRY(setLock, 0)
- JS_STATIC_METHOD_ENTRY(signatureGetModifications, 0)
- JS_STATIC_METHOD_ENTRY(signatureGetSeedValue, 0)
- JS_STATIC_METHOD_ENTRY(signatureInfo, 0)
- JS_STATIC_METHOD_ENTRY(signatureSetSeedValue, 0)
- JS_STATIC_METHOD_ENTRY(signatureSign, 0)
- JS_STATIC_METHOD_ENTRY(signatureValidate, 0)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Field, Field)
-
-FX_BOOL CJS_Field::InitInstance(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- Field* pField = (Field*)GetEmbedObject();
- ASSERT(pField != NULL);
-
- pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
-
- return TRUE;
-};
-
-Field::Field(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject),
- m_pJSDoc(NULL),
- m_pDocument(NULL),
- m_nFormControlIndex(-1),
- m_bCanSet(FALSE),
- m_bDelay(FALSE),
- m_isolate(NULL)
-{
-}
-
-Field::~Field()
-{
-}
-
-//note: iControlNo = -1, means not a widget.
-void Field::ParseFieldName(const std::wstring &strFieldNameParsed,std::wstring &strFieldName,int & iControlNo)
-{
- int iStart = strFieldNameParsed.find_last_of(L'.');
- if (iStart == -1)
- {
- strFieldName = strFieldNameParsed;
- iControlNo = -1;
- return;
- }
- std::wstring suffixal = strFieldNameParsed.substr(iStart+1);
- iControlNo = FXSYS_wtoi((FX_LPCWSTR)suffixal.c_str());
- if (iControlNo == 0)
- {
- int iStart;
- while((iStart = suffixal.find_last_of(L" ")) != -1)
- {
- suffixal.erase(iStart,1);
- }
-
- if (suffixal.compare(L"0") != 0)
- {
- strFieldName = strFieldNameParsed;
- iControlNo = -1;
- return;
- }
-
- }
- strFieldName = strFieldNameParsed.substr(0,iStart);
-}
-
-FX_BOOL Field::AttachField(Document* pDocument, const CFX_WideString& csFieldName)
-{
- ASSERT(pDocument != NULL);
- m_pJSDoc = pDocument;
-
- m_pDocument = pDocument->GetReaderDoc();
- ASSERT(m_pDocument != NULL);
-
- m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_MODIFY);
-
- CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
- ASSERT(pRDInterForm != NULL);
-
- CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_WideString swFieldNameTemp = csFieldName;
- swFieldNameTemp.Replace((FX_LPCWSTR)L"..", (FX_LPCWSTR)L".");
-
- if (pInterForm->CountFields(swFieldNameTemp) <= 0)
- {
- std::wstring strFieldName;
- int iControlNo = -1;
- ParseFieldName((wchar_t*)(FX_LPCWSTR)swFieldNameTemp, strFieldName, iControlNo);
- if (iControlNo == -1) return FALSE;
-
- m_FieldName = strFieldName.c_str();
- m_nFormControlIndex = iControlNo;
- return TRUE;
- }
-
- m_FieldName = swFieldNameTemp;
- m_nFormControlIndex = -1;
-
- return TRUE;
-}
-
-void Field::GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
- ASSERT(pReaderInterForm != NULL);
-
- CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- ASSERT(FieldArray.GetSize() == 0);
-
- for (int i=0,sz=pInterForm->CountFields(csFieldName); i<sz; i++)
- {
- if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
- FieldArray.Add((void*)pFormField);
- }
-}
-
-void Field::GetFormFields(const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
-{
- ASSERT(m_pDocument != NULL);
-
- Field::GetFormFields(m_pDocument, csFieldName, FieldArray);
-}
-
-void Field::UpdateFormField(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
- FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
-{
- ASSERT(pDocument != NULL);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray widgets;
- pInterForm->GetWidgets(pFormField, widgets);
-
- if (bResetAP)
- {
- int nFieldType = pFormField->GetFieldType();
- if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
- {
- for (int i=0,sz=widgets.GetSize(); i<sz; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
- ASSERT(pWidget != NULL);
-
- FX_BOOL bFormated = FALSE;
- CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
- if (bFormated)
- pWidget->ResetAppearance(sValue, FALSE);
- else
- pWidget->ResetAppearance(NULL, FALSE);
- }
- }
- else
- {
- for (int i=0,sz=widgets.GetSize(); i<sz; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
- ASSERT(pWidget != NULL);
-
- pWidget->ResetAppearance(NULL, FALSE);
- }
- }
- }
-
- if (bRefresh)
- {
- for (int i=0,sz=widgets.GetSize(); i<sz; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
- ASSERT(pWidget != NULL);
-
- CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
- CPDFSDK_Document* pDoc = pInterForm->GetDocument();
-// CReader_Page* pPage = pWidget->GetPage();
- ASSERT(pDoc != NULL);
- pDoc->UpdateAllViews(NULL, pWidget);
- }
- }
-
- if (bChangeMark)
- pDocument->SetChangeMark();
-}
-
-void Field::UpdateFormControl(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl,
- FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
-{
- ASSERT(pDocument != NULL);
- ASSERT(pFormControl != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
-
- if (pWidget)
- {
- if (bResetAP)
- {
- int nFieldType = pWidget->GetFieldType();
- if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
- {
- FX_BOOL bFormated = FALSE;
- CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
- if (bFormated)
- pWidget->ResetAppearance(sValue, FALSE);
- else
- pWidget->ResetAppearance(NULL, FALSE);
- }
- else
- {
- pWidget->ResetAppearance(NULL, FALSE);
- }
- }
-
- if (bRefresh)
- {
- CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
- CPDFSDK_Document* pDoc = pInterForm->GetDocument();
- ASSERT(pDoc != NULL);
- pDoc->UpdateAllViews(NULL, pWidget);
- }
-
- }
-
- if (bChangeMark)
- pDocument->SetChangeMark();
-}
-
-CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl)
-{
- ASSERT(pDocument != NULL);
- ASSERT(pFormControl != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- return pInterForm->GetWidget(pFormControl);
-}
-
-FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel)
-{
- ASSERT(pFormField != NULL);
-
- for (int i=0,sz = pFormField->CountOptions(); i < sz; i++)
- {
- if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
- return TRUE;
- }
-
- return FALSE;
-}
-
-CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField)
-{
- ASSERT(pFormField != NULL);
- if(!pFormField->CountControls() || m_nFormControlIndex>=pFormField->CountControls()) return NULL;
-
- if (m_nFormControlIndex<0)
- return pFormField->GetControl(0);
- else
- return pFormField->GetControl(m_nFormControlIndex);
-}
-
-/* ---------------------------------------- property ---------------------------------------- */
-
-FX_BOOL Field::alignment(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString alignStr;
- vp >> alignStr;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_ALIGNMENT, alignStr);
- }
- else
- {
- Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex, alignStr);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- switch (pFormControl->GetControlAlignment())
- {
- case 1:
- vp << (FX_LPCWSTR)L"center";
- break;
- case 0:
- vp << (FX_LPCWSTR)L"left";
- break;
- case 2:
- vp << (FX_LPCWSTR)L"right";
- break;
- default:
- vp << (FX_LPCWSTR)L"";
- }
- }
-
- return TRUE;
-}
-
-void Field::SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_ByteString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::borderStyle(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString strType = "";
- vp >> strType;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_BORDERSTYLE, strType);
- }
- else
- {
- Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex, strType);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- if (!pFormField) return FALSE;
-
- CPDFSDK_Widget* pWidget = GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
- if (!pWidget) return FALSE;
-
- int nBorderstyle = pWidget->GetBorderStyle();
-
- switch (nBorderstyle)
- {
- case BBS_SOLID:
- vp << (FX_LPCWSTR)L"solid";
- break;
- case BBS_DASH:
- vp << (FX_LPCWSTR)L"dashed";
- break;
- case BBS_BEVELED:
- vp << (FX_LPCWSTR)L"beveled";
- break;
- case BBS_INSET:
- vp << (FX_LPCWSTR)L"inset";
- break;
- case BBS_UNDERLINE:
- vp << (FX_LPCWSTR)L"underline";
- break;
- default:
- vp << (FX_LPCWSTR)L"";
- break;
- }
- }
-
- return TRUE;
-}
-
-void Field::SetBorderStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_ByteString& string)
-{
- ASSERT(pDocument != NULL);
-
- int nBorderStyle = 0;
-
- if (string == "solid")
- nBorderStyle = BBS_SOLID;
- else if (string == "beveled")
- nBorderStyle = BBS_BEVELED;
- else if (string == "dashed")
- nBorderStyle = BBS_DASH;
- else if (string == "inset")
- nBorderStyle = BBS_INSET;
- else if (string == "underline")
- nBorderStyle = BBS_UNDERLINE;
- else return;
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
- {
- if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormField->GetControl(j)))
- {
- if (pWidget->GetBorderStyle() != nBorderStyle)
- {
- pWidget->SetBorderStyle(nBorderStyle);
- bSet = TRUE;
- }
- }
- }
- if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl))
- {
- if (pWidget->GetBorderStyle() != nBorderStyle)
- {
- pWidget->SetBorderStyle(nBorderStyle);
- UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::buttonAlignX(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONALIGNX, nVP);
- }
- else
- {
- Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
-
- FX_FLOAT fLeft,fBottom;
- IconFit.GetIconPosition(fLeft,fBottom);
-
- vp << (FX_INT32)fLeft;
- }
-
- return TRUE;
-}
-
-void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonAlignY(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONALIGNY, nVP);
- }
- else
- {
- Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
-
- FX_FLOAT fLeft,fBottom;
- IconFit.GetIconPosition(fLeft,fBottom);
-
- vp << (FX_INT32)fBottom;
- }
-
- return TRUE;
-}
-
-void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonFitBounds(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
- }
- else
- {
- Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
- vp << IconFit.GetFittingBounds();
- }
-
- return TRUE;
-}
-
-void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonPosition(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONPOSITION, nVP);
- }
- else
- {
- Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- vp << pFormControl->GetTextPosition();
- }
- return TRUE;
-}
-
-void Field::SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonScaleHow(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
- }
- else
- {
- Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
- if (IconFit.IsProportionalScale())
- vp << (FX_INT32)0;
- else
- vp << (FX_INT32)1;
- }
-
- return TRUE;
-}
-
-void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonScaleWhen(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
- }
- else
- {
- Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*) FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl) return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
- int ScaleM = IconFit.GetScaleMethod();
- switch (ScaleM)
- {
- case CPDF_IconFit::Always :
- vp << (FX_INT32) CPDF_IconFit::Always;
- break;
- case CPDF_IconFit::Bigger :
- vp << (FX_INT32) CPDF_IconFit::Bigger;
- break;
- case CPDF_IconFit::Never :
- vp << (FX_INT32) CPDF_IconFit::Never;
- break;
- case CPDF_IconFit::Smaller :
- vp << (FX_INT32) CPDF_IconFit::Smaller;
- break;
- }
- }
-
- return TRUE;
-}
-
-void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::calcOrderIndex(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_CALCORDERINDEX, nVP);
- }
- else
- {
- Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
- ASSERT(pRDInterForm != NULL);
-
- CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- vp << (FX_INT32)pInterForm->FindFieldInCalculationOrder(pFormField);
- }
-
- return TRUE;
-}
-
-void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::charLimit(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_CHARLIMIT, nVP);
- }
- else
- {
- Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- vp << (FX_INT32)pFormField->GetMaxLen();
- }
- return TRUE;
-}
-
-void Field::SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::comb(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_COMB, bVP);
- }
- else
- {
- Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::commitOnSelChange(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
- }
- else
- {
- Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::currentValueIndices(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_DWordArray array;
-
- if (vp.GetType() == VT_number)
- {
- int iSelecting = 0;
- vp >> iSelecting;
- array.Add(iSelecting);
- }
- else if (vp.IsArrayObject())
- {
- CJS_Array SelArray(m_isolate);
- CJS_Value SelValue(m_isolate);
- int iSelecting;
- vp >> SelArray;
- for (int i=0,sz=SelArray.GetLength(); i<sz; i++)
- {
- SelArray.GetElement(i,SelValue);
- iSelecting = (FX_INT32)SelValue;
- array.Add(iSelecting);
- }
- }
-
- if (m_bDelay)
- {
- AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
- }
- else
- {
- Field::SetCurrentValueIndices(m_pDocument, m_FieldName, m_nFormControlIndex, array);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
-
- if (pFormField->CountSelectedItems() == 1)
- vp << pFormField->GetSelectedIndex(0);
- else if (pFormField->CountSelectedItems() > 1)
- {
- CJS_Array SelArray(m_isolate);
- for (int i=0,sz=pFormField->CountSelectedItems(); i<sz; i++)
- {
- SelArray.SetElement(i, CJS_Value(m_isolate,pFormField->GetSelectedIndex(i)));
- }
- vp << SelArray;
- }
- else
- vp << -1;
- }
-
- return TRUE;
-}
-
-void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_DWordArray& array)
-{
- ASSERT(pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- int nFieldType = pFormField->GetFieldType();
- if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX)
- {
- FX_DWORD dwFieldFlags = pFormField->GetFieldFlags();
- pFormField->ClearSelection(TRUE);
-
- for (int i=0,sz=array.GetSize(); i<sz; i++)
- {
- if (i>0 && !(dwFieldFlags & (1<<21)))
- {
- break;
- }
-
- int iSelecting = (FX_INT32)array.GetAt(i);
- if (iSelecting < pFormField->CountOptions() && !pFormField->IsItemSelected(iSelecting))
- pFormField->SetItemSelection(iSelecting, TRUE);
-
- }
- UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- }
-}
-
-FX_BOOL Field::defaultStyle(OBJ_PROP_PARAMS)
-{
- // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT);
- return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- ;
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
-{
- //Not supported.
-}
-
-FX_BOOL Field::defaultValue(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_WideString WideStr;
- vp >> WideStr;
-
- if (m_bDelay)
- {
- AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
- }
- else
- {
- Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex, WideStr);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
- pFormField->GetFieldType() == FIELDTYPE_SIGNATURE)
- return FALSE;
-
- vp << pFormField->GetDefaultValue();
- }
- return TRUE;
-}
-
-void Field::SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_WideString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::doNotScroll(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_DONOTSCROLL, bVP);
- }
- else
- {
- Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::doNotSpellCheck(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
- pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetDelay(FX_BOOL bDelay)
-{
- m_bDelay = bDelay;
-
- if (!m_bDelay)
- {
- if (m_pJSDoc)
- m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
- }
-}
-
-FX_BOOL Field::delay(OBJ_PROP_PARAMS)
-{
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- SetDelay(bVP);
- }
- else
- {
- vp << m_bDelay;
- }
- return TRUE;
-}
-
-FX_BOOL Field::display(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_DISPLAY, nVP);
- }
- else
- {
- Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
- if (!pWidget)return FALSE;
-
- FX_DWORD dwFlag = pWidget->GetFlags();
-
- if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag)
- {
- vp << (FX_INT32)1;
- }
- else
- {
- if (ANNOTFLAG_PRINT & dwFlag)
- {
- if (ANNOTFLAG_NOVIEW & dwFlag)
- {
- vp << (FX_INT32)3;
- }
- else
- {
- vp << (FX_INT32)0;
- }
- }
- else
- {
- vp << (FX_INT32)2;
- }
- }
- }
-
- return TRUE;
-}
-
-void Field::SetDisplay(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
- {
- CPDF_FormControl* pFormControl = pFormField->GetControl(j);
- ASSERT(pFormControl != NULL);
-
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- FX_DWORD dwFlag = pWidget->GetFlags();
- switch (number)
- {
- case 0:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= ANNOTFLAG_PRINT;
- break;
- case 1:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- break;
- case 2:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_PRINT);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- break;
- case 3:
- dwFlag |= ANNOTFLAG_NOVIEW;
- dwFlag |= ANNOTFLAG_PRINT;
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- break;
- }
-
- if (dwFlag != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlag);
- bSet = TRUE;
- }
- }
- }
-
- if (bSet) UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
-
- FX_DWORD dwFlag = pWidget->GetFlags();
- switch (number)
- {
- case 0:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= ANNOTFLAG_PRINT;
- break;
- case 1:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- break;
- case 2:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_PRINT);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- break;
- case 3:
- dwFlag |= ANNOTFLAG_NOVIEW;
- dwFlag |= ANNOTFLAG_PRINT;
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- break;
- }
- if (dwFlag != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlag);
- UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::doc(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pJSDoc != NULL);
-
- if (!vp.IsGetting())return FALSE;
-
- vp << (CJS_Object*)(*m_pJSDoc);
-
- return TRUE;
-}
-
-FX_BOOL Field::editable(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::exportValues(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
- pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
- return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
- if (!vp.IsArrayObject())return FALSE;
- }
- else
- {
- CJS_Array ExportValusArray(m_isolate);
-
- if (m_nFormControlIndex < 0)
- {
- for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
- {
- CPDF_FormControl* pFormControl = pFormField->GetControl(i);
- ASSERT(pFormControl != NULL);
-
- ExportValusArray.SetElement(i, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
- }
- }
- else
- {
- if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
- CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex);
- if (!pFormControl) return FALSE;
-
- ExportValusArray.SetElement(0, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
- }
-
- vp << ExportValusArray;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::fileSelect(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::fillColor(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CJS_Array crArray(m_isolate);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
- if (!vp.IsArrayObject()) return FALSE;
-
- vp >> crArray;
-
- CPWL_Color color;
- color::ConvertArrayToPWLColor(crArray, color);
-
- if (m_bDelay)
- {
- AddDelay_Color(FP_FILLCOLOR, color);
- }
- else
- {
- Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
- }
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- int iColorType;
- pFormControl->GetBackgroundColor(iColorType);
-
- CPWL_Color color;
-
- if (iColorType == COLORTYPE_TRANSPARENT)
- {
- color = CPWL_Color(COLORTYPE_TRANSPARENT);
- }
- else if (iColorType == COLORTYPE_GRAY)
- {
- color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
- }
- else if (iColorType == COLORTYPE_RGB)
- {
- color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
- pFormControl->GetOriginalBackgroundColor(1),
- pFormControl->GetOriginalBackgroundColor(2));
- }
- else if (iColorType == COLORTYPE_CMYK)
- {
- color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
- pFormControl->GetOriginalBackgroundColor(1),
- pFormControl->GetOriginalBackgroundColor(2),
- pFormControl->GetOriginalBackgroundColor(3));
- }
- else
- return FALSE;
-
- color::ConvertPWLColorToArray(color, crArray);
- vp << crArray;
- }
-
- return TRUE;
-}
-
-void Field::SetFillColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
-{
- //Not supported.
-}
-
-FX_BOOL Field::hidden(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_HIDDEN, bVP);
- }
- else
- {
- Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
- if (!pWidget) return FALSE;
-
- FX_DWORD dwFlags = pWidget->GetFlags();
-
- if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
- {
- vp << true;
- }
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetHidden(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
- {
- FX_DWORD dwFlags = pWidget->GetFlags();
-
- if (b)
- {
- dwFlags &= (~ANNOTFLAG_INVISIBLE);
- dwFlags &= (~ANNOTFLAG_NOVIEW);
- dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- }
- else
- {
- dwFlags &= (~ANNOTFLAG_INVISIBLE);
- dwFlags &= (~ANNOTFLAG_HIDDEN);
- dwFlags &= (~ANNOTFLAG_NOVIEW);
- dwFlags |= ANNOTFLAG_PRINT;
- }
-
- if (dwFlags != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlags);
- bSet = TRUE;
- }
- }
- }
-
- if (bSet)
- UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- FX_DWORD dwFlags = pWidget->GetFlags();
-
- if (b)
- {
- dwFlags &= (~ANNOTFLAG_INVISIBLE);
- dwFlags &= (~ANNOTFLAG_NOVIEW);
- dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- }
- else
- {
- dwFlags &= (~ANNOTFLAG_INVISIBLE);
- dwFlags &= (~ANNOTFLAG_HIDDEN);
- dwFlags &= (~ANNOTFLAG_NOVIEW);
- dwFlags |= ANNOTFLAG_PRINT;
- }
-
- if (dwFlags != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlags);
- UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::highlight(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString strMode;
- vp >> strMode;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_HIGHLIGHT, strMode);
- }
- else
- {
- Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex, strMode);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl) return FALSE;
-
- int eHM = pFormControl->GetHighlightingMode();
- switch (eHM)
- {
- case CPDF_FormControl::None:
- vp << (FX_LPCWSTR)L"none";
- break;
- case CPDF_FormControl::Push:
- vp << (FX_LPCWSTR)L"push";
- break;
- case CPDF_FormControl::Invert:
- vp << (FX_LPCWSTR)L"invert";
- break;
- case CPDF_FormControl::Outline:
- vp << (FX_LPCWSTR)L"outline";
- break;
- case CPDF_FormControl::Toggle:
- vp << (FX_LPCWSTR)L"toggle";
- break;
- }
- }
-
- return TRUE;
-}
-
-void Field::SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::lineWidth(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int iWidth;
- vp >> iWidth;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_LINEWIDTH, iWidth);
- }
- else
- {
- Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex, iWidth);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl) return FALSE;
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- if(!pFormField->CountControls()) return FALSE;
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
- if (!pWidget) return FALSE;
-
- vp << (FX_INT32)pWidget->GetBorderWidth();
- }
-
- return TRUE;
-}
-
-void Field::SetLineWidth(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz=pFormField->CountControls(); j<jsz; j++)
- {
- CPDF_FormControl* pFormControl = pFormField->GetControl(j);
- ASSERT(pFormControl != NULL);
-
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- if (number != pWidget->GetBorderWidth())
- {
- pWidget->SetBorderWidth(number);
- bSet = TRUE;
- }
- }
- }
- if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- if (number != pWidget->GetBorderWidth())
- {
- pWidget->SetBorderWidth(number);
- UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::multiline(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_MULTILINE, bVP);
- }
- else
- {
- Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::multipleSelection(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
- }
- else
- {
- Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::name(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting()) return FALSE;
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- vp << m_FieldName;
-
- return TRUE;
-}
-
-FX_BOOL Field::numItems(OBJ_PROP_PARAMS)
-{
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
- pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
-
- if (!vp.IsGetting()) return FALSE;
-
- vp << (FX_INT32)pFormField->CountOptions();
-
- return TRUE;
-}
-
-FX_BOOL Field::page(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting()) return FALSE;
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- if (!pFormField) return FALSE;
-
- ASSERT(m_pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray widgetArray;
- pInterForm->GetWidgets(pFormField, widgetArray);
-
- if (widgetArray.GetSize() > 0)
- {
- CJS_Array PageArray(m_isolate);
-
- for (int i=0,sz=widgetArray.GetSize(); i<sz; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgetArray.GetAt(i);
- ASSERT(pWidget != NULL);
-
- CPDFSDK_PageView* pPageView = pWidget->GetPageView();
- if(!pPageView)
- return FALSE;
-
- PageArray.SetElement(i, CJS_Value(m_isolate,(FX_INT32)pPageView->GetPageIndex()));
- }
-
- vp << PageArray;
- }
- else
- {
- vp << (FX_INT32) -1;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::password(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_PASSWORD, bVP);
- }
- else
- {
- Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::print(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (m_nFormControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
- {
- FX_DWORD dwFlags = pWidget->GetFlags();
- if (bVP)
- dwFlags |= ANNOTFLAG_PRINT;
- else
- dwFlags &= ~ANNOTFLAG_PRINT;
-
- if (dwFlags != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlags);
- bSet = TRUE;
- }
- }
- }
-
- if (bSet)
- UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- else
- {
- if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- FX_DWORD dwFlags = pWidget->GetFlags();
- if (bVP)
- dwFlags |= ANNOTFLAG_PRINT;
- else
- dwFlags &= ~ANNOTFLAG_PRINT;
-
- if (dwFlags != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlags);
- UpdateFormControl(m_pDocument, pFormField->GetControl(m_nFormControlIndex), TRUE, FALSE, TRUE);
- }
- }
- }
- }
- }
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
- if (!pWidget) return FALSE;
-
- if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::radiosInUnison(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::readonly(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::rect(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
- if (!vp.IsArrayObject())return FALSE;
-
- CJS_Array rcArray(m_isolate);
- vp >> rcArray;
- CJS_Value Upper_Leftx(m_isolate), Upper_Lefty(m_isolate), Lower_Rightx(m_isolate), Lower_Righty(m_isolate);
- rcArray.GetElement(0, Upper_Leftx);
- rcArray.GetElement(1, Upper_Lefty);
- rcArray.GetElement(2, Lower_Rightx);
- rcArray.GetElement(3, Lower_Righty);
-
- FX_FLOAT pArray[4] = {0.0f,0.0f,0.0f,0.0f};
- pArray[0] = (FX_FLOAT)(FX_INT32)Upper_Leftx;
- pArray[1] = (FX_FLOAT)(FX_INT32)Lower_Righty;
- pArray[2] = (FX_FLOAT)(FX_INT32)Lower_Rightx;
- pArray[3] = (FX_FLOAT)(FX_INT32)Upper_Lefty;
-
- CPDF_Rect crRect(pArray);
-
- if (m_bDelay)
- {
- AddDelay_Rect(FP_RECT, crRect);
- }
- else
- {
- Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
- if (!pWidget) return FALSE;
-
- CFX_FloatRect crRect = pWidget->GetRect();
- CJS_Value Upper_Leftx(m_isolate),Upper_Lefty(m_isolate),Lower_Rightx(m_isolate),Lower_Righty(m_isolate);
- Upper_Leftx = (FX_INT32)crRect.left;
- Upper_Lefty = (FX_INT32)crRect.top;
- Lower_Rightx = (FX_INT32)crRect.right;
- Lower_Righty = (FX_INT32)crRect.bottom;
-
- CJS_Array rcArray(m_isolate);
- rcArray.SetElement(0,Upper_Leftx);
- rcArray.SetElement(1,Upper_Lefty);
- rcArray.SetElement(2,Lower_Rightx);
- rcArray.SetElement(3,Lower_Righty);
-
- vp << rcArray;
- }
-
- return TRUE;
-}
-
-void Field::SetRect(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPDF_Rect& rect)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
- {
- CPDF_FormControl* pFormControl = pFormField->GetControl(i);
- ASSERT(pFormControl != NULL);
-
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- CPDF_Rect crRect = rect;
-
- CPDF_Page* pPDFPage = pWidget->GetPDFPage();
- ASSERT(pPDFPage != NULL);
-
-// CPDF_Page* pPDFPage = pPage->GetPage();
-// ASSERT(pPDFPage != NULL);
-
- crRect.Intersect(pPDFPage->GetPageBBox());
-
- if (!crRect.IsEmpty())
- {
- CPDF_Rect rcOld = pWidget->GetRect();
- if (crRect.left != rcOld.left ||
- crRect.right != rcOld.right ||
- crRect.top != rcOld.top ||
- crRect.bottom != rcOld.bottom)
- {
- pWidget->SetRect(crRect);
- bSet = TRUE;
- }
- }
- }
- }
-
- if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- CPDF_Rect crRect = rect;
-
- CPDF_Page* pPDFPage = pWidget->GetPDFPage();
- ASSERT(pPDFPage != NULL);
-
-// CPDF_Page* pPDFPage = pPage->GetPage();
-// ASSERT(pPDFPage != NULL);
-
- crRect.Intersect(pPDFPage->GetPageBBox());
-
- if (!crRect.IsEmpty())
- {
- CPDF_Rect rcOld = pWidget->GetRect();
- if (crRect.left != rcOld.left ||
- crRect.right != rcOld.right ||
- crRect.top != rcOld.top ||
- crRect.bottom != rcOld.bottom)
- {
- pWidget->SetRect(crRect);
- UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
- }
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::required(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::richText(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_RICHTEXT, bVP);
- }
- else
- {
- Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::richValue(OBJ_PROP_PARAMS)
-{
- return TRUE;
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
- ;
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-void Field::SetRichValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
-{
- //Not supported.
-}
-
-FX_BOOL Field::rotation(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_ROTATION, nVP);
- }
- else
- {
- Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- vp << (FX_INT32)pFormControl->GetRotation();
- }
-
- return TRUE;
-}
-
-void Field::SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::strokeColor(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- if (!vp.IsArrayObject())return FALSE;
-
- CJS_Array crArray(m_isolate);
- vp >> crArray;
-
- CPWL_Color color;
- color::ConvertArrayToPWLColor(crArray, color);
-
- if (m_bDelay)
- {
- AddDelay_Color(FP_STROKECOLOR, color);
- }
- else
- {
- Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- int iColorType;
- pFormControl->GetBorderColor(iColorType);
-
- CPWL_Color color;
-
- if (iColorType == COLORTYPE_TRANSPARENT)
- {
- color = CPWL_Color(COLORTYPE_TRANSPARENT);
- }
- else if (iColorType == COLORTYPE_GRAY)
- {
- color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
- }
- else if (iColorType == COLORTYPE_RGB)
- {
- color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
- pFormControl->GetOriginalBorderColor(1),
- pFormControl->GetOriginalBorderColor(2));
- }
- else if (iColorType == COLORTYPE_CMYK)
- {
- color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
- pFormControl->GetOriginalBorderColor(1),
- pFormControl->GetOriginalBorderColor(2),
- pFormControl->GetOriginalBorderColor(3));
- }
- else
- return FALSE;
-
- CJS_Array crArray(m_isolate);
- color::ConvertPWLColorToArray(color, crArray);
- vp << crArray;
- }
-
- return TRUE;
-}
-
-void Field::SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
-{
- //Not supported.
-}
-
-FX_BOOL Field::style(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString csBCaption;
- vp >> csBCaption;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_STYLE, csBCaption);
- }
- else
- {
- Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex, csBCaption);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
- pFormField->GetFieldType() != FIELDTYPE_CHECKBOX)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl) return FALSE;
-
- CFX_WideString csWCaption = pFormControl->GetNormalCaption();
- CFX_ByteString csBCaption;
-
- switch (csWCaption[0])
- {
- case L'l':
- csBCaption = "circle";
- break;
- case L'8':
- csBCaption = "cross";
- break;
- case L'u':
- csBCaption = "diamond";
- break;
- case L'n':
- csBCaption = "square";
- break;
- case L'H':
- csBCaption = "star";
- break;
- default: //L'4'
- csBCaption = "check";
- break;
- }
- vp << csBCaption;
- }
-
- return TRUE;
-}
-
-void Field::SetStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_ByteString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::submitName(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::textColor(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CJS_Array crArray(m_isolate);
- if (!vp.IsArrayObject())return FALSE;
- vp >> crArray;
-
- CPWL_Color color;
- color::ConvertArrayToPWLColor(crArray, color);
-
- if (m_bDelay)
- {
- AddDelay_Color(FP_TEXTCOLOR, color);
- }
- else
- {
- Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- int iColorType;
- FX_ARGB color;
- CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
- FieldAppearance.GetColor(color, iColorType);
- FX_INT32 a,r,g,b;
- ArgbDecode(color, a, r, g, b);
-
- CPWL_Color crRet = CPWL_Color(COLORTYPE_RGB, r / 255.0f,
- g / 255.0f,
- b / 255.0f);
-
- if (iColorType == COLORTYPE_TRANSPARENT)
- crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
-
- CJS_Array crArray(m_isolate);
- color::ConvertPWLColorToArray(crRet, crArray);
- vp << crArray;
- }
-
- return TRUE;
-}
-
-void Field::SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
-{
- //Not supported.
-}
-
-FX_BOOL Field::textFont(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString csFontName;
- vp >> csFontName;
- if (csFontName.IsEmpty()) return FALSE;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_TEXTFONT, csFontName);
- }
- else
- {
- Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex, csFontName);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- int nFieldType = pFormField->GetFieldType();
-
- if (nFieldType == FIELDTYPE_PUSHBUTTON ||
- nFieldType == FIELDTYPE_COMBOBOX ||
- nFieldType == FIELDTYPE_LISTBOX ||
- nFieldType == FIELDTYPE_TEXTFIELD)
- {
- CPDF_Font * pFont = pFormControl->GetDefaultControlFont();
- if (!pFont) return FALSE;
-
- vp << pFont->GetBaseFont();
- }
- else
- return FALSE;
- }
-
- return TRUE;
-}
-
-void Field::SetTextFont(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::textSize(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_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_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
-
- CFX_ByteString csFontNameTag;
- FX_FLOAT fFontSize;
- FieldAppearance.GetFont(csFontNameTag,fFontSize);
-
- vp << (int)fFontSize;
- }
-
- return TRUE;
-}
-
-void Field::SetTextSize(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::type(OBJ_PROP_PARAMS)
-{
- 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 << (FX_LPCWSTR)L"unknown";
- break;
- case FIELDTYPE_PUSHBUTTON:
- vp << (FX_LPCWSTR)L"button";
- break;
- case FIELDTYPE_CHECKBOX:
- vp << (FX_LPCWSTR)L"checkbox";
- break;
- case FIELDTYPE_RADIOBUTTON:
- vp << (FX_LPCWSTR)L"radiobutton";
- break;
- case FIELDTYPE_COMBOBOX:
- vp << (FX_LPCWSTR)L"combobox";
- break;
- case FIELDTYPE_LISTBOX:
- vp << (FX_LPCWSTR)L"listbox";
- break;
- case FIELDTYPE_TEXTFIELD:
- vp << (FX_LPCWSTR)L"text";
- break;
- case FIELDTYPE_SIGNATURE:
- vp << (FX_LPCWSTR)L"signature";
- break;
- default :
- vp << (FX_LPCWSTR)L"unknown";
- break;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::userName(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- 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;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- vp << (CFX_WideString)pFormField->GetAlternateName();
- }
-
- return TRUE;
-}
-
-void Field::SetUserName(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::value(OBJ_PROP_PARAMS)
-{
- 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.operator CFX_WideString());
- }
- }
- 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,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);
- if (FXSYS_wcslen((FX_LPCWSTR)ElementValue.operator CFX_WideString()) == 0)
- ElementValue = pFormField->GetOptionLabel(iIndex);
- ValueArray.SetElement(i, ElementValue);
- }
- vp << ValueArray;
- }
- else
- {
- CFX_WideString swValue = pFormField->GetValue();
-
- double dRet;
- FX_BOOL bDot;
- if (CJS_PublicMethods::ConvertStringToNumber(swValue,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,dRet,bDot))
- {
- if (bDot)
- vp << dRet;
- else
- vp << dRet;
- }
- else
- vp << swValue;
-
- bFind = TRUE;
- break;
- }
- else
- continue;
- }
- if (!bFind)
- vp << (FX_LPCWSTR)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;
- }
- }
-}
-
-FX_BOOL Field::valueAsString(OBJ_PROP_PARAMS)
-{
- 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 << (FX_LPCWSTR)L"Yes";
- else
- vp << (FX_LPCWSTR)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 << (FX_LPCWSTR)pFormField->GetControl(i)->GetExportValue();
- break;
- }
- else
- vp << (FX_LPCWSTR)L"Off";
- }
- }
- else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && (pFormField->CountSelectedItems() > 1))
- {
- vp << (FX_LPCWSTR)L"";
- }
- else
- vp << (FX_LPCWSTR)pFormField->GetValue();
-
- return TRUE;
-}
-
-/* --------------------------------- methods --------------------------------- */
-
-FX_BOOL Field::browseForFileToSubmit(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- 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);
- }
- }
- else
- return FALSE;
-
- return TRUE;
-}
-
-
-FX_BOOL Field::buttonGetCaption(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nface = 0;
- int iSize = params.size();
- if ( iSize >= 1)
- nface = (FX_INT32) params[0];
-
- 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;
-
- if (nface == 0)
- vRet = pFormControl->GetNormalCaption();
- else if (nface == 1)
- vRet = pFormControl->GetDownCaption();
- else if (nface == 2)
- vRet = pFormControl->GetRolloverCaption();
- else
- return FALSE;
-
- return TRUE;
-}
-
-//#pragma warning(disable: 4800)
-
-FX_BOOL Field::buttonGetIcon(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nface = 0;
- int iSize = params.size();
- if ( iSize >= 1)
- nface = (FX_INT32) params[0];
-
- 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;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- 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);
-
- 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;
-
- pIcon->SetStream(pIconStream);
- vRet = pJS_Icon;
-
- return TRUE;
-}
-
-//#pragma warning(default: 4800)
-
-FX_BOOL Field::buttonImportIcon(OBJ_METHOD_PARAMS)
-{
-#if 0
- 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)return FALSE;
-
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv);
-
- CFX_WideString sIconFileName = pEnv->JS_fieldBrowse();
- if (sIconFileName.IsEmpty())
- {
- vRet = 1;
- return TRUE;
- }
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_Stream* pStream = pInterForm->LoadImageFromFile(sIconFileName);
- if (!pStream)
- {
- vRet = -1;
- return TRUE;
- }
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- pFormControl->SetNormalIcon(pStream);
- UpdateFormControl(m_pDocument, pFormControl, TRUE, TRUE, TRUE);
-
- vRet = 0;
-#endif // 0
- return TRUE;
-}
-
-FX_BOOL Field::buttonSetCaption(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::buttonSetIcon(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::checkThisBox(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!m_bCanSet) return FALSE;
-
- int iSize = params.size();
- int nWidget = -1;
- if ( iSize >= 1)
- nWidget= (FX_INT32) params[0];
- else
- return FALSE;
- FX_BOOL bCheckit = TRUE;
- if ( iSize >= 2)
- bCheckit = params[1];
-
-
- 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(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;
-}
-
-FX_BOOL Field::clearItems(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::defaultIsChecked(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!m_bCanSet) return FALSE;
-
- int iSize = params.size();
- int nWidget = -1;
- if ( iSize >= 1)
- nWidget= (FX_INT32) params[0];
- else
- return FALSE;
- //FX_BOOL bIsDefaultChecked = TRUE;
- //if ( iSize >= 2)
- // bIsDefaultChecked = params[1];
-
- 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(nWidget <0 || nWidget >= pFormField->CountControls())
- {
- vRet = FALSE;
- return FALSE;
- }
- if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
- || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
- {
-
- vRet = TRUE;
- }
- else
- vRet = FALSE;
-
- return TRUE;
-}
-
-FX_BOOL Field::deleteItemAt(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2)
-{
- ASSERT(ps1 != NULL);
- ASSERT(ps2 != NULL);
-
- return ps1->Compare(*ps2);
-}
-
-
-FX_BOOL Field::getArray(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- 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);
-
- swSort.Add(new CFX_WideString(pFormField->GetFullName()));
-
- }
- swSort.Sort(JS_COMPARESTRING);
-
- 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);
-
- 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);
-
- Field* pField = (Field*)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
-
- pField->AttachField(this->m_pJSDoc, *pStr);
-
- CJS_Value FormFieldValue(m_isolate);
- FormFieldValue = pJSField;
- FormFieldArray.SetElement(j, FormFieldValue);
-
- delete pStr;
- }
-
- vRet = FormFieldArray;
- swSort.RemoveAll();
- return TRUE;
-}
-
-FX_BOOL Field::getItemAt(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nIdx = -1;
- if (params.size() >=1)
- nIdx = (FX_INT32) params[0];
- FX_BOOL bExport = TRUE;
- int iSize = params.size();
- if ( iSize >= 2)
- {
- bExport =(FX_BOOL) params[1];
- }
-
- 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);
- else
- vRet = strval;
- }
- else
- vRet = pFormField->GetOptionLabel(nIdx);
- }
- else
- return FALSE;
-
- return TRUE;
-}
-
-FX_BOOL Field::getLock(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::insertItemAt(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::isBoxChecked(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nIndex = -1;
- if (params.size() >=1)
- nIndex = (FX_INT32) params[0];
-
- 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(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;
-
- return TRUE;
-}
-
-FX_BOOL Field::isDefaultChecked(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nIndex = -1;
- if (params.size() >=1)
- nIndex = (FX_INT32) params[0];
-
- 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(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;
-}
-
-FX_BOOL Field::setAction(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::setFocus(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- FX_INT32 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 (FX_INT32 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(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::setLock(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureGetModifications(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureGetSeedValue(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureInfo(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureSetSeedValue(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureSign(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureValidate(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::source(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << (CJS_Object*)NULL;
- }
-
- return TRUE;
-}
-
-/////////////////////////////////////////// delay /////////////////////////////////////////////
-
-void Field::AddDelay_Int(enum FIELD_PROP prop, FX_INT32 n)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->num = n;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_Bool(enum FIELD_PROP prop,bool b)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->b = b;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_String(enum FIELD_PROP prop, const CFX_ByteString& string)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->string = string;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_WideString(enum FIELD_PROP prop, const CFX_WideString& string)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->widestring = string;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->rect = rect;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->color = color;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_WordArray(enum FIELD_PROP prop, const CFX_DWordArray& array)
-{
- 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->wordarray.Add(array.GetAt(i));
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_WideStringArray(enum FIELD_PROP prop, const CJS_WideStringArray& array)
-{
- 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));
-
- 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
-
-void Field::AddField(CPDFSDK_Document* pDocument, int nPageIndex, int nFieldType,
- const CFX_WideString& sName, const CPDF_Rect& rcCoords)
-{
- //Not supported.
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Field.h"
+#include "../../include/javascript/JS_EventHandler.h"
+//#include "../include/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/color.h"
+#include "../../include/javascript/PublicMethods.h"
+#include "../../include/javascript/Icon.h"
+
+
+/* ---------------------- Field ---------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Field)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Field)
+ JS_STATIC_PROP_ENTRY(alignment)
+ JS_STATIC_PROP_ENTRY(borderStyle)
+ JS_STATIC_PROP_ENTRY(buttonAlignX)
+ JS_STATIC_PROP_ENTRY(buttonAlignY)
+ JS_STATIC_PROP_ENTRY(buttonFitBounds)
+ JS_STATIC_PROP_ENTRY(buttonPosition)
+ JS_STATIC_PROP_ENTRY(buttonScaleHow)
+ JS_STATIC_PROP_ENTRY(buttonScaleWhen)
+ JS_STATIC_PROP_ENTRY(calcOrderIndex)
+ JS_STATIC_PROP_ENTRY(charLimit)
+ JS_STATIC_PROP_ENTRY(comb)
+ JS_STATIC_PROP_ENTRY(commitOnSelChange)
+ JS_STATIC_PROP_ENTRY(currentValueIndices)
+ JS_STATIC_PROP_ENTRY(defaultStyle)
+ JS_STATIC_PROP_ENTRY(defaultValue)
+ JS_STATIC_PROP_ENTRY(doNotScroll)
+ JS_STATIC_PROP_ENTRY(doNotSpellCheck)
+ JS_STATIC_PROP_ENTRY(delay)
+ JS_STATIC_PROP_ENTRY(display)
+ JS_STATIC_PROP_ENTRY(doc)
+ JS_STATIC_PROP_ENTRY(editable)
+ JS_STATIC_PROP_ENTRY(exportValues)
+ JS_STATIC_PROP_ENTRY(hidden)
+ JS_STATIC_PROP_ENTRY(fileSelect)
+ JS_STATIC_PROP_ENTRY(fillColor)
+ JS_STATIC_PROP_ENTRY(lineWidth)
+ JS_STATIC_PROP_ENTRY(highlight)
+ JS_STATIC_PROP_ENTRY(multiline)
+ JS_STATIC_PROP_ENTRY(multipleSelection)
+ JS_STATIC_PROP_ENTRY(name)
+ JS_STATIC_PROP_ENTRY(numItems)
+ JS_STATIC_PROP_ENTRY(page)
+ JS_STATIC_PROP_ENTRY(password)
+ JS_STATIC_PROP_ENTRY(print)
+ JS_STATIC_PROP_ENTRY(radiosInUnison)
+ JS_STATIC_PROP_ENTRY(readonly)
+ JS_STATIC_PROP_ENTRY(rect)
+ JS_STATIC_PROP_ENTRY(required)
+ JS_STATIC_PROP_ENTRY(richText)
+ JS_STATIC_PROP_ENTRY(richValue)
+ JS_STATIC_PROP_ENTRY(rotation)
+ JS_STATIC_PROP_ENTRY(strokeColor)
+ JS_STATIC_PROP_ENTRY(style)
+ JS_STATIC_PROP_ENTRY(submitName)
+ JS_STATIC_PROP_ENTRY(textColor)
+ JS_STATIC_PROP_ENTRY(textFont)
+ JS_STATIC_PROP_ENTRY(textSize)
+ JS_STATIC_PROP_ENTRY(type)
+ JS_STATIC_PROP_ENTRY(userName)
+ JS_STATIC_PROP_ENTRY(value)
+ JS_STATIC_PROP_ENTRY(valueAsString)
+ JS_STATIC_PROP_ENTRY(source)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Field)
+ JS_STATIC_METHOD_ENTRY(browseForFileToSubmit, 0)
+ JS_STATIC_METHOD_ENTRY(buttonGetCaption, 1)
+ JS_STATIC_METHOD_ENTRY(buttonGetIcon, 1)
+ JS_STATIC_METHOD_ENTRY(buttonImportIcon, 0)
+ JS_STATIC_METHOD_ENTRY(buttonSetCaption, 2)
+ JS_STATIC_METHOD_ENTRY(buttonSetIcon, 2)
+ JS_STATIC_METHOD_ENTRY(checkThisBox, 2)
+ JS_STATIC_METHOD_ENTRY(clearItems, 0)
+ JS_STATIC_METHOD_ENTRY(defaultIsChecked, 2)
+ JS_STATIC_METHOD_ENTRY(deleteItemAt, 1)
+ JS_STATIC_METHOD_ENTRY(getArray , 0)
+ JS_STATIC_METHOD_ENTRY(getItemAt, 0)
+ JS_STATIC_METHOD_ENTRY(getLock, 0)
+ JS_STATIC_METHOD_ENTRY(insertItemAt, 0)
+ JS_STATIC_METHOD_ENTRY(isBoxChecked, 1)
+ JS_STATIC_METHOD_ENTRY(isDefaultChecked, 1)
+ JS_STATIC_METHOD_ENTRY(setAction, 2)
+ JS_STATIC_METHOD_ENTRY(setFocus, 0)
+ JS_STATIC_METHOD_ENTRY(setItems, 1)
+ JS_STATIC_METHOD_ENTRY(setLock, 0)
+ JS_STATIC_METHOD_ENTRY(signatureGetModifications, 0)
+ JS_STATIC_METHOD_ENTRY(signatureGetSeedValue, 0)
+ JS_STATIC_METHOD_ENTRY(signatureInfo, 0)
+ JS_STATIC_METHOD_ENTRY(signatureSetSeedValue, 0)
+ JS_STATIC_METHOD_ENTRY(signatureSign, 0)
+ JS_STATIC_METHOD_ENTRY(signatureValidate, 0)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Field, Field)
+
+FX_BOOL CJS_Field::InitInstance(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ Field* pField = (Field*)GetEmbedObject();
+ ASSERT(pField != NULL);
+
+ pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
+
+ return TRUE;
+};
+
+Field::Field(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject),
+ m_pJSDoc(NULL),
+ m_pDocument(NULL),
+ m_nFormControlIndex(-1),
+ m_bCanSet(FALSE),
+ m_bDelay(FALSE),
+ m_isolate(NULL)
+{
+}
+
+Field::~Field()
+{
+}
+
+//note: iControlNo = -1, means not a widget.
+void Field::ParseFieldName(const std::wstring &strFieldNameParsed,std::wstring &strFieldName,int & iControlNo)
+{
+ int iStart = strFieldNameParsed.find_last_of(L'.');
+ if (iStart == -1)
+ {
+ strFieldName = strFieldNameParsed;
+ iControlNo = -1;
+ return;
+ }
+ std::wstring suffixal = strFieldNameParsed.substr(iStart+1);
+ iControlNo = FXSYS_wtoi((FX_LPCWSTR)suffixal.c_str());
+ if (iControlNo == 0)
+ {
+ int iStart;
+ while((iStart = suffixal.find_last_of(L" ")) != -1)
+ {
+ suffixal.erase(iStart,1);
+ }
+
+ if (suffixal.compare(L"0") != 0)
+ {
+ strFieldName = strFieldNameParsed;
+ iControlNo = -1;
+ return;
+ }
+
+ }
+ strFieldName = strFieldNameParsed.substr(0,iStart);
+}
+
+FX_BOOL Field::AttachField(Document* pDocument, const CFX_WideString& csFieldName)
+{
+ ASSERT(pDocument != NULL);
+ m_pJSDoc = pDocument;
+
+ m_pDocument = pDocument->GetReaderDoc();
+ ASSERT(m_pDocument != NULL);
+
+ m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_MODIFY);
+
+ CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
+ ASSERT(pRDInterForm != NULL);
+
+ CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_WideString swFieldNameTemp = csFieldName;
+ swFieldNameTemp.Replace((FX_LPCWSTR)L"..", (FX_LPCWSTR)L".");
+
+ if (pInterForm->CountFields(swFieldNameTemp) <= 0)
+ {
+ std::wstring strFieldName;
+ int iControlNo = -1;
+ ParseFieldName((wchar_t*)(FX_LPCWSTR)swFieldNameTemp, strFieldName, iControlNo);
+ if (iControlNo == -1) return FALSE;
+
+ m_FieldName = strFieldName.c_str();
+ m_nFormControlIndex = iControlNo;
+ return TRUE;
+ }
+
+ m_FieldName = swFieldNameTemp;
+ m_nFormControlIndex = -1;
+
+ return TRUE;
+}
+
+void Field::GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
+ ASSERT(pReaderInterForm != NULL);
+
+ CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ ASSERT(FieldArray.GetSize() == 0);
+
+ for (int i=0,sz=pInterForm->CountFields(csFieldName); i<sz; i++)
+ {
+ if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
+ FieldArray.Add((void*)pFormField);
+ }
+}
+
+void Field::GetFormFields(const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
+{
+ ASSERT(m_pDocument != NULL);
+
+ Field::GetFormFields(m_pDocument, csFieldName, FieldArray);
+}
+
+void Field::UpdateFormField(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
+ FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray widgets;
+ pInterForm->GetWidgets(pFormField, widgets);
+
+ if (bResetAP)
+ {
+ int nFieldType = pFormField->GetFieldType();
+ if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
+ {
+ for (int i=0,sz=widgets.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
+ ASSERT(pWidget != NULL);
+
+ FX_BOOL bFormated = FALSE;
+ CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
+ if (bFormated)
+ pWidget->ResetAppearance(sValue, FALSE);
+ else
+ pWidget->ResetAppearance(NULL, FALSE);
+ }
+ }
+ else
+ {
+ for (int i=0,sz=widgets.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
+ ASSERT(pWidget != NULL);
+
+ pWidget->ResetAppearance(NULL, FALSE);
+ }
+ }
+ }
+
+ if (bRefresh)
+ {
+ for (int i=0,sz=widgets.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
+ ASSERT(pWidget != NULL);
+
+ CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
+ CPDFSDK_Document* pDoc = pInterForm->GetDocument();
+// CReader_Page* pPage = pWidget->GetPage();
+ ASSERT(pDoc != NULL);
+ pDoc->UpdateAllViews(NULL, pWidget);
+ }
+ }
+
+ if (bChangeMark)
+ pDocument->SetChangeMark();
+}
+
+void Field::UpdateFormControl(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl,
+ FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(pFormControl != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
+
+ if (pWidget)
+ {
+ if (bResetAP)
+ {
+ int nFieldType = pWidget->GetFieldType();
+ if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
+ {
+ FX_BOOL bFormated = FALSE;
+ CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
+ if (bFormated)
+ pWidget->ResetAppearance(sValue, FALSE);
+ else
+ pWidget->ResetAppearance(NULL, FALSE);
+ }
+ else
+ {
+ pWidget->ResetAppearance(NULL, FALSE);
+ }
+ }
+
+ if (bRefresh)
+ {
+ CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
+ CPDFSDK_Document* pDoc = pInterForm->GetDocument();
+ ASSERT(pDoc != NULL);
+ pDoc->UpdateAllViews(NULL, pWidget);
+ }
+
+ }
+
+ if (bChangeMark)
+ pDocument->SetChangeMark();
+}
+
+CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl)
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(pFormControl != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ return pInterForm->GetWidget(pFormControl);
+}
+
+FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel)
+{
+ ASSERT(pFormField != NULL);
+
+ for (int i=0,sz = pFormField->CountOptions(); i < sz; i++)
+ {
+ if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField)
+{
+ ASSERT(pFormField != NULL);
+ if(!pFormField->CountControls() || m_nFormControlIndex>=pFormField->CountControls()) return NULL;
+
+ if (m_nFormControlIndex<0)
+ return pFormField->GetControl(0);
+ else
+ return pFormField->GetControl(m_nFormControlIndex);
+}
+
+/* ---------------------------------------- property ---------------------------------------- */
+
+FX_BOOL Field::alignment(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString alignStr;
+ vp >> alignStr;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_ALIGNMENT, alignStr);
+ }
+ else
+ {
+ Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex, alignStr);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ switch (pFormControl->GetControlAlignment())
+ {
+ case 1:
+ vp << (FX_LPCWSTR)L"center";
+ break;
+ case 0:
+ vp << (FX_LPCWSTR)L"left";
+ break;
+ case 2:
+ vp << (FX_LPCWSTR)L"right";
+ break;
+ default:
+ vp << (FX_LPCWSTR)L"";
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_ByteString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::borderStyle(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString strType = "";
+ vp >> strType;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_BORDERSTYLE, strType);
+ }
+ else
+ {
+ Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex, strType);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ if (!pFormField) return FALSE;
+
+ CPDFSDK_Widget* pWidget = GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
+ if (!pWidget) return FALSE;
+
+ int nBorderstyle = pWidget->GetBorderStyle();
+
+ switch (nBorderstyle)
+ {
+ case BBS_SOLID:
+ vp << (FX_LPCWSTR)L"solid";
+ break;
+ case BBS_DASH:
+ vp << (FX_LPCWSTR)L"dashed";
+ break;
+ case BBS_BEVELED:
+ vp << (FX_LPCWSTR)L"beveled";
+ break;
+ case BBS_INSET:
+ vp << (FX_LPCWSTR)L"inset";
+ break;
+ case BBS_UNDERLINE:
+ vp << (FX_LPCWSTR)L"underline";
+ break;
+ default:
+ vp << (FX_LPCWSTR)L"";
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetBorderStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_ByteString& string)
+{
+ ASSERT(pDocument != NULL);
+
+ int nBorderStyle = 0;
+
+ if (string == "solid")
+ nBorderStyle = BBS_SOLID;
+ else if (string == "beveled")
+ nBorderStyle = BBS_BEVELED;
+ else if (string == "dashed")
+ nBorderStyle = BBS_DASH;
+ else if (string == "inset")
+ nBorderStyle = BBS_INSET;
+ else if (string == "underline")
+ nBorderStyle = BBS_UNDERLINE;
+ else return;
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
+ {
+ if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormField->GetControl(j)))
+ {
+ if (pWidget->GetBorderStyle() != nBorderStyle)
+ {
+ pWidget->SetBorderStyle(nBorderStyle);
+ bSet = TRUE;
+ }
+ }
+ }
+ if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl))
+ {
+ if (pWidget->GetBorderStyle() != nBorderStyle)
+ {
+ pWidget->SetBorderStyle(nBorderStyle);
+ UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::buttonAlignX(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONALIGNX, nVP);
+ }
+ else
+ {
+ Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+
+ FX_FLOAT fLeft,fBottom;
+ IconFit.GetIconPosition(fLeft,fBottom);
+
+ vp << (FX_INT32)fLeft;
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonAlignY(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONALIGNY, nVP);
+ }
+ else
+ {
+ Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+
+ FX_FLOAT fLeft,fBottom;
+ IconFit.GetIconPosition(fLeft,fBottom);
+
+ vp << (FX_INT32)fBottom;
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonFitBounds(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
+ }
+ else
+ {
+ Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ vp << IconFit.GetFittingBounds();
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonPosition(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONPOSITION, nVP);
+ }
+ else
+ {
+ Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ vp << pFormControl->GetTextPosition();
+ }
+ return TRUE;
+}
+
+void Field::SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonScaleHow(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
+ }
+ else
+ {
+ Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ if (IconFit.IsProportionalScale())
+ vp << (FX_INT32)0;
+ else
+ vp << (FX_INT32)1;
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonScaleWhen(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
+ }
+ else
+ {
+ Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*) FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl) return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ int ScaleM = IconFit.GetScaleMethod();
+ switch (ScaleM)
+ {
+ case CPDF_IconFit::Always :
+ vp << (FX_INT32) CPDF_IconFit::Always;
+ break;
+ case CPDF_IconFit::Bigger :
+ vp << (FX_INT32) CPDF_IconFit::Bigger;
+ break;
+ case CPDF_IconFit::Never :
+ vp << (FX_INT32) CPDF_IconFit::Never;
+ break;
+ case CPDF_IconFit::Smaller :
+ vp << (FX_INT32) CPDF_IconFit::Smaller;
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::calcOrderIndex(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_CALCORDERINDEX, nVP);
+ }
+ else
+ {
+ Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
+ ASSERT(pRDInterForm != NULL);
+
+ CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ vp << (FX_INT32)pInterForm->FindFieldInCalculationOrder(pFormField);
+ }
+
+ return TRUE;
+}
+
+void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::charLimit(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_CHARLIMIT, nVP);
+ }
+ else
+ {
+ Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ vp << (FX_INT32)pFormField->GetMaxLen();
+ }
+ return TRUE;
+}
+
+void Field::SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::comb(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_COMB, bVP);
+ }
+ else
+ {
+ Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::commitOnSelChange(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
+ }
+ else
+ {
+ Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::currentValueIndices(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_DWordArray array;
+
+ if (vp.GetType() == VT_number)
+ {
+ int iSelecting = 0;
+ vp >> iSelecting;
+ array.Add(iSelecting);
+ }
+ else if (vp.IsArrayObject())
+ {
+ CJS_Array SelArray(m_isolate);
+ CJS_Value SelValue(m_isolate);
+ int iSelecting;
+ vp >> SelArray;
+ for (int i=0,sz=SelArray.GetLength(); i<sz; i++)
+ {
+ SelArray.GetElement(i,SelValue);
+ iSelecting = (FX_INT32)SelValue;
+ array.Add(iSelecting);
+ }
+ }
+
+ if (m_bDelay)
+ {
+ AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
+ }
+ else
+ {
+ Field::SetCurrentValueIndices(m_pDocument, m_FieldName, m_nFormControlIndex, array);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
+
+ if (pFormField->CountSelectedItems() == 1)
+ vp << pFormField->GetSelectedIndex(0);
+ else if (pFormField->CountSelectedItems() > 1)
+ {
+ CJS_Array SelArray(m_isolate);
+ for (int i=0,sz=pFormField->CountSelectedItems(); i<sz; i++)
+ {
+ SelArray.SetElement(i, CJS_Value(m_isolate,pFormField->GetSelectedIndex(i)));
+ }
+ vp << SelArray;
+ }
+ else
+ vp << -1;
+ }
+
+ return TRUE;
+}
+
+void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_DWordArray& array)
+{
+ ASSERT(pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ int nFieldType = pFormField->GetFieldType();
+ if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX)
+ {
+ FX_DWORD dwFieldFlags = pFormField->GetFieldFlags();
+ pFormField->ClearSelection(TRUE);
+
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ {
+ if (i>0 && !(dwFieldFlags & (1<<21)))
+ {
+ break;
+ }
+
+ int iSelecting = (FX_INT32)array.GetAt(i);
+ if (iSelecting < pFormField->CountOptions() && !pFormField->IsItemSelected(iSelecting))
+ pFormField->SetItemSelection(iSelecting, TRUE);
+
+ }
+ UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ }
+}
+
+FX_BOOL Field::defaultStyle(OBJ_PROP_PARAMS)
+{
+ // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT);
+ return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ ;
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::defaultValue(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_WideString WideStr;
+ vp >> WideStr;
+
+ if (m_bDelay)
+ {
+ AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
+ }
+ else
+ {
+ Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex, WideStr);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
+ pFormField->GetFieldType() == FIELDTYPE_SIGNATURE)
+ return FALSE;
+
+ vp << pFormField->GetDefaultValue();
+ }
+ return TRUE;
+}
+
+void Field::SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_WideString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::doNotScroll(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_DONOTSCROLL, bVP);
+ }
+ else
+ {
+ Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::doNotSpellCheck(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
+ pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetDelay(FX_BOOL bDelay)
+{
+ m_bDelay = bDelay;
+
+ if (!m_bDelay)
+ {
+ if (m_pJSDoc)
+ m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
+ }
+}
+
+FX_BOOL Field::delay(OBJ_PROP_PARAMS)
+{
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ SetDelay(bVP);
+ }
+ else
+ {
+ vp << m_bDelay;
+ }
+ return TRUE;
+}
+
+FX_BOOL Field::display(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_DISPLAY, nVP);
+ }
+ else
+ {
+ Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
+ if (!pWidget)return FALSE;
+
+ FX_DWORD dwFlag = pWidget->GetFlags();
+
+ if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag)
+ {
+ vp << (FX_INT32)1;
+ }
+ else
+ {
+ if (ANNOTFLAG_PRINT & dwFlag)
+ {
+ if (ANNOTFLAG_NOVIEW & dwFlag)
+ {
+ vp << (FX_INT32)3;
+ }
+ else
+ {
+ vp << (FX_INT32)0;
+ }
+ }
+ else
+ {
+ vp << (FX_INT32)2;
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetDisplay(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
+ {
+ CPDF_FormControl* pFormControl = pFormField->GetControl(j);
+ ASSERT(pFormControl != NULL);
+
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ FX_DWORD dwFlag = pWidget->GetFlags();
+ switch (number)
+ {
+ case 0:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ dwFlag |= ANNOTFLAG_PRINT;
+ break;
+ case 1:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+ break;
+ case 2:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_PRINT);
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ break;
+ case 3:
+ dwFlag |= ANNOTFLAG_NOVIEW;
+ dwFlag |= ANNOTFLAG_PRINT;
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ break;
+ }
+
+ if (dwFlag != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlag);
+ bSet = TRUE;
+ }
+ }
+ }
+
+ if (bSet) UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+
+ FX_DWORD dwFlag = pWidget->GetFlags();
+ switch (number)
+ {
+ case 0:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ dwFlag |= ANNOTFLAG_PRINT;
+ break;
+ case 1:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+ break;
+ case 2:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_PRINT);
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ break;
+ case 3:
+ dwFlag |= ANNOTFLAG_NOVIEW;
+ dwFlag |= ANNOTFLAG_PRINT;
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ break;
+ }
+ if (dwFlag != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlag);
+ UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::doc(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ if (!vp.IsGetting())return FALSE;
+
+ vp << (CJS_Object*)(*m_pJSDoc);
+
+ return TRUE;
+}
+
+FX_BOOL Field::editable(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::exportValues(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
+ pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
+ return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+ if (!vp.IsArrayObject())return FALSE;
+ }
+ else
+ {
+ CJS_Array ExportValusArray(m_isolate);
+
+ if (m_nFormControlIndex < 0)
+ {
+ for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
+ {
+ CPDF_FormControl* pFormControl = pFormField->GetControl(i);
+ ASSERT(pFormControl != NULL);
+
+ ExportValusArray.SetElement(i, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
+ }
+ }
+ else
+ {
+ if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
+ CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex);
+ if (!pFormControl) return FALSE;
+
+ ExportValusArray.SetElement(0, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
+ }
+
+ vp << ExportValusArray;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::fileSelect(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::fillColor(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CJS_Array crArray(m_isolate);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+ if (!vp.IsArrayObject()) return FALSE;
+
+ vp >> crArray;
+
+ CPWL_Color color;
+ color::ConvertArrayToPWLColor(crArray, color);
+
+ if (m_bDelay)
+ {
+ AddDelay_Color(FP_FILLCOLOR, color);
+ }
+ else
+ {
+ Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
+ }
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ int iColorType;
+ pFormControl->GetBackgroundColor(iColorType);
+
+ CPWL_Color color;
+
+ if (iColorType == COLORTYPE_TRANSPARENT)
+ {
+ color = CPWL_Color(COLORTYPE_TRANSPARENT);
+ }
+ else if (iColorType == COLORTYPE_GRAY)
+ {
+ color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
+ }
+ else if (iColorType == COLORTYPE_RGB)
+ {
+ color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
+ pFormControl->GetOriginalBackgroundColor(1),
+ pFormControl->GetOriginalBackgroundColor(2));
+ }
+ else if (iColorType == COLORTYPE_CMYK)
+ {
+ color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
+ pFormControl->GetOriginalBackgroundColor(1),
+ pFormControl->GetOriginalBackgroundColor(2),
+ pFormControl->GetOriginalBackgroundColor(3));
+ }
+ else
+ return FALSE;
+
+ color::ConvertPWLColorToArray(color, crArray);
+ vp << crArray;
+ }
+
+ return TRUE;
+}
+
+void Field::SetFillColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::hidden(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_HIDDEN, bVP);
+ }
+ else
+ {
+ Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
+ if (!pWidget) return FALSE;
+
+ FX_DWORD dwFlags = pWidget->GetFlags();
+
+ if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
+ {
+ vp << true;
+ }
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetHidden(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
+ {
+ FX_DWORD dwFlags = pWidget->GetFlags();
+
+ if (b)
+ {
+ dwFlags &= (~ANNOTFLAG_INVISIBLE);
+ dwFlags &= (~ANNOTFLAG_NOVIEW);
+ dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+ }
+ else
+ {
+ dwFlags &= (~ANNOTFLAG_INVISIBLE);
+ dwFlags &= (~ANNOTFLAG_HIDDEN);
+ dwFlags &= (~ANNOTFLAG_NOVIEW);
+ dwFlags |= ANNOTFLAG_PRINT;
+ }
+
+ if (dwFlags != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlags);
+ bSet = TRUE;
+ }
+ }
+ }
+
+ if (bSet)
+ UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ FX_DWORD dwFlags = pWidget->GetFlags();
+
+ if (b)
+ {
+ dwFlags &= (~ANNOTFLAG_INVISIBLE);
+ dwFlags &= (~ANNOTFLAG_NOVIEW);
+ dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+ }
+ else
+ {
+ dwFlags &= (~ANNOTFLAG_INVISIBLE);
+ dwFlags &= (~ANNOTFLAG_HIDDEN);
+ dwFlags &= (~ANNOTFLAG_NOVIEW);
+ dwFlags |= ANNOTFLAG_PRINT;
+ }
+
+ if (dwFlags != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlags);
+ UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::highlight(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString strMode;
+ vp >> strMode;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_HIGHLIGHT, strMode);
+ }
+ else
+ {
+ Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex, strMode);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl) return FALSE;
+
+ int eHM = pFormControl->GetHighlightingMode();
+ switch (eHM)
+ {
+ case CPDF_FormControl::None:
+ vp << (FX_LPCWSTR)L"none";
+ break;
+ case CPDF_FormControl::Push:
+ vp << (FX_LPCWSTR)L"push";
+ break;
+ case CPDF_FormControl::Invert:
+ vp << (FX_LPCWSTR)L"invert";
+ break;
+ case CPDF_FormControl::Outline:
+ vp << (FX_LPCWSTR)L"outline";
+ break;
+ case CPDF_FormControl::Toggle:
+ vp << (FX_LPCWSTR)L"toggle";
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::lineWidth(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int iWidth;
+ vp >> iWidth;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_LINEWIDTH, iWidth);
+ }
+ else
+ {
+ Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex, iWidth);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl) return FALSE;
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ if(!pFormField->CountControls()) return FALSE;
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
+ if (!pWidget) return FALSE;
+
+ vp << (FX_INT32)pWidget->GetBorderWidth();
+ }
+
+ return TRUE;
+}
+
+void Field::SetLineWidth(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz=pFormField->CountControls(); j<jsz; j++)
+ {
+ CPDF_FormControl* pFormControl = pFormField->GetControl(j);
+ ASSERT(pFormControl != NULL);
+
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ if (number != pWidget->GetBorderWidth())
+ {
+ pWidget->SetBorderWidth(number);
+ bSet = TRUE;
+ }
+ }
+ }
+ if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ if (number != pWidget->GetBorderWidth())
+ {
+ pWidget->SetBorderWidth(number);
+ UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::multiline(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_MULTILINE, bVP);
+ }
+ else
+ {
+ Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::multipleSelection(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
+ }
+ else
+ {
+ Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::name(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting()) return FALSE;
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ vp << m_FieldName;
+
+ return TRUE;
+}
+
+FX_BOOL Field::numItems(OBJ_PROP_PARAMS)
+{
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
+ pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
+
+ if (!vp.IsGetting()) return FALSE;
+
+ vp << (FX_INT32)pFormField->CountOptions();
+
+ return TRUE;
+}
+
+FX_BOOL Field::page(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting()) return FALSE;
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ if (!pFormField) return FALSE;
+
+ ASSERT(m_pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray widgetArray;
+ pInterForm->GetWidgets(pFormField, widgetArray);
+
+ if (widgetArray.GetSize() > 0)
+ {
+ CJS_Array PageArray(m_isolate);
+
+ for (int i=0,sz=widgetArray.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgetArray.GetAt(i);
+ ASSERT(pWidget != NULL);
+
+ CPDFSDK_PageView* pPageView = pWidget->GetPageView();
+ if(!pPageView)
+ return FALSE;
+
+ PageArray.SetElement(i, CJS_Value(m_isolate,(FX_INT32)pPageView->GetPageIndex()));
+ }
+
+ vp << PageArray;
+ }
+ else
+ {
+ vp << (FX_INT32) -1;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::password(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_PASSWORD, bVP);
+ }
+ else
+ {
+ Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::print(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (m_nFormControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
+ {
+ FX_DWORD dwFlags = pWidget->GetFlags();
+ if (bVP)
+ dwFlags |= ANNOTFLAG_PRINT;
+ else
+ dwFlags &= ~ANNOTFLAG_PRINT;
+
+ if (dwFlags != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlags);
+ bSet = TRUE;
+ }
+ }
+ }
+
+ if (bSet)
+ UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ else
+ {
+ if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ FX_DWORD dwFlags = pWidget->GetFlags();
+ if (bVP)
+ dwFlags |= ANNOTFLAG_PRINT;
+ else
+ dwFlags &= ~ANNOTFLAG_PRINT;
+
+ if (dwFlags != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlags);
+ UpdateFormControl(m_pDocument, pFormField->GetControl(m_nFormControlIndex), TRUE, FALSE, TRUE);
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
+ if (!pWidget) return FALSE;
+
+ if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::radiosInUnison(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::readonly(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::rect(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+ if (!vp.IsArrayObject())return FALSE;
+
+ CJS_Array rcArray(m_isolate);
+ vp >> rcArray;
+ CJS_Value Upper_Leftx(m_isolate), Upper_Lefty(m_isolate), Lower_Rightx(m_isolate), Lower_Righty(m_isolate);
+ rcArray.GetElement(0, Upper_Leftx);
+ rcArray.GetElement(1, Upper_Lefty);
+ rcArray.GetElement(2, Lower_Rightx);
+ rcArray.GetElement(3, Lower_Righty);
+
+ FX_FLOAT pArray[4] = {0.0f,0.0f,0.0f,0.0f};
+ pArray[0] = (FX_FLOAT)(FX_INT32)Upper_Leftx;
+ pArray[1] = (FX_FLOAT)(FX_INT32)Lower_Righty;
+ pArray[2] = (FX_FLOAT)(FX_INT32)Lower_Rightx;
+ pArray[3] = (FX_FLOAT)(FX_INT32)Upper_Lefty;
+
+ CPDF_Rect crRect(pArray);
+
+ if (m_bDelay)
+ {
+ AddDelay_Rect(FP_RECT, crRect);
+ }
+ else
+ {
+ Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
+ if (!pWidget) return FALSE;
+
+ CFX_FloatRect crRect = pWidget->GetRect();
+ CJS_Value Upper_Leftx(m_isolate),Upper_Lefty(m_isolate),Lower_Rightx(m_isolate),Lower_Righty(m_isolate);
+ Upper_Leftx = (FX_INT32)crRect.left;
+ Upper_Lefty = (FX_INT32)crRect.top;
+ Lower_Rightx = (FX_INT32)crRect.right;
+ Lower_Righty = (FX_INT32)crRect.bottom;
+
+ CJS_Array rcArray(m_isolate);
+ rcArray.SetElement(0,Upper_Leftx);
+ rcArray.SetElement(1,Upper_Lefty);
+ rcArray.SetElement(2,Lower_Rightx);
+ rcArray.SetElement(3,Lower_Righty);
+
+ vp << rcArray;
+ }
+
+ return TRUE;
+}
+
+void Field::SetRect(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPDF_Rect& rect)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
+ {
+ CPDF_FormControl* pFormControl = pFormField->GetControl(i);
+ ASSERT(pFormControl != NULL);
+
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ CPDF_Rect crRect = rect;
+
+ CPDF_Page* pPDFPage = pWidget->GetPDFPage();
+ ASSERT(pPDFPage != NULL);
+
+// CPDF_Page* pPDFPage = pPage->GetPage();
+// ASSERT(pPDFPage != NULL);
+
+ crRect.Intersect(pPDFPage->GetPageBBox());
+
+ if (!crRect.IsEmpty())
+ {
+ CPDF_Rect rcOld = pWidget->GetRect();
+ if (crRect.left != rcOld.left ||
+ crRect.right != rcOld.right ||
+ crRect.top != rcOld.top ||
+ crRect.bottom != rcOld.bottom)
+ {
+ pWidget->SetRect(crRect);
+ bSet = TRUE;
+ }
+ }
+ }
+ }
+
+ if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ CPDF_Rect crRect = rect;
+
+ CPDF_Page* pPDFPage = pWidget->GetPDFPage();
+ ASSERT(pPDFPage != NULL);
+
+// CPDF_Page* pPDFPage = pPage->GetPage();
+// ASSERT(pPDFPage != NULL);
+
+ crRect.Intersect(pPDFPage->GetPageBBox());
+
+ if (!crRect.IsEmpty())
+ {
+ CPDF_Rect rcOld = pWidget->GetRect();
+ if (crRect.left != rcOld.left ||
+ crRect.right != rcOld.right ||
+ crRect.top != rcOld.top ||
+ crRect.bottom != rcOld.bottom)
+ {
+ pWidget->SetRect(crRect);
+ UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::required(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::richText(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_RICHTEXT, bVP);
+ }
+ else
+ {
+ Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::richValue(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+ ;
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+void Field::SetRichValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::rotation(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_ROTATION, nVP);
+ }
+ else
+ {
+ Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ vp << (FX_INT32)pFormControl->GetRotation();
+ }
+
+ return TRUE;
+}
+
+void Field::SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::strokeColor(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ if (!vp.IsArrayObject())return FALSE;
+
+ CJS_Array crArray(m_isolate);
+ vp >> crArray;
+
+ CPWL_Color color;
+ color::ConvertArrayToPWLColor(crArray, color);
+
+ if (m_bDelay)
+ {
+ AddDelay_Color(FP_STROKECOLOR, color);
+ }
+ else
+ {
+ Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ int iColorType;
+ pFormControl->GetBorderColor(iColorType);
+
+ CPWL_Color color;
+
+ if (iColorType == COLORTYPE_TRANSPARENT)
+ {
+ color = CPWL_Color(COLORTYPE_TRANSPARENT);
+ }
+ else if (iColorType == COLORTYPE_GRAY)
+ {
+ color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
+ }
+ else if (iColorType == COLORTYPE_RGB)
+ {
+ color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
+ pFormControl->GetOriginalBorderColor(1),
+ pFormControl->GetOriginalBorderColor(2));
+ }
+ else if (iColorType == COLORTYPE_CMYK)
+ {
+ color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
+ pFormControl->GetOriginalBorderColor(1),
+ pFormControl->GetOriginalBorderColor(2),
+ pFormControl->GetOriginalBorderColor(3));
+ }
+ else
+ return FALSE;
+
+ CJS_Array crArray(m_isolate);
+ color::ConvertPWLColorToArray(color, crArray);
+ vp << crArray;
+ }
+
+ return TRUE;
+}
+
+void Field::SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::style(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString csBCaption;
+ vp >> csBCaption;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_STYLE, csBCaption);
+ }
+ else
+ {
+ Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex, csBCaption);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
+ pFormField->GetFieldType() != FIELDTYPE_CHECKBOX)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl) return FALSE;
+
+ CFX_WideString csWCaption = pFormControl->GetNormalCaption();
+ CFX_ByteString csBCaption;
+
+ switch (csWCaption[0])
+ {
+ case L'l':
+ csBCaption = "circle";
+ break;
+ case L'8':
+ csBCaption = "cross";
+ break;
+ case L'u':
+ csBCaption = "diamond";
+ break;
+ case L'n':
+ csBCaption = "square";
+ break;
+ case L'H':
+ csBCaption = "star";
+ break;
+ default: //L'4'
+ csBCaption = "check";
+ break;
+ }
+ vp << csBCaption;
+ }
+
+ return TRUE;
+}
+
+void Field::SetStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_ByteString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::submitName(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::textColor(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CJS_Array crArray(m_isolate);
+ if (!vp.IsArrayObject())return FALSE;
+ vp >> crArray;
+
+ CPWL_Color color;
+ color::ConvertArrayToPWLColor(crArray, color);
+
+ if (m_bDelay)
+ {
+ AddDelay_Color(FP_TEXTCOLOR, color);
+ }
+ else
+ {
+ Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ int iColorType;
+ FX_ARGB color;
+ CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
+ FieldAppearance.GetColor(color, iColorType);
+ FX_INT32 a,r,g,b;
+ ArgbDecode(color, a, r, g, b);
+
+ CPWL_Color crRet = CPWL_Color(COLORTYPE_RGB, r / 255.0f,
+ g / 255.0f,
+ b / 255.0f);
+
+ if (iColorType == COLORTYPE_TRANSPARENT)
+ crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
+
+ CJS_Array crArray(m_isolate);
+ color::ConvertPWLColorToArray(crRet, crArray);
+ vp << crArray;
+ }
+
+ return TRUE;
+}
+
+void Field::SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::textFont(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString csFontName;
+ vp >> csFontName;
+ if (csFontName.IsEmpty()) return FALSE;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_TEXTFONT, csFontName);
+ }
+ else
+ {
+ Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex, csFontName);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ int nFieldType = pFormField->GetFieldType();
+
+ if (nFieldType == FIELDTYPE_PUSHBUTTON ||
+ nFieldType == FIELDTYPE_COMBOBOX ||
+ nFieldType == FIELDTYPE_LISTBOX ||
+ nFieldType == FIELDTYPE_TEXTFIELD)
+ {
+ CPDF_Font * pFont = pFormControl->GetDefaultControlFont();
+ if (!pFont) return FALSE;
+
+ vp << pFont->GetBaseFont();
+ }
+ else
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void Field::SetTextFont(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::textSize(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_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_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
+
+ CFX_ByteString csFontNameTag;
+ FX_FLOAT fFontSize;
+ FieldAppearance.GetFont(csFontNameTag,fFontSize);
+
+ vp << (int)fFontSize;
+ }
+
+ return TRUE;
+}
+
+void Field::SetTextSize(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::type(OBJ_PROP_PARAMS)
+{
+ 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 << (FX_LPCWSTR)L"unknown";
+ break;
+ case FIELDTYPE_PUSHBUTTON:
+ vp << (FX_LPCWSTR)L"button";
+ break;
+ case FIELDTYPE_CHECKBOX:
+ vp << (FX_LPCWSTR)L"checkbox";
+ break;
+ case FIELDTYPE_RADIOBUTTON:
+ vp << (FX_LPCWSTR)L"radiobutton";
+ break;
+ case FIELDTYPE_COMBOBOX:
+ vp << (FX_LPCWSTR)L"combobox";
+ break;
+ case FIELDTYPE_LISTBOX:
+ vp << (FX_LPCWSTR)L"listbox";
+ break;
+ case FIELDTYPE_TEXTFIELD:
+ vp << (FX_LPCWSTR)L"text";
+ break;
+ case FIELDTYPE_SIGNATURE:
+ vp << (FX_LPCWSTR)L"signature";
+ break;
+ default :
+ vp << (FX_LPCWSTR)L"unknown";
+ break;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::userName(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ 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;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ vp << (CFX_WideString)pFormField->GetAlternateName();
+ }
+
+ return TRUE;
+}
+
+void Field::SetUserName(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::value(OBJ_PROP_PARAMS)
+{
+ 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.operator CFX_WideString());
+ }
+ }
+ 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,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);
+ if (FXSYS_wcslen((FX_LPCWSTR)ElementValue.operator CFX_WideString()) == 0)
+ ElementValue = pFormField->GetOptionLabel(iIndex);
+ ValueArray.SetElement(i, ElementValue);
+ }
+ vp << ValueArray;
+ }
+ else
+ {
+ CFX_WideString swValue = pFormField->GetValue();
+
+ double dRet;
+ FX_BOOL bDot;
+ if (CJS_PublicMethods::ConvertStringToNumber(swValue,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,dRet,bDot))
+ {
+ if (bDot)
+ vp << dRet;
+ else
+ vp << dRet;
+ }
+ else
+ vp << swValue;
+
+ bFind = TRUE;
+ break;
+ }
+ else
+ continue;
+ }
+ if (!bFind)
+ vp << (FX_LPCWSTR)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;
+ }
+ }
+}
+
+FX_BOOL Field::valueAsString(OBJ_PROP_PARAMS)
+{
+ 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 << (FX_LPCWSTR)L"Yes";
+ else
+ vp << (FX_LPCWSTR)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 << (FX_LPCWSTR)pFormField->GetControl(i)->GetExportValue();
+ break;
+ }
+ else
+ vp << (FX_LPCWSTR)L"Off";
+ }
+ }
+ else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && (pFormField->CountSelectedItems() > 1))
+ {
+ vp << (FX_LPCWSTR)L"";
+ }
+ else
+ vp << (FX_LPCWSTR)pFormField->GetValue();
+
+ return TRUE;
+}
+
+/* --------------------------------- methods --------------------------------- */
+
+FX_BOOL Field::browseForFileToSubmit(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ 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);
+ }
+ }
+ else
+ return FALSE;
+
+ return TRUE;
+}
+
+
+FX_BOOL Field::buttonGetCaption(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nface = 0;
+ int iSize = params.size();
+ if ( iSize >= 1)
+ nface = (FX_INT32) params[0];
+
+ 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;
+
+ if (nface == 0)
+ vRet = pFormControl->GetNormalCaption();
+ else if (nface == 1)
+ vRet = pFormControl->GetDownCaption();
+ else if (nface == 2)
+ vRet = pFormControl->GetRolloverCaption();
+ else
+ return FALSE;
+
+ return TRUE;
+}
+
+//#pragma warning(disable: 4800)
+
+FX_BOOL Field::buttonGetIcon(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nface = 0;
+ int iSize = params.size();
+ if ( iSize >= 1)
+ nface = (FX_INT32) params[0];
+
+ 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;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ 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);
+
+ 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;
+
+ pIcon->SetStream(pIconStream);
+ vRet = pJS_Icon;
+
+ return TRUE;
+}
+
+//#pragma warning(default: 4800)
+
+FX_BOOL Field::buttonImportIcon(OBJ_METHOD_PARAMS)
+{
+#if 0
+ 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)return FALSE;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv);
+
+ CFX_WideString sIconFileName = pEnv->JS_fieldBrowse();
+ if (sIconFileName.IsEmpty())
+ {
+ vRet = 1;
+ return TRUE;
+ }
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_Stream* pStream = pInterForm->LoadImageFromFile(sIconFileName);
+ if (!pStream)
+ {
+ vRet = -1;
+ return TRUE;
+ }
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ pFormControl->SetNormalIcon(pStream);
+ UpdateFormControl(m_pDocument, pFormControl, TRUE, TRUE, TRUE);
+
+ vRet = 0;
+#endif // 0
+ return TRUE;
+}
+
+FX_BOOL Field::buttonSetCaption(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::buttonSetIcon(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::checkThisBox(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_bCanSet) return FALSE;
+
+ int iSize = params.size();
+ int nWidget = -1;
+ if ( iSize >= 1)
+ nWidget= (FX_INT32) params[0];
+ else
+ return FALSE;
+ FX_BOOL bCheckit = TRUE;
+ if ( iSize >= 2)
+ bCheckit = params[1];
+
+
+ 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(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;
+}
+
+FX_BOOL Field::clearItems(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::defaultIsChecked(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_bCanSet) return FALSE;
+
+ int iSize = params.size();
+ int nWidget = -1;
+ if ( iSize >= 1)
+ nWidget= (FX_INT32) params[0];
+ else
+ return FALSE;
+ //FX_BOOL bIsDefaultChecked = TRUE;
+ //if ( iSize >= 2)
+ // bIsDefaultChecked = params[1];
+
+ 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(nWidget <0 || nWidget >= pFormField->CountControls())
+ {
+ vRet = FALSE;
+ return FALSE;
+ }
+ if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
+ || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
+ {
+
+ vRet = TRUE;
+ }
+ else
+ vRet = FALSE;
+
+ return TRUE;
+}
+
+FX_BOOL Field::deleteItemAt(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2)
+{
+ ASSERT(ps1 != NULL);
+ ASSERT(ps2 != NULL);
+
+ return ps1->Compare(*ps2);
+}
+
+
+FX_BOOL Field::getArray(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ 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);
+
+ swSort.Add(new CFX_WideString(pFormField->GetFullName()));
+
+ }
+ swSort.Sort(JS_COMPARESTRING);
+
+ 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);
+
+ 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);
+
+ Field* pField = (Field*)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
+
+ pField->AttachField(this->m_pJSDoc, *pStr);
+
+ CJS_Value FormFieldValue(m_isolate);
+ FormFieldValue = pJSField;
+ FormFieldArray.SetElement(j, FormFieldValue);
+
+ delete pStr;
+ }
+
+ vRet = FormFieldArray;
+ swSort.RemoveAll();
+ return TRUE;
+}
+
+FX_BOOL Field::getItemAt(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nIdx = -1;
+ if (params.size() >=1)
+ nIdx = (FX_INT32) params[0];
+ FX_BOOL bExport = TRUE;
+ int iSize = params.size();
+ if ( iSize >= 2)
+ {
+ bExport =(FX_BOOL) params[1];
+ }
+
+ 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);
+ else
+ vRet = strval;
+ }
+ else
+ vRet = pFormField->GetOptionLabel(nIdx);
+ }
+ else
+ return FALSE;
+
+ return TRUE;
+}
+
+FX_BOOL Field::getLock(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::insertItemAt(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::isBoxChecked(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nIndex = -1;
+ if (params.size() >=1)
+ nIndex = (FX_INT32) params[0];
+
+ 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(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;
+
+ return TRUE;
+}
+
+FX_BOOL Field::isDefaultChecked(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nIndex = -1;
+ if (params.size() >=1)
+ nIndex = (FX_INT32) params[0];
+
+ 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(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;
+}
+
+FX_BOOL Field::setAction(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::setFocus(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ FX_INT32 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 (FX_INT32 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(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::setLock(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureGetModifications(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureGetSeedValue(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureInfo(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureSetSeedValue(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureSign(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureValidate(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::source(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << (CJS_Object*)NULL;
+ }
+
+ return TRUE;
+}
+
+/////////////////////////////////////////// delay /////////////////////////////////////////////
+
+void Field::AddDelay_Int(enum FIELD_PROP prop, FX_INT32 n)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->num = n;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_Bool(enum FIELD_PROP prop,bool b)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->b = b;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_String(enum FIELD_PROP prop, const CFX_ByteString& string)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->string = string;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_WideString(enum FIELD_PROP prop, const CFX_WideString& string)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->widestring = string;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->rect = rect;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->color = color;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_WordArray(enum FIELD_PROP prop, const CFX_DWordArray& array)
+{
+ 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->wordarray.Add(array.GetAt(i));
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_WideStringArray(enum FIELD_PROP prop, const CJS_WideStringArray& array)
+{
+ 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));
+
+ 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
+
+void Field::AddField(CPDFSDK_Document* pDocument, int nPageIndex, int nFieldType,
+ const CFX_WideString& sName, const CPDF_Rect& rcCoords)
+{
+ //Not supported.
+}
+
diff --git a/fpdfsdk/src/javascript/Icon.cpp b/fpdfsdk/src/javascript/Icon.cpp
index 418fcd53d5..286980c205 100644
--- a/fpdfsdk/src/javascript/Icon.cpp
+++ b/fpdfsdk/src/javascript/Icon.cpp
@@ -1,67 +1,67 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Icon.h"
-
-/* ---------------------- Icon ---------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Icon)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Icon)
- JS_STATIC_PROP_ENTRY(name)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Icon)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Icon,Icon)
-
-Icon::Icon(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
- m_pIconStream(NULL),
- m_swIconName(L"")
-{
-}
-
-Icon::~Icon()
-{
-
-}
-
-void Icon::SetStream(CPDF_Stream* pIconStream)
-{
- if(pIconStream)
- m_pIconStream = pIconStream;
-}
-
-CPDF_Stream* Icon::GetStream()
-{
- return m_pIconStream;
-}
-
-void Icon::SetIconName(CFX_WideString name)
-{
- m_swIconName = name;
-}
-
-CFX_WideString Icon::GetIconName()
-{
- return m_swIconName;
-}
-
-FX_BOOL Icon::name(OBJ_PROP_PARAMS)
-{
- if(!vp.IsGetting())return FALSE;
-
- vp << m_swIconName;
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Icon.h"
+
+/* ---------------------- Icon ---------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Icon)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Icon)
+ JS_STATIC_PROP_ENTRY(name)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Icon)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Icon,Icon)
+
+Icon::Icon(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
+ m_pIconStream(NULL),
+ m_swIconName(L"")
+{
+}
+
+Icon::~Icon()
+{
+
+}
+
+void Icon::SetStream(CPDF_Stream* pIconStream)
+{
+ if(pIconStream)
+ m_pIconStream = pIconStream;
+}
+
+CPDF_Stream* Icon::GetStream()
+{
+ return m_pIconStream;
+}
+
+void Icon::SetIconName(CFX_WideString name)
+{
+ m_swIconName = name;
+}
+
+CFX_WideString Icon::GetIconName()
+{
+ return m_swIconName;
+}
+
+FX_BOOL Icon::name(OBJ_PROP_PARAMS)
+{
+ if(!vp.IsGetting())return FALSE;
+
+ vp << m_swIconName;
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp
index c0d4e0847e..e34ffb51ba 100644
--- a/fpdfsdk/src/javascript/JS_Context.cpp
+++ b/fpdfsdk/src/javascript/JS_Context.cpp
@@ -1,364 +1,364 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-//#include "../../include/javascript/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/resource.h"
-
-/* -------------------------- CJS_Context -------------------------- */
-
-CJS_Context::CJS_Context(CJS_Runtime* pRuntime) :
- m_pRuntime(pRuntime),
- m_bBusy(FALSE),
- m_bMsgBoxEnable(TRUE)
-{
- m_pEventHandler = new CJS_EventHandler(this);
-}
-
-CJS_Context::~CJS_Context(void)
-{
- if (m_pEventHandler)
- {
- delete m_pEventHandler;
- m_pEventHandler = NULL;
- }
-}
-
-CPDFSDK_Document* CJS_Context::GetReaderDocument()
-{
- ASSERT(m_pRuntime != NULL);
-
- return m_pRuntime->GetReaderDocument();
-}
-
-CPDFDoc_Environment* CJS_Context::GetReaderApp()
-{
- ASSERT(m_pRuntime != NULL);
-
- return m_pRuntime->GetReaderApp();
-}
-
-FX_BOOL CJS_Context::DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info)
-{
- if (m_bBusy)
- {
- info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
- return FALSE;
- }
-
- m_bBusy = TRUE;
-
- ASSERT(m_pRuntime != NULL);
- ASSERT(m_pEventHandler != NULL);
- ASSERT(m_pEventHandler->IsValid());
-
- if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType()))
- {
- info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
- return FALSE;
- }
-
- FXJSErr error ={NULL,NULL, 0};
- int nRet = 0;
-
- try
- {
- if (script.GetLength() > 0)
- {
- if (nMode == 0)
- {
- nRet = JS_Execute(*m_pRuntime, this, script, script.GetLength(), &error);
- }
- else
- {
- nRet = JS_Parse(*m_pRuntime, this, script, script.GetLength(), &error);
- }
- }
-
- if (nRet < 0)
- {
- CFX_WideString sLine;
- sLine.Format((FX_LPCWSTR)L"[ Line: %05d { %s } ] : %s",error.linnum-1,error.srcline,error.message);
-
-// TRACE(L"/* -------------- JS Error -------------- */\n");
-// TRACE(sLine);
-// TRACE(L"\n");
- //CFX_ByteString sTemp = CFX_ByteString::FromUnicode(error.message);
- info += sLine;
- }
- else
- {
- info = JSGetStringFromID(this, IDS_STRING_RUN);
- }
-
- }
- catch (...)
- {
- info = JSGetStringFromID(this, IDS_STRING_UNHANDLED);
- nRet = -1;
- }
-
- m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType());
-
- m_pEventHandler->Destroy();
- m_bBusy = FALSE;
-
- return nRet >= 0;
-}
-
-FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString& info)
-{
- v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
- v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
- v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
- v8::Context::Scope context_scope(context);
-
- return DoJob(0, script, info);
-}
-
-FX_BOOL CJS_Context::Compile(const CFX_WideString& script, CFX_WideString& info)
-{
- v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
- v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
- v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
- v8::Context::Scope context_scope(context);
-
- return DoJob(1, script, info);
-}
-
-void CJS_Context::OnApp_Init()
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnApp_Init();
-}
-
-void CJS_Context::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString &strTargetName)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_Open(pDoc,strTargetName);
-}
-
-void CJS_Context::OnDoc_WillPrint(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_WillPrint(pDoc);
-}
-
-void CJS_Context::OnDoc_DidPrint(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_DidPrint(pDoc);
-}
-
-void CJS_Context::OnDoc_WillSave(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_WillSave(pDoc);
-}
-
-void CJS_Context::OnDoc_DidSave(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_DidSave(pDoc);
-}
-
-void CJS_Context::OnDoc_WillClose(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_WillClose(pDoc);
-}
-
-void CJS_Context::OnPage_Open(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnPage_Open(pTarget);
-}
-
-void CJS_Context::OnPage_Close(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnPage_Close(pTarget);
-}
-
-void CJS_Context::OnPage_InView(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnPage_InView(pTarget);
-}
-
-void CJS_Context::OnPage_OutView(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnPage_OutView(pTarget);
-}
-
-void CJS_Context::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget);
-}
-
-void CJS_Context::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget);
-}
-
-void CJS_Context::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget);
-}
-
-void CJS_Context::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget);
-}
-
-void CJS_Context::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value);
-}
-
-void CJS_Context::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value);
-}
-
-void CJS_Context::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc);
-}
-
-void CJS_Context::OnField_Format(int nCommitKey, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Format(nCommitKey, pTarget, Value, bWillCommit);
-}
-
-
-void CJS_Context::OnField_Keystroke(int nCommitKey, CFX_WideString& strChange, const CFX_WideString& strChangeEx,
- FX_BOOL bKeyDown, 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)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Keystroke(nCommitKey, strChange, strChangeEx, bKeyDown,
- bModifier, nSelEnd, nSelStart, bShift, pTarget, Value, bWillCommit, bFieldFull, bRc);
-}
-
-void CJS_Context::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)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bModifier, bShift, pTarget, Value, bRc);
-}
-
-void CJS_Context::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnBookmark_MouseUp(pBookMark);
-}
-
-void CJS_Context::OnLink_MouseUp(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnLink_MouseUp(pTarget);
-}
-
-void CJS_Context::OnConsole_Exec()
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnConsole_Exec();
-}
-
-void CJS_Context::OnExternal_Exec()
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnExternal_Exec();
-}
-
-void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnBatchExec(pTarget);
-}
-
-void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget,const CFX_WideString& strTargetName)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnMenu_Exec(pTarget, strTargetName);
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+//#include "../../include/javascript/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/resource.h"
+
+/* -------------------------- CJS_Context -------------------------- */
+
+CJS_Context::CJS_Context(CJS_Runtime* pRuntime) :
+ m_pRuntime(pRuntime),
+ m_bBusy(FALSE),
+ m_bMsgBoxEnable(TRUE)
+{
+ m_pEventHandler = new CJS_EventHandler(this);
+}
+
+CJS_Context::~CJS_Context(void)
+{
+ if (m_pEventHandler)
+ {
+ delete m_pEventHandler;
+ m_pEventHandler = NULL;
+ }
+}
+
+CPDFSDK_Document* CJS_Context::GetReaderDocument()
+{
+ ASSERT(m_pRuntime != NULL);
+
+ return m_pRuntime->GetReaderDocument();
+}
+
+CPDFDoc_Environment* CJS_Context::GetReaderApp()
+{
+ ASSERT(m_pRuntime != NULL);
+
+ return m_pRuntime->GetReaderApp();
+}
+
+FX_BOOL CJS_Context::DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info)
+{
+ if (m_bBusy)
+ {
+ info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
+ return FALSE;
+ }
+
+ m_bBusy = TRUE;
+
+ ASSERT(m_pRuntime != NULL);
+ ASSERT(m_pEventHandler != NULL);
+ ASSERT(m_pEventHandler->IsValid());
+
+ if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType()))
+ {
+ info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
+ return FALSE;
+ }
+
+ FXJSErr error ={NULL,NULL, 0};
+ int nRet = 0;
+
+ try
+ {
+ if (script.GetLength() > 0)
+ {
+ if (nMode == 0)
+ {
+ nRet = JS_Execute(*m_pRuntime, this, script, script.GetLength(), &error);
+ }
+ else
+ {
+ nRet = JS_Parse(*m_pRuntime, this, script, script.GetLength(), &error);
+ }
+ }
+
+ if (nRet < 0)
+ {
+ CFX_WideString sLine;
+ sLine.Format((FX_LPCWSTR)L"[ Line: %05d { %s } ] : %s",error.linnum-1,error.srcline,error.message);
+
+// TRACE(L"/* -------------- JS Error -------------- */\n");
+// TRACE(sLine);
+// TRACE(L"\n");
+ //CFX_ByteString sTemp = CFX_ByteString::FromUnicode(error.message);
+ info += sLine;
+ }
+ else
+ {
+ info = JSGetStringFromID(this, IDS_STRING_RUN);
+ }
+
+ }
+ catch (...)
+ {
+ info = JSGetStringFromID(this, IDS_STRING_UNHANDLED);
+ nRet = -1;
+ }
+
+ m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType());
+
+ m_pEventHandler->Destroy();
+ m_bBusy = FALSE;
+
+ return nRet >= 0;
+}
+
+FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString& info)
+{
+ v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
+ v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
+ v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
+ v8::Context::Scope context_scope(context);
+
+ return DoJob(0, script, info);
+}
+
+FX_BOOL CJS_Context::Compile(const CFX_WideString& script, CFX_WideString& info)
+{
+ v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
+ v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
+ v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
+ v8::Context::Scope context_scope(context);
+
+ return DoJob(1, script, info);
+}
+
+void CJS_Context::OnApp_Init()
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnApp_Init();
+}
+
+void CJS_Context::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString &strTargetName)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_Open(pDoc,strTargetName);
+}
+
+void CJS_Context::OnDoc_WillPrint(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_WillPrint(pDoc);
+}
+
+void CJS_Context::OnDoc_DidPrint(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_DidPrint(pDoc);
+}
+
+void CJS_Context::OnDoc_WillSave(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_WillSave(pDoc);
+}
+
+void CJS_Context::OnDoc_DidSave(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_DidSave(pDoc);
+}
+
+void CJS_Context::OnDoc_WillClose(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_WillClose(pDoc);
+}
+
+void CJS_Context::OnPage_Open(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnPage_Open(pTarget);
+}
+
+void CJS_Context::OnPage_Close(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnPage_Close(pTarget);
+}
+
+void CJS_Context::OnPage_InView(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnPage_InView(pTarget);
+}
+
+void CJS_Context::OnPage_OutView(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnPage_OutView(pTarget);
+}
+
+void CJS_Context::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget);
+}
+
+void CJS_Context::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget);
+}
+
+void CJS_Context::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget);
+}
+
+void CJS_Context::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget);
+}
+
+void CJS_Context::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value);
+}
+
+void CJS_Context::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value);
+}
+
+void CJS_Context::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc);
+}
+
+void CJS_Context::OnField_Format(int nCommitKey, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Format(nCommitKey, pTarget, Value, bWillCommit);
+}
+
+
+void CJS_Context::OnField_Keystroke(int nCommitKey, CFX_WideString& strChange, const CFX_WideString& strChangeEx,
+ FX_BOOL bKeyDown, 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)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Keystroke(nCommitKey, strChange, strChangeEx, bKeyDown,
+ bModifier, nSelEnd, nSelStart, bShift, pTarget, Value, bWillCommit, bFieldFull, bRc);
+}
+
+void CJS_Context::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)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bModifier, bShift, pTarget, Value, bRc);
+}
+
+void CJS_Context::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnBookmark_MouseUp(pBookMark);
+}
+
+void CJS_Context::OnLink_MouseUp(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnLink_MouseUp(pTarget);
+}
+
+void CJS_Context::OnConsole_Exec()
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnConsole_Exec();
+}
+
+void CJS_Context::OnExternal_Exec()
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnExternal_Exec();
+}
+
+void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnBatchExec(pTarget);
+}
+
+void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget,const CFX_WideString& strTargetName)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnMenu_Exec(pTarget, strTargetName);
+}
+
diff --git a/fpdfsdk/src/javascript/JS_EventHandler.cpp b/fpdfsdk/src/javascript/JS_EventHandler.cpp
index ce69e6b9d2..76c6d37f03 100644
--- a/fpdfsdk/src/javascript/JS_EventHandler.cpp
+++ b/fpdfsdk/src/javascript/JS_EventHandler.cpp
@@ -1,676 +1,676 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_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"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/Field.h"
-
-/* ---------------------------- 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()
-{
-}
-
-void CJS_EventHandler::OnApp_Init()
-{
- Initial(JET_APP_INIT);
-}
-
-void CJS_EventHandler::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName)
-{
- Initial(JET_DOC_OPEN);
-
- m_pTargetDoc = pDoc;
- m_strTargetName = strTargetName;
-}
-
-void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_WILLPRINT);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_DIDPRINT);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnDoc_WillSave(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_WILLSAVE);
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnDoc_DidSave(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_DIDSAVE);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_WILLCLOSE);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc)
-{
- Initial(JET_PAGE_OPEN);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc)
-{
- Initial(JET_PAGE_CLOSE);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc)
-{
- Initial(JET_PAGE_INVIEW);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc)
-{
- Initial(JET_PAGE_OUTVIEW);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
-{
- Initial(JET_FIELD_MOUSEENTER);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
-
- 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);
-
- 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;
-
- 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);
-
- 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)
-{
- Initial(JET_FIELD_FOCUS);
-
- 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)
-{
- Initial(JET_FIELD_BLUR);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = (CFX_WideString*)&Value;
-}
-
-void CJS_EventHandler::OnField_Keystroke(int nCommitKey, 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 = nCommitKey;
- 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;
-}
-
-void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget,
- CFX_WideString& Value, FX_BOOL& bRc)
-{
- Initial(JET_FIELD_CALCULATE);
-
- if (pSource)
- m_strSourceName = pSource->GetFullName();
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = &Value;
- m_pbRc = &bRc;
-}
-
-void CJS_EventHandler::OnField_Format(int nCommitKey, CPDF_FormField* pTarget,
- CFX_WideString& Value, FX_BOOL bWillCommit)
-{
- Initial(JET_FIELD_FORMAT);
-
- m_nCommitKey = nCommitKey;
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget)
-{
- Initial(JET_LINK_MOUSEUP);
-
- m_pTargetDoc = pTarget;
-}
-
-void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
-{
- Initial(JET_BOOKMARK_MOUSEUP);
-
- m_pTargetBookMark = pBookMark;
-}
-
-void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName)
-{
- Initial(JET_MENU_EXEC);
-
- m_pTargetDoc = pTarget;
- m_strTargetName = strTargetName;
-}
-
-void CJS_EventHandler::OnExternal_Exec()
-{
- Initial(JET_EXTERNAL_EXEC);
-}
-
-void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget)
-{
- Initial(JET_BATCH_EXEC);
-
- m_pTargetDoc = pTarget;
-}
-
-void CJS_EventHandler::OnConsole_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;
-}
-
-void CJS_EventHandler::Destroy()
-{
- m_bValid = FALSE;
-}
-
-FX_BOOL CJS_EventHandler::IsValid()
-{
- return m_bValid;
-}
-
-CFX_WideString & CJS_EventHandler::Change()
-{
- if (m_pWideStrChange != NULL)
- return *m_pWideStrChange;
- else
- {
- return m_WideStrChangeDu;
- }
-}
-
-CFX_WideString CJS_EventHandler::ChangeEx()
-{
- return m_WideStrChangeEx;
-}
-
-int CJS_EventHandler::CommitKey()
-{
- return m_nCommitKey;
-}
-
-FX_BOOL CJS_EventHandler::FieldFull()
-{
- return m_bFieldFull;
-}
-
-FX_BOOL CJS_EventHandler::KeyDown()
-{
- return m_bKeyDown;
-}
-
-FX_BOOL CJS_EventHandler::Modifier()
-{
- return m_bModifier;
-}
-
-FX_LPCWSTR CJS_EventHandler::Name()
-{
- switch (m_eEventType)
- {
- case JET_APP_INIT: return (FX_LPCWSTR)L"Init";
- case JET_BATCH_EXEC: return (FX_LPCWSTR)L"Exec";
- case JET_BOOKMARK_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
- case JET_CONSOLE_EXEC: return (FX_LPCWSTR)L"Exec";
- case JET_DOC_DIDPRINT: return (FX_LPCWSTR)L"DidPrint";
- case JET_DOC_DIDSAVE: return (FX_LPCWSTR)L"DidSave";
- case JET_DOC_OPEN: return (FX_LPCWSTR)L"Open";
- case JET_DOC_WILLCLOSE: return (FX_LPCWSTR)L"WillClose";
- case JET_DOC_WILLPRINT: return (FX_LPCWSTR)L"WillPrint";
- case JET_DOC_WILLSAVE: return (FX_LPCWSTR)L"WillSave";
- case JET_EXTERNAL_EXEC: return (FX_LPCWSTR)L"Exec";
- case JET_FIELD_FOCUS:
- case JET_SCREEN_FOCUS: return (FX_LPCWSTR)L"Focus";
- case JET_FIELD_BLUR:
- case JET_SCREEN_BLUR: return (FX_LPCWSTR)L"Blur";
- case JET_FIELD_MOUSEDOWN:
- case JET_SCREEN_MOUSEDOWN: return (FX_LPCWSTR)L"Mouse Down";
- case JET_FIELD_MOUSEUP:
- case JET_SCREEN_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
- case JET_FIELD_MOUSEENTER:
- case JET_SCREEN_MOUSEENTER: return (FX_LPCWSTR)L"Mouse Enter";
- case JET_FIELD_MOUSEEXIT:
- case JET_SCREEN_MOUSEEXIT: return (FX_LPCWSTR)L"Mouse Exit";
- case JET_FIELD_CALCULATE: return (FX_LPCWSTR)L"Calculate";
- case JET_FIELD_FORMAT: return (FX_LPCWSTR)L"Format";
- case JET_FIELD_KEYSTROKE: return (FX_LPCWSTR)L"Keystroke";
- case JET_FIELD_VALIDATE: return (FX_LPCWSTR)L"Validate";
- case JET_LINK_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
- case JET_MENU_EXEC: return (FX_LPCWSTR)L"Exec";
- case JET_PAGE_OPEN:
- case JET_SCREEN_OPEN: return (FX_LPCWSTR)L"Open";
- case JET_PAGE_CLOSE:
- case JET_SCREEN_CLOSE: return (FX_LPCWSTR)L"Close";
- case JET_SCREEN_INVIEW:
- case JET_PAGE_INVIEW: return (FX_LPCWSTR)L"InView";
- case JET_PAGE_OUTVIEW:
- case JET_SCREEN_OUTVIEW: return (FX_LPCWSTR)L"OutView";
- default:
- return (FX_LPCWSTR)L"";
- }
-
- return (FX_LPCWSTR)L"";
-}
-
-FX_LPCWSTR CJS_EventHandler::Type()
-{
- switch (m_eEventType)
- {
- case JET_APP_INIT: return (FX_LPCWSTR)L"App";
- case JET_BATCH_EXEC: return (FX_LPCWSTR)L"Batch";
- case JET_BOOKMARK_MOUSEUP: return (FX_LPCWSTR)L"BookMark";
- case JET_CONSOLE_EXEC: return (FX_LPCWSTR)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 (FX_LPCWSTR)L"Doc";
- case JET_EXTERNAL_EXEC: return (FX_LPCWSTR)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 (FX_LPCWSTR)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 (FX_LPCWSTR)L"Screen";
- case JET_LINK_MOUSEUP: return (FX_LPCWSTR)L"Link";
- case JET_MENU_EXEC: return (FX_LPCWSTR)L"Menu";
- case JET_PAGE_OPEN:
- case JET_PAGE_CLOSE:
- case JET_PAGE_INVIEW:
- case JET_PAGE_OUTVIEW:return (FX_LPCWSTR)L"Page";
- default:
- return (FX_LPCWSTR)L"";
- }
-
- return (FX_LPCWSTR)L"";
-}
-
-FX_BOOL& CJS_EventHandler::Rc()
-{
- if (m_pbRc != NULL)
- return *m_pbRc;
- else
- {
- return m_bRcDu;
- }
-}
-
-int & CJS_EventHandler::SelEnd()
-{
- if (m_pISelEnd != NULL)
- {
- return *m_pISelEnd;
- }
- else
- {
- return m_nSelEndDu;
- }
-}
-
-int & CJS_EventHandler::SelStart()
-{
- if (m_pISelStart != NULL)
- return * m_pISelStart;
- else
- {
- return m_nSelStartDu;
- }
-}
-
-FX_BOOL CJS_EventHandler::Shift()
-{
- 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;
-}
-
-Field* CJS_EventHandler::Target_Field()
-{
- 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());
-
- CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
- ASSERT(pJSField != NULL);
-
- Field* pField = (Field *)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
-
- pField->AttachField(pDocument, m_strTargetName);
- return pField;
-}
-
-CFX_WideString& CJS_EventHandler::Value()
-{
- return *m_pValue;
-}
-
-FX_BOOL CJS_EventHandler::WillCommit()
-{
- return m_bWillCommit;
-}
-
-CFX_WideString CJS_EventHandler::TargetName()
-{
- return m_strTargetName;
-}
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_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"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/Field.h"
+
+/* ---------------------------- 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()
+{
+}
+
+void CJS_EventHandler::OnApp_Init()
+{
+ Initial(JET_APP_INIT);
+}
+
+void CJS_EventHandler::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName)
+{
+ Initial(JET_DOC_OPEN);
+
+ m_pTargetDoc = pDoc;
+ m_strTargetName = strTargetName;
+}
+
+void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_WILLPRINT);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_DIDPRINT);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_WillSave(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_WILLSAVE);
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_DidSave(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_DIDSAVE);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_WILLCLOSE);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_PAGE_OPEN);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_PAGE_CLOSE);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_PAGE_INVIEW);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_PAGE_OUTVIEW);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
+{
+ Initial(JET_FIELD_MOUSEENTER);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+
+ 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);
+
+ 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;
+
+ 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);
+
+ 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)
+{
+ Initial(JET_FIELD_FOCUS);
+
+ 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)
+{
+ Initial(JET_FIELD_BLUR);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = (CFX_WideString*)&Value;
+}
+
+void CJS_EventHandler::OnField_Keystroke(int nCommitKey, 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 = nCommitKey;
+ 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;
+}
+
+void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget,
+ CFX_WideString& Value, FX_BOOL& bRc)
+{
+ Initial(JET_FIELD_CALCULATE);
+
+ if (pSource)
+ m_strSourceName = pSource->GetFullName();
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = &Value;
+ m_pbRc = &bRc;
+}
+
+void CJS_EventHandler::OnField_Format(int nCommitKey, CPDF_FormField* pTarget,
+ CFX_WideString& Value, FX_BOOL bWillCommit)
+{
+ Initial(JET_FIELD_FORMAT);
+
+ m_nCommitKey = nCommitKey;
+ 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);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget)
+{
+ Initial(JET_LINK_MOUSEUP);
+
+ m_pTargetDoc = pTarget;
+}
+
+void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
+{
+ Initial(JET_BOOKMARK_MOUSEUP);
+
+ m_pTargetBookMark = pBookMark;
+}
+
+void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName)
+{
+ Initial(JET_MENU_EXEC);
+
+ m_pTargetDoc = pTarget;
+ m_strTargetName = strTargetName;
+}
+
+void CJS_EventHandler::OnExternal_Exec()
+{
+ Initial(JET_EXTERNAL_EXEC);
+}
+
+void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget)
+{
+ Initial(JET_BATCH_EXEC);
+
+ m_pTargetDoc = pTarget;
+}
+
+void CJS_EventHandler::OnConsole_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;
+}
+
+void CJS_EventHandler::Destroy()
+{
+ m_bValid = FALSE;
+}
+
+FX_BOOL CJS_EventHandler::IsValid()
+{
+ return m_bValid;
+}
+
+CFX_WideString & CJS_EventHandler::Change()
+{
+ if (m_pWideStrChange != NULL)
+ return *m_pWideStrChange;
+ else
+ {
+ return m_WideStrChangeDu;
+ }
+}
+
+CFX_WideString CJS_EventHandler::ChangeEx()
+{
+ return m_WideStrChangeEx;
+}
+
+int CJS_EventHandler::CommitKey()
+{
+ return m_nCommitKey;
+}
+
+FX_BOOL CJS_EventHandler::FieldFull()
+{
+ return m_bFieldFull;
+}
+
+FX_BOOL CJS_EventHandler::KeyDown()
+{
+ return m_bKeyDown;
+}
+
+FX_BOOL CJS_EventHandler::Modifier()
+{
+ return m_bModifier;
+}
+
+FX_LPCWSTR CJS_EventHandler::Name()
+{
+ switch (m_eEventType)
+ {
+ case JET_APP_INIT: return (FX_LPCWSTR)L"Init";
+ case JET_BATCH_EXEC: return (FX_LPCWSTR)L"Exec";
+ case JET_BOOKMARK_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
+ case JET_CONSOLE_EXEC: return (FX_LPCWSTR)L"Exec";
+ case JET_DOC_DIDPRINT: return (FX_LPCWSTR)L"DidPrint";
+ case JET_DOC_DIDSAVE: return (FX_LPCWSTR)L"DidSave";
+ case JET_DOC_OPEN: return (FX_LPCWSTR)L"Open";
+ case JET_DOC_WILLCLOSE: return (FX_LPCWSTR)L"WillClose";
+ case JET_DOC_WILLPRINT: return (FX_LPCWSTR)L"WillPrint";
+ case JET_DOC_WILLSAVE: return (FX_LPCWSTR)L"WillSave";
+ case JET_EXTERNAL_EXEC: return (FX_LPCWSTR)L"Exec";
+ case JET_FIELD_FOCUS:
+ case JET_SCREEN_FOCUS: return (FX_LPCWSTR)L"Focus";
+ case JET_FIELD_BLUR:
+ case JET_SCREEN_BLUR: return (FX_LPCWSTR)L"Blur";
+ case JET_FIELD_MOUSEDOWN:
+ case JET_SCREEN_MOUSEDOWN: return (FX_LPCWSTR)L"Mouse Down";
+ case JET_FIELD_MOUSEUP:
+ case JET_SCREEN_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
+ case JET_FIELD_MOUSEENTER:
+ case JET_SCREEN_MOUSEENTER: return (FX_LPCWSTR)L"Mouse Enter";
+ case JET_FIELD_MOUSEEXIT:
+ case JET_SCREEN_MOUSEEXIT: return (FX_LPCWSTR)L"Mouse Exit";
+ case JET_FIELD_CALCULATE: return (FX_LPCWSTR)L"Calculate";
+ case JET_FIELD_FORMAT: return (FX_LPCWSTR)L"Format";
+ case JET_FIELD_KEYSTROKE: return (FX_LPCWSTR)L"Keystroke";
+ case JET_FIELD_VALIDATE: return (FX_LPCWSTR)L"Validate";
+ case JET_LINK_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
+ case JET_MENU_EXEC: return (FX_LPCWSTR)L"Exec";
+ case JET_PAGE_OPEN:
+ case JET_SCREEN_OPEN: return (FX_LPCWSTR)L"Open";
+ case JET_PAGE_CLOSE:
+ case JET_SCREEN_CLOSE: return (FX_LPCWSTR)L"Close";
+ case JET_SCREEN_INVIEW:
+ case JET_PAGE_INVIEW: return (FX_LPCWSTR)L"InView";
+ case JET_PAGE_OUTVIEW:
+ case JET_SCREEN_OUTVIEW: return (FX_LPCWSTR)L"OutView";
+ default:
+ return (FX_LPCWSTR)L"";
+ }
+
+ return (FX_LPCWSTR)L"";
+}
+
+FX_LPCWSTR CJS_EventHandler::Type()
+{
+ switch (m_eEventType)
+ {
+ case JET_APP_INIT: return (FX_LPCWSTR)L"App";
+ case JET_BATCH_EXEC: return (FX_LPCWSTR)L"Batch";
+ case JET_BOOKMARK_MOUSEUP: return (FX_LPCWSTR)L"BookMark";
+ case JET_CONSOLE_EXEC: return (FX_LPCWSTR)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 (FX_LPCWSTR)L"Doc";
+ case JET_EXTERNAL_EXEC: return (FX_LPCWSTR)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 (FX_LPCWSTR)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 (FX_LPCWSTR)L"Screen";
+ case JET_LINK_MOUSEUP: return (FX_LPCWSTR)L"Link";
+ case JET_MENU_EXEC: return (FX_LPCWSTR)L"Menu";
+ case JET_PAGE_OPEN:
+ case JET_PAGE_CLOSE:
+ case JET_PAGE_INVIEW:
+ case JET_PAGE_OUTVIEW:return (FX_LPCWSTR)L"Page";
+ default:
+ return (FX_LPCWSTR)L"";
+ }
+
+ return (FX_LPCWSTR)L"";
+}
+
+FX_BOOL& CJS_EventHandler::Rc()
+{
+ if (m_pbRc != NULL)
+ return *m_pbRc;
+ else
+ {
+ return m_bRcDu;
+ }
+}
+
+int & CJS_EventHandler::SelEnd()
+{
+ if (m_pISelEnd != NULL)
+ {
+ return *m_pISelEnd;
+ }
+ else
+ {
+ return m_nSelEndDu;
+ }
+}
+
+int & CJS_EventHandler::SelStart()
+{
+ if (m_pISelStart != NULL)
+ return * m_pISelStart;
+ else
+ {
+ return m_nSelStartDu;
+ }
+}
+
+FX_BOOL CJS_EventHandler::Shift()
+{
+ 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;
+}
+
+Field* CJS_EventHandler::Target_Field()
+{
+ 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());
+
+ CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
+ ASSERT(pJSField != NULL);
+
+ Field* pField = (Field *)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
+
+ pField->AttachField(pDocument, m_strTargetName);
+ return pField;
+}
+
+CFX_WideString& CJS_EventHandler::Value()
+{
+ return *m_pValue;
+}
+
+FX_BOOL CJS_EventHandler::WillCommit()
+{
+ return m_bWillCommit;
+}
+
+CFX_WideString CJS_EventHandler::TargetName()
+{
+ return m_strTargetName;
+}
+
+
diff --git a/fpdfsdk/src/javascript/JS_GlobalData.cpp b/fpdfsdk/src/javascript/JS_GlobalData.cpp
index 97bba8d243..2207726890 100644
--- a/fpdfsdk/src/javascript/JS_GlobalData.cpp
+++ b/fpdfsdk/src/javascript/JS_GlobalData.cpp
@@ -1,581 +1,581 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_GlobalData.h"
-
-#define JS_MAXGLOBALDATA (1024 * 4 - 8)
-
-/* --------------------- CJS_GlobalVariableArray --------------------- */
-
-CJS_GlobalVariableArray::CJS_GlobalVariableArray()
-{
-}
-
-CJS_GlobalVariableArray::~CJS_GlobalVariableArray()
-{
- 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);
- }
- }
- }
-}
-
-void CJS_GlobalVariableArray::Add(CJS_KeyValue* p)
-{
- array.Add(p);
-}
-
-int CJS_GlobalVariableArray::Count() const
-{
- return array.GetSize();
-}
-
-CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const
-{
- return array.GetAt(index);
-}
-
-void CJS_GlobalVariableArray::Empty()
-{
- 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"
-
-static const FX_BYTE 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
- };
-
-CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) : m_pApp(pApp)
-{
-// IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp);
-// ASSERT(pBaseAnnot != NULL);
-//
-// m_sFilePath = pBaseAnnot->GetUserPath();
- m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
-
- LoadGlobalPersistentVariables();
-}
-
-CJS_GlobalData::~CJS_GlobalData()
-{
- SaveGlobalPersisitentVariables();
-
- for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
- delete m_arrayGlobalData.GetAt(i);
-
- m_arrayGlobalData.RemoveAll();
-}
-
-int CJS_GlobalData::FindGlobalVariable(FX_LPCSTR propname)
-{
- ASSERT(propname != NULL);
-
- 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;
- }
- }
-
- return nRet;
-}
-
-CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(FX_LPCSTR propname)
-{
- ASSERT(propname != NULL);
-
- int nFind = FindGlobalVariable(propname);
-
- if (nFind >= 0)
- return m_arrayGlobalData.GetAt(nFind);
- else
- return NULL;
-}
-
-void CJS_GlobalData::SetGlobalVariableNumber(FX_LPCSTR 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);
- }
-}
-
-void CJS_GlobalData::SetGlobalVariableBoolean(FX_LPCSTR 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);
- }
-}
-
-void CJS_GlobalData::SetGlobalVariableString(FX_LPCSTR 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);
- }
-}
-
-void CJS_GlobalData::SetGlobalVariableObject(FX_LPCSTR 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);
- }
-}
-
-void CJS_GlobalData::SetGlobalVariableNull(FX_LPCSTR 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);
- }
-}
-
-FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(FX_LPCSTR propname, FX_BOOL bPersistent)
-{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return FALSE;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->bPersistent = bPersistent;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CJS_GlobalData::DeleteGlobalVariable(FX_LPCSTR propname)
-{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return FALSE;
-
- int nFind = FindGlobalVariable(sPropName);
-
- if (nFind >= 0)
- {
- delete m_arrayGlobalData.GetAt(nFind);
- m_arrayGlobalData.RemoveAt(nFind);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_INT32 CJS_GlobalData::GetSize() const
-{
- return m_arrayGlobalData.GetSize();
-}
-
-CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const
-{
- return m_arrayGlobalData.GetAt(index);
-}
-
-void CJS_GlobalData::LoadGlobalPersistentVariables()
-{
- FX_LPBYTE pBuffer = NULL;
- FX_INT32 nLength = 0;
-
- LoadFileBuffer(m_sFilePath, pBuffer, nLength);
-
- CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY));
-
- if (pBuffer)
- {
- FX_LPBYTE 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 (FX_INT32 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;
-};
-struct js_global_datafile_data
-{
- 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;
-
- 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 (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA)
- break;
-
- sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize());
- nCount++;
- }
- }
-
- 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));
-
- sFile.AppendBlock(sData.GetBuffer(), sData.GetSize());
-
- CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY, sizeof(JS_RC4KEY));
- WriteFileBuffer(m_sFilePath, (FX_LPCSTR)sFile.GetBuffer(), sFile.GetSize());
-}
-
-void CJS_GlobalData::LoadFileBuffer(FX_LPCWSTR sFilePath, FX_LPBYTE& pBuffer, FX_INT32& nLength)
-{
-//UnSupport.
-}
-
-void CJS_GlobalData::WriteFileBuffer(FX_LPCWSTR sFilePath, FX_LPCSTR pBuffer, FX_INT32 nLength)
-{
-//UnSupport.
-}
-
-void CJS_GlobalData::MakeByteString(const CFX_ByteString& name, CJS_KeyValue* pData, CFX_BinaryBuf& sData)
-{
- 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;
- }
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_GlobalData.h"
+
+#define JS_MAXGLOBALDATA (1024 * 4 - 8)
+
+/* --------------------- CJS_GlobalVariableArray --------------------- */
+
+CJS_GlobalVariableArray::CJS_GlobalVariableArray()
+{
+}
+
+CJS_GlobalVariableArray::~CJS_GlobalVariableArray()
+{
+ 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);
+ }
+ }
+ }
+}
+
+void CJS_GlobalVariableArray::Add(CJS_KeyValue* p)
+{
+ array.Add(p);
+}
+
+int CJS_GlobalVariableArray::Count() const
+{
+ return array.GetSize();
+}
+
+CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const
+{
+ return array.GetAt(index);
+}
+
+void CJS_GlobalVariableArray::Empty()
+{
+ 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"
+
+static const FX_BYTE 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
+ };
+
+CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) : m_pApp(pApp)
+{
+// IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp);
+// ASSERT(pBaseAnnot != NULL);
+//
+// m_sFilePath = pBaseAnnot->GetUserPath();
+ m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
+
+ LoadGlobalPersistentVariables();
+}
+
+CJS_GlobalData::~CJS_GlobalData()
+{
+ SaveGlobalPersisitentVariables();
+
+ for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
+ delete m_arrayGlobalData.GetAt(i);
+
+ m_arrayGlobalData.RemoveAll();
+}
+
+int CJS_GlobalData::FindGlobalVariable(FX_LPCSTR propname)
+{
+ ASSERT(propname != NULL);
+
+ 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;
+ }
+ }
+
+ return nRet;
+}
+
+CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(FX_LPCSTR propname)
+{
+ ASSERT(propname != NULL);
+
+ int nFind = FindGlobalVariable(propname);
+
+ if (nFind >= 0)
+ return m_arrayGlobalData.GetAt(nFind);
+ else
+ return NULL;
+}
+
+void CJS_GlobalData::SetGlobalVariableNumber(FX_LPCSTR 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);
+ }
+}
+
+void CJS_GlobalData::SetGlobalVariableBoolean(FX_LPCSTR 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);
+ }
+}
+
+void CJS_GlobalData::SetGlobalVariableString(FX_LPCSTR 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);
+ }
+}
+
+void CJS_GlobalData::SetGlobalVariableObject(FX_LPCSTR 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);
+ }
+}
+
+void CJS_GlobalData::SetGlobalVariableNull(FX_LPCSTR 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);
+ }
+}
+
+FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(FX_LPCSTR propname, FX_BOOL bPersistent)
+{
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return FALSE;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->bPersistent = bPersistent;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CJS_GlobalData::DeleteGlobalVariable(FX_LPCSTR propname)
+{
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return FALSE;
+
+ int nFind = FindGlobalVariable(sPropName);
+
+ if (nFind >= 0)
+ {
+ delete m_arrayGlobalData.GetAt(nFind);
+ m_arrayGlobalData.RemoveAt(nFind);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_INT32 CJS_GlobalData::GetSize() const
+{
+ return m_arrayGlobalData.GetSize();
+}
+
+CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const
+{
+ return m_arrayGlobalData.GetAt(index);
+}
+
+void CJS_GlobalData::LoadGlobalPersistentVariables()
+{
+ FX_LPBYTE pBuffer = NULL;
+ FX_INT32 nLength = 0;
+
+ LoadFileBuffer(m_sFilePath, pBuffer, nLength);
+
+ CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY));
+
+ if (pBuffer)
+ {
+ FX_LPBYTE 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 (FX_INT32 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;
+};
+struct js_global_datafile_data
+{
+ 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;
+
+ 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 (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA)
+ break;
+
+ sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize());
+ nCount++;
+ }
+ }
+
+ 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));
+
+ sFile.AppendBlock(sData.GetBuffer(), sData.GetSize());
+
+ CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY, sizeof(JS_RC4KEY));
+ WriteFileBuffer(m_sFilePath, (FX_LPCSTR)sFile.GetBuffer(), sFile.GetSize());
+}
+
+void CJS_GlobalData::LoadFileBuffer(FX_LPCWSTR sFilePath, FX_LPBYTE& pBuffer, FX_INT32& nLength)
+{
+//UnSupport.
+}
+
+void CJS_GlobalData::WriteFileBuffer(FX_LPCWSTR sFilePath, FX_LPCSTR pBuffer, FX_INT32 nLength)
+{
+//UnSupport.
+}
+
+void CJS_GlobalData::MakeByteString(const CFX_ByteString& name, CJS_KeyValue* pData, CFX_BinaryBuf& sData)
+{
+ 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_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp
index 3830b2ac53..3b7774d4d8 100644
--- a/fpdfsdk/src/javascript/JS_Object.cpp
+++ b/fpdfsdk/src/javascript/JS_Object.cpp
@@ -1,145 +1,145 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-// #include "../../include/javascript/JS_MsgBox.h"
-// #include "../../include/javascript/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-
-int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
-{
- int nRet = 0;
-
- if(pApp)
- {
- CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
- if(pDoc)
- pDoc->KillFocusAnnot();
- nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon);
- }
-
- return nRet;
-}
-
-CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc)
-{
- if (CJS_Context* pContext = (CJS_Context *)cc)
- {
- if (pContext->GetReaderDocument())
- return NULL;
- }
- return NULL;
-}
-
-/* --------------------------------- CJS_EmbedObj --------------------------------- */
-
-CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) :
- m_pJSObject(pJSObject)
-{
-}
-
-CJS_EmbedObj::~CJS_EmbedObj()
-{
- m_pJSObject = NULL;
-
-}
-
-CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc)
-{
- return FXJS_GetPageView(cc);
-}
-
-int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,FX_LPCWSTR swMsg,FX_LPCWSTR swTitle,FX_UINT nType,FX_UINT nIcon)
-{
- return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
-}
-
-void CJS_EmbedObj::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
-{
- CJS_Object::Alert(pContext, swMsg);
-}
-
-CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse)
-{
- CJS_Timer* pTimer = new CJS_Timer(this,pApp);
- pTimer->SetJSTimer(nElapse);
-
- return pTimer;
-}
-
-void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer)
-{
- ASSERT(pTimer != NULL);
- pTimer->KillJSTimer();
- delete pTimer;
-}
-
-FX_BOOL CJS_EmbedObj::IsSafeMode(IFXJS_Context* cc)
-{
- ASSERT(cc != NULL);
-
- return TRUE;
-}
-
-/* --------------------------------- CJS_Object --------------------------------- */
-void FreeObject(const v8::WeakCallbackData<v8::Object, CJS_Object>& data)
-{
- CJS_Object* pJSObj = data.GetParameter();
- if(pJSObj)
- {
- pJSObj->ExitInstance();
- delete pJSObj;
- }
- v8::Local<v8::Object> obj = data.GetValue();
- JS_FreePrivate(obj);
-}
-
-CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL)
-{
- v8::Local<v8::Context> context = pObject->CreationContext();
- m_pIsolate = context->GetIsolate();
- m_pObject.Reset(m_pIsolate, pObject);
-};
-
-CJS_Object::~CJS_Object(void)
-{
- delete m_pEmbedObj;
- m_pEmbedObj = NULL;
-
- m_pObject.Reset();
-};
-
-void CJS_Object::MakeWeak()
-{
- m_pObject.SetWeak(this, FreeObject);
-}
-
-CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc)
-{
- return FXJS_GetPageView(cc);
-}
-
-int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
-{
- return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
-}
-
-void CJS_Object::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
-{
- ASSERT(pContext != NULL);
-
- if (pContext->IsMsgBoxEnabled())
- {
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- if(pApp)
- pApp->JS_appAlert(swMsg, NULL, 0, 3);
- }
-}
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+// #include "../../include/javascript/JS_MsgBox.h"
+// #include "../../include/javascript/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+
+int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
+{
+ int nRet = 0;
+
+ if(pApp)
+ {
+ CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
+ if(pDoc)
+ pDoc->KillFocusAnnot();
+ nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon);
+ }
+
+ return nRet;
+}
+
+CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc)
+{
+ if (CJS_Context* pContext = (CJS_Context *)cc)
+ {
+ if (pContext->GetReaderDocument())
+ return NULL;
+ }
+ return NULL;
+}
+
+/* --------------------------------- CJS_EmbedObj --------------------------------- */
+
+CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) :
+ m_pJSObject(pJSObject)
+{
+}
+
+CJS_EmbedObj::~CJS_EmbedObj()
+{
+ m_pJSObject = NULL;
+
+}
+
+CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc)
+{
+ return FXJS_GetPageView(cc);
+}
+
+int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,FX_LPCWSTR swMsg,FX_LPCWSTR swTitle,FX_UINT nType,FX_UINT nIcon)
+{
+ return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
+}
+
+void CJS_EmbedObj::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
+{
+ CJS_Object::Alert(pContext, swMsg);
+}
+
+CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse)
+{
+ CJS_Timer* pTimer = new CJS_Timer(this,pApp);
+ pTimer->SetJSTimer(nElapse);
+
+ return pTimer;
+}
+
+void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer)
+{
+ ASSERT(pTimer != NULL);
+ pTimer->KillJSTimer();
+ delete pTimer;
+}
+
+FX_BOOL CJS_EmbedObj::IsSafeMode(IFXJS_Context* cc)
+{
+ ASSERT(cc != NULL);
+
+ return TRUE;
+}
+
+/* --------------------------------- CJS_Object --------------------------------- */
+void FreeObject(const v8::WeakCallbackData<v8::Object, CJS_Object>& data)
+{
+ CJS_Object* pJSObj = data.GetParameter();
+ if(pJSObj)
+ {
+ pJSObj->ExitInstance();
+ delete pJSObj;
+ }
+ v8::Local<v8::Object> obj = data.GetValue();
+ JS_FreePrivate(obj);
+}
+
+CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL)
+{
+ v8::Local<v8::Context> context = pObject->CreationContext();
+ m_pIsolate = context->GetIsolate();
+ m_pObject.Reset(m_pIsolate, pObject);
+};
+
+CJS_Object::~CJS_Object(void)
+{
+ delete m_pEmbedObj;
+ m_pEmbedObj = NULL;
+
+ m_pObject.Reset();
+};
+
+void CJS_Object::MakeWeak()
+{
+ m_pObject.SetWeak(this, FreeObject);
+}
+
+CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc)
+{
+ return FXJS_GetPageView(cc);
+}
+
+int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
+{
+ return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
+}
+
+void CJS_Object::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
+{
+ ASSERT(pContext != NULL);
+
+ if (pContext->IsMsgBoxEnabled())
+ {
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ if(pApp)
+ pApp->JS_appAlert(swMsg, NULL, 0, 3);
+ }
+}
+
+
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 77796431d4..c7a92ebde2 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -1,470 +1,470 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/app.h"
-#include "../../include/javascript/color.h"
-#include "../../include/javascript/Consts.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/event.h"
-#include "../../include/javascript/Field.h"
-#include "../../include/javascript/Icon.h"
-#include "../../include/javascript/PublicMethods.h"
-#include "../../include/javascript/report.h"
-#include "../../include/javascript/util.h"
-#include "../../include/javascript/JS_GlobalData.h"
-#include "../../include/javascript/global.h"
-#include "../../include/javascript/console.h"
-
-CJS_RuntimeFactory::~CJS_RuntimeFactory()
-{
-}
-
-IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
-{
- if (!m_bInit)
- {
- JS_Initial();
-
- m_bInit = TRUE;
- }
- return new CJS_Runtime(pApp);
-}
-void CJS_RuntimeFactory::AddRef()
-{
- //to do.Should be implemented as atom manipulation.
- m_nRef++;
-}
-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;
- }
- }
-}
-
-void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime)
-{
- if(pRuntime)
- delete (CJS_Runtime*)pRuntime;
-}
-
-CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
-{
- 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--;
-
- if (m_nGlobalDataCount <= 0)
- {
- delete m_pGlobalData;
- m_pGlobalData = NULL;
- }
-}
-
-/* ------------------------------ CJS_Runtime ------------------------------ */
-
-CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
- m_pApp(pApp),
- m_pDocument(NULL),
- m_pFieldEventPath(NULL),
- m_bBlocking(FALSE),
- m_bRegistered(FALSE)
-{
- m_isolate = v8::Isolate::New();
- //m_isolate->Enter();
-
- InitJSObjects();
-
- 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);
-
- m_ContextArray.RemoveAll();
-
- JS_ReleaseRuntime(*this, m_context);
-
- RemoveEventsInLoop(m_pFieldEventPath);
-
- m_pApp = NULL;
- m_pDocument = NULL;
- m_pFieldEventPath = NULL;
- m_context.Reset();
-
- //m_isolate->Exit();
- m_isolate->Dispose();
-}
-
-FX_BOOL CJS_Runtime::InitJSObjects()
-{
- v8::Isolate::Scope isolate_scope(GetIsolate());
- v8::HandleScope handle_scope(GetIsolate());
- v8::Handle<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;
-}
-
-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;
- }
- }
-}
-
-IFXJS_Context* CJS_Runtime::GetCurrentContext()
-{
- 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"));
- }
- }
-}
-
-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;
-}
-
-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;
- }
-}
-
-void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart)
-{
- CJS_FieldEvent* p = pStart;
-
- while (p)
- {
- CJS_FieldEvent* pOld = p;
- p = pOld->pNext;
-
- delete pOld;
- }
-}
-
-v8::Handle<v8::Context> CJS_Runtime::NewJSContext()
-{
- return v8::Local<v8::Context>::New(m_isolate, m_context);
-}
-
-CFX_WideString ChangeObjName(const CFX_WideString& str)
-{
- CFX_WideString sRet = str;
- sRet.Replace((FX_LPCWSTR)L"_", (FX_LPCWSTR)L".");
- return sRet;
-}
-
-void CJS_Runtime::GetObjectNames(CFX_WideStringArray& array)
-{
- array.RemoveAll();
-
- array.Add(CJS_Border::m_pClassName);
- array.Add(CJS_Display::m_pClassName);
- array.Add(CJS_Font::m_pClassName);
- array.Add(CJS_Highlight::m_pClassName);
- array.Add(CJS_Position::m_pClassName);
- array.Add(CJS_ScaleHow::m_pClassName);
- array.Add(CJS_ScaleWhen::m_pClassName);
- array.Add(CJS_Style::m_pClassName);
- array.Add(CJS_Zoomtype::m_pClassName);
-
- array.Add(CJS_App::m_pClassName);
- array.Add((FX_LPCWSTR)"this");
- array.Add(CJS_Event::m_pClassName);
-
- array.Add(CJS_Global::m_pClassName);
- array.Add(CJS_Util::m_pClassName);
-}
-
-void CJS_Runtime::GetObjectConsts(const CFX_WideString& sObjName, CFX_WideStringArray& array)
-{
- JSConstSpec* pConsts = NULL;
- int nSize = 0;
-
- if (sObjName == CJS_Border::m_pClassName)
- CJS_Border::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Display::m_pClassName)
- CJS_Display::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Font::m_pClassName)
- CJS_Font::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Highlight::m_pClassName)
- CJS_Highlight::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Position::m_pClassName)
- CJS_Position::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_ScaleHow::m_pClassName)
- CJS_ScaleHow::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_ScaleWhen::m_pClassName)
- CJS_ScaleWhen::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Style::m_pClassName)
- CJS_Style::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Zoomtype::m_pClassName)
- CJS_Zoomtype::GetConsts(pConsts, nSize);
-
- else if (sObjName == CJS_App::m_pClassName)
- CJS_App::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Color::m_pClassName)
- CJS_Color::GetConsts(pConsts, nSize);
-
- else if (sObjName == L"this")
- {
- if (GetReaderDocument())
- CJS_Document::GetConsts(pConsts, nSize);
- else
- CJS_App::GetConsts(pConsts, nSize);
- }
-
- if (sObjName == CJS_Event::m_pClassName)
- CJS_Event::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Field::m_pClassName)
- CJS_Field::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Global::m_pClassName)
- CJS_Global::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Util::m_pClassName)
- CJS_Util::GetConsts(pConsts, nSize);
-
- for (int i=0; i<nSize; i++)
- array.Add(pConsts[i].pName);
-}
-
-void CJS_Runtime::GetObjectProps(const CFX_WideString& sObjName, CFX_WideStringArray& array)
-{
- JSPropertySpec* pProperties = NULL;
- int nSize = 0;
-
- if (sObjName == CJS_App::m_pClassName)
- CJS_App::GetProperties(pProperties, nSize);
- else if (sObjName == CJS_Color::m_pClassName)
- CJS_Color::GetProperties(pProperties, nSize);
- else if (sObjName == L"this")
- {
- if (GetReaderDocument())
- CJS_Document::GetProperties(pProperties, nSize);
- else
- CJS_App::GetProperties(pProperties, nSize);
- }
- else if (sObjName == CJS_Event::m_pClassName)
- CJS_Event::GetProperties(pProperties, nSize);
- else if (sObjName == CJS_Field::m_pClassName)
- CJS_Field::GetProperties(pProperties, nSize);
- else if (sObjName == CJS_Global::m_pClassName)
- CJS_Global::GetProperties(pProperties, nSize);
- else if (sObjName == CJS_Util::m_pClassName)
- CJS_Util::GetProperties(pProperties, nSize);
-
- for (int i=0; i<nSize; i++)
- array.Add(pProperties[i].pName);
-}
-
-void CJS_Runtime::GetObjectMethods(const CFX_WideString& sObjName, CFX_WideStringArray& array)
-{
- JSMethodSpec* pMethods = NULL;
- int nSize = 0;
-
- if (sObjName == CJS_App::m_pClassName)
- CJS_App::GetMethods(pMethods, nSize);
- else if (sObjName == CJS_Color::m_pClassName)
- CJS_Color::GetMethods(pMethods, nSize);
- else if (sObjName == L"this")
- {
- if (GetReaderDocument())
- CJS_Document::GetMethods(pMethods, nSize);
- else
- CJS_App::GetMethods(pMethods, nSize);
- }
- else if (sObjName == CJS_Event::m_pClassName)
- CJS_Event::GetMethods(pMethods, nSize);
- else if (sObjName == CJS_Field::m_pClassName)
- CJS_Field::GetMethods(pMethods, nSize);
- else if (sObjName == CJS_Global::m_pClassName)
- CJS_Global::GetMethods(pMethods, nSize);
- else if (sObjName == CJS_Util::m_pClassName)
- CJS_Util::GetMethods(pMethods, nSize);
-
- for (int i=0; i<nSize; i++)
- array.Add(pMethods[i].pName);
-}
-
-FX_BOOL CJS_Runtime::IsEntered()
-{
- return v8::Isolate::GetCurrent() == m_isolate;
-}
-void CJS_Runtime::Exit()
-{
- if(m_isolate) m_isolate->Exit();
-}
-void CJS_Runtime::Enter()
-{
- if(m_isolate) m_isolate->Enter();
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/app.h"
+#include "../../include/javascript/color.h"
+#include "../../include/javascript/Consts.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/event.h"
+#include "../../include/javascript/Field.h"
+#include "../../include/javascript/Icon.h"
+#include "../../include/javascript/PublicMethods.h"
+#include "../../include/javascript/report.h"
+#include "../../include/javascript/util.h"
+#include "../../include/javascript/JS_GlobalData.h"
+#include "../../include/javascript/global.h"
+#include "../../include/javascript/console.h"
+
+CJS_RuntimeFactory::~CJS_RuntimeFactory()
+{
+}
+
+IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
+{
+ if (!m_bInit)
+ {
+ JS_Initial();
+
+ m_bInit = TRUE;
+ }
+ return new CJS_Runtime(pApp);
+}
+void CJS_RuntimeFactory::AddRef()
+{
+ //to do.Should be implemented as atom manipulation.
+ m_nRef++;
+}
+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;
+ }
+ }
+}
+
+void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime)
+{
+ if(pRuntime)
+ delete (CJS_Runtime*)pRuntime;
+}
+
+CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
+{
+ 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--;
+
+ if (m_nGlobalDataCount <= 0)
+ {
+ delete m_pGlobalData;
+ m_pGlobalData = NULL;
+ }
+}
+
+/* ------------------------------ CJS_Runtime ------------------------------ */
+
+CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
+ m_pApp(pApp),
+ m_pDocument(NULL),
+ m_pFieldEventPath(NULL),
+ m_bBlocking(FALSE),
+ m_bRegistered(FALSE)
+{
+ m_isolate = v8::Isolate::New();
+ //m_isolate->Enter();
+
+ InitJSObjects();
+
+ 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);
+
+ m_ContextArray.RemoveAll();
+
+ JS_ReleaseRuntime(*this, m_context);
+
+ RemoveEventsInLoop(m_pFieldEventPath);
+
+ m_pApp = NULL;
+ m_pDocument = NULL;
+ m_pFieldEventPath = NULL;
+ m_context.Reset();
+
+ //m_isolate->Exit();
+ m_isolate->Dispose();
+}
+
+FX_BOOL CJS_Runtime::InitJSObjects()
+{
+ v8::Isolate::Scope isolate_scope(GetIsolate());
+ v8::HandleScope handle_scope(GetIsolate());
+ v8::Handle<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;
+}
+
+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;
+ }
+ }
+}
+
+IFXJS_Context* CJS_Runtime::GetCurrentContext()
+{
+ 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"));
+ }
+ }
+}
+
+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;
+}
+
+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;
+ }
+}
+
+void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart)
+{
+ CJS_FieldEvent* p = pStart;
+
+ while (p)
+ {
+ CJS_FieldEvent* pOld = p;
+ p = pOld->pNext;
+
+ delete pOld;
+ }
+}
+
+v8::Handle<v8::Context> CJS_Runtime::NewJSContext()
+{
+ return v8::Local<v8::Context>::New(m_isolate, m_context);
+}
+
+CFX_WideString ChangeObjName(const CFX_WideString& str)
+{
+ CFX_WideString sRet = str;
+ sRet.Replace((FX_LPCWSTR)L"_", (FX_LPCWSTR)L".");
+ return sRet;
+}
+
+void CJS_Runtime::GetObjectNames(CFX_WideStringArray& array)
+{
+ array.RemoveAll();
+
+ array.Add(CJS_Border::m_pClassName);
+ array.Add(CJS_Display::m_pClassName);
+ array.Add(CJS_Font::m_pClassName);
+ array.Add(CJS_Highlight::m_pClassName);
+ array.Add(CJS_Position::m_pClassName);
+ array.Add(CJS_ScaleHow::m_pClassName);
+ array.Add(CJS_ScaleWhen::m_pClassName);
+ array.Add(CJS_Style::m_pClassName);
+ array.Add(CJS_Zoomtype::m_pClassName);
+
+ array.Add(CJS_App::m_pClassName);
+ array.Add((FX_LPCWSTR)"this");
+ array.Add(CJS_Event::m_pClassName);
+
+ array.Add(CJS_Global::m_pClassName);
+ array.Add(CJS_Util::m_pClassName);
+}
+
+void CJS_Runtime::GetObjectConsts(const CFX_WideString& sObjName, CFX_WideStringArray& array)
+{
+ JSConstSpec* pConsts = NULL;
+ int nSize = 0;
+
+ if (sObjName == CJS_Border::m_pClassName)
+ CJS_Border::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Display::m_pClassName)
+ CJS_Display::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Font::m_pClassName)
+ CJS_Font::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Highlight::m_pClassName)
+ CJS_Highlight::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Position::m_pClassName)
+ CJS_Position::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_ScaleHow::m_pClassName)
+ CJS_ScaleHow::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_ScaleWhen::m_pClassName)
+ CJS_ScaleWhen::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Style::m_pClassName)
+ CJS_Style::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Zoomtype::m_pClassName)
+ CJS_Zoomtype::GetConsts(pConsts, nSize);
+
+ else if (sObjName == CJS_App::m_pClassName)
+ CJS_App::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Color::m_pClassName)
+ CJS_Color::GetConsts(pConsts, nSize);
+
+ else if (sObjName == L"this")
+ {
+ if (GetReaderDocument())
+ CJS_Document::GetConsts(pConsts, nSize);
+ else
+ CJS_App::GetConsts(pConsts, nSize);
+ }
+
+ if (sObjName == CJS_Event::m_pClassName)
+ CJS_Event::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Field::m_pClassName)
+ CJS_Field::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Global::m_pClassName)
+ CJS_Global::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Util::m_pClassName)
+ CJS_Util::GetConsts(pConsts, nSize);
+
+ for (int i=0; i<nSize; i++)
+ array.Add(pConsts[i].pName);
+}
+
+void CJS_Runtime::GetObjectProps(const CFX_WideString& sObjName, CFX_WideStringArray& array)
+{
+ JSPropertySpec* pProperties = NULL;
+ int nSize = 0;
+
+ if (sObjName == CJS_App::m_pClassName)
+ CJS_App::GetProperties(pProperties, nSize);
+ else if (sObjName == CJS_Color::m_pClassName)
+ CJS_Color::GetProperties(pProperties, nSize);
+ else if (sObjName == L"this")
+ {
+ if (GetReaderDocument())
+ CJS_Document::GetProperties(pProperties, nSize);
+ else
+ CJS_App::GetProperties(pProperties, nSize);
+ }
+ else if (sObjName == CJS_Event::m_pClassName)
+ CJS_Event::GetProperties(pProperties, nSize);
+ else if (sObjName == CJS_Field::m_pClassName)
+ CJS_Field::GetProperties(pProperties, nSize);
+ else if (sObjName == CJS_Global::m_pClassName)
+ CJS_Global::GetProperties(pProperties, nSize);
+ else if (sObjName == CJS_Util::m_pClassName)
+ CJS_Util::GetProperties(pProperties, nSize);
+
+ for (int i=0; i<nSize; i++)
+ array.Add(pProperties[i].pName);
+}
+
+void CJS_Runtime::GetObjectMethods(const CFX_WideString& sObjName, CFX_WideStringArray& array)
+{
+ JSMethodSpec* pMethods = NULL;
+ int nSize = 0;
+
+ if (sObjName == CJS_App::m_pClassName)
+ CJS_App::GetMethods(pMethods, nSize);
+ else if (sObjName == CJS_Color::m_pClassName)
+ CJS_Color::GetMethods(pMethods, nSize);
+ else if (sObjName == L"this")
+ {
+ if (GetReaderDocument())
+ CJS_Document::GetMethods(pMethods, nSize);
+ else
+ CJS_App::GetMethods(pMethods, nSize);
+ }
+ else if (sObjName == CJS_Event::m_pClassName)
+ CJS_Event::GetMethods(pMethods, nSize);
+ else if (sObjName == CJS_Field::m_pClassName)
+ CJS_Field::GetMethods(pMethods, nSize);
+ else if (sObjName == CJS_Global::m_pClassName)
+ CJS_Global::GetMethods(pMethods, nSize);
+ else if (sObjName == CJS_Util::m_pClassName)
+ CJS_Util::GetMethods(pMethods, nSize);
+
+ for (int i=0; i<nSize; i++)
+ array.Add(pMethods[i].pName);
+}
+
+FX_BOOL CJS_Runtime::IsEntered()
+{
+ return v8::Isolate::GetCurrent() == m_isolate;
+}
+void CJS_Runtime::Exit()
+{
+ if(m_isolate) m_isolate->Exit();
+}
+void CJS_Runtime::Enter()
+{
+ if(m_isolate) m_isolate->Enter();
+}
diff --git a/fpdfsdk/src/javascript/JS_Value.cpp b/fpdfsdk/src/javascript/JS_Value.cpp
index 037f6184ed..0217ea1374 100644
--- a/fpdfsdk/src/javascript/JS_Value.cpp
+++ b/fpdfsdk/src/javascript/JS_Value.cpp
@@ -1,643 +1,643 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-
-/* ---------------------------- CJS_Value ---------------------------- */
-
-CJS_Value::CJS_Value(v8::Isolate* isolate) : m_isolate(isolate),m_eType(VT_unknown)
-{
-}
-CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Handle<v8::Value> pValue,FXJSVALUETYPE t) :m_isolate(isolate), m_pValue(pValue) , m_eType(t)
-{
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, const int &iValue):m_isolate(isolate)
-{
- operator =(iValue);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, const bool &bValue):m_isolate(isolate)
-{
- operator =(bValue);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, const float &fValue):m_isolate(isolate)
-{
- operator =(fValue);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, const double &dValue):m_isolate(isolate)
-{
- operator =(dValue);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, JSFXObject pJsObj):m_isolate(isolate)
-{
- operator =(pJsObj);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Object * pJsObj):m_isolate(isolate)
-{
- operator =(pJsObj);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, FX_LPCWSTR pWstr):m_isolate(isolate)
-{
- operator =(pWstr);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, FX_LPCSTR pStr):m_isolate(isolate)
-{
- operator = (pStr);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array):m_isolate(isolate)
-{
- operator = (array);
-}
-
-CJS_Value::~CJS_Value()
-{
-}
-
-void CJS_Value::Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t)
-{
- m_pValue = pValue;
- m_eType = t;
-}
-
-void CJS_Value::Attach(CJS_Value *pValue)
-{
- if (pValue)
- Attach(pValue->ToJSValue(),pValue->GetType());
-}
-
-void CJS_Value::Detach()
-{
- m_pValue = v8::Handle<v8::Value>();
- m_eType = VT_unknown;
-}
-
-/* ---------------------------------------------------------------------------------------- */
-
-CJS_Value::operator int() const
-{
-
- return JS_ToInt32(m_pValue);
-
-}
-
-CJS_Value::operator bool() const
-{
-
- return JS_ToBoolean(m_pValue);
-
-}
-
-CJS_Value::operator double() const
-{
-
- return JS_ToNumber(m_pValue);
-
-}
-
-CJS_Value::operator float() const
-{
-
- return (float)JS_ToNumber(m_pValue);
-
-}
-
-CJS_Value::operator CJS_Object *() const
-{
-
- v8::Handle<v8::Object> pObj = JS_ToObject(m_pValue);
- return (CJS_Object*)JS_GetPrivate(m_isolate, pObj);
-}
-
-CJS_Value::operator v8::Handle<v8::Object>() const
-{
- return JS_ToObject(m_pValue);
-}
-
-CJS_Value::operator CFX_WideString() const
-{
- return JS_ToString(m_pValue);
-}
-
-CJS_Value::operator CFX_ByteString() const
-{
- return CFX_ByteString::FromUnicode(operator CFX_WideString());
-}
-
-v8::Handle<v8::Value> CJS_Value::ToJSValue()
-{
- return m_pValue;
-}
-
-
-CJS_Value::operator v8::Handle<v8::Array>() const
-{
- if (IsArrayObject())
- return v8::Handle<v8::Array>::Cast(JS_ToObject(m_pValue));
- return v8::Handle<v8::Array>();
-}
-
-/* ---------------------------------------------------------------------------------------- */
-
-void CJS_Value::operator =(int iValue)
-{
- m_pValue = JS_NewNumber(m_isolate, iValue);
-
- m_eType = VT_number;
-}
-
-void CJS_Value::operator =(bool bValue)
-{
- m_pValue = JS_NewBoolean(m_isolate, bValue);
-
- m_eType = VT_boolean;
-}
-
-void CJS_Value::operator =(double dValue)
-{
- m_pValue = JS_NewNumber(m_isolate,dValue);
-
- m_eType = VT_number;
-}
-
-void CJS_Value::operator = (float fValue)
-{
- m_pValue = JS_NewNumber(m_isolate,fValue);
- m_eType = VT_number;
-}
-
-void CJS_Value::operator =(v8::Handle<v8::Object> pObj)
-{
-
- m_pValue = JS_NewObject(m_isolate,pObj);
-
- m_eType = VT_fxobject;
-}
-
-void CJS_Value::operator =(CJS_Object * pObj)
-{
- if (pObj)
- operator = ((JSFXObject)*pObj);
-}
-
-void CJS_Value::operator =(FX_LPCWSTR pWstr)
-{
- m_pValue = JS_NewString(m_isolate,(wchar_t *)pWstr);
-
- m_eType = VT_string;
-}
-
-void CJS_Value::SetNull()
-{
- m_pValue = JS_NewNull();
-
- m_eType = VT_null;
-}
-
-void CJS_Value::operator = (FX_LPCSTR pStr)
-{
- operator = (CFX_WideString::FromLocal(pStr));
-}
-
-void CJS_Value::operator = (CJS_Array & array)
-{
- m_pValue = JS_NewObject2(m_isolate,(v8::Handle<v8::Array>)array);
-
- m_eType = VT_object;
-}
-
-void CJS_Value::operator = (CJS_Date & date)
-{
- m_pValue = JS_NewDate(m_isolate, (double)date);
-
- m_eType = VT_date;
-}
-
-void CJS_Value::operator = (CJS_Value value)
-{
- m_pValue = value.ToJSValue();
-
- m_eType = value.m_eType;
-}
-
-/* ---------------------------------------------------------------------------------------- */
-
-FXJSVALUETYPE CJS_Value::GetType() const
-{
- if(m_pValue.IsEmpty()) return VT_unknown;
- if(m_pValue->IsString()) return VT_string;
- if(m_pValue->IsNumber()) return VT_number;
- if(m_pValue->IsBoolean()) return VT_boolean;
- if(m_pValue->IsDate()) return VT_date;
- if(m_pValue->IsObject()) return VT_object;
- if(m_pValue->IsNull()) return VT_null;
- if(m_pValue->IsUndefined()) return VT_undefined;
- return VT_unknown;
-}
-
-FX_BOOL CJS_Value::IsArrayObject() const
-{
- if(m_pValue.IsEmpty()) return FALSE;
- return m_pValue->IsArray();
-}
-
-FX_BOOL CJS_Value::IsDateObject() const
-{
- if(m_pValue.IsEmpty()) return FALSE;
- return m_pValue->IsDate();
-}
-
-//CJS_Value::operator CJS_Array()
-FX_BOOL CJS_Value::ConvertToArray(CJS_Array &array) const
-{
- if (IsArrayObject())
- {
- array.Attach(JS_ToArray(m_pValue));
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CJS_Value::ConvertToDate(CJS_Date &date) const
-{
-// if (GetType() == VT_date)
-// {
-// date = (double)(*this);
-// return TRUE;
-// }
-
- if (IsDateObject())
- {
- date.Attach(m_pValue);
- return TRUE;
- }
-
- return FALSE;
-}
-
-/* ---------------------------- CJS_PropValue ---------------------------- */
-
-CJS_PropValue::CJS_PropValue(const CJS_Value &value) :
- CJS_Value(value),
- m_bIsSetting(0)
-{
-}
-
-CJS_PropValue::CJS_PropValue(v8::Isolate* isolate) : CJS_Value(isolate),
- m_bIsSetting(0)
-{
-}
-
-CJS_PropValue::~CJS_PropValue()
-{
-}
-
-FX_BOOL CJS_PropValue::IsSetting()
-{
- return m_bIsSetting;
-}
-
-FX_BOOL CJS_PropValue::IsGetting()
-{
- return !m_bIsSetting;
-}
-
-void CJS_PropValue::operator <<(int iValue)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =(iValue);
-}
-
-void CJS_PropValue::operator >>(int & iValue) const
-{
- ASSERT(m_bIsSetting);
- iValue = CJS_Value::operator int();
-}
-
-
-void CJS_PropValue::operator <<(bool bValue)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =(bValue);
-}
-
-void CJS_PropValue::operator >>(bool &bValue) const
-{
- ASSERT(m_bIsSetting);
- bValue = CJS_Value::operator bool();
-
-}
-
-void CJS_PropValue::operator <<(double dValue)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =(dValue);
-}
-
-void CJS_PropValue::operator >>(double &dValue) const
-{
- ASSERT(m_bIsSetting);
- dValue = CJS_Value::operator double();
-}
-
-void CJS_PropValue::operator <<(CJS_Object *pObj)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator = (pObj);
-}
-
-void CJS_PropValue::operator >>(CJS_Object *&ppObj) const
-{
- ASSERT(m_bIsSetting);
- ppObj = CJS_Value::operator CJS_Object *();
-}
-
-void CJS_PropValue::operator<<(JSFXObject pObj)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator = (pObj);
-}
-
-void CJS_PropValue::operator>>(JSFXObject &ppObj) const
-{
- ASSERT(m_bIsSetting);
- ppObj = CJS_Value::operator JSFXObject ();
-}
-
-
-void CJS_PropValue::StartSetting()
-{
- m_bIsSetting = 1;
-}
-
-void CJS_PropValue::StartGetting()
-{
- m_bIsSetting = 0;
-}
-void CJS_PropValue::operator <<(CFX_ByteString string)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =((FX_LPCSTR)string);
-}
-
-void CJS_PropValue::operator >>(CFX_ByteString &string) const
-{
- ASSERT(m_bIsSetting);
- string = CJS_Value::operator CFX_ByteString();
-}
-
-void CJS_PropValue::operator <<(FX_LPCWSTR c_string)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =(c_string);
-}
-
-void CJS_PropValue::operator >>(CFX_WideString &wide_string) const
-{
- ASSERT(m_bIsSetting);
- wide_string = CJS_Value::operator CFX_WideString();
-}
-
-void CJS_PropValue::operator <<(CFX_WideString wide_string)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator = (wide_string);
-}
-
-void CJS_PropValue::operator >>(CJS_Array &array) const
-{
- ASSERT(m_bIsSetting);
- ConvertToArray(array);
-}
-
-void CJS_PropValue::operator <<(CJS_Array &array)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator=(array);
-}
-
-void CJS_PropValue::operator>>(CJS_Date &date) const
-{
- ASSERT(m_bIsSetting);
- ConvertToDate(date);
-}
-
-void CJS_PropValue::operator<<(CJS_Date &date)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator=(date);
-}
-
-CJS_PropValue::operator v8::Handle<v8::Value>() const
-{
- return m_pValue;
-}
-
-/* ======================================== CJS_Array ========================================= */
-CJS_Array::CJS_Array(v8::Isolate* isolate):m_isolate(isolate)
-{
-}
-
-CJS_Array::~CJS_Array()
-{
-}
-
-void CJS_Array::Attach(v8::Handle<v8::Array> pArray)
-{
- m_pArray = pArray;
-}
-
-FX_BOOL CJS_Array::IsAttached()
-{
- return FALSE;
-}
-
-void CJS_Array::GetElement(unsigned index,CJS_Value &value)
-{
- if (m_pArray.IsEmpty())
- return;
- v8::Handle<v8::Value> p = JS_GetArrayElemnet(m_pArray,index);
- value.Attach(p,VT_object);
-}
-
-void CJS_Array::SetElement(unsigned index,CJS_Value value)
-{
- if (m_pArray.IsEmpty())
- m_pArray = JS_NewArray(m_isolate);
-
- JS_PutArrayElement(m_pArray,index,value.ToJSValue(),value.GetType());
-}
-
-int CJS_Array::GetLength()
-{
- if (m_pArray.IsEmpty())
- return 0;
- return JS_GetArrayLength(m_pArray);
-}
-
-CJS_Array:: operator v8::Handle<v8::Array>()
-{
- if (m_pArray.IsEmpty())
- m_pArray = JS_NewArray(m_isolate);
-
- return m_pArray;
-}
-
-/* ======================================== CJS_Date ========================================= */
-
-CJS_Date::CJS_Date(v8::Isolate* isolate) :m_isolate(isolate)
-{
-}
-
-CJS_Date::CJS_Date(v8::Isolate* isolate,double dMsec_time)
-{
- m_isolate = isolate;
- m_pDate = JS_NewDate(isolate,dMsec_time);
-}
-
-CJS_Date::CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int min, int sec)
-{
- m_isolate = isolate;
- m_pDate = JS_NewDate(isolate,MakeDate(year,mon,day,hour,min,sec,0));
-}
-
-double CJS_Date::MakeDate(int year, int mon, int day,int hour, int min, int sec,int ms)
-{
- return JS_MakeDate(JS_MakeDay(year,mon,day), JS_MakeTime(hour,min,sec,ms));
-}
-
-CJS_Date::~CJS_Date()
-{
-}
-
-FX_BOOL CJS_Date::IsValidDate()
-{
- if(m_pDate.IsEmpty()) return FALSE;
- return !JS_PortIsNan(JS_ToNumber(m_pDate));
-}
-
-void CJS_Date::Attach(v8::Handle<v8::Value> pDate)
-{
- m_pDate = pDate;
-}
-
-int CJS_Date::GetYear()
-{
- if (IsValidDate())
- return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetYear(int iYear)
-{
- double date = MakeDate(iYear,GetMonth(),GetDay(),GetHours(),GetMinutes(),GetSeconds(),0);
- JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date));
-}
-
-int CJS_Date::GetMonth()
-{
- if (IsValidDate())
- return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetMonth(int iMonth)
-{
-
- double date = MakeDate(GetYear(),iMonth,GetDay(),GetHours(),GetMinutes(),GetSeconds(),0);
- JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date));
-
-}
-
-int CJS_Date::GetDay()
-{
- if (IsValidDate())
- return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetDay(int iDay)
-{
-
- double date = MakeDate(GetYear(),GetMonth(),iDay,GetHours(),GetMinutes(),GetSeconds(),0);
- JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
-
-}
-
-int CJS_Date::GetHours()
-{
- if (IsValidDate())
- return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetHours(int iHours)
-{
- double date = MakeDate(GetYear(),GetMonth(),GetDay(),iHours,GetMinutes(),GetSeconds(),0);
- JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
-}
-
-int CJS_Date::GetMinutes()
-{
- if (IsValidDate())
- return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetMinutes(int minutes)
-{
- double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),minutes,GetSeconds(),0);
- JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
-}
-
-int CJS_Date::GetSeconds()
-{
- if (IsValidDate())
- return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetSeconds(int seconds)
-{
- double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),GetMinutes(),seconds,0);
- JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
-}
-
-CJS_Date::operator v8::Handle<v8::Value>()
-{
- return m_pDate;
-}
-
-CJS_Date::operator double() const
-{
- if(m_pDate.IsEmpty())
- return 0.0;
- return JS_ToNumber(m_pDate);
-}
-
-CFX_WideString CJS_Date::ToString() const
-{
- if(m_pDate.IsEmpty())
- return L"";
- return JS_ToString(m_pDate);
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+
+/* ---------------------------- CJS_Value ---------------------------- */
+
+CJS_Value::CJS_Value(v8::Isolate* isolate) : m_isolate(isolate),m_eType(VT_unknown)
+{
+}
+CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Handle<v8::Value> pValue,FXJSVALUETYPE t) :m_isolate(isolate), m_pValue(pValue) , m_eType(t)
+{
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, const int &iValue):m_isolate(isolate)
+{
+ operator =(iValue);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, const bool &bValue):m_isolate(isolate)
+{
+ operator =(bValue);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, const float &fValue):m_isolate(isolate)
+{
+ operator =(fValue);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, const double &dValue):m_isolate(isolate)
+{
+ operator =(dValue);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, JSFXObject pJsObj):m_isolate(isolate)
+{
+ operator =(pJsObj);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Object * pJsObj):m_isolate(isolate)
+{
+ operator =(pJsObj);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, FX_LPCWSTR pWstr):m_isolate(isolate)
+{
+ operator =(pWstr);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, FX_LPCSTR pStr):m_isolate(isolate)
+{
+ operator = (pStr);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array):m_isolate(isolate)
+{
+ operator = (array);
+}
+
+CJS_Value::~CJS_Value()
+{
+}
+
+void CJS_Value::Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t)
+{
+ m_pValue = pValue;
+ m_eType = t;
+}
+
+void CJS_Value::Attach(CJS_Value *pValue)
+{
+ if (pValue)
+ Attach(pValue->ToJSValue(),pValue->GetType());
+}
+
+void CJS_Value::Detach()
+{
+ m_pValue = v8::Handle<v8::Value>();
+ m_eType = VT_unknown;
+}
+
+/* ---------------------------------------------------------------------------------------- */
+
+CJS_Value::operator int() const
+{
+
+ return JS_ToInt32(m_pValue);
+
+}
+
+CJS_Value::operator bool() const
+{
+
+ return JS_ToBoolean(m_pValue);
+
+}
+
+CJS_Value::operator double() const
+{
+
+ return JS_ToNumber(m_pValue);
+
+}
+
+CJS_Value::operator float() const
+{
+
+ return (float)JS_ToNumber(m_pValue);
+
+}
+
+CJS_Value::operator CJS_Object *() const
+{
+
+ v8::Handle<v8::Object> pObj = JS_ToObject(m_pValue);
+ return (CJS_Object*)JS_GetPrivate(m_isolate, pObj);
+}
+
+CJS_Value::operator v8::Handle<v8::Object>() const
+{
+ return JS_ToObject(m_pValue);
+}
+
+CJS_Value::operator CFX_WideString() const
+{
+ return JS_ToString(m_pValue);
+}
+
+CJS_Value::operator CFX_ByteString() const
+{
+ return CFX_ByteString::FromUnicode(operator CFX_WideString());
+}
+
+v8::Handle<v8::Value> CJS_Value::ToJSValue()
+{
+ return m_pValue;
+}
+
+
+CJS_Value::operator v8::Handle<v8::Array>() const
+{
+ if (IsArrayObject())
+ return v8::Handle<v8::Array>::Cast(JS_ToObject(m_pValue));
+ return v8::Handle<v8::Array>();
+}
+
+/* ---------------------------------------------------------------------------------------- */
+
+void CJS_Value::operator =(int iValue)
+{
+ m_pValue = JS_NewNumber(m_isolate, iValue);
+
+ m_eType = VT_number;
+}
+
+void CJS_Value::operator =(bool bValue)
+{
+ m_pValue = JS_NewBoolean(m_isolate, bValue);
+
+ m_eType = VT_boolean;
+}
+
+void CJS_Value::operator =(double dValue)
+{
+ m_pValue = JS_NewNumber(m_isolate,dValue);
+
+ m_eType = VT_number;
+}
+
+void CJS_Value::operator = (float fValue)
+{
+ m_pValue = JS_NewNumber(m_isolate,fValue);
+ m_eType = VT_number;
+}
+
+void CJS_Value::operator =(v8::Handle<v8::Object> pObj)
+{
+
+ m_pValue = JS_NewObject(m_isolate,pObj);
+
+ m_eType = VT_fxobject;
+}
+
+void CJS_Value::operator =(CJS_Object * pObj)
+{
+ if (pObj)
+ operator = ((JSFXObject)*pObj);
+}
+
+void CJS_Value::operator =(FX_LPCWSTR pWstr)
+{
+ m_pValue = JS_NewString(m_isolate,(wchar_t *)pWstr);
+
+ m_eType = VT_string;
+}
+
+void CJS_Value::SetNull()
+{
+ m_pValue = JS_NewNull();
+
+ m_eType = VT_null;
+}
+
+void CJS_Value::operator = (FX_LPCSTR pStr)
+{
+ operator = (CFX_WideString::FromLocal(pStr));
+}
+
+void CJS_Value::operator = (CJS_Array & array)
+{
+ m_pValue = JS_NewObject2(m_isolate,(v8::Handle<v8::Array>)array);
+
+ m_eType = VT_object;
+}
+
+void CJS_Value::operator = (CJS_Date & date)
+{
+ m_pValue = JS_NewDate(m_isolate, (double)date);
+
+ m_eType = VT_date;
+}
+
+void CJS_Value::operator = (CJS_Value value)
+{
+ m_pValue = value.ToJSValue();
+
+ m_eType = value.m_eType;
+}
+
+/* ---------------------------------------------------------------------------------------- */
+
+FXJSVALUETYPE CJS_Value::GetType() const
+{
+ if(m_pValue.IsEmpty()) return VT_unknown;
+ if(m_pValue->IsString()) return VT_string;
+ if(m_pValue->IsNumber()) return VT_number;
+ if(m_pValue->IsBoolean()) return VT_boolean;
+ if(m_pValue->IsDate()) return VT_date;
+ if(m_pValue->IsObject()) return VT_object;
+ if(m_pValue->IsNull()) return VT_null;
+ if(m_pValue->IsUndefined()) return VT_undefined;
+ return VT_unknown;
+}
+
+FX_BOOL CJS_Value::IsArrayObject() const
+{
+ if(m_pValue.IsEmpty()) return FALSE;
+ return m_pValue->IsArray();
+}
+
+FX_BOOL CJS_Value::IsDateObject() const
+{
+ if(m_pValue.IsEmpty()) return FALSE;
+ return m_pValue->IsDate();
+}
+
+//CJS_Value::operator CJS_Array()
+FX_BOOL CJS_Value::ConvertToArray(CJS_Array &array) const
+{
+ if (IsArrayObject())
+ {
+ array.Attach(JS_ToArray(m_pValue));
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CJS_Value::ConvertToDate(CJS_Date &date) const
+{
+// if (GetType() == VT_date)
+// {
+// date = (double)(*this);
+// return TRUE;
+// }
+
+ if (IsDateObject())
+ {
+ date.Attach(m_pValue);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/* ---------------------------- CJS_PropValue ---------------------------- */
+
+CJS_PropValue::CJS_PropValue(const CJS_Value &value) :
+ CJS_Value(value),
+ m_bIsSetting(0)
+{
+}
+
+CJS_PropValue::CJS_PropValue(v8::Isolate* isolate) : CJS_Value(isolate),
+ m_bIsSetting(0)
+{
+}
+
+CJS_PropValue::~CJS_PropValue()
+{
+}
+
+FX_BOOL CJS_PropValue::IsSetting()
+{
+ return m_bIsSetting;
+}
+
+FX_BOOL CJS_PropValue::IsGetting()
+{
+ return !m_bIsSetting;
+}
+
+void CJS_PropValue::operator <<(int iValue)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =(iValue);
+}
+
+void CJS_PropValue::operator >>(int & iValue) const
+{
+ ASSERT(m_bIsSetting);
+ iValue = CJS_Value::operator int();
+}
+
+
+void CJS_PropValue::operator <<(bool bValue)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =(bValue);
+}
+
+void CJS_PropValue::operator >>(bool &bValue) const
+{
+ ASSERT(m_bIsSetting);
+ bValue = CJS_Value::operator bool();
+
+}
+
+void CJS_PropValue::operator <<(double dValue)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =(dValue);
+}
+
+void CJS_PropValue::operator >>(double &dValue) const
+{
+ ASSERT(m_bIsSetting);
+ dValue = CJS_Value::operator double();
+}
+
+void CJS_PropValue::operator <<(CJS_Object *pObj)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator = (pObj);
+}
+
+void CJS_PropValue::operator >>(CJS_Object *&ppObj) const
+{
+ ASSERT(m_bIsSetting);
+ ppObj = CJS_Value::operator CJS_Object *();
+}
+
+void CJS_PropValue::operator<<(JSFXObject pObj)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator = (pObj);
+}
+
+void CJS_PropValue::operator>>(JSFXObject &ppObj) const
+{
+ ASSERT(m_bIsSetting);
+ ppObj = CJS_Value::operator JSFXObject ();
+}
+
+
+void CJS_PropValue::StartSetting()
+{
+ m_bIsSetting = 1;
+}
+
+void CJS_PropValue::StartGetting()
+{
+ m_bIsSetting = 0;
+}
+void CJS_PropValue::operator <<(CFX_ByteString string)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =((FX_LPCSTR)string);
+}
+
+void CJS_PropValue::operator >>(CFX_ByteString &string) const
+{
+ ASSERT(m_bIsSetting);
+ string = CJS_Value::operator CFX_ByteString();
+}
+
+void CJS_PropValue::operator <<(FX_LPCWSTR c_string)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =(c_string);
+}
+
+void CJS_PropValue::operator >>(CFX_WideString &wide_string) const
+{
+ ASSERT(m_bIsSetting);
+ wide_string = CJS_Value::operator CFX_WideString();
+}
+
+void CJS_PropValue::operator <<(CFX_WideString wide_string)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator = (wide_string);
+}
+
+void CJS_PropValue::operator >>(CJS_Array &array) const
+{
+ ASSERT(m_bIsSetting);
+ ConvertToArray(array);
+}
+
+void CJS_PropValue::operator <<(CJS_Array &array)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator=(array);
+}
+
+void CJS_PropValue::operator>>(CJS_Date &date) const
+{
+ ASSERT(m_bIsSetting);
+ ConvertToDate(date);
+}
+
+void CJS_PropValue::operator<<(CJS_Date &date)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator=(date);
+}
+
+CJS_PropValue::operator v8::Handle<v8::Value>() const
+{
+ return m_pValue;
+}
+
+/* ======================================== CJS_Array ========================================= */
+CJS_Array::CJS_Array(v8::Isolate* isolate):m_isolate(isolate)
+{
+}
+
+CJS_Array::~CJS_Array()
+{
+}
+
+void CJS_Array::Attach(v8::Handle<v8::Array> pArray)
+{
+ m_pArray = pArray;
+}
+
+FX_BOOL CJS_Array::IsAttached()
+{
+ return FALSE;
+}
+
+void CJS_Array::GetElement(unsigned index,CJS_Value &value)
+{
+ if (m_pArray.IsEmpty())
+ return;
+ v8::Handle<v8::Value> p = JS_GetArrayElemnet(m_pArray,index);
+ value.Attach(p,VT_object);
+}
+
+void CJS_Array::SetElement(unsigned index,CJS_Value value)
+{
+ if (m_pArray.IsEmpty())
+ m_pArray = JS_NewArray(m_isolate);
+
+ JS_PutArrayElement(m_pArray,index,value.ToJSValue(),value.GetType());
+}
+
+int CJS_Array::GetLength()
+{
+ if (m_pArray.IsEmpty())
+ return 0;
+ return JS_GetArrayLength(m_pArray);
+}
+
+CJS_Array:: operator v8::Handle<v8::Array>()
+{
+ if (m_pArray.IsEmpty())
+ m_pArray = JS_NewArray(m_isolate);
+
+ return m_pArray;
+}
+
+/* ======================================== CJS_Date ========================================= */
+
+CJS_Date::CJS_Date(v8::Isolate* isolate) :m_isolate(isolate)
+{
+}
+
+CJS_Date::CJS_Date(v8::Isolate* isolate,double dMsec_time)
+{
+ m_isolate = isolate;
+ m_pDate = JS_NewDate(isolate,dMsec_time);
+}
+
+CJS_Date::CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int min, int sec)
+{
+ m_isolate = isolate;
+ m_pDate = JS_NewDate(isolate,MakeDate(year,mon,day,hour,min,sec,0));
+}
+
+double CJS_Date::MakeDate(int year, int mon, int day,int hour, int min, int sec,int ms)
+{
+ return JS_MakeDate(JS_MakeDay(year,mon,day), JS_MakeTime(hour,min,sec,ms));
+}
+
+CJS_Date::~CJS_Date()
+{
+}
+
+FX_BOOL CJS_Date::IsValidDate()
+{
+ if(m_pDate.IsEmpty()) return FALSE;
+ return !JS_PortIsNan(JS_ToNumber(m_pDate));
+}
+
+void CJS_Date::Attach(v8::Handle<v8::Value> pDate)
+{
+ m_pDate = pDate;
+}
+
+int CJS_Date::GetYear()
+{
+ if (IsValidDate())
+ return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetYear(int iYear)
+{
+ double date = MakeDate(iYear,GetMonth(),GetDay(),GetHours(),GetMinutes(),GetSeconds(),0);
+ JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date));
+}
+
+int CJS_Date::GetMonth()
+{
+ if (IsValidDate())
+ return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetMonth(int iMonth)
+{
+
+ double date = MakeDate(GetYear(),iMonth,GetDay(),GetHours(),GetMinutes(),GetSeconds(),0);
+ JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date));
+
+}
+
+int CJS_Date::GetDay()
+{
+ if (IsValidDate())
+ return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetDay(int iDay)
+{
+
+ double date = MakeDate(GetYear(),GetMonth(),iDay,GetHours(),GetMinutes(),GetSeconds(),0);
+ JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
+
+}
+
+int CJS_Date::GetHours()
+{
+ if (IsValidDate())
+ return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetHours(int iHours)
+{
+ double date = MakeDate(GetYear(),GetMonth(),GetDay(),iHours,GetMinutes(),GetSeconds(),0);
+ JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
+}
+
+int CJS_Date::GetMinutes()
+{
+ if (IsValidDate())
+ return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetMinutes(int minutes)
+{
+ double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),minutes,GetSeconds(),0);
+ JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
+}
+
+int CJS_Date::GetSeconds()
+{
+ if (IsValidDate())
+ return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetSeconds(int seconds)
+{
+ double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),GetMinutes(),seconds,0);
+ JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
+}
+
+CJS_Date::operator v8::Handle<v8::Value>()
+{
+ return m_pDate;
+}
+
+CJS_Date::operator double() const
+{
+ if(m_pDate.IsEmpty())
+ return 0.0;
+ return JS_ToNumber(m_pDate);
+}
+
+CFX_WideString CJS_Date::ToString() const
+{
+ if(m_pDate.IsEmpty())
+ return L"";
+ return JS_ToString(m_pDate);
+}
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index c39c8a00dd..bd4acaef9a 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -1,2335 +1,2335 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/PublicMethods.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/resource.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/util.h"
-#include "../../include/javascript/Field.h"
-#include "../../include/javascript/color.h"
-#include "../../include/javascript/JS_Runtime.h"
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-
-/* -------------------------------- CJS_PublicMethods -------------------------------- */
-
-#define DOUBLE_CORRECT 0.000000000000001
-
-BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format,6)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke,6)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format,2)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke,2)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple,3)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate,2)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate,4)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx,2)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums,1)
-END_JS_STATIC_GLOBAL_FUN()
-
-IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
-
-struct stru_TbConvert
-{
- FX_LPCSTR lpszJSMark;
- FX_LPCSTR lpszCppMark;
-};
-
-static const stru_TbConvert fcTable[] = {"mmmm","%B",
- "mmm", "%b",
- "mm", "%m",
- //"m"
- "dddd","%A",
- "ddd", "%a",
- "dd", "%d",
- //"d", "%w",
- "yyyy","%Y",
- "yy", "%y",
- "HH", "%H",
- //"H"
- "hh", "%I",
- //"h"
- "MM", "%M",
- //"M"
- "ss", "%S",
- //"s
- "tt", "%p"
- //"t"
-};
-
-static FX_LPCWSTR months[] =
-{
- (FX_LPCWSTR)L"Jan", (FX_LPCWSTR)L"Feb", (FX_LPCWSTR)L"Mar", (FX_LPCWSTR)L"Apr", (FX_LPCWSTR)L"May", (FX_LPCWSTR)L"Jun", (FX_LPCWSTR)L"Jul", (FX_LPCWSTR)L"Aug", (FX_LPCWSTR)L"Sep", (FX_LPCWSTR)L"Oct", (FX_LPCWSTR)L"Nov", (FX_LPCWSTR)L"Dec"
-};
-
-static FX_LPCWSTR fullmonths[] =
-{
- (FX_LPCWSTR)L"January", (FX_LPCWSTR)L"February", (FX_LPCWSTR)L"March", (FX_LPCWSTR)L"April", (FX_LPCWSTR)L"May", (FX_LPCWSTR)L"June", (FX_LPCWSTR)L"July", (FX_LPCWSTR)L"August", (FX_LPCWSTR)L"September", (FX_LPCWSTR)L"October", (FX_LPCWSTR)L"November", (FX_LPCWSTR)L"December"
-};
-
-FX_BOOL CJS_PublicMethods::IsNumber(FX_LPCWSTR string)
-{
- CFX_WideString sTrim = StrTrim(string);
- FX_LPCWSTR pTrim = sTrim;
- FX_LPCWSTR 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');
-}
-
-FX_BOOL CJS_PublicMethods::IsDigit(char ch)
-{
- 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'));
-}
-
-FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t 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':
- return IsDigit(c_Change);
- case L'A':
- return IsAlphabetic(c_Change);
- case L'O':
- return IsAlphaNumeric(c_Change);
- case L'X':
- return TRUE;
- 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';
-}
-
-double CJS_PublicMethods::AF_Simple(FX_LPCWSTR sFuction, double dValue1, double dValue2)
-{
- if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"AVG") == 0 || FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"SUM") == 0)
- {
- return dValue1 + dValue2;
- }
- else if (FXSYS_wcsicmp(sFuction, (FX_LPCWSTR)L"PRD") == 0)
- {
- return dValue1 * dValue2;
- }
- else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MIN") == 0)
- {
- return FX_MIN(dValue1, dValue2);
- }
- else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MAX") == 0)
- {
- return FX_MAX(dValue1, dValue2);
- }
-
- return dValue1;
-}
-
-CFX_WideString CJS_PublicMethods::StrLTrim(FX_LPCWSTR pStr)
-{
- while (*pStr && *pStr == L' ') pStr++;
-
- return pStr;
-}
-
-CFX_WideString CJS_PublicMethods::StrRTrim(FX_LPCWSTR pStr)
-{
- FX_LPCWSTR p = pStr;
-
- while (*p) p++;
- p--;
- if (p >= pStr)
- {
- while (*p && *p == L' ') p--;
- p++;
- return CFX_WideString(pStr,p-pStr);
- }
- return L"";
-}
-
-CFX_WideString CJS_PublicMethods::StrTrim(FX_LPCWSTR pStr)
-{
- return StrRTrim(StrLTrim(pStr));
-}
-
-CFX_ByteString CJS_PublicMethods::StrLTrim(FX_LPCSTR pStr)
-{
- while (*pStr && *pStr == ' ') pStr++;
-
- return pStr;
-}
-
-CFX_ByteString CJS_PublicMethods::StrRTrim(FX_LPCSTR pStr)
-{
- FX_LPCSTR p = pStr;
-
- while (*p) p++;
- p--;
- if (p >= pStr)
- {
- while (*p && *p == ' ') p--;
- p++;
- return CFX_ByteString(pStr,p-pStr);
- }
- return "";
-}
-
-CFX_ByteString CJS_PublicMethods::StrTrim(FX_LPCSTR pStr)
-{
- return StrRTrim(StrLTrim(pStr));
-}
-
-double CJS_PublicMethods::ParseNumber(FX_LPCWSTR swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS)
-{
- bDot = FALSE;
- bSign = FALSE;
- bKXJS = FALSE;
-
- FX_BOOL bDigitExist = FALSE;
-
- FX_LPCWSTR p = swSource;
- wchar_t c;
-
- FX_LPCWSTR pStart = NULL;
- FX_LPCWSTR 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(FX_LPCWSTR swSource)
-{
- FX_BOOL bAllDigits = FALSE;
- FX_BOOL bDot = FALSE;
- FX_BOOL bSign = FALSE;
- FX_BOOL bKXJS = FALSE;
-
- return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
-}
-
-FX_BOOL CJS_PublicMethods::ConvertStringToNumber(FX_LPCWSTR swSource, double & dRet, FX_BOOL & bDot)
-{
- FX_BOOL bAllDigits = FALSE;
- FX_BOOL bSign = FALSE;
- FX_BOOL bKXJS = FALSE;
-
- dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
-
- 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.operator CFX_WideString();
- 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,(FX_LPCSTR)StrTrim(p)));
- break;
- }
- else
- {
- char * pSub = new char[pTemp - p + 1];
- strncpy(pSub, p, pTemp - p);
- *(pSub + (pTemp - p)) = '\0';
-
- StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(pSub)));
- 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;
-}
-
-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;
-}
-
-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((FX_LPCWSTR)L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
- return JS_DateParse(swTemp);
-}
-
-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;
-
- if (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 = value.GetAt(i) == 'p';
- i++;
- j++;
- break;
- }
- }
- else if (format.GetAt(i+1) == c && 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 = (value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm');
- i += 2;
- j += 2;
- break;
- }
- }
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && 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 (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && 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, 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 (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);
- }
- }
-
- 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;
- FX_WCHAR c;
- while (i < format.GetLength())
- {
- c = format.GetAt(i);
- sPart = L"";
- switch (c)
- {
- case 'y':
- case 'm':
- case 'd':
- case 'H':
- case 'h':
- case 'M':
- case 's':
- case 't':
- if (format.GetAt(i+1) != c)
- {
- switch (c)
- {
- case 'y':
- sPart += c;
- break;
- case 'm':
- sPart.Format((FX_LPCWSTR)L"%d",nMonth);
- break;
- case 'd':
- sPart.Format((FX_LPCWSTR)L"%d",nDay);
- break;
- case 'H':
- sPart.Format((FX_LPCWSTR)L"%d",nHour);
- break;
- case 'h':
- sPart.Format((FX_LPCWSTR)L"%d",nHour>12?nHour - 12:nHour);
- break;
- case 'M':
- sPart.Format((FX_LPCWSTR)L"%d",nMin);
- break;
- case 's':
- sPart.Format((FX_LPCWSTR)L"%d",nSec);
- break;
- case 't':
- sPart += nHour>12?'p':'a';
- break;
- }
- i++;
- }
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) != c)
- {
- switch (c)
- {
- case 'y':
- sPart.Format((FX_LPCWSTR)L"%02d",nYear - (nYear / 100) * 100);
- break;
- case 'm':
- sPart.Format((FX_LPCWSTR)L"%02d",nMonth);
- break;
- case 'd':
- sPart.Format((FX_LPCWSTR)L"%02d",nDay);
- break;
- case 'H':
- sPart.Format((FX_LPCWSTR)L"%02d",nHour);
- break;
- case 'h':
- sPart.Format((FX_LPCWSTR)L"%02d",nHour>12?nHour - 12:nHour);
- break;
- case 'M':
- sPart.Format((FX_LPCWSTR)L"%02d",nMin);
- break;
- case 's':
- sPart.Format((FX_LPCWSTR)L"%02d",nSec);
- break;
- case 't':
- sPart = nHour>12? (FX_LPCWSTR)L"pm": (FX_LPCWSTR)L"am";
- break;
- }
- i+=2;
- }
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && 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 (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c)
- {
- switch (c)
- {
- case 'y':
- sPart.Format((FX_LPCWSTR)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;
-}
-
-/* -------------------------------------------------------------------------- */
-
-//function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
-FX_BOOL CJS_PublicMethods::AFNumber_Format(OBJ_METHOD_PARAMS)
-{
-#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];
- int iSepStyle = params[1];
- int iNegStyle = params[2];
- int icurrStyle = params[3]; //it's no use!
- std::wstring wstrCurrency(params[4].operator CFX_WideString());
- FX_BOOL bCurrencyPrepend = params[5];
-
- 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 bNagative = FALSE;
-
- strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
- if (strValue.IsEmpty())
- {
- dValue = 0;
- strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
- 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,iDecNagative;
- iDecPositive = iDec2;
- iDecNagative = 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);
-
- if (bCurrencyPrepend)
- strValue2 = wstrCurrency + strValue2;
- else
- strValue2 = strValue2 + wstrCurrency;
-
-
-
- /////////////////////////////////////////////////////////////////////////
- //for processing negative style
- if (bNagative)
- {
- 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;
-}
-
-//function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
-FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(OBJ_METHOD_PARAMS)
-{
- 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];
-
- 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);
- if (wstrValue.IsEmpty())
- return TRUE;
-
- CFX_WideString swTemp = wstrValue;
- swTemp.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L".");
- if (!IsNumber(swTemp)) //!(IsNumber(wstrChange) &&
- {
- pEvent->Rc() = FALSE;
- sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
- Alert(pContext, sError);
- return TRUE;
- }
- return TRUE; // it happens after the last keystroke and before validating,
- }
-
- std::wstring w_strValue2 (w_strValue);
- std::wstring w_strChange2(w_strChange);
-
- 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;
- }
- 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;
-
-}
-
-//function AFPercent_Format(nDec, sepStyle)
-FX_BOOL CJS_PublicMethods::AFPercent_Format(OBJ_METHOD_PARAMS)
-{
-#if _FX_OS_ != _FX_ANDROID_
- 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();
-
-// HWND hMainFrame = NULL;
-//
-// CPDFSDK_FormFillApp *pApp = pContext->GetReaderApp();
-// ASSERT(pApp);
-// hMainFrame = pApp->GetMainFrameWnd();
-
- CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
-
- if (strValue.IsEmpty())
- return TRUE;
-
- int iDec = params[0];
- int iSepStyle = params[1];
-
- //ASSERT(iDec > 0);
- if (iDec < 0)
- iDec = -iDec;
-
- 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 bNagative = FALSE;
- strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
- if (strValue.IsEmpty())
- {
- dValue = 0;
- strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
- }
-
- 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,iDecNagative;
- iDecPositive = iDec2;
- iDecNagative = iDec2;
-
- for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3)
- {
- strValue.Insert(iDecPositive,cSeperator);
- iMax++;
- }
- }
- ////////////////////////////////////////////////////////////////////
- //nagative mark
- if(bNagative)
- strValue = "-" + strValue;
- strValue += "%";
- Value = CFX_WideString::FromLocal(strValue);
-#endif
- return TRUE;
-}
-//AFPercent_Keystroke(nDec, sepStyle)
-FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(OBJ_METHOD_PARAMS)
-{
- return AFNumber_Keystroke(cc,params,vRet,sError);
-}
-
-//function AFDate_FormatEx(cFormat)
-FX_BOOL CJS_PublicMethods::AFDate_FormatEx(OBJ_METHOD_PARAMS)
-{
- 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].operator CFX_WideString();
-
- 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), (FX_LPCWSTR)sFormat);
- Alert(pContext, swMsg);
- 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]);
- nHour = (int)ParseStringToNumber(wsArray[3]);
- nMin = (int)ParseStringToNumber(wsArray[4]);
- nSec = (int)ParseStringToNumber(wsArray[5]);
- nYear = (int)ParseStringToNumber(wsArray[7]);
-
- double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
-
- if (JS_PortIsNan(dRet))
- {
- dRet = JS_DateParse(strValue);
- }
-
- return dRet;
-}
-
-//AFDate_KeystrokeEx(cFormat)
-FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(OBJ_METHOD_PARAMS)
-{
- 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].operator CFX_WideString();
-
- 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), (FX_LPCWSTR)sFormat);
- Alert(pContext, swMsg);
- pEvent->Rc() = FALSE;
- return TRUE;
- }
- }
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFDate_Format(OBJ_METHOD_PARAMS)
-{
- 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];
- FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"m/d", (FX_LPCWSTR)L"m/d/yy", (FX_LPCWSTR)L"mm/dd/yy", (FX_LPCWSTR)L"mm/yy", (FX_LPCWSTR)L"d-mmm", (FX_LPCWSTR)L"d-mmm-yy", (FX_LPCWSTR)L"dd-mmm-yy",
- (FX_LPCWSTR)L"yy-mm-dd", (FX_LPCWSTR)L"mmm-yy", (FX_LPCWSTR)L"mmmm-yy", (FX_LPCWSTR)L"mmm d, yyyy", (FX_LPCWSTR)L"mmmm d, yyyy",
- (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
-
- ASSERT(iIndex < sizeof(cFormats)/sizeof(FX_LPCWSTR));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
- 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(OBJ_METHOD_PARAMS)
-{
- 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];
- FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"m/d", (FX_LPCWSTR)L"m/d/yy", (FX_LPCWSTR)L"mm/dd/yy", (FX_LPCWSTR)L"mm/yy", (FX_LPCWSTR)L"d-mmm", (FX_LPCWSTR)L"d-mmm-yy", (FX_LPCWSTR)L"dd-mmm-yy",
- (FX_LPCWSTR)L"yy-mm-dd", (FX_LPCWSTR)L"mmm-yy", (FX_LPCWSTR)L"mmmm-yy", (FX_LPCWSTR)L"mmm d, yyyy", (FX_LPCWSTR)L"mmmm d, yyyy",
- (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
-
- ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
- 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(OBJ_METHOD_PARAMS)
-{
- 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];
- FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"HH:MM", (FX_LPCWSTR)L"h:MM tt", (FX_LPCWSTR)L"HH:MM:ss", (FX_LPCWSTR)L"h:MM:ss tt"};
-
- ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
- 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(OBJ_METHOD_PARAMS)
-{
- 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];
- FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"HH:MM", (FX_LPCWSTR)L"h:MM tt", (FX_LPCWSTR)L"HH:MM:ss", (FX_LPCWSTR)L"h:MM:ss tt"};
-
- ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
- 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(OBJ_METHOD_PARAMS)
-{
- return AFDate_FormatEx(cc,params,vRet,sError);
-}
-
-FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(OBJ_METHOD_PARAMS)
-{
- return AFDate_KeystrokeEx(cc,params,vRet,sError);
-}
-
-//function AFSpecial_Format(psf)
-FX_BOOL CJS_PublicMethods::AFSpecial_Format(OBJ_METHOD_PARAMS)
-{
- 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];
-
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString& Value = pEvent->Value();
- std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(Value);
-
- 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(OBJ_METHOD_PARAMS)
-{
- 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].operator CFX_WideString();
- if (wstrMask.IsEmpty()) return TRUE;
-
- std::wstring wstrValue(valEvent);
-
- 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));
- pEvent->Rc() = FALSE;
- }
- return TRUE;
- }
-
-
- CFX_WideString &wideChange = pEvent->Change();
- std::wstring wChange(wideChange);
-
- if (wChange.empty())
- return TRUE;
- int iIndexMask = pEvent->SelStart();
- //iIndexMask++;
-
-
- if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength())
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
- pEvent->Rc() = FALSE;
- return TRUE;
- }
-
-
- if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
- 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));
- pEvent->Rc() = FALSE;
- return TRUE;
- }
- wchar_t w_Mask = wstrMask[iIndexMask];
- if (!isReservedMaskChar(w_Mask))
- {
- //wChange.insert(it,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(OBJ_METHOD_PARAMS)
-{
- 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 = (int)params[0];
-
- if(!pEvent->m_pValue)
- return FALSE;
- //CJS_Value val = pEvent->Value();
- CFX_WideString& val = pEvent->Value();
- std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(val);
- std::wstring wstrChange(pEvent->Change());
-
- 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(OBJ_METHOD_PARAMS)
-{
- 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;
- return TRUE;
- }
-
- CFX_WideString prefix,postfix;
-
- 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"";
-
- vRet = prefix + pEventHandler->Change() + postfix;
-
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFParseDateEx(OBJ_METHOD_PARAMS)
-{
- 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].operator CFX_WideString();
- CFX_WideString sFormat = params[1].operator CFX_WideString();
-
- FX_BOOL bWrongFormat = FALSE;
- double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
-
- if (JS_PortIsNan(dDate))
- {
- CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
- Alert((CJS_Context *)cc, swMsg);
- return FALSE;
- }
-
- vRet = dDate;
-
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFSimple(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 3)
- {
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- vRet = (double)AF_Simple(params[0].operator CFX_WideString(), (double)params[1], (double)params[2]);
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFMakeNumber(OBJ_METHOD_PARAMS)
-{
- 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].operator CFX_WideString());
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFSimple_Calculate(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- if (params.size() != 2)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CJS_Value params1 = params[1];
-
- if (!params1.IsArrayObject() && params1.GetType() != VT_string)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
- ASSERT(pReaderDoc != NULL);
-
- CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
- ASSERT(pReaderInterForm != NULL);
-
- CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- double dValue;
- CFX_WideString sFunction = params[0].operator CFX_WideString();
- if (wcscmp(sFunction, L"PRD") == 0)
- dValue = 1.0;
- else
- dValue = 0.0;
-
- CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
-
- 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.operator CFX_WideString();
-
- 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());
- 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());
- break;
- }
- else
- continue;
- }
- }
- break;
- }
- case FIELDTYPE_LISTBOX:
- {
- dTemp = 0.0;
- if (pFormField->CountSelectedItems() > 1)
- break;
- else
- {
- dTemp = ParseStringToNumber(pFormField->GetValue());
- break;
- }
- }
- default:
- break;
- }
-
- if (i == 0 && j == 0 && (wcscmp(sFunction,L"MIN") == 0 || wcscmp(sFunction, L"MAX") == 0))
- dValue = dTemp;
-
- dValue = AF_Simple(sFunction, dValue, dTemp);
-
- nFieldsCount++;
- }
- }
- }
-
- if (wcscmp(sFunction, 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;
-
- return TRUE;
-}
-
-/* This function validates the current event to ensure that its value is
-** within the specified range. */
-
-FX_BOOL CJS_PublicMethods::AFRange_Validate(OBJ_METHOD_PARAMS)
-{
- 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, bLessThan;
- double dGreaterThan, dLessThan;
- bGreaterThan = (FX_BOOL)params[0];
- CFX_WideString swMsg;
- dGreaterThan = (double)params[1];
- bLessThan = (FX_BOOL)params[2];
- dLessThan = (double)params[3];
-
- if (bGreaterThan && bLessThan)
- {
- if (dEentValue < dGreaterThan || dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1),(FX_LPCWSTR)params[1].operator CFX_WideString(), (FX_LPCWSTR)params[3].operator CFX_WideString());
- }
- else if (bGreaterThan)
- {
- if (dEentValue < dGreaterThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2), (FX_LPCWSTR)params[1].operator CFX_WideString());
- }
- else if (bLessThan)
- {
- if (dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3), (FX_LPCWSTR)params[3].operator CFX_WideString());
- }
-
- if (!swMsg.IsEmpty())
- {
- Alert(pContext, swMsg);
- pEvent->Rc() = FALSE;
- }
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFExtractNums(OBJ_METHOD_PARAMS)
-{
- 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].operator CFX_WideString();
- 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,(FX_LPCWSTR)sPart));
- sPart = L"";
- nIndex ++;
- }
- }
- }
-
- if (sPart.GetLength() > 0)
- {
- nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
- }
-
- if (nums.GetLength() > 0)
- vRet = nums;
- else
- vRet.SetNull();
-
- return TRUE;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/PublicMethods.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/resource.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/util.h"
+#include "../../include/javascript/Field.h"
+#include "../../include/javascript/color.h"
+#include "../../include/javascript/JS_Runtime.h"
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+
+
+/* -------------------------------- CJS_PublicMethods -------------------------------- */
+
+#define DOUBLE_CORRECT 0.000000000000001
+
+BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format,6)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke,6)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format,2)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke,2)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple,3)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate,2)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate,4)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx,2)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums,1)
+END_JS_STATIC_GLOBAL_FUN()
+
+IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
+
+struct stru_TbConvert
+{
+ FX_LPCSTR lpszJSMark;
+ FX_LPCSTR lpszCppMark;
+};
+
+static const stru_TbConvert fcTable[] = {"mmmm","%B",
+ "mmm", "%b",
+ "mm", "%m",
+ //"m"
+ "dddd","%A",
+ "ddd", "%a",
+ "dd", "%d",
+ //"d", "%w",
+ "yyyy","%Y",
+ "yy", "%y",
+ "HH", "%H",
+ //"H"
+ "hh", "%I",
+ //"h"
+ "MM", "%M",
+ //"M"
+ "ss", "%S",
+ //"s
+ "tt", "%p"
+ //"t"
+};
+
+static FX_LPCWSTR months[] =
+{
+ (FX_LPCWSTR)L"Jan", (FX_LPCWSTR)L"Feb", (FX_LPCWSTR)L"Mar", (FX_LPCWSTR)L"Apr", (FX_LPCWSTR)L"May", (FX_LPCWSTR)L"Jun", (FX_LPCWSTR)L"Jul", (FX_LPCWSTR)L"Aug", (FX_LPCWSTR)L"Sep", (FX_LPCWSTR)L"Oct", (FX_LPCWSTR)L"Nov", (FX_LPCWSTR)L"Dec"
+};
+
+static FX_LPCWSTR fullmonths[] =
+{
+ (FX_LPCWSTR)L"January", (FX_LPCWSTR)L"February", (FX_LPCWSTR)L"March", (FX_LPCWSTR)L"April", (FX_LPCWSTR)L"May", (FX_LPCWSTR)L"June", (FX_LPCWSTR)L"July", (FX_LPCWSTR)L"August", (FX_LPCWSTR)L"September", (FX_LPCWSTR)L"October", (FX_LPCWSTR)L"November", (FX_LPCWSTR)L"December"
+};
+
+FX_BOOL CJS_PublicMethods::IsNumber(FX_LPCWSTR string)
+{
+ CFX_WideString sTrim = StrTrim(string);
+ FX_LPCWSTR pTrim = sTrim;
+ FX_LPCWSTR 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');
+}
+
+FX_BOOL CJS_PublicMethods::IsDigit(char ch)
+{
+ 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'));
+}
+
+FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t 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':
+ return IsDigit(c_Change);
+ case L'A':
+ return IsAlphabetic(c_Change);
+ case L'O':
+ return IsAlphaNumeric(c_Change);
+ case L'X':
+ return TRUE;
+ 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';
+}
+
+double CJS_PublicMethods::AF_Simple(FX_LPCWSTR sFuction, double dValue1, double dValue2)
+{
+ if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"AVG") == 0 || FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"SUM") == 0)
+ {
+ return dValue1 + dValue2;
+ }
+ else if (FXSYS_wcsicmp(sFuction, (FX_LPCWSTR)L"PRD") == 0)
+ {
+ return dValue1 * dValue2;
+ }
+ else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MIN") == 0)
+ {
+ return FX_MIN(dValue1, dValue2);
+ }
+ else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MAX") == 0)
+ {
+ return FX_MAX(dValue1, dValue2);
+ }
+
+ return dValue1;
+}
+
+CFX_WideString CJS_PublicMethods::StrLTrim(FX_LPCWSTR pStr)
+{
+ while (*pStr && *pStr == L' ') pStr++;
+
+ return pStr;
+}
+
+CFX_WideString CJS_PublicMethods::StrRTrim(FX_LPCWSTR pStr)
+{
+ FX_LPCWSTR p = pStr;
+
+ while (*p) p++;
+ p--;
+ if (p >= pStr)
+ {
+ while (*p && *p == L' ') p--;
+ p++;
+ return CFX_WideString(pStr,p-pStr);
+ }
+ return L"";
+}
+
+CFX_WideString CJS_PublicMethods::StrTrim(FX_LPCWSTR pStr)
+{
+ return StrRTrim(StrLTrim(pStr));
+}
+
+CFX_ByteString CJS_PublicMethods::StrLTrim(FX_LPCSTR pStr)
+{
+ while (*pStr && *pStr == ' ') pStr++;
+
+ return pStr;
+}
+
+CFX_ByteString CJS_PublicMethods::StrRTrim(FX_LPCSTR pStr)
+{
+ FX_LPCSTR p = pStr;
+
+ while (*p) p++;
+ p--;
+ if (p >= pStr)
+ {
+ while (*p && *p == ' ') p--;
+ p++;
+ return CFX_ByteString(pStr,p-pStr);
+ }
+ return "";
+}
+
+CFX_ByteString CJS_PublicMethods::StrTrim(FX_LPCSTR pStr)
+{
+ return StrRTrim(StrLTrim(pStr));
+}
+
+double CJS_PublicMethods::ParseNumber(FX_LPCWSTR swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS)
+{
+ bDot = FALSE;
+ bSign = FALSE;
+ bKXJS = FALSE;
+
+ FX_BOOL bDigitExist = FALSE;
+
+ FX_LPCWSTR p = swSource;
+ wchar_t c;
+
+ FX_LPCWSTR pStart = NULL;
+ FX_LPCWSTR 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(FX_LPCWSTR swSource)
+{
+ FX_BOOL bAllDigits = FALSE;
+ FX_BOOL bDot = FALSE;
+ FX_BOOL bSign = FALSE;
+ FX_BOOL bKXJS = FALSE;
+
+ return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
+}
+
+FX_BOOL CJS_PublicMethods::ConvertStringToNumber(FX_LPCWSTR swSource, double & dRet, FX_BOOL & bDot)
+{
+ FX_BOOL bAllDigits = FALSE;
+ FX_BOOL bSign = FALSE;
+ FX_BOOL bKXJS = FALSE;
+
+ dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
+
+ 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.operator CFX_WideString();
+ 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,(FX_LPCSTR)StrTrim(p)));
+ break;
+ }
+ else
+ {
+ char * pSub = new char[pTemp - p + 1];
+ strncpy(pSub, p, pTemp - p);
+ *(pSub + (pTemp - p)) = '\0';
+
+ StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(pSub)));
+ 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;
+}
+
+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;
+}
+
+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((FX_LPCWSTR)L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
+ return JS_DateParse(swTemp);
+}
+
+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;
+
+ if (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 = value.GetAt(i) == 'p';
+ i++;
+ j++;
+ break;
+ }
+ }
+ else if (format.GetAt(i+1) == c && 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 = (value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm');
+ i += 2;
+ j += 2;
+ break;
+ }
+ }
+ else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && 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 (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && 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, 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 (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);
+ }
+ }
+
+ 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;
+ FX_WCHAR c;
+ while (i < format.GetLength())
+ {
+ c = format.GetAt(i);
+ sPart = L"";
+ switch (c)
+ {
+ case 'y':
+ case 'm':
+ case 'd':
+ case 'H':
+ case 'h':
+ case 'M':
+ case 's':
+ case 't':
+ if (format.GetAt(i+1) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ sPart += c;
+ break;
+ case 'm':
+ sPart.Format((FX_LPCWSTR)L"%d",nMonth);
+ break;
+ case 'd':
+ sPart.Format((FX_LPCWSTR)L"%d",nDay);
+ break;
+ case 'H':
+ sPart.Format((FX_LPCWSTR)L"%d",nHour);
+ break;
+ case 'h':
+ sPart.Format((FX_LPCWSTR)L"%d",nHour>12?nHour - 12:nHour);
+ break;
+ case 'M':
+ sPart.Format((FX_LPCWSTR)L"%d",nMin);
+ break;
+ case 's':
+ sPart.Format((FX_LPCWSTR)L"%d",nSec);
+ break;
+ case 't':
+ sPart += nHour>12?'p':'a';
+ break;
+ }
+ i++;
+ }
+ else if (format.GetAt(i+1) == c && format.GetAt(i+2) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ sPart.Format((FX_LPCWSTR)L"%02d",nYear - (nYear / 100) * 100);
+ break;
+ case 'm':
+ sPart.Format((FX_LPCWSTR)L"%02d",nMonth);
+ break;
+ case 'd':
+ sPart.Format((FX_LPCWSTR)L"%02d",nDay);
+ break;
+ case 'H':
+ sPart.Format((FX_LPCWSTR)L"%02d",nHour);
+ break;
+ case 'h':
+ sPart.Format((FX_LPCWSTR)L"%02d",nHour>12?nHour - 12:nHour);
+ break;
+ case 'M':
+ sPart.Format((FX_LPCWSTR)L"%02d",nMin);
+ break;
+ case 's':
+ sPart.Format((FX_LPCWSTR)L"%02d",nSec);
+ break;
+ case 't':
+ sPart = nHour>12? (FX_LPCWSTR)L"pm": (FX_LPCWSTR)L"am";
+ break;
+ }
+ i+=2;
+ }
+ else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && 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 (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ sPart.Format((FX_LPCWSTR)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;
+}
+
+/* -------------------------------------------------------------------------- */
+
+//function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
+FX_BOOL CJS_PublicMethods::AFNumber_Format(OBJ_METHOD_PARAMS)
+{
+#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];
+ int iSepStyle = params[1];
+ int iNegStyle = params[2];
+ int icurrStyle = params[3]; //it's no use!
+ std::wstring wstrCurrency(params[4].operator CFX_WideString());
+ FX_BOOL bCurrencyPrepend = params[5];
+
+ 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 bNagative = FALSE;
+
+ strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
+ if (strValue.IsEmpty())
+ {
+ dValue = 0;
+ strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
+ 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,iDecNagative;
+ iDecPositive = iDec2;
+ iDecNagative = 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);
+
+ if (bCurrencyPrepend)
+ strValue2 = wstrCurrency + strValue2;
+ else
+ strValue2 = strValue2 + wstrCurrency;
+
+
+
+ /////////////////////////////////////////////////////////////////////////
+ //for processing negative style
+ if (bNagative)
+ {
+ 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;
+}
+
+//function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
+FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(OBJ_METHOD_PARAMS)
+{
+ 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];
+
+ 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);
+ if (wstrValue.IsEmpty())
+ return TRUE;
+
+ CFX_WideString swTemp = wstrValue;
+ swTemp.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L".");
+ if (!IsNumber(swTemp)) //!(IsNumber(wstrChange) &&
+ {
+ pEvent->Rc() = FALSE;
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ Alert(pContext, sError);
+ return TRUE;
+ }
+ return TRUE; // it happens after the last keystroke and before validating,
+ }
+
+ std::wstring w_strValue2 (w_strValue);
+ std::wstring w_strChange2(w_strChange);
+
+ 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;
+ }
+ 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;
+
+}
+
+//function AFPercent_Format(nDec, sepStyle)
+FX_BOOL CJS_PublicMethods::AFPercent_Format(OBJ_METHOD_PARAMS)
+{
+#if _FX_OS_ != _FX_ANDROID_
+ 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();
+
+// HWND hMainFrame = NULL;
+//
+// CPDFSDK_FormFillApp *pApp = pContext->GetReaderApp();
+// ASSERT(pApp);
+// hMainFrame = pApp->GetMainFrameWnd();
+
+ CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
+
+ if (strValue.IsEmpty())
+ return TRUE;
+
+ int iDec = params[0];
+ int iSepStyle = params[1];
+
+ //ASSERT(iDec > 0);
+ if (iDec < 0)
+ iDec = -iDec;
+
+ 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 bNagative = FALSE;
+ strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
+ if (strValue.IsEmpty())
+ {
+ dValue = 0;
+ strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
+ }
+
+ 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,iDecNagative;
+ iDecPositive = iDec2;
+ iDecNagative = iDec2;
+
+ for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3)
+ {
+ strValue.Insert(iDecPositive,cSeperator);
+ iMax++;
+ }
+ }
+ ////////////////////////////////////////////////////////////////////
+ //nagative mark
+ if(bNagative)
+ strValue = "-" + strValue;
+ strValue += "%";
+ Value = CFX_WideString::FromLocal(strValue);
+#endif
+ return TRUE;
+}
+//AFPercent_Keystroke(nDec, sepStyle)
+FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(OBJ_METHOD_PARAMS)
+{
+ return AFNumber_Keystroke(cc,params,vRet,sError);
+}
+
+//function AFDate_FormatEx(cFormat)
+FX_BOOL CJS_PublicMethods::AFDate_FormatEx(OBJ_METHOD_PARAMS)
+{
+ 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].operator CFX_WideString();
+
+ 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), (FX_LPCWSTR)sFormat);
+ Alert(pContext, swMsg);
+ 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]);
+ nHour = (int)ParseStringToNumber(wsArray[3]);
+ nMin = (int)ParseStringToNumber(wsArray[4]);
+ nSec = (int)ParseStringToNumber(wsArray[5]);
+ nYear = (int)ParseStringToNumber(wsArray[7]);
+
+ double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
+
+ if (JS_PortIsNan(dRet))
+ {
+ dRet = JS_DateParse(strValue);
+ }
+
+ return dRet;
+}
+
+//AFDate_KeystrokeEx(cFormat)
+FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(OBJ_METHOD_PARAMS)
+{
+ 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].operator CFX_WideString();
+
+ 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), (FX_LPCWSTR)sFormat);
+ Alert(pContext, swMsg);
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+ }
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFDate_Format(OBJ_METHOD_PARAMS)
+{
+ 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];
+ FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"m/d", (FX_LPCWSTR)L"m/d/yy", (FX_LPCWSTR)L"mm/dd/yy", (FX_LPCWSTR)L"mm/yy", (FX_LPCWSTR)L"d-mmm", (FX_LPCWSTR)L"d-mmm-yy", (FX_LPCWSTR)L"dd-mmm-yy",
+ (FX_LPCWSTR)L"yy-mm-dd", (FX_LPCWSTR)L"mmm-yy", (FX_LPCWSTR)L"mmmm-yy", (FX_LPCWSTR)L"mmm d, yyyy", (FX_LPCWSTR)L"mmmm d, yyyy",
+ (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
+
+ ASSERT(iIndex < sizeof(cFormats)/sizeof(FX_LPCWSTR));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
+ 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(OBJ_METHOD_PARAMS)
+{
+ 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];
+ FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"m/d", (FX_LPCWSTR)L"m/d/yy", (FX_LPCWSTR)L"mm/dd/yy", (FX_LPCWSTR)L"mm/yy", (FX_LPCWSTR)L"d-mmm", (FX_LPCWSTR)L"d-mmm-yy", (FX_LPCWSTR)L"dd-mmm-yy",
+ (FX_LPCWSTR)L"yy-mm-dd", (FX_LPCWSTR)L"mmm-yy", (FX_LPCWSTR)L"mmmm-yy", (FX_LPCWSTR)L"mmm d, yyyy", (FX_LPCWSTR)L"mmmm d, yyyy",
+ (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
+
+ ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
+ 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(OBJ_METHOD_PARAMS)
+{
+ 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];
+ FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"HH:MM", (FX_LPCWSTR)L"h:MM tt", (FX_LPCWSTR)L"HH:MM:ss", (FX_LPCWSTR)L"h:MM:ss tt"};
+
+ ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
+ 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(OBJ_METHOD_PARAMS)
+{
+ 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];
+ FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"HH:MM", (FX_LPCWSTR)L"h:MM tt", (FX_LPCWSTR)L"HH:MM:ss", (FX_LPCWSTR)L"h:MM:ss tt"};
+
+ ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
+ 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(OBJ_METHOD_PARAMS)
+{
+ return AFDate_FormatEx(cc,params,vRet,sError);
+}
+
+FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(OBJ_METHOD_PARAMS)
+{
+ return AFDate_KeystrokeEx(cc,params,vRet,sError);
+}
+
+//function AFSpecial_Format(psf)
+FX_BOOL CJS_PublicMethods::AFSpecial_Format(OBJ_METHOD_PARAMS)
+{
+ 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];
+
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString& Value = pEvent->Value();
+ std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(Value);
+
+ 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(OBJ_METHOD_PARAMS)
+{
+ 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].operator CFX_WideString();
+ if (wstrMask.IsEmpty()) return TRUE;
+
+ std::wstring wstrValue(valEvent);
+
+ 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));
+ pEvent->Rc() = FALSE;
+ }
+ return TRUE;
+ }
+
+
+ CFX_WideString &wideChange = pEvent->Change();
+ std::wstring wChange(wideChange);
+
+ if (wChange.empty())
+ return TRUE;
+ int iIndexMask = pEvent->SelStart();
+ //iIndexMask++;
+
+
+ if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength())
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+
+
+ if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
+ 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));
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+ wchar_t w_Mask = wstrMask[iIndexMask];
+ if (!isReservedMaskChar(w_Mask))
+ {
+ //wChange.insert(it,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(OBJ_METHOD_PARAMS)
+{
+ 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 = (int)params[0];
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ //CJS_Value val = pEvent->Value();
+ CFX_WideString& val = pEvent->Value();
+ std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(val);
+ std::wstring wstrChange(pEvent->Change());
+
+ 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(OBJ_METHOD_PARAMS)
+{
+ 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;
+ return TRUE;
+ }
+
+ CFX_WideString prefix,postfix;
+
+ 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"";
+
+ vRet = prefix + pEventHandler->Change() + postfix;
+
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFParseDateEx(OBJ_METHOD_PARAMS)
+{
+ 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].operator CFX_WideString();
+ CFX_WideString sFormat = params[1].operator CFX_WideString();
+
+ FX_BOOL bWrongFormat = FALSE;
+ double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
+
+ if (JS_PortIsNan(dDate))
+ {
+ CFX_WideString swMsg;
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
+ Alert((CJS_Context *)cc, swMsg);
+ return FALSE;
+ }
+
+ vRet = dDate;
+
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFSimple(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 3)
+ {
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ vRet = (double)AF_Simple(params[0].operator CFX_WideString(), (double)params[1], (double)params[2]);
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFMakeNumber(OBJ_METHOD_PARAMS)
+{
+ 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].operator CFX_WideString());
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFSimple_Calculate(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ if (params.size() != 2)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CJS_Value params1 = params[1];
+
+ if (!params1.IsArrayObject() && params1.GetType() != VT_string)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
+ ASSERT(pReaderDoc != NULL);
+
+ CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
+ ASSERT(pReaderInterForm != NULL);
+
+ CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ double dValue;
+ CFX_WideString sFunction = params[0].operator CFX_WideString();
+ if (wcscmp(sFunction, L"PRD") == 0)
+ dValue = 1.0;
+ else
+ dValue = 0.0;
+
+ CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
+
+ 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.operator CFX_WideString();
+
+ 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());
+ 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());
+ break;
+ }
+ else
+ continue;
+ }
+ }
+ break;
+ }
+ case FIELDTYPE_LISTBOX:
+ {
+ dTemp = 0.0;
+ if (pFormField->CountSelectedItems() > 1)
+ break;
+ else
+ {
+ dTemp = ParseStringToNumber(pFormField->GetValue());
+ break;
+ }
+ }
+ default:
+ break;
+ }
+
+ if (i == 0 && j == 0 && (wcscmp(sFunction,L"MIN") == 0 || wcscmp(sFunction, L"MAX") == 0))
+ dValue = dTemp;
+
+ dValue = AF_Simple(sFunction, dValue, dTemp);
+
+ nFieldsCount++;
+ }
+ }
+ }
+
+ if (wcscmp(sFunction, 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;
+
+ return TRUE;
+}
+
+/* This function validates the current event to ensure that its value is
+** within the specified range. */
+
+FX_BOOL CJS_PublicMethods::AFRange_Validate(OBJ_METHOD_PARAMS)
+{
+ 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, bLessThan;
+ double dGreaterThan, dLessThan;
+ bGreaterThan = (FX_BOOL)params[0];
+ CFX_WideString swMsg;
+ dGreaterThan = (double)params[1];
+ bLessThan = (FX_BOOL)params[2];
+ dLessThan = (double)params[3];
+
+ if (bGreaterThan && bLessThan)
+ {
+ if (dEentValue < dGreaterThan || dEentValue > dLessThan)
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1),(FX_LPCWSTR)params[1].operator CFX_WideString(), (FX_LPCWSTR)params[3].operator CFX_WideString());
+ }
+ else if (bGreaterThan)
+ {
+ if (dEentValue < dGreaterThan)
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2), (FX_LPCWSTR)params[1].operator CFX_WideString());
+ }
+ else if (bLessThan)
+ {
+ if (dEentValue > dLessThan)
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3), (FX_LPCWSTR)params[3].operator CFX_WideString());
+ }
+
+ if (!swMsg.IsEmpty())
+ {
+ Alert(pContext, swMsg);
+ pEvent->Rc() = FALSE;
+ }
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFExtractNums(OBJ_METHOD_PARAMS)
+{
+ 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].operator CFX_WideString();
+ 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,(FX_LPCWSTR)sPart));
+ sPart = L"";
+ nIndex ++;
+ }
+ }
+ }
+
+ if (sPart.GetLength() > 0)
+ {
+ nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
+ }
+
+ if (nums.GetLength() > 0)
+ vRet = nums;
+ else
+ vRet.SetNull();
+
+ return TRUE;
+}
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index c1ef76c3b8..a3e61c01ab 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -1,1134 +1,1134 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/app.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/resource.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/Document.h"
-
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-/* ---------------------------- TimerObj ---------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_TimerObj)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_TimerObj)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
-
-TimerObj::TimerObj(CJS_Object* pJSObject)
-: CJS_EmbedObj(pJSObject),
-m_pTimer(NULL)
-{
-
-}
-
-TimerObj::~TimerObj()
-{
-}
-
-void TimerObj::SetTimer(CJS_Timer* pTimer)
-{
- m_pTimer = pTimer;
-}
-
-CJS_Timer* TimerObj::GetTimer() const
-{
- return m_pTimer;
-}
-
-#define JS_STR_VIEWERTYPE_READER L"Reader"
-#define JS_STR_VIEWERTYPE_STANDARD L"Exchange"
-#define JS_STR_VIEWERVARIATION L"Full"
-#define JS_STR_PLATFORM L"WIN"
-#define JS_STR_LANGUANGE L"ENU"
-#define JS_STR_VIEWERVERSION 8
-#define JS_NUM_FORMSVERSION 7
-
-#define JS_FILEPATH_MAXLEN 2000
-
-/* ---------------------------- app ---------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_App)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_App)
- JS_STATIC_PROP_ENTRY(activeDocs)
- JS_STATIC_PROP_ENTRY(calculate)
- JS_STATIC_PROP_ENTRY(formsVersion)
- JS_STATIC_PROP_ENTRY(fs)
- JS_STATIC_PROP_ENTRY(fullscreen)
- JS_STATIC_PROP_ENTRY(language)
- JS_STATIC_PROP_ENTRY(media)
- JS_STATIC_PROP_ENTRY(platform)
- JS_STATIC_PROP_ENTRY(runtimeHighlight)
- JS_STATIC_PROP_ENTRY(viewerType)
- JS_STATIC_PROP_ENTRY(viewerVariation)
- JS_STATIC_PROP_ENTRY(viewerVersion)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_App)
- JS_STATIC_METHOD_ENTRY(alert, 6)
- JS_STATIC_METHOD_ENTRY(beep, 1)
- JS_STATIC_METHOD_ENTRY(browseForDoc, 0)
- JS_STATIC_METHOD_ENTRY(clearInterval, 1)
- JS_STATIC_METHOD_ENTRY(clearTimeOut, 1)
- JS_STATIC_METHOD_ENTRY(execDialog, 3)
- JS_STATIC_METHOD_ENTRY(execMenuItem, 1)
- JS_STATIC_METHOD_ENTRY(findComponent, 1)
- JS_STATIC_METHOD_ENTRY(goBack, 0)
- JS_STATIC_METHOD_ENTRY(goForward, 0)
- JS_STATIC_METHOD_ENTRY(launchURL, 0)
- JS_STATIC_METHOD_ENTRY(mailMsg, 0)
- JS_STATIC_METHOD_ENTRY(newFDF, 0)
- JS_STATIC_METHOD_ENTRY(newDoc, 0)
- JS_STATIC_METHOD_ENTRY(openDoc, 0)
- JS_STATIC_METHOD_ENTRY(openFDF, 5)
- JS_STATIC_METHOD_ENTRY(popUpMenuEx, 0)
- JS_STATIC_METHOD_ENTRY(popUpMenu, 0)
- JS_STATIC_METHOD_ENTRY(response, 0)
- JS_STATIC_METHOD_ENTRY(setInterval, 2)
- JS_STATIC_METHOD_ENTRY(setTimeOut, 2)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_App,app)
-
-app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) ,
- m_bCalculate(true),
- m_pRuntime(NULL),
- m_bRuntimeHighLight(false)
-// m_pMenuHead(NULL)
-{
-}
-
-app::~app(void)
-{
- for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
- delete m_aTimer[i];
-
- m_aTimer.RemoveAll();
-}
-
-FX_BOOL app::activeDocs(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
-
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
-
- CJS_Array aDocs(pRuntime->GetIsolate());
-// int iNumDocs = pApp->CountDocuments();
-
-// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
-// {
- CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
- if (pDoc)
- {
- CJS_Document * pJSDocument = NULL;
-
- if (pDoc == pCurDoc)
- {
- JSFXObject pObj = JS_GetThisObj(*pRuntime);
-
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))
- {
- pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
- }
- }
- else
- {
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document"));
- pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
- ASSERT(pJSDocument != NULL);
-
-
- // pDocument->AttachDoc(pDoc);
- }
-
- aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));
- }
- // }
-
- if (aDocs.GetLength() > 0)
- vp << aDocs;
- else
- vp.SetNull();
- return TRUE;
- }
- return FALSE;
-}
-
-FX_BOOL app::calculate(OBJ_PROP_PARAMS)
-{
- if (vp.IsSetting())
- {
- bool bVP;
- vp >> bVP;
- m_bCalculate = (FX_BOOL)bVP;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CJS_Array aDocs(pRuntime->GetIsolate());
-// int iNumDocs = pApp->CountDocuments();
-//
-// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
-// {
- if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
- {
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
- ASSERT(pInterForm != NULL);
- pInterForm->EnableCalculate((FX_BOOL)m_bCalculate);
- }
-// }
- }
- else
- {
- vp << (bool)m_bCalculate;
- }
-
- return TRUE;
-}
-
-FX_BOOL app::formsVersion(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_NUM_FORMSVERSION;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::viewerType(OBJ_PROP_PARAMS)
-{
-
-
-
-
-
-
- if (vp.IsGetting())
- {
-// if (pApp->GetAppName() == PHANTOM)
-// vp << JS_STR_VIEWERTYPE_STANDARD;
-// else
-// vp << JS_STR_VIEWERTYPE_READER;
- vp << L"unknown";
-
- //vp << pApp->GetAppTitle();
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::viewerVariation(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_STR_VIEWERVARIATION;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::viewerVersion(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_STR_VIEWERVERSION;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::platform(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_STR_PLATFORM;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::language(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_STR_LANGUANGE;
- return TRUE;
- }
-
- return FALSE;
-}
-
-//creates a new fdf object that contains no data
-//comment: need reader support
-//note:
-//CFDF_Document * CPDFDoc_Environment::NewFDF();
-FX_BOOL app::newFDF(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-//opens a specified pdf document and returns its document object
-//comment:need reader support
-//note: as defined in js reference, the proto of this function's fourth parmeters, how old an fdf document while do not show it.
-//CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
-
-FX_BOOL app::openFDF(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL app::alert(OBJ_METHOD_PARAMS)
-{
- int iSize = params.size();
- if (iSize < 1)
- return FALSE;
-
- CFX_WideString swMsg = L"";
- CFX_WideString swTitle = L"";
- int iIcon = 0;
- int iType = 0;
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = params[0];
- {
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
- swMsg = CJS_Value(isolate,pValue,VT_unknown).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
- swTitle = CJS_Value(isolate, pValue,VT_unknown).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"nIcon");
- iIcon = (int)CJS_Value(isolate,pValue,VT_unknown);
-
- pValue = JS_GetObjectElement(isolate,pObj,L"nType");
- iType = (int)CJS_Value(isolate,pValue,VT_unknown);
- }
-
- if (swMsg == L"")
- {
- CJS_Array carray(isolate);
- if (params[0].ConvertToArray(carray))
- {
- int iLenth = carray.GetLength();
- CJS_Value* pValue = new CJS_Value(isolate);
-// if (iLenth == 1)
-// pValue = new CJS_Value(isolate);
-// else if (iLenth > 1)
-// pValue = new CJS_Value[iLenth];
-
- for(int i = 0; i < iLenth; i++)
- {
- carray.GetElement(i, *pValue);
- swMsg += (*pValue).operator CFX_WideString();
- if (i < iLenth - 1)
- swMsg += L", ";
- }
-
- if(pValue) delete pValue;
-// if ((iLenth > 1) && pValue)
-// {
-// delete[]pValue;
-// pValue = NULL;
-// }
-// else if ((iLenth == 1) && pValue)
-// {
-// delete pValue;
-// pValue = NULL;
-// }
- }
- }
-
- if (swTitle == L"")
- swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
- }
- else if (params[0].GetType() == VT_boolean)
- {
- FX_BOOL bGet = (FX_BOOL)params[0];
- if (bGet)
- swMsg = L"true";
- else
- swMsg = L"false";
-
- swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
- }
- else
- {
- swMsg = params[0];
- swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
- }
- }
- else
- {
- if (params[0].GetType() == VT_boolean)
- {
- FX_BOOL bGet = (FX_BOOL)params[0];
- if (bGet)
- swMsg = L"true";
- else
- swMsg = L"false";
- }
- else
- {
- swMsg = params[0];
- }
- swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
-
- for(int i = 1;i<iSize;i++)
- {
- if (i == 1)
- iIcon = int(params[i]);
- if (i == 2)
- iType = int(params[i]);
- if (i == 3)
- swTitle = params[i];
- }
- }
-
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
- pRuntime->BeginBlock();
- vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc),swMsg,swTitle,iType,iIcon);
- pRuntime->EndBlock();
-
- return TRUE;
-}
-
-
-FX_BOOL app::beep(OBJ_METHOD_PARAMS)
-{
- if (params.size() == 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp();
- pEnv->JS_appBeep((int)params[0]);
-
- return TRUE;
- }
- else
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-}
-
-FX_BOOL app::findComponent(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL app::popUpMenuEx(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::fs(OBJ_PROP_PARAMS)
-{
-#ifdef FOXIT_CHROME_BUILD
- return FALSE;
-#else
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- if (vp.IsGetting())
- {
- return TRUE;
- }
- else
- {
- return TRUE;
- }
-#endif
-}
-
-FX_BOOL app::setInterval(OBJ_METHOD_PARAMS)
-{
- if (params.size() > 2 || params.size() == 0)
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";
- if (script.IsEmpty())
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
- return TRUE;
- }
-
- FX_DWORD dwInterval = params.size() > 1 ? (int)params[1] : 1000;
-
- CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
- ASSERT(pApp);
- CJS_Timer* pTimer = new CJS_Timer(this, pApp);
- m_aTimer.Add(pTimer);
-
- pTimer->SetType(0);
- pTimer->SetRuntime(pRuntime);
- pTimer->SetJScript(script);
- pTimer->SetTimeOut(0);
-// pTimer->SetStartTime(GetTickCount());
- pTimer->SetJSTimer(dwInterval);
-
- JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
-
- CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
- ASSERT(pJS_TimerObj != NULL);
-
- TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
- ASSERT(pTimerObj != NULL);
-
- pTimerObj->SetTimer(pTimer);
-
- vRet = pRetObj;
-
- return TRUE;
-}
-
-FX_BOOL app::setTimeOut(OBJ_METHOD_PARAMS)
-{
- if (params.size() > 2 || params.size() == 0)
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";
- if (script.IsEmpty())
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
- return TRUE;
- }
-
- FX_DWORD dwTimeOut = params.size() > 1 ? (int)params[1] : 1000;
-
- CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
- ASSERT(pApp);
- CJS_Timer* pTimer = new CJS_Timer(this, pApp);
- m_aTimer.Add(pTimer);
-
- pTimer->SetType(1);
- pTimer->SetRuntime(pRuntime);
- pTimer->SetJScript(script);
- pTimer->SetTimeOut(dwTimeOut);
-// pTimer->SetStartTime(GetTickCount());
-// pTimer->SetJSTimer(1000);
- pTimer->SetJSTimer(dwTimeOut);
-
- JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
-// ASSERT(pRetObj != NULL);
-
- CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
- ASSERT(pJS_TimerObj != NULL);
-
- TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
- ASSERT(pTimerObj != NULL);
-
- pTimerObj->SetTimer(pTimer);
-
- vRet = pRetObj;
-
- return TRUE;
-}
-
-FX_BOOL app::clearTimeOut(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- if (params[0].GetType() == VT_fxobject)
- {
- JSFXObject pObj = (JSFXObject)params[0];
- {
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
- {
- if (CJS_Object* pJSObj = (CJS_Object*)params[0])
- {
- if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
- {
- if (CJS_Timer* pTimer = pTimerObj->GetTimer())
- {
- pTimer->KillJSTimer();
-
- for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
- {
- if (m_aTimer[i] == pTimer)
- {
- m_aTimer.RemoveAt(i);
- break;
- }
- }
-
- delete pTimer;
- pTimerObj->SetTimer(NULL);
- }
- }
- }
- }
- }
- }
-
- return TRUE;
-}
-
-FX_BOOL app::clearInterval(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- if (params[0].GetType() == VT_fxobject)
- {
- JSFXObject pObj = (JSFXObject)params[0];
- {
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
- {
- if (CJS_Object* pJSObj = (CJS_Object*)params[0])
- {
- if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
- {
- if (CJS_Timer* pTimer = pTimerObj->GetTimer())
- {
- pTimer->KillJSTimer();
-
- for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
- {
- if (m_aTimer[i] == pTimer)
- {
- m_aTimer.RemoveAt(i);
- break;
- }
- }
-
- delete pTimer;
- pTimerObj->SetTimer(NULL);
- }
- }
- }
- }
- }
- }
-
- return TRUE;
-}
-
-FX_BOOL app::execMenuItem(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-void app::TimerProc(CJS_Timer* pTimer)
-{
- ASSERT(pTimer != NULL);
-
- switch (pTimer->GetType())
- {
- case 0: //interval
- RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
- break;
- case 1:
- if (pTimer->GetTimeOut() > 0)
- {
- RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
- pTimer->KillJSTimer();
- }
- break;
- }
-
-}
-
-void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript)
-{
- ASSERT(pRuntime != NULL);
-
- if (!pRuntime->IsBlocking())
- {
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
- pContext->OnExternal_Exec();
- CFX_WideString wtInfo;
- pContext->RunScript(wsScript,wtInfo);
- pRuntime->ReleaseContext(pContext);
- }
-}
-
-FX_BOOL app::goBack(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- return TRUE;
-}
-
-FX_BOOL app::goForward(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- return TRUE;
-}
-
-FX_BOOL app::mailMsg(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- 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() < 2)
- return FALSE;
-
- bUI = params.size()>=1?(int)params[0]:TRUE;
- cTo = params.size()>=2?(const wchar_t*)(FX_LPCWSTR)params[1].operator CFX_WideString():L"";
- cCc = params.size()>=3?(const wchar_t*)(FX_LPCWSTR)params[2].operator CFX_WideString():L"";
- cBcc = params.size()>=4?(const wchar_t*)(FX_LPCWSTR)params[3].operator CFX_WideString():L"";
- cSubject = params.size()>=5?(const wchar_t*)(FX_LPCWSTR)params[4].operator CFX_WideString():L"";
- cMsg = params.size()>=6?(const wchar_t*)(FX_LPCWSTR)params[5].operator CFX_WideString():L"";
-
-
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject)params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
- bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
- cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
- cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
- cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
- cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
- cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
- }
-
-
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
- pRuntime->BeginBlock();
- pApp->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
- ///////////////////////////////////////////////////////////////////////////////////////////////
- pRuntime->EndBlock();
-
- //return bRet;
- return FALSE;
-}
-
-FX_BOOL app::launchURL(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
-
-
-
- CFX_WideString swURL = params[0].operator CFX_WideString();
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->BeginBlock();
-// FX_BOOL bRet = pApp->OpenURL(swURL);
- pRuntime->EndBlock();
-
-// return bRet;
- return FALSE;
-}
-
-FX_BOOL app::runtimeHighlight(OBJ_PROP_PARAMS)
-{
- if (vp.IsSetting())
- {
- vp>>m_bRuntimeHighLight;
- }
- else
- {
- vp<<m_bRuntimeHighLight;
- }
-
- return TRUE;
-}
-
-FX_BOOL app::fullscreen(OBJ_PROP_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::popUpMenu(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-
-FX_BOOL app::browseForDoc(OBJ_METHOD_PARAMS)
-{
- //This method may trigger a "file save" dialog,while enable user to save contents of the document.
- //Such action is considered to be unsafe.
- if (IsSafeMode(cc)) return TRUE;
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- bool bSave = false;
- CFX_ByteString cFilenameInit = CFX_ByteString();
- CFX_ByteString cFSInit = CFX_ByteString();
-
- if(params.size()>0 && (params[0].GetType() == VT_object))
- {
- JSObject pObj = (JSObject )params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"bSave");
- bSave = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate, pObj,L"cFilenameInit");
- {
- CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));
- cFilenameInit = t.operator CFX_ByteString();
- }
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cFSInit");
- {
- CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));
- cFSInit = t.operator CFX_ByteString();
- }
- }
- else
- {
- if(params.size() >= 1)
- {
- bSave = (bool)params[0];
- }
- if(params.size() >= 2)
- {
- CJS_Value t = params[1];
- cFilenameInit = t.operator CFX_ByteString();
- }
- if(params.size() >= 3)
- {
- CJS_Value t = params[2];
- cFSInit = t.operator CFX_ByteString();
- }
- }
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CFX_WideString wsFileNameInit = CFX_WideString::FromLocal(cFilenameInit);
- CFX_WideString wsFSInit = CFX_WideString::FromLocal(cFSInit);
- CFX_WideString wsFilePath = pApp->JS_appbrowseForDoc(bSave, wsFileNameInit);
- if(wsFilePath.IsEmpty())
- return FALSE;
-
- JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
-
- JS_PutObjectString(isolate,pRetObj, L"cPath", SysPathToPDFPath(wsFilePath));
- JS_PutObjectString(isolate,pRetObj, L"cURL", SysPathToPDFPath(wsFilePath));
-
- if (!cFSInit.IsEmpty())
- {
- JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal(cFSInit.GetBuffer(cFSInit.GetLength())));
- }
- else
- {
- JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal("DOS"));
- }
-
- vRet = pRetObj;
-
- return TRUE;
-}
-
-CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath)
-{
- CFX_WideString sRet = L"/";
-
- for (int i=0,sz=sOldPath.GetLength(); i<sz; i++)
- {
- wchar_t c = sOldPath.GetAt(i);
- if (c == L':')
- {
- }
- else
- {
- if (c == L'\\')
- {
- sRet += L"/";
- }
- else
- {
- sRet += c;
- }
- }
- }
-
- return sRet;
-}
-
-CFX_WideString app::PDFPathToSysPath(const CFX_WideString& sOldPath)
-{
- //strLPath = "D:\temporay.fdf";
- CFX_WideString strOPath = sOldPath;
- strOPath.TrimLeft();
- strOPath.TrimRight();
-
- if (strOPath.GetAt(0) == L'/' && strOPath.GetAt(2) == L'/')
- {
- wchar_t c_Drive = strOPath.GetAt(1);
- if ((c_Drive >= L'a' && c_Drive <= L'z' )||( c_Drive >= L'A' && c_Drive <= L'Z'))
- {
- strOPath.Replace((FX_LPCWSTR)L"/",(FX_LPCWSTR)L"\\");
- //strOPath.SetAt(0,'');
- strOPath.Insert(2,':');
- strOPath.Delete(0);
- }
- }
-
- return strOPath;
-}
-
-CFX_WideString app::RelativePathToSysPath(const CFX_WideString& sOldPath, const CFX_WideString& sFilePath)
-{
-// if (!PathIsRelative(sOldPath)) return sOldPath;
-
- int nSplit = 0;
- for (int i=sFilePath.GetLength()-1; i>=0; i--)
- {
- if (sFilePath[i] == '\\' || sFilePath[i] == '/')
- {
- nSplit = i;
- break;
- }
- }
-
- return sFilePath.Left(nSplit+1) + sOldPath;
-}
-
-FX_BOOL app::newDoc(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::openDoc(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::response(OBJ_METHOD_PARAMS)
-{
- CFX_WideString swQuestion = L"";
- CFX_WideString swLabel = L"";
-#ifndef FOXIT_CHROME_BUILD
- CFX_WideString swTitle = L"Foxit";
-#else
- CFX_WideString swTitle = L"PDF";
-#endif
- CFX_WideString swDefault = L"";
- CFX_WideString swResponse = L"";
- bool bPassWord = false;
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- int iLength = params.size();
- if (iLength > 0 && params[0].GetType() == VT_object)
- {
-
- JSObject pObj = (JSObject )params[0];
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion");
- swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
- swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");
- swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cLabel");
- swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"bPassword");
- bPassWord = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
- }
- else
- {
- switch(iLength)
- {
- case 1:
- swQuestion = params[0];
- break;
- case 2:
- swQuestion = params[0];
- swTitle = params[1];
- break;
- case 3:
- swQuestion = params[0];
- swTitle = params[1];
- swDefault = params[2];
- break;
- case 4:
- swQuestion = params[0];
- swTitle = params[1];
- swDefault = params[2];
- bPassWord = params[3];
- break;
- case 5:
- swQuestion = params[0];
- swTitle = params[1];
- swDefault = params[2];
- bPassWord = params[3];
- swLabel = params[4];
- break;
- default:
- break;
- }
- }
-
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
- int nLength = 2048;
- char* pBuff = new char[nLength];
- nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength);
- if(nLength<=0)
- {
- vRet.SetNull();
- return FALSE;
- }
- else
- {
- nLength = nLength>2046?2046:nLength;
- pBuff[nLength] = 0;
- pBuff[nLength+1] = 0;
- swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength);
- vRet = swResponse;
- }
- delete[] pBuff;
-
- return TRUE;
-}
-
-FX_BOOL app::media(OBJ_PROP_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::execDialog(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/app.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/resource.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/Document.h"
+
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+
+/* ---------------------------- TimerObj ---------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_TimerObj)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_TimerObj)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
+
+TimerObj::TimerObj(CJS_Object* pJSObject)
+: CJS_EmbedObj(pJSObject),
+m_pTimer(NULL)
+{
+
+}
+
+TimerObj::~TimerObj()
+{
+}
+
+void TimerObj::SetTimer(CJS_Timer* pTimer)
+{
+ m_pTimer = pTimer;
+}
+
+CJS_Timer* TimerObj::GetTimer() const
+{
+ return m_pTimer;
+}
+
+#define JS_STR_VIEWERTYPE_READER L"Reader"
+#define JS_STR_VIEWERTYPE_STANDARD L"Exchange"
+#define JS_STR_VIEWERVARIATION L"Full"
+#define JS_STR_PLATFORM L"WIN"
+#define JS_STR_LANGUANGE L"ENU"
+#define JS_STR_VIEWERVERSION 8
+#define JS_NUM_FORMSVERSION 7
+
+#define JS_FILEPATH_MAXLEN 2000
+
+/* ---------------------------- app ---------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_App)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_App)
+ JS_STATIC_PROP_ENTRY(activeDocs)
+ JS_STATIC_PROP_ENTRY(calculate)
+ JS_STATIC_PROP_ENTRY(formsVersion)
+ JS_STATIC_PROP_ENTRY(fs)
+ JS_STATIC_PROP_ENTRY(fullscreen)
+ JS_STATIC_PROP_ENTRY(language)
+ JS_STATIC_PROP_ENTRY(media)
+ JS_STATIC_PROP_ENTRY(platform)
+ JS_STATIC_PROP_ENTRY(runtimeHighlight)
+ JS_STATIC_PROP_ENTRY(viewerType)
+ JS_STATIC_PROP_ENTRY(viewerVariation)
+ JS_STATIC_PROP_ENTRY(viewerVersion)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_App)
+ JS_STATIC_METHOD_ENTRY(alert, 6)
+ JS_STATIC_METHOD_ENTRY(beep, 1)
+ JS_STATIC_METHOD_ENTRY(browseForDoc, 0)
+ JS_STATIC_METHOD_ENTRY(clearInterval, 1)
+ JS_STATIC_METHOD_ENTRY(clearTimeOut, 1)
+ JS_STATIC_METHOD_ENTRY(execDialog, 3)
+ JS_STATIC_METHOD_ENTRY(execMenuItem, 1)
+ JS_STATIC_METHOD_ENTRY(findComponent, 1)
+ JS_STATIC_METHOD_ENTRY(goBack, 0)
+ JS_STATIC_METHOD_ENTRY(goForward, 0)
+ JS_STATIC_METHOD_ENTRY(launchURL, 0)
+ JS_STATIC_METHOD_ENTRY(mailMsg, 0)
+ JS_STATIC_METHOD_ENTRY(newFDF, 0)
+ JS_STATIC_METHOD_ENTRY(newDoc, 0)
+ JS_STATIC_METHOD_ENTRY(openDoc, 0)
+ JS_STATIC_METHOD_ENTRY(openFDF, 5)
+ JS_STATIC_METHOD_ENTRY(popUpMenuEx, 0)
+ JS_STATIC_METHOD_ENTRY(popUpMenu, 0)
+ JS_STATIC_METHOD_ENTRY(response, 0)
+ JS_STATIC_METHOD_ENTRY(setInterval, 2)
+ JS_STATIC_METHOD_ENTRY(setTimeOut, 2)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_App,app)
+
+app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) ,
+ m_bCalculate(true),
+ m_pRuntime(NULL),
+ m_bRuntimeHighLight(false)
+// m_pMenuHead(NULL)
+{
+}
+
+app::~app(void)
+{
+ for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
+ delete m_aTimer[i];
+
+ m_aTimer.RemoveAll();
+}
+
+FX_BOOL app::activeDocs(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
+
+ CJS_Array aDocs(pRuntime->GetIsolate());
+// int iNumDocs = pApp->CountDocuments();
+
+// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
+// {
+ CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
+ if (pDoc)
+ {
+ CJS_Document * pJSDocument = NULL;
+
+ if (pDoc == pCurDoc)
+ {
+ JSFXObject pObj = JS_GetThisObj(*pRuntime);
+
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))
+ {
+ pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
+ }
+ }
+ else
+ {
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document"));
+ pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
+ ASSERT(pJSDocument != NULL);
+
+
+ // pDocument->AttachDoc(pDoc);
+ }
+
+ aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));
+ }
+ // }
+
+ if (aDocs.GetLength() > 0)
+ vp << aDocs;
+ else
+ vp.SetNull();
+ return TRUE;
+ }
+ return FALSE;
+}
+
+FX_BOOL app::calculate(OBJ_PROP_PARAMS)
+{
+ if (vp.IsSetting())
+ {
+ bool bVP;
+ vp >> bVP;
+ m_bCalculate = (FX_BOOL)bVP;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CJS_Array aDocs(pRuntime->GetIsolate());
+// int iNumDocs = pApp->CountDocuments();
+//
+// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
+// {
+ if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
+ {
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
+ ASSERT(pInterForm != NULL);
+ pInterForm->EnableCalculate((FX_BOOL)m_bCalculate);
+ }
+// }
+ }
+ else
+ {
+ vp << (bool)m_bCalculate;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL app::formsVersion(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_NUM_FORMSVERSION;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::viewerType(OBJ_PROP_PARAMS)
+{
+
+
+
+
+
+
+ if (vp.IsGetting())
+ {
+// if (pApp->GetAppName() == PHANTOM)
+// vp << JS_STR_VIEWERTYPE_STANDARD;
+// else
+// vp << JS_STR_VIEWERTYPE_READER;
+ vp << L"unknown";
+
+ //vp << pApp->GetAppTitle();
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::viewerVariation(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_STR_VIEWERVARIATION;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::viewerVersion(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_STR_VIEWERVERSION;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::platform(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_STR_PLATFORM;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::language(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_STR_LANGUANGE;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+//creates a new fdf object that contains no data
+//comment: need reader support
+//note:
+//CFDF_Document * CPDFDoc_Environment::NewFDF();
+FX_BOOL app::newFDF(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+//opens a specified pdf document and returns its document object
+//comment:need reader support
+//note: as defined in js reference, the proto of this function's fourth parmeters, how old an fdf document while do not show it.
+//CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
+
+FX_BOOL app::openFDF(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL app::alert(OBJ_METHOD_PARAMS)
+{
+ int iSize = params.size();
+ if (iSize < 1)
+ return FALSE;
+
+ CFX_WideString swMsg = L"";
+ CFX_WideString swTitle = L"";
+ int iIcon = 0;
+ int iType = 0;
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = params[0];
+ {
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
+ swMsg = CJS_Value(isolate,pValue,VT_unknown).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
+ swTitle = CJS_Value(isolate, pValue,VT_unknown).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"nIcon");
+ iIcon = (int)CJS_Value(isolate,pValue,VT_unknown);
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"nType");
+ iType = (int)CJS_Value(isolate,pValue,VT_unknown);
+ }
+
+ if (swMsg == L"")
+ {
+ CJS_Array carray(isolate);
+ if (params[0].ConvertToArray(carray))
+ {
+ int iLenth = carray.GetLength();
+ CJS_Value* pValue = new CJS_Value(isolate);
+// if (iLenth == 1)
+// pValue = new CJS_Value(isolate);
+// else if (iLenth > 1)
+// pValue = new CJS_Value[iLenth];
+
+ for(int i = 0; i < iLenth; i++)
+ {
+ carray.GetElement(i, *pValue);
+ swMsg += (*pValue).operator CFX_WideString();
+ if (i < iLenth - 1)
+ swMsg += L", ";
+ }
+
+ if(pValue) delete pValue;
+// if ((iLenth > 1) && pValue)
+// {
+// delete[]pValue;
+// pValue = NULL;
+// }
+// else if ((iLenth == 1) && pValue)
+// {
+// delete pValue;
+// pValue = NULL;
+// }
+ }
+ }
+
+ if (swTitle == L"")
+ swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+ }
+ else if (params[0].GetType() == VT_boolean)
+ {
+ FX_BOOL bGet = (FX_BOOL)params[0];
+ if (bGet)
+ swMsg = L"true";
+ else
+ swMsg = L"false";
+
+ swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+ }
+ else
+ {
+ swMsg = params[0];
+ swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+ }
+ }
+ else
+ {
+ if (params[0].GetType() == VT_boolean)
+ {
+ FX_BOOL bGet = (FX_BOOL)params[0];
+ if (bGet)
+ swMsg = L"true";
+ else
+ swMsg = L"false";
+ }
+ else
+ {
+ swMsg = params[0];
+ }
+ swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+
+ for(int i = 1;i<iSize;i++)
+ {
+ if (i == 1)
+ iIcon = int(params[i]);
+ if (i == 2)
+ iType = int(params[i]);
+ if (i == 3)
+ swTitle = params[i];
+ }
+ }
+
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+ pRuntime->BeginBlock();
+ vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc),swMsg,swTitle,iType,iIcon);
+ pRuntime->EndBlock();
+
+ return TRUE;
+}
+
+
+FX_BOOL app::beep(OBJ_METHOD_PARAMS)
+{
+ if (params.size() == 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp();
+ pEnv->JS_appBeep((int)params[0]);
+
+ return TRUE;
+ }
+ else
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+}
+
+FX_BOOL app::findComponent(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL app::popUpMenuEx(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::fs(OBJ_PROP_PARAMS)
+{
+#ifdef FOXIT_CHROME_BUILD
+ return FALSE;
+#else
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ if (vp.IsGetting())
+ {
+ return TRUE;
+ }
+ else
+ {
+ return TRUE;
+ }
+#endif
+}
+
+FX_BOOL app::setInterval(OBJ_METHOD_PARAMS)
+{
+ if (params.size() > 2 || params.size() == 0)
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";
+ if (script.IsEmpty())
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ return TRUE;
+ }
+
+ FX_DWORD dwInterval = params.size() > 1 ? (int)params[1] : 1000;
+
+ CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
+ ASSERT(pApp);
+ CJS_Timer* pTimer = new CJS_Timer(this, pApp);
+ m_aTimer.Add(pTimer);
+
+ pTimer->SetType(0);
+ pTimer->SetRuntime(pRuntime);
+ pTimer->SetJScript(script);
+ pTimer->SetTimeOut(0);
+// pTimer->SetStartTime(GetTickCount());
+ pTimer->SetJSTimer(dwInterval);
+
+ JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
+
+ CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
+ ASSERT(pJS_TimerObj != NULL);
+
+ TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
+ ASSERT(pTimerObj != NULL);
+
+ pTimerObj->SetTimer(pTimer);
+
+ vRet = pRetObj;
+
+ return TRUE;
+}
+
+FX_BOOL app::setTimeOut(OBJ_METHOD_PARAMS)
+{
+ if (params.size() > 2 || params.size() == 0)
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";
+ if (script.IsEmpty())
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ return TRUE;
+ }
+
+ FX_DWORD dwTimeOut = params.size() > 1 ? (int)params[1] : 1000;
+
+ CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
+ ASSERT(pApp);
+ CJS_Timer* pTimer = new CJS_Timer(this, pApp);
+ m_aTimer.Add(pTimer);
+
+ pTimer->SetType(1);
+ pTimer->SetRuntime(pRuntime);
+ pTimer->SetJScript(script);
+ pTimer->SetTimeOut(dwTimeOut);
+// pTimer->SetStartTime(GetTickCount());
+// pTimer->SetJSTimer(1000);
+ pTimer->SetJSTimer(dwTimeOut);
+
+ JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
+// ASSERT(pRetObj != NULL);
+
+ CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
+ ASSERT(pJS_TimerObj != NULL);
+
+ TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
+ ASSERT(pTimerObj != NULL);
+
+ pTimerObj->SetTimer(pTimer);
+
+ vRet = pRetObj;
+
+ return TRUE;
+}
+
+FX_BOOL app::clearTimeOut(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ if (params[0].GetType() == VT_fxobject)
+ {
+ JSFXObject pObj = (JSFXObject)params[0];
+ {
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
+ {
+ if (CJS_Object* pJSObj = (CJS_Object*)params[0])
+ {
+ if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
+ {
+ if (CJS_Timer* pTimer = pTimerObj->GetTimer())
+ {
+ pTimer->KillJSTimer();
+
+ for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
+ {
+ if (m_aTimer[i] == pTimer)
+ {
+ m_aTimer.RemoveAt(i);
+ break;
+ }
+ }
+
+ delete pTimer;
+ pTimerObj->SetTimer(NULL);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+FX_BOOL app::clearInterval(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ if (params[0].GetType() == VT_fxobject)
+ {
+ JSFXObject pObj = (JSFXObject)params[0];
+ {
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
+ {
+ if (CJS_Object* pJSObj = (CJS_Object*)params[0])
+ {
+ if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
+ {
+ if (CJS_Timer* pTimer = pTimerObj->GetTimer())
+ {
+ pTimer->KillJSTimer();
+
+ for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
+ {
+ if (m_aTimer[i] == pTimer)
+ {
+ m_aTimer.RemoveAt(i);
+ break;
+ }
+ }
+
+ delete pTimer;
+ pTimerObj->SetTimer(NULL);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+FX_BOOL app::execMenuItem(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+void app::TimerProc(CJS_Timer* pTimer)
+{
+ ASSERT(pTimer != NULL);
+
+ switch (pTimer->GetType())
+ {
+ case 0: //interval
+ RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
+ break;
+ case 1:
+ if (pTimer->GetTimeOut() > 0)
+ {
+ RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
+ pTimer->KillJSTimer();
+ }
+ break;
+ }
+
+}
+
+void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript)
+{
+ ASSERT(pRuntime != NULL);
+
+ if (!pRuntime->IsBlocking())
+ {
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+ pContext->OnExternal_Exec();
+ CFX_WideString wtInfo;
+ pContext->RunScript(wsScript,wtInfo);
+ pRuntime->ReleaseContext(pContext);
+ }
+}
+
+FX_BOOL app::goBack(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ return TRUE;
+}
+
+FX_BOOL app::goForward(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ return TRUE;
+}
+
+FX_BOOL app::mailMsg(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ 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() < 2)
+ return FALSE;
+
+ bUI = params.size()>=1?(int)params[0]:TRUE;
+ cTo = params.size()>=2?(const wchar_t*)(FX_LPCWSTR)params[1].operator CFX_WideString():L"";
+ cCc = params.size()>=3?(const wchar_t*)(FX_LPCWSTR)params[2].operator CFX_WideString():L"";
+ cBcc = params.size()>=4?(const wchar_t*)(FX_LPCWSTR)params[3].operator CFX_WideString():L"";
+ cSubject = params.size()>=5?(const wchar_t*)(FX_LPCWSTR)params[4].operator CFX_WideString():L"";
+ cMsg = params.size()>=6?(const wchar_t*)(FX_LPCWSTR)params[5].operator CFX_WideString():L"";
+
+
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject)params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
+ bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
+ cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
+ cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
+ cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
+ cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
+ cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+ }
+
+
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ pRuntime->BeginBlock();
+ pApp->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+ ///////////////////////////////////////////////////////////////////////////////////////////////
+ pRuntime->EndBlock();
+
+ //return bRet;
+ return FALSE;
+}
+
+FX_BOOL app::launchURL(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+
+
+
+ CFX_WideString swURL = params[0].operator CFX_WideString();
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->BeginBlock();
+// FX_BOOL bRet = pApp->OpenURL(swURL);
+ pRuntime->EndBlock();
+
+// return bRet;
+ return FALSE;
+}
+
+FX_BOOL app::runtimeHighlight(OBJ_PROP_PARAMS)
+{
+ if (vp.IsSetting())
+ {
+ vp>>m_bRuntimeHighLight;
+ }
+ else
+ {
+ vp<<m_bRuntimeHighLight;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL app::fullscreen(OBJ_PROP_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::popUpMenu(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+
+FX_BOOL app::browseForDoc(OBJ_METHOD_PARAMS)
+{
+ //This method may trigger a "file save" dialog,while enable user to save contents of the document.
+ //Such action is considered to be unsafe.
+ if (IsSafeMode(cc)) return TRUE;
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ bool bSave = false;
+ CFX_ByteString cFilenameInit = CFX_ByteString();
+ CFX_ByteString cFSInit = CFX_ByteString();
+
+ if(params.size()>0 && (params[0].GetType() == VT_object))
+ {
+ JSObject pObj = (JSObject )params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"bSave");
+ bSave = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate, pObj,L"cFilenameInit");
+ {
+ CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));
+ cFilenameInit = t.operator CFX_ByteString();
+ }
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cFSInit");
+ {
+ CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));
+ cFSInit = t.operator CFX_ByteString();
+ }
+ }
+ else
+ {
+ if(params.size() >= 1)
+ {
+ bSave = (bool)params[0];
+ }
+ if(params.size() >= 2)
+ {
+ CJS_Value t = params[1];
+ cFilenameInit = t.operator CFX_ByteString();
+ }
+ if(params.size() >= 3)
+ {
+ CJS_Value t = params[2];
+ cFSInit = t.operator CFX_ByteString();
+ }
+ }
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CFX_WideString wsFileNameInit = CFX_WideString::FromLocal(cFilenameInit);
+ CFX_WideString wsFSInit = CFX_WideString::FromLocal(cFSInit);
+ CFX_WideString wsFilePath = pApp->JS_appbrowseForDoc(bSave, wsFileNameInit);
+ if(wsFilePath.IsEmpty())
+ return FALSE;
+
+ JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
+
+ JS_PutObjectString(isolate,pRetObj, L"cPath", SysPathToPDFPath(wsFilePath));
+ JS_PutObjectString(isolate,pRetObj, L"cURL", SysPathToPDFPath(wsFilePath));
+
+ if (!cFSInit.IsEmpty())
+ {
+ JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal(cFSInit.GetBuffer(cFSInit.GetLength())));
+ }
+ else
+ {
+ JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal("DOS"));
+ }
+
+ vRet = pRetObj;
+
+ return TRUE;
+}
+
+CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath)
+{
+ CFX_WideString sRet = L"/";
+
+ for (int i=0,sz=sOldPath.GetLength(); i<sz; i++)
+ {
+ wchar_t c = sOldPath.GetAt(i);
+ if (c == L':')
+ {
+ }
+ else
+ {
+ if (c == L'\\')
+ {
+ sRet += L"/";
+ }
+ else
+ {
+ sRet += c;
+ }
+ }
+ }
+
+ return sRet;
+}
+
+CFX_WideString app::PDFPathToSysPath(const CFX_WideString& sOldPath)
+{
+ //strLPath = "D:\temporay.fdf";
+ CFX_WideString strOPath = sOldPath;
+ strOPath.TrimLeft();
+ strOPath.TrimRight();
+
+ if (strOPath.GetAt(0) == L'/' && strOPath.GetAt(2) == L'/')
+ {
+ wchar_t c_Drive = strOPath.GetAt(1);
+ if ((c_Drive >= L'a' && c_Drive <= L'z' )||( c_Drive >= L'A' && c_Drive <= L'Z'))
+ {
+ strOPath.Replace((FX_LPCWSTR)L"/",(FX_LPCWSTR)L"\\");
+ //strOPath.SetAt(0,'');
+ strOPath.Insert(2,':');
+ strOPath.Delete(0);
+ }
+ }
+
+ return strOPath;
+}
+
+CFX_WideString app::RelativePathToSysPath(const CFX_WideString& sOldPath, const CFX_WideString& sFilePath)
+{
+// if (!PathIsRelative(sOldPath)) return sOldPath;
+
+ int nSplit = 0;
+ for (int i=sFilePath.GetLength()-1; i>=0; i--)
+ {
+ if (sFilePath[i] == '\\' || sFilePath[i] == '/')
+ {
+ nSplit = i;
+ break;
+ }
+ }
+
+ return sFilePath.Left(nSplit+1) + sOldPath;
+}
+
+FX_BOOL app::newDoc(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::openDoc(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::response(OBJ_METHOD_PARAMS)
+{
+ CFX_WideString swQuestion = L"";
+ CFX_WideString swLabel = L"";
+#ifndef FOXIT_CHROME_BUILD
+ CFX_WideString swTitle = L"Foxit";
+#else
+ CFX_WideString swTitle = L"PDF";
+#endif
+ CFX_WideString swDefault = L"";
+ CFX_WideString swResponse = L"";
+ bool bPassWord = false;
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ int iLength = params.size();
+ if (iLength > 0 && params[0].GetType() == VT_object)
+ {
+
+ JSObject pObj = (JSObject )params[0];
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion");
+ swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
+ swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");
+ swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cLabel");
+ swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"bPassword");
+ bPassWord = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+ }
+ else
+ {
+ switch(iLength)
+ {
+ case 1:
+ swQuestion = params[0];
+ break;
+ case 2:
+ swQuestion = params[0];
+ swTitle = params[1];
+ break;
+ case 3:
+ swQuestion = params[0];
+ swTitle = params[1];
+ swDefault = params[2];
+ break;
+ case 4:
+ swQuestion = params[0];
+ swTitle = params[1];
+ swDefault = params[2];
+ bPassWord = params[3];
+ break;
+ case 5:
+ swQuestion = params[0];
+ swTitle = params[1];
+ swDefault = params[2];
+ bPassWord = params[3];
+ swLabel = params[4];
+ break;
+ default:
+ break;
+ }
+ }
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+ int nLength = 2048;
+ char* pBuff = new char[nLength];
+ nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength);
+ if(nLength<=0)
+ {
+ vRet.SetNull();
+ return FALSE;
+ }
+ else
+ {
+ nLength = nLength>2046?2046:nLength;
+ pBuff[nLength] = 0;
+ pBuff[nLength+1] = 0;
+ swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength);
+ vRet = swResponse;
+ }
+ delete[] pBuff;
+
+ return TRUE;
+}
+
+FX_BOOL app::media(OBJ_PROP_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::execDialog(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/color.cpp b/fpdfsdk/src/javascript/color.cpp
index de5a53fc5f..3841706743 100644
--- a/fpdfsdk/src/javascript/color.cpp
+++ b/fpdfsdk/src/javascript/color.cpp
@@ -1,253 +1,253 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/color.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-/* -------------------------- color -------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Color)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Color)
- JS_STATIC_PROP_ENTRY(black)
- JS_STATIC_PROP_ENTRY(blue)
- JS_STATIC_PROP_ENTRY(cyan)
- JS_STATIC_PROP_ENTRY(dkGray)
- JS_STATIC_PROP_ENTRY(gray)
- JS_STATIC_PROP_ENTRY(green)
- JS_STATIC_PROP_ENTRY(ltGray)
- JS_STATIC_PROP_ENTRY(magenta)
- JS_STATIC_PROP_ENTRY(red)
- JS_STATIC_PROP_ENTRY(transparent)
- JS_STATIC_PROP_ENTRY(white)
- JS_STATIC_PROP_ENTRY(yellow)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Color)
- JS_STATIC_METHOD_ENTRY(convert, 2)
- JS_STATIC_METHOD_ENTRY(equal, 2)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Color,color)
-
-color::color(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject)
-{
- m_crTransparent = CPWL_Color(COLORTYPE_TRANSPARENT);
- m_crBlack = CPWL_Color(COLORTYPE_GRAY, 0);
- m_crWhite = CPWL_Color(COLORTYPE_GRAY, 1);
- m_crRed = CPWL_Color(COLORTYPE_RGB, 1, 0 ,0);
- m_crGreen = CPWL_Color(COLORTYPE_RGB, 0, 1 ,0);
- m_crBlue = CPWL_Color(COLORTYPE_RGB, 0, 0 ,1);
- m_crCyan = CPWL_Color(COLORTYPE_CMYK, 1, 0 ,0, 0);
- m_crMagenta = CPWL_Color(COLORTYPE_CMYK, 0, 1 ,0, 0);
- m_crYellow = CPWL_Color(COLORTYPE_CMYK, 0, 0 ,1, 0);
- m_crDKGray = CPWL_Color(COLORTYPE_GRAY, 0.25);
- m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5);
- m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75);
-}
-
-color::~color(void)
-{
-}
-
-void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array)
-{
- switch (color.nColorType)
- {
- case COLORTYPE_TRANSPARENT:
- array.SetElement(0, CJS_Value(array.GetIsolate(), "T"));
- break;
- case COLORTYPE_GRAY:
- array.SetElement(0, CJS_Value(array.GetIsolate(),"G"));
- array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
- break;
- case COLORTYPE_RGB:
- array.SetElement(0, CJS_Value(array.GetIsolate(),"RGB"));
- array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
- array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2));
- array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3));
- break;
- case COLORTYPE_CMYK:
- array.SetElement(0, CJS_Value(array.GetIsolate(),"CMYK"));
- array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
- array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2));
- array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3));
- array.SetElement(4, CJS_Value(array.GetIsolate(),color.fColor4));
- break;
- }
-}
-
-void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color)
-{
- int nArrayLen = array.GetLength();
- if (nArrayLen < 1) return;
-
- CJS_Value value(array.GetIsolate());
- CFX_ByteString sSpace;
- array.GetElement(0, value);
- sSpace = value;
-
- double d1 = 0;
- double d2 = 0;
- double d3 = 0;
- double d4 = 0;
-
- if (nArrayLen > 1)
- {
- array.GetElement(1, value);
- d1 = value;
- }
-
- if (nArrayLen > 2)
- {
- array.GetElement(2, value);
- d2 = value;
- }
-
- if (nArrayLen > 3)
- {
- array.GetElement(3, value);
- d3 = value;
- }
-
- if (nArrayLen > 4)
- {
- array.GetElement(4, value);
- d4 = value;
- }
-
- if (sSpace == "T")
- {
- color = CPWL_Color(COLORTYPE_TRANSPARENT);
- }
- else if (sSpace == "G")
- {
- color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
- }
- else if (sSpace == "RGB")
- {
- color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3);
- }
- else if (sSpace == "CMYK")
- {
- color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3, (FX_FLOAT)d4);
- }
-}
-
-#define JS_IMPLEMENT_COLORPROP(prop, var)\
-FX_BOOL color::prop(OBJ_PROP_PARAMS)\
-{\
- CJS_Context* pContext = (CJS_Context*)cc;\
- v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate();\
- if (vp.IsGetting())\
- {\
- CJS_Array array(isolate);\
- ConvertPWLColorToArray(var, array);\
- vp << array;\
- }\
- else\
- {\
- CJS_Array array(isolate);\
- if (!vp.ConvertToArray(array)) return FALSE;\
- ConvertArrayToPWLColor(array, var);\
- }\
- return TRUE;\
-}
-
-JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent)
-JS_IMPLEMENT_COLORPROP(black, m_crBlack)
-JS_IMPLEMENT_COLORPROP(white, m_crWhite)
-JS_IMPLEMENT_COLORPROP(red, m_crRed)
-JS_IMPLEMENT_COLORPROP(green, m_crGreen)
-JS_IMPLEMENT_COLORPROP(blue, m_crBlue)
-JS_IMPLEMENT_COLORPROP(cyan, m_crCyan)
-JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta)
-JS_IMPLEMENT_COLORPROP(yellow, m_crYellow)
-JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray)
-JS_IMPLEMENT_COLORPROP(gray, m_crGray)
-JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray)
-
-FX_BOOL color::convert(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- int iSize = params.size();
- if (iSize < 2) return FALSE;
- CJS_Array aSource(isolate);
- if (!params[0].ConvertToArray(aSource)) return FALSE;
-
- CPWL_Color crSource;
- ConvertArrayToPWLColor(aSource, crSource);
-
- CFX_ByteString sDestSpace = params[1];
-
- int nColorType = COLORTYPE_TRANSPARENT;
-
- if (sDestSpace == "T")
- {
- nColorType = COLORTYPE_TRANSPARENT;
- }
- else if (sDestSpace == "G")
- {
- nColorType = COLORTYPE_GRAY;
- }
- else if (sDestSpace == "RGB")
- {
- nColorType = COLORTYPE_RGB;
- }
- else if (sDestSpace == "CMYK")
- {
- nColorType = COLORTYPE_CMYK;
- }
-
- CJS_Array aDest(isolate);
- CPWL_Color crDest = crSource;
- crDest.ConvertColorType(nColorType);
- ConvertPWLColorToArray(crDest, aDest);
- vRet = aDest;
-
- return TRUE;
-}
-
-FX_BOOL color::equal(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- if (params.size() < 2) return FALSE;
-
- CJS_Array array1(isolate), array2(isolate);
-
- if (!params[0].ConvertToArray(array1)) return FALSE;
- if (!params[1].ConvertToArray(array2)) return FALSE;
-
- CPWL_Color color1;
- CPWL_Color color2;
-
- ConvertArrayToPWLColor(array1, color1);
- ConvertArrayToPWLColor(array2, color2);
-
- color1.ConvertColorType(color2.nColorType);
-
- vRet = color1 == color2;
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/color.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+/* -------------------------- color -------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Color)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Color)
+ JS_STATIC_PROP_ENTRY(black)
+ JS_STATIC_PROP_ENTRY(blue)
+ JS_STATIC_PROP_ENTRY(cyan)
+ JS_STATIC_PROP_ENTRY(dkGray)
+ JS_STATIC_PROP_ENTRY(gray)
+ JS_STATIC_PROP_ENTRY(green)
+ JS_STATIC_PROP_ENTRY(ltGray)
+ JS_STATIC_PROP_ENTRY(magenta)
+ JS_STATIC_PROP_ENTRY(red)
+ JS_STATIC_PROP_ENTRY(transparent)
+ JS_STATIC_PROP_ENTRY(white)
+ JS_STATIC_PROP_ENTRY(yellow)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Color)
+ JS_STATIC_METHOD_ENTRY(convert, 2)
+ JS_STATIC_METHOD_ENTRY(equal, 2)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Color,color)
+
+color::color(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject)
+{
+ m_crTransparent = CPWL_Color(COLORTYPE_TRANSPARENT);
+ m_crBlack = CPWL_Color(COLORTYPE_GRAY, 0);
+ m_crWhite = CPWL_Color(COLORTYPE_GRAY, 1);
+ m_crRed = CPWL_Color(COLORTYPE_RGB, 1, 0 ,0);
+ m_crGreen = CPWL_Color(COLORTYPE_RGB, 0, 1 ,0);
+ m_crBlue = CPWL_Color(COLORTYPE_RGB, 0, 0 ,1);
+ m_crCyan = CPWL_Color(COLORTYPE_CMYK, 1, 0 ,0, 0);
+ m_crMagenta = CPWL_Color(COLORTYPE_CMYK, 0, 1 ,0, 0);
+ m_crYellow = CPWL_Color(COLORTYPE_CMYK, 0, 0 ,1, 0);
+ m_crDKGray = CPWL_Color(COLORTYPE_GRAY, 0.25);
+ m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5);
+ m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75);
+}
+
+color::~color(void)
+{
+}
+
+void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array)
+{
+ switch (color.nColorType)
+ {
+ case COLORTYPE_TRANSPARENT:
+ array.SetElement(0, CJS_Value(array.GetIsolate(), "T"));
+ break;
+ case COLORTYPE_GRAY:
+ array.SetElement(0, CJS_Value(array.GetIsolate(),"G"));
+ array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
+ break;
+ case COLORTYPE_RGB:
+ array.SetElement(0, CJS_Value(array.GetIsolate(),"RGB"));
+ array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
+ array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2));
+ array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3));
+ break;
+ case COLORTYPE_CMYK:
+ array.SetElement(0, CJS_Value(array.GetIsolate(),"CMYK"));
+ array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
+ array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2));
+ array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3));
+ array.SetElement(4, CJS_Value(array.GetIsolate(),color.fColor4));
+ break;
+ }
+}
+
+void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color)
+{
+ int nArrayLen = array.GetLength();
+ if (nArrayLen < 1) return;
+
+ CJS_Value value(array.GetIsolate());
+ CFX_ByteString sSpace;
+ array.GetElement(0, value);
+ sSpace = value;
+
+ double d1 = 0;
+ double d2 = 0;
+ double d3 = 0;
+ double d4 = 0;
+
+ if (nArrayLen > 1)
+ {
+ array.GetElement(1, value);
+ d1 = value;
+ }
+
+ if (nArrayLen > 2)
+ {
+ array.GetElement(2, value);
+ d2 = value;
+ }
+
+ if (nArrayLen > 3)
+ {
+ array.GetElement(3, value);
+ d3 = value;
+ }
+
+ if (nArrayLen > 4)
+ {
+ array.GetElement(4, value);
+ d4 = value;
+ }
+
+ if (sSpace == "T")
+ {
+ color = CPWL_Color(COLORTYPE_TRANSPARENT);
+ }
+ else if (sSpace == "G")
+ {
+ color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
+ }
+ else if (sSpace == "RGB")
+ {
+ color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3);
+ }
+ else if (sSpace == "CMYK")
+ {
+ color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3, (FX_FLOAT)d4);
+ }
+}
+
+#define JS_IMPLEMENT_COLORPROP(prop, var)\
+FX_BOOL color::prop(OBJ_PROP_PARAMS)\
+{\
+ CJS_Context* pContext = (CJS_Context*)cc;\
+ v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate();\
+ if (vp.IsGetting())\
+ {\
+ CJS_Array array(isolate);\
+ ConvertPWLColorToArray(var, array);\
+ vp << array;\
+ }\
+ else\
+ {\
+ CJS_Array array(isolate);\
+ if (!vp.ConvertToArray(array)) return FALSE;\
+ ConvertArrayToPWLColor(array, var);\
+ }\
+ return TRUE;\
+}
+
+JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent)
+JS_IMPLEMENT_COLORPROP(black, m_crBlack)
+JS_IMPLEMENT_COLORPROP(white, m_crWhite)
+JS_IMPLEMENT_COLORPROP(red, m_crRed)
+JS_IMPLEMENT_COLORPROP(green, m_crGreen)
+JS_IMPLEMENT_COLORPROP(blue, m_crBlue)
+JS_IMPLEMENT_COLORPROP(cyan, m_crCyan)
+JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta)
+JS_IMPLEMENT_COLORPROP(yellow, m_crYellow)
+JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray)
+JS_IMPLEMENT_COLORPROP(gray, m_crGray)
+JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray)
+
+FX_BOOL color::convert(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ int iSize = params.size();
+ if (iSize < 2) return FALSE;
+ CJS_Array aSource(isolate);
+ if (!params[0].ConvertToArray(aSource)) return FALSE;
+
+ CPWL_Color crSource;
+ ConvertArrayToPWLColor(aSource, crSource);
+
+ CFX_ByteString sDestSpace = params[1];
+
+ int nColorType = COLORTYPE_TRANSPARENT;
+
+ if (sDestSpace == "T")
+ {
+ nColorType = COLORTYPE_TRANSPARENT;
+ }
+ else if (sDestSpace == "G")
+ {
+ nColorType = COLORTYPE_GRAY;
+ }
+ else if (sDestSpace == "RGB")
+ {
+ nColorType = COLORTYPE_RGB;
+ }
+ else if (sDestSpace == "CMYK")
+ {
+ nColorType = COLORTYPE_CMYK;
+ }
+
+ CJS_Array aDest(isolate);
+ CPWL_Color crDest = crSource;
+ crDest.ConvertColorType(nColorType);
+ ConvertPWLColorToArray(crDest, aDest);
+ vRet = aDest;
+
+ return TRUE;
+}
+
+FX_BOOL color::equal(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ if (params.size() < 2) return FALSE;
+
+ CJS_Array array1(isolate), array2(isolate);
+
+ if (!params[0].ConvertToArray(array1)) return FALSE;
+ if (!params[1].ConvertToArray(array2)) return FALSE;
+
+ CPWL_Color color1;
+ CPWL_Color color2;
+
+ ConvertArrayToPWLColor(array1, color1);
+ ConvertArrayToPWLColor(array2, color2);
+
+ color1.ConvertColorType(color2.nColorType);
+
+ vRet = color1 == color2;
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/console.cpp b/fpdfsdk/src/javascript/console.cpp
index 25e5559a06..350b4e1dcc 100644
--- a/fpdfsdk/src/javascript/console.cpp
+++ b/fpdfsdk/src/javascript/console.cpp
@@ -1,78 +1,78 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/console.h"
-//#include "../../include/javascript/JS_Module.h"
-#include "../../include/javascript/JS_EventHandler.h"
-//#include "../../include/javascript/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-
-/* ------------------------ console ------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Console)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Console)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Console)
- JS_STATIC_METHOD_ENTRY(clear, 0)
- JS_STATIC_METHOD_ENTRY(hide, 0)
- JS_STATIC_METHOD_ENTRY(println, 1)
- JS_STATIC_METHOD_ENTRY(show, 0)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Console,console)
-
-#define MAXCONSOLECONTENTS 10000
-
-console::console(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject)
-{
-}
-
-console::~console()
-{
-}
-
-FX_BOOL console::clear(OBJ_METHOD_PARAMS)
-{
-
-
-
- return TRUE;
-}
-
-FX_BOOL console::hide(OBJ_METHOD_PARAMS)
-{
-
-
-
-
- return TRUE;
-}
-
-FX_BOOL console::println(OBJ_METHOD_PARAMS)
-{
- if (params.size() < 1)
- {
- return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL console::show(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/console.h"
+//#include "../../include/javascript/JS_Module.h"
+#include "../../include/javascript/JS_EventHandler.h"
+//#include "../../include/javascript/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+
+/* ------------------------ console ------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Console)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Console)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Console)
+ JS_STATIC_METHOD_ENTRY(clear, 0)
+ JS_STATIC_METHOD_ENTRY(hide, 0)
+ JS_STATIC_METHOD_ENTRY(println, 1)
+ JS_STATIC_METHOD_ENTRY(show, 0)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Console,console)
+
+#define MAXCONSOLECONTENTS 10000
+
+console::console(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject)
+{
+}
+
+console::~console()
+{
+}
+
+FX_BOOL console::clear(OBJ_METHOD_PARAMS)
+{
+
+
+
+ return TRUE;
+}
+
+FX_BOOL console::hide(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+ return TRUE;
+}
+
+FX_BOOL console::println(OBJ_METHOD_PARAMS)
+{
+ if (params.size() < 1)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL console::show(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+
+
diff --git a/fpdfsdk/src/javascript/event.cpp b/fpdfsdk/src/javascript/event.cpp
index 9168a2e0cf..5188765a04 100644
--- a/fpdfsdk/src/javascript/event.cpp
+++ b/fpdfsdk/src/javascript/event.cpp
@@ -1,379 +1,379 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/JS_EventHandler.h"
-//#include "../include/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/event.h"
-#include "../../include/javascript/Field.h"
-
-/* -------------------------- event -------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Event)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Event)
- JS_STATIC_PROP_ENTRY(change)
- JS_STATIC_PROP_ENTRY(changeEx)
- JS_STATIC_PROP_ENTRY(commitKey)
- JS_STATIC_PROP_ENTRY(fieldFull)
- JS_STATIC_PROP_ENTRY(keyDown)
- JS_STATIC_PROP_ENTRY(modifier)
- JS_STATIC_PROP_ENTRY(name)
- JS_STATIC_PROP_ENTRY(rc)
- JS_STATIC_PROP_ENTRY(richChange)
- JS_STATIC_PROP_ENTRY(richChangeEx)
- JS_STATIC_PROP_ENTRY(richValue)
- JS_STATIC_PROP_ENTRY(selEnd)
- JS_STATIC_PROP_ENTRY(selStart)
- JS_STATIC_PROP_ENTRY(shift)
- JS_STATIC_PROP_ENTRY(source)
- JS_STATIC_PROP_ENTRY(target)
- JS_STATIC_PROP_ENTRY(targetName)
- JS_STATIC_PROP_ENTRY(type)
- JS_STATIC_PROP_ENTRY(value)
- JS_STATIC_PROP_ENTRY(willCommit)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Event)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Event,event)
-
-event::event(CJS_Object * pJsObject) : CJS_EmbedObj(pJsObject)
-{
-}
-
-event::~event(void)
-{
-}
-
-FX_BOOL event::change(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- CFX_WideString &wChange = pEvent->Change();
- if (vp.IsSetting())
- {
- if (vp.GetType() == VT_string)
- vp >> wChange;
- }
- else
- {
- vp << wChange;
- }
- return TRUE;
-}
-
-FX_BOOL event::changeEx(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->ChangeEx();
- return TRUE;
-}
-
-FX_BOOL event::commitKey(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->CommitKey();
- return TRUE;
-}
-
-FX_BOOL event::fieldFull(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (!vp.IsGetting() && wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
- return FALSE;
-
- if (pEvent->FieldFull())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
-FX_BOOL event::keyDown(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (pEvent->KeyDown())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
-FX_BOOL event::modifier(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (pEvent->Modifier())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
-FX_BOOL event::name(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->Name();
- return TRUE;
-}
-
-FX_BOOL event::rc(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- FX_BOOL &bRc = pEvent->Rc();
- if (vp.IsSetting())
- {
- vp>>bRc;
- }
- else
- {
- vp<<bRc;
- }
- return TRUE;
-}
-
-FX_BOOL event::richChange(OBJ_PROP_PARAMS)
-{
- return TRUE;
- if (vp.IsSetting())
- {
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-FX_BOOL event::richChangeEx(OBJ_PROP_PARAMS)
-{
- return TRUE;
- if (vp.IsSetting())
- {
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-
-FX_BOOL event::richValue(OBJ_PROP_PARAMS)
-{
- return TRUE;
- if (vp.IsSetting())
- {
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-FX_BOOL event::selEnd(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
- {
- return TRUE;
- }
-
- int &iSelEnd = pEvent->SelEnd();
- if (vp.IsSetting())
- {
- vp >> iSelEnd;
- }
- else
- {
- vp << iSelEnd;
- }
- return TRUE;
-}
-
-FX_BOOL event::selStart(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
- {
- return TRUE;
- }
- int &iSelStart = pEvent->SelStart();
- if (vp.IsSetting())
- {
- vp >> iSelStart;
- }
- else
- {
- vp << iSelStart;
- }
- return TRUE;
-}
-
-FX_BOOL event::shift(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (pEvent->Shift())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
-FX_BOOL event::source(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->Source()->GetJSObject();
- return TRUE;
-}
-
-FX_BOOL event::target(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp<<pEvent->Target_Field()->GetJSObject();
- return TRUE;
-}
-
-FX_BOOL event::targetName(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->TargetName();
- return TRUE;
-}
-
-FX_BOOL event::type(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->Type();
- return TRUE;
-}
-
-FX_BOOL event::value(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (wcscmp((const wchar_t*)pEvent->Type(),L"Field") != 0)
- return FALSE;
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString & val = pEvent->Value();
- if (vp.IsSetting())
- {
- val = vp;
- }
- else
- {
- vp << val;
- }
- return TRUE;
-}
-
-FX_BOOL event::willCommit(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (pEvent->WillCommit())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/JS_EventHandler.h"
+//#include "../include/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/event.h"
+#include "../../include/javascript/Field.h"
+
+/* -------------------------- event -------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Event)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Event)
+ JS_STATIC_PROP_ENTRY(change)
+ JS_STATIC_PROP_ENTRY(changeEx)
+ JS_STATIC_PROP_ENTRY(commitKey)
+ JS_STATIC_PROP_ENTRY(fieldFull)
+ JS_STATIC_PROP_ENTRY(keyDown)
+ JS_STATIC_PROP_ENTRY(modifier)
+ JS_STATIC_PROP_ENTRY(name)
+ JS_STATIC_PROP_ENTRY(rc)
+ JS_STATIC_PROP_ENTRY(richChange)
+ JS_STATIC_PROP_ENTRY(richChangeEx)
+ JS_STATIC_PROP_ENTRY(richValue)
+ JS_STATIC_PROP_ENTRY(selEnd)
+ JS_STATIC_PROP_ENTRY(selStart)
+ JS_STATIC_PROP_ENTRY(shift)
+ JS_STATIC_PROP_ENTRY(source)
+ JS_STATIC_PROP_ENTRY(target)
+ JS_STATIC_PROP_ENTRY(targetName)
+ JS_STATIC_PROP_ENTRY(type)
+ JS_STATIC_PROP_ENTRY(value)
+ JS_STATIC_PROP_ENTRY(willCommit)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Event)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Event,event)
+
+event::event(CJS_Object * pJsObject) : CJS_EmbedObj(pJsObject)
+{
+}
+
+event::~event(void)
+{
+}
+
+FX_BOOL event::change(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ CFX_WideString &wChange = pEvent->Change();
+ if (vp.IsSetting())
+ {
+ if (vp.GetType() == VT_string)
+ vp >> wChange;
+ }
+ else
+ {
+ vp << wChange;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::changeEx(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->ChangeEx();
+ return TRUE;
+}
+
+FX_BOOL event::commitKey(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->CommitKey();
+ return TRUE;
+}
+
+FX_BOOL event::fieldFull(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (!vp.IsGetting() && wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
+ return FALSE;
+
+ if (pEvent->FieldFull())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
+FX_BOOL event::keyDown(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (pEvent->KeyDown())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
+FX_BOOL event::modifier(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (pEvent->Modifier())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
+FX_BOOL event::name(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->Name();
+ return TRUE;
+}
+
+FX_BOOL event::rc(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ FX_BOOL &bRc = pEvent->Rc();
+ if (vp.IsSetting())
+ {
+ vp>>bRc;
+ }
+ else
+ {
+ vp<<bRc;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::richChange(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+ if (vp.IsSetting())
+ {
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::richChangeEx(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+ if (vp.IsSetting())
+ {
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+
+FX_BOOL event::richValue(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+ if (vp.IsSetting())
+ {
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::selEnd(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
+ {
+ return TRUE;
+ }
+
+ int &iSelEnd = pEvent->SelEnd();
+ if (vp.IsSetting())
+ {
+ vp >> iSelEnd;
+ }
+ else
+ {
+ vp << iSelEnd;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::selStart(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
+ {
+ return TRUE;
+ }
+ int &iSelStart = pEvent->SelStart();
+ if (vp.IsSetting())
+ {
+ vp >> iSelStart;
+ }
+ else
+ {
+ vp << iSelStart;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::shift(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (pEvent->Shift())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
+FX_BOOL event::source(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->Source()->GetJSObject();
+ return TRUE;
+}
+
+FX_BOOL event::target(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp<<pEvent->Target_Field()->GetJSObject();
+ return TRUE;
+}
+
+FX_BOOL event::targetName(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->TargetName();
+ return TRUE;
+}
+
+FX_BOOL event::type(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->Type();
+ return TRUE;
+}
+
+FX_BOOL event::value(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (wcscmp((const wchar_t*)pEvent->Type(),L"Field") != 0)
+ return FALSE;
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString & val = pEvent->Value();
+ if (vp.IsSetting())
+ {
+ val = vp;
+ }
+ else
+ {
+ vp << val;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::willCommit(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (pEvent->WillCommit())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index 984ba55cb4..295a8d49af 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -1,550 +1,550 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/JS_GlobalData.h"
-#include "../../include/javascript/global.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Context.h"
-
-/* ---------------------------- global ---------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Global)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Global)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Global)
- JS_STATIC_METHOD_ENTRY(setPersistent, 2)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, global_alternate, global);
-
-FX_BOOL CJS_Global::InitInstance(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- global_alternate* pGlobal = (global_alternate*)GetEmbedObject();
- ASSERT(pGlobal != NULL);
-
- pGlobal->Initial(pContext->GetReaderApp());
-
- return TRUE;
-};
-
-global_alternate::global_alternate(CJS_Object* pJSObject)
- : CJS_EmbedObj(pJSObject),
- m_pApp(NULL)
-{
-}
-
-global_alternate::~global_alternate(void)
-{
- ASSERT(m_pApp != NULL);
-
-// CommitGlobalPersisitentVariables();
- DestroyGlobalPersisitentVariables();
-
- CJS_RuntimeFactory* pFactory = m_pApp->m_pJSRuntimeFactory;
- ASSERT(pFactory);
-
- pFactory->ReleaseGlobalData();
-}
-
-void global_alternate::Initial(CPDFDoc_Environment* pApp)
-{
- m_pApp = pApp;
-
- CJS_RuntimeFactory* pFactory = pApp->m_pJSRuntimeFactory;
- ASSERT(pFactory);
- m_pGlobalData = pFactory->NewGlobalData(pApp);
- UpdateGlobalPersistentVariables();
-}
-
-FX_BOOL global_alternate::QueryProperty(FX_LPCWSTR propname)
-{
- return CFX_WideString(propname) != L"setPersistent";
-}
-
-FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc, FX_LPCWSTR propname, JS_ErrorString& sError)
-{
- js_global_data* pData = NULL;
- CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
-
- if (m_mapGlobal.Lookup(sPropName, (FX_LPVOID&)pData))
- {
- pData->bDeleted = TRUE;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc, FX_LPCWSTR propname, CJS_PropValue& vp, JS_ErrorString& 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::Handle<v8::Object>(), FALSE);
- }
- case VT_boolean:
- {
- bool bData;
- vp >> bData;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)vp, "", v8::Handle<v8::Object>(), FALSE);
- }
- case VT_string:
- {
- CFX_ByteString sData;
- vp >> sData;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, false, sData, v8::Handle<v8::Object>(), FALSE);
- }
- case VT_object:
- {
- JSObject pData = (JSObject)vp;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "", pData, FALSE);
-// else
-// {
-// if (vp.IsArrayObject())
-// {
-// CJS_Array array;
-// vp.ConvertToArray(array);
-// return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "",
-// (Dobject*)(Darray*)array, FALSE);
-// }
-// else
-// return FALSE;
-// }
- }
- case VT_null:
- {
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Handle<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, (FX_LPVOID&)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::Handle<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(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 2)
- {
- //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CFX_ByteString sName = params[0];
-
- js_global_data* pData = NULL;
- if (m_mapGlobal.Lookup(sName, (FX_LPVOID&)pData))
- {
- if (pData && !pData->bDeleted)
- {
- pData->bPersistent = (bool)params[1];
- return TRUE;
- }
- }
-
- //sError = JSGetStringFromID(IDS_JSPARAM_INCORRECT);
- 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:
- this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, pData->data.dData, false, "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectNumber(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode(), pData->data.dData);
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)(pData->data.bData == 1), "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectBoolean(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode(), (bool)(pData->data.bData == 1));
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, false, pData->data.sData, v8::Handle<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectString(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode(),
- pData->data.sData.UTF8Decode());
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
- v8::Handle<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
-
- PutObjectProperty(pObj, &pData->data);
-
- this->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(), (JSObject)pObj);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectNull(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode());
- 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, (FX_LPVOID&)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::Handle<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::Handle<v8::Object> pObj, CJS_GlobalVariableArray& array)
-{
- v8::Handle<v8::Array> pKeyList = JS_GetObjectElementNames(pObj);
- int nObjElements = pKeyList->Length();
-
- v8::Local<v8::Context> context = pObj->CreationContext();
- v8::Isolate* isolate = context->GetIsolate();
-
- for (int i=0; i<nObjElements; i++)
- {
-
- CFX_WideString ws = JS_ToString(JS_GetArrayElemnet(pKeyList, i));
- CFX_ByteString sKey = ws.UTF8Encode();
-
- v8::Handle<v8::Value> v = JS_GetObjectElement(isolate, pObj, (const wchar_t*)(FX_LPCWSTR)ws);
- 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(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(v);
- array.Add(pObjElement);
- }
- break;
- case VT_string:
- {
- CFX_ByteString sValue = CJS_Value(isolate, v, VT_string);
- 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(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::Handle<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(), pObjData->dData);
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- JS_PutObjectBoolean(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), (bool)(pObjData->bData == 1));
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- JS_PutObjectString(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), pObjData->sData.UTF8Decode());
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
- v8::Handle<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
- PutObjectProperty(pNewObj, pObjData);
- JS_PutObjectObject(NULL, (JSObject)pObj, pObjData->sKey.UTF8Decode(), (JSObject)pNewObj);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- JS_PutObjectNull(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode());
- 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, (FX_LPVOID&)pData);
- delete pData;
- }
-
- m_mapGlobal.RemoveAll();
-}
-
-
-FX_BOOL global_alternate::SetGlobalVariables(FX_LPCSTR propname, int nType,
- 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, (FX_LPVOID&)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, (FX_LPVOID)pNewData);
-
- return TRUE;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/JS_GlobalData.h"
+#include "../../include/javascript/global.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Context.h"
+
+/* ---------------------------- global ---------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Global)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Global)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Global)
+ JS_STATIC_METHOD_ENTRY(setPersistent, 2)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, global_alternate, global);
+
+FX_BOOL CJS_Global::InitInstance(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ global_alternate* pGlobal = (global_alternate*)GetEmbedObject();
+ ASSERT(pGlobal != NULL);
+
+ pGlobal->Initial(pContext->GetReaderApp());
+
+ return TRUE;
+};
+
+global_alternate::global_alternate(CJS_Object* pJSObject)
+ : CJS_EmbedObj(pJSObject),
+ m_pApp(NULL)
+{
+}
+
+global_alternate::~global_alternate(void)
+{
+ ASSERT(m_pApp != NULL);
+
+// CommitGlobalPersisitentVariables();
+ DestroyGlobalPersisitentVariables();
+
+ CJS_RuntimeFactory* pFactory = m_pApp->m_pJSRuntimeFactory;
+ ASSERT(pFactory);
+
+ pFactory->ReleaseGlobalData();
+}
+
+void global_alternate::Initial(CPDFDoc_Environment* pApp)
+{
+ m_pApp = pApp;
+
+ CJS_RuntimeFactory* pFactory = pApp->m_pJSRuntimeFactory;
+ ASSERT(pFactory);
+ m_pGlobalData = pFactory->NewGlobalData(pApp);
+ UpdateGlobalPersistentVariables();
+}
+
+FX_BOOL global_alternate::QueryProperty(FX_LPCWSTR propname)
+{
+ return CFX_WideString(propname) != L"setPersistent";
+}
+
+FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc, FX_LPCWSTR propname, JS_ErrorString& sError)
+{
+ js_global_data* pData = NULL;
+ CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
+
+ if (m_mapGlobal.Lookup(sPropName, (FX_LPVOID&)pData))
+ {
+ pData->bDeleted = TRUE;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc, FX_LPCWSTR propname, CJS_PropValue& vp, JS_ErrorString& 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::Handle<v8::Object>(), FALSE);
+ }
+ case VT_boolean:
+ {
+ bool bData;
+ vp >> bData;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)vp, "", v8::Handle<v8::Object>(), FALSE);
+ }
+ case VT_string:
+ {
+ CFX_ByteString sData;
+ vp >> sData;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, false, sData, v8::Handle<v8::Object>(), FALSE);
+ }
+ case VT_object:
+ {
+ JSObject pData = (JSObject)vp;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "", pData, FALSE);
+// else
+// {
+// if (vp.IsArrayObject())
+// {
+// CJS_Array array;
+// vp.ConvertToArray(array);
+// return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "",
+// (Dobject*)(Darray*)array, FALSE);
+// }
+// else
+// return FALSE;
+// }
+ }
+ case VT_null:
+ {
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Handle<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, (FX_LPVOID&)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::Handle<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(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 2)
+ {
+ //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CFX_ByteString sName = params[0];
+
+ js_global_data* pData = NULL;
+ if (m_mapGlobal.Lookup(sName, (FX_LPVOID&)pData))
+ {
+ if (pData && !pData->bDeleted)
+ {
+ pData->bPersistent = (bool)params[1];
+ return TRUE;
+ }
+ }
+
+ //sError = JSGetStringFromID(IDS_JSPARAM_INCORRECT);
+ 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:
+ this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, pData->data.dData, false, "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectNumber(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode(), pData->data.dData);
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)(pData->data.bData == 1), "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectBoolean(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode(), (bool)(pData->data.bData == 1));
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, false, pData->data.sData, v8::Handle<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectString(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode(),
+ pData->data.sData.UTF8Decode());
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
+ v8::Handle<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
+
+ PutObjectProperty(pObj, &pData->data);
+
+ this->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(), (JSObject)pObj);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectNull(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode());
+ 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, (FX_LPVOID&)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::Handle<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::Handle<v8::Object> pObj, CJS_GlobalVariableArray& array)
+{
+ v8::Handle<v8::Array> pKeyList = JS_GetObjectElementNames(pObj);
+ int nObjElements = pKeyList->Length();
+
+ v8::Local<v8::Context> context = pObj->CreationContext();
+ v8::Isolate* isolate = context->GetIsolate();
+
+ for (int i=0; i<nObjElements; i++)
+ {
+
+ CFX_WideString ws = JS_ToString(JS_GetArrayElemnet(pKeyList, i));
+ CFX_ByteString sKey = ws.UTF8Encode();
+
+ v8::Handle<v8::Value> v = JS_GetObjectElement(isolate, pObj, (const wchar_t*)(FX_LPCWSTR)ws);
+ 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(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(v);
+ array.Add(pObjElement);
+ }
+ break;
+ case VT_string:
+ {
+ CFX_ByteString sValue = CJS_Value(isolate, v, VT_string);
+ 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(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::Handle<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(), pObjData->dData);
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ JS_PutObjectBoolean(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), (bool)(pObjData->bData == 1));
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ JS_PutObjectString(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), pObjData->sData.UTF8Decode());
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
+ v8::Handle<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
+ PutObjectProperty(pNewObj, pObjData);
+ JS_PutObjectObject(NULL, (JSObject)pObj, pObjData->sKey.UTF8Decode(), (JSObject)pNewObj);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ JS_PutObjectNull(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode());
+ 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, (FX_LPVOID&)pData);
+ delete pData;
+ }
+
+ m_mapGlobal.RemoveAll();
+}
+
+
+FX_BOOL global_alternate::SetGlobalVariables(FX_LPCSTR propname, int nType,
+ 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, (FX_LPVOID&)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, (FX_LPVOID)pNewData);
+
+ return TRUE;
+}
diff --git a/fpdfsdk/src/javascript/report.cpp b/fpdfsdk/src/javascript/report.cpp
index 5063c68e4c..9cb9da5051 100644
--- a/fpdfsdk/src/javascript/report.cpp
+++ b/fpdfsdk/src/javascript/report.cpp
@@ -1,50 +1,50 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/report.h"
-
-/* ---------------------- report ---------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Report)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Report)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Report)
- JS_STATIC_METHOD_ENTRY(save, 1)
- JS_STATIC_METHOD_ENTRY(writeText,1)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Report, Report)
-
-Report::Report(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject)
-{
-
-}
-
-Report::~Report()
-{
-
-}
-
-FX_BOOL Report::writeText(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- return TRUE;
-}
-
-FX_BOOL Report::save(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/report.h"
+
+/* ---------------------- report ---------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Report)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Report)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Report)
+ JS_STATIC_METHOD_ENTRY(save, 1)
+ JS_STATIC_METHOD_ENTRY(writeText,1)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Report, Report)
+
+Report::Report(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject)
+{
+
+}
+
+Report::~Report()
+{
+
+}
+
+FX_BOOL Report::writeText(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ return TRUE;
+}
+
+FX_BOOL Report::save(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp
index b7303a7578..bafdb22da9 100644
--- a/fpdfsdk/src/javascript/util.cpp
+++ b/fpdfsdk/src/javascript/util.cpp
@@ -1,649 +1,649 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/util.h"
-#include "../../include/javascript/PublicMethods.h"
-#include "../../include/javascript/resource.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Runtime.h"
-
-#if _FX_OS_ == _FX_ANDROID_
-#include <ctype.h>
-#endif
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-BEGIN_JS_STATIC_CONST(CJS_Util)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Util)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Util)
- JS_STATIC_METHOD_ENTRY(printd, 3)
- JS_STATIC_METHOD_ENTRY(printf, 20)
- JS_STATIC_METHOD_ENTRY(printx, 2)
- JS_STATIC_METHOD_ENTRY(scand, 2)
- JS_STATIC_METHOD_ENTRY(byteToChar, 1)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Util,util)
-
-util::util(CJS_Object *pJSObject) : CJS_EmbedObj(pJSObject)
-{
-}
-
-util::~util(void)
-{
-}
-
-
-struct stru_TbConvert
-{
- FX_LPCWSTR lpszJSMark;
- FX_LPCWSTR lpszCppMark;
-};
-
-const stru_TbConvert fcTable[] = {
- (FX_LPCWSTR)L"mmmm", (FX_LPCWSTR)L"%B",
- (FX_LPCWSTR)L"mmm", (FX_LPCWSTR)L"%b",
- (FX_LPCWSTR)L"mm", (FX_LPCWSTR)L"%m",
- //"m"
- (FX_LPCWSTR)L"dddd", (FX_LPCWSTR)L"%A",
- (FX_LPCWSTR)L"ddd", (FX_LPCWSTR)L"%a",
- (FX_LPCWSTR)L"dd", (FX_LPCWSTR)L"%d",
- //"d", "%w",
- (FX_LPCWSTR)L"yyyy", (FX_LPCWSTR)L"%Y",
- (FX_LPCWSTR)L"yy", (FX_LPCWSTR)L"%y",
- (FX_LPCWSTR)L"HH", (FX_LPCWSTR)L"%H",
- //"H"
- (FX_LPCWSTR)L"hh", (FX_LPCWSTR)L"%I",
- //"h"
- (FX_LPCWSTR)L"MM", (FX_LPCWSTR)L"%M",
- //"M"
- (FX_LPCWSTR)L"ss", (FX_LPCWSTR)L"%S",
- //"s
- (FX_LPCWSTR)L"TT", (FX_LPCWSTR)L"%p",
- //"t"
-#if defined(_WIN32)
- (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%p",
- (FX_LPCWSTR)L"h", (FX_LPCWSTR)L"%#I",
-#else
- (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%P",
- (FX_LPCWSTR)L"h", (FX_LPCWSTR)L"%l",
-#endif
-};
-
-#define UTIL_INT 0
-#define UTIL_DOUBLE 1
-#define UTIL_STRING 2
-
-int util::ParstDataType(std::wstring* sFormat)
-{
- 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(OBJ_METHOD_PARAMS)
-{
- int iSize = params.size();
- if (iSize < 1)
- return FALSE;
- std::wstring c_ConvChar((const wchar_t*)(FX_LPCWSTR)params[0].operator CFX_WideString());
- 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((FX_LPCWSTR)c_strFormat.c_str(),(int)params[iIndex]);
- break;
- case UTIL_DOUBLE:
- strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(double)params[iIndex]);
- break;
- case UTIL_STRING:
- strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(FX_LPCWSTR)params[iIndex].operator CFX_WideString());
- break;
- default:
- strSegment.Format((FX_LPCWSTR)L"%S", (FX_LPCWSTR)c_strFormat.c_str());
- break;
- }
- c_strResult += (wchar_t*)strSegment.GetBuffer(strSegment.GetLength()+1);
- }
-
- c_strResult.erase(c_strResult.begin());
- vRet = (FX_LPCWSTR)c_strResult.c_str();
- return TRUE;
-}
-
-FX_BOOL util::printd(OBJ_METHOD_PARAMS)
-{
- 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;
-
- CFX_WideString swResult;
-
- switch (nFormat)
- {
- case 0:
- swResult.Format((FX_LPCWSTR)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((FX_LPCWSTR)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((FX_LPCWSTR)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;
- return TRUE;
- }
- else if (p1.GetType() == VT_string)
- {
- std::basic_string<wchar_t> cFormat = (wchar_t*)(FX_LPCWSTR)p1.operator CFX_WideString();
-
- bool bXFAPicture = false;
- if (iSize > 2)
- {
- //CJS_Value value;
- bXFAPicture = params[2];
- }
-
- 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((CFX_WideString)fcTable[iIndex].lpszJSMark, iStart)) != -1)
- {
- cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)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 = {0};
- 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
- {
- FX_LPCWSTR lpszJSMark;
- int iValue;
- };
-
- stru_TbConvertAd cTableAd[] ={
- (FX_LPCWSTR)L"m", iMonth+1,
- (FX_LPCWSTR)L"d", iDay,
- (FX_LPCWSTR)L"H", iHour,
- (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
- (FX_LPCWSTR)L"M", iMin,
- (FX_LPCWSTR)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((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue);
- memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),
- (sValue.GetLength()+1)*sizeof(wchar_t));
-
- //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
- //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
- int iStart = 0;
- int iEnd;
- while((iEnd = cFormat.find((CFX_WideString)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((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
-// CString strFormat = cppTm.Format(cFormat.c_str());
- wchar_t buf[64] = {0};
- strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
- cFormat = buf;
- vRet = (FX_LPCWSTR)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;
-
- 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((CFX_WideString)fcTable[iIndex].lpszJSMark,iStart)) != -1)
- {
- cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)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 = {0};
- 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
- {
- FX_LPCWSTR lpszJSMark;
- int iValue;
- };
-
- stru_TbConvertAd cTableAd[] ={
- (FX_LPCWSTR)L"m", iMonth+1,
- (FX_LPCWSTR)L"d", iDay,
- (FX_LPCWSTR)L"H", iHour,
- (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
- (FX_LPCWSTR)L"M", iMin,
- (FX_LPCWSTR)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((FX_LPCWSTR)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((CFX_WideString)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((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
-// CString strFormat = cppTm.Format(cFormat.c_str());
- wchar_t buf[64] = {0};
- strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
- cFormat = buf;
- cPurpose = cFormat;
-}
-
-FX_BOOL util::printx(OBJ_METHOD_PARAMS)
-{
- int iSize = params.size();
- if (iSize<2)
- return FALSE;
- CFX_WideString sFormat = params[0].operator CFX_WideString();
- CFX_WideString sSource = params[1].operator CFX_WideString();
- std::string cFormat = (FX_LPCSTR)CFX_ByteString::FromUnicode(sFormat);
- std::string cSource = (FX_LPCSTR)CFX_ByteString::FromUnicode(sSource);
- 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;
- }
- }
-}
-
-FX_BOOL util::scand(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- int iSize = params.size();
- if (iSize < 2)
- return FALSE;
- CFX_WideString sFormat = params[0].operator CFX_WideString();
- CFX_WideString sDate = params[1].operator CFX_WideString();
-
- 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;
-}
-
-FX_INT64 FX_atoi64(const char *nptr)
-{
- int c; /* current char */
- FX_INT64 total; /* current total */
- int sign; /* if '-', then negative, otherwise positive */
-
- /* skip whitespace */
- while ( isspace((int)(unsigned char)*nptr) )
- ++nptr;
-
- c = (int)(unsigned char)*nptr++;
- sign = c; /* save sign indication */
- if (c == '-' || c == '+')
- c = (int)(unsigned char)*nptr++; /* skip sign */
-
- total = 0;
-
- while (isdigit(c)) {
- total = 10 * total + (c - '0'); /* accumulate digit */
- c = (int)(unsigned char)*nptr++; /* get next char */
- }
-
- if (sign == '-')
- return -total;
- else
- return total; /* return result, negated if necessary */
-}
-
-FX_BOOL util::byteToChar(OBJ_METHOD_PARAMS)
-{
- int iSize = params.size();
- if (iSize == 0)
- return FALSE;
- int nByte = (int)params[0];
- unsigned char cByte = (unsigned char)nByte;
- CFX_WideString csValue;
- csValue.Format((FX_LPCWSTR)L"%c", cByte);
- vRet = csValue;
- return TRUE;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/util.h"
+#include "../../include/javascript/PublicMethods.h"
+#include "../../include/javascript/resource.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Runtime.h"
+
+#if _FX_OS_ == _FX_ANDROID_
+#include <ctype.h>
+#endif
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+
+BEGIN_JS_STATIC_CONST(CJS_Util)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Util)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Util)
+ JS_STATIC_METHOD_ENTRY(printd, 3)
+ JS_STATIC_METHOD_ENTRY(printf, 20)
+ JS_STATIC_METHOD_ENTRY(printx, 2)
+ JS_STATIC_METHOD_ENTRY(scand, 2)
+ JS_STATIC_METHOD_ENTRY(byteToChar, 1)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Util,util)
+
+util::util(CJS_Object *pJSObject) : CJS_EmbedObj(pJSObject)
+{
+}
+
+util::~util(void)
+{
+}
+
+
+struct stru_TbConvert
+{
+ FX_LPCWSTR lpszJSMark;
+ FX_LPCWSTR lpszCppMark;
+};
+
+const stru_TbConvert fcTable[] = {
+ (FX_LPCWSTR)L"mmmm", (FX_LPCWSTR)L"%B",
+ (FX_LPCWSTR)L"mmm", (FX_LPCWSTR)L"%b",
+ (FX_LPCWSTR)L"mm", (FX_LPCWSTR)L"%m",
+ //"m"
+ (FX_LPCWSTR)L"dddd", (FX_LPCWSTR)L"%A",
+ (FX_LPCWSTR)L"ddd", (FX_LPCWSTR)L"%a",
+ (FX_LPCWSTR)L"dd", (FX_LPCWSTR)L"%d",
+ //"d", "%w",
+ (FX_LPCWSTR)L"yyyy", (FX_LPCWSTR)L"%Y",
+ (FX_LPCWSTR)L"yy", (FX_LPCWSTR)L"%y",
+ (FX_LPCWSTR)L"HH", (FX_LPCWSTR)L"%H",
+ //"H"
+ (FX_LPCWSTR)L"hh", (FX_LPCWSTR)L"%I",
+ //"h"
+ (FX_LPCWSTR)L"MM", (FX_LPCWSTR)L"%M",
+ //"M"
+ (FX_LPCWSTR)L"ss", (FX_LPCWSTR)L"%S",
+ //"s
+ (FX_LPCWSTR)L"TT", (FX_LPCWSTR)L"%p",
+ //"t"
+#if defined(_WIN32)
+ (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%p",
+ (FX_LPCWSTR)L"h", (FX_LPCWSTR)L"%#I",
+#else
+ (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%P",
+ (FX_LPCWSTR)L"h", (FX_LPCWSTR)L"%l",
+#endif
+};
+
+#define UTIL_INT 0
+#define UTIL_DOUBLE 1
+#define UTIL_STRING 2
+
+int util::ParstDataType(std::wstring* sFormat)
+{
+ 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(OBJ_METHOD_PARAMS)
+{
+ int iSize = params.size();
+ if (iSize < 1)
+ return FALSE;
+ std::wstring c_ConvChar((const wchar_t*)(FX_LPCWSTR)params[0].operator CFX_WideString());
+ 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((FX_LPCWSTR)c_strFormat.c_str(),(int)params[iIndex]);
+ break;
+ case UTIL_DOUBLE:
+ strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(double)params[iIndex]);
+ break;
+ case UTIL_STRING:
+ strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(FX_LPCWSTR)params[iIndex].operator CFX_WideString());
+ break;
+ default:
+ strSegment.Format((FX_LPCWSTR)L"%S", (FX_LPCWSTR)c_strFormat.c_str());
+ break;
+ }
+ c_strResult += (wchar_t*)strSegment.GetBuffer(strSegment.GetLength()+1);
+ }
+
+ c_strResult.erase(c_strResult.begin());
+ vRet = (FX_LPCWSTR)c_strResult.c_str();
+ return TRUE;
+}
+
+FX_BOOL util::printd(OBJ_METHOD_PARAMS)
+{
+ 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;
+
+ CFX_WideString swResult;
+
+ switch (nFormat)
+ {
+ case 0:
+ swResult.Format((FX_LPCWSTR)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((FX_LPCWSTR)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((FX_LPCWSTR)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;
+ return TRUE;
+ }
+ else if (p1.GetType() == VT_string)
+ {
+ std::basic_string<wchar_t> cFormat = (wchar_t*)(FX_LPCWSTR)p1.operator CFX_WideString();
+
+ bool bXFAPicture = false;
+ if (iSize > 2)
+ {
+ //CJS_Value value;
+ bXFAPicture = params[2];
+ }
+
+ 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((CFX_WideString)fcTable[iIndex].lpszJSMark, iStart)) != -1)
+ {
+ cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)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 = {0};
+ 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
+ {
+ FX_LPCWSTR lpszJSMark;
+ int iValue;
+ };
+
+ stru_TbConvertAd cTableAd[] ={
+ (FX_LPCWSTR)L"m", iMonth+1,
+ (FX_LPCWSTR)L"d", iDay,
+ (FX_LPCWSTR)L"H", iHour,
+ (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
+ (FX_LPCWSTR)L"M", iMin,
+ (FX_LPCWSTR)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((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue);
+ memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),
+ (sValue.GetLength()+1)*sizeof(wchar_t));
+
+ //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
+ //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
+ int iStart = 0;
+ int iEnd;
+ while((iEnd = cFormat.find((CFX_WideString)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((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
+// CString strFormat = cppTm.Format(cFormat.c_str());
+ wchar_t buf[64] = {0};
+ strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
+ cFormat = buf;
+ vRet = (FX_LPCWSTR)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;
+
+ 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((CFX_WideString)fcTable[iIndex].lpszJSMark,iStart)) != -1)
+ {
+ cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)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 = {0};
+ 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
+ {
+ FX_LPCWSTR lpszJSMark;
+ int iValue;
+ };
+
+ stru_TbConvertAd cTableAd[] ={
+ (FX_LPCWSTR)L"m", iMonth+1,
+ (FX_LPCWSTR)L"d", iDay,
+ (FX_LPCWSTR)L"H", iHour,
+ (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
+ (FX_LPCWSTR)L"M", iMin,
+ (FX_LPCWSTR)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((FX_LPCWSTR)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((CFX_WideString)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((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
+// CString strFormat = cppTm.Format(cFormat.c_str());
+ wchar_t buf[64] = {0};
+ strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
+ cFormat = buf;
+ cPurpose = cFormat;
+}
+
+FX_BOOL util::printx(OBJ_METHOD_PARAMS)
+{
+ int iSize = params.size();
+ if (iSize<2)
+ return FALSE;
+ CFX_WideString sFormat = params[0].operator CFX_WideString();
+ CFX_WideString sSource = params[1].operator CFX_WideString();
+ std::string cFormat = (FX_LPCSTR)CFX_ByteString::FromUnicode(sFormat);
+ std::string cSource = (FX_LPCSTR)CFX_ByteString::FromUnicode(sSource);
+ 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;
+ }
+ }
+}
+
+FX_BOOL util::scand(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ int iSize = params.size();
+ if (iSize < 2)
+ return FALSE;
+ CFX_WideString sFormat = params[0].operator CFX_WideString();
+ CFX_WideString sDate = params[1].operator CFX_WideString();
+
+ 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;
+}
+
+FX_INT64 FX_atoi64(const char *nptr)
+{
+ int c; /* current char */
+ FX_INT64 total; /* current total */
+ int sign; /* if '-', then negative, otherwise positive */
+
+ /* skip whitespace */
+ while ( isspace((int)(unsigned char)*nptr) )
+ ++nptr;
+
+ c = (int)(unsigned char)*nptr++;
+ sign = c; /* save sign indication */
+ if (c == '-' || c == '+')
+ c = (int)(unsigned char)*nptr++; /* skip sign */
+
+ total = 0;
+
+ while (isdigit(c)) {
+ total = 10 * total + (c - '0'); /* accumulate digit */
+ c = (int)(unsigned char)*nptr++; /* get next char */
+ }
+
+ if (sign == '-')
+ return -total;
+ else
+ return total; /* return result, negated if necessary */
+}
+
+FX_BOOL util::byteToChar(OBJ_METHOD_PARAMS)
+{
+ int iSize = params.size();
+ if (iSize == 0)
+ return FALSE;
+ int nByte = (int)params[0];
+ unsigned char cByte = (unsigned char)nByte;
+ CFX_WideString csValue;
+ csValue.Format((FX_LPCWSTR)L"%c", cByte);
+ vRet = csValue;
+ return TRUE;
+}
diff --git a/fpdfsdk/src/pdfwindow/PWL_Button.cpp b/fpdfsdk/src/pdfwindow/PWL_Button.cpp
index c71e5cc8b4..f95469aa93 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Button.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Button.cpp
@@ -1,53 +1,53 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_Button.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-
-/* ------------------------------- CPWL_Button ---------------------------------- */
-
-CPWL_Button::CPWL_Button() :
- m_bMouseDown(FALSE)
-{
-}
-
-CPWL_Button::~CPWL_Button()
-{
-// PWL_TRACE("~CPWL_Button\n");
-}
-
-CFX_ByteString CPWL_Button::GetClassName() const
-{
- return "CPWL_Button";
-}
-
-void CPWL_Button::OnCreate(PWL_CREATEPARAM & cp)
-{
- cp.eCursorType = FXCT_HAND;
-}
-
-FX_BOOL CPWL_Button::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonDown(point, nFlag);
-
- m_bMouseDown = TRUE;
- SetCapture();
-
- return TRUE;
-}
-
-FX_BOOL CPWL_Button::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonUp(point, nFlag);
-
- ReleaseCapture();
- m_bMouseDown = FALSE;
-
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Button.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+/* ------------------------------- CPWL_Button ---------------------------------- */
+
+CPWL_Button::CPWL_Button() :
+ m_bMouseDown(FALSE)
+{
+}
+
+CPWL_Button::~CPWL_Button()
+{
+// PWL_TRACE("~CPWL_Button\n");
+}
+
+CFX_ByteString CPWL_Button::GetClassName() const
+{
+ return "CPWL_Button";
+}
+
+void CPWL_Button::OnCreate(PWL_CREATEPARAM & cp)
+{
+ cp.eCursorType = FXCT_HAND;
+}
+
+FX_BOOL CPWL_Button::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonDown(point, nFlag);
+
+ m_bMouseDown = TRUE;
+ SetCapture();
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_Button::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonUp(point, nFlag);
+
+ ReleaseCapture();
+ m_bMouseDown = FALSE;
+
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_Caret.cpp b/fpdfsdk/src/pdfwindow/PWL_Caret.cpp
index e54538ea73..cdc7d57a9b 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Caret.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Caret.cpp
@@ -1,197 +1,197 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_Caret.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-
-#define PWL_CARET_FLASHINTERVAL 500
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CPWL_Caret::CPWL_Caret() :
- m_bFlash(FALSE),
- m_ptHead(0,0),
- m_ptFoot(0,0),
- m_fWidth(0.4f),
- m_nDelay(0)
-{
-}
-
-CPWL_Caret::~CPWL_Caret()
-{
-}
-
-CFX_ByteString CPWL_Caret::GetClassName() const
-{
- return "CPWL_Caret";
-}
-
-void CPWL_Caret::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- GetCaretApp(sAppStream,CPDF_Point(0.0f,0.0f));
-}
-
-void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- if (IsVisible() && m_bFlash)
- {
- CPDF_Rect rcRect = GetCaretRect();
- CPDF_Rect rcClip = GetClipRect();
-
- CFX_PathData path;
-
- path.SetPointCount(2);
-
- FX_FLOAT fCaretX = rcRect.left + m_fWidth * 0.5f;
- FX_FLOAT fCaretTop = rcRect.top;
- FX_FLOAT fCaretBottom = rcRect.bottom;
-
- if (!rcClip.IsEmpty())
- {
- rcRect.Intersect(rcClip);
- if (!rcRect.IsEmpty())
- {
- fCaretTop = rcRect.top;
- fCaretBottom = rcRect.bottom;
- path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOVETO);
- path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO);
- }
- else
- {
- return;
- }
- }
- else
- {
- path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOVETO);
- path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO);
- }
-
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = m_fWidth;
-
- pDevice->DrawPath(&path, pUser2Device, &gsd,0, ArgbEncode(255,0,0,0), FXFILL_ALTERNATE);
- }
-}
-
-void CPWL_Caret::GetCaretApp(CFX_ByteTextBuf & sAppStream,const CPDF_Point & ptOffset)
-{
- if (IsVisible() && m_bFlash)
- {
- CFX_ByteTextBuf sCaret;
-
- CPDF_Rect rcRect = GetCaretRect();
- CPDF_Rect rcClip = GetClipRect();
-
- rcRect = CPWL_Utils::OffsetRect(rcRect,ptOffset.x,ptOffset.y);
- rcClip = CPWL_Utils::OffsetRect(rcClip,ptOffset.x,ptOffset.y);
-
- sCaret << "q\n";
- if (!rcClip.IsEmpty())
- {
- sCaret << rcClip.left << " " << rcClip.bottom + 2.5f << " "
- << rcClip.right - rcClip.left << " " << rcClip.top - rcClip.bottom - 4.5f << " re W n\n";
- }
- sCaret << m_fWidth << " w\n0 G\n";
- sCaret << rcRect.left + m_fWidth/2 << " " << rcRect.bottom << " m\n";
- sCaret << rcRect.left + m_fWidth/2 << " " << rcRect.top << " l S\nQ\n";
-
- sAppStream << sCaret;
- }
-}
-
-CFX_ByteString CPWL_Caret::GetCaretAppearanceStream(const CPDF_Point & ptOffset)
-{
- CFX_ByteTextBuf sCaret;
- GetCaretApp(sCaret,ptOffset);
- return sCaret.GetByteString();
-}
-
-void CPWL_Caret::TimerProc()
-{
- if (m_nDelay > 0)
- {
- m_nDelay--;
- }
- else
- {
- m_bFlash = !m_bFlash;
- InvalidateRect();
- }
-}
-
-CPDF_Rect CPWL_Caret::GetCaretRect() const
-{
- return CPDF_Rect(m_ptFoot.x,
- m_ptFoot.y,
- m_ptHead.x + this->m_fWidth,
- m_ptHead.y);
-}
-
-void CPWL_Caret::SetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot)
-{
- if (bVisible)
- {
- if (IsVisible())
- {
- if (m_ptHead.x != ptHead.x || m_ptHead.y != ptHead.y ||
- m_ptFoot.x != ptFoot.x || m_ptFoot.y != ptFoot.y)
- {
- this->m_ptHead = ptHead;
- this->m_ptFoot = ptFoot;
-
- m_bFlash = TRUE;
- //Move(GetCaretRect(),FALSE,TRUE);
- Move(m_rcInvalid, FALSE, TRUE);
- }
- }
- else
- {
- this->m_ptHead = ptHead;
- this->m_ptFoot = ptFoot;
-
- EndTimer();
- BeginTimer(PWL_CARET_FLASHINTERVAL);
-
- CPWL_Wnd::SetVisible(TRUE);
- m_bFlash = TRUE;
-
- //Move(GetCaretRect(),FALSE,TRUE);
- Move(m_rcInvalid, FALSE, TRUE);
- }
- }
- else
- {
- this->m_ptHead = CPDF_Point(0,0);
- this->m_ptFoot = CPDF_Point(0,0);
-
- m_bFlash = FALSE;
- if (IsVisible())
- {
- EndTimer();
- CPWL_Wnd::SetVisible(FALSE);
- }
- }
-}
-
-void CPWL_Caret::InvalidateRect(CPDF_Rect * pRect)
-{
- if (pRect)
- {
- CPDF_Rect rcRefresh = CPWL_Utils::InflateRect(*pRect,0.5f);
- rcRefresh.top += 1;
- rcRefresh.bottom -= 1;
-
- CPWL_Wnd::InvalidateRect(&rcRefresh);
- }
- else
- CPWL_Wnd::InvalidateRect(pRect);
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Caret.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+#define PWL_CARET_FLASHINTERVAL 500
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+CPWL_Caret::CPWL_Caret() :
+ m_bFlash(FALSE),
+ m_ptHead(0,0),
+ m_ptFoot(0,0),
+ m_fWidth(0.4f),
+ m_nDelay(0)
+{
+}
+
+CPWL_Caret::~CPWL_Caret()
+{
+}
+
+CFX_ByteString CPWL_Caret::GetClassName() const
+{
+ return "CPWL_Caret";
+}
+
+void CPWL_Caret::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ GetCaretApp(sAppStream,CPDF_Point(0.0f,0.0f));
+}
+
+void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ if (IsVisible() && m_bFlash)
+ {
+ CPDF_Rect rcRect = GetCaretRect();
+ CPDF_Rect rcClip = GetClipRect();
+
+ CFX_PathData path;
+
+ path.SetPointCount(2);
+
+ FX_FLOAT fCaretX = rcRect.left + m_fWidth * 0.5f;
+ FX_FLOAT fCaretTop = rcRect.top;
+ FX_FLOAT fCaretBottom = rcRect.bottom;
+
+ if (!rcClip.IsEmpty())
+ {
+ rcRect.Intersect(rcClip);
+ if (!rcRect.IsEmpty())
+ {
+ fCaretTop = rcRect.top;
+ fCaretBottom = rcRect.bottom;
+ path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOVETO);
+ path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO);
+ }
+ else
+ {
+ return;
+ }
+ }
+ else
+ {
+ path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOVETO);
+ path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO);
+ }
+
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = m_fWidth;
+
+ pDevice->DrawPath(&path, pUser2Device, &gsd,0, ArgbEncode(255,0,0,0), FXFILL_ALTERNATE);
+ }
+}
+
+void CPWL_Caret::GetCaretApp(CFX_ByteTextBuf & sAppStream,const CPDF_Point & ptOffset)
+{
+ if (IsVisible() && m_bFlash)
+ {
+ CFX_ByteTextBuf sCaret;
+
+ CPDF_Rect rcRect = GetCaretRect();
+ CPDF_Rect rcClip = GetClipRect();
+
+ rcRect = CPWL_Utils::OffsetRect(rcRect,ptOffset.x,ptOffset.y);
+ rcClip = CPWL_Utils::OffsetRect(rcClip,ptOffset.x,ptOffset.y);
+
+ sCaret << "q\n";
+ if (!rcClip.IsEmpty())
+ {
+ sCaret << rcClip.left << " " << rcClip.bottom + 2.5f << " "
+ << rcClip.right - rcClip.left << " " << rcClip.top - rcClip.bottom - 4.5f << " re W n\n";
+ }
+ sCaret << m_fWidth << " w\n0 G\n";
+ sCaret << rcRect.left + m_fWidth/2 << " " << rcRect.bottom << " m\n";
+ sCaret << rcRect.left + m_fWidth/2 << " " << rcRect.top << " l S\nQ\n";
+
+ sAppStream << sCaret;
+ }
+}
+
+CFX_ByteString CPWL_Caret::GetCaretAppearanceStream(const CPDF_Point & ptOffset)
+{
+ CFX_ByteTextBuf sCaret;
+ GetCaretApp(sCaret,ptOffset);
+ return sCaret.GetByteString();
+}
+
+void CPWL_Caret::TimerProc()
+{
+ if (m_nDelay > 0)
+ {
+ m_nDelay--;
+ }
+ else
+ {
+ m_bFlash = !m_bFlash;
+ InvalidateRect();
+ }
+}
+
+CPDF_Rect CPWL_Caret::GetCaretRect() const
+{
+ return CPDF_Rect(m_ptFoot.x,
+ m_ptFoot.y,
+ m_ptHead.x + this->m_fWidth,
+ m_ptHead.y);
+}
+
+void CPWL_Caret::SetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot)
+{
+ if (bVisible)
+ {
+ if (IsVisible())
+ {
+ if (m_ptHead.x != ptHead.x || m_ptHead.y != ptHead.y ||
+ m_ptFoot.x != ptFoot.x || m_ptFoot.y != ptFoot.y)
+ {
+ this->m_ptHead = ptHead;
+ this->m_ptFoot = ptFoot;
+
+ m_bFlash = TRUE;
+ //Move(GetCaretRect(),FALSE,TRUE);
+ Move(m_rcInvalid, FALSE, TRUE);
+ }
+ }
+ else
+ {
+ this->m_ptHead = ptHead;
+ this->m_ptFoot = ptFoot;
+
+ EndTimer();
+ BeginTimer(PWL_CARET_FLASHINTERVAL);
+
+ CPWL_Wnd::SetVisible(TRUE);
+ m_bFlash = TRUE;
+
+ //Move(GetCaretRect(),FALSE,TRUE);
+ Move(m_rcInvalid, FALSE, TRUE);
+ }
+ }
+ else
+ {
+ this->m_ptHead = CPDF_Point(0,0);
+ this->m_ptFoot = CPDF_Point(0,0);
+
+ m_bFlash = FALSE;
+ if (IsVisible())
+ {
+ EndTimer();
+ CPWL_Wnd::SetVisible(FALSE);
+ }
+ }
+}
+
+void CPWL_Caret::InvalidateRect(CPDF_Rect * pRect)
+{
+ if (pRect)
+ {
+ CPDF_Rect rcRefresh = CPWL_Utils::InflateRect(*pRect,0.5f);
+ rcRefresh.top += 1;
+ rcRefresh.bottom -= 1;
+
+ CPWL_Wnd::InvalidateRect(&rcRefresh);
+ }
+ else
+ CPWL_Wnd::InvalidateRect(pRect);
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp b/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp
index 7650a23e5b..020765aba5 100644
--- a/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp
@@ -1,662 +1,662 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_EditCtrl.h"
-#include "../../include/pdfwindow/PWL_Edit.h"
-#include "../../include/pdfwindow/PWL_ListBox.h"
-#include "../../include/pdfwindow/PWL_ComboBox.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-
-#define PWLCB_DEFAULTFONTSIZE 12.0f
-
-#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
-#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
-
-
-/* ---------------------------- CPWL_CBListBox ---------------------------- */
-
-FX_BOOL CPWL_CBListBox::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonUp(point,nFlag);
-
- if (m_bMouseDown)
- {
- ReleaseCapture();
- m_bMouseDown = FALSE;
-
- if (this->ClientHitTest(point))
- {
- if (CPWL_Wnd * pParent = GetParentWindow())
- {
- pParent->OnNotify(this,PNM_LBUTTONUP,0,PWL_MAKEDWORD(point.x,point.y));
- }
-
- FX_BOOL bExit = FALSE;
- OnNotifySelChanged(FALSE,bExit, nFlag);
- if (bExit) return FALSE;
- }
- }
-
- return TRUE;
-}
-
-FX_BOOL CPWL_CBListBox::OnKeyDown(FX_WORD nChar, FX_BOOL & bExit, FX_DWORD nFlag)
-{
- if (!m_pList) return FALSE;
-
- switch (nChar)
- {
- default:
- return FALSE;
- case FWL_VKEY_Up:
- case FWL_VKEY_Down:
- case FWL_VKEY_Home:
- case FWL_VKEY_Left:
- case FWL_VKEY_End:
- case FWL_VKEY_Right:
- break;
- }
-
- switch (nChar)
- {
- case FWL_VKEY_Up:
- m_pList->OnVK_UP(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Down:
- m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Home:
- m_pList->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Left:
- m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_End:
- m_pList->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Right:
- m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Delete:
- break;
- }
-
- OnNotifySelChanged(TRUE,bExit, nFlag);
-
- return TRUE;
-}
-
-FX_BOOL CPWL_CBListBox::OnChar(FX_WORD nChar, FX_BOOL & bExit, FX_DWORD nFlag)
-{
- if (!m_pList) return FALSE;
-
- if (!m_pList->OnChar(nChar,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag))) return FALSE;
-
- if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow())
- {
- pComboBox->SetSelectText();
- }
-
- OnNotifySelChanged(TRUE,bExit,nFlag);
-
- return TRUE;
-}
-
-/* ---------------------------- CPWL_CBButton ---------------------------- */
-
-void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- CPWL_Wnd::GetThisAppearanceStream(sAppStream);
-
- CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect();
-
- if (IsVisible() && !rectWnd.IsEmpty())
- {
- CFX_ByteTextBuf sButton;
-
- CPDF_Point ptCenter = this->GetCenterPoint();
-
- CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
- CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
- CPDF_Point pt3(ptCenter.x,ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
-
- if (IsFloatBigger(rectWnd.right - rectWnd.left,PWL_CBBUTTON_TRIANGLE_HALFLEN * 2)
- &&
- IsFloatBigger(rectWnd.top - rectWnd.bottom,PWL_CBBUTTON_TRIANGLE_HALFLEN)
- )
- {
- sButton << "0 g\n";
- sButton << pt1.x << " " << pt1.y << " m\n";
- sButton << pt2.x << " " << pt2.y << " l\n";
- sButton << pt3.x << " " << pt3.y << " l\n";
- sButton << pt1.x << " " << pt1.y << " l f\n";
-
- sAppStream << "q\n" << sButton << "Q\n";
- }
- }
-}
-
-void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
-
- CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect();
-
- if (IsVisible() && !rectWnd.IsEmpty())
- {
- CPDF_Point ptCenter = this->GetCenterPoint();
-
- CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
- CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
- CPDF_Point pt3(ptCenter.x,ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
-
- if (IsFloatBigger(rectWnd.right - rectWnd.left,PWL_CBBUTTON_TRIANGLE_HALFLEN * 2)
- &&
- IsFloatBigger(rectWnd.top - rectWnd.bottom,PWL_CBBUTTON_TRIANGLE_HALFLEN)
- )
- {
- CFX_PathData path;
-
- path.SetPointCount(4);
- path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
- path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
- path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
- path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
-
- pDevice->DrawPath(&path, pUser2Device, NULL,
- CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR,GetTransparency()),
- 0, FXFILL_ALTERNATE);
- }
- }
-}
-
-FX_BOOL CPWL_CBButton::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonDown(point,nFlag);
-
- SetCapture();
-
- if (CPWL_Wnd * pParent = GetParentWindow())
- {
- pParent->OnNotify(this,PNM_LBUTTONDOWN,0,PWL_MAKEDWORD(point.x,point.y));
- }
-
- return TRUE;
-}
-
-FX_BOOL CPWL_CBButton::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonUp(point, nFlag);
-
- ReleaseCapture();
-
- return TRUE;
-}
-
-/* ---------------------------- CPWL_ComboBox ---------------------------- */
-
-CPWL_ComboBox::CPWL_ComboBox() : m_pEdit(NULL),
- m_pButton(NULL),
- m_pList(NULL),
- m_bPopup(FALSE),
- m_nPopupWhere(0),
- m_nSelectItem(-1),
- m_pFillerNotify(NULL)
-{
-}
-
-CFX_ByteString CPWL_ComboBox::GetClassName() const
-{
- return "CPWL_ComboBox";
-}
-
-void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM & cp)
-{
- cp.dwFlags &= ~PWS_HSCROLL;
- cp.dwFlags &= ~PWS_VSCROLL;
-}
-
-void CPWL_ComboBox::SetFocus()
-{
- if (m_pEdit)
- m_pEdit->SetFocus();
-}
-
-void CPWL_ComboBox::KillFocus()
-{
- SetPopup(FALSE);
- CPWL_Wnd::KillFocus();
-}
-
-CFX_WideString CPWL_ComboBox::GetText() const
-{
- if (m_pEdit)
- {
- return m_pEdit->GetText();
- }
- return CFX_WideString();
-}
-
-void CPWL_ComboBox::SetText(FX_LPCWSTR text)
-{
- if (m_pEdit)
- m_pEdit->SetText(text);
-}
-
-void CPWL_ComboBox::AddString(FX_LPCWSTR string)
-{
- if (m_pList)
- m_pList->AddString(string);
-}
-
-FX_INT32 CPWL_ComboBox::GetSelect() const
-{
- return m_nSelectItem;
-}
-
-void CPWL_ComboBox::SetSelect(FX_INT32 nItemIndex)
-{
- if (m_pList)
- m_pList->Select(nItemIndex);
-
- m_pEdit->SetText(m_pList->GetText());
-
- m_nSelectItem = nItemIndex;
-}
-
-void CPWL_ComboBox::SetEditSel(FX_INT32 nStartChar,FX_INT32 nEndChar)
-{
- if (m_pEdit)
- {
- m_pEdit->SetSel(nStartChar,nEndChar);
- }
-}
-
-void CPWL_ComboBox::GetEditSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
-{
- nStartChar = -1;
- nEndChar = -1;
-
- if (m_pEdit)
- {
- m_pEdit->GetSel(nStartChar,nEndChar);
- }
-}
-
-void CPWL_ComboBox::Clear()
-{
- if (m_pEdit)
- {
- m_pEdit->Clear();
- }
-}
-
-void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- CreateEdit(cp);
- CreateButton(cp);
- CreateListBox(cp);
-}
-
-void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM & cp)
-{
- if (!m_pEdit)
- {
- m_pEdit = new CPWL_CBEdit;
- m_pEdit->AttachFFLData(m_pFormFiller);
-
- PWL_CREATEPARAM ecp = cp;
- ecp.pParentWnd = this;
- ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | PES_AUTOSCROLL | PES_UNDO;
-
- if (HasFlag(PWS_AUTOFONTSIZE))
- ecp.dwFlags |= PWS_AUTOFONTSIZE;
-
- if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
- ecp.dwFlags |= PWS_READONLY;
-
- ecp.rcRectWnd = CPDF_Rect(0,0,0,0);
- ecp.dwBorderWidth = 0;
- ecp.nBorderStyle = PBS_SOLID;
-
- m_pEdit->Create(ecp);
- }
-}
-
-void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM & cp)
-{
- if (!m_pButton)
- {
- m_pButton = new CPWL_CBButton;
-
- PWL_CREATEPARAM bcp = cp;
- bcp.pParentWnd = this;
- bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
- bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR;
- bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
- bcp.dwBorderWidth = 2;
- bcp.nBorderStyle = PBS_BEVELED;
- bcp.eCursorType = FXCT_ARROW;
-
- m_pButton->Create(bcp);
- }
-}
-
-void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM & cp)
-{
- if (!m_pList)
- {
- m_pList = new CPWL_CBListBox;
- m_pList->AttachFFLData(m_pFormFiller);
- PWL_CREATEPARAM lcp = cp;
- lcp.pParentWnd = this;
- lcp.dwFlags = PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
- lcp.nBorderStyle = PBS_SOLID;
- lcp.dwBorderWidth = 1;
- lcp.eCursorType = FXCT_ARROW;
- lcp.rcRectWnd = CPDF_Rect(0,0,0,0);
-
- if (cp.dwFlags & PWS_AUTOFONTSIZE)
- lcp.fFontSize = PWLCB_DEFAULTFONTSIZE;
- else
- lcp.fFontSize = cp.fFontSize;
-
- if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
- lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
-
- if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
- lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
-
- m_pList->Create(lcp);
- }
-}
-
-void CPWL_ComboBox::RePosChildWnd()
-{
- CPDF_Rect rcClient = GetClientRect();
-
- if (m_bPopup)
- {
- CPDF_Rect rclient = GetClientRect();
- CPDF_Rect rcButton = rclient;
- CPDF_Rect rcEdit = rcClient;
- CPDF_Rect rcList = CPWL_Wnd::GetWindowRect();
-
- FX_FLOAT fOldWindowHeight = m_rcOldWindow.Height();
- FX_FLOAT fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2;
-
- switch (m_nPopupWhere)
- {
- case 0:
- rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
-
- if (rcButton.left < rclient.left)
- rcButton.left = rclient.left;
-
- rcButton.bottom = rcButton.top - fOldClientHeight;
-
- rcEdit.right = rcButton.left - 1.0f;
-
- if (rcEdit.left < rclient.left)
- rcEdit.left = rclient.left;
-
- if (rcEdit.right < rcEdit.left)
- rcEdit.right = rcEdit.left;
-
- rcEdit.bottom = rcEdit.top - fOldClientHeight;
-
- rcList.top -= fOldWindowHeight;
-
- break;
- case 1:
- rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
-
- if (rcButton.left < rclient.left)
- rcButton.left = rclient.left;
-
- rcButton.top = rcButton.bottom + fOldClientHeight;
-
- rcEdit.right = rcButton.left - 1.0f;
-
- if (rcEdit.left < rclient.left)
- rcEdit.left = rclient.left;
-
- if (rcEdit.right < rcEdit.left)
- rcEdit.right = rcEdit.left;
-
- rcEdit.top = rcEdit.bottom + fOldClientHeight;
-
- rcList.bottom += fOldWindowHeight;
-
- break;
- }
-
- if (m_pButton)
- m_pButton->Move(rcButton,TRUE,FALSE);
-
- if (m_pEdit)
- m_pEdit->Move(rcEdit,TRUE,FALSE);
-
- if (m_pList)
- {
- m_pList->SetVisible(TRUE);
- m_pList->Move(rcList,TRUE,FALSE);
- m_pList->ScrollToListItem(m_nSelectItem);
- }
- }
- else
- {
- CPDF_Rect rcButton = rcClient;
-
- rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
-
- if (rcButton.left < rcClient.left)
- rcButton.left = rcClient.left;
-
- if (m_pButton)
- m_pButton->Move(rcButton,TRUE,FALSE);
-
- CPDF_Rect rcEdit = rcClient;
- rcEdit.right = rcButton.left - 1.0f;
-
- if (rcEdit.left < rcClient.left)
- rcEdit.left = rcClient.left;
-
- if (rcEdit.right < rcEdit.left)
- rcEdit.right = rcEdit.left;
-
- if (m_pEdit)
- m_pEdit->Move(rcEdit,TRUE,FALSE);
-
- if (m_pList)
- m_pList->SetVisible(FALSE);
- }
-}
-
-void CPWL_ComboBox::SelectAll()
-{
- if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT))
- m_pEdit->SelectAll();
-}
-
-CPDF_Rect CPWL_ComboBox::GetFocusRect() const
-{
- return CPDF_Rect();
-}
-
-void CPWL_ComboBox::SetPopup(FX_BOOL bPopup)
-{
- if (!m_pList) return;
- if (bPopup == m_bPopup) return;
- FX_FLOAT fListHeight = m_pList->GetContentRect().Height();
- if (!IsFloatBigger(fListHeight,0.0f)) return;
-
- if (bPopup)
- {
- if (m_pFillerNotify)
- {
- FX_INT32 nWhere = 0;
- FX_FLOAT fPopupRet = 0.0f;
- FX_FLOAT fPopupMin = 0.0f;
- if (m_pList->GetCount() > 3)
- fPopupMin = m_pList->GetFirstHeight() * 3 + m_pList->GetBorderWidth() * 2;
- FX_FLOAT fPopupMax = fListHeight + m_pList->GetBorderWidth() * 2;
- m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin,fPopupMax,nWhere,fPopupRet);
-
- if (IsFloatBigger(fPopupRet,0.0f))
- {
- m_bPopup = bPopup;
-
- CPDF_Rect rcWindow = CPWL_Wnd::GetWindowRect();
- m_rcOldWindow = rcWindow;
- switch (nWhere)
- {
- default:
- case 0:
- rcWindow.bottom -= fPopupRet;
- break;
- case 1:
- rcWindow.top += fPopupRet;
- break;
- }
-
- m_nPopupWhere = nWhere;
- Move(rcWindow, TRUE, TRUE);
- }
- }
- }
- else
- {
- m_bPopup = bPopup;
- Move(m_rcOldWindow, TRUE, TRUE);
- }
-}
-
-FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
-{
- if (!m_pList) return FALSE;
- if (!m_pEdit) return FALSE;
-
- m_nSelectItem = -1;
-
- switch (nChar)
- {
- case FWL_VKEY_Up:
- if (m_pList->GetCurSel() > 0)
- {
- FX_BOOL bExit = FALSE;
- if (m_pList->OnKeyDown(nChar,bExit,nFlag))
- {
- if (bExit) return FALSE;
- SetSelectText();
- }
- }
- return TRUE;
- case FWL_VKEY_Down:
- if (m_pList->GetCurSel() < m_pList->GetCount() - 1)
- {
- FX_BOOL bExit = FALSE;
- if (m_pList->OnKeyDown(nChar,bExit,nFlag))
- {
- if (bExit) return FALSE;
- SetSelectText();
- }
- }
- return TRUE;
- }
-
- if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
- return m_pEdit->OnKeyDown(nChar,nFlag);
- else
- return FALSE;
-}
-
-FX_BOOL CPWL_ComboBox::OnChar(FX_WORD nChar, FX_DWORD nFlag)
-{
- if (!m_pList) return FALSE;
- if (!m_pEdit) return FALSE;
-
- m_nSelectItem = -1;
- FX_BOOL bExit = FALSE;
-
- if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
- {
- return m_pEdit->OnChar(nChar,nFlag);
- }
- else
- {
- if (m_pList->OnChar(nChar,bExit,nFlag))
- {
- return bExit;
- }
- else
- return FALSE;
- }
-}
-
-void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- switch (msg)
- {
- case PNM_LBUTTONDOWN:
- if (pWnd == m_pButton)
- {
- SetPopup(!m_bPopup);
- return;
- }
- break;
- case PNM_LBUTTONUP:
- if (m_pEdit && m_pList)
- {
- if (pWnd == m_pList)
- {
- SetSelectText();
- SelectAll();
- m_pEdit->SetFocus();
- SetPopup(FALSE);
- return;
- }
- }
- }
-
- CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
-}
-
-FX_BOOL CPWL_ComboBox::IsPopup() const
-{
- return m_bPopup;
-}
-
-void CPWL_ComboBox::SetSelectText()
-{
- CFX_WideString swText = m_pList->GetText();
- m_pEdit->SelectAll();
- m_pEdit->ReplaceSel(m_pList->GetText());
- m_pEdit->SelectAll();
-
- m_nSelectItem = m_pList->GetCurSel();
-}
-
-FX_BOOL CPWL_ComboBox::IsModified() const
-{
- return m_pEdit->IsModified();
-}
-
-void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify)
-{
- m_pFillerNotify = pNotify;
-
- if (m_pEdit)
- m_pEdit->SetFillerNotify(pNotify);
-
- if (m_pList)
- m_pList->SetFillerNotify(pNotify);
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_EditCtrl.h"
+#include "../../include/pdfwindow/PWL_Edit.h"
+#include "../../include/pdfwindow/PWL_ListBox.h"
+#include "../../include/pdfwindow/PWL_ComboBox.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+#define PWLCB_DEFAULTFONTSIZE 12.0f
+
+#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
+#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
+
+
+/* ---------------------------- CPWL_CBListBox ---------------------------- */
+
+FX_BOOL CPWL_CBListBox::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonUp(point,nFlag);
+
+ if (m_bMouseDown)
+ {
+ ReleaseCapture();
+ m_bMouseDown = FALSE;
+
+ if (this->ClientHitTest(point))
+ {
+ if (CPWL_Wnd * pParent = GetParentWindow())
+ {
+ pParent->OnNotify(this,PNM_LBUTTONUP,0,PWL_MAKEDWORD(point.x,point.y));
+ }
+
+ FX_BOOL bExit = FALSE;
+ OnNotifySelChanged(FALSE,bExit, nFlag);
+ if (bExit) return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_CBListBox::OnKeyDown(FX_WORD nChar, FX_BOOL & bExit, FX_DWORD nFlag)
+{
+ if (!m_pList) return FALSE;
+
+ switch (nChar)
+ {
+ default:
+ return FALSE;
+ case FWL_VKEY_Up:
+ case FWL_VKEY_Down:
+ case FWL_VKEY_Home:
+ case FWL_VKEY_Left:
+ case FWL_VKEY_End:
+ case FWL_VKEY_Right:
+ break;
+ }
+
+ switch (nChar)
+ {
+ case FWL_VKEY_Up:
+ m_pList->OnVK_UP(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Down:
+ m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Home:
+ m_pList->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Left:
+ m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_End:
+ m_pList->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Right:
+ m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Delete:
+ break;
+ }
+
+ OnNotifySelChanged(TRUE,bExit, nFlag);
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_CBListBox::OnChar(FX_WORD nChar, FX_BOOL & bExit, FX_DWORD nFlag)
+{
+ if (!m_pList) return FALSE;
+
+ if (!m_pList->OnChar(nChar,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag))) return FALSE;
+
+ if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow())
+ {
+ pComboBox->SetSelectText();
+ }
+
+ OnNotifySelChanged(TRUE,bExit,nFlag);
+
+ return TRUE;
+}
+
+/* ---------------------------- CPWL_CBButton ---------------------------- */
+
+void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ CPWL_Wnd::GetThisAppearanceStream(sAppStream);
+
+ CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect();
+
+ if (IsVisible() && !rectWnd.IsEmpty())
+ {
+ CFX_ByteTextBuf sButton;
+
+ CPDF_Point ptCenter = this->GetCenterPoint();
+
+ CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
+ CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
+ CPDF_Point pt3(ptCenter.x,ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
+
+ if (IsFloatBigger(rectWnd.right - rectWnd.left,PWL_CBBUTTON_TRIANGLE_HALFLEN * 2)
+ &&
+ IsFloatBigger(rectWnd.top - rectWnd.bottom,PWL_CBBUTTON_TRIANGLE_HALFLEN)
+ )
+ {
+ sButton << "0 g\n";
+ sButton << pt1.x << " " << pt1.y << " m\n";
+ sButton << pt2.x << " " << pt2.y << " l\n";
+ sButton << pt3.x << " " << pt3.y << " l\n";
+ sButton << pt1.x << " " << pt1.y << " l f\n";
+
+ sAppStream << "q\n" << sButton << "Q\n";
+ }
+ }
+}
+
+void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
+
+ CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect();
+
+ if (IsVisible() && !rectWnd.IsEmpty())
+ {
+ CPDF_Point ptCenter = this->GetCenterPoint();
+
+ CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
+ CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
+ CPDF_Point pt3(ptCenter.x,ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
+
+ if (IsFloatBigger(rectWnd.right - rectWnd.left,PWL_CBBUTTON_TRIANGLE_HALFLEN * 2)
+ &&
+ IsFloatBigger(rectWnd.top - rectWnd.bottom,PWL_CBBUTTON_TRIANGLE_HALFLEN)
+ )
+ {
+ CFX_PathData path;
+
+ path.SetPointCount(4);
+ path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
+ path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
+ path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
+ path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
+
+ pDevice->DrawPath(&path, pUser2Device, NULL,
+ CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR,GetTransparency()),
+ 0, FXFILL_ALTERNATE);
+ }
+ }
+}
+
+FX_BOOL CPWL_CBButton::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonDown(point,nFlag);
+
+ SetCapture();
+
+ if (CPWL_Wnd * pParent = GetParentWindow())
+ {
+ pParent->OnNotify(this,PNM_LBUTTONDOWN,0,PWL_MAKEDWORD(point.x,point.y));
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_CBButton::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonUp(point, nFlag);
+
+ ReleaseCapture();
+
+ return TRUE;
+}
+
+/* ---------------------------- CPWL_ComboBox ---------------------------- */
+
+CPWL_ComboBox::CPWL_ComboBox() : m_pEdit(NULL),
+ m_pButton(NULL),
+ m_pList(NULL),
+ m_bPopup(FALSE),
+ m_nPopupWhere(0),
+ m_nSelectItem(-1),
+ m_pFillerNotify(NULL)
+{
+}
+
+CFX_ByteString CPWL_ComboBox::GetClassName() const
+{
+ return "CPWL_ComboBox";
+}
+
+void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM & cp)
+{
+ cp.dwFlags &= ~PWS_HSCROLL;
+ cp.dwFlags &= ~PWS_VSCROLL;
+}
+
+void CPWL_ComboBox::SetFocus()
+{
+ if (m_pEdit)
+ m_pEdit->SetFocus();
+}
+
+void CPWL_ComboBox::KillFocus()
+{
+ SetPopup(FALSE);
+ CPWL_Wnd::KillFocus();
+}
+
+CFX_WideString CPWL_ComboBox::GetText() const
+{
+ if (m_pEdit)
+ {
+ return m_pEdit->GetText();
+ }
+ return CFX_WideString();
+}
+
+void CPWL_ComboBox::SetText(FX_LPCWSTR text)
+{
+ if (m_pEdit)
+ m_pEdit->SetText(text);
+}
+
+void CPWL_ComboBox::AddString(FX_LPCWSTR string)
+{
+ if (m_pList)
+ m_pList->AddString(string);
+}
+
+FX_INT32 CPWL_ComboBox::GetSelect() const
+{
+ return m_nSelectItem;
+}
+
+void CPWL_ComboBox::SetSelect(FX_INT32 nItemIndex)
+{
+ if (m_pList)
+ m_pList->Select(nItemIndex);
+
+ m_pEdit->SetText(m_pList->GetText());
+
+ m_nSelectItem = nItemIndex;
+}
+
+void CPWL_ComboBox::SetEditSel(FX_INT32 nStartChar,FX_INT32 nEndChar)
+{
+ if (m_pEdit)
+ {
+ m_pEdit->SetSel(nStartChar,nEndChar);
+ }
+}
+
+void CPWL_ComboBox::GetEditSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
+{
+ nStartChar = -1;
+ nEndChar = -1;
+
+ if (m_pEdit)
+ {
+ m_pEdit->GetSel(nStartChar,nEndChar);
+ }
+}
+
+void CPWL_ComboBox::Clear()
+{
+ if (m_pEdit)
+ {
+ m_pEdit->Clear();
+ }
+}
+
+void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ CreateEdit(cp);
+ CreateButton(cp);
+ CreateListBox(cp);
+}
+
+void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM & cp)
+{
+ if (!m_pEdit)
+ {
+ m_pEdit = new CPWL_CBEdit;
+ m_pEdit->AttachFFLData(m_pFormFiller);
+
+ PWL_CREATEPARAM ecp = cp;
+ ecp.pParentWnd = this;
+ ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | PES_AUTOSCROLL | PES_UNDO;
+
+ if (HasFlag(PWS_AUTOFONTSIZE))
+ ecp.dwFlags |= PWS_AUTOFONTSIZE;
+
+ if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
+ ecp.dwFlags |= PWS_READONLY;
+
+ ecp.rcRectWnd = CPDF_Rect(0,0,0,0);
+ ecp.dwBorderWidth = 0;
+ ecp.nBorderStyle = PBS_SOLID;
+
+ m_pEdit->Create(ecp);
+ }
+}
+
+void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM & cp)
+{
+ if (!m_pButton)
+ {
+ m_pButton = new CPWL_CBButton;
+
+ PWL_CREATEPARAM bcp = cp;
+ bcp.pParentWnd = this;
+ bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
+ bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR;
+ bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
+ bcp.dwBorderWidth = 2;
+ bcp.nBorderStyle = PBS_BEVELED;
+ bcp.eCursorType = FXCT_ARROW;
+
+ m_pButton->Create(bcp);
+ }
+}
+
+void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM & cp)
+{
+ if (!m_pList)
+ {
+ m_pList = new CPWL_CBListBox;
+ m_pList->AttachFFLData(m_pFormFiller);
+ PWL_CREATEPARAM lcp = cp;
+ lcp.pParentWnd = this;
+ lcp.dwFlags = PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
+ lcp.nBorderStyle = PBS_SOLID;
+ lcp.dwBorderWidth = 1;
+ lcp.eCursorType = FXCT_ARROW;
+ lcp.rcRectWnd = CPDF_Rect(0,0,0,0);
+
+ if (cp.dwFlags & PWS_AUTOFONTSIZE)
+ lcp.fFontSize = PWLCB_DEFAULTFONTSIZE;
+ else
+ lcp.fFontSize = cp.fFontSize;
+
+ if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
+ lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
+
+ if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
+ lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
+
+ m_pList->Create(lcp);
+ }
+}
+
+void CPWL_ComboBox::RePosChildWnd()
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ if (m_bPopup)
+ {
+ CPDF_Rect rclient = GetClientRect();
+ CPDF_Rect rcButton = rclient;
+ CPDF_Rect rcEdit = rcClient;
+ CPDF_Rect rcList = CPWL_Wnd::GetWindowRect();
+
+ FX_FLOAT fOldWindowHeight = m_rcOldWindow.Height();
+ FX_FLOAT fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2;
+
+ switch (m_nPopupWhere)
+ {
+ case 0:
+ rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
+
+ if (rcButton.left < rclient.left)
+ rcButton.left = rclient.left;
+
+ rcButton.bottom = rcButton.top - fOldClientHeight;
+
+ rcEdit.right = rcButton.left - 1.0f;
+
+ if (rcEdit.left < rclient.left)
+ rcEdit.left = rclient.left;
+
+ if (rcEdit.right < rcEdit.left)
+ rcEdit.right = rcEdit.left;
+
+ rcEdit.bottom = rcEdit.top - fOldClientHeight;
+
+ rcList.top -= fOldWindowHeight;
+
+ break;
+ case 1:
+ rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
+
+ if (rcButton.left < rclient.left)
+ rcButton.left = rclient.left;
+
+ rcButton.top = rcButton.bottom + fOldClientHeight;
+
+ rcEdit.right = rcButton.left - 1.0f;
+
+ if (rcEdit.left < rclient.left)
+ rcEdit.left = rclient.left;
+
+ if (rcEdit.right < rcEdit.left)
+ rcEdit.right = rcEdit.left;
+
+ rcEdit.top = rcEdit.bottom + fOldClientHeight;
+
+ rcList.bottom += fOldWindowHeight;
+
+ break;
+ }
+
+ if (m_pButton)
+ m_pButton->Move(rcButton,TRUE,FALSE);
+
+ if (m_pEdit)
+ m_pEdit->Move(rcEdit,TRUE,FALSE);
+
+ if (m_pList)
+ {
+ m_pList->SetVisible(TRUE);
+ m_pList->Move(rcList,TRUE,FALSE);
+ m_pList->ScrollToListItem(m_nSelectItem);
+ }
+ }
+ else
+ {
+ CPDF_Rect rcButton = rcClient;
+
+ rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
+
+ if (rcButton.left < rcClient.left)
+ rcButton.left = rcClient.left;
+
+ if (m_pButton)
+ m_pButton->Move(rcButton,TRUE,FALSE);
+
+ CPDF_Rect rcEdit = rcClient;
+ rcEdit.right = rcButton.left - 1.0f;
+
+ if (rcEdit.left < rcClient.left)
+ rcEdit.left = rcClient.left;
+
+ if (rcEdit.right < rcEdit.left)
+ rcEdit.right = rcEdit.left;
+
+ if (m_pEdit)
+ m_pEdit->Move(rcEdit,TRUE,FALSE);
+
+ if (m_pList)
+ m_pList->SetVisible(FALSE);
+ }
+}
+
+void CPWL_ComboBox::SelectAll()
+{
+ if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT))
+ m_pEdit->SelectAll();
+}
+
+CPDF_Rect CPWL_ComboBox::GetFocusRect() const
+{
+ return CPDF_Rect();
+}
+
+void CPWL_ComboBox::SetPopup(FX_BOOL bPopup)
+{
+ if (!m_pList) return;
+ if (bPopup == m_bPopup) return;
+ FX_FLOAT fListHeight = m_pList->GetContentRect().Height();
+ if (!IsFloatBigger(fListHeight,0.0f)) return;
+
+ if (bPopup)
+ {
+ if (m_pFillerNotify)
+ {
+ FX_INT32 nWhere = 0;
+ FX_FLOAT fPopupRet = 0.0f;
+ FX_FLOAT fPopupMin = 0.0f;
+ if (m_pList->GetCount() > 3)
+ fPopupMin = m_pList->GetFirstHeight() * 3 + m_pList->GetBorderWidth() * 2;
+ FX_FLOAT fPopupMax = fListHeight + m_pList->GetBorderWidth() * 2;
+ m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin,fPopupMax,nWhere,fPopupRet);
+
+ if (IsFloatBigger(fPopupRet,0.0f))
+ {
+ m_bPopup = bPopup;
+
+ CPDF_Rect rcWindow = CPWL_Wnd::GetWindowRect();
+ m_rcOldWindow = rcWindow;
+ switch (nWhere)
+ {
+ default:
+ case 0:
+ rcWindow.bottom -= fPopupRet;
+ break;
+ case 1:
+ rcWindow.top += fPopupRet;
+ break;
+ }
+
+ m_nPopupWhere = nWhere;
+ Move(rcWindow, TRUE, TRUE);
+ }
+ }
+ }
+ else
+ {
+ m_bPopup = bPopup;
+ Move(m_rcOldWindow, TRUE, TRUE);
+ }
+}
+
+FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
+{
+ if (!m_pList) return FALSE;
+ if (!m_pEdit) return FALSE;
+
+ m_nSelectItem = -1;
+
+ switch (nChar)
+ {
+ case FWL_VKEY_Up:
+ if (m_pList->GetCurSel() > 0)
+ {
+ FX_BOOL bExit = FALSE;
+ if (m_pList->OnKeyDown(nChar,bExit,nFlag))
+ {
+ if (bExit) return FALSE;
+ SetSelectText();
+ }
+ }
+ return TRUE;
+ case FWL_VKEY_Down:
+ if (m_pList->GetCurSel() < m_pList->GetCount() - 1)
+ {
+ FX_BOOL bExit = FALSE;
+ if (m_pList->OnKeyDown(nChar,bExit,nFlag))
+ {
+ if (bExit) return FALSE;
+ SetSelectText();
+ }
+ }
+ return TRUE;
+ }
+
+ if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
+ return m_pEdit->OnKeyDown(nChar,nFlag);
+ else
+ return FALSE;
+}
+
+FX_BOOL CPWL_ComboBox::OnChar(FX_WORD nChar, FX_DWORD nFlag)
+{
+ if (!m_pList) return FALSE;
+ if (!m_pEdit) return FALSE;
+
+ m_nSelectItem = -1;
+ FX_BOOL bExit = FALSE;
+
+ if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
+ {
+ return m_pEdit->OnChar(nChar,nFlag);
+ }
+ else
+ {
+ if (m_pList->OnChar(nChar,bExit,nFlag))
+ {
+ return bExit;
+ }
+ else
+ return FALSE;
+ }
+}
+
+void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ switch (msg)
+ {
+ case PNM_LBUTTONDOWN:
+ if (pWnd == m_pButton)
+ {
+ SetPopup(!m_bPopup);
+ return;
+ }
+ break;
+ case PNM_LBUTTONUP:
+ if (m_pEdit && m_pList)
+ {
+ if (pWnd == m_pList)
+ {
+ SetSelectText();
+ SelectAll();
+ m_pEdit->SetFocus();
+ SetPopup(FALSE);
+ return;
+ }
+ }
+ }
+
+ CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
+}
+
+FX_BOOL CPWL_ComboBox::IsPopup() const
+{
+ return m_bPopup;
+}
+
+void CPWL_ComboBox::SetSelectText()
+{
+ CFX_WideString swText = m_pList->GetText();
+ m_pEdit->SelectAll();
+ m_pEdit->ReplaceSel(m_pList->GetText());
+ m_pEdit->SelectAll();
+
+ m_nSelectItem = m_pList->GetCurSel();
+}
+
+FX_BOOL CPWL_ComboBox::IsModified() const
+{
+ return m_pEdit->IsModified();
+}
+
+void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify)
+{
+ m_pFillerNotify = pNotify;
+
+ if (m_pEdit)
+ m_pEdit->SetFillerNotify(pNotify);
+
+ if (m_pList)
+ m_pList->SetFillerNotify(pNotify);
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_Edit.cpp b/fpdfsdk/src/pdfwindow/PWL_Edit.cpp
index 87ddd87fb0..df59c2ccc8 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Edit.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Edit.cpp
@@ -1,1316 +1,1316 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_EditCtrl.h"
-#include "../../include/pdfwindow/PWL_Edit.h"
-#include "../../include/pdfwindow/PWL_ScrollBar.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-#include "../../include/pdfwindow/PWL_Caret.h"
-#include "../../include/pdfwindow/PWL_FontMap.h"
-
-/* ---------------------------- CPWL_Edit ------------------------------ */
-
-CPWL_Edit::CPWL_Edit() : m_pFillerNotify(NULL),
- m_pSpellCheck(NULL),
- m_bFocus(FALSE)
-{
- m_pFormFiller = NULL;
-}
-
-CPWL_Edit::~CPWL_Edit()
-{
- ASSERT(m_bFocus == FALSE);
-}
-
-CFX_ByteString CPWL_Edit::GetClassName() const
-{
- return PWL_CLASSNAME_EDIT;
-}
-
-void CPWL_Edit::OnDestroy()
-{
-}
-
-void CPWL_Edit::SetText(FX_LPCWSTR csText)
-{
- CFX_WideString swText = csText;
-
- if (HasFlag(PES_RICH))
- {
- CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText);
-
- if (CXML_Element * pXML = CXML_Element::Parse((FX_LPCSTR)sValue,sValue.GetLength()))
- {
- FX_INT32 nCount = pXML->CountChildren();
- FX_BOOL bFirst = TRUE;
-
- swText.Empty();
-
- for (FX_INT32 i=0; i<nCount; i++)
- {
- if (CXML_Element * pSubElement = pXML->GetElement(i))
- {
- CFX_ByteString tag=pSubElement->GetTagName();
- if (tag.EqualNoCase("p"))
- {
- int nChild = pSubElement->CountChildren();
- CFX_WideString swSection;
- for(FX_INT32 j=0; j<nChild; j++)
- {
- swSection += pSubElement->GetContent(j);
- }
-
- if (bFirst)bFirst = FALSE;
- else
- swText += FWL_VKEY_Return;
- swText += swSection;
- }
- }
- }
-
- delete pXML;
- }
- }
-
- m_pEdit->SetText(swText);
-}
-
-void CPWL_Edit::RePosChildWnd()
-{
- if (CPWL_ScrollBar * pVSB = this->GetVScrollBar())
- {
- //if (pVSB->IsVisible())
- {
- CPDF_Rect rcWindow = m_rcOldWindow;
- CPDF_Rect rcVScroll = CPDF_Rect(rcWindow.right,
- rcWindow.bottom,
- rcWindow.right + PWL_SCROLLBAR_WIDTH,
- rcWindow.top);
- pVSB->Move(rcVScroll, TRUE, FALSE);
- }
- }
-
- if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
- m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(GetClientRect(),1.0f)); //+1 for caret beside border
-
- CPWL_EditCtrl::RePosChildWnd();
-}
-
-CPDF_Rect CPWL_Edit::GetClientRect() const
-{
- CPDF_Rect rcClient = CPWL_Utils::DeflateRect(GetWindowRect(),(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
-
- if (CPWL_ScrollBar * pVSB = this->GetVScrollBar())
- {
- if (pVSB->IsVisible())
- {
- rcClient.right -= PWL_SCROLLBAR_WIDTH;
- }
- }
-
- return rcClient;
-}
-
-void CPWL_Edit::SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pEdit->SetAlignmentH((FX_INT32)nFormat, bPaint);
-}
-
-void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pEdit->SetAlignmentV((FX_INT32)nFormat, bPaint);
-}
-
-FX_BOOL CPWL_Edit::CanSelectAll() const
-{
- return GetSelectWordRange() != m_pEdit->GetWholeWordRange();
-}
-
-FX_BOOL CPWL_Edit::CanClear() const
-{
- return !IsReadOnly() && m_pEdit->IsSelected();
-}
-
-FX_BOOL CPWL_Edit::CanCopy() const
-{
- return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && m_pEdit->IsSelected();
-}
-
-FX_BOOL CPWL_Edit::CanCut() const
-{
- return CanCopy() && !IsReadOnly();
-}
-
-FX_BOOL CPWL_Edit::CanPaste() const
-{
- if (IsReadOnly()) return FALSE;
-
- CFX_WideString swClipboard;
- if (IFX_SystemHandler* pSH = GetSystemHandler())
- swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
-
- return !swClipboard.IsEmpty();
-}
-
-void CPWL_Edit::CopyText()
-{
- if (!CanCopy()) return;
-
- CFX_WideString str = m_pEdit->GetSelText();
-
- if (IFX_SystemHandler* pSH = GetSystemHandler())
- pSH->SetClipboardText(GetAttachedHWnd(), str);
-}
-
-void CPWL_Edit::PasteText()
-{
- if (!CanPaste()) return;
-
- CFX_WideString swClipboard;
- if (IFX_SystemHandler* pSH = GetSystemHandler())
- swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
-
- if (m_pFillerNotify)
- {
- FX_BOOL bRC = TRUE;
- FX_BOOL bExit = FALSE;
- CFX_WideString strChangeEx;
- int nSelStart = 0;
- int nSelEnd = 0;
- GetSel(nSelStart, nSelEnd);
- m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), 0 , swClipboard, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, 0);
- if (!bRC) return;
- if (bExit) return;
- }
-
- if (swClipboard.GetLength() > 0)
- {
- Clear();
- InsertText(swClipboard);
- }
-
- if (m_pFillerNotify)
- {
- FX_BOOL bExit = FALSE;
- m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit,0);
- if (bExit) return;
- }
-}
-
-void CPWL_Edit::CutText()
-{
- if (!CanCut()) return;
-
- CFX_WideString str = m_pEdit->GetSelText();
-
- if (IFX_SystemHandler* pSH = GetSystemHandler())
- pSH->SetClipboardText(GetAttachedHWnd(), str);
-
- m_pEdit->Clear();
-}
-
-void CPWL_Edit::OnCreated()
-{
- CPWL_EditCtrl::OnCreated();
-
- if (CPWL_ScrollBar * pScroll = GetVScrollBar())
- {
- pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
- pScroll->SetTransparency(255);
- }
-
- SetParamByFlag();
-
- m_rcOldWindow = GetWindowRect();
-
- m_pEdit->SetOprNotify(this);
- m_pEdit->EnableOprNotify(TRUE);
-}
-
-void CPWL_Edit::SetParamByFlag()
-{
- if (HasFlag(PES_RIGHT))
- {
- m_pEdit->SetAlignmentH(2, FALSE);
- }
- else if (HasFlag(PES_MIDDLE))
- {
- m_pEdit->SetAlignmentH(1, FALSE);
- }
- else
- {
- m_pEdit->SetAlignmentH(0, FALSE);
- }
-
- if (HasFlag(PES_BOTTOM))
- {
- m_pEdit->SetAlignmentV(2, FALSE);
- }
- else if (HasFlag(PES_CENTER))
- {
- m_pEdit->SetAlignmentV(1, FALSE);
- }
- else
- {
- m_pEdit->SetAlignmentV(0, FALSE);
- }
-
- if (HasFlag(PES_PASSWORD))
- {
- m_pEdit->SetPasswordChar('*', FALSE);
- }
-
- m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), FALSE);
- m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), FALSE);
- m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), FALSE);
- m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), FALSE);
- m_pEdit->EnableUndo(HasFlag(PES_UNDO));
-
- if (HasFlag(PES_TEXTOVERFLOW))
- {
- SetClipRect(CPDF_Rect(0.0f,0.0f,0.0f,0.0f));
- m_pEdit->SetTextOverflow(TRUE, FALSE);
- }
- else
- {
- if (m_pEditCaret)
- {
- m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(GetClientRect(),1.0f)); //+1 for caret beside border
- }
- }
-
- if (HasFlag(PES_SPELLCHECK))
- {
- m_pSpellCheck = GetCreationParam().pSpellCheck;
- }
-}
-
-void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- CPWL_Wnd::GetThisAppearanceStream(sAppStream);
-
- CPDF_Rect rcClient = GetClientRect();
- CFX_ByteTextBuf sLine;
-
- FX_INT32 nCharArray = m_pEdit->GetCharArray();
-
- if (nCharArray > 0)
- {
- switch (GetBorderStyle())
- {
- case PBS_SOLID:
- {
- sLine << "q\n" << GetBorderWidth() << " w\n"
- << CPWL_Utils::GetColorAppStream(GetBorderColor(),FALSE) << " 2 J 0 j\n";
-
- for (FX_INT32 i=1;i<nCharArray;i++)
- {
- sLine << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
- << rcClient.bottom << " m\n"
- << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
- << rcClient.top << " l S\n";
- }
-
- sLine << "Q\n";
- }
- break;
- case PBS_DASH:
- {
- sLine << "q\n" << GetBorderWidth() << " w\n"
- << CPWL_Utils::GetColorAppStream(GetBorderColor(),FALSE) << " 2 J 0 j\n"
- << "[" << GetBorderDash().nDash << " "
- << GetBorderDash().nGap << "] "
- << GetBorderDash().nPhase << " d\n";
-
- for (FX_INT32 i=1;i<nCharArray;i++)
- {
- sLine << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
- << rcClient.bottom << " m\n"
- << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
- << rcClient.top << " l S\n";
- }
-
- sLine << "Q\n";
- }
- break;
- }
- }
-
- sAppStream << sLine;
-
- CFX_ByteTextBuf sText;
-
- CPDF_Point ptOffset = CPDF_Point(0.0f,0.0f);
-
- CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
- CPVT_WordRange wrSelect = GetSelectWordRange();
- CPVT_WordRange wrVisible = (HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange());
- CPVT_WordRange wrSelBefore(wrWhole.BeginPos,wrSelect.BeginPos);
- CPVT_WordRange wrSelAfter(wrSelect.EndPos,wrWhole.EndPos);
-
- CPVT_WordRange wrTemp = CPWL_Utils::OverlapWordRange(GetSelectWordRange(),wrVisible);
- CFX_ByteString sEditSel = CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset,
- &wrTemp);
-
- if (sEditSel.GetLength() > 0)
- sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR) << sEditSel ;
-
- wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelBefore);
- CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset,
- &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordChar());
-
- if (sEditBefore.GetLength() > 0)
- sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEditBefore << "ET\n";
-
- wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelect);
- CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset,
- &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordChar());
-
- if (sEditMid.GetLength() > 0)
- sText << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY,1)) << sEditMid << "ET\n";
-
- wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelAfter);
- CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset,
- &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordChar());
-
- if (sEditAfter.GetLength() > 0)
- sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEditAfter<< "ET\n";
-
- if (HasFlag(PES_SPELLCHECK))
- {
- CFX_ByteString sSpellCheck = CPWL_Utils::GetSpellCheckAppStream(m_pEdit, m_pSpellCheck, ptOffset, &wrVisible);
- if (sSpellCheck.GetLength() > 0)
- sText << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,1,0,0),FALSE) << sSpellCheck;
- }
-
- if (sText.GetLength() > 0)
- {
- CPDF_Rect rcClient = this->GetClientRect();
- sAppStream << "q\n/Tx BMC\n";
-
- if (!HasFlag(PES_TEXTOVERFLOW))
- sAppStream << rcClient.left << " " << rcClient.bottom << " "
- << rcClient.right - rcClient.left << " " << rcClient.top - rcClient.bottom << " re W n\n";
-
- sAppStream << sText;
-
- sAppStream << "EMC\nQ\n";
- }
-}
-
-void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
-
- CPDF_Rect rcClient = GetClientRect();
- CFX_ByteTextBuf sLine;
-
- FX_INT32 nCharArray = m_pEdit->GetCharArray();
-
- if (nCharArray > 0)
- {
- switch (GetBorderStyle())
- {
- case PBS_SOLID:
- {
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
-
- CFX_PathData path;
- path.SetPointCount((nCharArray-1)*2);
-
- for (FX_INT32 i=0; i<nCharArray-1; i++)
- {
- path.SetPoint(i*2, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
- rcClient.bottom, FXPT_MOVETO);
- path.SetPoint(i*2+1, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
- rcClient.top, FXPT_LINETO);
- }
- if (path.GetPointCount() > 0)
- pDevice->DrawPath(&path, pUser2Device, &gsd,0,
- CPWL_Utils::PWLColorToFXColor(GetBorderColor(),255), FXFILL_ALTERNATE);
- }
- break;
- case PBS_DASH:
- {
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
-
- gsd.SetDashCount(2);
- gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash;
- gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap;
- gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase;
-
- CFX_PathData path;
- path.SetPointCount((nCharArray-1)*2);
-
- for (FX_INT32 i=0; i<nCharArray-1; i++)
- {
- path.SetPoint(i*2, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
- rcClient.bottom, FXPT_MOVETO);
- path.SetPoint(i*2+1, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
- rcClient.top, FXPT_LINETO);
- }
- if (path.GetPointCount() > 0)
- pDevice->DrawPath(&path, pUser2Device, &gsd,0,
- CPWL_Utils::PWLColorToFXColor(GetBorderColor(),255), FXFILL_ALTERNATE);
- }
- break;
- }
- }
-
- CPDF_Rect rcClip;
- CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
- CPVT_WordRange* pRange = NULL;
-
- if (!HasFlag(PES_TEXTOVERFLOW))
- {
- rcClip = GetClientRect();
- pRange = &wrRange;
- }
-IFX_SystemHandler* pSysHandler = GetSystemHandler();
- IFX_Edit::DrawEdit(pDevice,pUser2Device,m_pEdit,
- CPWL_Utils::PWLColorToFXColor(GetTextColor(),this->GetTransparency()),
- CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(),this->GetTransparency()),
- rcClip,CPDF_Point(0.0f,0.0f),pRange, pSysHandler, m_pFormFiller);
-
- if (HasFlag(PES_SPELLCHECK))
- {
- CPWL_Utils::DrawEditSpellCheck(pDevice,pUser2Device,m_pEdit,rcClip,
- CPDF_Point(0.0f,0.0f),pRange, this->GetCreationParam().pSpellCheck);
- }
-}
-
-FX_BOOL CPWL_Edit::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonDown(point,nFlag);
-
- if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point))
- {
- if (m_bMouseDown)
- this->InvalidateRect();
-
- m_bMouseDown = TRUE;
- SetCapture();
-
- m_pEdit->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- }
-
- return TRUE;
-}
-
-FX_BOOL CPWL_Edit::OnLButtonDblClk(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonDblClk(point, nFlag);
-
- if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point))
- {
- m_pEdit->SelectAll();
- }
-
- return TRUE;
-}
-
-#define WM_PWLEDIT_UNDO 0x01
-#define WM_PWLEDIT_REDO 0x02
-#define WM_PWLEDIT_CUT 0x03
-#define WM_PWLEDIT_COPY 0x04
-#define WM_PWLEDIT_PASTE 0x05
-#define WM_PWLEDIT_DELETE 0x06
-#define WM_PWLEDIT_SELECTALL 0x07
-#define WM_PWLEDIT_SUGGEST 0x08
-
-FX_BOOL CPWL_Edit::OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- if (m_bMouseDown) return FALSE;
-
- CPWL_Wnd::OnRButtonUp(point, nFlag);
-
- if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) return TRUE;
-
- IFX_SystemHandler* pSH = GetSystemHandler();
- if (!pSH) return FALSE;
-
- this->SetFocus();
-
- CPVT_WordRange wrLatin = GetLatinWordsRange(point);
- CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin);
-
- FX_HMENU hPopup = pSH->CreatePopupMenu();
- if (!hPopup) return FALSE;
-
- CFX_ByteStringArray sSuggestWords;
- CPDF_Point ptPopup = point;
-
- if (!IsReadOnly())
- {
- if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty())
- {
- if (m_pSpellCheck)
- {
- CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin);
-
- if (!m_pSpellCheck->CheckWord(sLatin))
- {
- m_pSpellCheck->SuggestWords(sLatin,sSuggestWords);
-
- FX_INT32 nSuggest = sSuggestWords.GetSize();
-
- for (FX_INT32 nWord=0; nWord<nSuggest; nWord++)
- {
- pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST+nWord, sSuggestWords[nWord].UTF8Decode());
- }
-
- if (nSuggest > 0)
- pSH->AppendMenuItem(hPopup, 0, L"");
-
- ptPopup = GetWordRightBottomPoint(wrLatin.EndPos);
- }
- }
- }
- }
-
- IPWL_Provider* pProvider = this->GetProvider();
-
- if (HasFlag(PES_UNDO))
- {
- pSH->AppendMenuItem(hPopup, WM_PWLEDIT_UNDO,
- pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo");
- pSH->AppendMenuItem(hPopup, WM_PWLEDIT_REDO,
- pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo");
- pSH->AppendMenuItem(hPopup, 0, L"");
-
- if (!m_pEdit->CanUndo())
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE);
- if (!m_pEdit->CanRedo())
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE);
- }
-
- pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT,
- pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t");
- pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY,
- pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy");
- pSH->AppendMenuItem(hPopup, WM_PWLEDIT_PASTE,
- pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste");
- pSH->AppendMenuItem(hPopup, WM_PWLEDIT_DELETE,
- pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete");
-
- CFX_WideString swText = pSH->GetClipboardText(this->GetAttachedHWnd());
- if (swText.IsEmpty())
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
-
- if (!m_pEdit->IsSelected())
- {
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
- }
-
- if (IsReadOnly())
- {
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
- }
-
- if (HasFlag(PES_PASSWORD))
- {
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
- }
-
- if (HasFlag(PES_NOREAD))
- {
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
- }
-
- pSH->AppendMenuItem(hPopup, 0, L"");
- pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SELECTALL,
- pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All");
-
- if (m_pEdit->GetTotalWords() == 0)
- {
- pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE);
- }
-
- FX_INT32 x, y;
- PWLtoWnd(ptPopup, x, y);
- pSH->ClientToScreen(GetAttachedHWnd(), x, y);
- pSH->SetCursor(FXCT_ARROW);
- FX_INT32 nCmd = pSH->TrackPopupMenu(hPopup,
- x,
- y,
- GetAttachedHWnd());
-
-
- switch (nCmd)
- {
- case WM_PWLEDIT_UNDO:
- Undo();
- break;
- case WM_PWLEDIT_REDO:
- Redo();
- break;
- case WM_PWLEDIT_CUT:
- this->CutText();
- break;
- case WM_PWLEDIT_COPY:
- this->CopyText();
- break;
- case WM_PWLEDIT_PASTE:
- this->PasteText();
- break;
- case WM_PWLEDIT_DELETE:
- this->Clear();
- break;
- case WM_PWLEDIT_SELECTALL:
- this->SelectAll();
- break;
- case WM_PWLEDIT_SUGGEST + 0:
- SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
- ReplaceSel(sSuggestWords[0].UTF8Decode());
- break;
- case WM_PWLEDIT_SUGGEST + 1:
- SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
- ReplaceSel(sSuggestWords[1].UTF8Decode());
- break;
- case WM_PWLEDIT_SUGGEST + 2:
- SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
- ReplaceSel(sSuggestWords[2].UTF8Decode());
- break;
- case WM_PWLEDIT_SUGGEST + 3:
- SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
- ReplaceSel(sSuggestWords[3].UTF8Decode());
- break;
- case WM_PWLEDIT_SUGGEST + 4:
- SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
- ReplaceSel(sSuggestWords[4].UTF8Decode());
- break;
- default:
- break;
- }
-
- pSH->DestroyMenu(hPopup);
-
- return TRUE;
-}
-
-void CPWL_Edit::OnSetFocus()
-{
- SetEditCaret(TRUE);
-
- if (!IsReadOnly())
- {
- if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
- pFocusHandler->OnSetFocus(this);
- }
-
- m_bFocus = TRUE;
-}
-
-void CPWL_Edit::OnKillFocus()
-{
- ShowVScrollBar(FALSE);
-
- m_pEdit->SelectNone();
- SetCaret(FALSE, CPDF_Point(0.0f,0.0f), CPDF_Point(0.0f,0.0f));
-
- SetCharSet(0);
-
- if (!IsReadOnly())
- {
- if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
- pFocusHandler->OnKillFocus(this);
- }
-
- m_bFocus = FALSE;
-}
-
-void CPWL_Edit::SetHorzScale(FX_INT32 nHorzScale, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pEdit->SetHorzScale(nHorzScale, bPaint);
-}
-
-void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pEdit->SetCharSpace(fCharSpace, bPaint);
-}
-
-void CPWL_Edit::SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint/* = TRUE*/)
-{
- m_pEdit->SetLineLeading(fLineLeading, bPaint);
-}
-
-CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(const CPDF_Point & ptOffset) const
-{
- CPVT_WordRange wr = GetSelectWordRange();
- return CPWL_Utils::GetEditSelAppStream(m_pEdit,ptOffset,&wr);
-}
-
-CPVT_WordRange CPWL_Edit::GetSelectWordRange() const
-{
- if (m_pEdit->IsSelected())
- {
- FX_INT32 nStart = -1;
- FX_INT32 nEnd = -1;
-
- m_pEdit->GetSel(nStart, nEnd);
-
- CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
- CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
-
- return CPVT_WordRange(wpStart,wpEnd);
- }
-
- return CPVT_WordRange();
-}
-
-CFX_ByteString CPWL_Edit::GetTextAppearanceStream(const CPDF_Point & ptOffset) const
-{
- CFX_ByteTextBuf sRet;
- CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit,ptOffset);
-
- if (sEdit.GetLength() > 0)
- {
- sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEdit << "ET\n";
- }
-
- return sRet.GetByteString();
-}
-
-CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(const CPDF_Point & ptOffset) const
-{
- if (m_pEditCaret)
- return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
-
- return CFX_ByteString();
-}
-
-CPDF_Point CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord)
-{
- CPDF_Point pt(0.0f, 0.0f);
-
- if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
- {
- CPVT_WordPlace wpOld = pIterator->GetAt();
- pIterator->SetAt(wpWord);
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- pt = CPDF_Point(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
- }
-
- pIterator->SetAt(wpOld);
- }
-
- return pt;
-}
-
-FX_BOOL CPWL_Edit::IsTextFull() const
-{
- return m_pEdit->IsTextFull();
-}
-
-FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, const CPDF_Rect& rcPlate, FX_INT32 nCharArray)
-{
- if (pFont && !pFont->IsStandardFont())
- {
- FX_RECT rcBBox;
- pFont->GetFontBBox(rcBBox);
-
- CPDF_Rect rcCell = rcPlate;
- FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
- FX_FLOAT ydiv = - rcCell.Height() * 1000.0f / rcBBox.Height();
-
- return xdiv < ydiv ? xdiv : ydiv;
- }
-
- return 0.0f;
-}
-
-void CPWL_Edit::SetCharArray(FX_INT32 nCharArray)
-{
- if (HasFlag(PES_CHARARRAY) && nCharArray > 0)
- {
- m_pEdit->SetCharArray(nCharArray);
- m_pEdit->SetTextOverflow(TRUE);
-
- if (HasFlag(PWS_AUTOFONTSIZE))
- {
- if (IFX_Edit_FontMap* pFontMap = this->GetFontMap())
- {
- FX_FLOAT fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0), GetClientRect(), nCharArray);
- if (fFontSize > 0.0f)
- {
- m_pEdit->SetAutoFontSize(FALSE);
- m_pEdit->SetFontSize(fFontSize);
- }
- }
- }
- }
-}
-
-void CPWL_Edit::SetLimitChar(FX_INT32 nLimitChar)
-{
- m_pEdit->SetLimitChar(nLimitChar);
-}
-
-void CPWL_Edit::ReplaceSel(FX_LPCWSTR csText)
-{
- m_pEdit->Clear();
- m_pEdit->InsertText(csText);
-}
-
-CPDF_Rect CPWL_Edit::GetFocusRect() const
-{
- return CPDF_Rect();
-}
-
-void CPWL_Edit::ShowVScrollBar(FX_BOOL bShow)
-{
- if (CPWL_ScrollBar * pScroll = GetVScrollBar())
- {
- if (bShow)
- {
- if (!pScroll->IsVisible())
- {
- pScroll->SetVisible(TRUE);
- CPDF_Rect rcWindow = GetWindowRect();
- m_rcOldWindow = rcWindow;
- rcWindow.right += PWL_SCROLLBAR_WIDTH;
- Move(rcWindow, TRUE, TRUE);
- }
- }
- else
- {
- if (pScroll->IsVisible())
- {
- pScroll->SetVisible(FALSE);
- Move(m_rcOldWindow, TRUE, TRUE);
- }
- }
- }
-}
-
-FX_BOOL CPWL_Edit::IsVScrollBarVisible() const
-{
- if (CPWL_ScrollBar * pScroll = GetVScrollBar())
- {
- return pScroll->IsVisible();
- }
-
- return FALSE;
-}
-
-void CPWL_Edit::EnableSpellCheck(FX_BOOL bEnabled)
-{
- if (bEnabled)
- AddFlag(PES_SPELLCHECK);
- else
- RemoveFlag(PES_SPELLCHECK);
-}
-
-FX_BOOL CPWL_Edit::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
-{
- if (m_bMouseDown) return TRUE;
-
- if (nChar == FWL_VKEY_Delete)
- {
- if (m_pFillerNotify)
- {
- FX_BOOL bRC = TRUE;
- FX_BOOL bExit = FALSE;
- CFX_WideString strChange;
- CFX_WideString strChangeEx;
-
- int nSelStart = 0;
- int nSelEnd = 0;
- GetSel(nSelStart, nSelEnd);
-
- if (nSelStart == nSelEnd)
- nSelEnd = nSelStart + 1;
- m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), FWL_VKEY_Delete, strChange, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, nFlag);
- if (!bRC) return FALSE;
- if (bExit) return FALSE;
- }
- }
-
- FX_BOOL bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
-
- if (nChar == FWL_VKEY_Delete)
- {
- if (m_pFillerNotify)
- {
- FX_BOOL bExit = FALSE;
- m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit,nFlag);
- if (bExit) return FALSE;
- }
- }
-
- //In case of implementation swallow the OnKeyDown event.
- if(IsProceedtoOnChar(nChar, nFlag))
- return TRUE;
-
- return bRet;
-}
-
-/**
-*In case of implementation swallow the OnKeyDown event.
-*If the event is swallowed, implementation may do other unexpected things, which is not the control means to do.
-*/
-FX_BOOL CPWL_Edit::IsProceedtoOnChar(FX_WORD nKeyCode, FX_DWORD nFlag)
-{
-
- FX_BOOL bCtrl = IsCTRLpressed(nFlag);
- FX_BOOL bAlt = IsALTpressed(nFlag);
- if(bCtrl && !bAlt)
- {
- //hot keys for edit control.
- switch(nKeyCode)
- {
- case 'C':
- case 'V':
- case 'X':
- case 'A':
- case 'Z':
- return TRUE;
- default:
- break;
- }
- }
- //control characters.
- switch(nKeyCode)
- {
- case FWL_VKEY_Escape:
- case FWL_VKEY_Back:
- case FWL_VKEY_Return:
- case FWL_VKEY_Space:
- return TRUE;
- default:
- break;
- }
- return FALSE;
-
-}
-
-FX_BOOL CPWL_Edit::OnChar(FX_WORD nChar, FX_DWORD nFlag)
-{
- if (m_bMouseDown) return TRUE;
-
- FX_BOOL bRC = TRUE;
- FX_BOOL bExit = FALSE;
-
- FX_BOOL bCtrl = IsCTRLpressed(nFlag);
- if (!bCtrl)
- {
- if (m_pFillerNotify)
- {
- CFX_WideString swChange;
- FX_INT32 nKeyCode;
-
- int nSelStart = 0;
- int nSelEnd = 0;
- GetSel(nSelStart, nSelEnd);
-
- switch (nChar)
- {
- case FWL_VKEY_Back:
- nKeyCode = nChar;
- if (nSelStart == nSelEnd)
- nSelStart = nSelEnd - 1;
- break;
- case FWL_VKEY_Return:
- nKeyCode = nChar;
- break;
- default:
- nKeyCode = 0;
- swChange += nChar;
- break;
- }
-
- CFX_WideString strChangeEx;
- m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), nKeyCode, swChange, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, nFlag);
- }
- }
-
- if (!bRC) return TRUE;
- if (bExit) return FALSE;
-
- if (IFX_Edit_FontMap * pFontMap = GetFontMap())
- {
- FX_INT32 nOldCharSet = GetCharSet();
- FX_INT32 nNewCharSet = pFontMap->CharSetFromUnicode(nChar, DEFAULT_CHARSET);
- if(nOldCharSet != nNewCharSet)
- {
- SetCharSet(nNewCharSet);
- }
- }
- FX_BOOL bRet = CPWL_EditCtrl::OnChar(nChar,nFlag);
-
- if (!bCtrl)
- {
- if (m_pFillerNotify)
- {
- m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit,nFlag);
- if (bExit) return FALSE;
- }
- }
-
- return bRet;
-}
-
-FX_BOOL CPWL_Edit::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag)
-{
- if (HasFlag(PES_MULTILINE))
- {
- CPDF_Point ptScroll = GetScrollPos();
-
- if (zDelta > 0)
- {
- ptScroll.y += this->GetFontSize();
- }
- else
- {
- ptScroll.y -= this->GetFontSize();
- }
- this->SetScrollPos(ptScroll);
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
-{
- if (HasFlag(PES_SPELLCHECK))
- {
- m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
- }
-
- if (m_pEditNotify)
- {
- m_pEditNotify->OnInsertReturn(place, oldplace);
- }
-}
-
-void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
-{
- if (HasFlag(PES_SPELLCHECK))
- {
- m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
- }
-
- if (m_pEditNotify)
- {
- m_pEditNotify->OnBackSpace(place, oldplace);
- }
-}
-
-void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
-{
- if (HasFlag(PES_SPELLCHECK))
- {
- m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
- }
-
- if (m_pEditNotify)
- {
- m_pEditNotify->OnDelete(place, oldplace);
- }
-}
-
-void CPWL_Edit::OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
-{
- if (HasFlag(PES_SPELLCHECK))
- {
- m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
- }
-
- if (m_pEditNotify)
- {
- m_pEditNotify->OnClear(place, oldplace);
- }
-}
-
-void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
-{
- if (HasFlag(PES_SPELLCHECK))
- {
- m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
- }
-
- if (m_pEditNotify)
- {
- m_pEditNotify->OnInsertWord(place, oldplace);
- }
-}
-
-void CPWL_Edit::OnSetText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
-{
-}
-
-void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
-{
- if (HasFlag(PES_SPELLCHECK))
- {
- m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
- }
-
- if (m_pEditNotify)
- {
- m_pEditNotify->OnInsertText(place, oldplace);
- }
-}
-
-void CPWL_Edit::OnAddUndo(IFX_Edit_UndoItem* pUndoItem)
-{
- if (m_pEditNotify)
- {
- m_pEditNotify->OnAddUndo(this);
- }
-}
-
-CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, const CPVT_WordRange& wr2)
-{
- CPVT_WordRange wrRet;
-
- if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0)
- {
- wrRet.BeginPos = wr1.BeginPos;
- }
- else
- {
- wrRet.BeginPos = wr2.BeginPos;
- }
-
- if (wr1.EndPos.WordCmp(wr2.EndPos) < 0)
- {
- wrRet.EndPos = wr2.EndPos;
- }
- else
- {
- wrRet.EndPos = wr1.EndPos;
- }
-
- return wrRet;
-}
-
-CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CPDF_Point& point) const
-{
- return GetSameWordsRange(m_pEdit->SearchWordPlace(point), TRUE, FALSE);
-}
-
-CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CPVT_WordPlace & place) const
-{
- return GetSameWordsRange(place, TRUE, FALSE);
-}
-
-CPVT_WordRange CPWL_Edit::GetArabicWordsRange(const CPVT_WordPlace & place) const
-{
- return GetSameWordsRange(place, FALSE, TRUE);
-}
-
-#define PWL_ISARABICWORD(word) ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
-
-CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace & place, FX_BOOL bLatin, FX_BOOL bArabic) const
-{
- CPVT_WordRange range;
-
- if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator())
- {
- CPVT_Word wordinfo;
- CPVT_WordPlace wpStart(place),wpEnd(place);
- pIterator->SetAt(place);
-
- if (bLatin)
- {
- while (pIterator->NextWord())
- {
- if (pIterator->GetWord(wordinfo) && FX_EDIT_ISLATINWORD(wordinfo.Word))
- {
- wpEnd = pIterator->GetAt();
- continue;
- }
- else
- break;
- };
- }
- else if (bArabic)
- {
- while (pIterator->NextWord())
- {
- if (pIterator->GetWord(wordinfo) && PWL_ISARABICWORD(wordinfo.Word))
- {
- wpEnd = pIterator->GetAt();
- continue;
- }
- else
- break;
- };
- }
-
- pIterator->SetAt(place);
-
- if (bLatin)
- {
- do
- {
- if (pIterator->GetWord(wordinfo) && FX_EDIT_ISLATINWORD(wordinfo.Word))
- {
- continue;
- }
- else
- {
- wpStart = pIterator->GetAt();
- break;
- }
- }
- while (pIterator->PrevWord());
- }
- else if (bArabic)
- {
- do
- {
- if (pIterator->GetWord(wordinfo) && PWL_ISARABICWORD(wordinfo.Word))
- {
- continue;
- }
- else
- {
- wpStart = pIterator->GetAt();
- break;
- }
- }
- while (pIterator->PrevWord());
- }
-
- range.Set(wpStart,wpEnd);
- }
-
- return range;
-}
-
-void CPWL_Edit::AjustArabicWords(const CPVT_WordRange& wr)
-{
-}
-
-void CPWL_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects,
- const CPDF_Point& ptOffset, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray)
-{
- IFX_Edit::GeneratePageObjects(pPageObjects, m_pEdit, ptOffset, NULL, CPWL_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()), ObjArray);
-}
-
-void CPWL_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects,
- const CPDF_Point& ptOffset)
-{
- CFX_ArrayTemplate<CPDF_TextObject*> ObjArray;
- IFX_Edit::GeneratePageObjects(pPageObjects, m_pEdit, ptOffset, NULL, CPWL_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()), ObjArray);
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_EditCtrl.h"
+#include "../../include/pdfwindow/PWL_Edit.h"
+#include "../../include/pdfwindow/PWL_ScrollBar.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+#include "../../include/pdfwindow/PWL_Caret.h"
+#include "../../include/pdfwindow/PWL_FontMap.h"
+
+/* ---------------------------- CPWL_Edit ------------------------------ */
+
+CPWL_Edit::CPWL_Edit() : m_pFillerNotify(NULL),
+ m_pSpellCheck(NULL),
+ m_bFocus(FALSE)
+{
+ m_pFormFiller = NULL;
+}
+
+CPWL_Edit::~CPWL_Edit()
+{
+ ASSERT(m_bFocus == FALSE);
+}
+
+CFX_ByteString CPWL_Edit::GetClassName() const
+{
+ return PWL_CLASSNAME_EDIT;
+}
+
+void CPWL_Edit::OnDestroy()
+{
+}
+
+void CPWL_Edit::SetText(FX_LPCWSTR csText)
+{
+ CFX_WideString swText = csText;
+
+ if (HasFlag(PES_RICH))
+ {
+ CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText);
+
+ if (CXML_Element * pXML = CXML_Element::Parse((FX_LPCSTR)sValue,sValue.GetLength()))
+ {
+ FX_INT32 nCount = pXML->CountChildren();
+ FX_BOOL bFirst = TRUE;
+
+ swText.Empty();
+
+ for (FX_INT32 i=0; i<nCount; i++)
+ {
+ if (CXML_Element * pSubElement = pXML->GetElement(i))
+ {
+ CFX_ByteString tag=pSubElement->GetTagName();
+ if (tag.EqualNoCase("p"))
+ {
+ int nChild = pSubElement->CountChildren();
+ CFX_WideString swSection;
+ for(FX_INT32 j=0; j<nChild; j++)
+ {
+ swSection += pSubElement->GetContent(j);
+ }
+
+ if (bFirst)bFirst = FALSE;
+ else
+ swText += FWL_VKEY_Return;
+ swText += swSection;
+ }
+ }
+ }
+
+ delete pXML;
+ }
+ }
+
+ m_pEdit->SetText(swText);
+}
+
+void CPWL_Edit::RePosChildWnd()
+{
+ if (CPWL_ScrollBar * pVSB = this->GetVScrollBar())
+ {
+ //if (pVSB->IsVisible())
+ {
+ CPDF_Rect rcWindow = m_rcOldWindow;
+ CPDF_Rect rcVScroll = CPDF_Rect(rcWindow.right,
+ rcWindow.bottom,
+ rcWindow.right + PWL_SCROLLBAR_WIDTH,
+ rcWindow.top);
+ pVSB->Move(rcVScroll, TRUE, FALSE);
+ }
+ }
+
+ if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
+ m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(GetClientRect(),1.0f)); //+1 for caret beside border
+
+ CPWL_EditCtrl::RePosChildWnd();
+}
+
+CPDF_Rect CPWL_Edit::GetClientRect() const
+{
+ CPDF_Rect rcClient = CPWL_Utils::DeflateRect(GetWindowRect(),(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
+
+ if (CPWL_ScrollBar * pVSB = this->GetVScrollBar())
+ {
+ if (pVSB->IsVisible())
+ {
+ rcClient.right -= PWL_SCROLLBAR_WIDTH;
+ }
+ }
+
+ return rcClient;
+}
+
+void CPWL_Edit::SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pEdit->SetAlignmentH((FX_INT32)nFormat, bPaint);
+}
+
+void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pEdit->SetAlignmentV((FX_INT32)nFormat, bPaint);
+}
+
+FX_BOOL CPWL_Edit::CanSelectAll() const
+{
+ return GetSelectWordRange() != m_pEdit->GetWholeWordRange();
+}
+
+FX_BOOL CPWL_Edit::CanClear() const
+{
+ return !IsReadOnly() && m_pEdit->IsSelected();
+}
+
+FX_BOOL CPWL_Edit::CanCopy() const
+{
+ return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && m_pEdit->IsSelected();
+}
+
+FX_BOOL CPWL_Edit::CanCut() const
+{
+ return CanCopy() && !IsReadOnly();
+}
+
+FX_BOOL CPWL_Edit::CanPaste() const
+{
+ if (IsReadOnly()) return FALSE;
+
+ CFX_WideString swClipboard;
+ if (IFX_SystemHandler* pSH = GetSystemHandler())
+ swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
+
+ return !swClipboard.IsEmpty();
+}
+
+void CPWL_Edit::CopyText()
+{
+ if (!CanCopy()) return;
+
+ CFX_WideString str = m_pEdit->GetSelText();
+
+ if (IFX_SystemHandler* pSH = GetSystemHandler())
+ pSH->SetClipboardText(GetAttachedHWnd(), str);
+}
+
+void CPWL_Edit::PasteText()
+{
+ if (!CanPaste()) return;
+
+ CFX_WideString swClipboard;
+ if (IFX_SystemHandler* pSH = GetSystemHandler())
+ swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
+
+ if (m_pFillerNotify)
+ {
+ FX_BOOL bRC = TRUE;
+ FX_BOOL bExit = FALSE;
+ CFX_WideString strChangeEx;
+ int nSelStart = 0;
+ int nSelEnd = 0;
+ GetSel(nSelStart, nSelEnd);
+ m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), 0 , swClipboard, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, 0);
+ if (!bRC) return;
+ if (bExit) return;
+ }
+
+ if (swClipboard.GetLength() > 0)
+ {
+ Clear();
+ InsertText(swClipboard);
+ }
+
+ if (m_pFillerNotify)
+ {
+ FX_BOOL bExit = FALSE;
+ m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit,0);
+ if (bExit) return;
+ }
+}
+
+void CPWL_Edit::CutText()
+{
+ if (!CanCut()) return;
+
+ CFX_WideString str = m_pEdit->GetSelText();
+
+ if (IFX_SystemHandler* pSH = GetSystemHandler())
+ pSH->SetClipboardText(GetAttachedHWnd(), str);
+
+ m_pEdit->Clear();
+}
+
+void CPWL_Edit::OnCreated()
+{
+ CPWL_EditCtrl::OnCreated();
+
+ if (CPWL_ScrollBar * pScroll = GetVScrollBar())
+ {
+ pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
+ pScroll->SetTransparency(255);
+ }
+
+ SetParamByFlag();
+
+ m_rcOldWindow = GetWindowRect();
+
+ m_pEdit->SetOprNotify(this);
+ m_pEdit->EnableOprNotify(TRUE);
+}
+
+void CPWL_Edit::SetParamByFlag()
+{
+ if (HasFlag(PES_RIGHT))
+ {
+ m_pEdit->SetAlignmentH(2, FALSE);
+ }
+ else if (HasFlag(PES_MIDDLE))
+ {
+ m_pEdit->SetAlignmentH(1, FALSE);
+ }
+ else
+ {
+ m_pEdit->SetAlignmentH(0, FALSE);
+ }
+
+ if (HasFlag(PES_BOTTOM))
+ {
+ m_pEdit->SetAlignmentV(2, FALSE);
+ }
+ else if (HasFlag(PES_CENTER))
+ {
+ m_pEdit->SetAlignmentV(1, FALSE);
+ }
+ else
+ {
+ m_pEdit->SetAlignmentV(0, FALSE);
+ }
+
+ if (HasFlag(PES_PASSWORD))
+ {
+ m_pEdit->SetPasswordChar('*', FALSE);
+ }
+
+ m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), FALSE);
+ m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), FALSE);
+ m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), FALSE);
+ m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), FALSE);
+ m_pEdit->EnableUndo(HasFlag(PES_UNDO));
+
+ if (HasFlag(PES_TEXTOVERFLOW))
+ {
+ SetClipRect(CPDF_Rect(0.0f,0.0f,0.0f,0.0f));
+ m_pEdit->SetTextOverflow(TRUE, FALSE);
+ }
+ else
+ {
+ if (m_pEditCaret)
+ {
+ m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(GetClientRect(),1.0f)); //+1 for caret beside border
+ }
+ }
+
+ if (HasFlag(PES_SPELLCHECK))
+ {
+ m_pSpellCheck = GetCreationParam().pSpellCheck;
+ }
+}
+
+void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ CPWL_Wnd::GetThisAppearanceStream(sAppStream);
+
+ CPDF_Rect rcClient = GetClientRect();
+ CFX_ByteTextBuf sLine;
+
+ FX_INT32 nCharArray = m_pEdit->GetCharArray();
+
+ if (nCharArray > 0)
+ {
+ switch (GetBorderStyle())
+ {
+ case PBS_SOLID:
+ {
+ sLine << "q\n" << GetBorderWidth() << " w\n"
+ << CPWL_Utils::GetColorAppStream(GetBorderColor(),FALSE) << " 2 J 0 j\n";
+
+ for (FX_INT32 i=1;i<nCharArray;i++)
+ {
+ sLine << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
+ << rcClient.bottom << " m\n"
+ << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
+ << rcClient.top << " l S\n";
+ }
+
+ sLine << "Q\n";
+ }
+ break;
+ case PBS_DASH:
+ {
+ sLine << "q\n" << GetBorderWidth() << " w\n"
+ << CPWL_Utils::GetColorAppStream(GetBorderColor(),FALSE) << " 2 J 0 j\n"
+ << "[" << GetBorderDash().nDash << " "
+ << GetBorderDash().nGap << "] "
+ << GetBorderDash().nPhase << " d\n";
+
+ for (FX_INT32 i=1;i<nCharArray;i++)
+ {
+ sLine << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
+ << rcClient.bottom << " m\n"
+ << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
+ << rcClient.top << " l S\n";
+ }
+
+ sLine << "Q\n";
+ }
+ break;
+ }
+ }
+
+ sAppStream << sLine;
+
+ CFX_ByteTextBuf sText;
+
+ CPDF_Point ptOffset = CPDF_Point(0.0f,0.0f);
+
+ CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
+ CPVT_WordRange wrSelect = GetSelectWordRange();
+ CPVT_WordRange wrVisible = (HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange());
+ CPVT_WordRange wrSelBefore(wrWhole.BeginPos,wrSelect.BeginPos);
+ CPVT_WordRange wrSelAfter(wrSelect.EndPos,wrWhole.EndPos);
+
+ CPVT_WordRange wrTemp = CPWL_Utils::OverlapWordRange(GetSelectWordRange(),wrVisible);
+ CFX_ByteString sEditSel = CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset,
+ &wrTemp);
+
+ if (sEditSel.GetLength() > 0)
+ sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR) << sEditSel ;
+
+ wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelBefore);
+ CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset,
+ &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordChar());
+
+ if (sEditBefore.GetLength() > 0)
+ sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEditBefore << "ET\n";
+
+ wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelect);
+ CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset,
+ &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordChar());
+
+ if (sEditMid.GetLength() > 0)
+ sText << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY,1)) << sEditMid << "ET\n";
+
+ wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelAfter);
+ CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset,
+ &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordChar());
+
+ if (sEditAfter.GetLength() > 0)
+ sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEditAfter<< "ET\n";
+
+ if (HasFlag(PES_SPELLCHECK))
+ {
+ CFX_ByteString sSpellCheck = CPWL_Utils::GetSpellCheckAppStream(m_pEdit, m_pSpellCheck, ptOffset, &wrVisible);
+ if (sSpellCheck.GetLength() > 0)
+ sText << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,1,0,0),FALSE) << sSpellCheck;
+ }
+
+ if (sText.GetLength() > 0)
+ {
+ CPDF_Rect rcClient = this->GetClientRect();
+ sAppStream << "q\n/Tx BMC\n";
+
+ if (!HasFlag(PES_TEXTOVERFLOW))
+ sAppStream << rcClient.left << " " << rcClient.bottom << " "
+ << rcClient.right - rcClient.left << " " << rcClient.top - rcClient.bottom << " re W n\n";
+
+ sAppStream << sText;
+
+ sAppStream << "EMC\nQ\n";
+ }
+}
+
+void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
+
+ CPDF_Rect rcClient = GetClientRect();
+ CFX_ByteTextBuf sLine;
+
+ FX_INT32 nCharArray = m_pEdit->GetCharArray();
+
+ if (nCharArray > 0)
+ {
+ switch (GetBorderStyle())
+ {
+ case PBS_SOLID:
+ {
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
+
+ CFX_PathData path;
+ path.SetPointCount((nCharArray-1)*2);
+
+ for (FX_INT32 i=0; i<nCharArray-1; i++)
+ {
+ path.SetPoint(i*2, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
+ rcClient.bottom, FXPT_MOVETO);
+ path.SetPoint(i*2+1, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
+ rcClient.top, FXPT_LINETO);
+ }
+ if (path.GetPointCount() > 0)
+ pDevice->DrawPath(&path, pUser2Device, &gsd,0,
+ CPWL_Utils::PWLColorToFXColor(GetBorderColor(),255), FXFILL_ALTERNATE);
+ }
+ break;
+ case PBS_DASH:
+ {
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
+
+ gsd.SetDashCount(2);
+ gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash;
+ gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap;
+ gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase;
+
+ CFX_PathData path;
+ path.SetPointCount((nCharArray-1)*2);
+
+ for (FX_INT32 i=0; i<nCharArray-1; i++)
+ {
+ path.SetPoint(i*2, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
+ rcClient.bottom, FXPT_MOVETO);
+ path.SetPoint(i*2+1, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
+ rcClient.top, FXPT_LINETO);
+ }
+ if (path.GetPointCount() > 0)
+ pDevice->DrawPath(&path, pUser2Device, &gsd,0,
+ CPWL_Utils::PWLColorToFXColor(GetBorderColor(),255), FXFILL_ALTERNATE);
+ }
+ break;
+ }
+ }
+
+ CPDF_Rect rcClip;
+ CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
+ CPVT_WordRange* pRange = NULL;
+
+ if (!HasFlag(PES_TEXTOVERFLOW))
+ {
+ rcClip = GetClientRect();
+ pRange = &wrRange;
+ }
+IFX_SystemHandler* pSysHandler = GetSystemHandler();
+ IFX_Edit::DrawEdit(pDevice,pUser2Device,m_pEdit,
+ CPWL_Utils::PWLColorToFXColor(GetTextColor(),this->GetTransparency()),
+ CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(),this->GetTransparency()),
+ rcClip,CPDF_Point(0.0f,0.0f),pRange, pSysHandler, m_pFormFiller);
+
+ if (HasFlag(PES_SPELLCHECK))
+ {
+ CPWL_Utils::DrawEditSpellCheck(pDevice,pUser2Device,m_pEdit,rcClip,
+ CPDF_Point(0.0f,0.0f),pRange, this->GetCreationParam().pSpellCheck);
+ }
+}
+
+FX_BOOL CPWL_Edit::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonDown(point,nFlag);
+
+ if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point))
+ {
+ if (m_bMouseDown)
+ this->InvalidateRect();
+
+ m_bMouseDown = TRUE;
+ SetCapture();
+
+ m_pEdit->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_Edit::OnLButtonDblClk(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonDblClk(point, nFlag);
+
+ if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point))
+ {
+ m_pEdit->SelectAll();
+ }
+
+ return TRUE;
+}
+
+#define WM_PWLEDIT_UNDO 0x01
+#define WM_PWLEDIT_REDO 0x02
+#define WM_PWLEDIT_CUT 0x03
+#define WM_PWLEDIT_COPY 0x04
+#define WM_PWLEDIT_PASTE 0x05
+#define WM_PWLEDIT_DELETE 0x06
+#define WM_PWLEDIT_SELECTALL 0x07
+#define WM_PWLEDIT_SUGGEST 0x08
+
+FX_BOOL CPWL_Edit::OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ if (m_bMouseDown) return FALSE;
+
+ CPWL_Wnd::OnRButtonUp(point, nFlag);
+
+ if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) return TRUE;
+
+ IFX_SystemHandler* pSH = GetSystemHandler();
+ if (!pSH) return FALSE;
+
+ this->SetFocus();
+
+ CPVT_WordRange wrLatin = GetLatinWordsRange(point);
+ CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin);
+
+ FX_HMENU hPopup = pSH->CreatePopupMenu();
+ if (!hPopup) return FALSE;
+
+ CFX_ByteStringArray sSuggestWords;
+ CPDF_Point ptPopup = point;
+
+ if (!IsReadOnly())
+ {
+ if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty())
+ {
+ if (m_pSpellCheck)
+ {
+ CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin);
+
+ if (!m_pSpellCheck->CheckWord(sLatin))
+ {
+ m_pSpellCheck->SuggestWords(sLatin,sSuggestWords);
+
+ FX_INT32 nSuggest = sSuggestWords.GetSize();
+
+ for (FX_INT32 nWord=0; nWord<nSuggest; nWord++)
+ {
+ pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST+nWord, sSuggestWords[nWord].UTF8Decode());
+ }
+
+ if (nSuggest > 0)
+ pSH->AppendMenuItem(hPopup, 0, L"");
+
+ ptPopup = GetWordRightBottomPoint(wrLatin.EndPos);
+ }
+ }
+ }
+ }
+
+ IPWL_Provider* pProvider = this->GetProvider();
+
+ if (HasFlag(PES_UNDO))
+ {
+ pSH->AppendMenuItem(hPopup, WM_PWLEDIT_UNDO,
+ pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo");
+ pSH->AppendMenuItem(hPopup, WM_PWLEDIT_REDO,
+ pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo");
+ pSH->AppendMenuItem(hPopup, 0, L"");
+
+ if (!m_pEdit->CanUndo())
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE);
+ if (!m_pEdit->CanRedo())
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE);
+ }
+
+ pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT,
+ pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t");
+ pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY,
+ pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy");
+ pSH->AppendMenuItem(hPopup, WM_PWLEDIT_PASTE,
+ pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste");
+ pSH->AppendMenuItem(hPopup, WM_PWLEDIT_DELETE,
+ pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete");
+
+ CFX_WideString swText = pSH->GetClipboardText(this->GetAttachedHWnd());
+ if (swText.IsEmpty())
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
+
+ if (!m_pEdit->IsSelected())
+ {
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
+ }
+
+ if (IsReadOnly())
+ {
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
+ }
+
+ if (HasFlag(PES_PASSWORD))
+ {
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
+ }
+
+ if (HasFlag(PES_NOREAD))
+ {
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
+ }
+
+ pSH->AppendMenuItem(hPopup, 0, L"");
+ pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SELECTALL,
+ pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All");
+
+ if (m_pEdit->GetTotalWords() == 0)
+ {
+ pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE);
+ }
+
+ FX_INT32 x, y;
+ PWLtoWnd(ptPopup, x, y);
+ pSH->ClientToScreen(GetAttachedHWnd(), x, y);
+ pSH->SetCursor(FXCT_ARROW);
+ FX_INT32 nCmd = pSH->TrackPopupMenu(hPopup,
+ x,
+ y,
+ GetAttachedHWnd());
+
+
+ switch (nCmd)
+ {
+ case WM_PWLEDIT_UNDO:
+ Undo();
+ break;
+ case WM_PWLEDIT_REDO:
+ Redo();
+ break;
+ case WM_PWLEDIT_CUT:
+ this->CutText();
+ break;
+ case WM_PWLEDIT_COPY:
+ this->CopyText();
+ break;
+ case WM_PWLEDIT_PASTE:
+ this->PasteText();
+ break;
+ case WM_PWLEDIT_DELETE:
+ this->Clear();
+ break;
+ case WM_PWLEDIT_SELECTALL:
+ this->SelectAll();
+ break;
+ case WM_PWLEDIT_SUGGEST + 0:
+ SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
+ ReplaceSel(sSuggestWords[0].UTF8Decode());
+ break;
+ case WM_PWLEDIT_SUGGEST + 1:
+ SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
+ ReplaceSel(sSuggestWords[1].UTF8Decode());
+ break;
+ case WM_PWLEDIT_SUGGEST + 2:
+ SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
+ ReplaceSel(sSuggestWords[2].UTF8Decode());
+ break;
+ case WM_PWLEDIT_SUGGEST + 3:
+ SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
+ ReplaceSel(sSuggestWords[3].UTF8Decode());
+ break;
+ case WM_PWLEDIT_SUGGEST + 4:
+ SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
+ ReplaceSel(sSuggestWords[4].UTF8Decode());
+ break;
+ default:
+ break;
+ }
+
+ pSH->DestroyMenu(hPopup);
+
+ return TRUE;
+}
+
+void CPWL_Edit::OnSetFocus()
+{
+ SetEditCaret(TRUE);
+
+ if (!IsReadOnly())
+ {
+ if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
+ pFocusHandler->OnSetFocus(this);
+ }
+
+ m_bFocus = TRUE;
+}
+
+void CPWL_Edit::OnKillFocus()
+{
+ ShowVScrollBar(FALSE);
+
+ m_pEdit->SelectNone();
+ SetCaret(FALSE, CPDF_Point(0.0f,0.0f), CPDF_Point(0.0f,0.0f));
+
+ SetCharSet(0);
+
+ if (!IsReadOnly())
+ {
+ if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
+ pFocusHandler->OnKillFocus(this);
+ }
+
+ m_bFocus = FALSE;
+}
+
+void CPWL_Edit::SetHorzScale(FX_INT32 nHorzScale, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pEdit->SetHorzScale(nHorzScale, bPaint);
+}
+
+void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pEdit->SetCharSpace(fCharSpace, bPaint);
+}
+
+void CPWL_Edit::SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint/* = TRUE*/)
+{
+ m_pEdit->SetLineLeading(fLineLeading, bPaint);
+}
+
+CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(const CPDF_Point & ptOffset) const
+{
+ CPVT_WordRange wr = GetSelectWordRange();
+ return CPWL_Utils::GetEditSelAppStream(m_pEdit,ptOffset,&wr);
+}
+
+CPVT_WordRange CPWL_Edit::GetSelectWordRange() const
+{
+ if (m_pEdit->IsSelected())
+ {
+ FX_INT32 nStart = -1;
+ FX_INT32 nEnd = -1;
+
+ m_pEdit->GetSel(nStart, nEnd);
+
+ CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
+ CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
+
+ return CPVT_WordRange(wpStart,wpEnd);
+ }
+
+ return CPVT_WordRange();
+}
+
+CFX_ByteString CPWL_Edit::GetTextAppearanceStream(const CPDF_Point & ptOffset) const
+{
+ CFX_ByteTextBuf sRet;
+ CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit,ptOffset);
+
+ if (sEdit.GetLength() > 0)
+ {
+ sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEdit << "ET\n";
+ }
+
+ return sRet.GetByteString();
+}
+
+CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(const CPDF_Point & ptOffset) const
+{
+ if (m_pEditCaret)
+ return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
+
+ return CFX_ByteString();
+}
+
+CPDF_Point CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord)
+{
+ CPDF_Point pt(0.0f, 0.0f);
+
+ if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
+ {
+ CPVT_WordPlace wpOld = pIterator->GetAt();
+ pIterator->SetAt(wpWord);
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ pt = CPDF_Point(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
+ }
+
+ pIterator->SetAt(wpOld);
+ }
+
+ return pt;
+}
+
+FX_BOOL CPWL_Edit::IsTextFull() const
+{
+ return m_pEdit->IsTextFull();
+}
+
+FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, const CPDF_Rect& rcPlate, FX_INT32 nCharArray)
+{
+ if (pFont && !pFont->IsStandardFont())
+ {
+ FX_RECT rcBBox;
+ pFont->GetFontBBox(rcBBox);
+
+ CPDF_Rect rcCell = rcPlate;
+ FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
+ FX_FLOAT ydiv = - rcCell.Height() * 1000.0f / rcBBox.Height();
+
+ return xdiv < ydiv ? xdiv : ydiv;
+ }
+
+ return 0.0f;
+}
+
+void CPWL_Edit::SetCharArray(FX_INT32 nCharArray)
+{
+ if (HasFlag(PES_CHARARRAY) && nCharArray > 0)
+ {
+ m_pEdit->SetCharArray(nCharArray);
+ m_pEdit->SetTextOverflow(TRUE);
+
+ if (HasFlag(PWS_AUTOFONTSIZE))
+ {
+ if (IFX_Edit_FontMap* pFontMap = this->GetFontMap())
+ {
+ FX_FLOAT fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0), GetClientRect(), nCharArray);
+ if (fFontSize > 0.0f)
+ {
+ m_pEdit->SetAutoFontSize(FALSE);
+ m_pEdit->SetFontSize(fFontSize);
+ }
+ }
+ }
+ }
+}
+
+void CPWL_Edit::SetLimitChar(FX_INT32 nLimitChar)
+{
+ m_pEdit->SetLimitChar(nLimitChar);
+}
+
+void CPWL_Edit::ReplaceSel(FX_LPCWSTR csText)
+{
+ m_pEdit->Clear();
+ m_pEdit->InsertText(csText);
+}
+
+CPDF_Rect CPWL_Edit::GetFocusRect() const
+{
+ return CPDF_Rect();
+}
+
+void CPWL_Edit::ShowVScrollBar(FX_BOOL bShow)
+{
+ if (CPWL_ScrollBar * pScroll = GetVScrollBar())
+ {
+ if (bShow)
+ {
+ if (!pScroll->IsVisible())
+ {
+ pScroll->SetVisible(TRUE);
+ CPDF_Rect rcWindow = GetWindowRect();
+ m_rcOldWindow = rcWindow;
+ rcWindow.right += PWL_SCROLLBAR_WIDTH;
+ Move(rcWindow, TRUE, TRUE);
+ }
+ }
+ else
+ {
+ if (pScroll->IsVisible())
+ {
+ pScroll->SetVisible(FALSE);
+ Move(m_rcOldWindow, TRUE, TRUE);
+ }
+ }
+ }
+}
+
+FX_BOOL CPWL_Edit::IsVScrollBarVisible() const
+{
+ if (CPWL_ScrollBar * pScroll = GetVScrollBar())
+ {
+ return pScroll->IsVisible();
+ }
+
+ return FALSE;
+}
+
+void CPWL_Edit::EnableSpellCheck(FX_BOOL bEnabled)
+{
+ if (bEnabled)
+ AddFlag(PES_SPELLCHECK);
+ else
+ RemoveFlag(PES_SPELLCHECK);
+}
+
+FX_BOOL CPWL_Edit::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
+{
+ if (m_bMouseDown) return TRUE;
+
+ if (nChar == FWL_VKEY_Delete)
+ {
+ if (m_pFillerNotify)
+ {
+ FX_BOOL bRC = TRUE;
+ FX_BOOL bExit = FALSE;
+ CFX_WideString strChange;
+ CFX_WideString strChangeEx;
+
+ int nSelStart = 0;
+ int nSelEnd = 0;
+ GetSel(nSelStart, nSelEnd);
+
+ if (nSelStart == nSelEnd)
+ nSelEnd = nSelStart + 1;
+ m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), FWL_VKEY_Delete, strChange, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, nFlag);
+ if (!bRC) return FALSE;
+ if (bExit) return FALSE;
+ }
+ }
+
+ FX_BOOL bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
+
+ if (nChar == FWL_VKEY_Delete)
+ {
+ if (m_pFillerNotify)
+ {
+ FX_BOOL bExit = FALSE;
+ m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit,nFlag);
+ if (bExit) return FALSE;
+ }
+ }
+
+ //In case of implementation swallow the OnKeyDown event.
+ if(IsProceedtoOnChar(nChar, nFlag))
+ return TRUE;
+
+ return bRet;
+}
+
+/**
+*In case of implementation swallow the OnKeyDown event.
+*If the event is swallowed, implementation may do other unexpected things, which is not the control means to do.
+*/
+FX_BOOL CPWL_Edit::IsProceedtoOnChar(FX_WORD nKeyCode, FX_DWORD nFlag)
+{
+
+ FX_BOOL bCtrl = IsCTRLpressed(nFlag);
+ FX_BOOL bAlt = IsALTpressed(nFlag);
+ if(bCtrl && !bAlt)
+ {
+ //hot keys for edit control.
+ switch(nKeyCode)
+ {
+ case 'C':
+ case 'V':
+ case 'X':
+ case 'A':
+ case 'Z':
+ return TRUE;
+ default:
+ break;
+ }
+ }
+ //control characters.
+ switch(nKeyCode)
+ {
+ case FWL_VKEY_Escape:
+ case FWL_VKEY_Back:
+ case FWL_VKEY_Return:
+ case FWL_VKEY_Space:
+ return TRUE;
+ default:
+ break;
+ }
+ return FALSE;
+
+}
+
+FX_BOOL CPWL_Edit::OnChar(FX_WORD nChar, FX_DWORD nFlag)
+{
+ if (m_bMouseDown) return TRUE;
+
+ FX_BOOL bRC = TRUE;
+ FX_BOOL bExit = FALSE;
+
+ FX_BOOL bCtrl = IsCTRLpressed(nFlag);
+ if (!bCtrl)
+ {
+ if (m_pFillerNotify)
+ {
+ CFX_WideString swChange;
+ FX_INT32 nKeyCode;
+
+ int nSelStart = 0;
+ int nSelEnd = 0;
+ GetSel(nSelStart, nSelEnd);
+
+ switch (nChar)
+ {
+ case FWL_VKEY_Back:
+ nKeyCode = nChar;
+ if (nSelStart == nSelEnd)
+ nSelStart = nSelEnd - 1;
+ break;
+ case FWL_VKEY_Return:
+ nKeyCode = nChar;
+ break;
+ default:
+ nKeyCode = 0;
+ swChange += nChar;
+ break;
+ }
+
+ CFX_WideString strChangeEx;
+ m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), nKeyCode, swChange, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, nFlag);
+ }
+ }
+
+ if (!bRC) return TRUE;
+ if (bExit) return FALSE;
+
+ if (IFX_Edit_FontMap * pFontMap = GetFontMap())
+ {
+ FX_INT32 nOldCharSet = GetCharSet();
+ FX_INT32 nNewCharSet = pFontMap->CharSetFromUnicode(nChar, DEFAULT_CHARSET);
+ if(nOldCharSet != nNewCharSet)
+ {
+ SetCharSet(nNewCharSet);
+ }
+ }
+ FX_BOOL bRet = CPWL_EditCtrl::OnChar(nChar,nFlag);
+
+ if (!bCtrl)
+ {
+ if (m_pFillerNotify)
+ {
+ m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit,nFlag);
+ if (bExit) return FALSE;
+ }
+ }
+
+ return bRet;
+}
+
+FX_BOOL CPWL_Edit::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag)
+{
+ if (HasFlag(PES_MULTILINE))
+ {
+ CPDF_Point ptScroll = GetScrollPos();
+
+ if (zDelta > 0)
+ {
+ ptScroll.y += this->GetFontSize();
+ }
+ else
+ {
+ ptScroll.y -= this->GetFontSize();
+ }
+ this->SetScrollPos(ptScroll);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
+{
+ if (HasFlag(PES_SPELLCHECK))
+ {
+ m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
+ }
+
+ if (m_pEditNotify)
+ {
+ m_pEditNotify->OnInsertReturn(place, oldplace);
+ }
+}
+
+void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
+{
+ if (HasFlag(PES_SPELLCHECK))
+ {
+ m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
+ }
+
+ if (m_pEditNotify)
+ {
+ m_pEditNotify->OnBackSpace(place, oldplace);
+ }
+}
+
+void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
+{
+ if (HasFlag(PES_SPELLCHECK))
+ {
+ m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
+ }
+
+ if (m_pEditNotify)
+ {
+ m_pEditNotify->OnDelete(place, oldplace);
+ }
+}
+
+void CPWL_Edit::OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
+{
+ if (HasFlag(PES_SPELLCHECK))
+ {
+ m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
+ }
+
+ if (m_pEditNotify)
+ {
+ m_pEditNotify->OnClear(place, oldplace);
+ }
+}
+
+void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
+{
+ if (HasFlag(PES_SPELLCHECK))
+ {
+ m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
+ }
+
+ if (m_pEditNotify)
+ {
+ m_pEditNotify->OnInsertWord(place, oldplace);
+ }
+}
+
+void CPWL_Edit::OnSetText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
+{
+}
+
+void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
+{
+ if (HasFlag(PES_SPELLCHECK))
+ {
+ m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
+ }
+
+ if (m_pEditNotify)
+ {
+ m_pEditNotify->OnInsertText(place, oldplace);
+ }
+}
+
+void CPWL_Edit::OnAddUndo(IFX_Edit_UndoItem* pUndoItem)
+{
+ if (m_pEditNotify)
+ {
+ m_pEditNotify->OnAddUndo(this);
+ }
+}
+
+CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, const CPVT_WordRange& wr2)
+{
+ CPVT_WordRange wrRet;
+
+ if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0)
+ {
+ wrRet.BeginPos = wr1.BeginPos;
+ }
+ else
+ {
+ wrRet.BeginPos = wr2.BeginPos;
+ }
+
+ if (wr1.EndPos.WordCmp(wr2.EndPos) < 0)
+ {
+ wrRet.EndPos = wr2.EndPos;
+ }
+ else
+ {
+ wrRet.EndPos = wr1.EndPos;
+ }
+
+ return wrRet;
+}
+
+CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CPDF_Point& point) const
+{
+ return GetSameWordsRange(m_pEdit->SearchWordPlace(point), TRUE, FALSE);
+}
+
+CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CPVT_WordPlace & place) const
+{
+ return GetSameWordsRange(place, TRUE, FALSE);
+}
+
+CPVT_WordRange CPWL_Edit::GetArabicWordsRange(const CPVT_WordPlace & place) const
+{
+ return GetSameWordsRange(place, FALSE, TRUE);
+}
+
+#define PWL_ISARABICWORD(word) ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
+
+CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace & place, FX_BOOL bLatin, FX_BOOL bArabic) const
+{
+ CPVT_WordRange range;
+
+ if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator())
+ {
+ CPVT_Word wordinfo;
+ CPVT_WordPlace wpStart(place),wpEnd(place);
+ pIterator->SetAt(place);
+
+ if (bLatin)
+ {
+ while (pIterator->NextWord())
+ {
+ if (pIterator->GetWord(wordinfo) && FX_EDIT_ISLATINWORD(wordinfo.Word))
+ {
+ wpEnd = pIterator->GetAt();
+ continue;
+ }
+ else
+ break;
+ };
+ }
+ else if (bArabic)
+ {
+ while (pIterator->NextWord())
+ {
+ if (pIterator->GetWord(wordinfo) && PWL_ISARABICWORD(wordinfo.Word))
+ {
+ wpEnd = pIterator->GetAt();
+ continue;
+ }
+ else
+ break;
+ };
+ }
+
+ pIterator->SetAt(place);
+
+ if (bLatin)
+ {
+ do
+ {
+ if (pIterator->GetWord(wordinfo) && FX_EDIT_ISLATINWORD(wordinfo.Word))
+ {
+ continue;
+ }
+ else
+ {
+ wpStart = pIterator->GetAt();
+ break;
+ }
+ }
+ while (pIterator->PrevWord());
+ }
+ else if (bArabic)
+ {
+ do
+ {
+ if (pIterator->GetWord(wordinfo) && PWL_ISARABICWORD(wordinfo.Word))
+ {
+ continue;
+ }
+ else
+ {
+ wpStart = pIterator->GetAt();
+ break;
+ }
+ }
+ while (pIterator->PrevWord());
+ }
+
+ range.Set(wpStart,wpEnd);
+ }
+
+ return range;
+}
+
+void CPWL_Edit::AjustArabicWords(const CPVT_WordRange& wr)
+{
+}
+
+void CPWL_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects,
+ const CPDF_Point& ptOffset, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray)
+{
+ IFX_Edit::GeneratePageObjects(pPageObjects, m_pEdit, ptOffset, NULL, CPWL_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()), ObjArray);
+}
+
+void CPWL_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects,
+ const CPDF_Point& ptOffset)
+{
+ CFX_ArrayTemplate<CPDF_TextObject*> ObjArray;
+ IFX_Edit::GeneratePageObjects(pPageObjects, m_pEdit, ptOffset, NULL, CPWL_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()), ObjArray);
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_EditCtrl.cpp b/fpdfsdk/src/pdfwindow/PWL_EditCtrl.cpp
index 25628223ec..90a198a771 100644
--- a/fpdfsdk/src/pdfwindow/PWL_EditCtrl.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_EditCtrl.cpp
@@ -1,728 +1,728 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_EditCtrl.h"
-#include "../../include/pdfwindow/PWL_ScrollBar.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-#include "../../include/pdfwindow/PWL_Caret.h"
-#include "../../include/pdfwindow/PWL_FontMap.h"
-
-#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
-#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
-
-/* ---------------------------- CPWL_EditCtrl ------------------------------ */
-
-CPWL_EditCtrl::CPWL_EditCtrl() :
- m_pEdit(NULL),
- m_pEditCaret(NULL),
- m_bMouseDown(FALSE),
- m_pEditNotify(NULL),
- m_nCharSet(DEFAULT_CHARSET),
- m_nCodePage(0)
-{
- m_pEdit = IFX_Edit::NewEdit();
- ASSERT(m_pEdit != NULL);
-}
-
-CPWL_EditCtrl::~CPWL_EditCtrl()
-{
- IFX_Edit::DelEdit(m_pEdit);
-}
-
-void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM & cp)
-{
- cp.eCursorType = FXCT_VBEAM;
-}
-
-void CPWL_EditCtrl::OnCreated()
-{
- SetFontSize(this->GetCreationParam().fFontSize);
-
- m_pEdit->SetFontMap(this->GetFontMap());
- m_pEdit->SetNotify(this);
- m_pEdit->Initialize();
-}
-
-FX_BOOL CPWL_EditCtrl::IsWndHorV()
-{
- CPDF_Matrix mt = GetWindowMatrix();
- CPDF_Point point1(0,1);
- CPDF_Point point2(1,1);
-
- mt.Transform(point1.x, point1.y);
- mt.Transform(point2.x, point2.y);
-
- return point2.y == point1.y;
-}
-
-void CPWL_EditCtrl::SetCursor()
-{
- if (IsValid())
- {
- if (IFX_SystemHandler* pSH = GetSystemHandler())
- {
- if (IsWndHorV())
- pSH->SetCursor(FXCT_VBEAM);
- else
- pSH->SetCursor(FXCT_HBEAM);
- }
- }
-}
-
-void CPWL_EditCtrl::RePosChildWnd()
-{
- m_pEdit->SetPlateRect(GetClientRect());
-}
-
-void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
-
- switch (msg)
- {
- case PNM_SETSCROLLINFO:
- switch (wParam)
- {
- case SBT_VSCROLL:
- if (CPWL_Wnd * pChild = GetVScrollBar())
- {
- pChild->OnNotify(pWnd,PNM_SETSCROLLINFO,wParam,lParam);
- }
- break;
- }
- break;
- case PNM_SETSCROLLPOS:
- switch (wParam)
- {
- case SBT_VSCROLL:
- if (CPWL_Wnd * pChild = GetVScrollBar())
- {
- pChild->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);
- }
- break;
- }
- break;
- case PNM_SCROLLWINDOW:
- {
- FX_FLOAT fPos = *(FX_FLOAT*)lParam;
- switch (wParam)
- {
- case SBT_VSCROLL:
- m_pEdit->SetScrollPos(CPDF_Point(m_pEdit->GetScrollPos().x,fPos));
- break;
- }
- }
- break;
- case PNM_SETCARETINFO:
- {
- if (PWL_CARET_INFO * pCaretInfo = (PWL_CARET_INFO *)wParam)
- {
- this->SetCaret(pCaretInfo->bVisible,
- pCaretInfo->ptHead,
- pCaretInfo->ptFoot);
- }
- }
- break;
- }
-}
-
-void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- if (!IsReadOnly())
- CreateEditCaret(cp);
-}
-
-void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM & cp)
-{
- if (!m_pEditCaret)
- {
- m_pEditCaret = new CPWL_Caret;
- m_pEditCaret->SetInvalidRect(GetClientRect());
-
- PWL_CREATEPARAM ecp = cp;
- ecp.pParentWnd = this;
- ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
- ecp.dwBorderWidth = 0;
- ecp.nBorderStyle = PBS_SOLID;
- ecp.rcRectWnd = CPDF_Rect(0,0,0,0);
-
- m_pEditCaret->Create(ecp);
- }
-}
-
-void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize)
-{
- m_pEdit->SetFontSize(fFontSize);
-}
-
-FX_FLOAT CPWL_EditCtrl::GetFontSize() const
-{
- return m_pEdit->GetFontSize();
-}
-
-FX_BOOL CPWL_EditCtrl::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
-{
- if (m_bMouseDown) return TRUE;
-
- FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar,nFlag);
-
- //FILTER
- switch (nChar)
- {
- default:
- return FALSE;
- case FWL_VKEY_Delete:
- case FWL_VKEY_Up:
- case FWL_VKEY_Down:
- case FWL_VKEY_Left:
- case FWL_VKEY_Right:
- case FWL_VKEY_Home:
- case FWL_VKEY_End:
- case FWL_VKEY_Insert:
- case 'C':
- case 'V':
- case 'X':
- case 'A':
- case 'Z':
- case 'c':
- case 'v':
- case 'x':
- case 'a':
- case 'z':
- break;
- }
-
- if (nChar == FWL_VKEY_Delete)
- {
- if (m_pEdit->IsSelected())
- nChar = FWL_VKEY_Unknown;
- }
-
- switch (nChar)
- {
- case FWL_VKEY_Delete:
- Delete();
- return TRUE;
- case FWL_VKEY_Insert:
- if (IsSHIFTpressed(nFlag))
- PasteText();
- return TRUE;
- case FWL_VKEY_Up:
- m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag),FALSE);
- return TRUE;
- case FWL_VKEY_Down:
- m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag),FALSE);
- return TRUE;
- case FWL_VKEY_Left:
- m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag),FALSE);
- return TRUE;
- case FWL_VKEY_Right:
- m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag),FALSE);
- return TRUE;
- case FWL_VKEY_Home:
- m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- return TRUE;
- case FWL_VKEY_End:
- m_pEdit->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- return TRUE;
- case FWL_VKEY_Unknown:
- if (!IsSHIFTpressed(nFlag))
- Clear();
- else
- CutText();
- return TRUE;
- default:
- break;
- }
-
- return bRet;
-}
-
-FX_BOOL CPWL_EditCtrl::OnChar(FX_WORD nChar, FX_DWORD nFlag)
-{
- if (m_bMouseDown) return TRUE;
-
- CPWL_Wnd::OnChar(nChar,nFlag);
-
- //FILTER
- switch (nChar)
- {
- case 0x0A:
- case 0x1B:
- return FALSE;
- default:
- break;
- }
-
- FX_BOOL bCtrl = IsCTRLpressed(nFlag);
- FX_BOOL bAlt = IsALTpressed(nFlag);
- FX_BOOL bShift = IsSHIFTpressed(nFlag);
-
- FX_WORD word = nChar;
-
- if (bCtrl && !bAlt)
- {
- switch (nChar)
- {
- case 'C' - 'A' + 1:
- this->CopyText();
- return TRUE;
- case 'V' - 'A' + 1:
- this->PasteText();
- return TRUE;
- case 'X' - 'A' + 1:
- this->CutText();
- return TRUE;
- case 'A' - 'A' + 1:
- this->SelectAll();
- return TRUE;
- case 'Z' - 'A' + 1:
- if (bShift)
- Redo();
- else
- Undo();
- return TRUE;
- default:
- if (nChar < 32)
- return FALSE;
- }
- }
-
- if (IsReadOnly()) return TRUE;
-
- if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
- word = FWL_VKEY_Unknown;
-
- Clear();
-
- switch (word)
- {
- case FWL_VKEY_Back:
- Backspace();
- break;
- case FWL_VKEY_Return:
- InsertReturn();
- break;
- case FWL_VKEY_Unknown:
- break;
- default:
- if (IsINSERTpressed(nFlag))
- Delete();
- InsertWord(word, this->GetCharSet());
- break;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonDown(point,nFlag);
-
- if (ClientHitTest(point))
- {
- if (m_bMouseDown)
- this->InvalidateRect();
-
- m_bMouseDown = TRUE;
- SetCapture();
-
- m_pEdit->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- }
-
- return TRUE;
-}
-
-FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonUp(point,nFlag);
-
- if (m_bMouseDown)
- {
- //can receive keybord message
- if (ClientHitTest(point) && !this->IsFocused())
- SetFocus();
-
- ReleaseCapture();
- m_bMouseDown = FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL CPWL_EditCtrl::OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnMouseMove(point,nFlag);
-
- if (m_bMouseDown)
- m_pEdit->OnMouseMove(point,FALSE,FALSE);
-
- return TRUE;
-}
-
-CPDF_Rect CPWL_EditCtrl::GetContentRect() const
-{
- return m_pEdit->GetContentRect();
-}
-
-void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible)
-{
- CPDF_Point ptHead(0,0),ptFoot(0,0);
-
- if (bVisible)
- {
- GetCaretInfo(ptHead,ptFoot);
- }
-
- CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
- this->IOnSetCaret(bVisible,ptHead,ptFoot,wpTemp);
-}
-
-void CPWL_EditCtrl::GetCaretInfo(CPDF_Point & ptHead, CPDF_Point & ptFoot) const
-{
- if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
- {
- pIterator->SetAt(m_pEdit->GetCaret());
- CPVT_Word word;
- CPVT_Line line;
- if (pIterator->GetWord(word))
- {
- ptHead.x = word.ptWord.x + word.fWidth;
- ptHead.y = word.ptWord.y + word.fAscent;
- ptFoot.x = word.ptWord.x + word.fWidth;
- ptFoot.y = word.ptWord.y + word.fDescent;
- }
- else if (pIterator->GetLine(line))
- {
- ptHead.x = line.ptLine.x;
- ptHead.y = line.ptLine.y + line.fLineAscent;
- ptFoot.x = line.ptLine.x;
- ptFoot.y = line.ptLine.y + line.fLineDescent;
- }
- }
-}
-
-void CPWL_EditCtrl::GetCaretPos(FX_INT32& x, FX_INT32& y) const
-{
- CPDF_Point ptHead(0,0), ptFoot(0,0);
-
- GetCaretInfo(ptHead,ptFoot);
-
- PWLtoWnd(ptHead, x, y);
-}
-
-void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot)
-{
- if (m_pEditCaret)
- {
- if (!IsFocused() || m_pEdit->IsSelected())
- bVisible = FALSE;
-
- m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
- }
-}
-
-FX_BOOL CPWL_EditCtrl::IsModified() const
-{
- return m_pEdit->IsModified();
-}
-
-CFX_WideString CPWL_EditCtrl::GetText() const
-{
- return m_pEdit->GetText();
-}
-
-void CPWL_EditCtrl::SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar)
-{
- m_pEdit->SetSel(nStartChar, nEndChar);
-}
-
-void CPWL_EditCtrl::GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar ) const
-{
- m_pEdit->GetSel(nStartChar, nEndChar);
-}
-
-void CPWL_EditCtrl::Clear()
-{
- if (!IsReadOnly())
- m_pEdit->Clear();
-}
-
-void CPWL_EditCtrl::SelectAll()
-{
- m_pEdit->SelectAll();
-}
-
-void CPWL_EditCtrl::Paint()
-{
- if (m_pEdit)
- m_pEdit->Paint();
-}
-
-void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh)
-{
- if (m_pEdit)
- m_pEdit->EnableRefresh(bRefresh);
-}
-
-FX_INT32 CPWL_EditCtrl::GetCaret() const
-{
- if (m_pEdit)
- return m_pEdit->GetCaret();
-
- return -1;
-}
-
-void CPWL_EditCtrl::SetCaret(FX_INT32 nPos)
-{
- if (m_pEdit)
- m_pEdit->SetCaret(nPos);
-}
-
-FX_INT32 CPWL_EditCtrl::GetTotalWords() const
-{
- if (m_pEdit)
- return m_pEdit->GetTotalWords();
-
- return 0;
-}
-
-void CPWL_EditCtrl::SetScrollPos(const CPDF_Point& point)
-{
- if (m_pEdit)
- m_pEdit->SetScrollPos(point);
-}
-
-CPDF_Point CPWL_EditCtrl::GetScrollPos() const
-{
- if (m_pEdit)
- return m_pEdit->GetScrollPos();
-
- return CPDF_Point(0.0f, 0.0f);
-}
-
-CPDF_Font * CPWL_EditCtrl::GetCaretFont() const
-{
- FX_INT32 nFontIndex = 0;
-
- if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
- {
- pIterator->SetAt(m_pEdit->GetCaret());
- CPVT_Word word;
- CPVT_Section section;
- if (pIterator->GetWord(word))
- {
- nFontIndex = word.nFontIndex;
- }
- else if (HasFlag(PES_RICH))
- {
- if (pIterator->GetSection(section))
- {
- nFontIndex = section.WordProps.nFontIndex;
- }
- }
- }
-
- if (IFX_Edit_FontMap * pFontMap = GetFontMap())
- return pFontMap->GetPDFFont(nFontIndex);
- else
- return NULL;
-}
-
-FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const
-{
- FX_FLOAT fFontSize = GetFontSize();
-
- if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
- {
- pIterator->SetAt(m_pEdit->GetCaret());
- CPVT_Word word;
- CPVT_Section section;
- if (pIterator->GetWord(word))
- {
- fFontSize = word.fFontSize;
- }
- else if (HasFlag(PES_RICH))
- {
- if (pIterator->GetSection(section))
- {
- fFontSize = section.WordProps.fFontSize;
- }
- }
- }
-
- return fFontSize;
-}
-
-void CPWL_EditCtrl::SetText(FX_LPCWSTR csText)
-{
- m_pEdit->SetText(csText);
-}
-
-void CPWL_EditCtrl::CopyText()
-{
-}
-
-void CPWL_EditCtrl::PasteText()
-{
-}
-
-void CPWL_EditCtrl::CutText()
-{
-}
-
-void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow)
-{
-}
-
-void CPWL_EditCtrl::InsertText(FX_LPCWSTR csText)
-{
- if (!IsReadOnly())
- m_pEdit->InsertText(csText);
-}
-
-void CPWL_EditCtrl::InsertWord(FX_WORD word, FX_INT32 nCharset)
-{
- if (!IsReadOnly())
- m_pEdit->InsertWord(word, nCharset);
-}
-
-void CPWL_EditCtrl::InsertReturn()
-{
- if (!IsReadOnly())
- m_pEdit->InsertReturn();
-}
-
-void CPWL_EditCtrl::Delete()
-{
- if (!IsReadOnly())
- m_pEdit->Delete();
-}
-
-void CPWL_EditCtrl::Backspace()
-{
- if (!IsReadOnly())
- m_pEdit->Backspace();
-}
-
-FX_BOOL CPWL_EditCtrl::CanUndo() const
-{
- return !IsReadOnly() && m_pEdit->CanUndo();
-}
-
-FX_BOOL CPWL_EditCtrl::CanRedo() const
-{
- return !IsReadOnly() && m_pEdit->CanRedo();
-}
-
-void CPWL_EditCtrl::Redo()
-{
- if (CanRedo())
- m_pEdit->Redo();
-}
-
-void CPWL_EditCtrl::Undo()
-{
- if (CanUndo())
- m_pEdit->Undo();
-}
-
-void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin, FX_FLOAT fPlateMax,
- FX_FLOAT fContentMin, FX_FLOAT fContentMax,
- FX_FLOAT fSmallStep, FX_FLOAT fBigStep)
-{
- PWL_SCROLL_INFO Info;
-
- Info.fPlateWidth = fPlateMax - fPlateMin;
- Info.fContentMin = fContentMin;
- Info.fContentMax = fContentMax;
- Info.fSmallStep = fSmallStep;
- Info.fBigStep = fBigStep;
-
- this->OnNotify(this,PNM_SETSCROLLINFO,SBT_VSCROLL,(FX_INTPTR)&Info);
-
-// PWL_TRACE("set scroll info:%f\n",fContentMax - fContentMin);
-
- if (IsFloatBigger(Info.fPlateWidth,Info.fContentMax-Info.fContentMin)
- || IsFloatEqual(Info.fPlateWidth,Info.fContentMax-Info.fContentMin))
- {
- this->ShowVScrollBar(FALSE);
- }
- else
- {
- this->ShowVScrollBar(TRUE);
- }
-}
-
-void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy)
-{
-// PWL_TRACE("set scroll position:%f\n",fy);
- this->OnNotify(this,PNM_SETSCROLLPOS,SBT_VSCROLL,(FX_INTPTR)&fy);
-}
-
-void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot, const CPVT_WordPlace& place)
-{
- PWL_CARET_INFO cInfo;
- cInfo.bVisible = bVisible;
- cInfo.ptHead = ptHead;
- cInfo.ptFoot = ptFoot;
-
- this->OnNotify(this,PNM_SETCARETINFO,(FX_INTPTR)&cInfo,(FX_INTPTR)NULL);
-}
-
-void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps & secProps, const CPVT_WordProps & wordProps)
-{
-}
-
-void CPWL_EditCtrl::IOnContentChange(const CPDF_Rect& rcContent)
-{
- if (this->IsValid())
- {
- if (m_pEditNotify)
- {
- m_pEditNotify->OnContentChange(rcContent);
- }
- }
-}
-
-void CPWL_EditCtrl::IOnInvalidateRect(CPDF_Rect * pRect)
-{
- this->InvalidateRect(pRect);
-}
-
-FX_INT32 CPWL_EditCtrl::GetCharSet() const
-{
- if (m_nCharSet < 0)
- return DEFAULT_CHARSET;
- else
- return m_nCharSet;
-}
-
-void CPWL_EditCtrl::GetTextRange(const CPDF_Rect& rect, FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
-{
- nStartChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.left, rect.top)));
- nEndChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.right, rect.bottom)));
-}
-
-CFX_WideString CPWL_EditCtrl::GetText(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
-{
- CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
- CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
- return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
-}
-
-void CPWL_EditCtrl::SetReadyToInput()
-{
- if (m_bMouseDown)
- {
- ReleaseCapture();
- m_bMouseDown = FALSE;
- }
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_EditCtrl.h"
+#include "../../include/pdfwindow/PWL_ScrollBar.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+#include "../../include/pdfwindow/PWL_Caret.h"
+#include "../../include/pdfwindow/PWL_FontMap.h"
+
+#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
+#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
+
+/* ---------------------------- CPWL_EditCtrl ------------------------------ */
+
+CPWL_EditCtrl::CPWL_EditCtrl() :
+ m_pEdit(NULL),
+ m_pEditCaret(NULL),
+ m_bMouseDown(FALSE),
+ m_pEditNotify(NULL),
+ m_nCharSet(DEFAULT_CHARSET),
+ m_nCodePage(0)
+{
+ m_pEdit = IFX_Edit::NewEdit();
+ ASSERT(m_pEdit != NULL);
+}
+
+CPWL_EditCtrl::~CPWL_EditCtrl()
+{
+ IFX_Edit::DelEdit(m_pEdit);
+}
+
+void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM & cp)
+{
+ cp.eCursorType = FXCT_VBEAM;
+}
+
+void CPWL_EditCtrl::OnCreated()
+{
+ SetFontSize(this->GetCreationParam().fFontSize);
+
+ m_pEdit->SetFontMap(this->GetFontMap());
+ m_pEdit->SetNotify(this);
+ m_pEdit->Initialize();
+}
+
+FX_BOOL CPWL_EditCtrl::IsWndHorV()
+{
+ CPDF_Matrix mt = GetWindowMatrix();
+ CPDF_Point point1(0,1);
+ CPDF_Point point2(1,1);
+
+ mt.Transform(point1.x, point1.y);
+ mt.Transform(point2.x, point2.y);
+
+ return point2.y == point1.y;
+}
+
+void CPWL_EditCtrl::SetCursor()
+{
+ if (IsValid())
+ {
+ if (IFX_SystemHandler* pSH = GetSystemHandler())
+ {
+ if (IsWndHorV())
+ pSH->SetCursor(FXCT_VBEAM);
+ else
+ pSH->SetCursor(FXCT_HBEAM);
+ }
+ }
+}
+
+void CPWL_EditCtrl::RePosChildWnd()
+{
+ m_pEdit->SetPlateRect(GetClientRect());
+}
+
+void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
+
+ switch (msg)
+ {
+ case PNM_SETSCROLLINFO:
+ switch (wParam)
+ {
+ case SBT_VSCROLL:
+ if (CPWL_Wnd * pChild = GetVScrollBar())
+ {
+ pChild->OnNotify(pWnd,PNM_SETSCROLLINFO,wParam,lParam);
+ }
+ break;
+ }
+ break;
+ case PNM_SETSCROLLPOS:
+ switch (wParam)
+ {
+ case SBT_VSCROLL:
+ if (CPWL_Wnd * pChild = GetVScrollBar())
+ {
+ pChild->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);
+ }
+ break;
+ }
+ break;
+ case PNM_SCROLLWINDOW:
+ {
+ FX_FLOAT fPos = *(FX_FLOAT*)lParam;
+ switch (wParam)
+ {
+ case SBT_VSCROLL:
+ m_pEdit->SetScrollPos(CPDF_Point(m_pEdit->GetScrollPos().x,fPos));
+ break;
+ }
+ }
+ break;
+ case PNM_SETCARETINFO:
+ {
+ if (PWL_CARET_INFO * pCaretInfo = (PWL_CARET_INFO *)wParam)
+ {
+ this->SetCaret(pCaretInfo->bVisible,
+ pCaretInfo->ptHead,
+ pCaretInfo->ptFoot);
+ }
+ }
+ break;
+ }
+}
+
+void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ if (!IsReadOnly())
+ CreateEditCaret(cp);
+}
+
+void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM & cp)
+{
+ if (!m_pEditCaret)
+ {
+ m_pEditCaret = new CPWL_Caret;
+ m_pEditCaret->SetInvalidRect(GetClientRect());
+
+ PWL_CREATEPARAM ecp = cp;
+ ecp.pParentWnd = this;
+ ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
+ ecp.dwBorderWidth = 0;
+ ecp.nBorderStyle = PBS_SOLID;
+ ecp.rcRectWnd = CPDF_Rect(0,0,0,0);
+
+ m_pEditCaret->Create(ecp);
+ }
+}
+
+void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize)
+{
+ m_pEdit->SetFontSize(fFontSize);
+}
+
+FX_FLOAT CPWL_EditCtrl::GetFontSize() const
+{
+ return m_pEdit->GetFontSize();
+}
+
+FX_BOOL CPWL_EditCtrl::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
+{
+ if (m_bMouseDown) return TRUE;
+
+ FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar,nFlag);
+
+ //FILTER
+ switch (nChar)
+ {
+ default:
+ return FALSE;
+ case FWL_VKEY_Delete:
+ case FWL_VKEY_Up:
+ case FWL_VKEY_Down:
+ case FWL_VKEY_Left:
+ case FWL_VKEY_Right:
+ case FWL_VKEY_Home:
+ case FWL_VKEY_End:
+ case FWL_VKEY_Insert:
+ case 'C':
+ case 'V':
+ case 'X':
+ case 'A':
+ case 'Z':
+ case 'c':
+ case 'v':
+ case 'x':
+ case 'a':
+ case 'z':
+ break;
+ }
+
+ if (nChar == FWL_VKEY_Delete)
+ {
+ if (m_pEdit->IsSelected())
+ nChar = FWL_VKEY_Unknown;
+ }
+
+ switch (nChar)
+ {
+ case FWL_VKEY_Delete:
+ Delete();
+ return TRUE;
+ case FWL_VKEY_Insert:
+ if (IsSHIFTpressed(nFlag))
+ PasteText();
+ return TRUE;
+ case FWL_VKEY_Up:
+ m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag),FALSE);
+ return TRUE;
+ case FWL_VKEY_Down:
+ m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag),FALSE);
+ return TRUE;
+ case FWL_VKEY_Left:
+ m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag),FALSE);
+ return TRUE;
+ case FWL_VKEY_Right:
+ m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag),FALSE);
+ return TRUE;
+ case FWL_VKEY_Home:
+ m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ return TRUE;
+ case FWL_VKEY_End:
+ m_pEdit->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ return TRUE;
+ case FWL_VKEY_Unknown:
+ if (!IsSHIFTpressed(nFlag))
+ Clear();
+ else
+ CutText();
+ return TRUE;
+ default:
+ break;
+ }
+
+ return bRet;
+}
+
+FX_BOOL CPWL_EditCtrl::OnChar(FX_WORD nChar, FX_DWORD nFlag)
+{
+ if (m_bMouseDown) return TRUE;
+
+ CPWL_Wnd::OnChar(nChar,nFlag);
+
+ //FILTER
+ switch (nChar)
+ {
+ case 0x0A:
+ case 0x1B:
+ return FALSE;
+ default:
+ break;
+ }
+
+ FX_BOOL bCtrl = IsCTRLpressed(nFlag);
+ FX_BOOL bAlt = IsALTpressed(nFlag);
+ FX_BOOL bShift = IsSHIFTpressed(nFlag);
+
+ FX_WORD word = nChar;
+
+ if (bCtrl && !bAlt)
+ {
+ switch (nChar)
+ {
+ case 'C' - 'A' + 1:
+ this->CopyText();
+ return TRUE;
+ case 'V' - 'A' + 1:
+ this->PasteText();
+ return TRUE;
+ case 'X' - 'A' + 1:
+ this->CutText();
+ return TRUE;
+ case 'A' - 'A' + 1:
+ this->SelectAll();
+ return TRUE;
+ case 'Z' - 'A' + 1:
+ if (bShift)
+ Redo();
+ else
+ Undo();
+ return TRUE;
+ default:
+ if (nChar < 32)
+ return FALSE;
+ }
+ }
+
+ if (IsReadOnly()) return TRUE;
+
+ if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
+ word = FWL_VKEY_Unknown;
+
+ Clear();
+
+ switch (word)
+ {
+ case FWL_VKEY_Back:
+ Backspace();
+ break;
+ case FWL_VKEY_Return:
+ InsertReturn();
+ break;
+ case FWL_VKEY_Unknown:
+ break;
+ default:
+ if (IsINSERTpressed(nFlag))
+ Delete();
+ InsertWord(word, this->GetCharSet());
+ break;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonDown(point,nFlag);
+
+ if (ClientHitTest(point))
+ {
+ if (m_bMouseDown)
+ this->InvalidateRect();
+
+ m_bMouseDown = TRUE;
+ SetCapture();
+
+ m_pEdit->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonUp(point,nFlag);
+
+ if (m_bMouseDown)
+ {
+ //can receive keybord message
+ if (ClientHitTest(point) && !this->IsFocused())
+ SetFocus();
+
+ ReleaseCapture();
+ m_bMouseDown = FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_EditCtrl::OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnMouseMove(point,nFlag);
+
+ if (m_bMouseDown)
+ m_pEdit->OnMouseMove(point,FALSE,FALSE);
+
+ return TRUE;
+}
+
+CPDF_Rect CPWL_EditCtrl::GetContentRect() const
+{
+ return m_pEdit->GetContentRect();
+}
+
+void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible)
+{
+ CPDF_Point ptHead(0,0),ptFoot(0,0);
+
+ if (bVisible)
+ {
+ GetCaretInfo(ptHead,ptFoot);
+ }
+
+ CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
+ this->IOnSetCaret(bVisible,ptHead,ptFoot,wpTemp);
+}
+
+void CPWL_EditCtrl::GetCaretInfo(CPDF_Point & ptHead, CPDF_Point & ptFoot) const
+{
+ if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
+ {
+ pIterator->SetAt(m_pEdit->GetCaret());
+ CPVT_Word word;
+ CPVT_Line line;
+ if (pIterator->GetWord(word))
+ {
+ ptHead.x = word.ptWord.x + word.fWidth;
+ ptHead.y = word.ptWord.y + word.fAscent;
+ ptFoot.x = word.ptWord.x + word.fWidth;
+ ptFoot.y = word.ptWord.y + word.fDescent;
+ }
+ else if (pIterator->GetLine(line))
+ {
+ ptHead.x = line.ptLine.x;
+ ptHead.y = line.ptLine.y + line.fLineAscent;
+ ptFoot.x = line.ptLine.x;
+ ptFoot.y = line.ptLine.y + line.fLineDescent;
+ }
+ }
+}
+
+void CPWL_EditCtrl::GetCaretPos(FX_INT32& x, FX_INT32& y) const
+{
+ CPDF_Point ptHead(0,0), ptFoot(0,0);
+
+ GetCaretInfo(ptHead,ptFoot);
+
+ PWLtoWnd(ptHead, x, y);
+}
+
+void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot)
+{
+ if (m_pEditCaret)
+ {
+ if (!IsFocused() || m_pEdit->IsSelected())
+ bVisible = FALSE;
+
+ m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
+ }
+}
+
+FX_BOOL CPWL_EditCtrl::IsModified() const
+{
+ return m_pEdit->IsModified();
+}
+
+CFX_WideString CPWL_EditCtrl::GetText() const
+{
+ return m_pEdit->GetText();
+}
+
+void CPWL_EditCtrl::SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar)
+{
+ m_pEdit->SetSel(nStartChar, nEndChar);
+}
+
+void CPWL_EditCtrl::GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar ) const
+{
+ m_pEdit->GetSel(nStartChar, nEndChar);
+}
+
+void CPWL_EditCtrl::Clear()
+{
+ if (!IsReadOnly())
+ m_pEdit->Clear();
+}
+
+void CPWL_EditCtrl::SelectAll()
+{
+ m_pEdit->SelectAll();
+}
+
+void CPWL_EditCtrl::Paint()
+{
+ if (m_pEdit)
+ m_pEdit->Paint();
+}
+
+void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh)
+{
+ if (m_pEdit)
+ m_pEdit->EnableRefresh(bRefresh);
+}
+
+FX_INT32 CPWL_EditCtrl::GetCaret() const
+{
+ if (m_pEdit)
+ return m_pEdit->GetCaret();
+
+ return -1;
+}
+
+void CPWL_EditCtrl::SetCaret(FX_INT32 nPos)
+{
+ if (m_pEdit)
+ m_pEdit->SetCaret(nPos);
+}
+
+FX_INT32 CPWL_EditCtrl::GetTotalWords() const
+{
+ if (m_pEdit)
+ return m_pEdit->GetTotalWords();
+
+ return 0;
+}
+
+void CPWL_EditCtrl::SetScrollPos(const CPDF_Point& point)
+{
+ if (m_pEdit)
+ m_pEdit->SetScrollPos(point);
+}
+
+CPDF_Point CPWL_EditCtrl::GetScrollPos() const
+{
+ if (m_pEdit)
+ return m_pEdit->GetScrollPos();
+
+ return CPDF_Point(0.0f, 0.0f);
+}
+
+CPDF_Font * CPWL_EditCtrl::GetCaretFont() const
+{
+ FX_INT32 nFontIndex = 0;
+
+ if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
+ {
+ pIterator->SetAt(m_pEdit->GetCaret());
+ CPVT_Word word;
+ CPVT_Section section;
+ if (pIterator->GetWord(word))
+ {
+ nFontIndex = word.nFontIndex;
+ }
+ else if (HasFlag(PES_RICH))
+ {
+ if (pIterator->GetSection(section))
+ {
+ nFontIndex = section.WordProps.nFontIndex;
+ }
+ }
+ }
+
+ if (IFX_Edit_FontMap * pFontMap = GetFontMap())
+ return pFontMap->GetPDFFont(nFontIndex);
+ else
+ return NULL;
+}
+
+FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const
+{
+ FX_FLOAT fFontSize = GetFontSize();
+
+ if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
+ {
+ pIterator->SetAt(m_pEdit->GetCaret());
+ CPVT_Word word;
+ CPVT_Section section;
+ if (pIterator->GetWord(word))
+ {
+ fFontSize = word.fFontSize;
+ }
+ else if (HasFlag(PES_RICH))
+ {
+ if (pIterator->GetSection(section))
+ {
+ fFontSize = section.WordProps.fFontSize;
+ }
+ }
+ }
+
+ return fFontSize;
+}
+
+void CPWL_EditCtrl::SetText(FX_LPCWSTR csText)
+{
+ m_pEdit->SetText(csText);
+}
+
+void CPWL_EditCtrl::CopyText()
+{
+}
+
+void CPWL_EditCtrl::PasteText()
+{
+}
+
+void CPWL_EditCtrl::CutText()
+{
+}
+
+void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow)
+{
+}
+
+void CPWL_EditCtrl::InsertText(FX_LPCWSTR csText)
+{
+ if (!IsReadOnly())
+ m_pEdit->InsertText(csText);
+}
+
+void CPWL_EditCtrl::InsertWord(FX_WORD word, FX_INT32 nCharset)
+{
+ if (!IsReadOnly())
+ m_pEdit->InsertWord(word, nCharset);
+}
+
+void CPWL_EditCtrl::InsertReturn()
+{
+ if (!IsReadOnly())
+ m_pEdit->InsertReturn();
+}
+
+void CPWL_EditCtrl::Delete()
+{
+ if (!IsReadOnly())
+ m_pEdit->Delete();
+}
+
+void CPWL_EditCtrl::Backspace()
+{
+ if (!IsReadOnly())
+ m_pEdit->Backspace();
+}
+
+FX_BOOL CPWL_EditCtrl::CanUndo() const
+{
+ return !IsReadOnly() && m_pEdit->CanUndo();
+}
+
+FX_BOOL CPWL_EditCtrl::CanRedo() const
+{
+ return !IsReadOnly() && m_pEdit->CanRedo();
+}
+
+void CPWL_EditCtrl::Redo()
+{
+ if (CanRedo())
+ m_pEdit->Redo();
+}
+
+void CPWL_EditCtrl::Undo()
+{
+ if (CanUndo())
+ m_pEdit->Undo();
+}
+
+void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin, FX_FLOAT fPlateMax,
+ FX_FLOAT fContentMin, FX_FLOAT fContentMax,
+ FX_FLOAT fSmallStep, FX_FLOAT fBigStep)
+{
+ PWL_SCROLL_INFO Info;
+
+ Info.fPlateWidth = fPlateMax - fPlateMin;
+ Info.fContentMin = fContentMin;
+ Info.fContentMax = fContentMax;
+ Info.fSmallStep = fSmallStep;
+ Info.fBigStep = fBigStep;
+
+ this->OnNotify(this,PNM_SETSCROLLINFO,SBT_VSCROLL,(FX_INTPTR)&Info);
+
+// PWL_TRACE("set scroll info:%f\n",fContentMax - fContentMin);
+
+ if (IsFloatBigger(Info.fPlateWidth,Info.fContentMax-Info.fContentMin)
+ || IsFloatEqual(Info.fPlateWidth,Info.fContentMax-Info.fContentMin))
+ {
+ this->ShowVScrollBar(FALSE);
+ }
+ else
+ {
+ this->ShowVScrollBar(TRUE);
+ }
+}
+
+void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy)
+{
+// PWL_TRACE("set scroll position:%f\n",fy);
+ this->OnNotify(this,PNM_SETSCROLLPOS,SBT_VSCROLL,(FX_INTPTR)&fy);
+}
+
+void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot, const CPVT_WordPlace& place)
+{
+ PWL_CARET_INFO cInfo;
+ cInfo.bVisible = bVisible;
+ cInfo.ptHead = ptHead;
+ cInfo.ptFoot = ptFoot;
+
+ this->OnNotify(this,PNM_SETCARETINFO,(FX_INTPTR)&cInfo,(FX_INTPTR)NULL);
+}
+
+void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps & secProps, const CPVT_WordProps & wordProps)
+{
+}
+
+void CPWL_EditCtrl::IOnContentChange(const CPDF_Rect& rcContent)
+{
+ if (this->IsValid())
+ {
+ if (m_pEditNotify)
+ {
+ m_pEditNotify->OnContentChange(rcContent);
+ }
+ }
+}
+
+void CPWL_EditCtrl::IOnInvalidateRect(CPDF_Rect * pRect)
+{
+ this->InvalidateRect(pRect);
+}
+
+FX_INT32 CPWL_EditCtrl::GetCharSet() const
+{
+ if (m_nCharSet < 0)
+ return DEFAULT_CHARSET;
+ else
+ return m_nCharSet;
+}
+
+void CPWL_EditCtrl::GetTextRange(const CPDF_Rect& rect, FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
+{
+ nStartChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.left, rect.top)));
+ nEndChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.right, rect.bottom)));
+}
+
+CFX_WideString CPWL_EditCtrl::GetText(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
+{
+ CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
+ CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
+ return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
+}
+
+void CPWL_EditCtrl::SetReadyToInput()
+{
+ if (m_bMouseDown)
+ {
+ ReleaseCapture();
+ m_bMouseDown = FALSE;
+ }
+}
diff --git a/fpdfsdk/src/pdfwindow/PWL_FontMap.cpp b/fpdfsdk/src/pdfwindow/PWL_FontMap.cpp
index 1e2259fe50..c656f0c15e 100644
--- a/fpdfsdk/src/pdfwindow/PWL_FontMap.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_FontMap.cpp
@@ -1,601 +1,601 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_FontMap.h"
-
-#define DEFAULT_FONT_NAME "Helvetica"
-
-/* ------------------------------ CPWL_FontMap ------------------------------ */
-
-CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler) :
- m_pPDFDoc(NULL),
- m_pSystemHandler(pSystemHandler)
-{
- ASSERT(m_pSystemHandler != NULL);
-}
-
-CPWL_FontMap::~CPWL_FontMap()
-{
- if (m_pPDFDoc)
- {
- delete m_pPDFDoc;
- m_pPDFDoc = NULL;
- }
-
- Empty();
-}
-
-void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler)
-{
- m_pSystemHandler = pSystemHandler;
-}
-
-CPDF_Document* CPWL_FontMap::GetDocument()
-{
- if (!m_pPDFDoc)
- {
- if (CPDF_ModuleMgr::Get())
- {
- m_pPDFDoc = FX_NEW CPDF_Document;
- m_pPDFDoc->CreateNewDoc();
- }
- }
-
- return m_pPDFDoc;
-}
-
-CPDF_Font* CPWL_FontMap::GetPDFFont(FX_INT32 nFontIndex)
-{
- if (nFontIndex >=0 && nFontIndex < m_aData.GetSize())
- {
- if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
- {
- return pData->pFont;
- }
- }
-
- return NULL;
-}
-
-CFX_ByteString CPWL_FontMap::GetPDFFontAlias(FX_INT32 nFontIndex)
-{
- if (nFontIndex >=0 && nFontIndex < m_aData.GetSize())
- {
- if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
- {
- return pData->sFontName;
- }
- }
-
- return "";
-}
-
-FX_BOOL CPWL_FontMap::KnowWord(FX_INT32 nFontIndex, FX_WORD word)
-{
- if (nFontIndex >=0 && nFontIndex < m_aData.GetSize())
- {
- if (m_aData.GetAt(nFontIndex))
- {
- return CharCodeFromUnicode(nFontIndex, word) >= 0;
- }
- }
-
- return FALSE;
-}
-
-FX_INT32 CPWL_FontMap::GetWordFontIndex(FX_WORD word, FX_INT32 nCharset, FX_INT32 nFontIndex)
-{
- if (nFontIndex > 0)
- {
- if (KnowWord(nFontIndex, word))
- return nFontIndex;
- }
- else
- {
- if (const CPWL_FontMap_Data* pData = GetFontMapData(0))
- {
- if (nCharset == DEFAULT_CHARSET ||
- pData->nCharset == SYMBOL_CHARSET ||
- nCharset == pData->nCharset)
- {
- if (KnowWord(0, word))
- {
- return 0;
- }
- }
- }
- }
-
- FX_INT32 nNewFontIndex = -1;
-
- nNewFontIndex = this->GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE);
- if (nNewFontIndex >= 0)
- {
- if (KnowWord(nNewFontIndex, word))
- return nNewFontIndex;
- }
-
- nNewFontIndex = this->GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE);
- if (nNewFontIndex >= 0)
- {
- if (KnowWord(nNewFontIndex, word))
- return nNewFontIndex;
- }
-
- return -1;
-}
-
-FX_INT32 CPWL_FontMap::CharCodeFromUnicode(FX_INT32 nFontIndex, FX_WORD word)
-{
- if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
- {
- if (pData->pFont)
- {
- if (pData->pFont->IsUnicodeCompatible())
- {
- int nCharCode = pData->pFont->CharCodeFromUnicode(word);
- pData->pFont->GlyphFromCharCode(nCharCode);
- return nCharCode;
- }
- else
- {
- if (word < 0xFF)
- return word;
- }
- }
- }
-
- return -1;
-}
-
-CFX_ByteString CPWL_FontMap::GetNativeFontName(FX_INT32 nCharset)
-{
- //searching native font is slow, so we must save time
- for (FX_INT32 i=0,sz=m_aNativeFont.GetSize(); i<sz; i++)
- {
- if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i))
- {
- if (pData->nCharset == nCharset)
- return pData->sFontName;
- }
- }
-
- CFX_ByteString sNew = GetNativeFont(nCharset);
-
- if (!sNew.IsEmpty())
- {
- CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native;
- pNewData->nCharset = nCharset;
- pNewData->sFontName = sNew;
-
- m_aNativeFont.Add(pNewData);
- }
-
- return sNew;
-}
-
-void CPWL_FontMap::Empty()
-{
- {
- for (FX_INT32 i=0, sz=m_aData.GetSize(); i<sz; i++)
- delete m_aData.GetAt(i);
-
- m_aData.RemoveAll();
- }
- {
- for (FX_INT32 i=0, sz=m_aNativeFont.GetSize(); i<sz; i++)
- delete m_aNativeFont.GetAt(i);
-
- m_aNativeFont.RemoveAll();
- }
-}
-
-void CPWL_FontMap::Initial(FX_LPCSTR fontname)
-{
- CFX_ByteString sFontName = fontname;
-
- if (sFontName.IsEmpty())
- sFontName = DEFAULT_FONT_NAME;
-
- GetFontIndex(sFontName, ANSI_CHARSET, FALSE);
-
- //GetFontIndex(this->GetNativeFontName(nCharset), nCharset);
-}
-
-
-/*
-List of currently supported standard fonts:
-Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique
-Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique
-Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
-Symbol, ZapfDingbats
-*/
-
-const char* g_sDEStandardFontName[] = {"Courier", "Courier-Bold", "Courier-BoldOblique", "Courier-Oblique",
- "Helvetica", "Helvetica-Bold", "Helvetica-BoldOblique", "Helvetica-Oblique",
- "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",
- "Symbol", "ZapfDingbats"};
-
-FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName)
-{
- for (FX_INT32 i=0; i<14; i++)
- {
- if (sFontName == g_sDEStandardFontName[i])
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_INT32 CPWL_FontMap::FindFont(const CFX_ByteString& sFontName, FX_INT32 nCharset)
-{
- for (FX_INT32 i=0,sz=m_aData.GetSize(); i<sz; i++)
- {
- if (CPWL_FontMap_Data* pData = m_aData.GetAt(i))
- {
- if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset)
- {
- if (sFontName.IsEmpty() || pData->sFontName == sFontName)
- return i;
- }
- }
- }
-
- return -1;
-}
-
-FX_INT32 CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, FX_INT32 nCharset, FX_BOOL bFind)
-{
- FX_INT32 nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
- if (nFontIndex >= 0) return nFontIndex;
-
-// nFontIndex = FindFont("", nCharset);
-// if (nFontIndex >= 0) return nFontIndex;
-
- CFX_ByteString sAlias;
- CPDF_Font* pFont = NULL;
-
- if (bFind)
- pFont = FindFontSameCharset(sAlias, nCharset);
-
- if (!pFont)
- {
- CFX_ByteString sTemp = sFontName;
- pFont = AddFontToDocument(GetDocument(), sTemp, nCharset);
-
- /*
- if (FindFont(sAlias))
- {
- sAlias = EncodeFontAlias(sTemp, nCharset);
- }
- else
- */
- {
- sAlias = EncodeFontAlias(sTemp, nCharset);
- }
- }
-
- AddedFont(pFont, sAlias);
-
- return AddFontData(pFont, sAlias, nCharset);
-}
-
-FX_INT32 CPWL_FontMap::GetPWLFontIndex(FX_WORD word, FX_INT32 nCharset)
-{
- FX_INT32 nFind = -1;
-
- for (FX_INT32 i=0,sz=m_aData.GetSize(); i<sz; i++)
- {
- if (CPWL_FontMap_Data* pData = m_aData.GetAt(i))
- {
- if (pData->nCharset == nCharset)
- {
- nFind = i;
- break;
- }
- }
- }
-
- CPDF_Font* pNewFont = GetPDFFont(nFind);
-
- if (!pNewFont) return -1;
-
- /*
- if (CPDF_Font* pFont = GetPDFFont(nFind))
- {
- PWLFont.AddWordToFontDict(pFontDict, word);
- }
- */
-
-#ifdef FOXIT_CHROME_BUILD
- CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset);
-#else
- CFX_ByteString sAlias = EncodeFontAlias("Arial_Foxit", nCharset);
-#endif
- AddedFont(pNewFont, sAlias);
-
- return AddFontData(pNewFont, sAlias, nCharset);
-}
-
-CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, FX_INT32 nCharset)
-{
- return NULL;
-}
-
-FX_INT32 CPWL_FontMap::AddFontData(CPDF_Font* pFont, const CFX_ByteString& sFontAlias, FX_INT32 nCharset)
-{
- CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data;
- pNewData->pFont = pFont;
- pNewData->sFontName = sFontAlias;
- pNewData->nCharset = nCharset;
-
- m_aData.Add(pNewData);
-
- return m_aData.GetSize() -1;
-}
-
-void CPWL_FontMap::AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias)
-{
-}
-
-CFX_ByteString CPWL_FontMap::GetFontName(FX_INT32 nFontIndex)
-{
- if (nFontIndex >=0 && nFontIndex < m_aData.GetSize())
- {
- if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
- {
- return pData->sFontName;
- }
- }
-
- return "";
-}
-
-CFX_ByteString CPWL_FontMap::GetNativeFont(FX_INT32 nCharset)
-{
- CFX_ByteString sFontName;
-
- if (nCharset == DEFAULT_CHARSET)
- nCharset = GetNativeCharset();
-
- sFontName = GetDefaultFontByCharset(nCharset);
-
- if (m_pSystemHandler)
- {
- if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName))
- return sFontName;
-
- sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset);
- }
-
- return sFontName;
-}
-
-CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc, CFX_ByteString& sFontName, FX_BYTE nCharset)
-{
- if (IsStandardFont(sFontName))
- return AddStandardFont(pDoc, sFontName);
- else
- return AddSystemFont(pDoc, sFontName, nCharset);
-}
-
-CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc, CFX_ByteString& sFontName)
-{
- if (!pDoc) return NULL;
-
- CPDF_Font* pFont = NULL;
-
- if (sFontName == "ZapfDingbats")
- pFont = pDoc->AddStandardFont(sFontName, NULL);
- else
- {
- CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI);
- pFont = pDoc->AddStandardFont(sFontName, &fe);
- }
-
- return pFont;
-}
-
-CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, CFX_ByteString& sFontName, FX_BYTE nCharset)
-{
- if (!pDoc) return NULL;
-
- if (sFontName.IsEmpty()) sFontName = GetNativeFont(nCharset);
- if (nCharset == DEFAULT_CHARSET) nCharset = GetNativeCharset();
-
- if (m_pSystemHandler)
- return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, nCharset);
-
- return NULL;
-}
-
-CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, FX_INT32 nCharset)
-{
- CFX_ByteString sPostfix;
- sPostfix.Format("_%02X", nCharset);
- return EncodeFontAlias(sFontName) + sPostfix;
-}
-
-CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName)
-{
- CFX_ByteString sRet = sFontName;
- sRet.Remove(' ');
- return sRet;
-}
-
-FX_INT32 CPWL_FontMap::GetFontMapCount() const
-{
- return m_aData.GetSize();
-}
-
-const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(FX_INT32 nIndex) const
-{
- if (nIndex >=0 && nIndex < m_aData.GetSize())
- {
- return m_aData.GetAt(nIndex);
- }
-
- return NULL;
-}
-
-FX_INT32 CPWL_FontMap::GetNativeCharset()
-{
- FX_BYTE nCharset = ANSI_CHARSET;
- FX_INT32 iCodePage = FXSYS_GetACP();
- switch (iCodePage)
- {
- case 932://Japan
- nCharset = SHIFTJIS_CHARSET;
- break;
- case 936://Chinese (PRC, Singapore)
- nCharset = GB2312_CHARSET;
- break;
- case 950://Chinese (Taiwan; Hong Kong SAR, PRC)
- nCharset = GB2312_CHARSET;
- break;
- case 1252://Windows 3.1 Latin 1 (US, Western Europe)
- nCharset = ANSI_CHARSET;
- break;
- case 874://Thai
- nCharset = THAI_CHARSET;
- break;
- case 949://Korean
- nCharset = HANGUL_CHARSET;
- break;
- case 1200://Unicode (BMP of ISO 10646)
- nCharset = ANSI_CHARSET;
- break;
- case 1250://Windows 3.1 Eastern European
- nCharset = EASTEUROPE_CHARSET;
- break;
- case 1251://Windows 3.1 Cyrillic
- nCharset = RUSSIAN_CHARSET;
- break;
- case 1253://Windows 3.1 Greek
- nCharset = GREEK_CHARSET;
- break;
- case 1254://Windows 3.1 Turkish
- nCharset = TURKISH_CHARSET;
- break;
- case 1255://Hebrew
- nCharset = HEBREW_CHARSET;
- break;
- case 1256://Arabic
- nCharset = ARABIC_CHARSET;
- break;
- case 1257://Baltic
- nCharset = BALTIC_CHARSET;
- break;
- case 1258://Vietnamese
- nCharset = VIETNAMESE_CHARSET;
- break;
- case 1361://Korean(Johab)
- nCharset = JOHAB_CHARSET;
- break;
- }
- return nCharset;
-}
-
-const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
- { ANSI_CHARSET, "Helvetica" },
- { GB2312_CHARSET, "SimSun" },
- { CHINESEBIG5_CHARSET, "MingLiU" },
- { SHIFTJIS_CHARSET, "MS Gothic" },
- { HANGUL_CHARSET, "Batang" },
- { RUSSIAN_CHARSET, "Arial" },
- { EASTEUROPE_CHARSET, "Tahoma" },
- { ARABIC_CHARSET, "Arial" },
- { -1, NULL }
-};
-
-CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(FX_INT32 nCharset)
-{
- int i = 0;
- while (defaultTTFMap[i].charset != -1) {
- if (nCharset == defaultTTFMap[i].charset)
- return defaultTTFMap[i].fontname;
- ++i;
- }
- return "";
-}
-
-FX_INT32 CPWL_FontMap::CharSetFromUnicode(FX_WORD word, FX_INT32 nOldCharset)
-{
- if(m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet()))
- return m_pSystemHandler->GetCharSet();
- //to avoid CJK Font to show ASCII
- if (word < 0x7F) return ANSI_CHARSET;
- //follow the old charset
- if (nOldCharset != DEFAULT_CHARSET) return nOldCharset;
-
- //find new charset
- if ((word >= 0x4E00 && word <= 0x9FA5) ||
- (word >= 0xE7C7 && word <= 0xE7F3) ||
- (word >= 0x3000 && word <= 0x303F) || //£©"¡¶" "¡·" "¡£" "¡¢"
- (word >= 0x2000 && word <= 0x206F))
- {
- return GB2312_CHARSET;
- }
-
- if (((word >= 0x3040) && (word <= 0x309F)) ||
- ((word >= 0x30A0) && (word <= 0x30FF)) ||
- ((word >= 0x31F0) && (word <= 0x31FF)) ||
- ((word >= 0xFF00) && (word <= 0xFFEF)) )
- {
- return SHIFTJIS_CHARSET;
- }
-
- if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
- ((word >= 0x1100) && (word <= 0x11FF)) ||
- ((word >= 0x3130) && (word <= 0x318F)))
- {
- return HANGUL_CHARSET;
- }
-
- if (word >= 0x0E00 && word <= 0x0E7F)
- return THAI_CHARSET;
-
- if ((word >= 0x0370 && word <= 0x03FF) ||
- (word >= 0x1F00 && word <= 0x1FFF))
- return GREEK_CHARSET;
-
- if ((word >= 0x0600 && word <= 0x06FF) ||
- (word >= 0xFB50 && word <= 0xFEFC))
- return ARABIC_CHARSET;
-
- if (word >= 0x0590 && word <= 0x05FF)
- return HEBREW_CHARSET;
-
- if (word >= 0x0400 && word <= 0x04FF)
- return RUSSIAN_CHARSET;
-
- if (word >= 0x0100 && word <= 0x024F)
- return EASTEUROPE_CHARSET;
-
- if (word >= 0x1E00 && word <= 0x1EFF)
- return VIETNAMESE_CHARSET;
-
- return ANSI_CHARSET;
-}
-
-/* ------------------------ CPWL_DocFontMap ------------------------ */
-
-CPWL_DocFontMap::CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler, CPDF_Document* pAttachedDoc)
- : CPWL_FontMap(pSystemHandler),
- m_pAttachedDoc(pAttachedDoc)
-{
-}
-
-CPWL_DocFontMap::~CPWL_DocFontMap()
-{
-}
-
-CPDF_Document* CPWL_DocFontMap::GetDocument()
-{
- return m_pAttachedDoc;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_FontMap.h"
+
+#define DEFAULT_FONT_NAME "Helvetica"
+
+/* ------------------------------ CPWL_FontMap ------------------------------ */
+
+CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler) :
+ m_pPDFDoc(NULL),
+ m_pSystemHandler(pSystemHandler)
+{
+ ASSERT(m_pSystemHandler != NULL);
+}
+
+CPWL_FontMap::~CPWL_FontMap()
+{
+ if (m_pPDFDoc)
+ {
+ delete m_pPDFDoc;
+ m_pPDFDoc = NULL;
+ }
+
+ Empty();
+}
+
+void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler)
+{
+ m_pSystemHandler = pSystemHandler;
+}
+
+CPDF_Document* CPWL_FontMap::GetDocument()
+{
+ if (!m_pPDFDoc)
+ {
+ if (CPDF_ModuleMgr::Get())
+ {
+ m_pPDFDoc = FX_NEW CPDF_Document;
+ m_pPDFDoc->CreateNewDoc();
+ }
+ }
+
+ return m_pPDFDoc;
+}
+
+CPDF_Font* CPWL_FontMap::GetPDFFont(FX_INT32 nFontIndex)
+{
+ if (nFontIndex >=0 && nFontIndex < m_aData.GetSize())
+ {
+ if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
+ {
+ return pData->pFont;
+ }
+ }
+
+ return NULL;
+}
+
+CFX_ByteString CPWL_FontMap::GetPDFFontAlias(FX_INT32 nFontIndex)
+{
+ if (nFontIndex >=0 && nFontIndex < m_aData.GetSize())
+ {
+ if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
+ {
+ return pData->sFontName;
+ }
+ }
+
+ return "";
+}
+
+FX_BOOL CPWL_FontMap::KnowWord(FX_INT32 nFontIndex, FX_WORD word)
+{
+ if (nFontIndex >=0 && nFontIndex < m_aData.GetSize())
+ {
+ if (m_aData.GetAt(nFontIndex))
+ {
+ return CharCodeFromUnicode(nFontIndex, word) >= 0;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_INT32 CPWL_FontMap::GetWordFontIndex(FX_WORD word, FX_INT32 nCharset, FX_INT32 nFontIndex)
+{
+ if (nFontIndex > 0)
+ {
+ if (KnowWord(nFontIndex, word))
+ return nFontIndex;
+ }
+ else
+ {
+ if (const CPWL_FontMap_Data* pData = GetFontMapData(0))
+ {
+ if (nCharset == DEFAULT_CHARSET ||
+ pData->nCharset == SYMBOL_CHARSET ||
+ nCharset == pData->nCharset)
+ {
+ if (KnowWord(0, word))
+ {
+ return 0;
+ }
+ }
+ }
+ }
+
+ FX_INT32 nNewFontIndex = -1;
+
+ nNewFontIndex = this->GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE);
+ if (nNewFontIndex >= 0)
+ {
+ if (KnowWord(nNewFontIndex, word))
+ return nNewFontIndex;
+ }
+
+ nNewFontIndex = this->GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE);
+ if (nNewFontIndex >= 0)
+ {
+ if (KnowWord(nNewFontIndex, word))
+ return nNewFontIndex;
+ }
+
+ return -1;
+}
+
+FX_INT32 CPWL_FontMap::CharCodeFromUnicode(FX_INT32 nFontIndex, FX_WORD word)
+{
+ if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
+ {
+ if (pData->pFont)
+ {
+ if (pData->pFont->IsUnicodeCompatible())
+ {
+ int nCharCode = pData->pFont->CharCodeFromUnicode(word);
+ pData->pFont->GlyphFromCharCode(nCharCode);
+ return nCharCode;
+ }
+ else
+ {
+ if (word < 0xFF)
+ return word;
+ }
+ }
+ }
+
+ return -1;
+}
+
+CFX_ByteString CPWL_FontMap::GetNativeFontName(FX_INT32 nCharset)
+{
+ //searching native font is slow, so we must save time
+ for (FX_INT32 i=0,sz=m_aNativeFont.GetSize(); i<sz; i++)
+ {
+ if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i))
+ {
+ if (pData->nCharset == nCharset)
+ return pData->sFontName;
+ }
+ }
+
+ CFX_ByteString sNew = GetNativeFont(nCharset);
+
+ if (!sNew.IsEmpty())
+ {
+ CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native;
+ pNewData->nCharset = nCharset;
+ pNewData->sFontName = sNew;
+
+ m_aNativeFont.Add(pNewData);
+ }
+
+ return sNew;
+}
+
+void CPWL_FontMap::Empty()
+{
+ {
+ for (FX_INT32 i=0, sz=m_aData.GetSize(); i<sz; i++)
+ delete m_aData.GetAt(i);
+
+ m_aData.RemoveAll();
+ }
+ {
+ for (FX_INT32 i=0, sz=m_aNativeFont.GetSize(); i<sz; i++)
+ delete m_aNativeFont.GetAt(i);
+
+ m_aNativeFont.RemoveAll();
+ }
+}
+
+void CPWL_FontMap::Initial(FX_LPCSTR fontname)
+{
+ CFX_ByteString sFontName = fontname;
+
+ if (sFontName.IsEmpty())
+ sFontName = DEFAULT_FONT_NAME;
+
+ GetFontIndex(sFontName, ANSI_CHARSET, FALSE);
+
+ //GetFontIndex(this->GetNativeFontName(nCharset), nCharset);
+}
+
+
+/*
+List of currently supported standard fonts:
+Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique
+Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique
+Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
+Symbol, ZapfDingbats
+*/
+
+const char* g_sDEStandardFontName[] = {"Courier", "Courier-Bold", "Courier-BoldOblique", "Courier-Oblique",
+ "Helvetica", "Helvetica-Bold", "Helvetica-BoldOblique", "Helvetica-Oblique",
+ "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",
+ "Symbol", "ZapfDingbats"};
+
+FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName)
+{
+ for (FX_INT32 i=0; i<14; i++)
+ {
+ if (sFontName == g_sDEStandardFontName[i])
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_INT32 CPWL_FontMap::FindFont(const CFX_ByteString& sFontName, FX_INT32 nCharset)
+{
+ for (FX_INT32 i=0,sz=m_aData.GetSize(); i<sz; i++)
+ {
+ if (CPWL_FontMap_Data* pData = m_aData.GetAt(i))
+ {
+ if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset)
+ {
+ if (sFontName.IsEmpty() || pData->sFontName == sFontName)
+ return i;
+ }
+ }
+ }
+
+ return -1;
+}
+
+FX_INT32 CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, FX_INT32 nCharset, FX_BOOL bFind)
+{
+ FX_INT32 nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
+ if (nFontIndex >= 0) return nFontIndex;
+
+// nFontIndex = FindFont("", nCharset);
+// if (nFontIndex >= 0) return nFontIndex;
+
+ CFX_ByteString sAlias;
+ CPDF_Font* pFont = NULL;
+
+ if (bFind)
+ pFont = FindFontSameCharset(sAlias, nCharset);
+
+ if (!pFont)
+ {
+ CFX_ByteString sTemp = sFontName;
+ pFont = AddFontToDocument(GetDocument(), sTemp, nCharset);
+
+ /*
+ if (FindFont(sAlias))
+ {
+ sAlias = EncodeFontAlias(sTemp, nCharset);
+ }
+ else
+ */
+ {
+ sAlias = EncodeFontAlias(sTemp, nCharset);
+ }
+ }
+
+ AddedFont(pFont, sAlias);
+
+ return AddFontData(pFont, sAlias, nCharset);
+}
+
+FX_INT32 CPWL_FontMap::GetPWLFontIndex(FX_WORD word, FX_INT32 nCharset)
+{
+ FX_INT32 nFind = -1;
+
+ for (FX_INT32 i=0,sz=m_aData.GetSize(); i<sz; i++)
+ {
+ if (CPWL_FontMap_Data* pData = m_aData.GetAt(i))
+ {
+ if (pData->nCharset == nCharset)
+ {
+ nFind = i;
+ break;
+ }
+ }
+ }
+
+ CPDF_Font* pNewFont = GetPDFFont(nFind);
+
+ if (!pNewFont) return -1;
+
+ /*
+ if (CPDF_Font* pFont = GetPDFFont(nFind))
+ {
+ PWLFont.AddWordToFontDict(pFontDict, word);
+ }
+ */
+
+#ifdef FOXIT_CHROME_BUILD
+ CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset);
+#else
+ CFX_ByteString sAlias = EncodeFontAlias("Arial_Foxit", nCharset);
+#endif
+ AddedFont(pNewFont, sAlias);
+
+ return AddFontData(pNewFont, sAlias, nCharset);
+}
+
+CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, FX_INT32 nCharset)
+{
+ return NULL;
+}
+
+FX_INT32 CPWL_FontMap::AddFontData(CPDF_Font* pFont, const CFX_ByteString& sFontAlias, FX_INT32 nCharset)
+{
+ CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data;
+ pNewData->pFont = pFont;
+ pNewData->sFontName = sFontAlias;
+ pNewData->nCharset = nCharset;
+
+ m_aData.Add(pNewData);
+
+ return m_aData.GetSize() -1;
+}
+
+void CPWL_FontMap::AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias)
+{
+}
+
+CFX_ByteString CPWL_FontMap::GetFontName(FX_INT32 nFontIndex)
+{
+ if (nFontIndex >=0 && nFontIndex < m_aData.GetSize())
+ {
+ if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
+ {
+ return pData->sFontName;
+ }
+ }
+
+ return "";
+}
+
+CFX_ByteString CPWL_FontMap::GetNativeFont(FX_INT32 nCharset)
+{
+ CFX_ByteString sFontName;
+
+ if (nCharset == DEFAULT_CHARSET)
+ nCharset = GetNativeCharset();
+
+ sFontName = GetDefaultFontByCharset(nCharset);
+
+ if (m_pSystemHandler)
+ {
+ if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName))
+ return sFontName;
+
+ sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset);
+ }
+
+ return sFontName;
+}
+
+CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc, CFX_ByteString& sFontName, FX_BYTE nCharset)
+{
+ if (IsStandardFont(sFontName))
+ return AddStandardFont(pDoc, sFontName);
+ else
+ return AddSystemFont(pDoc, sFontName, nCharset);
+}
+
+CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc, CFX_ByteString& sFontName)
+{
+ if (!pDoc) return NULL;
+
+ CPDF_Font* pFont = NULL;
+
+ if (sFontName == "ZapfDingbats")
+ pFont = pDoc->AddStandardFont(sFontName, NULL);
+ else
+ {
+ CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI);
+ pFont = pDoc->AddStandardFont(sFontName, &fe);
+ }
+
+ return pFont;
+}
+
+CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, CFX_ByteString& sFontName, FX_BYTE nCharset)
+{
+ if (!pDoc) return NULL;
+
+ if (sFontName.IsEmpty()) sFontName = GetNativeFont(nCharset);
+ if (nCharset == DEFAULT_CHARSET) nCharset = GetNativeCharset();
+
+ if (m_pSystemHandler)
+ return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, nCharset);
+
+ return NULL;
+}
+
+CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, FX_INT32 nCharset)
+{
+ CFX_ByteString sPostfix;
+ sPostfix.Format("_%02X", nCharset);
+ return EncodeFontAlias(sFontName) + sPostfix;
+}
+
+CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName)
+{
+ CFX_ByteString sRet = sFontName;
+ sRet.Remove(' ');
+ return sRet;
+}
+
+FX_INT32 CPWL_FontMap::GetFontMapCount() const
+{
+ return m_aData.GetSize();
+}
+
+const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(FX_INT32 nIndex) const
+{
+ if (nIndex >=0 && nIndex < m_aData.GetSize())
+ {
+ return m_aData.GetAt(nIndex);
+ }
+
+ return NULL;
+}
+
+FX_INT32 CPWL_FontMap::GetNativeCharset()
+{
+ FX_BYTE nCharset = ANSI_CHARSET;
+ FX_INT32 iCodePage = FXSYS_GetACP();
+ switch (iCodePage)
+ {
+ case 932://Japan
+ nCharset = SHIFTJIS_CHARSET;
+ break;
+ case 936://Chinese (PRC, Singapore)
+ nCharset = GB2312_CHARSET;
+ break;
+ case 950://Chinese (Taiwan; Hong Kong SAR, PRC)
+ nCharset = GB2312_CHARSET;
+ break;
+ case 1252://Windows 3.1 Latin 1 (US, Western Europe)
+ nCharset = ANSI_CHARSET;
+ break;
+ case 874://Thai
+ nCharset = THAI_CHARSET;
+ break;
+ case 949://Korean
+ nCharset = HANGUL_CHARSET;
+ break;
+ case 1200://Unicode (BMP of ISO 10646)
+ nCharset = ANSI_CHARSET;
+ break;
+ case 1250://Windows 3.1 Eastern European
+ nCharset = EASTEUROPE_CHARSET;
+ break;
+ case 1251://Windows 3.1 Cyrillic
+ nCharset = RUSSIAN_CHARSET;
+ break;
+ case 1253://Windows 3.1 Greek
+ nCharset = GREEK_CHARSET;
+ break;
+ case 1254://Windows 3.1 Turkish
+ nCharset = TURKISH_CHARSET;
+ break;
+ case 1255://Hebrew
+ nCharset = HEBREW_CHARSET;
+ break;
+ case 1256://Arabic
+ nCharset = ARABIC_CHARSET;
+ break;
+ case 1257://Baltic
+ nCharset = BALTIC_CHARSET;
+ break;
+ case 1258://Vietnamese
+ nCharset = VIETNAMESE_CHARSET;
+ break;
+ case 1361://Korean(Johab)
+ nCharset = JOHAB_CHARSET;
+ break;
+ }
+ return nCharset;
+}
+
+const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
+ { ANSI_CHARSET, "Helvetica" },
+ { GB2312_CHARSET, "SimSun" },
+ { CHINESEBIG5_CHARSET, "MingLiU" },
+ { SHIFTJIS_CHARSET, "MS Gothic" },
+ { HANGUL_CHARSET, "Batang" },
+ { RUSSIAN_CHARSET, "Arial" },
+ { EASTEUROPE_CHARSET, "Tahoma" },
+ { ARABIC_CHARSET, "Arial" },
+ { -1, NULL }
+};
+
+CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(FX_INT32 nCharset)
+{
+ int i = 0;
+ while (defaultTTFMap[i].charset != -1) {
+ if (nCharset == defaultTTFMap[i].charset)
+ return defaultTTFMap[i].fontname;
+ ++i;
+ }
+ return "";
+}
+
+FX_INT32 CPWL_FontMap::CharSetFromUnicode(FX_WORD word, FX_INT32 nOldCharset)
+{
+ if(m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet()))
+ return m_pSystemHandler->GetCharSet();
+ //to avoid CJK Font to show ASCII
+ if (word < 0x7F) return ANSI_CHARSET;
+ //follow the old charset
+ if (nOldCharset != DEFAULT_CHARSET) return nOldCharset;
+
+ //find new charset
+ if ((word >= 0x4E00 && word <= 0x9FA5) ||
+ (word >= 0xE7C7 && word <= 0xE7F3) ||
+ (word >= 0x3000 && word <= 0x303F) || //£©"¡¶" "¡·" "¡£" "¡¢"
+ (word >= 0x2000 && word <= 0x206F))
+ {
+ return GB2312_CHARSET;
+ }
+
+ if (((word >= 0x3040) && (word <= 0x309F)) ||
+ ((word >= 0x30A0) && (word <= 0x30FF)) ||
+ ((word >= 0x31F0) && (word <= 0x31FF)) ||
+ ((word >= 0xFF00) && (word <= 0xFFEF)) )
+ {
+ return SHIFTJIS_CHARSET;
+ }
+
+ if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
+ ((word >= 0x1100) && (word <= 0x11FF)) ||
+ ((word >= 0x3130) && (word <= 0x318F)))
+ {
+ return HANGUL_CHARSET;
+ }
+
+ if (word >= 0x0E00 && word <= 0x0E7F)
+ return THAI_CHARSET;
+
+ if ((word >= 0x0370 && word <= 0x03FF) ||
+ (word >= 0x1F00 && word <= 0x1FFF))
+ return GREEK_CHARSET;
+
+ if ((word >= 0x0600 && word <= 0x06FF) ||
+ (word >= 0xFB50 && word <= 0xFEFC))
+ return ARABIC_CHARSET;
+
+ if (word >= 0x0590 && word <= 0x05FF)
+ return HEBREW_CHARSET;
+
+ if (word >= 0x0400 && word <= 0x04FF)
+ return RUSSIAN_CHARSET;
+
+ if (word >= 0x0100 && word <= 0x024F)
+ return EASTEUROPE_CHARSET;
+
+ if (word >= 0x1E00 && word <= 0x1EFF)
+ return VIETNAMESE_CHARSET;
+
+ return ANSI_CHARSET;
+}
+
+/* ------------------------ CPWL_DocFontMap ------------------------ */
+
+CPWL_DocFontMap::CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler, CPDF_Document* pAttachedDoc)
+ : CPWL_FontMap(pSystemHandler),
+ m_pAttachedDoc(pAttachedDoc)
+{
+}
+
+CPWL_DocFontMap::~CPWL_DocFontMap()
+{
+}
+
+CPDF_Document* CPWL_DocFontMap::GetDocument()
+{
+ return m_pAttachedDoc;
+}
diff --git a/fpdfsdk/src/pdfwindow/PWL_Icon.cpp b/fpdfsdk/src/pdfwindow/PWL_Icon.cpp
index a859a52de7..b85b845553 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Icon.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Icon.cpp
@@ -1,272 +1,272 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_Icon.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-
-/* ------------------------------- CPWL_Image ---------------------------------- */
-
-CPWL_Image::CPWL_Image() : m_pPDFStream(NULL)
-{
-}
-
-CPWL_Image::~CPWL_Image()
-{
-}
-
-CFX_ByteString CPWL_Image::GetImageAppStream()
-{
- CFX_ByteTextBuf sAppStream;
-
- CFX_ByteString sAlias = this->GetImageAlias();
- CPDF_Rect rcPlate = GetClientRect();
- CPDF_Matrix mt;
- mt.SetReverse(GetImageMatrix());
-
- FX_FLOAT fHScale = 1.0f;
- FX_FLOAT fVScale = 1.0f;
- GetScale(fHScale,fVScale);
-
- FX_FLOAT fx = 0.0f;
- FX_FLOAT fy = 0.0f;
- GetImageOffset(fx,fy);
-
- if (m_pPDFStream && sAlias.GetLength()>0)
- {
- sAppStream << "q\n";
- sAppStream << rcPlate.left << " " << rcPlate.bottom << " "
- << rcPlate.right - rcPlate.left << " " << rcPlate.top - rcPlate.bottom << " re W n\n";
-
- sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx << " " << rcPlate.bottom + fy << " cm\n";
- sAppStream << mt.GetA() << " " << mt.GetB() << " " << mt.GetC() << " " << mt.GetD() << " " << mt.GetE() << " " << mt.GetF() << " cm\n";
-
- sAppStream << "0 g 0 G 1 w /" << sAlias << " Do\n" << "Q\n";
- }
-
- return sAppStream.GetByteString();
-}
-
-void CPWL_Image::SetPDFStream(CPDF_Stream * pStream)
-{
- m_pPDFStream = pStream;
-}
-
-CPDF_Stream * CPWL_Image::GetPDFStream()
-{
- return this->m_pPDFStream;
-}
-
-void CPWL_Image::GetImageSize(FX_FLOAT & fWidth,FX_FLOAT & fHeight)
-{
- fWidth = 0.0f;
- fHeight = 0.0f;
-
- if (m_pPDFStream)
- {
- if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())
- {
- CPDF_Rect rect = pDict->GetRect("BBox");
-
- fWidth = rect.right - rect.left;
- fHeight = rect.top - rect.bottom;
- }
- }
-}
-
-CPDF_Matrix CPWL_Image::GetImageMatrix()
-{
- if (m_pPDFStream)
- {
- if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())
- {
- return pDict->GetMatrix("Matrix");
- }
- }
-
- return CPDF_Matrix();
-}
-
-CFX_ByteString CPWL_Image::GetImageAlias()
-{
- if (m_sImageAlias.IsEmpty())
- {
- if (m_pPDFStream)
- {
- if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())
- {
- return pDict->GetString("Name");
- }
- }
- }
- else
- return m_sImageAlias;
-
- return CFX_ByteString();
-}
-
-void CPWL_Image::SetImageAlias(FX_LPCSTR sImageAlias)
-{
- m_sImageAlias = sImageAlias;
-}
-
-void CPWL_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
-{
- fHScale = 1.0f;
- fVScale = 1.0f;
-}
-
-
-void CPWL_Image::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y)
-{
- x = 0.0f;
- y = 0.0f;
-}
-
-/* ------------------------------- CPWL_Icon ---------------------------------- */
-
-CPWL_Icon::CPWL_Icon() : m_pIconFit(NULL)
-{
-}
-
-CPWL_Icon::~CPWL_Icon()
-{
-}
-
-FX_INT32 CPWL_Icon::GetScaleMethod()
-{
- if (m_pIconFit)
- return m_pIconFit->GetScaleMethod();
-
- return 0;
-}
-
-FX_BOOL CPWL_Icon::IsProportionalScale()
-{
- if (m_pIconFit)
- return m_pIconFit->IsProportionalScale();
-
- return FALSE;
-}
-
-void CPWL_Icon::GetIconPosition(FX_FLOAT & fLeft, FX_FLOAT & fBottom)
-{
- if (m_pIconFit)
- {
- //m_pIconFit->GetIconPosition(fLeft,fBottom);
- fLeft = 0.0f;
- fBottom = 0.0f;
- CPDF_Array* pA = m_pIconFit->m_pDict->GetArray("A");
- if (pA != NULL)
- {
- FX_DWORD dwCount = pA->GetCount();
- if (dwCount > 0) fLeft = pA->GetNumber(0);
- if (dwCount > 1) fBottom = pA->GetNumber(1);
- }
- }
- else
- {
- fLeft = 0.0f;
- fBottom = 0.0f;
- }
-}
-
-FX_BOOL CPWL_Icon::GetFittingBounds()
-{
- if (m_pIconFit)
- return m_pIconFit->GetFittingBounds();
-
- return FALSE;
-}
-
-void CPWL_Icon::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
-{
- fHScale = 1.0f;
- fVScale = 1.0f;
-
- if (m_pPDFStream)
- {
- FX_FLOAT fImageWidth,fImageHeight;
- FX_FLOAT fPlateWidth,fPlateHeight;
-
- CPDF_Rect rcPlate = this->GetClientRect();
- fPlateWidth = rcPlate.right - rcPlate.left;
- fPlateHeight = rcPlate.top - rcPlate.bottom;
-
- GetImageSize(fImageWidth,fImageHeight);
-
- FX_INT32 nScaleMethod = this->GetScaleMethod();
-
- /*
- enum ScaleMethod
- {
- Always = 0, //A, Always scale
- Bigger, //B, Scale only when the icon is bigger than the annotation rectangle
- Smaller, //S, Scale only when the icon is smaller then the annotation rectangle
- Never //N, Never scale
- };
- */
-
- switch (nScaleMethod)
- {
- default:
- case 0:
- fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);
- fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);
- break;
- case 1:
- if (fPlateWidth < fImageWidth)
- fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);
- if (fPlateHeight < fImageHeight)
- fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);
- break;
- case 2:
- if (fPlateWidth > fImageWidth)
- fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);
- if (fPlateHeight > fImageHeight)
- fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);
- break;
- case 3:
- break;
- }
-
- FX_FLOAT fMinScale;
- if (IsProportionalScale())
- {
- fMinScale = PWL_MIN(fHScale,fVScale);
- fHScale = fMinScale;
- fVScale = fMinScale;
- }
- }
-}
-
-void CPWL_Icon::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y)
-{
- FX_FLOAT fLeft,fBottom;
-
- this->GetIconPosition(fLeft,fBottom);
- x = 0.0f;
- y = 0.0f;
-
- FX_FLOAT fImageWidth,fImageHeight;
- GetImageSize(fImageWidth,fImageHeight);
-
- FX_FLOAT fHScale,fVScale;
- GetScale(fHScale,fVScale);
-
- FX_FLOAT fImageFactWidth = fImageWidth * fHScale;
- FX_FLOAT fImageFactHeight = fImageHeight * fVScale;
-
- FX_FLOAT fPlateWidth,fPlateHeight;
- CPDF_Rect rcPlate = this->GetClientRect();
- fPlateWidth = rcPlate.right - rcPlate.left;
- fPlateHeight = rcPlate.top - rcPlate.bottom;
-
- x = (fPlateWidth - fImageFactWidth) * fLeft;
- y = (fPlateHeight - fImageFactHeight) * fBottom;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Icon.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+/* ------------------------------- CPWL_Image ---------------------------------- */
+
+CPWL_Image::CPWL_Image() : m_pPDFStream(NULL)
+{
+}
+
+CPWL_Image::~CPWL_Image()
+{
+}
+
+CFX_ByteString CPWL_Image::GetImageAppStream()
+{
+ CFX_ByteTextBuf sAppStream;
+
+ CFX_ByteString sAlias = this->GetImageAlias();
+ CPDF_Rect rcPlate = GetClientRect();
+ CPDF_Matrix mt;
+ mt.SetReverse(GetImageMatrix());
+
+ FX_FLOAT fHScale = 1.0f;
+ FX_FLOAT fVScale = 1.0f;
+ GetScale(fHScale,fVScale);
+
+ FX_FLOAT fx = 0.0f;
+ FX_FLOAT fy = 0.0f;
+ GetImageOffset(fx,fy);
+
+ if (m_pPDFStream && sAlias.GetLength()>0)
+ {
+ sAppStream << "q\n";
+ sAppStream << rcPlate.left << " " << rcPlate.bottom << " "
+ << rcPlate.right - rcPlate.left << " " << rcPlate.top - rcPlate.bottom << " re W n\n";
+
+ sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx << " " << rcPlate.bottom + fy << " cm\n";
+ sAppStream << mt.GetA() << " " << mt.GetB() << " " << mt.GetC() << " " << mt.GetD() << " " << mt.GetE() << " " << mt.GetF() << " cm\n";
+
+ sAppStream << "0 g 0 G 1 w /" << sAlias << " Do\n" << "Q\n";
+ }
+
+ return sAppStream.GetByteString();
+}
+
+void CPWL_Image::SetPDFStream(CPDF_Stream * pStream)
+{
+ m_pPDFStream = pStream;
+}
+
+CPDF_Stream * CPWL_Image::GetPDFStream()
+{
+ return this->m_pPDFStream;
+}
+
+void CPWL_Image::GetImageSize(FX_FLOAT & fWidth,FX_FLOAT & fHeight)
+{
+ fWidth = 0.0f;
+ fHeight = 0.0f;
+
+ if (m_pPDFStream)
+ {
+ if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())
+ {
+ CPDF_Rect rect = pDict->GetRect("BBox");
+
+ fWidth = rect.right - rect.left;
+ fHeight = rect.top - rect.bottom;
+ }
+ }
+}
+
+CPDF_Matrix CPWL_Image::GetImageMatrix()
+{
+ if (m_pPDFStream)
+ {
+ if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())
+ {
+ return pDict->GetMatrix("Matrix");
+ }
+ }
+
+ return CPDF_Matrix();
+}
+
+CFX_ByteString CPWL_Image::GetImageAlias()
+{
+ if (m_sImageAlias.IsEmpty())
+ {
+ if (m_pPDFStream)
+ {
+ if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())
+ {
+ return pDict->GetString("Name");
+ }
+ }
+ }
+ else
+ return m_sImageAlias;
+
+ return CFX_ByteString();
+}
+
+void CPWL_Image::SetImageAlias(FX_LPCSTR sImageAlias)
+{
+ m_sImageAlias = sImageAlias;
+}
+
+void CPWL_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
+{
+ fHScale = 1.0f;
+ fVScale = 1.0f;
+}
+
+
+void CPWL_Image::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y)
+{
+ x = 0.0f;
+ y = 0.0f;
+}
+
+/* ------------------------------- CPWL_Icon ---------------------------------- */
+
+CPWL_Icon::CPWL_Icon() : m_pIconFit(NULL)
+{
+}
+
+CPWL_Icon::~CPWL_Icon()
+{
+}
+
+FX_INT32 CPWL_Icon::GetScaleMethod()
+{
+ if (m_pIconFit)
+ return m_pIconFit->GetScaleMethod();
+
+ return 0;
+}
+
+FX_BOOL CPWL_Icon::IsProportionalScale()
+{
+ if (m_pIconFit)
+ return m_pIconFit->IsProportionalScale();
+
+ return FALSE;
+}
+
+void CPWL_Icon::GetIconPosition(FX_FLOAT & fLeft, FX_FLOAT & fBottom)
+{
+ if (m_pIconFit)
+ {
+ //m_pIconFit->GetIconPosition(fLeft,fBottom);
+ fLeft = 0.0f;
+ fBottom = 0.0f;
+ CPDF_Array* pA = m_pIconFit->m_pDict->GetArray("A");
+ if (pA != NULL)
+ {
+ FX_DWORD dwCount = pA->GetCount();
+ if (dwCount > 0) fLeft = pA->GetNumber(0);
+ if (dwCount > 1) fBottom = pA->GetNumber(1);
+ }
+ }
+ else
+ {
+ fLeft = 0.0f;
+ fBottom = 0.0f;
+ }
+}
+
+FX_BOOL CPWL_Icon::GetFittingBounds()
+{
+ if (m_pIconFit)
+ return m_pIconFit->GetFittingBounds();
+
+ return FALSE;
+}
+
+void CPWL_Icon::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
+{
+ fHScale = 1.0f;
+ fVScale = 1.0f;
+
+ if (m_pPDFStream)
+ {
+ FX_FLOAT fImageWidth,fImageHeight;
+ FX_FLOAT fPlateWidth,fPlateHeight;
+
+ CPDF_Rect rcPlate = this->GetClientRect();
+ fPlateWidth = rcPlate.right - rcPlate.left;
+ fPlateHeight = rcPlate.top - rcPlate.bottom;
+
+ GetImageSize(fImageWidth,fImageHeight);
+
+ FX_INT32 nScaleMethod = this->GetScaleMethod();
+
+ /*
+ enum ScaleMethod
+ {
+ Always = 0, //A, Always scale
+ Bigger, //B, Scale only when the icon is bigger than the annotation rectangle
+ Smaller, //S, Scale only when the icon is smaller then the annotation rectangle
+ Never //N, Never scale
+ };
+ */
+
+ switch (nScaleMethod)
+ {
+ default:
+ case 0:
+ fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);
+ fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);
+ break;
+ case 1:
+ if (fPlateWidth < fImageWidth)
+ fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);
+ if (fPlateHeight < fImageHeight)
+ fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);
+ break;
+ case 2:
+ if (fPlateWidth > fImageWidth)
+ fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);
+ if (fPlateHeight > fImageHeight)
+ fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);
+ break;
+ case 3:
+ break;
+ }
+
+ FX_FLOAT fMinScale;
+ if (IsProportionalScale())
+ {
+ fMinScale = PWL_MIN(fHScale,fVScale);
+ fHScale = fMinScale;
+ fVScale = fMinScale;
+ }
+ }
+}
+
+void CPWL_Icon::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y)
+{
+ FX_FLOAT fLeft,fBottom;
+
+ this->GetIconPosition(fLeft,fBottom);
+ x = 0.0f;
+ y = 0.0f;
+
+ FX_FLOAT fImageWidth,fImageHeight;
+ GetImageSize(fImageWidth,fImageHeight);
+
+ FX_FLOAT fHScale,fVScale;
+ GetScale(fHScale,fVScale);
+
+ FX_FLOAT fImageFactWidth = fImageWidth * fHScale;
+ FX_FLOAT fImageFactHeight = fImageHeight * fVScale;
+
+ FX_FLOAT fPlateWidth,fPlateHeight;
+ CPDF_Rect rcPlate = this->GetClientRect();
+ fPlateWidth = rcPlate.right - rcPlate.left;
+ fPlateHeight = rcPlate.top - rcPlate.bottom;
+
+ x = (fPlateWidth - fImageFactWidth) * fLeft;
+ y = (fPlateHeight - fImageFactHeight) * fBottom;
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_IconList.cpp b/fpdfsdk/src/pdfwindow/PWL_IconList.cpp
index 09b66786db..72317908bb 100644
--- a/fpdfsdk/src/pdfwindow/PWL_IconList.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_IconList.cpp
@@ -1,592 +1,592 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_ListCtrl.h"
-#include "../../include/pdfwindow/PWL_IconList.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-#include "../../include/pdfwindow/PWL_ScrollBar.h"
-#include "../../include/pdfwindow/PWL_Label.h"
-
-#define PWL_IconList_ITEM_ICON_LEFTMARGIN 10.0f
-#define PWL_IconList_ITEM_WIDTH 20.0f
-#define PWL_IconList_ITEM_HEIGHT 20.0f
-#define PWL_IconList_ITEM_SPACE 4.0f
-
-/* ------------------ CPWL_IconList_Item ------------------- */
-
-CPWL_IconList_Item::CPWL_IconList_Item() :
- m_nIconIndex(-1),
- m_pData(NULL),
- m_bSelected(FALSE),
- m_pText(NULL)
-{
-}
-
-CPWL_IconList_Item::~CPWL_IconList_Item()
-{
-}
-
-CFX_ByteString CPWL_IconList_Item::GetClassName() const
-{
- return "CPWL_IconList_Item";
-}
-
-FX_FLOAT CPWL_IconList_Item::GetItemHeight(FX_FLOAT fLimitWidth)
-{
- return PWL_IconList_ITEM_HEIGHT;
-}
-
-void CPWL_IconList_Item::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPDF_Rect rcClient = GetClientRect();
-
- if (m_bSelected)
- {
- if (this->IsEnabled())
- {
- CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
- CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_SELBACKCOLOR,this->GetTransparency()));
- }
- else
- {
- CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
- CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_LIGHTGRAYCOLOR,this->GetTransparency()));
- }
- }
-
- CPDF_Rect rcIcon = rcClient;
- rcIcon.left += PWL_IconList_ITEM_ICON_LEFTMARGIN;
- rcIcon.right = rcIcon.left + PWL_IconList_ITEM_WIDTH;
-
- CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, m_nIconIndex, rcIcon,
- m_crIcon, m_pText->GetTextColor(), this->GetTransparency());
-}
-
-void CPWL_IconList_Item::SetSelect(FX_BOOL bSelected)
-{
- m_bSelected = bSelected;
-
- if (bSelected)
- m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR);
- else
- m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR);
-
-}
-
-FX_BOOL CPWL_IconList_Item::IsSelected() const
-{
- return m_bSelected;
-}
-
-void CPWL_IconList_Item::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- m_pText = new CPWL_Label;
-
- PWL_CREATEPARAM lcp = cp;
- lcp.pParentWnd = this;
- lcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PES_LEFT | PES_CENTER;
- lcp.sTextColor = PWL_DEFAULT_BLACKCOLOR;
- lcp.fFontSize = 12;
- m_pText->Create(lcp);
-}
-
-void CPWL_IconList_Item::SetData(void* pData)
-{
- m_pData = pData;
-}
-
-void CPWL_IconList_Item::SetIcon(FX_INT32 nIconIndex)
-{
- m_nIconIndex = nIconIndex;
-}
-
-void CPWL_IconList_Item::SetText(const CFX_WideString& str)
-{
- m_pText->SetText(str);
-}
-
-CFX_WideString CPWL_IconList_Item::GetText() const
-{
- return m_pText->GetText();
-}
-
-void CPWL_IconList_Item::RePosChildWnd()
-{
- CPDF_Rect rcClient = GetClientRect();
-
- rcClient.left += (PWL_IconList_ITEM_ICON_LEFTMARGIN + PWL_IconList_ITEM_WIDTH + PWL_IconList_ITEM_ICON_LEFTMARGIN);
-
- m_pText->Move(rcClient, TRUE, FALSE);
-}
-
-void CPWL_IconList_Item::SetIconFillColor(const CPWL_Color& color)
-{
- m_crIcon = color;
-}
-
-void CPWL_IconList_Item::OnEnabled()
-{
- if (m_bSelected)
- m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR);
- else
- m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR);
-
- this->InvalidateRect();
-}
-
-void CPWL_IconList_Item::OnDisabled()
-{
- m_pText->SetTextColor(PWL_DEFAULT_HEAVYGRAYCOLOR);
-
- this->InvalidateRect();
-}
-
-/* ----------------- CPWL_IconList_Content ----------------- */
-
-CPWL_IconList_Content::CPWL_IconList_Content(FX_INT32 nListCount) :
- m_nSelectIndex(-1),
- m_pNotify(NULL),
- m_bEnableNotify(TRUE),
- m_bMouseDown(FALSE),
- m_nListCount(nListCount)
-{
-}
-
-CPWL_IconList_Content::~CPWL_IconList_Content()
-{
-}
-
-void CPWL_IconList_Content::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- for (FX_INT32 i=0; i<m_nListCount; i++)
- {
- CPWL_IconList_Item* pNewItem = new CPWL_IconList_Item();
-
- PWL_CREATEPARAM icp = cp;
- icp.pParentWnd = this;
- icp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_NOREFRESHCLIP;
- pNewItem->Create(icp);
- }
-
- this->SetItemSpace(PWL_IconList_ITEM_SPACE);
- this->ResetContent(0);
-
- if (CPWL_Wnd * pParent = this->GetParentWindow())
- {
- CPDF_Rect rcScroll = this->GetScrollArea();
- this->GetScrollPos();
-
- PWL_SCROLL_INFO sInfo;
- sInfo.fContentMin = rcScroll.bottom;
- sInfo.fContentMax = rcScroll.top;
- sInfo.fPlateWidth = GetClientRect().Height();
- sInfo.fSmallStep = 13.0f;
- sInfo.fBigStep = sInfo.fPlateWidth;
-
- pParent->OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (FX_INTPTR)&sInfo);
- }
-}
-
-FX_BOOL CPWL_IconList_Content::OnLButtonDown(const CPDF_Point & point)
-{
- SetFocus();
-
- SetCapture();
- m_bMouseDown = TRUE;
-
- FX_INT32 nItemIndex = FindItemIndex(point);
- SetSelect(nItemIndex);
- ScrollToItem(nItemIndex);
-
- return TRUE;
-}
-
-FX_BOOL CPWL_IconList_Content::OnLButtonUp(const CPDF_Point & point)
-{
- m_bMouseDown = FALSE;
- ReleaseCapture();
-
- return TRUE;
-}
-
-FX_BOOL CPWL_IconList_Content::OnMouseMove(const CPDF_Point & point)
-{
- if (m_bMouseDown)
- {
- FX_INT32 nItemIndex = FindItemIndex(point);
- SetSelect(nItemIndex);
- ScrollToItem(nItemIndex);
- }
-
- return TRUE;
-}
-
-FX_BOOL CPWL_IconList_Content::OnKeyDown(FX_WORD nChar)
-{
- switch (nChar)
- {
- case FWL_VKEY_Up:
- if (m_nSelectIndex > 0)
- {
- FX_INT32 nItemIndex = m_nSelectIndex - 1;
- SetSelect(nItemIndex);
- ScrollToItem(nItemIndex);
- }
- return TRUE;
- case FWL_VKEY_Down:
- if (m_nSelectIndex < m_nListCount-1)
- {
- FX_INT32 nItemIndex = m_nSelectIndex + 1;
- SetSelect(nItemIndex);
- ScrollToItem(nItemIndex);
- }
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_INT32 CPWL_IconList_Content::FindItemIndex(const CPDF_Point& point)
-{
- FX_INT32 nIndex = 0;
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
- {
- CPDF_Rect rcWnd = pChild->ChildToParent(pChild->GetWindowRect());
-
- if (point.y < rcWnd.top)
- {
- nIndex = i;
- }
- }
- }
-
- return nIndex;
-}
-
-void CPWL_IconList_Content::ScrollToItem(FX_INT32 nItemIndex)
-{
- CPDF_Rect rcClient = GetClientRect();
-
- if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
- {
- CPDF_Rect rcOrigin = pItem->GetWindowRect();
- CPDF_Rect rcWnd = pItem->ChildToParent(rcOrigin);
-
- if (!(rcWnd.bottom > rcClient.bottom && rcWnd.top < rcClient.top))
- {
- CPDF_Point ptScroll = GetScrollPos();
-
- if (rcWnd.top > rcClient.top)
- {
- ptScroll.y = rcOrigin.top;
- }
- else if (rcWnd.bottom < rcClient.bottom)
- {
- ptScroll.y = rcOrigin.bottom + rcClient.Height();
- }
-
- this->SetScrollPos(ptScroll);
- this->ResetFace();
- this->InvalidateRect();
- if (CPWL_Wnd* pParent = this->GetParentWindow())
- {
- pParent->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
- }
- }
- }
-}
-
-void CPWL_IconList_Content::SetSelect(FX_INT32 nIndex)
-{
- if (m_nSelectIndex != nIndex)
- {
- SelectItem(m_nSelectIndex, FALSE);
- SelectItem(nIndex, TRUE);
- m_nSelectIndex = nIndex;
-
- if (IPWL_IconList_Notify* pNotify = GetNotify())
- pNotify->OnNoteListSelChanged(nIndex);
- }
-}
-
-FX_INT32 CPWL_IconList_Content::GetSelect() const
-{
- return m_nSelectIndex;
-}
-
-IPWL_IconList_Notify* CPWL_IconList_Content::GetNotify() const
-{
- if (m_bEnableNotify)
- return m_pNotify;
- return NULL;
-}
-
-void CPWL_IconList_Content::SetNotify(IPWL_IconList_Notify* pNotify)
-{
- m_pNotify = pNotify;
-}
-
-void CPWL_IconList_Content::EnableNotify(FX_BOOL bNotify)
-{
- m_bEnableNotify = bNotify;
-}
-
-void CPWL_IconList_Content::SelectItem(FX_INT32 nItemIndex, FX_BOOL bSelect)
-{
- if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
- {
- pItem->SetSelect(bSelect);
- pItem->InvalidateRect();
- }
-}
-
-CPWL_IconList_Item* CPWL_IconList_Content::GetListItem(FX_INT32 nItemIndex) const
-{
- if (nItemIndex >= 0 && nItemIndex<m_aChildren.GetSize())
- {
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(nItemIndex))
- {
- if (pChild->GetClassName() == "CPWL_IconList_Item")
- {
- return (CPWL_IconList_Item*)pChild;
- }
- }
- }
-
- return NULL;
-}
-
-void CPWL_IconList_Content::SetListData(FX_INT32 nItemIndex, void* pData)
-{
- if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
- pItem->SetData(pData);
-}
-
-void CPWL_IconList_Content::SetListIcon(FX_INT32 nItemIndex, FX_INT32 nIconIndex)
-{
- if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
- pItem->SetIcon(nIconIndex);
-}
-
-void CPWL_IconList_Content::SetListString(FX_INT32 nItemIndex, const CFX_WideString& str)
-{
- if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
- pItem->SetText(str);
-}
-
-CFX_WideString CPWL_IconList_Content::GetListString(FX_INT32 nItemIndex) const
-{
- if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
- return pItem->GetText();
-
- return L"";
-}
-
-void CPWL_IconList_Content::SetIconFillColor(const CPWL_Color& color)
-{
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
- {
- if (pChild->GetClassName() == "CPWL_IconList_Item")
- {
- CPWL_IconList_Item* pItem = (CPWL_IconList_Item*)pChild;
- pItem->SetIconFillColor(color);
- pItem->InvalidateRect();
- }
- }
- }
-
-}
-
-/* -------------------- CPWL_IconList --------------------- */
-
-CPWL_IconList::CPWL_IconList(FX_INT32 nListCount) :
- m_pListContent(NULL),
- m_nListCount(nListCount)
-{
-}
-
-CPWL_IconList::~CPWL_IconList()
-{
-}
-
-void CPWL_IconList::RePosChildWnd()
-{
- CPWL_Wnd::RePosChildWnd();
-
- if (m_pListContent)
- m_pListContent->Move(GetClientRect(), TRUE, FALSE);
-}
-
-void CPWL_IconList::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- m_pListContent = new CPWL_IconList_Content(m_nListCount);
-
- PWL_CREATEPARAM ccp = cp;
- ccp.pParentWnd = this;
- ccp.dwFlags = PWS_CHILD | PWS_VISIBLE;
- m_pListContent->Create(ccp);
-}
-
-void CPWL_IconList::OnCreated()
-{
- if (CPWL_ScrollBar* pScrollBar = this->GetVScrollBar())
- {
- pScrollBar->RemoveFlag(PWS_AUTOTRANSPARENT);
- pScrollBar->SetTransparency(255);
- pScrollBar->SetNotifyForever(TRUE);
- }
-}
-
-void CPWL_IconList::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
-
- if (wParam == SBT_VSCROLL)
- {
- switch (msg)
- {
- case PNM_SETSCROLLINFO:
- if (PWL_SCROLL_INFO* pInfo = (PWL_SCROLL_INFO*)lParam)
- {
- if (CPWL_ScrollBar* pScrollBar = this->GetVScrollBar())
- {
- if (pInfo->fContentMax - pInfo->fContentMin > pInfo->fPlateWidth)
- {
- if (!pScrollBar->IsVisible())
- {
- pScrollBar->SetVisible(TRUE);
- RePosChildWnd();
- }
- else
- {
- }
- }
- else
- {
- if (pScrollBar->IsVisible())
- {
- pScrollBar->SetVisible(FALSE);
- RePosChildWnd();
- }
-
- if (m_pListContent)
- m_pListContent->SetScrollPos(CPDF_Point(0.0f,0.0f));
- }
-
- pScrollBar->OnNotify(pWnd,PNM_SETSCROLLINFO,wParam,lParam);
- }
- }
- return;
- case PNM_SCROLLWINDOW:
- if (m_pListContent)
- {
- m_pListContent->SetScrollPos(CPDF_Point(0.0f, *(FX_FLOAT*)lParam));
- m_pListContent->ResetFace();
- m_pListContent->InvalidateRect(NULL);
- }
- return;
- case PNM_SETSCROLLPOS:
- if (CPWL_ScrollBar* pScrollBar = this->GetVScrollBar())
- pScrollBar->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);
- return;
- }
- }
-}
-
-void CPWL_IconList::SetSelect(FX_INT32 nIndex)
-{
- m_pListContent->SetSelect(nIndex);
-}
-
-void CPWL_IconList::SetTopItem(FX_INT32 nIndex)
-{
- m_pListContent->ScrollToItem(nIndex);
-}
-
-FX_INT32 CPWL_IconList::GetSelect() const
-{
- return m_pListContent->GetSelect();
-}
-
-void CPWL_IconList::SetNotify(IPWL_IconList_Notify* pNotify)
-{
- m_pListContent->SetNotify(pNotify);
-}
-
-void CPWL_IconList::EnableNotify(FX_BOOL bNotify)
-{
- m_pListContent->EnableNotify(bNotify);
-}
-
-void CPWL_IconList::SetListData(FX_INT32 nItemIndex, void* pData)
-{
- m_pListContent->SetListData(nItemIndex, pData);
-}
-
-void CPWL_IconList::SetListIcon(FX_INT32 nItemIndex, FX_INT32 nIconIndex)
-{
- m_pListContent->SetListIcon(nItemIndex, nIconIndex);
-}
-
-void CPWL_IconList::SetListString(FX_INT32 nItemIndex, const CFX_WideString& str)
-{
- m_pListContent->SetListString(nItemIndex, str);
-}
-
-CFX_WideString CPWL_IconList::GetListString(FX_INT32 nItemIndex) const
-{
- return m_pListContent->GetListString(nItemIndex);
-}
-
-void CPWL_IconList::SetIconFillColor(const CPWL_Color& color)
-{
- m_pListContent->SetIconFillColor(color);
-}
-
-FX_BOOL CPWL_IconList::OnMouseWheel(short zDelta, const CPDF_Point & point)
-{
- CPDF_Point ptScroll = m_pListContent->GetScrollPos();
- CPDF_Rect rcScroll = m_pListContent->GetScrollArea();
- CPDF_Rect rcContents = m_pListContent->GetClientRect();
-
- if (rcScroll.top - rcScroll.bottom > rcContents.Height())
- {
- CPDF_Point ptNew = ptScroll;
-
- if (zDelta > 0)
- ptNew.y += 30;
- else
- ptNew.y -= 30;
-
- if (ptNew.y > rcScroll.top)
- ptNew.y = rcScroll.top;
- if (ptNew.y < rcScroll.bottom + rcContents.Height())
- ptNew.y = rcScroll.bottom + rcContents.Height();
- if (ptNew.y < rcScroll.bottom)
- ptNew.y = rcScroll.bottom;
-
- if (ptNew.y != ptScroll.y)
- {
- m_pListContent->SetScrollPos(ptNew);
- m_pListContent->ResetFace();
- m_pListContent->InvalidateRect(NULL);
-
- if (CPWL_ScrollBar* pScrollBar = this->GetVScrollBar())
- pScrollBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptNew.y);
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_ListCtrl.h"
+#include "../../include/pdfwindow/PWL_IconList.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+#include "../../include/pdfwindow/PWL_ScrollBar.h"
+#include "../../include/pdfwindow/PWL_Label.h"
+
+#define PWL_IconList_ITEM_ICON_LEFTMARGIN 10.0f
+#define PWL_IconList_ITEM_WIDTH 20.0f
+#define PWL_IconList_ITEM_HEIGHT 20.0f
+#define PWL_IconList_ITEM_SPACE 4.0f
+
+/* ------------------ CPWL_IconList_Item ------------------- */
+
+CPWL_IconList_Item::CPWL_IconList_Item() :
+ m_nIconIndex(-1),
+ m_pData(NULL),
+ m_bSelected(FALSE),
+ m_pText(NULL)
+{
+}
+
+CPWL_IconList_Item::~CPWL_IconList_Item()
+{
+}
+
+CFX_ByteString CPWL_IconList_Item::GetClassName() const
+{
+ return "CPWL_IconList_Item";
+}
+
+FX_FLOAT CPWL_IconList_Item::GetItemHeight(FX_FLOAT fLimitWidth)
+{
+ return PWL_IconList_ITEM_HEIGHT;
+}
+
+void CPWL_IconList_Item::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ if (m_bSelected)
+ {
+ if (this->IsEnabled())
+ {
+ CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
+ CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_SELBACKCOLOR,this->GetTransparency()));
+ }
+ else
+ {
+ CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
+ CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_LIGHTGRAYCOLOR,this->GetTransparency()));
+ }
+ }
+
+ CPDF_Rect rcIcon = rcClient;
+ rcIcon.left += PWL_IconList_ITEM_ICON_LEFTMARGIN;
+ rcIcon.right = rcIcon.left + PWL_IconList_ITEM_WIDTH;
+
+ CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, m_nIconIndex, rcIcon,
+ m_crIcon, m_pText->GetTextColor(), this->GetTransparency());
+}
+
+void CPWL_IconList_Item::SetSelect(FX_BOOL bSelected)
+{
+ m_bSelected = bSelected;
+
+ if (bSelected)
+ m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR);
+ else
+ m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR);
+
+}
+
+FX_BOOL CPWL_IconList_Item::IsSelected() const
+{
+ return m_bSelected;
+}
+
+void CPWL_IconList_Item::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ m_pText = new CPWL_Label;
+
+ PWL_CREATEPARAM lcp = cp;
+ lcp.pParentWnd = this;
+ lcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PES_LEFT | PES_CENTER;
+ lcp.sTextColor = PWL_DEFAULT_BLACKCOLOR;
+ lcp.fFontSize = 12;
+ m_pText->Create(lcp);
+}
+
+void CPWL_IconList_Item::SetData(void* pData)
+{
+ m_pData = pData;
+}
+
+void CPWL_IconList_Item::SetIcon(FX_INT32 nIconIndex)
+{
+ m_nIconIndex = nIconIndex;
+}
+
+void CPWL_IconList_Item::SetText(const CFX_WideString& str)
+{
+ m_pText->SetText(str);
+}
+
+CFX_WideString CPWL_IconList_Item::GetText() const
+{
+ return m_pText->GetText();
+}
+
+void CPWL_IconList_Item::RePosChildWnd()
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ rcClient.left += (PWL_IconList_ITEM_ICON_LEFTMARGIN + PWL_IconList_ITEM_WIDTH + PWL_IconList_ITEM_ICON_LEFTMARGIN);
+
+ m_pText->Move(rcClient, TRUE, FALSE);
+}
+
+void CPWL_IconList_Item::SetIconFillColor(const CPWL_Color& color)
+{
+ m_crIcon = color;
+}
+
+void CPWL_IconList_Item::OnEnabled()
+{
+ if (m_bSelected)
+ m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR);
+ else
+ m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR);
+
+ this->InvalidateRect();
+}
+
+void CPWL_IconList_Item::OnDisabled()
+{
+ m_pText->SetTextColor(PWL_DEFAULT_HEAVYGRAYCOLOR);
+
+ this->InvalidateRect();
+}
+
+/* ----------------- CPWL_IconList_Content ----------------- */
+
+CPWL_IconList_Content::CPWL_IconList_Content(FX_INT32 nListCount) :
+ m_nSelectIndex(-1),
+ m_pNotify(NULL),
+ m_bEnableNotify(TRUE),
+ m_bMouseDown(FALSE),
+ m_nListCount(nListCount)
+{
+}
+
+CPWL_IconList_Content::~CPWL_IconList_Content()
+{
+}
+
+void CPWL_IconList_Content::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ for (FX_INT32 i=0; i<m_nListCount; i++)
+ {
+ CPWL_IconList_Item* pNewItem = new CPWL_IconList_Item();
+
+ PWL_CREATEPARAM icp = cp;
+ icp.pParentWnd = this;
+ icp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_NOREFRESHCLIP;
+ pNewItem->Create(icp);
+ }
+
+ this->SetItemSpace(PWL_IconList_ITEM_SPACE);
+ this->ResetContent(0);
+
+ if (CPWL_Wnd * pParent = this->GetParentWindow())
+ {
+ CPDF_Rect rcScroll = this->GetScrollArea();
+ this->GetScrollPos();
+
+ PWL_SCROLL_INFO sInfo;
+ sInfo.fContentMin = rcScroll.bottom;
+ sInfo.fContentMax = rcScroll.top;
+ sInfo.fPlateWidth = GetClientRect().Height();
+ sInfo.fSmallStep = 13.0f;
+ sInfo.fBigStep = sInfo.fPlateWidth;
+
+ pParent->OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (FX_INTPTR)&sInfo);
+ }
+}
+
+FX_BOOL CPWL_IconList_Content::OnLButtonDown(const CPDF_Point & point)
+{
+ SetFocus();
+
+ SetCapture();
+ m_bMouseDown = TRUE;
+
+ FX_INT32 nItemIndex = FindItemIndex(point);
+ SetSelect(nItemIndex);
+ ScrollToItem(nItemIndex);
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_IconList_Content::OnLButtonUp(const CPDF_Point & point)
+{
+ m_bMouseDown = FALSE;
+ ReleaseCapture();
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_IconList_Content::OnMouseMove(const CPDF_Point & point)
+{
+ if (m_bMouseDown)
+ {
+ FX_INT32 nItemIndex = FindItemIndex(point);
+ SetSelect(nItemIndex);
+ ScrollToItem(nItemIndex);
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_IconList_Content::OnKeyDown(FX_WORD nChar)
+{
+ switch (nChar)
+ {
+ case FWL_VKEY_Up:
+ if (m_nSelectIndex > 0)
+ {
+ FX_INT32 nItemIndex = m_nSelectIndex - 1;
+ SetSelect(nItemIndex);
+ ScrollToItem(nItemIndex);
+ }
+ return TRUE;
+ case FWL_VKEY_Down:
+ if (m_nSelectIndex < m_nListCount-1)
+ {
+ FX_INT32 nItemIndex = m_nSelectIndex + 1;
+ SetSelect(nItemIndex);
+ ScrollToItem(nItemIndex);
+ }
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_INT32 CPWL_IconList_Content::FindItemIndex(const CPDF_Point& point)
+{
+ FX_INT32 nIndex = 0;
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
+ {
+ CPDF_Rect rcWnd = pChild->ChildToParent(pChild->GetWindowRect());
+
+ if (point.y < rcWnd.top)
+ {
+ nIndex = i;
+ }
+ }
+ }
+
+ return nIndex;
+}
+
+void CPWL_IconList_Content::ScrollToItem(FX_INT32 nItemIndex)
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
+ {
+ CPDF_Rect rcOrigin = pItem->GetWindowRect();
+ CPDF_Rect rcWnd = pItem->ChildToParent(rcOrigin);
+
+ if (!(rcWnd.bottom > rcClient.bottom && rcWnd.top < rcClient.top))
+ {
+ CPDF_Point ptScroll = GetScrollPos();
+
+ if (rcWnd.top > rcClient.top)
+ {
+ ptScroll.y = rcOrigin.top;
+ }
+ else if (rcWnd.bottom < rcClient.bottom)
+ {
+ ptScroll.y = rcOrigin.bottom + rcClient.Height();
+ }
+
+ this->SetScrollPos(ptScroll);
+ this->ResetFace();
+ this->InvalidateRect();
+ if (CPWL_Wnd* pParent = this->GetParentWindow())
+ {
+ pParent->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
+ }
+ }
+ }
+}
+
+void CPWL_IconList_Content::SetSelect(FX_INT32 nIndex)
+{
+ if (m_nSelectIndex != nIndex)
+ {
+ SelectItem(m_nSelectIndex, FALSE);
+ SelectItem(nIndex, TRUE);
+ m_nSelectIndex = nIndex;
+
+ if (IPWL_IconList_Notify* pNotify = GetNotify())
+ pNotify->OnNoteListSelChanged(nIndex);
+ }
+}
+
+FX_INT32 CPWL_IconList_Content::GetSelect() const
+{
+ return m_nSelectIndex;
+}
+
+IPWL_IconList_Notify* CPWL_IconList_Content::GetNotify() const
+{
+ if (m_bEnableNotify)
+ return m_pNotify;
+ return NULL;
+}
+
+void CPWL_IconList_Content::SetNotify(IPWL_IconList_Notify* pNotify)
+{
+ m_pNotify = pNotify;
+}
+
+void CPWL_IconList_Content::EnableNotify(FX_BOOL bNotify)
+{
+ m_bEnableNotify = bNotify;
+}
+
+void CPWL_IconList_Content::SelectItem(FX_INT32 nItemIndex, FX_BOOL bSelect)
+{
+ if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
+ {
+ pItem->SetSelect(bSelect);
+ pItem->InvalidateRect();
+ }
+}
+
+CPWL_IconList_Item* CPWL_IconList_Content::GetListItem(FX_INT32 nItemIndex) const
+{
+ if (nItemIndex >= 0 && nItemIndex<m_aChildren.GetSize())
+ {
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(nItemIndex))
+ {
+ if (pChild->GetClassName() == "CPWL_IconList_Item")
+ {
+ return (CPWL_IconList_Item*)pChild;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+void CPWL_IconList_Content::SetListData(FX_INT32 nItemIndex, void* pData)
+{
+ if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
+ pItem->SetData(pData);
+}
+
+void CPWL_IconList_Content::SetListIcon(FX_INT32 nItemIndex, FX_INT32 nIconIndex)
+{
+ if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
+ pItem->SetIcon(nIconIndex);
+}
+
+void CPWL_IconList_Content::SetListString(FX_INT32 nItemIndex, const CFX_WideString& str)
+{
+ if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
+ pItem->SetText(str);
+}
+
+CFX_WideString CPWL_IconList_Content::GetListString(FX_INT32 nItemIndex) const
+{
+ if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
+ return pItem->GetText();
+
+ return L"";
+}
+
+void CPWL_IconList_Content::SetIconFillColor(const CPWL_Color& color)
+{
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
+ {
+ if (pChild->GetClassName() == "CPWL_IconList_Item")
+ {
+ CPWL_IconList_Item* pItem = (CPWL_IconList_Item*)pChild;
+ pItem->SetIconFillColor(color);
+ pItem->InvalidateRect();
+ }
+ }
+ }
+
+}
+
+/* -------------------- CPWL_IconList --------------------- */
+
+CPWL_IconList::CPWL_IconList(FX_INT32 nListCount) :
+ m_pListContent(NULL),
+ m_nListCount(nListCount)
+{
+}
+
+CPWL_IconList::~CPWL_IconList()
+{
+}
+
+void CPWL_IconList::RePosChildWnd()
+{
+ CPWL_Wnd::RePosChildWnd();
+
+ if (m_pListContent)
+ m_pListContent->Move(GetClientRect(), TRUE, FALSE);
+}
+
+void CPWL_IconList::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ m_pListContent = new CPWL_IconList_Content(m_nListCount);
+
+ PWL_CREATEPARAM ccp = cp;
+ ccp.pParentWnd = this;
+ ccp.dwFlags = PWS_CHILD | PWS_VISIBLE;
+ m_pListContent->Create(ccp);
+}
+
+void CPWL_IconList::OnCreated()
+{
+ if (CPWL_ScrollBar* pScrollBar = this->GetVScrollBar())
+ {
+ pScrollBar->RemoveFlag(PWS_AUTOTRANSPARENT);
+ pScrollBar->SetTransparency(255);
+ pScrollBar->SetNotifyForever(TRUE);
+ }
+}
+
+void CPWL_IconList::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
+
+ if (wParam == SBT_VSCROLL)
+ {
+ switch (msg)
+ {
+ case PNM_SETSCROLLINFO:
+ if (PWL_SCROLL_INFO* pInfo = (PWL_SCROLL_INFO*)lParam)
+ {
+ if (CPWL_ScrollBar* pScrollBar = this->GetVScrollBar())
+ {
+ if (pInfo->fContentMax - pInfo->fContentMin > pInfo->fPlateWidth)
+ {
+ if (!pScrollBar->IsVisible())
+ {
+ pScrollBar->SetVisible(TRUE);
+ RePosChildWnd();
+ }
+ else
+ {
+ }
+ }
+ else
+ {
+ if (pScrollBar->IsVisible())
+ {
+ pScrollBar->SetVisible(FALSE);
+ RePosChildWnd();
+ }
+
+ if (m_pListContent)
+ m_pListContent->SetScrollPos(CPDF_Point(0.0f,0.0f));
+ }
+
+ pScrollBar->OnNotify(pWnd,PNM_SETSCROLLINFO,wParam,lParam);
+ }
+ }
+ return;
+ case PNM_SCROLLWINDOW:
+ if (m_pListContent)
+ {
+ m_pListContent->SetScrollPos(CPDF_Point(0.0f, *(FX_FLOAT*)lParam));
+ m_pListContent->ResetFace();
+ m_pListContent->InvalidateRect(NULL);
+ }
+ return;
+ case PNM_SETSCROLLPOS:
+ if (CPWL_ScrollBar* pScrollBar = this->GetVScrollBar())
+ pScrollBar->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);
+ return;
+ }
+ }
+}
+
+void CPWL_IconList::SetSelect(FX_INT32 nIndex)
+{
+ m_pListContent->SetSelect(nIndex);
+}
+
+void CPWL_IconList::SetTopItem(FX_INT32 nIndex)
+{
+ m_pListContent->ScrollToItem(nIndex);
+}
+
+FX_INT32 CPWL_IconList::GetSelect() const
+{
+ return m_pListContent->GetSelect();
+}
+
+void CPWL_IconList::SetNotify(IPWL_IconList_Notify* pNotify)
+{
+ m_pListContent->SetNotify(pNotify);
+}
+
+void CPWL_IconList::EnableNotify(FX_BOOL bNotify)
+{
+ m_pListContent->EnableNotify(bNotify);
+}
+
+void CPWL_IconList::SetListData(FX_INT32 nItemIndex, void* pData)
+{
+ m_pListContent->SetListData(nItemIndex, pData);
+}
+
+void CPWL_IconList::SetListIcon(FX_INT32 nItemIndex, FX_INT32 nIconIndex)
+{
+ m_pListContent->SetListIcon(nItemIndex, nIconIndex);
+}
+
+void CPWL_IconList::SetListString(FX_INT32 nItemIndex, const CFX_WideString& str)
+{
+ m_pListContent->SetListString(nItemIndex, str);
+}
+
+CFX_WideString CPWL_IconList::GetListString(FX_INT32 nItemIndex) const
+{
+ return m_pListContent->GetListString(nItemIndex);
+}
+
+void CPWL_IconList::SetIconFillColor(const CPWL_Color& color)
+{
+ m_pListContent->SetIconFillColor(color);
+}
+
+FX_BOOL CPWL_IconList::OnMouseWheel(short zDelta, const CPDF_Point & point)
+{
+ CPDF_Point ptScroll = m_pListContent->GetScrollPos();
+ CPDF_Rect rcScroll = m_pListContent->GetScrollArea();
+ CPDF_Rect rcContents = m_pListContent->GetClientRect();
+
+ if (rcScroll.top - rcScroll.bottom > rcContents.Height())
+ {
+ CPDF_Point ptNew = ptScroll;
+
+ if (zDelta > 0)
+ ptNew.y += 30;
+ else
+ ptNew.y -= 30;
+
+ if (ptNew.y > rcScroll.top)
+ ptNew.y = rcScroll.top;
+ if (ptNew.y < rcScroll.bottom + rcContents.Height())
+ ptNew.y = rcScroll.bottom + rcContents.Height();
+ if (ptNew.y < rcScroll.bottom)
+ ptNew.y = rcScroll.bottom;
+
+ if (ptNew.y != ptScroll.y)
+ {
+ m_pListContent->SetScrollPos(ptNew);
+ m_pListContent->ResetFace();
+ m_pListContent->InvalidateRect(NULL);
+
+ if (CPWL_ScrollBar* pScrollBar = this->GetVScrollBar())
+ pScrollBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptNew.y);
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_Label.cpp b/fpdfsdk/src/pdfwindow/PWL_Label.cpp
index e1b8522248..18580f3be7 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Label.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Label.cpp
@@ -1,187 +1,187 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_Label.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-
-/* ---------------------------- CPWL_Label ------------------------------ */
-
-CPWL_Label::CPWL_Label() : m_pEdit(NULL)
-{
- m_pEdit = IFX_Edit::NewEdit();
-
- ASSERT(m_pEdit != NULL);
-}
-
-CPWL_Label::~CPWL_Label()
-{
- IFX_Edit::DelEdit(m_pEdit);
-}
-
-CFX_ByteString CPWL_Label::GetClassName() const
-{
- return "CPWL_Label";
-}
-
-void CPWL_Label::OnCreated()
-{
- SetParamByFlag();
- SetFontSize(this->GetCreationParam().fFontSize);
-
- m_pEdit->SetFontMap(this->GetFontMap());
- m_pEdit->Initialize();
-
- if (HasFlag(PES_TEXTOVERFLOW))
- {
- SetClipRect(CPDF_Rect(0.0f,0.0f,0.0f,0.0f));
- m_pEdit->SetTextOverflow(TRUE);
- }
-}
-
-void CPWL_Label::SetText(FX_LPCWSTR csText)
-{
- m_pEdit->SetText(csText);
-}
-
-void CPWL_Label::RePosChildWnd()
-{
- m_pEdit->SetPlateRect(GetClientRect());
-}
-
-void CPWL_Label::SetFontSize(FX_FLOAT fFontSize)
-{
- m_pEdit->SetFontSize(fFontSize);
-}
-
-FX_FLOAT CPWL_Label::GetFontSize() const
-{
- return m_pEdit->GetFontSize();
-}
-
-void CPWL_Label::SetParamByFlag()
-{
- if (HasFlag(PES_LEFT))
- {
- m_pEdit->SetAlignmentH(0);
- }
- else if (HasFlag(PES_MIDDLE))
- {
- m_pEdit->SetAlignmentH(1);
- }
- else if (HasFlag(PES_RIGHT))
- {
- m_pEdit->SetAlignmentH(2);
- }
- else
- {
- m_pEdit->SetAlignmentH(0);
- }
-
- if (HasFlag(PES_TOP))
- {
- m_pEdit->SetAlignmentV(0);
- }
- else if (HasFlag(PES_CENTER))
- {
- m_pEdit->SetAlignmentV(1);
- }
- else if (HasFlag(PES_BOTTOM))
- {
- m_pEdit->SetAlignmentV(2);
- }
- else
- {
- m_pEdit->SetAlignmentV(0);
- }
-
- if (HasFlag(PES_PASSWORD))
- {
- m_pEdit->SetPasswordChar('*');
- }
-
- m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE));
- m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN));
- m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE));
- m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL));
-}
-
-void CPWL_Label::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
-
- GetClientRect();
-
- CPDF_Rect rcClip;
- CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
- CPVT_WordRange* pRange = NULL;
-
- if (!HasFlag(PES_TEXTOVERFLOW))
- {
- rcClip = GetClientRect();
- pRange = &wrRange;
- }
-IFX_SystemHandler* pSysHandler = GetSystemHandler();
- IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit,
- CPWL_Utils::PWLColorToFXColor(GetTextColor(), this->GetTransparency()),
- CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), this->GetTransparency()),
- rcClip, CPDF_Point(0.0f,0.0f), pRange,pSysHandler, NULL);
-}
-
-void CPWL_Label::SetHorzScale(FX_INT32 nHorzScale)
-{
- m_pEdit->SetHorzScale(nHorzScale);
-}
-
-void CPWL_Label::SetCharSpace(FX_FLOAT fCharSpace)
-{
- m_pEdit->SetCharSpace(fCharSpace);
-}
-
-CPDF_Rect CPWL_Label::GetContentRect() const
-{
- return m_pEdit->GetContentRect();
-}
-
-void CPWL_Label::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- CPWL_Wnd::GetThisAppearanceStream(sAppStream);
-
- sAppStream << GetTextAppearanceStream(CPDF_Point(0.0f, 0.0f));
-}
-
-CFX_ByteString CPWL_Label::GetTextAppearanceStream(const CPDF_Point & ptOffset) const
-{
- CFX_ByteTextBuf sRet;
- CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit,ptOffset);
-
- if (sEdit.GetLength() > 0)
- {
- sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEdit << "ET\n";
- }
-
- return sRet.GetByteString();
-}
-
-CFX_WideString CPWL_Label::GetText() const
-{
- return m_pEdit->GetText();
-}
-
-void CPWL_Label::SetLimitChar(FX_INT32 nLimitChar)
-{
- m_pEdit->SetLimitChar(nLimitChar);
-}
-
-FX_INT32 CPWL_Label::GetTotalWords()
-{
- if (m_pEdit)
- return m_pEdit->GetTotalWords();
-
- return 0;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Label.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+/* ---------------------------- CPWL_Label ------------------------------ */
+
+CPWL_Label::CPWL_Label() : m_pEdit(NULL)
+{
+ m_pEdit = IFX_Edit::NewEdit();
+
+ ASSERT(m_pEdit != NULL);
+}
+
+CPWL_Label::~CPWL_Label()
+{
+ IFX_Edit::DelEdit(m_pEdit);
+}
+
+CFX_ByteString CPWL_Label::GetClassName() const
+{
+ return "CPWL_Label";
+}
+
+void CPWL_Label::OnCreated()
+{
+ SetParamByFlag();
+ SetFontSize(this->GetCreationParam().fFontSize);
+
+ m_pEdit->SetFontMap(this->GetFontMap());
+ m_pEdit->Initialize();
+
+ if (HasFlag(PES_TEXTOVERFLOW))
+ {
+ SetClipRect(CPDF_Rect(0.0f,0.0f,0.0f,0.0f));
+ m_pEdit->SetTextOverflow(TRUE);
+ }
+}
+
+void CPWL_Label::SetText(FX_LPCWSTR csText)
+{
+ m_pEdit->SetText(csText);
+}
+
+void CPWL_Label::RePosChildWnd()
+{
+ m_pEdit->SetPlateRect(GetClientRect());
+}
+
+void CPWL_Label::SetFontSize(FX_FLOAT fFontSize)
+{
+ m_pEdit->SetFontSize(fFontSize);
+}
+
+FX_FLOAT CPWL_Label::GetFontSize() const
+{
+ return m_pEdit->GetFontSize();
+}
+
+void CPWL_Label::SetParamByFlag()
+{
+ if (HasFlag(PES_LEFT))
+ {
+ m_pEdit->SetAlignmentH(0);
+ }
+ else if (HasFlag(PES_MIDDLE))
+ {
+ m_pEdit->SetAlignmentH(1);
+ }
+ else if (HasFlag(PES_RIGHT))
+ {
+ m_pEdit->SetAlignmentH(2);
+ }
+ else
+ {
+ m_pEdit->SetAlignmentH(0);
+ }
+
+ if (HasFlag(PES_TOP))
+ {
+ m_pEdit->SetAlignmentV(0);
+ }
+ else if (HasFlag(PES_CENTER))
+ {
+ m_pEdit->SetAlignmentV(1);
+ }
+ else if (HasFlag(PES_BOTTOM))
+ {
+ m_pEdit->SetAlignmentV(2);
+ }
+ else
+ {
+ m_pEdit->SetAlignmentV(0);
+ }
+
+ if (HasFlag(PES_PASSWORD))
+ {
+ m_pEdit->SetPasswordChar('*');
+ }
+
+ m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE));
+ m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN));
+ m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE));
+ m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL));
+}
+
+void CPWL_Label::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
+
+ GetClientRect();
+
+ CPDF_Rect rcClip;
+ CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
+ CPVT_WordRange* pRange = NULL;
+
+ if (!HasFlag(PES_TEXTOVERFLOW))
+ {
+ rcClip = GetClientRect();
+ pRange = &wrRange;
+ }
+IFX_SystemHandler* pSysHandler = GetSystemHandler();
+ IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit,
+ CPWL_Utils::PWLColorToFXColor(GetTextColor(), this->GetTransparency()),
+ CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), this->GetTransparency()),
+ rcClip, CPDF_Point(0.0f,0.0f), pRange,pSysHandler, NULL);
+}
+
+void CPWL_Label::SetHorzScale(FX_INT32 nHorzScale)
+{
+ m_pEdit->SetHorzScale(nHorzScale);
+}
+
+void CPWL_Label::SetCharSpace(FX_FLOAT fCharSpace)
+{
+ m_pEdit->SetCharSpace(fCharSpace);
+}
+
+CPDF_Rect CPWL_Label::GetContentRect() const
+{
+ return m_pEdit->GetContentRect();
+}
+
+void CPWL_Label::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ CPWL_Wnd::GetThisAppearanceStream(sAppStream);
+
+ sAppStream << GetTextAppearanceStream(CPDF_Point(0.0f, 0.0f));
+}
+
+CFX_ByteString CPWL_Label::GetTextAppearanceStream(const CPDF_Point & ptOffset) const
+{
+ CFX_ByteTextBuf sRet;
+ CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit,ptOffset);
+
+ if (sEdit.GetLength() > 0)
+ {
+ sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEdit << "ET\n";
+ }
+
+ return sRet.GetByteString();
+}
+
+CFX_WideString CPWL_Label::GetText() const
+{
+ return m_pEdit->GetText();
+}
+
+void CPWL_Label::SetLimitChar(FX_INT32 nLimitChar)
+{
+ m_pEdit->SetLimitChar(nLimitChar);
+}
+
+FX_INT32 CPWL_Label::GetTotalWords()
+{
+ if (m_pEdit)
+ return m_pEdit->GetTotalWords();
+
+ return 0;
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_ListBox.cpp b/fpdfsdk/src/pdfwindow/PWL_ListBox.cpp
index 951ed93f79..035d81959d 100644
--- a/fpdfsdk/src/pdfwindow/PWL_ListBox.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_ListBox.cpp
@@ -1,632 +1,632 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_ListBox.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-#include "../../include/pdfwindow/PWL_ScrollBar.h"
-#include "../../include/pdfwindow/PWL_EditCtrl.h"
-#include "../../include/pdfwindow/PWL_Edit.h"
-
-#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
-#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
-
-/* ------------------------ CPWL_List_Notify ----------------------- */
-
-CPWL_List_Notify::CPWL_List_Notify(CPWL_ListBox* pList) : m_pList(pList)
-{
- ASSERT(m_pList != NULL);
-}
-
-CPWL_List_Notify::~CPWL_List_Notify()
-{
-}
-
-void CPWL_List_Notify::IOnSetScrollInfoY(FX_FLOAT fPlateMin, FX_FLOAT fPlateMax,
- FX_FLOAT fContentMin, FX_FLOAT fContentMax,
- FX_FLOAT fSmallStep, FX_FLOAT fBigStep)
-{
- PWL_SCROLL_INFO Info;
-
- Info.fPlateWidth = fPlateMax - fPlateMin;
- Info.fContentMin = fContentMin;
- Info.fContentMax = fContentMax;
- Info.fSmallStep = fSmallStep;
- Info.fBigStep = fBigStep;
-
- m_pList->OnNotify(m_pList,PNM_SETSCROLLINFO,SBT_VSCROLL,(FX_INTPTR)&Info);
-
- if (CPWL_ScrollBar * pScroll = m_pList->GetVScrollBar())
- {
- if (IsFloatBigger(Info.fPlateWidth,Info.fContentMax-Info.fContentMin)
- || IsFloatEqual(Info.fPlateWidth,Info.fContentMax-Info.fContentMin))
- {
- if (pScroll->IsVisible())
- {
- pScroll->SetVisible(FALSE);
- m_pList->RePosChildWnd();
- }
- }
- else
- {
- if (!pScroll->IsVisible())
- {
- pScroll->SetVisible(TRUE);
- m_pList->RePosChildWnd();
- }
- }
- }
-}
-
-void CPWL_List_Notify::IOnSetScrollPosY(FX_FLOAT fy)
-{
- m_pList->OnNotify(m_pList,PNM_SETSCROLLPOS,SBT_VSCROLL,(FX_INTPTR)&fy);
-}
-
-void CPWL_List_Notify::IOnInvalidateRect(CPDF_Rect * pRect)
-{
- m_pList->InvalidateRect(pRect);
-}
-
-/* --------------------------- CPWL_ListBox ---------------------------- */
-
-CPWL_ListBox::CPWL_ListBox() :
- m_pList(NULL),
- m_pListNotify(NULL),
- m_bMouseDown(FALSE),
- m_bHoverSel(FALSE),
- m_pFillerNotify(NULL)
-{
- m_pList = IFX_List::NewList();
-
- ASSERT(m_pList != NULL);
-}
-
-CPWL_ListBox::~CPWL_ListBox()
-{
- IFX_List::DelList(m_pList);
-
- if (m_pListNotify)
- {
- delete m_pListNotify;
- m_pListNotify = NULL;
- }
-}
-
-CFX_ByteString CPWL_ListBox::GetClassName() const
-{
- return "CPWL_ListBox";
-}
-
-void CPWL_ListBox::OnCreated()
-{
- if (m_pList)
- {
- if (m_pListNotify) delete m_pListNotify;
-
- m_pList->SetFontMap(GetFontMap());
- m_pList->SetNotify(m_pListNotify = new CPWL_List_Notify(this));
-
- SetHoverSel(HasFlag(PLBS_HOVERSEL));
- m_pList->SetMultipleSel(HasFlag(PLBS_MULTIPLESEL));
- m_pList->SetFontSize(this->GetCreationParam().fFontSize);
-
- m_bHoverSel = HasFlag(PLBS_HOVERSEL);
- }
-}
-
-void CPWL_ListBox::OnDestroy()
-{
- if (m_pListNotify)
- {
- delete m_pListNotify;
- m_pListNotify = NULL;
- }
-}
-
-void CPWL_ListBox::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- CPWL_Wnd::GetThisAppearanceStream(sAppStream);
-
- CFX_ByteTextBuf sListItems;
-
- if (m_pList)
- {
- CPDF_Rect rcPlate = m_pList->GetPlateRect();
- for (FX_INT32 i=0,sz=m_pList->GetCount(); i<sz; i++)
- {
- CPDF_Rect rcItem = m_pList->GetItemRect(i);
-
- if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) continue;
-
- CPDF_Point ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f);
- if (m_pList->IsItemSelected(i))
- {
- sListItems << CPWL_Utils::GetRectFillAppStream(rcItem,PWL_DEFAULT_SELBACKCOLOR);
- CFX_ByteString sItem = CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset);
- if (sItem.GetLength() > 0)
- {
- sListItems << "BT\n" << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELTEXTCOLOR) << sItem << "ET\n";
- }
- }
- else
- {
- CFX_ByteString sItem = CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset);
- if (sItem.GetLength() > 0)
- {
- sListItems << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sItem << "ET\n";
- }
- }
- }
- }
-
- if (sListItems.GetLength() > 0)
- {
- CFX_ByteTextBuf sClip;
- CPDF_Rect rcClient = this->GetClientRect();
-
- sClip << "q\n";
- sClip << rcClient.left << " " << rcClient.bottom << " "
- << rcClient.right - rcClient.left << " " << rcClient.top - rcClient.bottom << " re W n\n";
-
- sClip << sListItems << "Q\n";
-
- sAppStream << "/Tx BMC\n" << sClip << "EMC\n";
- }
-}
-
-void CPWL_ListBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
-
- if (m_pList)
- {
- CPDF_Rect rcPlate = m_pList->GetPlateRect();
- CPDF_Rect rcList = GetListRect();
- CPDF_Rect rcClient = GetClientRect();
-
- for (FX_INT32 i=0,sz=m_pList->GetCount(); i<sz; i++)
- {
- CPDF_Rect rcItem = m_pList->GetItemRect(i);
- if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) continue;
-
- CPDF_Point ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f);
- if (IFX_Edit* pEdit = m_pList->GetItemEdit(i))
- {
- CPDF_Rect rcContent = pEdit->GetContentRect();
- if (rcContent.Width() > rcClient.Width())
- rcItem.Intersect(rcList);
- else
- rcItem.Intersect(rcClient);
- }
-
- if (m_pList->IsItemSelected(i))
- {
- // CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, ArgbEncode(255,0,51,113));
- IFX_SystemHandler* pSysHandler = GetSystemHandler();
- if(pSysHandler && pSysHandler->IsSelectionImplemented())
- {
- IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), CPWL_Utils::PWLColorToFXColor(GetTextColor()), CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()),
- rcList, ptOffset, NULL,pSysHandler, m_pFormFiller);
- pSysHandler->OutputSelectedRect(m_pFormFiller, rcItem);
- }
- else
- {
- CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, ArgbEncode(255,0,51,113));
- IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), ArgbEncode(255,255,255,255), 0,
- rcList, ptOffset, NULL, pSysHandler, m_pFormFiller);
- }
- }
- else
- {
- IFX_SystemHandler* pSysHandler = GetSystemHandler();
- IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i),
- CPWL_Utils::PWLColorToFXColor(GetTextColor()),
- CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()),
- rcList, ptOffset, NULL,pSysHandler, NULL);
-
- }
- }
- }
-}
-
-FX_BOOL CPWL_ListBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnKeyDown(nChar, nFlag);
-
- if (!m_pList) return FALSE;
-
- switch (nChar)
- {
- default:
- return FALSE;
- case FWL_VKEY_Up:
- case FWL_VKEY_Down:
- case FWL_VKEY_Home:
- case FWL_VKEY_Left:
- case FWL_VKEY_End:
- case FWL_VKEY_Right:
- break;
- }
-
- switch (nChar)
- {
- case FWL_VKEY_Up:
- m_pList->OnVK_UP(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Down:
- m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Home:
- m_pList->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Left:
- m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_End:
- m_pList->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Right:
- m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Delete:
- break;
- }
-
- FX_BOOL bExit = FALSE;
- OnNotifySelChanged(TRUE,bExit,nFlag);
-
- return TRUE;
-}
-
-FX_BOOL CPWL_ListBox::OnChar(FX_WORD nChar, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnChar(nChar,nFlag);
-
- if (!m_pList) return FALSE;
-
- if (!m_pList->OnChar(nChar,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag))) return FALSE;
-
- FX_BOOL bExit = FALSE;
- OnNotifySelChanged(TRUE,bExit, nFlag);
-
- return TRUE;
-}
-
-FX_BOOL CPWL_ListBox::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonDown(point,nFlag);
-
- if (ClientHitTest(point))
- {
- m_bMouseDown = TRUE;
- SetFocus();
- SetCapture();
-
- if (m_pList)
- m_pList->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- }
-
- return TRUE;
-}
-
-FX_BOOL CPWL_ListBox::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonUp(point,nFlag);
-
- if (m_bMouseDown)
- {
- ReleaseCapture();
- m_bMouseDown = FALSE;
- }
-
- FX_BOOL bExit = FALSE;
- OnNotifySelChanged(FALSE,bExit,nFlag);
-
- return TRUE;
-}
-
-void CPWL_ListBox::SetHoverSel(FX_BOOL bHoverSel)
-{
- m_bHoverSel = bHoverSel;
-}
-
-FX_BOOL CPWL_ListBox::OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnMouseMove(point, nFlag);
-
- if (m_bHoverSel && !IsCaptureMouse() && ClientHitTest(point))
- {
- if (m_pList)
- m_pList->Select(m_pList->GetItemIndex(point));
- }
-
- if (m_bMouseDown)
- {
- if (m_pList)
- m_pList->OnMouseMove(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- }
-
- return TRUE;
-}
-
-void CPWL_ListBox::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
-
- FX_FLOAT fPos;
-
- switch (msg)
- {
- case PNM_SETSCROLLINFO:
- switch (wParam)
- {
- case SBT_VSCROLL:
- if (CPWL_Wnd * pChild = GetVScrollBar())
- {
- pChild->OnNotify(pWnd,PNM_SETSCROLLINFO,wParam,lParam);
- }
- break;
- }
- break;
- case PNM_SETSCROLLPOS:
- switch (wParam)
- {
- case SBT_VSCROLL:
- if (CPWL_Wnd * pChild = GetVScrollBar())
- {
- pChild->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);
- }
- break;
- }
- break;
- case PNM_SCROLLWINDOW:
- fPos = *(FX_FLOAT*)lParam;
- switch (wParam)
- {
- case SBT_VSCROLL:
- if (m_pList)
- m_pList->SetScrollPos(CPDF_Point(0,fPos));
- break;
- }
- break;
- }
-}
-
-void CPWL_ListBox::KillFocus()
-{
- CPWL_Wnd::KillFocus();
-
- /*
- if (this->IsMultipleSel())
- {
- for(FX_INT32 i=0;i<this->GetCount();i++)
- {
- if (this->IsListItemSelected(i))
- {
- if (!IsListItemVisible(i))
- this->ScrollToListItem(i);
- break;
- }
- }
- }
- else
- {
- if (!IsListItemVisible(this->GetCurSel()))
- this->ScrollToListItem(this->GetCurSel());
- }
-
- SetListItemCaret(m_nCaretIndex,FALSE);
- */
-}
-
-void CPWL_ListBox::RePosChildWnd()
-{
- CPWL_Wnd::RePosChildWnd();
-
- if (m_pList)
- m_pList->SetPlateRect(GetListRect());
-}
-
-void CPWL_ListBox::OnNotifySelChanged(FX_BOOL bKeyDown, FX_BOOL & bExit, FX_DWORD nFlag)
-{
- if (m_pFillerNotify)
- {
- FX_BOOL bRC = TRUE;
- CFX_WideString swChange = GetText();
- CFX_WideString strChangeEx;
- int nSelStart = 0;
- int nSelEnd = swChange.GetLength();
- m_pFillerNotify->OnBeforeKeyStroke(FALSE, GetAttachedData(), 0, swChange, strChangeEx, nSelStart, nSelEnd, bKeyDown, bRC, bExit, nFlag);
- if (bExit) return;
-
- m_pFillerNotify->OnAfterKeyStroke(FALSE, GetAttachedData(), bExit,nFlag);
- }
-}
-
-CPDF_Rect CPWL_ListBox::GetFocusRect() const
-{
- if (m_pList && m_pList->IsMultipleSel())
- {
- CPDF_Rect rcCaret = m_pList->GetItemRect(m_pList->GetCaret());
- rcCaret.Intersect(GetClientRect());
- return rcCaret;
- }
-
- return CPWL_Wnd::GetFocusRect();
-}
-
-void CPWL_ListBox::AddString(FX_LPCWSTR string)
-{
- if (m_pList)
- {
- m_pList->AddString(string);
- }
-}
-
-void CPWL_ListBox::SetText(FX_LPCWSTR csText,FX_BOOL bRefresh)
-{
- //return CPDF_List::SetText(csText,bRefresh);
-}
-
-CFX_WideString CPWL_ListBox::GetText() const
-{
- if (m_pList)
- return m_pList->GetText();
-
- return L"";
-}
-
-void CPWL_ListBox::SetFontSize(FX_FLOAT fFontSize)
-{
- if (m_pList)
- m_pList->SetFontSize(fFontSize);
-}
-
-FX_FLOAT CPWL_ListBox::GetFontSize() const
-{
- if (m_pList)
- return m_pList->GetFontSize();
- return 0.0f;
-}
-
-void CPWL_ListBox::Select(FX_INT32 nItemIndex)
-{
- if (m_pList)
- m_pList->Select(nItemIndex);
-}
-
-void CPWL_ListBox::SetCaret(FX_INT32 nItemIndex)
-{
- if (m_pList)
- m_pList->SetCaret(nItemIndex);
-}
-
-void CPWL_ListBox::SetTopVisibleIndex(FX_INT32 nItemIndex)
-{
- if (m_pList)
- m_pList->SetTopItem(nItemIndex);
-}
-
-void CPWL_ListBox::ScrollToListItem(FX_INT32 nItemIndex)
-{
- if (m_pList)
- m_pList->ScrollToListItem(nItemIndex);
-}
-
-void CPWL_ListBox::ResetContent()
-{
- if (m_pList)
- m_pList->Empty();
-}
-
-void CPWL_ListBox::Reset()
-{
- if (m_pList)
- m_pList->Cancel();
-}
-
-FX_BOOL CPWL_ListBox::IsMultipleSel() const
-{
- if (m_pList)
- return m_pList->IsMultipleSel();
-
- return FALSE;
-}
-
-FX_INT32 CPWL_ListBox::GetCaretIndex() const
-{
- if (m_pList)
- return m_pList->GetCaret();
-
- return -1;
-}
-
-FX_INT32 CPWL_ListBox::GetCurSel() const
-{
- if (m_pList)
- return m_pList->GetSelect();
-
- return -1;
-}
-
-FX_BOOL CPWL_ListBox::IsItemSelected(FX_INT32 nItemIndex) const
-{
- if (m_pList)
- return m_pList->IsItemSelected(nItemIndex);
-
- return FALSE;
-}
-
-FX_INT32 CPWL_ListBox::GetTopVisibleIndex() const
-{
- if (m_pList)
- {
- m_pList->ScrollToListItem(m_pList->GetFirstSelected());
- return m_pList->GetTopItem();
- }
-
- return -1;
-}
-
-FX_INT32 CPWL_ListBox::GetCount() const
-{
- if (m_pList)
- return m_pList->GetCount();
-
- return 0;
-}
-
-FX_INT32 CPWL_ListBox::FindNext(FX_INT32 nIndex,FX_WCHAR nChar) const
-{
- if (m_pList)
- return m_pList->FindNext(nIndex,nChar);
-
- return nIndex;
-}
-
-CPDF_Rect CPWL_ListBox::GetContentRect() const
-{
- if (m_pList)
- return m_pList->GetContentRect();
-
- return CPDF_Rect();
-}
-
-FX_FLOAT CPWL_ListBox::GetFirstHeight() const
-{
- if (m_pList)
- return m_pList->GetFirstHeight();
-
- return 0.0f;
-}
-
-CPDF_Rect CPWL_ListBox::GetListRect() const
-{
- return CPWL_Utils::DeflateRect(GetWindowRect(),(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
-}
-
-FX_BOOL CPWL_ListBox::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag)
-{
- if (!m_pList) return FALSE;
-
- if (zDelta < 0)
- {
- m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- }
- else
- {
- m_pList->OnVK_UP(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
- }
-
- FX_BOOL bExit = FALSE;
- OnNotifySelChanged(FALSE,bExit, nFlag);
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_ListBox.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+#include "../../include/pdfwindow/PWL_ScrollBar.h"
+#include "../../include/pdfwindow/PWL_EditCtrl.h"
+#include "../../include/pdfwindow/PWL_Edit.h"
+
+#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
+#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
+
+/* ------------------------ CPWL_List_Notify ----------------------- */
+
+CPWL_List_Notify::CPWL_List_Notify(CPWL_ListBox* pList) : m_pList(pList)
+{
+ ASSERT(m_pList != NULL);
+}
+
+CPWL_List_Notify::~CPWL_List_Notify()
+{
+}
+
+void CPWL_List_Notify::IOnSetScrollInfoY(FX_FLOAT fPlateMin, FX_FLOAT fPlateMax,
+ FX_FLOAT fContentMin, FX_FLOAT fContentMax,
+ FX_FLOAT fSmallStep, FX_FLOAT fBigStep)
+{
+ PWL_SCROLL_INFO Info;
+
+ Info.fPlateWidth = fPlateMax - fPlateMin;
+ Info.fContentMin = fContentMin;
+ Info.fContentMax = fContentMax;
+ Info.fSmallStep = fSmallStep;
+ Info.fBigStep = fBigStep;
+
+ m_pList->OnNotify(m_pList,PNM_SETSCROLLINFO,SBT_VSCROLL,(FX_INTPTR)&Info);
+
+ if (CPWL_ScrollBar * pScroll = m_pList->GetVScrollBar())
+ {
+ if (IsFloatBigger(Info.fPlateWidth,Info.fContentMax-Info.fContentMin)
+ || IsFloatEqual(Info.fPlateWidth,Info.fContentMax-Info.fContentMin))
+ {
+ if (pScroll->IsVisible())
+ {
+ pScroll->SetVisible(FALSE);
+ m_pList->RePosChildWnd();
+ }
+ }
+ else
+ {
+ if (!pScroll->IsVisible())
+ {
+ pScroll->SetVisible(TRUE);
+ m_pList->RePosChildWnd();
+ }
+ }
+ }
+}
+
+void CPWL_List_Notify::IOnSetScrollPosY(FX_FLOAT fy)
+{
+ m_pList->OnNotify(m_pList,PNM_SETSCROLLPOS,SBT_VSCROLL,(FX_INTPTR)&fy);
+}
+
+void CPWL_List_Notify::IOnInvalidateRect(CPDF_Rect * pRect)
+{
+ m_pList->InvalidateRect(pRect);
+}
+
+/* --------------------------- CPWL_ListBox ---------------------------- */
+
+CPWL_ListBox::CPWL_ListBox() :
+ m_pList(NULL),
+ m_pListNotify(NULL),
+ m_bMouseDown(FALSE),
+ m_bHoverSel(FALSE),
+ m_pFillerNotify(NULL)
+{
+ m_pList = IFX_List::NewList();
+
+ ASSERT(m_pList != NULL);
+}
+
+CPWL_ListBox::~CPWL_ListBox()
+{
+ IFX_List::DelList(m_pList);
+
+ if (m_pListNotify)
+ {
+ delete m_pListNotify;
+ m_pListNotify = NULL;
+ }
+}
+
+CFX_ByteString CPWL_ListBox::GetClassName() const
+{
+ return "CPWL_ListBox";
+}
+
+void CPWL_ListBox::OnCreated()
+{
+ if (m_pList)
+ {
+ if (m_pListNotify) delete m_pListNotify;
+
+ m_pList->SetFontMap(GetFontMap());
+ m_pList->SetNotify(m_pListNotify = new CPWL_List_Notify(this));
+
+ SetHoverSel(HasFlag(PLBS_HOVERSEL));
+ m_pList->SetMultipleSel(HasFlag(PLBS_MULTIPLESEL));
+ m_pList->SetFontSize(this->GetCreationParam().fFontSize);
+
+ m_bHoverSel = HasFlag(PLBS_HOVERSEL);
+ }
+}
+
+void CPWL_ListBox::OnDestroy()
+{
+ if (m_pListNotify)
+ {
+ delete m_pListNotify;
+ m_pListNotify = NULL;
+ }
+}
+
+void CPWL_ListBox::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ CPWL_Wnd::GetThisAppearanceStream(sAppStream);
+
+ CFX_ByteTextBuf sListItems;
+
+ if (m_pList)
+ {
+ CPDF_Rect rcPlate = m_pList->GetPlateRect();
+ for (FX_INT32 i=0,sz=m_pList->GetCount(); i<sz; i++)
+ {
+ CPDF_Rect rcItem = m_pList->GetItemRect(i);
+
+ if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) continue;
+
+ CPDF_Point ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f);
+ if (m_pList->IsItemSelected(i))
+ {
+ sListItems << CPWL_Utils::GetRectFillAppStream(rcItem,PWL_DEFAULT_SELBACKCOLOR);
+ CFX_ByteString sItem = CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset);
+ if (sItem.GetLength() > 0)
+ {
+ sListItems << "BT\n" << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELTEXTCOLOR) << sItem << "ET\n";
+ }
+ }
+ else
+ {
+ CFX_ByteString sItem = CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset);
+ if (sItem.GetLength() > 0)
+ {
+ sListItems << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sItem << "ET\n";
+ }
+ }
+ }
+ }
+
+ if (sListItems.GetLength() > 0)
+ {
+ CFX_ByteTextBuf sClip;
+ CPDF_Rect rcClient = this->GetClientRect();
+
+ sClip << "q\n";
+ sClip << rcClient.left << " " << rcClient.bottom << " "
+ << rcClient.right - rcClient.left << " " << rcClient.top - rcClient.bottom << " re W n\n";
+
+ sClip << sListItems << "Q\n";
+
+ sAppStream << "/Tx BMC\n" << sClip << "EMC\n";
+ }
+}
+
+void CPWL_ListBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
+
+ if (m_pList)
+ {
+ CPDF_Rect rcPlate = m_pList->GetPlateRect();
+ CPDF_Rect rcList = GetListRect();
+ CPDF_Rect rcClient = GetClientRect();
+
+ for (FX_INT32 i=0,sz=m_pList->GetCount(); i<sz; i++)
+ {
+ CPDF_Rect rcItem = m_pList->GetItemRect(i);
+ if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) continue;
+
+ CPDF_Point ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f);
+ if (IFX_Edit* pEdit = m_pList->GetItemEdit(i))
+ {
+ CPDF_Rect rcContent = pEdit->GetContentRect();
+ if (rcContent.Width() > rcClient.Width())
+ rcItem.Intersect(rcList);
+ else
+ rcItem.Intersect(rcClient);
+ }
+
+ if (m_pList->IsItemSelected(i))
+ {
+ // CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, ArgbEncode(255,0,51,113));
+ IFX_SystemHandler* pSysHandler = GetSystemHandler();
+ if(pSysHandler && pSysHandler->IsSelectionImplemented())
+ {
+ IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), CPWL_Utils::PWLColorToFXColor(GetTextColor()), CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()),
+ rcList, ptOffset, NULL,pSysHandler, m_pFormFiller);
+ pSysHandler->OutputSelectedRect(m_pFormFiller, rcItem);
+ }
+ else
+ {
+ CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, ArgbEncode(255,0,51,113));
+ IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), ArgbEncode(255,255,255,255), 0,
+ rcList, ptOffset, NULL, pSysHandler, m_pFormFiller);
+ }
+ }
+ else
+ {
+ IFX_SystemHandler* pSysHandler = GetSystemHandler();
+ IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i),
+ CPWL_Utils::PWLColorToFXColor(GetTextColor()),
+ CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()),
+ rcList, ptOffset, NULL,pSysHandler, NULL);
+
+ }
+ }
+ }
+}
+
+FX_BOOL CPWL_ListBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnKeyDown(nChar, nFlag);
+
+ if (!m_pList) return FALSE;
+
+ switch (nChar)
+ {
+ default:
+ return FALSE;
+ case FWL_VKEY_Up:
+ case FWL_VKEY_Down:
+ case FWL_VKEY_Home:
+ case FWL_VKEY_Left:
+ case FWL_VKEY_End:
+ case FWL_VKEY_Right:
+ break;
+ }
+
+ switch (nChar)
+ {
+ case FWL_VKEY_Up:
+ m_pList->OnVK_UP(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Down:
+ m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Home:
+ m_pList->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Left:
+ m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_End:
+ m_pList->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Right:
+ m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Delete:
+ break;
+ }
+
+ FX_BOOL bExit = FALSE;
+ OnNotifySelChanged(TRUE,bExit,nFlag);
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_ListBox::OnChar(FX_WORD nChar, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnChar(nChar,nFlag);
+
+ if (!m_pList) return FALSE;
+
+ if (!m_pList->OnChar(nChar,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag))) return FALSE;
+
+ FX_BOOL bExit = FALSE;
+ OnNotifySelChanged(TRUE,bExit, nFlag);
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_ListBox::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonDown(point,nFlag);
+
+ if (ClientHitTest(point))
+ {
+ m_bMouseDown = TRUE;
+ SetFocus();
+ SetCapture();
+
+ if (m_pList)
+ m_pList->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_ListBox::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonUp(point,nFlag);
+
+ if (m_bMouseDown)
+ {
+ ReleaseCapture();
+ m_bMouseDown = FALSE;
+ }
+
+ FX_BOOL bExit = FALSE;
+ OnNotifySelChanged(FALSE,bExit,nFlag);
+
+ return TRUE;
+}
+
+void CPWL_ListBox::SetHoverSel(FX_BOOL bHoverSel)
+{
+ m_bHoverSel = bHoverSel;
+}
+
+FX_BOOL CPWL_ListBox::OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnMouseMove(point, nFlag);
+
+ if (m_bHoverSel && !IsCaptureMouse() && ClientHitTest(point))
+ {
+ if (m_pList)
+ m_pList->Select(m_pList->GetItemIndex(point));
+ }
+
+ if (m_bMouseDown)
+ {
+ if (m_pList)
+ m_pList->OnMouseMove(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ }
+
+ return TRUE;
+}
+
+void CPWL_ListBox::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
+
+ FX_FLOAT fPos;
+
+ switch (msg)
+ {
+ case PNM_SETSCROLLINFO:
+ switch (wParam)
+ {
+ case SBT_VSCROLL:
+ if (CPWL_Wnd * pChild = GetVScrollBar())
+ {
+ pChild->OnNotify(pWnd,PNM_SETSCROLLINFO,wParam,lParam);
+ }
+ break;
+ }
+ break;
+ case PNM_SETSCROLLPOS:
+ switch (wParam)
+ {
+ case SBT_VSCROLL:
+ if (CPWL_Wnd * pChild = GetVScrollBar())
+ {
+ pChild->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);
+ }
+ break;
+ }
+ break;
+ case PNM_SCROLLWINDOW:
+ fPos = *(FX_FLOAT*)lParam;
+ switch (wParam)
+ {
+ case SBT_VSCROLL:
+ if (m_pList)
+ m_pList->SetScrollPos(CPDF_Point(0,fPos));
+ break;
+ }
+ break;
+ }
+}
+
+void CPWL_ListBox::KillFocus()
+{
+ CPWL_Wnd::KillFocus();
+
+ /*
+ if (this->IsMultipleSel())
+ {
+ for(FX_INT32 i=0;i<this->GetCount();i++)
+ {
+ if (this->IsListItemSelected(i))
+ {
+ if (!IsListItemVisible(i))
+ this->ScrollToListItem(i);
+ break;
+ }
+ }
+ }
+ else
+ {
+ if (!IsListItemVisible(this->GetCurSel()))
+ this->ScrollToListItem(this->GetCurSel());
+ }
+
+ SetListItemCaret(m_nCaretIndex,FALSE);
+ */
+}
+
+void CPWL_ListBox::RePosChildWnd()
+{
+ CPWL_Wnd::RePosChildWnd();
+
+ if (m_pList)
+ m_pList->SetPlateRect(GetListRect());
+}
+
+void CPWL_ListBox::OnNotifySelChanged(FX_BOOL bKeyDown, FX_BOOL & bExit, FX_DWORD nFlag)
+{
+ if (m_pFillerNotify)
+ {
+ FX_BOOL bRC = TRUE;
+ CFX_WideString swChange = GetText();
+ CFX_WideString strChangeEx;
+ int nSelStart = 0;
+ int nSelEnd = swChange.GetLength();
+ m_pFillerNotify->OnBeforeKeyStroke(FALSE, GetAttachedData(), 0, swChange, strChangeEx, nSelStart, nSelEnd, bKeyDown, bRC, bExit, nFlag);
+ if (bExit) return;
+
+ m_pFillerNotify->OnAfterKeyStroke(FALSE, GetAttachedData(), bExit,nFlag);
+ }
+}
+
+CPDF_Rect CPWL_ListBox::GetFocusRect() const
+{
+ if (m_pList && m_pList->IsMultipleSel())
+ {
+ CPDF_Rect rcCaret = m_pList->GetItemRect(m_pList->GetCaret());
+ rcCaret.Intersect(GetClientRect());
+ return rcCaret;
+ }
+
+ return CPWL_Wnd::GetFocusRect();
+}
+
+void CPWL_ListBox::AddString(FX_LPCWSTR string)
+{
+ if (m_pList)
+ {
+ m_pList->AddString(string);
+ }
+}
+
+void CPWL_ListBox::SetText(FX_LPCWSTR csText,FX_BOOL bRefresh)
+{
+ //return CPDF_List::SetText(csText,bRefresh);
+}
+
+CFX_WideString CPWL_ListBox::GetText() const
+{
+ if (m_pList)
+ return m_pList->GetText();
+
+ return L"";
+}
+
+void CPWL_ListBox::SetFontSize(FX_FLOAT fFontSize)
+{
+ if (m_pList)
+ m_pList->SetFontSize(fFontSize);
+}
+
+FX_FLOAT CPWL_ListBox::GetFontSize() const
+{
+ if (m_pList)
+ return m_pList->GetFontSize();
+ return 0.0f;
+}
+
+void CPWL_ListBox::Select(FX_INT32 nItemIndex)
+{
+ if (m_pList)
+ m_pList->Select(nItemIndex);
+}
+
+void CPWL_ListBox::SetCaret(FX_INT32 nItemIndex)
+{
+ if (m_pList)
+ m_pList->SetCaret(nItemIndex);
+}
+
+void CPWL_ListBox::SetTopVisibleIndex(FX_INT32 nItemIndex)
+{
+ if (m_pList)
+ m_pList->SetTopItem(nItemIndex);
+}
+
+void CPWL_ListBox::ScrollToListItem(FX_INT32 nItemIndex)
+{
+ if (m_pList)
+ m_pList->ScrollToListItem(nItemIndex);
+}
+
+void CPWL_ListBox::ResetContent()
+{
+ if (m_pList)
+ m_pList->Empty();
+}
+
+void CPWL_ListBox::Reset()
+{
+ if (m_pList)
+ m_pList->Cancel();
+}
+
+FX_BOOL CPWL_ListBox::IsMultipleSel() const
+{
+ if (m_pList)
+ return m_pList->IsMultipleSel();
+
+ return FALSE;
+}
+
+FX_INT32 CPWL_ListBox::GetCaretIndex() const
+{
+ if (m_pList)
+ return m_pList->GetCaret();
+
+ return -1;
+}
+
+FX_INT32 CPWL_ListBox::GetCurSel() const
+{
+ if (m_pList)
+ return m_pList->GetSelect();
+
+ return -1;
+}
+
+FX_BOOL CPWL_ListBox::IsItemSelected(FX_INT32 nItemIndex) const
+{
+ if (m_pList)
+ return m_pList->IsItemSelected(nItemIndex);
+
+ return FALSE;
+}
+
+FX_INT32 CPWL_ListBox::GetTopVisibleIndex() const
+{
+ if (m_pList)
+ {
+ m_pList->ScrollToListItem(m_pList->GetFirstSelected());
+ return m_pList->GetTopItem();
+ }
+
+ return -1;
+}
+
+FX_INT32 CPWL_ListBox::GetCount() const
+{
+ if (m_pList)
+ return m_pList->GetCount();
+
+ return 0;
+}
+
+FX_INT32 CPWL_ListBox::FindNext(FX_INT32 nIndex,FX_WCHAR nChar) const
+{
+ if (m_pList)
+ return m_pList->FindNext(nIndex,nChar);
+
+ return nIndex;
+}
+
+CPDF_Rect CPWL_ListBox::GetContentRect() const
+{
+ if (m_pList)
+ return m_pList->GetContentRect();
+
+ return CPDF_Rect();
+}
+
+FX_FLOAT CPWL_ListBox::GetFirstHeight() const
+{
+ if (m_pList)
+ return m_pList->GetFirstHeight();
+
+ return 0.0f;
+}
+
+CPDF_Rect CPWL_ListBox::GetListRect() const
+{
+ return CPWL_Utils::DeflateRect(GetWindowRect(),(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
+}
+
+FX_BOOL CPWL_ListBox::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag)
+{
+ if (!m_pList) return FALSE;
+
+ if (zDelta < 0)
+ {
+ m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ }
+ else
+ {
+ m_pList->OnVK_UP(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+ }
+
+ FX_BOOL bExit = FALSE;
+ OnNotifySelChanged(FALSE,bExit, nFlag);
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_ListCtrl.cpp b/fpdfsdk/src/pdfwindow/PWL_ListCtrl.cpp
index 603bb4a139..9ac18fdc63 100644
--- a/fpdfsdk/src/pdfwindow/PWL_ListCtrl.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_ListCtrl.cpp
@@ -1,245 +1,245 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_ListCtrl.h"
-
-/* ---------------------------- CPWL_ListCtrl ---------------------------- */
-
-CPWL_ListCtrl::CPWL_ListCtrl() :
- m_rcContent(0,0,0,0),
- m_ptScroll(0,0),
- m_fItemSpace(0.0f),
- m_fTopSpace(0.0f),
- m_fBottomSpace(0.0f)
-{
-}
-
-CPWL_ListCtrl::~CPWL_ListCtrl()
-{
-}
-
-void CPWL_ListCtrl::SetScrollPos(const CPDF_Point& point)
-{
- m_ptScroll = point;
-
- if (m_ptScroll.x < m_rcContent.left)
- m_ptScroll.x = m_rcContent.left;
-
- if (m_ptScroll.x > m_rcContent.right)
- m_ptScroll.x = m_rcContent.right;
-
- if (m_ptScroll.y > m_rcContent.top)
- m_ptScroll.y = m_rcContent.top;
-
- if (m_ptScroll.y < m_rcContent.bottom)
- m_ptScroll.y = m_rcContent.bottom;
-}
-
-CPDF_Point CPWL_ListCtrl::GetScrollPos() const
-{
- return m_ptScroll;
-}
-
-CPDF_Rect CPWL_ListCtrl::GetScrollArea() const
-{
- return m_rcContent;
-}
-
-void CPWL_ListCtrl::ResetFace()
-{
- ResetAll(FALSE, 0);
-}
-
-void CPWL_ListCtrl::ResetContent(FX_INT32 nStart)
-{
- if (nStart < 0)
- nStart = 0;
- if (nStart >= 0 && nStart < m_aChildren.GetSize())
- ResetAll(TRUE, nStart);
-}
-
-FX_FLOAT CPWL_ListCtrl::GetContentsHeight(FX_FLOAT fLimitWidth)
-{
- FX_FLOAT fRet = m_fTopSpace;
-
- FX_FLOAT fBorderWidth = (FX_FLOAT)this->GetBorderWidth();
-
- if (fLimitWidth > fBorderWidth* 2)
- {
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- FX_FLOAT fLeft = pChild->GetItemLeftMargin();
- FX_FLOAT fRight = pChild->GetItemRightMargin();
-
- fRet += pChild->GetItemHeight(fLimitWidth - fBorderWidth* 2 - fLeft - fRight);
- fRet += m_fItemSpace;
- }
- }
-
- fRet -= m_fItemSpace;
- }
-
- fRet += m_fBottomSpace;
-
- return fRet;
-}
-
-void CPWL_ListCtrl::ResetAll(FX_BOOL bMove, FX_INT32 nStart)
-{
- CPDF_Rect rcClient = GetClientRect();
-
- FX_FLOAT fWidth = rcClient.Width();
-
- FX_FLOAT fy = 0.0f - m_fTopSpace;
-
- if (nStart-1 >= 0 && nStart-1 < m_aChildren.GetSize())
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(nStart-1))
- fy = pChild->GetWindowRect().bottom - m_fItemSpace;
-
- for (FX_INT32 i=nStart,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- FX_FLOAT fLeft = pChild->GetItemLeftMargin();
- FX_FLOAT fRight = pChild->GetItemRightMargin();
-
- pChild->SetChildMatrix(
- CPDF_Matrix(1,0,0,1,
- rcClient.left - m_ptScroll.x,
- rcClient.top - m_ptScroll.y)
- );
-
- if (bMove)
- {
- FX_FLOAT fItemHeight = pChild->GetItemHeight(fWidth - fLeft - fRight);
- pChild->Move(CPDF_Rect(fLeft, fy-fItemHeight, fWidth - fRight, fy), TRUE, FALSE);
- fy -= fItemHeight;
- fy -= m_fItemSpace;
- }
- }
- }
-
- fy += m_fItemSpace;
-
- fy -= m_fBottomSpace;
-
- if (bMove)
- {
- m_rcContent.left = 0;
- m_rcContent.top = 0;
- m_rcContent.right = fWidth;
- m_rcContent.bottom = fy;
- }
-}
-
-void CPWL_ListCtrl::SetItemSpace(FX_FLOAT fSpace)
-{
- m_fItemSpace = fSpace;
-}
-
-void CPWL_ListCtrl::SetTopSpace(FX_FLOAT fSpace)
-{
- m_fTopSpace = fSpace;
-}
-
-void CPWL_ListCtrl::SetBottomSpace(FX_FLOAT fSpace)
-{
- m_fBottomSpace = fSpace;
-}
-
-void CPWL_ListCtrl::RePosChildWnd()
-{
- ResetFace();
-}
-
-void CPWL_ListCtrl::DrawChildAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- pDevice->SaveState();
- CPDF_Rect rcClient = GetClientRect();
- CPDF_Rect rcTemp = rcClient;
- pUser2Device->TransformRect(rcTemp);
- FX_RECT rcClip((FX_INT32)rcTemp.left,
- (FX_INT32)rcTemp.bottom,
- (FX_INT32)rcTemp.right,
- (FX_INT32)rcTemp.top);
-
- pDevice->SetClip_Rect(&rcClip);
-
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
- {
- CPDF_Rect rcChild = pChild->ChildToParent(pChild->GetWindowRect());
- if (!(rcChild.top < rcClient.bottom || rcChild.bottom > rcClient.top))
- {
- CPDF_Matrix mt = pChild->GetChildMatrix();
- if (mt.IsIdentity())
- {
- pChild->DrawAppearance(pDevice,pUser2Device);
- }
- else
- {
- mt.Concat(*pUser2Device);
- pChild->DrawAppearance(pDevice,&mt);
- }
- }
- }
- }
-
- pDevice->RestoreState();
-}
-
-FX_INT32 CPWL_ListCtrl::GetItemIndex(CPWL_Wnd* pItem)
-{
- for (FX_INT32 i=0, sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (pItem == m_aChildren.GetAt(i))
- return i;
- }
-
- return -1;
-}
-
-CPDF_Point CPWL_ListCtrl::InToOut(const CPDF_Point& point) const
-{
- CPDF_Rect rcClient = GetClientRect();
-
- return CPDF_Point(point.x + rcClient.left - m_ptScroll.x,
- point.y + rcClient.top - m_ptScroll.y);
-}
-
-CPDF_Point CPWL_ListCtrl::OutToIn(const CPDF_Point& point) const
-{
- CPDF_Rect rcClient = GetClientRect();
-
- return CPDF_Point(point.x - rcClient.left + m_ptScroll.x,
- point.y - rcClient.top + m_ptScroll.y);
-}
-
-CPDF_Rect CPWL_ListCtrl::InToOut(const CPDF_Rect& rect) const
-{
- CPDF_Rect rcClient = GetClientRect();
-
- return CPDF_Rect(rect.left + rcClient.left - m_ptScroll.x,
- rect.bottom + rcClient.top - m_ptScroll.y,
- rect.right + rcClient.left - m_ptScroll.x,
- rect.top + rcClient.top - m_ptScroll.y);
-}
-
-CPDF_Rect CPWL_ListCtrl::OutToIn(const CPDF_Rect& rect) const
-{
- CPDF_Rect rcClient = GetClientRect();
-
- return CPDF_Rect(rect.left - rcClient.left + m_ptScroll.x,
- rect.bottom - rcClient.top + m_ptScroll.y,
- rect.right - rcClient.left + m_ptScroll.x,
- rect.top - rcClient.top + m_ptScroll.y);
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_ListCtrl.h"
+
+/* ---------------------------- CPWL_ListCtrl ---------------------------- */
+
+CPWL_ListCtrl::CPWL_ListCtrl() :
+ m_rcContent(0,0,0,0),
+ m_ptScroll(0,0),
+ m_fItemSpace(0.0f),
+ m_fTopSpace(0.0f),
+ m_fBottomSpace(0.0f)
+{
+}
+
+CPWL_ListCtrl::~CPWL_ListCtrl()
+{
+}
+
+void CPWL_ListCtrl::SetScrollPos(const CPDF_Point& point)
+{
+ m_ptScroll = point;
+
+ if (m_ptScroll.x < m_rcContent.left)
+ m_ptScroll.x = m_rcContent.left;
+
+ if (m_ptScroll.x > m_rcContent.right)
+ m_ptScroll.x = m_rcContent.right;
+
+ if (m_ptScroll.y > m_rcContent.top)
+ m_ptScroll.y = m_rcContent.top;
+
+ if (m_ptScroll.y < m_rcContent.bottom)
+ m_ptScroll.y = m_rcContent.bottom;
+}
+
+CPDF_Point CPWL_ListCtrl::GetScrollPos() const
+{
+ return m_ptScroll;
+}
+
+CPDF_Rect CPWL_ListCtrl::GetScrollArea() const
+{
+ return m_rcContent;
+}
+
+void CPWL_ListCtrl::ResetFace()
+{
+ ResetAll(FALSE, 0);
+}
+
+void CPWL_ListCtrl::ResetContent(FX_INT32 nStart)
+{
+ if (nStart < 0)
+ nStart = 0;
+ if (nStart >= 0 && nStart < m_aChildren.GetSize())
+ ResetAll(TRUE, nStart);
+}
+
+FX_FLOAT CPWL_ListCtrl::GetContentsHeight(FX_FLOAT fLimitWidth)
+{
+ FX_FLOAT fRet = m_fTopSpace;
+
+ FX_FLOAT fBorderWidth = (FX_FLOAT)this->GetBorderWidth();
+
+ if (fLimitWidth > fBorderWidth* 2)
+ {
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ FX_FLOAT fLeft = pChild->GetItemLeftMargin();
+ FX_FLOAT fRight = pChild->GetItemRightMargin();
+
+ fRet += pChild->GetItemHeight(fLimitWidth - fBorderWidth* 2 - fLeft - fRight);
+ fRet += m_fItemSpace;
+ }
+ }
+
+ fRet -= m_fItemSpace;
+ }
+
+ fRet += m_fBottomSpace;
+
+ return fRet;
+}
+
+void CPWL_ListCtrl::ResetAll(FX_BOOL bMove, FX_INT32 nStart)
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ FX_FLOAT fWidth = rcClient.Width();
+
+ FX_FLOAT fy = 0.0f - m_fTopSpace;
+
+ if (nStart-1 >= 0 && nStart-1 < m_aChildren.GetSize())
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(nStart-1))
+ fy = pChild->GetWindowRect().bottom - m_fItemSpace;
+
+ for (FX_INT32 i=nStart,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ FX_FLOAT fLeft = pChild->GetItemLeftMargin();
+ FX_FLOAT fRight = pChild->GetItemRightMargin();
+
+ pChild->SetChildMatrix(
+ CPDF_Matrix(1,0,0,1,
+ rcClient.left - m_ptScroll.x,
+ rcClient.top - m_ptScroll.y)
+ );
+
+ if (bMove)
+ {
+ FX_FLOAT fItemHeight = pChild->GetItemHeight(fWidth - fLeft - fRight);
+ pChild->Move(CPDF_Rect(fLeft, fy-fItemHeight, fWidth - fRight, fy), TRUE, FALSE);
+ fy -= fItemHeight;
+ fy -= m_fItemSpace;
+ }
+ }
+ }
+
+ fy += m_fItemSpace;
+
+ fy -= m_fBottomSpace;
+
+ if (bMove)
+ {
+ m_rcContent.left = 0;
+ m_rcContent.top = 0;
+ m_rcContent.right = fWidth;
+ m_rcContent.bottom = fy;
+ }
+}
+
+void CPWL_ListCtrl::SetItemSpace(FX_FLOAT fSpace)
+{
+ m_fItemSpace = fSpace;
+}
+
+void CPWL_ListCtrl::SetTopSpace(FX_FLOAT fSpace)
+{
+ m_fTopSpace = fSpace;
+}
+
+void CPWL_ListCtrl::SetBottomSpace(FX_FLOAT fSpace)
+{
+ m_fBottomSpace = fSpace;
+}
+
+void CPWL_ListCtrl::RePosChildWnd()
+{
+ ResetFace();
+}
+
+void CPWL_ListCtrl::DrawChildAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ pDevice->SaveState();
+ CPDF_Rect rcClient = GetClientRect();
+ CPDF_Rect rcTemp = rcClient;
+ pUser2Device->TransformRect(rcTemp);
+ FX_RECT rcClip((FX_INT32)rcTemp.left,
+ (FX_INT32)rcTemp.bottom,
+ (FX_INT32)rcTemp.right,
+ (FX_INT32)rcTemp.top);
+
+ pDevice->SetClip_Rect(&rcClip);
+
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
+ {
+ CPDF_Rect rcChild = pChild->ChildToParent(pChild->GetWindowRect());
+ if (!(rcChild.top < rcClient.bottom || rcChild.bottom > rcClient.top))
+ {
+ CPDF_Matrix mt = pChild->GetChildMatrix();
+ if (mt.IsIdentity())
+ {
+ pChild->DrawAppearance(pDevice,pUser2Device);
+ }
+ else
+ {
+ mt.Concat(*pUser2Device);
+ pChild->DrawAppearance(pDevice,&mt);
+ }
+ }
+ }
+ }
+
+ pDevice->RestoreState();
+}
+
+FX_INT32 CPWL_ListCtrl::GetItemIndex(CPWL_Wnd* pItem)
+{
+ for (FX_INT32 i=0, sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (pItem == m_aChildren.GetAt(i))
+ return i;
+ }
+
+ return -1;
+}
+
+CPDF_Point CPWL_ListCtrl::InToOut(const CPDF_Point& point) const
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ return CPDF_Point(point.x + rcClient.left - m_ptScroll.x,
+ point.y + rcClient.top - m_ptScroll.y);
+}
+
+CPDF_Point CPWL_ListCtrl::OutToIn(const CPDF_Point& point) const
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ return CPDF_Point(point.x - rcClient.left + m_ptScroll.x,
+ point.y - rcClient.top + m_ptScroll.y);
+}
+
+CPDF_Rect CPWL_ListCtrl::InToOut(const CPDF_Rect& rect) const
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ return CPDF_Rect(rect.left + rcClient.left - m_ptScroll.x,
+ rect.bottom + rcClient.top - m_ptScroll.y,
+ rect.right + rcClient.left - m_ptScroll.x,
+ rect.top + rcClient.top - m_ptScroll.y);
+}
+
+CPDF_Rect CPWL_ListCtrl::OutToIn(const CPDF_Rect& rect) const
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ return CPDF_Rect(rect.left - rcClient.left + m_ptScroll.x,
+ rect.bottom - rcClient.top + m_ptScroll.y,
+ rect.right - rcClient.left + m_ptScroll.x,
+ rect.top - rcClient.top + m_ptScroll.y);
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_Note.cpp b/fpdfsdk/src/pdfwindow/PWL_Note.cpp
index 3c6d8661c6..5929a357c9 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Note.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Note.cpp
@@ -1,1779 +1,1779 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_Button.h"
-#include "../../include/pdfwindow/PWL_EditCtrl.h"
-#include "../../include/pdfwindow/PWL_Edit.h"
-#include "../../include/pdfwindow/PWL_ListCtrl.h"
-#include "../../include/pdfwindow/PWL_ScrollBar.h"
-#include "../../include/pdfwindow/PWL_Note.h"
-#include "../../include/pdfwindow/PWL_Label.h"
-#include "../../include/pdfwindow/PWL_Edit.h"
-#include "../../include/pdfwindow/PWL_ScrollBar.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-#include "../../include/pdfwindow/PWL_Caret.h"
-
-#define POPUP_ITEM_HEAD_BOTTOM 3.0f
-#define POPUP_ITEM_BOTTOMWIDTH 1.0f
-#define POPUP_ITEM_SIDEMARGIN 3.0f
-#define POPUP_ITEM_SPACE 4.0f
-#define POPUP_ITEM_TEXT_INDENT 2.0f
-#define POPUP_ITEM_BORDERCOLOR CPWL_Color(COLORTYPE_RGB, 80/255.0f, 80/255.0f, 80/255.0f)
-
-#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
-#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
-
-
-/* ------------------------------- CPWL_Note_Options ------------------------------- */
-
-CPWL_Note_Options::CPWL_Note_Options() : m_pText(NULL)
-{
-}
-
-CPWL_Note_Options::~CPWL_Note_Options()
-{
-}
-
-void CPWL_Note_Options::SetTextColor(const CPWL_Color & color)
-{
- CPWL_Wnd::SetTextColor(color);
-
- if (m_pText)
- m_pText->SetTextColor(color);
-}
-
-void CPWL_Note_Options::RePosChildWnd()
-{
- if (this->IsValid())
- {
- ASSERT(m_pText != NULL);
-
- CPDF_Rect rcClient = GetClientRect();
-
- if (rcClient.Width() > 15.0f)
- {
- rcClient.right -= 15.0f;
- m_pText->Move(rcClient, TRUE, FALSE);
- m_pText->SetVisible(TRUE);
- }
- else
- {
- m_pText->Move(CPDF_Rect(0,0,0,0), TRUE, FALSE);
- m_pText->SetVisible(FALSE);
- }
- }
-}
-
-void CPWL_Note_Options::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- m_pText = new CPWL_Label;
- PWL_CREATEPARAM tcp = cp;
- tcp.pParentWnd = this;
- tcp.dwFlags = PWS_CHILD | PWS_VISIBLE;
- m_pText->Create(tcp);
-}
-
-void CPWL_Note_Options::SetText(const CFX_WideString& sText)
-{
- m_pText->SetText(sText);
-}
-
-void CPWL_Note_Options::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
-
- CPDF_Rect rcClient = GetClientRect();
- rcClient.left = rcClient.right - 15.0f;
-
- CPDF_Point ptCenter = CPDF_Point((rcClient.left + rcClient.right) * 0.5f, (rcClient.top + rcClient.bottom) * 0.5f);
-
- CPDF_Point pt1(ptCenter.x - 2.0f, ptCenter.y + 2.0f * 0.5f);
- CPDF_Point pt2(ptCenter.x + 2.0f, ptCenter.y + 2.0f * 0.5f);
- CPDF_Point pt3(ptCenter.x, ptCenter.y - 3.0f * 0.5f);
-
- CFX_PathData path;
-
- path.SetPointCount(4);
- path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
- path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
- path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
- path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
-
- pDevice->DrawPath(&path, pUser2Device, NULL,
- CPWL_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()),
- 0, FXFILL_ALTERNATE);
-}
-
-CPDF_Rect CPWL_Note_Options::GetContentRect() const
-{
- ASSERT(m_pText != NULL);
-
- CPDF_Rect rcText = m_pText->GetContentRect();
- rcText.right += 15.0f;
- return rcText;
-}
-
-/* ------------------------------- CPWL_Note_Edit ------------------------------ */
-
-CPWL_Note_Edit::CPWL_Note_Edit() : m_bEnableNotify(TRUE),
- m_fOldItemHeight(0.0f),
- m_bSizeChanged(FALSE),
- m_fOldMin(0.0f),
- m_fOldMax(0.0f)
-{
-}
-
-CPWL_Note_Edit::~CPWL_Note_Edit()
-{
-}
-
-void CPWL_Note_Edit::RePosChildWnd()
-{
- m_bEnableNotify = FALSE;
- CPWL_Edit::RePosChildWnd();
- m_bEnableNotify = TRUE;
-
- m_fOldItemHeight = this->GetContentRect().Height();
-}
-
-void CPWL_Note_Edit::SetText(FX_LPCWSTR csText)
-{
- m_bEnableNotify = FALSE;
- CPWL_Edit::SetText(csText);
- m_bEnableNotify = TRUE;
- m_fOldItemHeight = this->GetContentRect().Height();
-}
-
-void CPWL_Note_Edit::OnSetFocus()
-{
- m_bEnableNotify = FALSE;
- CPWL_Edit::OnSetFocus();
- m_bEnableNotify = TRUE;
-
- this->EnableSpellCheck(TRUE);
-}
-
-void CPWL_Note_Edit::OnKillFocus()
-{
- this->EnableSpellCheck(FALSE);
-
- if (CPWL_Wnd* pParent = this->GetParentWindow())
- {
- if (CPWL_Wnd* pGrand = pParent->GetParentWindow())
- {
- ASSERT(pGrand->GetClassName() == "CPWL_NoteItem");
-
- CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pGrand;
-
- pNoteItem->OnContentsValidate();
- }
- }
-
- CPWL_Edit::OnKillFocus();
-}
-
-void CPWL_Note_Edit::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- if (m_bEnableNotify)
- {
- if (wParam == SBT_VSCROLL)
- {
- switch (msg)
- {
- case PNM_SETSCROLLINFO:
- if (PWL_SCROLL_INFO* pInfo = (PWL_SCROLL_INFO*)lParam)
- {
- if (!IsFloatEqual(pInfo->fContentMax, m_fOldMax) ||
- !IsFloatEqual(pInfo->fContentMin, m_fOldMin))
- {
- m_bSizeChanged = TRUE;
- if (CPWL_Wnd * pParent = this->GetParentWindow())
- {
- pParent->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
- }
-
- m_fOldMax = pInfo->fContentMax;
- m_fOldMin = pInfo->fContentMin;
- return;
- }
- }
- }
- }
- }
-
- CPWL_Edit::OnNotify(pWnd, msg, wParam, lParam);
-
- if (m_bEnableNotify)
- {
- switch (msg)
- {
- case PNM_SETCARETINFO:
- if (PWL_CARET_INFO * pInfo = (PWL_CARET_INFO*)wParam)
- {
- PWL_CARET_INFO newInfo = *pInfo;
- newInfo.bVisible = TRUE;
- newInfo.ptHead = this->ChildToParent(pInfo->ptHead);
- newInfo.ptFoot = this->ChildToParent(pInfo->ptFoot);
-
- if (CPWL_Wnd * pParent = this->GetParentWindow())
- {
- pParent->OnNotify(this, PNM_SETCARETINFO, (FX_INTPTR)&newInfo, 0);
- }
- }
- break;
- }
- }
-}
-
-FX_FLOAT CPWL_Note_Edit::GetItemHeight(FX_FLOAT fLimitWidth)
-{
- if (fLimitWidth > 0)
- {
- if (!m_bSizeChanged)
- return m_fOldItemHeight;
-
- m_bSizeChanged = FALSE;
-
- this->EnableNotify(FALSE);
- this->EnableRefresh(FALSE);
- m_pEdit->EnableNotify(FALSE);
-
- //CPDF_Rect rcOld = this->GetWindowRect();
-
- this->Move(CPDF_Rect(0,0,fLimitWidth,0), TRUE, FALSE);
- FX_FLOAT fRet = this->GetContentRect().Height();
-
- //this->Move(rcOld, TRUE, FALSE);
-
- m_pEdit->EnableNotify(TRUE);
- this->EnableNotify(TRUE);
- this->EnableRefresh(TRUE);
-
- return fRet;
- }
-
- return 0;
-}
-
-FX_FLOAT CPWL_Note_Edit::GetItemLeftMargin()
-{
- return POPUP_ITEM_TEXT_INDENT;
-}
-
-FX_FLOAT CPWL_Note_Edit::GetItemRightMargin()
-{
- return POPUP_ITEM_TEXT_INDENT;
-}
-
-/* -------------------------------- CPWL_Note_LBBox --------------------------------*/
-
-CPWL_Note_LBBox::CPWL_Note_LBBox()
-{
-}
-
-CPWL_Note_LBBox::~CPWL_Note_LBBox()
-{
-}
-
-void CPWL_Note_LBBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPDF_Rect rcClient = this->GetClientRect();
-
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = 1.0f;
-
- CFX_PathData pathCross;
-
- pathCross.SetPointCount(4);
- pathCross.SetPoint(0, rcClient.left, rcClient.top, FXPT_MOVETO);
- pathCross.SetPoint(1, rcClient.right, rcClient.bottom, FXPT_LINETO);
- pathCross.SetPoint(2, rcClient.left, rcClient.bottom + rcClient.Height() * 0.5f, FXPT_MOVETO);
- pathCross.SetPoint(3, rcClient.left + rcClient.Width() * 0.5f, rcClient.bottom, FXPT_LINETO);
-
- pDevice->DrawPath(&pathCross, pUser2Device, &gsd,
- 0, CPWL_Utils::PWLColorToFXColor(GetTextColor(),this->GetTransparency()), FXFILL_ALTERNATE);
-}
-
-/* -------------------------------- CPWL_Note_RBBox --------------------------------*/
-
-CPWL_Note_RBBox::CPWL_Note_RBBox()
-{
-}
-
-CPWL_Note_RBBox::~CPWL_Note_RBBox()
-{
-}
-
-void CPWL_Note_RBBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPDF_Rect rcClient = this->GetClientRect();
-
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = 1.0f;
-
- CFX_PathData pathCross;
-
- pathCross.SetPointCount(4);
- pathCross.SetPoint(0, rcClient.right, rcClient.top, FXPT_MOVETO);
- pathCross.SetPoint(1, rcClient.left, rcClient.bottom, FXPT_LINETO);
- pathCross.SetPoint(2, rcClient.right, rcClient.bottom + rcClient.Height() * 0.5f, FXPT_MOVETO);
- pathCross.SetPoint(3, rcClient.left + rcClient.Width() * 0.5f, rcClient.bottom, FXPT_LINETO);
-
- pDevice->DrawPath(&pathCross, pUser2Device, &gsd,
- 0, CPWL_Utils::PWLColorToFXColor(GetTextColor(),this->GetTransparency()), FXFILL_ALTERNATE);
-}
-
-/* --------------------------------- CPWL_Note_Icon ---------------------------------- */
-
-CPWL_Note_Icon::CPWL_Note_Icon() : m_nType(0)
-{
-}
-
-CPWL_Note_Icon::~CPWL_Note_Icon()
-{
-}
-
-void CPWL_Note_Icon::SetIconType(FX_INT32 nType)
-{
- m_nType = nType;
-}
-
-void CPWL_Note_Icon::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, m_nType, GetClientRect(),
- this->GetBackgroundColor(), PWL_DEFAULT_BLACKCOLOR, this->GetTransparency());
-}
-
-/* --------------------------------- CPWL_Note_CloseBox ---------------------------------- */
-
-CPWL_Note_CloseBox::CPWL_Note_CloseBox() : m_bMouseDown(FALSE)
-{
-}
-
-CPWL_Note_CloseBox::~CPWL_Note_CloseBox()
-{
-}
-
-void CPWL_Note_CloseBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPWL_Button::DrawThisAppearance(pDevice, pUser2Device);
-
- CPDF_Rect rcClient = this->GetClientRect();
- rcClient = CPWL_Utils::DeflateRect(rcClient, 2.0f);
-
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = 1.0f;
-
- CFX_PathData pathCross;
-
- if (m_bMouseDown)
- {
- rcClient.left += 0.5f;
- rcClient.right += 0.5f;
- rcClient.top -= 0.5f;
- rcClient.bottom -= 0.5f;
- }
-
- pathCross.SetPointCount(4);
- pathCross.SetPoint(0, rcClient.left, rcClient.bottom, FXPT_MOVETO);
- pathCross.SetPoint(1, rcClient.right, rcClient.top, FXPT_LINETO);
- pathCross.SetPoint(2, rcClient.left, rcClient.top, FXPT_MOVETO);
- pathCross.SetPoint(3, rcClient.right, rcClient.bottom, FXPT_LINETO);
-
- pDevice->DrawPath(&pathCross, pUser2Device, &gsd,
- 0, CPWL_Utils::PWLColorToFXColor(GetTextColor(),this->GetTransparency()), FXFILL_ALTERNATE);
-}
-
-FX_BOOL CPWL_Note_CloseBox::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
-{
- SetBorderStyle(PBS_INSET);
- InvalidateRect(NULL);
-
- m_bMouseDown = TRUE;
-
- return CPWL_Button::OnLButtonDown(point,nFlag);
-}
-
-FX_BOOL CPWL_Note_CloseBox::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- m_bMouseDown = FALSE;
-
- SetBorderStyle(PBS_BEVELED);
- InvalidateRect(NULL);
-
- return CPWL_Button::OnLButtonUp(point,nFlag);
-}
-
-/* ------------------------------ CPWL_Note_Contents ------------------------------- */
-
-CPWL_Note_Contents::CPWL_Note_Contents() : m_pEdit(NULL)
-{
-}
-
-CPWL_Note_Contents::~CPWL_Note_Contents()
-{
-}
-
-CFX_ByteString CPWL_Note_Contents::GetClassName() const
-{
- return "CPWL_Note_Contents";
-}
-
-void CPWL_Note_Contents::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- m_pEdit = new CPWL_Note_Edit;
- PWL_CREATEPARAM ecp = cp;
- ecp.pParentWnd = this;
- ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PES_MULTILINE | PES_AUTORETURN | PES_TEXTOVERFLOW | PES_UNDO | PES_SPELLCHECK;
-
- m_pEdit->EnableNotify(FALSE);
- m_pEdit->Create(ecp);
- m_pEdit->EnableNotify(TRUE);
-}
-
-void CPWL_Note_Contents::SetText(const CFX_WideString& sText)
-{
- if (m_pEdit)
- {
- m_pEdit->EnableNotify(FALSE);
- m_pEdit->SetText(sText);
- m_pEdit->EnableNotify(TRUE);
- OnNotify(m_pEdit, PNM_NOTEEDITCHANGED, 0, 0);
- }
-}
-
-CFX_WideString CPWL_Note_Contents::GetText() const
-{
- if (m_pEdit)
- return m_pEdit->GetText();
-
- return L"";
-}
-
-CPWL_NoteItem* CPWL_Note_Contents::CreateSubItem()
-{
- CPWL_NoteItem* pNoteItem = new CPWL_NoteItem;
- PWL_CREATEPARAM icp = this->GetCreationParam();
- icp.pParentWnd = this;
- icp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_BACKGROUND;
- pNoteItem->Create(icp);
-
- pNoteItem->OnCreateNoteItem();
-
- pNoteItem->ResetSubjectName(m_aChildren.GetSize() - 1);
-
- FX_SYSTEMTIME st;
- if (IFX_SystemHandler* pSH = this->GetSystemHandler())
- st = pSH->GetLocalTime();
- pNoteItem->SetDateTime(st);
-
- pNoteItem->SetContents(L"");
-
- this->OnNotify(pNoteItem, PNM_NOTEEDITCHANGED, 0, 0);
-
- return pNoteItem;
-}
-
-FX_INT32 CPWL_Note_Contents::CountSubItems() const
-{
- return m_aChildren.GetSize() - 1;
-}
-
-IPWL_NoteItem* CPWL_Note_Contents::GetSubItems(FX_INT32 index) const
-{
- FX_INT32 nIndex = index + 1;
-
- if (nIndex > 0 && nIndex < m_aChildren.GetSize())
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(nIndex))
- {
- ASSERT(pChild->GetClassName() == "CPWL_NoteItem");
- CPWL_NoteItem* pItem = (CPWL_NoteItem*)pChild;
- return pItem;
- }
- return NULL;
-}
-
-void CPWL_Note_Contents::DeleteSubItem(IPWL_NoteItem* pNoteItem)
-{
- FX_INT32 nIndex = this->GetItemIndex((CPWL_NoteItem*)pNoteItem);
-
- if (nIndex > 0)
- {
- if (CPWL_NoteItem* pPWLNoteItem = (CPWL_NoteItem*)pNoteItem)
- {
- pPWLNoteItem->KillFocus();
- pPWLNoteItem->Destroy();
- delete pPWLNoteItem;
- }
-
- for (FX_INT32 i=nIndex,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- ASSERT(pChild->GetClassName() == "CPWL_NoteItem");
- CPWL_NoteItem* pItem = (CPWL_NoteItem*)pChild;
- pItem->ResetSubjectName(i);
- }
- }
-
- this->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
- }
-}
-
-IPWL_NoteItem* CPWL_Note_Contents::GetHitNoteItem(const CPDF_Point& point)
-{
- CPDF_Point pt = this->ParentToChild(point);
-
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- if (pChild->GetClassName() == "CPWL_NoteItem")
- {
- CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pChild;
- if (IPWL_NoteItem* pRet = pNoteItem->GetHitNoteItem(pt))
- return pRet;
- }
- }
- }
- return NULL;
-}
-
-void CPWL_Note_Contents::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- switch (msg)
- {
- case PNM_NOTEEDITCHANGED:
- {
- FX_INT32 nIndex = this->GetItemIndex(pWnd);
- if (nIndex < 0) nIndex = 0;
-
- m_pEdit->EnableNotify(FALSE);
- this->ResetContent(nIndex);
- m_pEdit->EnableNotify(TRUE);
-
- for (FX_INT32 i=nIndex+1, sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- pChild->OnNotify(this, PNM_NOTERESET, 0, 0);
- }
-
- if (CPWL_Wnd * pParent = this->GetParentWindow())
- {
- pParent->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
- }
- }
- return;
- case PNM_SCROLLWINDOW:
- this->SetScrollPos(CPDF_Point(0.0f, *(FX_FLOAT*)lParam));
- this->ResetFace();
- InvalidateRect(NULL);
- return;
- case PNM_SETCARETINFO:
- if (PWL_CARET_INFO * pInfo = (PWL_CARET_INFO*)wParam)
- {
- PWL_CARET_INFO newInfo = *pInfo;
- newInfo.bVisible = TRUE;
- newInfo.ptHead = this->ChildToParent(pInfo->ptHead);
- newInfo.ptFoot = this->ChildToParent(pInfo->ptFoot);
-
- if (CPWL_Wnd * pParent = this->GetParentWindow())
- {
- pParent->OnNotify(this, PNM_SETCARETINFO, (FX_INTPTR)&newInfo, 0);
- }
- }
- return;
- case PNM_NOTERESET:
- {
- m_pEdit->EnableNotify(FALSE);
- this->ResetContent(0);
- m_pEdit->EnableNotify(TRUE);
-
- for (FX_INT32 i=1, sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- pChild->OnNotify(this, PNM_NOTERESET, 0, 0);
- }
-
- m_pEdit->EnableNotify(FALSE);
- this->ResetContent(0);
- m_pEdit->EnableNotify(TRUE);
- }
- return;
- }
-
- CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
-}
-
-FX_BOOL CPWL_Note_Contents::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
-{
- if (CPWL_Wnd::OnLButtonDown(point,nFlag)) return TRUE;
-
- if (!m_pEdit->IsFocused())
- {
- m_pEdit->SetFocus();
- }
-
- return TRUE;
-}
-
-void CPWL_Note_Contents::SetEditFocus(FX_BOOL bLast)
-{
- if (!m_pEdit->IsFocused())
- {
- m_pEdit->SetFocus();
- m_pEdit->SetCaret(bLast ? m_pEdit->GetTotalWords() : 0);
- }
-}
-
-CPWL_Edit* CPWL_Note_Contents::GetEdit() const
-{
- return m_pEdit;
-}
-
-void CPWL_Note_Contents::EnableModify(FX_BOOL bEnabled)
-{
- if (!bEnabled)
- m_pEdit->AddFlag(PWS_READONLY);
- else
- m_pEdit->RemoveFlag(PWS_READONLY);
-
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- if (pChild->GetClassName() == "CPWL_NoteItem")
- {
- CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pChild;
- pNoteItem->EnableModify(bEnabled);
- }
- }
- }
-}
-
-void CPWL_Note_Contents::EnableRead(FX_BOOL bEnabled)
-{
- if (!bEnabled)
- m_pEdit->AddFlag(PES_NOREAD);
- else
- m_pEdit->RemoveFlag(PES_NOREAD);
-
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- if (pChild->GetClassName() == "CPWL_NoteItem")
- {
- CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pChild;
- pNoteItem->EnableRead(bEnabled);
- }
- }
- }
-}
-
-/* ---------------------------------- CPWL_NoteItem ---------------------------------- */
-
-CPWL_NoteItem::CPWL_NoteItem() :
- m_pPrivateData(NULL),
- m_pSubject(NULL),
- m_pDateTime(NULL),
- m_pContents(NULL),
- m_sAuthor(L""),
- m_fOldItemHeight(0.0f),
- m_bSizeChanged(FALSE),
- m_bAllowModify(TRUE)
-{
-}
-
-CPWL_NoteItem::~CPWL_NoteItem()
-{
-}
-
-CFX_ByteString CPWL_NoteItem::GetClassName() const
-{
- return "CPWL_NoteItem";
-}
-
-void CPWL_NoteItem::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- CPWL_Color sTextColor;
-
- if (CPWL_Utils::IsBlackOrWhite(this->GetBackgroundColor()))
- sTextColor = PWL_DEFAULT_WHITECOLOR;
- else
- sTextColor = PWL_DEFAULT_BLACKCOLOR;
-
- m_pSubject = new CPWL_Label;
- PWL_CREATEPARAM scp = cp;
- scp.pParentWnd = this;
- scp.dwFlags = PWS_VISIBLE | PWS_CHILD | PES_LEFT | PES_TOP;
- scp.sTextColor = sTextColor;
- m_pSubject->Create(scp);
-
- m_pDateTime = new CPWL_Label;
- PWL_CREATEPARAM dcp = cp;
- dcp.pParentWnd = this;
- dcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PES_RIGHT | PES_TOP;
- dcp.sTextColor = sTextColor;
- m_pDateTime->Create(dcp);
-
- m_pContents = new CPWL_Note_Contents;
- PWL_CREATEPARAM ccp = cp;
- ccp.pParentWnd = this;
- //ccp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
- ccp.sBackgroundColor = CPWL_Color(COLORTYPE_RGB, 240/255.0f, 240/255.0f, 240/255.0f);
- ccp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BACKGROUND;
- m_pContents->Create(ccp);
- m_pContents->SetItemSpace(POPUP_ITEM_SPACE);
- m_pContents->SetTopSpace(POPUP_ITEM_SPACE);
- m_pContents->SetBottomSpace(POPUP_ITEM_SPACE);
-}
-
-void CPWL_NoteItem::RePosChildWnd()
-{
- if (this->IsValid())
- {
- ASSERT(m_pSubject != NULL);
- ASSERT(m_pDateTime != NULL);
- ASSERT(m_pContents != NULL);
-
- CPDF_Rect rcClient = GetClientRect();
-
- CPDF_Rect rcSubject = rcClient;
- rcSubject.left += POPUP_ITEM_TEXT_INDENT;
- rcSubject.top = rcClient.top;
- rcSubject.right = PWL_MIN(rcSubject.left + m_pSubject->GetContentRect().Width() + 1.0f, rcClient.right);
- rcSubject.bottom = rcSubject.top - m_pSubject->GetContentRect().Height();
- rcSubject.Normalize();
- m_pSubject->Move(rcSubject, TRUE, FALSE);
- m_pSubject->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcSubject));
-
- CPDF_Rect rcDate = rcClient;
- rcDate.right -= POPUP_ITEM_TEXT_INDENT;
- rcDate.left = PWL_MAX(rcDate.right - m_pDateTime->GetContentRect().Width() - 1.0f, rcSubject.right);
- rcDate.bottom = rcDate.top - m_pDateTime->GetContentRect().Height();
- rcDate.Normalize();
- m_pDateTime->Move(rcDate, TRUE, FALSE);
- m_pDateTime->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcDate));
-
- CPDF_Rect rcContents = rcClient;
- rcContents.left += 1.0f;
- rcContents.right -= 1.0f;
- rcContents.top = rcDate.bottom - POPUP_ITEM_HEAD_BOTTOM;
- rcContents.bottom += POPUP_ITEM_BOTTOMWIDTH;
- rcContents.Normalize();
- m_pContents->Move(rcContents, TRUE, FALSE);
- m_pContents->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcContents));
- }
-
- SetClipRect(CPWL_Utils::InflateRect(GetWindowRect(),1.0f));
-}
-
-void CPWL_NoteItem::SetPrivateData(void* pData)
-{
- m_pPrivateData = pData;
-}
-
-void CPWL_NoteItem::SetBkColor(const CPWL_Color& color)
-{
- CPWL_Color sBK = color;
- this->SetBackgroundColor(sBK);
-
- CPWL_Color sTextColor;
-
- if (CPWL_Utils::IsBlackOrWhite(sBK))
- sTextColor = PWL_DEFAULT_WHITECOLOR;
- else
- sTextColor = PWL_DEFAULT_BLACKCOLOR;
-
- this->SetTextColor(sTextColor);
- if (m_pSubject)
- m_pSubject->SetTextColor(sTextColor);
- if (m_pDateTime)
- m_pDateTime->SetTextColor(sTextColor);
-
- this->InvalidateRect(NULL);
-
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- pNotify->OnSetBkColor(this);
- }
-}
-
-void CPWL_NoteItem::SetSubjectName(const CFX_WideString& sName)
-{
- if (m_pSubject)
- {
- m_pSubject->SetText(sName);
- }
-
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- pNotify->OnSetSubjectName(this);
- }
-}
-
-void CPWL_NoteItem::SetAuthorName(const CFX_WideString& sName)
-{
- m_sAuthor = sName;
- ResetSubjectName(-1);
-
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- pNotify->OnSetAuthorName(this);
- }
-}
-
-void CPWL_NoteItem::ResetSubjectName(FX_INT32 nItemIndex)
-{
- if (nItemIndex < 0)
- {
- if (CPWL_Wnd* pParent = this->GetParentWindow())
- {
- ASSERT(pParent->GetClassName() == "CPWL_Note_Contents");
-
- CPWL_Note_Contents* pContents = (CPWL_Note_Contents*)pParent;
- nItemIndex = pContents->GetItemIndex(this);
- }
- }
-
- const CPWL_Note* pNote = GetNote();
- ASSERT(pNote != NULL);
-
- CFX_WideString sSubject;
- sSubject.Format(pNote->GetReplyString(), nItemIndex);
-
- if (!m_sAuthor.IsEmpty())
- {
-
- sSubject += L" - ";
- sSubject += m_sAuthor;
- }
- this->SetSubjectName(sSubject);
- this->RePosChildWnd();
-}
-
-void CPWL_NoteItem::SetDateTime(FX_SYSTEMTIME time)
-{
- m_dtNote = time;
-
- CFX_WideString swTime;
- swTime.Format((FX_LPCWSTR)L"%04d-%02d-%02d %02d:%02d:%02d", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond);
- if (m_pDateTime)
- {
- m_pDateTime->SetText(swTime);
- }
-
- this->RePosChildWnd();
-
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- pNotify->OnSetDateTime(this);
- }
-}
-
-void CPWL_NoteItem::SetContents(const CFX_WideString& sContents)
-{
- if (m_pContents)
- {
- m_pContents->SetText(sContents);
- }
-
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- pNotify->OnSetContents(this);
- }
-}
-
-CPWL_NoteItem* CPWL_NoteItem::GetParentNoteItem() const
-{
- if (CPWL_Wnd* pParent = this->GetParentWindow())
- {
- if (CPWL_Wnd* pGrand = pParent->GetParentWindow())
- {
- ASSERT(pGrand->GetClassName() == "CPWL_NoteItem");
- return (CPWL_NoteItem*)pGrand;
- }
- }
-
- return NULL;
-}
-
-IPWL_NoteItem* CPWL_NoteItem::GetParentItem() const
-{
- return GetParentNoteItem();
-}
-
-CPWL_Edit* CPWL_NoteItem::GetEdit() const
-{
- if (m_pContents)
- return m_pContents->GetEdit();
- return NULL;
-}
-
-void* CPWL_NoteItem::GetPrivateData() const
-{
- return m_pPrivateData;
-}
-
-CFX_WideString CPWL_NoteItem::GetAuthorName() const
-{
- return m_sAuthor;
-}
-
-CPWL_Color CPWL_NoteItem::GetBkColor() const
-{
- return this->GetBackgroundColor();
-}
-
-CFX_WideString CPWL_NoteItem::GetContents() const
-{
- if (m_pContents)
- return m_pContents->GetText();
-
- return L"";
-}
-
-FX_SYSTEMTIME CPWL_NoteItem::GetDateTime() const
-{
- return m_dtNote;
-}
-
-CFX_WideString CPWL_NoteItem::GetSubjectName() const
-{
- if (m_pSubject)
- return m_pSubject->GetText();
-
- return L"";
-}
-
-CPWL_NoteItem* CPWL_NoteItem::CreateNoteItem()
-{
- if (m_pContents)
- return m_pContents->CreateSubItem();
-
- return NULL;
-}
-
-IPWL_NoteItem* CPWL_NoteItem::CreateSubItem()
-{
- return CreateNoteItem();
-}
-
-FX_INT32 CPWL_NoteItem::CountSubItems() const
-{
- if (m_pContents)
- return m_pContents->CountSubItems();
-
- return 0;
-}
-
-IPWL_NoteItem* CPWL_NoteItem::GetSubItems(FX_INT32 index) const
-{
- if (m_pContents)
- return m_pContents->GetSubItems(index);
-
- return NULL;
-}
-
-void CPWL_NoteItem::DeleteSubItem(IPWL_NoteItem* pNoteItem)
-{
- this->KillFocus();
-
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- pNotify->OnItemDelete(pNoteItem);
- }
-
- if (m_pContents)
- m_pContents->DeleteSubItem(pNoteItem);
-}
-
-IPWL_NoteItem* CPWL_NoteItem::GetHitNoteItem(const CPDF_Point& point)
-{
- CPDF_Point pt = this->ParentToChild(point);
-
- if (this->WndHitTest(pt))
- {
- if (m_pContents)
- {
- if (IPWL_NoteItem* pNoteItem = m_pContents->GetHitNoteItem(pt))
- return pNoteItem;
- }
-
- return this;
- }
-
- return NULL;
-}
-
-IPWL_NoteItem* CPWL_NoteItem::GetFocusedNoteItem() const
-{
- if (const CPWL_Wnd* pWnd = this->GetFocused())
- {
- if (pWnd->GetClassName() == "CPWL_Edit")
- {
- if (CPWL_Wnd* pParent = pWnd->GetParentWindow())
- {
- ASSERT(pParent->GetClassName() == "CPWL_Note_Contents");
-
- if (CPWL_Wnd* pGrand = pParent->GetParentWindow())
- {
- ASSERT(pGrand->GetClassName() == "CPWL_NoteItem");
- return (CPWL_NoteItem*)pGrand;
- }
- }
- }
- }
-
- return NULL;
-}
-
-FX_FLOAT CPWL_NoteItem::GetItemHeight(FX_FLOAT fLimitWidth)
-{
- if (fLimitWidth > 0)
- {
- if (!m_bSizeChanged)
- return m_fOldItemHeight;
-
- m_bSizeChanged = FALSE;
-
- ASSERT(m_pSubject != NULL);
- ASSERT(m_pDateTime != NULL);
- ASSERT(m_pContents != NULL);
-
- FX_FLOAT fRet = m_pDateTime->GetContentRect().Height();
- FX_FLOAT fBorderWidth = (FX_FLOAT)this->GetBorderWidth();
- if (fLimitWidth > fBorderWidth * 2)
- fRet += m_pContents->GetContentsHeight(fLimitWidth - fBorderWidth * 2);
- fRet += POPUP_ITEM_HEAD_BOTTOM + POPUP_ITEM_BOTTOMWIDTH + fBorderWidth * 2;
-
- return m_fOldItemHeight = fRet;
- }
-
- return 0;
-}
-
-FX_FLOAT CPWL_NoteItem::GetItemLeftMargin()
-{
- return POPUP_ITEM_SIDEMARGIN;
-}
-
-FX_FLOAT CPWL_NoteItem::GetItemRightMargin()
-{
- return POPUP_ITEM_SIDEMARGIN;
-}
-
-FX_BOOL CPWL_NoteItem::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag)
-{
- if (!m_pContents->WndHitTest(m_pContents->ParentToChild(point)))
- {
- SetNoteFocus(FALSE);
- }
-
- CPWL_Wnd::OnLButtonDown(point,nFlag);
-
- return TRUE;
-}
-
-FX_BOOL CPWL_NoteItem::OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- if (!m_pContents->WndHitTest(m_pContents->ParentToChild(point)))
- {
- SetNoteFocus(FALSE);
- PopupNoteItemMenu(point);
-
- return TRUE;
- }
-
- return CPWL_Wnd::OnRButtonUp(point,nFlag);
-}
-
-void CPWL_NoteItem::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- switch (msg)
- {
- case PNM_NOTEEDITCHANGED:
- m_bSizeChanged = TRUE;
-
- if (CPWL_Wnd* pParent = this->GetParentWindow())
- {
- pParent->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
- }
- return;
- case PNM_SETCARETINFO:
- if (PWL_CARET_INFO * pInfo = (PWL_CARET_INFO*)wParam)
- {
- PWL_CARET_INFO newInfo = *pInfo;
- newInfo.bVisible = TRUE;
- newInfo.ptHead = this->ChildToParent(pInfo->ptHead);
- newInfo.ptFoot = this->ChildToParent(pInfo->ptFoot);
-
- if (CPWL_Wnd * pParent = this->GetParentWindow())
- {
- pParent->OnNotify(this, PNM_SETCARETINFO, (FX_INTPTR)&newInfo, 0);
- }
- }
- return;
- case PNM_NOTERESET:
- m_bSizeChanged = TRUE;
- m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
-
- return;
- }
-
- CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
-}
-
-void CPWL_NoteItem::PopupNoteItemMenu(const CPDF_Point& point)
-{
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- FX_INT32 x,y;
- PWLtoWnd(point, x, y);
- if (IFX_SystemHandler* pSH = GetSystemHandler())
- pSH->ClientToScreen(GetAttachedHWnd(), x, y);
- pNotify->OnPopupMenu(this, x, y);
- }
-}
-
-const CPWL_Note* CPWL_NoteItem::GetNote() const
-{
- if (const CPWL_Wnd* pRoot = this->GetRootWnd())
- {
- ASSERT(pRoot->GetClassName() == "CPWL_NoteItem");
- CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pRoot;
- if (pNoteItem->IsTopItem())
- {
- return (CPWL_Note*)pNoteItem;
- }
- }
-
- return NULL;
-}
-
-IPWL_NoteNotify* CPWL_NoteItem::GetNoteNotify() const
-{
- if (const CPWL_Note* pNote = GetNote())
- return pNote->GetNoteNotify();
-
- return NULL;
-}
-
-void CPWL_NoteItem::OnCreateNoteItem()
-{
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- pNotify->OnItemCreate(this);
- }
-}
-
-void CPWL_NoteItem::OnContentsValidate()
-{
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- pNotify->OnSetContents(this);
- }
-}
-
-void CPWL_NoteItem::SetNoteFocus(FX_BOOL bLast)
-{
- m_pContents->SetEditFocus(bLast);
-}
-
-void CPWL_NoteItem::EnableModify(FX_BOOL bEnabled)
-{
- m_pContents->EnableModify(bEnabled);
- m_bAllowModify = bEnabled;
-}
-
-void CPWL_NoteItem::EnableRead(FX_BOOL bEnabled)
-{
- m_pContents->EnableRead(bEnabled);
-}
-
-/* ---------------------------------- CPWL_Note ---------------------------------- */
-
-CPWL_Note::CPWL_Note(IPopup_Note* pPopupNote, IPWL_NoteNotify* pNoteNotify, IPWL_NoteHandler* pNoteHandler) :
- m_pAuthor(NULL),
- m_pIcon(NULL),
- m_pCloseBox(NULL),
- m_pContentsBar(NULL),
- m_pLBBox(NULL),
- m_pRBBox(NULL),
- m_pOptions(NULL),
- m_bResizing(FALSE),
- m_rcCaption(0,0,0,0),
- m_pNoteNotify(pNoteNotify),
- m_bEnalbleNotify(TRUE),
- m_pPopupNote(pPopupNote),
- m_pNoteHandler(pNoteHandler)
-{
-}
-
-CPWL_Note::~CPWL_Note()
-{
-}
-
-IPWL_NoteItem* CPWL_Note::Reply()
-{
- return CreateNoteItem();
-}
-
-void CPWL_Note::EnableNotify(FX_BOOL bEnabled)
-{
- m_bEnalbleNotify = bEnabled;
-}
-
-void CPWL_Note::RePosChildWnd()
-{
- RePosNoteChildren();
- m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
- ResetScrollBar();
- m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
- this->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
- //ͬ²½
- if (const CPWL_Wnd* pWnd = this->GetFocused())
- {
- if (pWnd->GetClassName() == "CPWL_Edit")
- {
- CPWL_Edit* pEdit = (CPWL_Edit*)pWnd;
- pEdit->SetCaret(pEdit->GetCaret());
- }
- }
- //CPDF_Point ptNew = m_pContents->GetScrollPos();
- //m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptNew.y);
-}
-
-FX_BOOL CPWL_Note::ResetScrollBar()
-{
- FX_BOOL bScrollChanged = FALSE;
-
- if (ScrollBarShouldVisible())
- {
- if (!m_pContentsBar->IsVisible())
- {
- m_pContentsBar->SetVisible(TRUE);
- if (m_pContentsBar->IsVisible())
- {
- m_pContentsBar->InvalidateRect(NULL);
- bScrollChanged = TRUE;
- }
- }
- }
- else
- {
- if (m_pContentsBar->IsVisible())
- {
- m_pContentsBar->SetVisible(FALSE);
- m_pContentsBar->InvalidateRect(NULL);
-
- bScrollChanged = TRUE;
- }
- }
-
- if (bScrollChanged)
- {
- CPDF_Rect rcNote = this->GetClientRect();
- CPDF_Rect rcContents = m_pContents->GetWindowRect();
- rcContents.right = rcNote.right - 3.0f;
- if (m_pContentsBar->IsVisible())
- rcContents.right -= PWL_SCROLLBAR_WIDTH;
- m_pContents->Move(rcContents, TRUE, TRUE);
- m_pContents->SetScrollPos(CPDF_Point(0.0f,0.0f));
- m_pContents->InvalidateRect(NULL);
- }
-
- return bScrollChanged;
-}
-
-FX_BOOL CPWL_Note::ScrollBarShouldVisible()
-{
- CPDF_Rect rcContentsFact = m_pContents->GetScrollArea();
- CPDF_Rect rcContentsClient = m_pContents->GetClientRect();
-
- return rcContentsFact.Height() > rcContentsClient.Height();
-}
-
-void CPWL_Note::SetOptionsText(const CFX_WideString& sText)
-{
- if (m_pOptions)
- m_pOptions->SetText(sText);
-
- RePosNoteChildren();
-}
-
-void CPWL_Note::RePosNoteChildren()
-{
- if (m_bResizing) return;
-
- m_bResizing = TRUE;
-
- if (this->IsValid())
- {
- ASSERT(m_pSubject != NULL);
- ASSERT(m_pDateTime != NULL);
- ASSERT(m_pContents != NULL);
- ASSERT(m_pAuthor != NULL);
- ASSERT(m_pCloseBox != NULL);
- ASSERT(m_pIcon != NULL);
- ASSERT(m_pLBBox != NULL);
- ASSERT(m_pRBBox != NULL);
- ASSERT(m_pContentsBar != NULL);
- ASSERT(m_pOptions != NULL);
-
- CPDF_Rect rcClient = GetClientRect();
-
- CPDF_Rect rcIcon = rcClient;
- rcIcon.top -= 2.0f;
- rcIcon.right = rcIcon.left + 14.0f;
- rcIcon.bottom = rcIcon.top - 14.0f;
- rcIcon.Normalize();
- m_pIcon->Move(rcIcon, TRUE, FALSE);
- m_pIcon->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcIcon));
-
- CPDF_Rect rcCloseBox = rcClient;
- rcCloseBox.right -= 1.0f;
- rcCloseBox.top -= 1.0f;
- rcCloseBox.left = rcCloseBox.right - 14.0f;
- rcCloseBox.bottom = rcCloseBox.top - 14.0f;
- rcCloseBox.Normalize();
- m_pCloseBox->Move(rcCloseBox, TRUE, FALSE);
- m_pCloseBox->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcCloseBox));
-
- CPDF_Rect rcDate = rcClient;
- rcDate.right = rcCloseBox.left - POPUP_ITEM_TEXT_INDENT;
- rcDate.left = PWL_MAX(rcDate.right - m_pDateTime->GetContentRect().Width() - 1.0f, rcIcon.right + 1.0f);
- rcDate.top = rcClient.top - 2.0f;
- rcDate.bottom = rcDate.top - m_pDateTime->GetContentRect().Height();
- rcDate.Normalize();
- m_pDateTime->Move(rcDate, TRUE, FALSE);
- m_pDateTime->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcDate));
-
- CPDF_Rect rcSubject = rcClient;
- rcSubject.top = rcClient.top - 2.0f;
- rcSubject.left = rcIcon.right + POPUP_ITEM_TEXT_INDENT;
- rcSubject.right = PWL_MIN(rcSubject.left + m_pSubject->GetContentRect().Width() + 1.0f, rcDate.left - 1.0f);
- rcSubject.bottom = rcSubject.top - m_pSubject->GetContentRect().Height();
- rcSubject.Normalize();
- m_pSubject->Move(rcSubject, TRUE, FALSE);
- m_pSubject->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcSubject));
-
- CPDF_Rect rcOptions = rcClient;
- rcOptions.left = PWL_MAX(rcOptions.right - m_pOptions->GetContentRect().Width(), rcIcon.right + 1.0f);
- rcOptions.top = rcSubject.bottom - 4.0f;
- rcOptions.bottom = rcOptions.top - m_pOptions->GetContentRect().Height();
- rcOptions.Normalize();
- m_pOptions->Move(rcOptions, TRUE, FALSE);
- m_pOptions->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcOptions));
-
- CPDF_Rect rcAuthor = rcClient;
- rcAuthor.top = rcSubject.bottom - 4.0f;
- rcAuthor.left = rcSubject.left;
- rcAuthor.right = PWL_MIN(rcSubject.left + m_pAuthor->GetContentRect().Width() + 1.0f, rcOptions.left - 1.0f);
- rcAuthor.bottom = rcAuthor.top - m_pAuthor->GetContentRect().Height();
- rcAuthor.Normalize();
- m_pAuthor->Move(rcAuthor, TRUE, FALSE);
- m_pAuthor->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcAuthor));
-
- CPDF_Rect rcLBBox = rcClient;
- rcLBBox.top = rcLBBox.bottom + 7.0f;
- rcLBBox.right = rcLBBox.left + 7.0f;
- rcLBBox.Normalize();
- m_pLBBox->Move(rcLBBox, TRUE, FALSE);
- m_pLBBox->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcLBBox));
-
- CPDF_Rect rcRBBox = rcClient;
- rcRBBox.top = rcRBBox.bottom + 7.0f;
- rcRBBox.left = rcRBBox.right - 7.0f;
- rcRBBox.Normalize();
- m_pRBBox->Move(rcRBBox, TRUE, FALSE);
- m_pRBBox->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcRBBox));
-
- CPDF_Rect rcContents = rcClient;
- rcContents.top = rcAuthor.bottom - POPUP_ITEM_HEAD_BOTTOM;
- rcContents.left += 3.0f;
- rcContents.right -= 3.0f;
- if (m_pContentsBar->IsVisible())
- rcContents.right -= PWL_SCROLLBAR_WIDTH;
- rcContents.bottom += 14.0f;
- rcContents.Normalize();
- m_pContents->Move(rcContents, FALSE, FALSE);
- m_pContents->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcContents));
-
- CPDF_Rect rcContentsBar = rcContents;
- rcContentsBar.right = rcClient.right - 3.0f;
- rcContentsBar.left = rcContentsBar.right - PWL_SCROLLBAR_WIDTH;
- rcContentsBar.Normalize();
- m_pContentsBar->Move(rcContentsBar, TRUE, FALSE);
-
- m_rcCaption = rcClient;
- m_rcCaption.bottom = rcContents.top;
- }
-
- m_bResizing = FALSE;
-}
-
-//0-normal / 1-caption / 2-leftbottom corner / 3-rightbottom corner / 4-close / 5-options
-FX_INT32 CPWL_Note::NoteHitTest(const CPDF_Point& point) const
-{
- ASSERT(m_pSubject != NULL);
- ASSERT(m_pDateTime != NULL);
- ASSERT(m_pContents != NULL);
- ASSERT(m_pAuthor != NULL);
- ASSERT(m_pIcon != NULL);
- ASSERT(m_pContentsBar != NULL);
-
- ASSERT(m_pCloseBox != NULL);
- ASSERT(m_pLBBox != NULL);
- ASSERT(m_pRBBox != NULL);
- ASSERT(m_pOptions != NULL);
-
- GetClientRect();
-
- if (m_pSubject->WndHitTest(m_pSubject->ParentToChild(point))) return 1;
- if (m_pDateTime->WndHitTest(m_pDateTime->ParentToChild(point))) return 1;
- if (m_pAuthor->WndHitTest(m_pAuthor->ParentToChild(point))) return 1;
- if (m_pIcon->WndHitTest(m_pIcon->ParentToChild(point))) return 1;
-
- if (m_pContents->WndHitTest(m_pContents->ParentToChild(point))) return 0;
- if (m_pContentsBar->WndHitTest(m_pContentsBar->ParentToChild(point))) return 0;
-
- if (m_pCloseBox->WndHitTest(m_pCloseBox->ParentToChild(point))) return 4;
- if (m_pLBBox->WndHitTest(m_pLBBox->ParentToChild(point))) return 2;
- if (m_pRBBox->WndHitTest(m_pRBBox->ParentToChild(point))) return 3;
- if (m_pOptions->WndHitTest(m_pOptions->ParentToChild(point))) return 5;
-
- return 1;
-}
-
-void CPWL_Note::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- CPWL_NoteItem::CreateChildWnd(cp);
-
- CPWL_Color sTextColor;
-
- if (CPWL_Utils::IsBlackOrWhite(this->GetBackgroundColor()))
- sTextColor = PWL_DEFAULT_WHITECOLOR;
- else
- sTextColor = PWL_DEFAULT_BLACKCOLOR;
-
- m_pAuthor = new CPWL_Label;
- PWL_CREATEPARAM acp = cp;
- acp.pParentWnd = this;
- acp.dwFlags = PWS_VISIBLE | PWS_CHILD | PES_LEFT | PES_TOP;
- acp.sTextColor = sTextColor;
- m_pAuthor->Create(acp);
-
- m_pCloseBox = new CPWL_Note_CloseBox;
- PWL_CREATEPARAM ccp = cp;
- ccp.pParentWnd = this;
- ccp.dwBorderWidth = 2;
- ccp.nBorderStyle = PBS_BEVELED;
- ccp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER;
- ccp.sTextColor = sTextColor;
- m_pCloseBox->Create(ccp);
-
- m_pIcon = new CPWL_Note_Icon;
- PWL_CREATEPARAM icp = cp;
- icp.pParentWnd = this;
- icp.dwFlags = PWS_VISIBLE | PWS_CHILD;
- m_pIcon->Create(icp);
-
- m_pOptions = new CPWL_Note_Options;
- PWL_CREATEPARAM ocp = cp;
- ocp.pParentWnd = this;
- ocp.dwFlags = PWS_CHILD | PWS_VISIBLE;
- ocp.sTextColor = sTextColor;
- m_pOptions->Create(ocp);
-
- m_pLBBox = new CPWL_Note_LBBox;
- PWL_CREATEPARAM lcp = cp;
- lcp.pParentWnd = this;
- lcp.dwFlags = PWS_VISIBLE | PWS_CHILD;
- lcp.eCursorType = FXCT_NESW;
- lcp.sTextColor = sTextColor;
- m_pLBBox->Create(lcp);
-
- m_pRBBox = new CPWL_Note_RBBox;
- PWL_CREATEPARAM rcp = cp;
- rcp.pParentWnd = this;
- rcp.dwFlags = PWS_VISIBLE | PWS_CHILD;
- rcp.eCursorType = FXCT_NWSE;
- rcp.sTextColor = sTextColor;
- m_pRBBox->Create(rcp);
-
- m_pContentsBar = new CPWL_ScrollBar(SBT_VSCROLL);
- PWL_CREATEPARAM scp = cp;
- scp.pParentWnd = this;
- scp.sBackgroundColor = CPWL_Color(COLORTYPE_RGB, 240/255.0f, 240/255.0f, 240/255.0f);
- scp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_BACKGROUND;
- m_pContentsBar->Create(scp);
- m_pContentsBar->SetNotifyForever(TRUE);
-}
-
-void CPWL_Note::SetSubjectName(const CFX_WideString& sName)
-{
- CPWL_NoteItem::SetSubjectName(sName);
- RePosChildWnd();
-}
-
-void CPWL_Note::SetAuthorName(const CFX_WideString& sName)
-{
- if (m_pAuthor)
- {
- m_pAuthor->SetText(sName);
- RePosChildWnd();
- }
-
- if (IPWL_NoteNotify* pNotify = GetNoteNotify())
- {
- pNotify->OnSetAuthorName(this);
- }
-}
-
-CFX_WideString CPWL_Note::GetAuthorName() const
-{
- if (m_pAuthor)
- return m_pAuthor->GetText();
-
- return L"";
-}
-
-FX_BOOL CPWL_Note::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPDF_Point ptScroll = m_pContents->GetScrollPos();
- CPDF_Rect rcScroll = m_pContents->GetScrollArea();
- CPDF_Rect rcContents = m_pContents->GetClientRect();
-
- if (rcScroll.top - rcScroll.bottom > rcContents.Height())
- {
- CPDF_Point ptNew = ptScroll;
-
- if (zDelta > 0)
- ptNew.y += 30;
- else
- ptNew.y -= 30;
-
- if (ptNew.y > rcScroll.top)
- ptNew.y = rcScroll.top;
- if (ptNew.y < rcScroll.bottom + rcContents.Height())
- ptNew.y = rcScroll.bottom + rcContents.Height();
- if (ptNew.y < rcScroll.bottom)
- ptNew.y = rcScroll.bottom;
-
- if (ptNew.y != ptScroll.y)
- {
- m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
- m_pContents->OnNotify(this, PNM_SCROLLWINDOW, SBT_VSCROLL, (FX_INTPTR)&ptNew.y);
- m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptNew.y);
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-void CPWL_Note::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- switch (msg)
- {
- case PNM_NOTEEDITCHANGED:
- {
- CPDF_Rect rcScroll = m_pContents->GetScrollArea();
-
-
- PWL_SCROLL_INFO sInfo;
- sInfo.fContentMin = rcScroll.bottom;
- sInfo.fContentMax = rcScroll.top;
- sInfo.fPlateWidth = m_pContents->GetClientRect().Height();
- sInfo.fSmallStep = 13.0f;
- sInfo.fBigStep = sInfo.fPlateWidth;
-
- if (FXSYS_memcmp(&m_OldScrollInfo, &sInfo, sizeof(PWL_SCROLL_INFO)) != 0)
- {
- FX_BOOL bScrollChanged = FALSE;
-
- if (lParam < 3) //·ÀÖ¹ËÀÑ­»· mantis:15759
- {
- bScrollChanged = ResetScrollBar();
- if (bScrollChanged)
- {
- lParam++;
- m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
- this->OnNotify(this, PNM_NOTEEDITCHANGED, 0, lParam);
- }
- }
-
- if (!bScrollChanged)
- {
- if (m_pContentsBar->IsVisible())
- {
- m_pContentsBar->OnNotify(pWnd, PNM_SETSCROLLINFO, SBT_VSCROLL, (FX_INTPTR)&sInfo);
- m_OldScrollInfo = sInfo;
-
- CPDF_Point ptScroll = m_pContents->GetScrollPos();
- CPDF_Point ptOld = ptScroll;
-
- if (ptScroll.y > sInfo.fContentMax)
- ptScroll.y = sInfo.fContentMax;
- if (ptScroll.y < sInfo.fContentMin + sInfo.fPlateWidth)
- ptScroll.y = sInfo.fContentMin + sInfo.fPlateWidth;
- if (ptScroll.y < sInfo.fContentMin)
- ptScroll.y = sInfo.fContentMin;
-
- if (ptOld.y != ptScroll.y)
- {
- m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
- m_pContentsBar->InvalidateRect(NULL);
- m_pContents->OnNotify(this, PNM_SCROLLWINDOW, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
- }
- }
- }
- }
- }
-
- m_pContents->InvalidateRect(NULL);
-
- return;
- case PNM_SCROLLWINDOW:
- if (m_pContents)
- m_pContents->OnNotify(pWnd, msg, wParam, lParam);
- return;
- case PNM_SETSCROLLPOS:
- if (m_pContentsBar)
- m_pContentsBar->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);
- return;
- }
-
- if (msg == PNM_SETCARETINFO && IsValid())
- {
- if (PWL_CARET_INFO * pInfo = (PWL_CARET_INFO*)wParam)
- {
- if (m_pContents)
- {
- CPDF_Rect rcClient = m_pContents->GetClientRect();
- if (pInfo->ptHead.y > rcClient.top)
- {
- CPDF_Point pt = m_pContents->OutToIn(pInfo->ptHead);
- m_pContents->OnNotify(this, PNM_SCROLLWINDOW, SBT_VSCROLL, (FX_INTPTR)&pt.y);
-
- CPDF_Point ptScroll = m_pContents->GetScrollPos();
- m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
-
- return;
- }
-
- if (pInfo->ptFoot.y < rcClient.bottom)
- {
- CPDF_Point pt = m_pContents->OutToIn(pInfo->ptFoot);
- pt.y += rcClient.Height();
- m_pContents->OnNotify(this, PNM_SCROLLWINDOW, SBT_VSCROLL, (FX_INTPTR)&pt.y);
-
- CPDF_Point ptScroll = m_pContents->GetScrollPos();
- m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
-
- return;
- }
- }
- }
- }
-
- CPWL_NoteItem::OnNotify(pWnd, msg, wParam, lParam);
-}
-
-void CPWL_Note::SetBkColor(const CPWL_Color& color)
-{
- CPWL_NoteItem::SetBkColor(color);
-
- CPWL_Color sBK = color;
- CPWL_Color sTextColor;
- if (CPWL_Utils::IsBlackOrWhite(sBK))
- sTextColor = PWL_DEFAULT_WHITECOLOR;
- else
- sTextColor = PWL_DEFAULT_BLACKCOLOR;
-
- if (m_pCloseBox)
- m_pCloseBox->SetTextColor(sTextColor);
- if (m_pAuthor)
- m_pAuthor->SetTextColor(sTextColor);
- if (m_pOptions)
- m_pOptions->SetTextColor(sTextColor);
- if (m_pLBBox)
- m_pLBBox->SetTextColor(sTextColor);
- if (m_pRBBox)
- m_pRBBox->SetTextColor(sTextColor);
-}
-
-FX_BOOL CPWL_Note::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag)
-{
- if (m_pOptions->WndHitTest(m_pOptions->ParentToChild(point)))
- {
- if (IPWL_NoteNotify* pNotify = this->GetNoteNotify())
- {
- FX_INT32 x, y;
- PWLtoWnd(point, x, y);
- if (IFX_SystemHandler* pSH = GetSystemHandler())
- pSH->ClientToScreen(GetAttachedHWnd(), x, y);
- this->KillFocus();
- pNotify->OnPopupMenu(x, y);
-
- return TRUE;
- }
- }
-
- return CPWL_Wnd::OnLButtonDown(point,nFlag);
-}
-
-FX_BOOL CPWL_Note::OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- return CPWL_Wnd::OnRButtonUp(point,nFlag);
-}
-
-const CPWL_Note* CPWL_Note::GetNote() const
-{
- return this;
-}
-
-IPWL_NoteNotify* CPWL_Note::GetNoteNotify() const
-{
- if (m_bEnalbleNotify)
- return m_pNoteNotify;
-
- return NULL;
-}
-
-void CPWL_Note::SetIconType(FX_INT32 nType)
-{
- if (m_pIcon)
- m_pIcon->SetIconType(nType);
-}
-
-void CPWL_Note::EnableModify(FX_BOOL bEnabled)
-{
- m_pContents->EnableModify(bEnabled);
-}
-
-void CPWL_Note::EnableRead(FX_BOOL bEnabled)
-{
- m_pContents->EnableRead(bEnabled);
-}
-
-CFX_WideString CPWL_Note::GetReplyString() const
-{
- return m_sReplyString;
-}
-
-void CPWL_Note::SetReplyString(const CFX_WideString& string)
-{
- m_sReplyString = string;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Button.h"
+#include "../../include/pdfwindow/PWL_EditCtrl.h"
+#include "../../include/pdfwindow/PWL_Edit.h"
+#include "../../include/pdfwindow/PWL_ListCtrl.h"
+#include "../../include/pdfwindow/PWL_ScrollBar.h"
+#include "../../include/pdfwindow/PWL_Note.h"
+#include "../../include/pdfwindow/PWL_Label.h"
+#include "../../include/pdfwindow/PWL_Edit.h"
+#include "../../include/pdfwindow/PWL_ScrollBar.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+#include "../../include/pdfwindow/PWL_Caret.h"
+
+#define POPUP_ITEM_HEAD_BOTTOM 3.0f
+#define POPUP_ITEM_BOTTOMWIDTH 1.0f
+#define POPUP_ITEM_SIDEMARGIN 3.0f
+#define POPUP_ITEM_SPACE 4.0f
+#define POPUP_ITEM_TEXT_INDENT 2.0f
+#define POPUP_ITEM_BORDERCOLOR CPWL_Color(COLORTYPE_RGB, 80/255.0f, 80/255.0f, 80/255.0f)
+
+#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
+#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
+
+
+/* ------------------------------- CPWL_Note_Options ------------------------------- */
+
+CPWL_Note_Options::CPWL_Note_Options() : m_pText(NULL)
+{
+}
+
+CPWL_Note_Options::~CPWL_Note_Options()
+{
+}
+
+void CPWL_Note_Options::SetTextColor(const CPWL_Color & color)
+{
+ CPWL_Wnd::SetTextColor(color);
+
+ if (m_pText)
+ m_pText->SetTextColor(color);
+}
+
+void CPWL_Note_Options::RePosChildWnd()
+{
+ if (this->IsValid())
+ {
+ ASSERT(m_pText != NULL);
+
+ CPDF_Rect rcClient = GetClientRect();
+
+ if (rcClient.Width() > 15.0f)
+ {
+ rcClient.right -= 15.0f;
+ m_pText->Move(rcClient, TRUE, FALSE);
+ m_pText->SetVisible(TRUE);
+ }
+ else
+ {
+ m_pText->Move(CPDF_Rect(0,0,0,0), TRUE, FALSE);
+ m_pText->SetVisible(FALSE);
+ }
+ }
+}
+
+void CPWL_Note_Options::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ m_pText = new CPWL_Label;
+ PWL_CREATEPARAM tcp = cp;
+ tcp.pParentWnd = this;
+ tcp.dwFlags = PWS_CHILD | PWS_VISIBLE;
+ m_pText->Create(tcp);
+}
+
+void CPWL_Note_Options::SetText(const CFX_WideString& sText)
+{
+ m_pText->SetText(sText);
+}
+
+void CPWL_Note_Options::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
+
+ CPDF_Rect rcClient = GetClientRect();
+ rcClient.left = rcClient.right - 15.0f;
+
+ CPDF_Point ptCenter = CPDF_Point((rcClient.left + rcClient.right) * 0.5f, (rcClient.top + rcClient.bottom) * 0.5f);
+
+ CPDF_Point pt1(ptCenter.x - 2.0f, ptCenter.y + 2.0f * 0.5f);
+ CPDF_Point pt2(ptCenter.x + 2.0f, ptCenter.y + 2.0f * 0.5f);
+ CPDF_Point pt3(ptCenter.x, ptCenter.y - 3.0f * 0.5f);
+
+ CFX_PathData path;
+
+ path.SetPointCount(4);
+ path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
+ path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
+ path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
+ path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
+
+ pDevice->DrawPath(&path, pUser2Device, NULL,
+ CPWL_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()),
+ 0, FXFILL_ALTERNATE);
+}
+
+CPDF_Rect CPWL_Note_Options::GetContentRect() const
+{
+ ASSERT(m_pText != NULL);
+
+ CPDF_Rect rcText = m_pText->GetContentRect();
+ rcText.right += 15.0f;
+ return rcText;
+}
+
+/* ------------------------------- CPWL_Note_Edit ------------------------------ */
+
+CPWL_Note_Edit::CPWL_Note_Edit() : m_bEnableNotify(TRUE),
+ m_fOldItemHeight(0.0f),
+ m_bSizeChanged(FALSE),
+ m_fOldMin(0.0f),
+ m_fOldMax(0.0f)
+{
+}
+
+CPWL_Note_Edit::~CPWL_Note_Edit()
+{
+}
+
+void CPWL_Note_Edit::RePosChildWnd()
+{
+ m_bEnableNotify = FALSE;
+ CPWL_Edit::RePosChildWnd();
+ m_bEnableNotify = TRUE;
+
+ m_fOldItemHeight = this->GetContentRect().Height();
+}
+
+void CPWL_Note_Edit::SetText(FX_LPCWSTR csText)
+{
+ m_bEnableNotify = FALSE;
+ CPWL_Edit::SetText(csText);
+ m_bEnableNotify = TRUE;
+ m_fOldItemHeight = this->GetContentRect().Height();
+}
+
+void CPWL_Note_Edit::OnSetFocus()
+{
+ m_bEnableNotify = FALSE;
+ CPWL_Edit::OnSetFocus();
+ m_bEnableNotify = TRUE;
+
+ this->EnableSpellCheck(TRUE);
+}
+
+void CPWL_Note_Edit::OnKillFocus()
+{
+ this->EnableSpellCheck(FALSE);
+
+ if (CPWL_Wnd* pParent = this->GetParentWindow())
+ {
+ if (CPWL_Wnd* pGrand = pParent->GetParentWindow())
+ {
+ ASSERT(pGrand->GetClassName() == "CPWL_NoteItem");
+
+ CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pGrand;
+
+ pNoteItem->OnContentsValidate();
+ }
+ }
+
+ CPWL_Edit::OnKillFocus();
+}
+
+void CPWL_Note_Edit::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ if (m_bEnableNotify)
+ {
+ if (wParam == SBT_VSCROLL)
+ {
+ switch (msg)
+ {
+ case PNM_SETSCROLLINFO:
+ if (PWL_SCROLL_INFO* pInfo = (PWL_SCROLL_INFO*)lParam)
+ {
+ if (!IsFloatEqual(pInfo->fContentMax, m_fOldMax) ||
+ !IsFloatEqual(pInfo->fContentMin, m_fOldMin))
+ {
+ m_bSizeChanged = TRUE;
+ if (CPWL_Wnd * pParent = this->GetParentWindow())
+ {
+ pParent->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
+ }
+
+ m_fOldMax = pInfo->fContentMax;
+ m_fOldMin = pInfo->fContentMin;
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ CPWL_Edit::OnNotify(pWnd, msg, wParam, lParam);
+
+ if (m_bEnableNotify)
+ {
+ switch (msg)
+ {
+ case PNM_SETCARETINFO:
+ if (PWL_CARET_INFO * pInfo = (PWL_CARET_INFO*)wParam)
+ {
+ PWL_CARET_INFO newInfo = *pInfo;
+ newInfo.bVisible = TRUE;
+ newInfo.ptHead = this->ChildToParent(pInfo->ptHead);
+ newInfo.ptFoot = this->ChildToParent(pInfo->ptFoot);
+
+ if (CPWL_Wnd * pParent = this->GetParentWindow())
+ {
+ pParent->OnNotify(this, PNM_SETCARETINFO, (FX_INTPTR)&newInfo, 0);
+ }
+ }
+ break;
+ }
+ }
+}
+
+FX_FLOAT CPWL_Note_Edit::GetItemHeight(FX_FLOAT fLimitWidth)
+{
+ if (fLimitWidth > 0)
+ {
+ if (!m_bSizeChanged)
+ return m_fOldItemHeight;
+
+ m_bSizeChanged = FALSE;
+
+ this->EnableNotify(FALSE);
+ this->EnableRefresh(FALSE);
+ m_pEdit->EnableNotify(FALSE);
+
+ //CPDF_Rect rcOld = this->GetWindowRect();
+
+ this->Move(CPDF_Rect(0,0,fLimitWidth,0), TRUE, FALSE);
+ FX_FLOAT fRet = this->GetContentRect().Height();
+
+ //this->Move(rcOld, TRUE, FALSE);
+
+ m_pEdit->EnableNotify(TRUE);
+ this->EnableNotify(TRUE);
+ this->EnableRefresh(TRUE);
+
+ return fRet;
+ }
+
+ return 0;
+}
+
+FX_FLOAT CPWL_Note_Edit::GetItemLeftMargin()
+{
+ return POPUP_ITEM_TEXT_INDENT;
+}
+
+FX_FLOAT CPWL_Note_Edit::GetItemRightMargin()
+{
+ return POPUP_ITEM_TEXT_INDENT;
+}
+
+/* -------------------------------- CPWL_Note_LBBox --------------------------------*/
+
+CPWL_Note_LBBox::CPWL_Note_LBBox()
+{
+}
+
+CPWL_Note_LBBox::~CPWL_Note_LBBox()
+{
+}
+
+void CPWL_Note_LBBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPDF_Rect rcClient = this->GetClientRect();
+
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = 1.0f;
+
+ CFX_PathData pathCross;
+
+ pathCross.SetPointCount(4);
+ pathCross.SetPoint(0, rcClient.left, rcClient.top, FXPT_MOVETO);
+ pathCross.SetPoint(1, rcClient.right, rcClient.bottom, FXPT_LINETO);
+ pathCross.SetPoint(2, rcClient.left, rcClient.bottom + rcClient.Height() * 0.5f, FXPT_MOVETO);
+ pathCross.SetPoint(3, rcClient.left + rcClient.Width() * 0.5f, rcClient.bottom, FXPT_LINETO);
+
+ pDevice->DrawPath(&pathCross, pUser2Device, &gsd,
+ 0, CPWL_Utils::PWLColorToFXColor(GetTextColor(),this->GetTransparency()), FXFILL_ALTERNATE);
+}
+
+/* -------------------------------- CPWL_Note_RBBox --------------------------------*/
+
+CPWL_Note_RBBox::CPWL_Note_RBBox()
+{
+}
+
+CPWL_Note_RBBox::~CPWL_Note_RBBox()
+{
+}
+
+void CPWL_Note_RBBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPDF_Rect rcClient = this->GetClientRect();
+
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = 1.0f;
+
+ CFX_PathData pathCross;
+
+ pathCross.SetPointCount(4);
+ pathCross.SetPoint(0, rcClient.right, rcClient.top, FXPT_MOVETO);
+ pathCross.SetPoint(1, rcClient.left, rcClient.bottom, FXPT_LINETO);
+ pathCross.SetPoint(2, rcClient.right, rcClient.bottom + rcClient.Height() * 0.5f, FXPT_MOVETO);
+ pathCross.SetPoint(3, rcClient.left + rcClient.Width() * 0.5f, rcClient.bottom, FXPT_LINETO);
+
+ pDevice->DrawPath(&pathCross, pUser2Device, &gsd,
+ 0, CPWL_Utils::PWLColorToFXColor(GetTextColor(),this->GetTransparency()), FXFILL_ALTERNATE);
+}
+
+/* --------------------------------- CPWL_Note_Icon ---------------------------------- */
+
+CPWL_Note_Icon::CPWL_Note_Icon() : m_nType(0)
+{
+}
+
+CPWL_Note_Icon::~CPWL_Note_Icon()
+{
+}
+
+void CPWL_Note_Icon::SetIconType(FX_INT32 nType)
+{
+ m_nType = nType;
+}
+
+void CPWL_Note_Icon::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, m_nType, GetClientRect(),
+ this->GetBackgroundColor(), PWL_DEFAULT_BLACKCOLOR, this->GetTransparency());
+}
+
+/* --------------------------------- CPWL_Note_CloseBox ---------------------------------- */
+
+CPWL_Note_CloseBox::CPWL_Note_CloseBox() : m_bMouseDown(FALSE)
+{
+}
+
+CPWL_Note_CloseBox::~CPWL_Note_CloseBox()
+{
+}
+
+void CPWL_Note_CloseBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPWL_Button::DrawThisAppearance(pDevice, pUser2Device);
+
+ CPDF_Rect rcClient = this->GetClientRect();
+ rcClient = CPWL_Utils::DeflateRect(rcClient, 2.0f);
+
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = 1.0f;
+
+ CFX_PathData pathCross;
+
+ if (m_bMouseDown)
+ {
+ rcClient.left += 0.5f;
+ rcClient.right += 0.5f;
+ rcClient.top -= 0.5f;
+ rcClient.bottom -= 0.5f;
+ }
+
+ pathCross.SetPointCount(4);
+ pathCross.SetPoint(0, rcClient.left, rcClient.bottom, FXPT_MOVETO);
+ pathCross.SetPoint(1, rcClient.right, rcClient.top, FXPT_LINETO);
+ pathCross.SetPoint(2, rcClient.left, rcClient.top, FXPT_MOVETO);
+ pathCross.SetPoint(3, rcClient.right, rcClient.bottom, FXPT_LINETO);
+
+ pDevice->DrawPath(&pathCross, pUser2Device, &gsd,
+ 0, CPWL_Utils::PWLColorToFXColor(GetTextColor(),this->GetTransparency()), FXFILL_ALTERNATE);
+}
+
+FX_BOOL CPWL_Note_CloseBox::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ SetBorderStyle(PBS_INSET);
+ InvalidateRect(NULL);
+
+ m_bMouseDown = TRUE;
+
+ return CPWL_Button::OnLButtonDown(point,nFlag);
+}
+
+FX_BOOL CPWL_Note_CloseBox::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ m_bMouseDown = FALSE;
+
+ SetBorderStyle(PBS_BEVELED);
+ InvalidateRect(NULL);
+
+ return CPWL_Button::OnLButtonUp(point,nFlag);
+}
+
+/* ------------------------------ CPWL_Note_Contents ------------------------------- */
+
+CPWL_Note_Contents::CPWL_Note_Contents() : m_pEdit(NULL)
+{
+}
+
+CPWL_Note_Contents::~CPWL_Note_Contents()
+{
+}
+
+CFX_ByteString CPWL_Note_Contents::GetClassName() const
+{
+ return "CPWL_Note_Contents";
+}
+
+void CPWL_Note_Contents::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ m_pEdit = new CPWL_Note_Edit;
+ PWL_CREATEPARAM ecp = cp;
+ ecp.pParentWnd = this;
+ ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PES_MULTILINE | PES_AUTORETURN | PES_TEXTOVERFLOW | PES_UNDO | PES_SPELLCHECK;
+
+ m_pEdit->EnableNotify(FALSE);
+ m_pEdit->Create(ecp);
+ m_pEdit->EnableNotify(TRUE);
+}
+
+void CPWL_Note_Contents::SetText(const CFX_WideString& sText)
+{
+ if (m_pEdit)
+ {
+ m_pEdit->EnableNotify(FALSE);
+ m_pEdit->SetText(sText);
+ m_pEdit->EnableNotify(TRUE);
+ OnNotify(m_pEdit, PNM_NOTEEDITCHANGED, 0, 0);
+ }
+}
+
+CFX_WideString CPWL_Note_Contents::GetText() const
+{
+ if (m_pEdit)
+ return m_pEdit->GetText();
+
+ return L"";
+}
+
+CPWL_NoteItem* CPWL_Note_Contents::CreateSubItem()
+{
+ CPWL_NoteItem* pNoteItem = new CPWL_NoteItem;
+ PWL_CREATEPARAM icp = this->GetCreationParam();
+ icp.pParentWnd = this;
+ icp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_BACKGROUND;
+ pNoteItem->Create(icp);
+
+ pNoteItem->OnCreateNoteItem();
+
+ pNoteItem->ResetSubjectName(m_aChildren.GetSize() - 1);
+
+ FX_SYSTEMTIME st;
+ if (IFX_SystemHandler* pSH = this->GetSystemHandler())
+ st = pSH->GetLocalTime();
+ pNoteItem->SetDateTime(st);
+
+ pNoteItem->SetContents(L"");
+
+ this->OnNotify(pNoteItem, PNM_NOTEEDITCHANGED, 0, 0);
+
+ return pNoteItem;
+}
+
+FX_INT32 CPWL_Note_Contents::CountSubItems() const
+{
+ return m_aChildren.GetSize() - 1;
+}
+
+IPWL_NoteItem* CPWL_Note_Contents::GetSubItems(FX_INT32 index) const
+{
+ FX_INT32 nIndex = index + 1;
+
+ if (nIndex > 0 && nIndex < m_aChildren.GetSize())
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(nIndex))
+ {
+ ASSERT(pChild->GetClassName() == "CPWL_NoteItem");
+ CPWL_NoteItem* pItem = (CPWL_NoteItem*)pChild;
+ return pItem;
+ }
+ return NULL;
+}
+
+void CPWL_Note_Contents::DeleteSubItem(IPWL_NoteItem* pNoteItem)
+{
+ FX_INT32 nIndex = this->GetItemIndex((CPWL_NoteItem*)pNoteItem);
+
+ if (nIndex > 0)
+ {
+ if (CPWL_NoteItem* pPWLNoteItem = (CPWL_NoteItem*)pNoteItem)
+ {
+ pPWLNoteItem->KillFocus();
+ pPWLNoteItem->Destroy();
+ delete pPWLNoteItem;
+ }
+
+ for (FX_INT32 i=nIndex,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ ASSERT(pChild->GetClassName() == "CPWL_NoteItem");
+ CPWL_NoteItem* pItem = (CPWL_NoteItem*)pChild;
+ pItem->ResetSubjectName(i);
+ }
+ }
+
+ this->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
+ }
+}
+
+IPWL_NoteItem* CPWL_Note_Contents::GetHitNoteItem(const CPDF_Point& point)
+{
+ CPDF_Point pt = this->ParentToChild(point);
+
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ if (pChild->GetClassName() == "CPWL_NoteItem")
+ {
+ CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pChild;
+ if (IPWL_NoteItem* pRet = pNoteItem->GetHitNoteItem(pt))
+ return pRet;
+ }
+ }
+ }
+ return NULL;
+}
+
+void CPWL_Note_Contents::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ switch (msg)
+ {
+ case PNM_NOTEEDITCHANGED:
+ {
+ FX_INT32 nIndex = this->GetItemIndex(pWnd);
+ if (nIndex < 0) nIndex = 0;
+
+ m_pEdit->EnableNotify(FALSE);
+ this->ResetContent(nIndex);
+ m_pEdit->EnableNotify(TRUE);
+
+ for (FX_INT32 i=nIndex+1, sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ pChild->OnNotify(this, PNM_NOTERESET, 0, 0);
+ }
+
+ if (CPWL_Wnd * pParent = this->GetParentWindow())
+ {
+ pParent->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
+ }
+ }
+ return;
+ case PNM_SCROLLWINDOW:
+ this->SetScrollPos(CPDF_Point(0.0f, *(FX_FLOAT*)lParam));
+ this->ResetFace();
+ InvalidateRect(NULL);
+ return;
+ case PNM_SETCARETINFO:
+ if (PWL_CARET_INFO * pInfo = (PWL_CARET_INFO*)wParam)
+ {
+ PWL_CARET_INFO newInfo = *pInfo;
+ newInfo.bVisible = TRUE;
+ newInfo.ptHead = this->ChildToParent(pInfo->ptHead);
+ newInfo.ptFoot = this->ChildToParent(pInfo->ptFoot);
+
+ if (CPWL_Wnd * pParent = this->GetParentWindow())
+ {
+ pParent->OnNotify(this, PNM_SETCARETINFO, (FX_INTPTR)&newInfo, 0);
+ }
+ }
+ return;
+ case PNM_NOTERESET:
+ {
+ m_pEdit->EnableNotify(FALSE);
+ this->ResetContent(0);
+ m_pEdit->EnableNotify(TRUE);
+
+ for (FX_INT32 i=1, sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ pChild->OnNotify(this, PNM_NOTERESET, 0, 0);
+ }
+
+ m_pEdit->EnableNotify(FALSE);
+ this->ResetContent(0);
+ m_pEdit->EnableNotify(TRUE);
+ }
+ return;
+ }
+
+ CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
+}
+
+FX_BOOL CPWL_Note_Contents::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ if (CPWL_Wnd::OnLButtonDown(point,nFlag)) return TRUE;
+
+ if (!m_pEdit->IsFocused())
+ {
+ m_pEdit->SetFocus();
+ }
+
+ return TRUE;
+}
+
+void CPWL_Note_Contents::SetEditFocus(FX_BOOL bLast)
+{
+ if (!m_pEdit->IsFocused())
+ {
+ m_pEdit->SetFocus();
+ m_pEdit->SetCaret(bLast ? m_pEdit->GetTotalWords() : 0);
+ }
+}
+
+CPWL_Edit* CPWL_Note_Contents::GetEdit() const
+{
+ return m_pEdit;
+}
+
+void CPWL_Note_Contents::EnableModify(FX_BOOL bEnabled)
+{
+ if (!bEnabled)
+ m_pEdit->AddFlag(PWS_READONLY);
+ else
+ m_pEdit->RemoveFlag(PWS_READONLY);
+
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ if (pChild->GetClassName() == "CPWL_NoteItem")
+ {
+ CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pChild;
+ pNoteItem->EnableModify(bEnabled);
+ }
+ }
+ }
+}
+
+void CPWL_Note_Contents::EnableRead(FX_BOOL bEnabled)
+{
+ if (!bEnabled)
+ m_pEdit->AddFlag(PES_NOREAD);
+ else
+ m_pEdit->RemoveFlag(PES_NOREAD);
+
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ if (pChild->GetClassName() == "CPWL_NoteItem")
+ {
+ CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pChild;
+ pNoteItem->EnableRead(bEnabled);
+ }
+ }
+ }
+}
+
+/* ---------------------------------- CPWL_NoteItem ---------------------------------- */
+
+CPWL_NoteItem::CPWL_NoteItem() :
+ m_pPrivateData(NULL),
+ m_pSubject(NULL),
+ m_pDateTime(NULL),
+ m_pContents(NULL),
+ m_sAuthor(L""),
+ m_fOldItemHeight(0.0f),
+ m_bSizeChanged(FALSE),
+ m_bAllowModify(TRUE)
+{
+}
+
+CPWL_NoteItem::~CPWL_NoteItem()
+{
+}
+
+CFX_ByteString CPWL_NoteItem::GetClassName() const
+{
+ return "CPWL_NoteItem";
+}
+
+void CPWL_NoteItem::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ CPWL_Color sTextColor;
+
+ if (CPWL_Utils::IsBlackOrWhite(this->GetBackgroundColor()))
+ sTextColor = PWL_DEFAULT_WHITECOLOR;
+ else
+ sTextColor = PWL_DEFAULT_BLACKCOLOR;
+
+ m_pSubject = new CPWL_Label;
+ PWL_CREATEPARAM scp = cp;
+ scp.pParentWnd = this;
+ scp.dwFlags = PWS_VISIBLE | PWS_CHILD | PES_LEFT | PES_TOP;
+ scp.sTextColor = sTextColor;
+ m_pSubject->Create(scp);
+
+ m_pDateTime = new CPWL_Label;
+ PWL_CREATEPARAM dcp = cp;
+ dcp.pParentWnd = this;
+ dcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PES_RIGHT | PES_TOP;
+ dcp.sTextColor = sTextColor;
+ m_pDateTime->Create(dcp);
+
+ m_pContents = new CPWL_Note_Contents;
+ PWL_CREATEPARAM ccp = cp;
+ ccp.pParentWnd = this;
+ //ccp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
+ ccp.sBackgroundColor = CPWL_Color(COLORTYPE_RGB, 240/255.0f, 240/255.0f, 240/255.0f);
+ ccp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BACKGROUND;
+ m_pContents->Create(ccp);
+ m_pContents->SetItemSpace(POPUP_ITEM_SPACE);
+ m_pContents->SetTopSpace(POPUP_ITEM_SPACE);
+ m_pContents->SetBottomSpace(POPUP_ITEM_SPACE);
+}
+
+void CPWL_NoteItem::RePosChildWnd()
+{
+ if (this->IsValid())
+ {
+ ASSERT(m_pSubject != NULL);
+ ASSERT(m_pDateTime != NULL);
+ ASSERT(m_pContents != NULL);
+
+ CPDF_Rect rcClient = GetClientRect();
+
+ CPDF_Rect rcSubject = rcClient;
+ rcSubject.left += POPUP_ITEM_TEXT_INDENT;
+ rcSubject.top = rcClient.top;
+ rcSubject.right = PWL_MIN(rcSubject.left + m_pSubject->GetContentRect().Width() + 1.0f, rcClient.right);
+ rcSubject.bottom = rcSubject.top - m_pSubject->GetContentRect().Height();
+ rcSubject.Normalize();
+ m_pSubject->Move(rcSubject, TRUE, FALSE);
+ m_pSubject->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcSubject));
+
+ CPDF_Rect rcDate = rcClient;
+ rcDate.right -= POPUP_ITEM_TEXT_INDENT;
+ rcDate.left = PWL_MAX(rcDate.right - m_pDateTime->GetContentRect().Width() - 1.0f, rcSubject.right);
+ rcDate.bottom = rcDate.top - m_pDateTime->GetContentRect().Height();
+ rcDate.Normalize();
+ m_pDateTime->Move(rcDate, TRUE, FALSE);
+ m_pDateTime->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcDate));
+
+ CPDF_Rect rcContents = rcClient;
+ rcContents.left += 1.0f;
+ rcContents.right -= 1.0f;
+ rcContents.top = rcDate.bottom - POPUP_ITEM_HEAD_BOTTOM;
+ rcContents.bottom += POPUP_ITEM_BOTTOMWIDTH;
+ rcContents.Normalize();
+ m_pContents->Move(rcContents, TRUE, FALSE);
+ m_pContents->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcContents));
+ }
+
+ SetClipRect(CPWL_Utils::InflateRect(GetWindowRect(),1.0f));
+}
+
+void CPWL_NoteItem::SetPrivateData(void* pData)
+{
+ m_pPrivateData = pData;
+}
+
+void CPWL_NoteItem::SetBkColor(const CPWL_Color& color)
+{
+ CPWL_Color sBK = color;
+ this->SetBackgroundColor(sBK);
+
+ CPWL_Color sTextColor;
+
+ if (CPWL_Utils::IsBlackOrWhite(sBK))
+ sTextColor = PWL_DEFAULT_WHITECOLOR;
+ else
+ sTextColor = PWL_DEFAULT_BLACKCOLOR;
+
+ this->SetTextColor(sTextColor);
+ if (m_pSubject)
+ m_pSubject->SetTextColor(sTextColor);
+ if (m_pDateTime)
+ m_pDateTime->SetTextColor(sTextColor);
+
+ this->InvalidateRect(NULL);
+
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ pNotify->OnSetBkColor(this);
+ }
+}
+
+void CPWL_NoteItem::SetSubjectName(const CFX_WideString& sName)
+{
+ if (m_pSubject)
+ {
+ m_pSubject->SetText(sName);
+ }
+
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ pNotify->OnSetSubjectName(this);
+ }
+}
+
+void CPWL_NoteItem::SetAuthorName(const CFX_WideString& sName)
+{
+ m_sAuthor = sName;
+ ResetSubjectName(-1);
+
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ pNotify->OnSetAuthorName(this);
+ }
+}
+
+void CPWL_NoteItem::ResetSubjectName(FX_INT32 nItemIndex)
+{
+ if (nItemIndex < 0)
+ {
+ if (CPWL_Wnd* pParent = this->GetParentWindow())
+ {
+ ASSERT(pParent->GetClassName() == "CPWL_Note_Contents");
+
+ CPWL_Note_Contents* pContents = (CPWL_Note_Contents*)pParent;
+ nItemIndex = pContents->GetItemIndex(this);
+ }
+ }
+
+ const CPWL_Note* pNote = GetNote();
+ ASSERT(pNote != NULL);
+
+ CFX_WideString sSubject;
+ sSubject.Format(pNote->GetReplyString(), nItemIndex);
+
+ if (!m_sAuthor.IsEmpty())
+ {
+
+ sSubject += L" - ";
+ sSubject += m_sAuthor;
+ }
+ this->SetSubjectName(sSubject);
+ this->RePosChildWnd();
+}
+
+void CPWL_NoteItem::SetDateTime(FX_SYSTEMTIME time)
+{
+ m_dtNote = time;
+
+ CFX_WideString swTime;
+ swTime.Format((FX_LPCWSTR)L"%04d-%02d-%02d %02d:%02d:%02d", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond);
+ if (m_pDateTime)
+ {
+ m_pDateTime->SetText(swTime);
+ }
+
+ this->RePosChildWnd();
+
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ pNotify->OnSetDateTime(this);
+ }
+}
+
+void CPWL_NoteItem::SetContents(const CFX_WideString& sContents)
+{
+ if (m_pContents)
+ {
+ m_pContents->SetText(sContents);
+ }
+
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ pNotify->OnSetContents(this);
+ }
+}
+
+CPWL_NoteItem* CPWL_NoteItem::GetParentNoteItem() const
+{
+ if (CPWL_Wnd* pParent = this->GetParentWindow())
+ {
+ if (CPWL_Wnd* pGrand = pParent->GetParentWindow())
+ {
+ ASSERT(pGrand->GetClassName() == "CPWL_NoteItem");
+ return (CPWL_NoteItem*)pGrand;
+ }
+ }
+
+ return NULL;
+}
+
+IPWL_NoteItem* CPWL_NoteItem::GetParentItem() const
+{
+ return GetParentNoteItem();
+}
+
+CPWL_Edit* CPWL_NoteItem::GetEdit() const
+{
+ if (m_pContents)
+ return m_pContents->GetEdit();
+ return NULL;
+}
+
+void* CPWL_NoteItem::GetPrivateData() const
+{
+ return m_pPrivateData;
+}
+
+CFX_WideString CPWL_NoteItem::GetAuthorName() const
+{
+ return m_sAuthor;
+}
+
+CPWL_Color CPWL_NoteItem::GetBkColor() const
+{
+ return this->GetBackgroundColor();
+}
+
+CFX_WideString CPWL_NoteItem::GetContents() const
+{
+ if (m_pContents)
+ return m_pContents->GetText();
+
+ return L"";
+}
+
+FX_SYSTEMTIME CPWL_NoteItem::GetDateTime() const
+{
+ return m_dtNote;
+}
+
+CFX_WideString CPWL_NoteItem::GetSubjectName() const
+{
+ if (m_pSubject)
+ return m_pSubject->GetText();
+
+ return L"";
+}
+
+CPWL_NoteItem* CPWL_NoteItem::CreateNoteItem()
+{
+ if (m_pContents)
+ return m_pContents->CreateSubItem();
+
+ return NULL;
+}
+
+IPWL_NoteItem* CPWL_NoteItem::CreateSubItem()
+{
+ return CreateNoteItem();
+}
+
+FX_INT32 CPWL_NoteItem::CountSubItems() const
+{
+ if (m_pContents)
+ return m_pContents->CountSubItems();
+
+ return 0;
+}
+
+IPWL_NoteItem* CPWL_NoteItem::GetSubItems(FX_INT32 index) const
+{
+ if (m_pContents)
+ return m_pContents->GetSubItems(index);
+
+ return NULL;
+}
+
+void CPWL_NoteItem::DeleteSubItem(IPWL_NoteItem* pNoteItem)
+{
+ this->KillFocus();
+
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ pNotify->OnItemDelete(pNoteItem);
+ }
+
+ if (m_pContents)
+ m_pContents->DeleteSubItem(pNoteItem);
+}
+
+IPWL_NoteItem* CPWL_NoteItem::GetHitNoteItem(const CPDF_Point& point)
+{
+ CPDF_Point pt = this->ParentToChild(point);
+
+ if (this->WndHitTest(pt))
+ {
+ if (m_pContents)
+ {
+ if (IPWL_NoteItem* pNoteItem = m_pContents->GetHitNoteItem(pt))
+ return pNoteItem;
+ }
+
+ return this;
+ }
+
+ return NULL;
+}
+
+IPWL_NoteItem* CPWL_NoteItem::GetFocusedNoteItem() const
+{
+ if (const CPWL_Wnd* pWnd = this->GetFocused())
+ {
+ if (pWnd->GetClassName() == "CPWL_Edit")
+ {
+ if (CPWL_Wnd* pParent = pWnd->GetParentWindow())
+ {
+ ASSERT(pParent->GetClassName() == "CPWL_Note_Contents");
+
+ if (CPWL_Wnd* pGrand = pParent->GetParentWindow())
+ {
+ ASSERT(pGrand->GetClassName() == "CPWL_NoteItem");
+ return (CPWL_NoteItem*)pGrand;
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
+
+FX_FLOAT CPWL_NoteItem::GetItemHeight(FX_FLOAT fLimitWidth)
+{
+ if (fLimitWidth > 0)
+ {
+ if (!m_bSizeChanged)
+ return m_fOldItemHeight;
+
+ m_bSizeChanged = FALSE;
+
+ ASSERT(m_pSubject != NULL);
+ ASSERT(m_pDateTime != NULL);
+ ASSERT(m_pContents != NULL);
+
+ FX_FLOAT fRet = m_pDateTime->GetContentRect().Height();
+ FX_FLOAT fBorderWidth = (FX_FLOAT)this->GetBorderWidth();
+ if (fLimitWidth > fBorderWidth * 2)
+ fRet += m_pContents->GetContentsHeight(fLimitWidth - fBorderWidth * 2);
+ fRet += POPUP_ITEM_HEAD_BOTTOM + POPUP_ITEM_BOTTOMWIDTH + fBorderWidth * 2;
+
+ return m_fOldItemHeight = fRet;
+ }
+
+ return 0;
+}
+
+FX_FLOAT CPWL_NoteItem::GetItemLeftMargin()
+{
+ return POPUP_ITEM_SIDEMARGIN;
+}
+
+FX_FLOAT CPWL_NoteItem::GetItemRightMargin()
+{
+ return POPUP_ITEM_SIDEMARGIN;
+}
+
+FX_BOOL CPWL_NoteItem::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag)
+{
+ if (!m_pContents->WndHitTest(m_pContents->ParentToChild(point)))
+ {
+ SetNoteFocus(FALSE);
+ }
+
+ CPWL_Wnd::OnLButtonDown(point,nFlag);
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_NoteItem::OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ if (!m_pContents->WndHitTest(m_pContents->ParentToChild(point)))
+ {
+ SetNoteFocus(FALSE);
+ PopupNoteItemMenu(point);
+
+ return TRUE;
+ }
+
+ return CPWL_Wnd::OnRButtonUp(point,nFlag);
+}
+
+void CPWL_NoteItem::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ switch (msg)
+ {
+ case PNM_NOTEEDITCHANGED:
+ m_bSizeChanged = TRUE;
+
+ if (CPWL_Wnd* pParent = this->GetParentWindow())
+ {
+ pParent->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
+ }
+ return;
+ case PNM_SETCARETINFO:
+ if (PWL_CARET_INFO * pInfo = (PWL_CARET_INFO*)wParam)
+ {
+ PWL_CARET_INFO newInfo = *pInfo;
+ newInfo.bVisible = TRUE;
+ newInfo.ptHead = this->ChildToParent(pInfo->ptHead);
+ newInfo.ptFoot = this->ChildToParent(pInfo->ptFoot);
+
+ if (CPWL_Wnd * pParent = this->GetParentWindow())
+ {
+ pParent->OnNotify(this, PNM_SETCARETINFO, (FX_INTPTR)&newInfo, 0);
+ }
+ }
+ return;
+ case PNM_NOTERESET:
+ m_bSizeChanged = TRUE;
+ m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
+
+ return;
+ }
+
+ CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
+}
+
+void CPWL_NoteItem::PopupNoteItemMenu(const CPDF_Point& point)
+{
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ FX_INT32 x,y;
+ PWLtoWnd(point, x, y);
+ if (IFX_SystemHandler* pSH = GetSystemHandler())
+ pSH->ClientToScreen(GetAttachedHWnd(), x, y);
+ pNotify->OnPopupMenu(this, x, y);
+ }
+}
+
+const CPWL_Note* CPWL_NoteItem::GetNote() const
+{
+ if (const CPWL_Wnd* pRoot = this->GetRootWnd())
+ {
+ ASSERT(pRoot->GetClassName() == "CPWL_NoteItem");
+ CPWL_NoteItem* pNoteItem = (CPWL_NoteItem*)pRoot;
+ if (pNoteItem->IsTopItem())
+ {
+ return (CPWL_Note*)pNoteItem;
+ }
+ }
+
+ return NULL;
+}
+
+IPWL_NoteNotify* CPWL_NoteItem::GetNoteNotify() const
+{
+ if (const CPWL_Note* pNote = GetNote())
+ return pNote->GetNoteNotify();
+
+ return NULL;
+}
+
+void CPWL_NoteItem::OnCreateNoteItem()
+{
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ pNotify->OnItemCreate(this);
+ }
+}
+
+void CPWL_NoteItem::OnContentsValidate()
+{
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ pNotify->OnSetContents(this);
+ }
+}
+
+void CPWL_NoteItem::SetNoteFocus(FX_BOOL bLast)
+{
+ m_pContents->SetEditFocus(bLast);
+}
+
+void CPWL_NoteItem::EnableModify(FX_BOOL bEnabled)
+{
+ m_pContents->EnableModify(bEnabled);
+ m_bAllowModify = bEnabled;
+}
+
+void CPWL_NoteItem::EnableRead(FX_BOOL bEnabled)
+{
+ m_pContents->EnableRead(bEnabled);
+}
+
+/* ---------------------------------- CPWL_Note ---------------------------------- */
+
+CPWL_Note::CPWL_Note(IPopup_Note* pPopupNote, IPWL_NoteNotify* pNoteNotify, IPWL_NoteHandler* pNoteHandler) :
+ m_pAuthor(NULL),
+ m_pIcon(NULL),
+ m_pCloseBox(NULL),
+ m_pContentsBar(NULL),
+ m_pLBBox(NULL),
+ m_pRBBox(NULL),
+ m_pOptions(NULL),
+ m_bResizing(FALSE),
+ m_rcCaption(0,0,0,0),
+ m_pNoteNotify(pNoteNotify),
+ m_bEnalbleNotify(TRUE),
+ m_pPopupNote(pPopupNote),
+ m_pNoteHandler(pNoteHandler)
+{
+}
+
+CPWL_Note::~CPWL_Note()
+{
+}
+
+IPWL_NoteItem* CPWL_Note::Reply()
+{
+ return CreateNoteItem();
+}
+
+void CPWL_Note::EnableNotify(FX_BOOL bEnabled)
+{
+ m_bEnalbleNotify = bEnabled;
+}
+
+void CPWL_Note::RePosChildWnd()
+{
+ RePosNoteChildren();
+ m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
+ ResetScrollBar();
+ m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
+ this->OnNotify(this, PNM_NOTEEDITCHANGED, 0, 0);
+ //ͬ²½
+ if (const CPWL_Wnd* pWnd = this->GetFocused())
+ {
+ if (pWnd->GetClassName() == "CPWL_Edit")
+ {
+ CPWL_Edit* pEdit = (CPWL_Edit*)pWnd;
+ pEdit->SetCaret(pEdit->GetCaret());
+ }
+ }
+ //CPDF_Point ptNew = m_pContents->GetScrollPos();
+ //m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptNew.y);
+}
+
+FX_BOOL CPWL_Note::ResetScrollBar()
+{
+ FX_BOOL bScrollChanged = FALSE;
+
+ if (ScrollBarShouldVisible())
+ {
+ if (!m_pContentsBar->IsVisible())
+ {
+ m_pContentsBar->SetVisible(TRUE);
+ if (m_pContentsBar->IsVisible())
+ {
+ m_pContentsBar->InvalidateRect(NULL);
+ bScrollChanged = TRUE;
+ }
+ }
+ }
+ else
+ {
+ if (m_pContentsBar->IsVisible())
+ {
+ m_pContentsBar->SetVisible(FALSE);
+ m_pContentsBar->InvalidateRect(NULL);
+
+ bScrollChanged = TRUE;
+ }
+ }
+
+ if (bScrollChanged)
+ {
+ CPDF_Rect rcNote = this->GetClientRect();
+ CPDF_Rect rcContents = m_pContents->GetWindowRect();
+ rcContents.right = rcNote.right - 3.0f;
+ if (m_pContentsBar->IsVisible())
+ rcContents.right -= PWL_SCROLLBAR_WIDTH;
+ m_pContents->Move(rcContents, TRUE, TRUE);
+ m_pContents->SetScrollPos(CPDF_Point(0.0f,0.0f));
+ m_pContents->InvalidateRect(NULL);
+ }
+
+ return bScrollChanged;
+}
+
+FX_BOOL CPWL_Note::ScrollBarShouldVisible()
+{
+ CPDF_Rect rcContentsFact = m_pContents->GetScrollArea();
+ CPDF_Rect rcContentsClient = m_pContents->GetClientRect();
+
+ return rcContentsFact.Height() > rcContentsClient.Height();
+}
+
+void CPWL_Note::SetOptionsText(const CFX_WideString& sText)
+{
+ if (m_pOptions)
+ m_pOptions->SetText(sText);
+
+ RePosNoteChildren();
+}
+
+void CPWL_Note::RePosNoteChildren()
+{
+ if (m_bResizing) return;
+
+ m_bResizing = TRUE;
+
+ if (this->IsValid())
+ {
+ ASSERT(m_pSubject != NULL);
+ ASSERT(m_pDateTime != NULL);
+ ASSERT(m_pContents != NULL);
+ ASSERT(m_pAuthor != NULL);
+ ASSERT(m_pCloseBox != NULL);
+ ASSERT(m_pIcon != NULL);
+ ASSERT(m_pLBBox != NULL);
+ ASSERT(m_pRBBox != NULL);
+ ASSERT(m_pContentsBar != NULL);
+ ASSERT(m_pOptions != NULL);
+
+ CPDF_Rect rcClient = GetClientRect();
+
+ CPDF_Rect rcIcon = rcClient;
+ rcIcon.top -= 2.0f;
+ rcIcon.right = rcIcon.left + 14.0f;
+ rcIcon.bottom = rcIcon.top - 14.0f;
+ rcIcon.Normalize();
+ m_pIcon->Move(rcIcon, TRUE, FALSE);
+ m_pIcon->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcIcon));
+
+ CPDF_Rect rcCloseBox = rcClient;
+ rcCloseBox.right -= 1.0f;
+ rcCloseBox.top -= 1.0f;
+ rcCloseBox.left = rcCloseBox.right - 14.0f;
+ rcCloseBox.bottom = rcCloseBox.top - 14.0f;
+ rcCloseBox.Normalize();
+ m_pCloseBox->Move(rcCloseBox, TRUE, FALSE);
+ m_pCloseBox->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcCloseBox));
+
+ CPDF_Rect rcDate = rcClient;
+ rcDate.right = rcCloseBox.left - POPUP_ITEM_TEXT_INDENT;
+ rcDate.left = PWL_MAX(rcDate.right - m_pDateTime->GetContentRect().Width() - 1.0f, rcIcon.right + 1.0f);
+ rcDate.top = rcClient.top - 2.0f;
+ rcDate.bottom = rcDate.top - m_pDateTime->GetContentRect().Height();
+ rcDate.Normalize();
+ m_pDateTime->Move(rcDate, TRUE, FALSE);
+ m_pDateTime->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcDate));
+
+ CPDF_Rect rcSubject = rcClient;
+ rcSubject.top = rcClient.top - 2.0f;
+ rcSubject.left = rcIcon.right + POPUP_ITEM_TEXT_INDENT;
+ rcSubject.right = PWL_MIN(rcSubject.left + m_pSubject->GetContentRect().Width() + 1.0f, rcDate.left - 1.0f);
+ rcSubject.bottom = rcSubject.top - m_pSubject->GetContentRect().Height();
+ rcSubject.Normalize();
+ m_pSubject->Move(rcSubject, TRUE, FALSE);
+ m_pSubject->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcSubject));
+
+ CPDF_Rect rcOptions = rcClient;
+ rcOptions.left = PWL_MAX(rcOptions.right - m_pOptions->GetContentRect().Width(), rcIcon.right + 1.0f);
+ rcOptions.top = rcSubject.bottom - 4.0f;
+ rcOptions.bottom = rcOptions.top - m_pOptions->GetContentRect().Height();
+ rcOptions.Normalize();
+ m_pOptions->Move(rcOptions, TRUE, FALSE);
+ m_pOptions->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcOptions));
+
+ CPDF_Rect rcAuthor = rcClient;
+ rcAuthor.top = rcSubject.bottom - 4.0f;
+ rcAuthor.left = rcSubject.left;
+ rcAuthor.right = PWL_MIN(rcSubject.left + m_pAuthor->GetContentRect().Width() + 1.0f, rcOptions.left - 1.0f);
+ rcAuthor.bottom = rcAuthor.top - m_pAuthor->GetContentRect().Height();
+ rcAuthor.Normalize();
+ m_pAuthor->Move(rcAuthor, TRUE, FALSE);
+ m_pAuthor->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcAuthor));
+
+ CPDF_Rect rcLBBox = rcClient;
+ rcLBBox.top = rcLBBox.bottom + 7.0f;
+ rcLBBox.right = rcLBBox.left + 7.0f;
+ rcLBBox.Normalize();
+ m_pLBBox->Move(rcLBBox, TRUE, FALSE);
+ m_pLBBox->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcLBBox));
+
+ CPDF_Rect rcRBBox = rcClient;
+ rcRBBox.top = rcRBBox.bottom + 7.0f;
+ rcRBBox.left = rcRBBox.right - 7.0f;
+ rcRBBox.Normalize();
+ m_pRBBox->Move(rcRBBox, TRUE, FALSE);
+ m_pRBBox->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcRBBox));
+
+ CPDF_Rect rcContents = rcClient;
+ rcContents.top = rcAuthor.bottom - POPUP_ITEM_HEAD_BOTTOM;
+ rcContents.left += 3.0f;
+ rcContents.right -= 3.0f;
+ if (m_pContentsBar->IsVisible())
+ rcContents.right -= PWL_SCROLLBAR_WIDTH;
+ rcContents.bottom += 14.0f;
+ rcContents.Normalize();
+ m_pContents->Move(rcContents, FALSE, FALSE);
+ m_pContents->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcContents));
+
+ CPDF_Rect rcContentsBar = rcContents;
+ rcContentsBar.right = rcClient.right - 3.0f;
+ rcContentsBar.left = rcContentsBar.right - PWL_SCROLLBAR_WIDTH;
+ rcContentsBar.Normalize();
+ m_pContentsBar->Move(rcContentsBar, TRUE, FALSE);
+
+ m_rcCaption = rcClient;
+ m_rcCaption.bottom = rcContents.top;
+ }
+
+ m_bResizing = FALSE;
+}
+
+//0-normal / 1-caption / 2-leftbottom corner / 3-rightbottom corner / 4-close / 5-options
+FX_INT32 CPWL_Note::NoteHitTest(const CPDF_Point& point) const
+{
+ ASSERT(m_pSubject != NULL);
+ ASSERT(m_pDateTime != NULL);
+ ASSERT(m_pContents != NULL);
+ ASSERT(m_pAuthor != NULL);
+ ASSERT(m_pIcon != NULL);
+ ASSERT(m_pContentsBar != NULL);
+
+ ASSERT(m_pCloseBox != NULL);
+ ASSERT(m_pLBBox != NULL);
+ ASSERT(m_pRBBox != NULL);
+ ASSERT(m_pOptions != NULL);
+
+ GetClientRect();
+
+ if (m_pSubject->WndHitTest(m_pSubject->ParentToChild(point))) return 1;
+ if (m_pDateTime->WndHitTest(m_pDateTime->ParentToChild(point))) return 1;
+ if (m_pAuthor->WndHitTest(m_pAuthor->ParentToChild(point))) return 1;
+ if (m_pIcon->WndHitTest(m_pIcon->ParentToChild(point))) return 1;
+
+ if (m_pContents->WndHitTest(m_pContents->ParentToChild(point))) return 0;
+ if (m_pContentsBar->WndHitTest(m_pContentsBar->ParentToChild(point))) return 0;
+
+ if (m_pCloseBox->WndHitTest(m_pCloseBox->ParentToChild(point))) return 4;
+ if (m_pLBBox->WndHitTest(m_pLBBox->ParentToChild(point))) return 2;
+ if (m_pRBBox->WndHitTest(m_pRBBox->ParentToChild(point))) return 3;
+ if (m_pOptions->WndHitTest(m_pOptions->ParentToChild(point))) return 5;
+
+ return 1;
+}
+
+void CPWL_Note::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ CPWL_NoteItem::CreateChildWnd(cp);
+
+ CPWL_Color sTextColor;
+
+ if (CPWL_Utils::IsBlackOrWhite(this->GetBackgroundColor()))
+ sTextColor = PWL_DEFAULT_WHITECOLOR;
+ else
+ sTextColor = PWL_DEFAULT_BLACKCOLOR;
+
+ m_pAuthor = new CPWL_Label;
+ PWL_CREATEPARAM acp = cp;
+ acp.pParentWnd = this;
+ acp.dwFlags = PWS_VISIBLE | PWS_CHILD | PES_LEFT | PES_TOP;
+ acp.sTextColor = sTextColor;
+ m_pAuthor->Create(acp);
+
+ m_pCloseBox = new CPWL_Note_CloseBox;
+ PWL_CREATEPARAM ccp = cp;
+ ccp.pParentWnd = this;
+ ccp.dwBorderWidth = 2;
+ ccp.nBorderStyle = PBS_BEVELED;
+ ccp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER;
+ ccp.sTextColor = sTextColor;
+ m_pCloseBox->Create(ccp);
+
+ m_pIcon = new CPWL_Note_Icon;
+ PWL_CREATEPARAM icp = cp;
+ icp.pParentWnd = this;
+ icp.dwFlags = PWS_VISIBLE | PWS_CHILD;
+ m_pIcon->Create(icp);
+
+ m_pOptions = new CPWL_Note_Options;
+ PWL_CREATEPARAM ocp = cp;
+ ocp.pParentWnd = this;
+ ocp.dwFlags = PWS_CHILD | PWS_VISIBLE;
+ ocp.sTextColor = sTextColor;
+ m_pOptions->Create(ocp);
+
+ m_pLBBox = new CPWL_Note_LBBox;
+ PWL_CREATEPARAM lcp = cp;
+ lcp.pParentWnd = this;
+ lcp.dwFlags = PWS_VISIBLE | PWS_CHILD;
+ lcp.eCursorType = FXCT_NESW;
+ lcp.sTextColor = sTextColor;
+ m_pLBBox->Create(lcp);
+
+ m_pRBBox = new CPWL_Note_RBBox;
+ PWL_CREATEPARAM rcp = cp;
+ rcp.pParentWnd = this;
+ rcp.dwFlags = PWS_VISIBLE | PWS_CHILD;
+ rcp.eCursorType = FXCT_NWSE;
+ rcp.sTextColor = sTextColor;
+ m_pRBBox->Create(rcp);
+
+ m_pContentsBar = new CPWL_ScrollBar(SBT_VSCROLL);
+ PWL_CREATEPARAM scp = cp;
+ scp.pParentWnd = this;
+ scp.sBackgroundColor = CPWL_Color(COLORTYPE_RGB, 240/255.0f, 240/255.0f, 240/255.0f);
+ scp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_BACKGROUND;
+ m_pContentsBar->Create(scp);
+ m_pContentsBar->SetNotifyForever(TRUE);
+}
+
+void CPWL_Note::SetSubjectName(const CFX_WideString& sName)
+{
+ CPWL_NoteItem::SetSubjectName(sName);
+ RePosChildWnd();
+}
+
+void CPWL_Note::SetAuthorName(const CFX_WideString& sName)
+{
+ if (m_pAuthor)
+ {
+ m_pAuthor->SetText(sName);
+ RePosChildWnd();
+ }
+
+ if (IPWL_NoteNotify* pNotify = GetNoteNotify())
+ {
+ pNotify->OnSetAuthorName(this);
+ }
+}
+
+CFX_WideString CPWL_Note::GetAuthorName() const
+{
+ if (m_pAuthor)
+ return m_pAuthor->GetText();
+
+ return L"";
+}
+
+FX_BOOL CPWL_Note::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPDF_Point ptScroll = m_pContents->GetScrollPos();
+ CPDF_Rect rcScroll = m_pContents->GetScrollArea();
+ CPDF_Rect rcContents = m_pContents->GetClientRect();
+
+ if (rcScroll.top - rcScroll.bottom > rcContents.Height())
+ {
+ CPDF_Point ptNew = ptScroll;
+
+ if (zDelta > 0)
+ ptNew.y += 30;
+ else
+ ptNew.y -= 30;
+
+ if (ptNew.y > rcScroll.top)
+ ptNew.y = rcScroll.top;
+ if (ptNew.y < rcScroll.bottom + rcContents.Height())
+ ptNew.y = rcScroll.bottom + rcContents.Height();
+ if (ptNew.y < rcScroll.bottom)
+ ptNew.y = rcScroll.bottom;
+
+ if (ptNew.y != ptScroll.y)
+ {
+ m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
+ m_pContents->OnNotify(this, PNM_SCROLLWINDOW, SBT_VSCROLL, (FX_INTPTR)&ptNew.y);
+ m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptNew.y);
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+void CPWL_Note::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ switch (msg)
+ {
+ case PNM_NOTEEDITCHANGED:
+ {
+ CPDF_Rect rcScroll = m_pContents->GetScrollArea();
+
+
+ PWL_SCROLL_INFO sInfo;
+ sInfo.fContentMin = rcScroll.bottom;
+ sInfo.fContentMax = rcScroll.top;
+ sInfo.fPlateWidth = m_pContents->GetClientRect().Height();
+ sInfo.fSmallStep = 13.0f;
+ sInfo.fBigStep = sInfo.fPlateWidth;
+
+ if (FXSYS_memcmp(&m_OldScrollInfo, &sInfo, sizeof(PWL_SCROLL_INFO)) != 0)
+ {
+ FX_BOOL bScrollChanged = FALSE;
+
+ if (lParam < 3) //·ÀÖ¹ËÀÑ­»· mantis:15759
+ {
+ bScrollChanged = ResetScrollBar();
+ if (bScrollChanged)
+ {
+ lParam++;
+ m_pContents->OnNotify(this, PNM_NOTERESET, 0, 0);
+ this->OnNotify(this, PNM_NOTEEDITCHANGED, 0, lParam);
+ }
+ }
+
+ if (!bScrollChanged)
+ {
+ if (m_pContentsBar->IsVisible())
+ {
+ m_pContentsBar->OnNotify(pWnd, PNM_SETSCROLLINFO, SBT_VSCROLL, (FX_INTPTR)&sInfo);
+ m_OldScrollInfo = sInfo;
+
+ CPDF_Point ptScroll = m_pContents->GetScrollPos();
+ CPDF_Point ptOld = ptScroll;
+
+ if (ptScroll.y > sInfo.fContentMax)
+ ptScroll.y = sInfo.fContentMax;
+ if (ptScroll.y < sInfo.fContentMin + sInfo.fPlateWidth)
+ ptScroll.y = sInfo.fContentMin + sInfo.fPlateWidth;
+ if (ptScroll.y < sInfo.fContentMin)
+ ptScroll.y = sInfo.fContentMin;
+
+ if (ptOld.y != ptScroll.y)
+ {
+ m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
+ m_pContentsBar->InvalidateRect(NULL);
+ m_pContents->OnNotify(this, PNM_SCROLLWINDOW, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
+ }
+ }
+ }
+ }
+ }
+
+ m_pContents->InvalidateRect(NULL);
+
+ return;
+ case PNM_SCROLLWINDOW:
+ if (m_pContents)
+ m_pContents->OnNotify(pWnd, msg, wParam, lParam);
+ return;
+ case PNM_SETSCROLLPOS:
+ if (m_pContentsBar)
+ m_pContentsBar->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);
+ return;
+ }
+
+ if (msg == PNM_SETCARETINFO && IsValid())
+ {
+ if (PWL_CARET_INFO * pInfo = (PWL_CARET_INFO*)wParam)
+ {
+ if (m_pContents)
+ {
+ CPDF_Rect rcClient = m_pContents->GetClientRect();
+ if (pInfo->ptHead.y > rcClient.top)
+ {
+ CPDF_Point pt = m_pContents->OutToIn(pInfo->ptHead);
+ m_pContents->OnNotify(this, PNM_SCROLLWINDOW, SBT_VSCROLL, (FX_INTPTR)&pt.y);
+
+ CPDF_Point ptScroll = m_pContents->GetScrollPos();
+ m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
+
+ return;
+ }
+
+ if (pInfo->ptFoot.y < rcClient.bottom)
+ {
+ CPDF_Point pt = m_pContents->OutToIn(pInfo->ptFoot);
+ pt.y += rcClient.Height();
+ m_pContents->OnNotify(this, PNM_SCROLLWINDOW, SBT_VSCROLL, (FX_INTPTR)&pt.y);
+
+ CPDF_Point ptScroll = m_pContents->GetScrollPos();
+ m_pContentsBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (FX_INTPTR)&ptScroll.y);
+
+ return;
+ }
+ }
+ }
+ }
+
+ CPWL_NoteItem::OnNotify(pWnd, msg, wParam, lParam);
+}
+
+void CPWL_Note::SetBkColor(const CPWL_Color& color)
+{
+ CPWL_NoteItem::SetBkColor(color);
+
+ CPWL_Color sBK = color;
+ CPWL_Color sTextColor;
+ if (CPWL_Utils::IsBlackOrWhite(sBK))
+ sTextColor = PWL_DEFAULT_WHITECOLOR;
+ else
+ sTextColor = PWL_DEFAULT_BLACKCOLOR;
+
+ if (m_pCloseBox)
+ m_pCloseBox->SetTextColor(sTextColor);
+ if (m_pAuthor)
+ m_pAuthor->SetTextColor(sTextColor);
+ if (m_pOptions)
+ m_pOptions->SetTextColor(sTextColor);
+ if (m_pLBBox)
+ m_pLBBox->SetTextColor(sTextColor);
+ if (m_pRBBox)
+ m_pRBBox->SetTextColor(sTextColor);
+}
+
+FX_BOOL CPWL_Note::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag)
+{
+ if (m_pOptions->WndHitTest(m_pOptions->ParentToChild(point)))
+ {
+ if (IPWL_NoteNotify* pNotify = this->GetNoteNotify())
+ {
+ FX_INT32 x, y;
+ PWLtoWnd(point, x, y);
+ if (IFX_SystemHandler* pSH = GetSystemHandler())
+ pSH->ClientToScreen(GetAttachedHWnd(), x, y);
+ this->KillFocus();
+ pNotify->OnPopupMenu(x, y);
+
+ return TRUE;
+ }
+ }
+
+ return CPWL_Wnd::OnLButtonDown(point,nFlag);
+}
+
+FX_BOOL CPWL_Note::OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ return CPWL_Wnd::OnRButtonUp(point,nFlag);
+}
+
+const CPWL_Note* CPWL_Note::GetNote() const
+{
+ return this;
+}
+
+IPWL_NoteNotify* CPWL_Note::GetNoteNotify() const
+{
+ if (m_bEnalbleNotify)
+ return m_pNoteNotify;
+
+ return NULL;
+}
+
+void CPWL_Note::SetIconType(FX_INT32 nType)
+{
+ if (m_pIcon)
+ m_pIcon->SetIconType(nType);
+}
+
+void CPWL_Note::EnableModify(FX_BOOL bEnabled)
+{
+ m_pContents->EnableModify(bEnabled);
+}
+
+void CPWL_Note::EnableRead(FX_BOOL bEnabled)
+{
+ m_pContents->EnableRead(bEnabled);
+}
+
+CFX_WideString CPWL_Note::GetReplyString() const
+{
+ return m_sReplyString;
+}
+
+void CPWL_Note::SetReplyString(const CFX_WideString& string)
+{
+ m_sReplyString = string;
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_ScrollBar.cpp b/fpdfsdk/src/pdfwindow/PWL_ScrollBar.cpp
index d51de4db75..772e184902 100644
--- a/fpdfsdk/src/pdfwindow/PWL_ScrollBar.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_ScrollBar.cpp
@@ -1,1353 +1,1353 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_ScrollBar.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-
-#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
-#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
-
-
-/* ------------------------------- PWL_FLOATRANGE ------------------------------- */
-
-PWL_FLOATRANGE::PWL_FLOATRANGE()
-{
- Default();
-}
-
-PWL_FLOATRANGE::PWL_FLOATRANGE(FX_FLOAT min,FX_FLOAT max)
-{
- Set(min,max);
-}
-
-void PWL_FLOATRANGE::Default()
-{
- fMin = 0;
- fMax = 0;
-}
-
-void PWL_FLOATRANGE::Set(FX_FLOAT min,FX_FLOAT max)
-{
- if (min > max)
- {
- fMin = max;
- fMax = min;
- }
- else
- {
- fMin = min;
- fMax = max;
- }
-}
-
-FX_BOOL PWL_FLOATRANGE::In(FX_FLOAT x) const
-{
- return (IsFloatBigger(x,fMin) || IsFloatEqual(x, fMin)) &&
- (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax));
-}
-
-FX_FLOAT PWL_FLOATRANGE::GetWidth() const
-{
- return fMax - fMin;
-}
-
-/* ------------------------------- PWL_SCROLL_PRIVATEDATA ------------------------------- */
-
-PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA()
-{
- Default();
-}
-
-void PWL_SCROLL_PRIVATEDATA::Default()
-{
- ScrollRange.Default();
- fScrollPos = ScrollRange.fMin;
- fClientWidth = 0;
- fBigStep = 10;
- fSmallStep = 1;
-}
-
-void PWL_SCROLL_PRIVATEDATA::SetScrollRange(FX_FLOAT min,FX_FLOAT max)
-{
- ScrollRange.Set(min,max);
-
- if (IsFloatSmaller(fScrollPos, ScrollRange.fMin))
- fScrollPos = ScrollRange.fMin;
- if (IsFloatBigger(fScrollPos, ScrollRange.fMax))
- fScrollPos = ScrollRange.fMax;
-}
-
-void PWL_SCROLL_PRIVATEDATA::SetClientWidth(FX_FLOAT width)
-{
- fClientWidth = width;
-}
-
-void PWL_SCROLL_PRIVATEDATA::SetSmallStep(FX_FLOAT step)
-{
- fSmallStep = step;
-}
-
-void PWL_SCROLL_PRIVATEDATA::SetBigStep(FX_FLOAT step)
-{
- fBigStep = step;
-}
-
-FX_BOOL PWL_SCROLL_PRIVATEDATA::SetPos(FX_FLOAT pos)
-{
- if (ScrollRange.In(pos))
- {
- fScrollPos = pos;
- return TRUE;
- }
- return FALSE;
-}
-
-void PWL_SCROLL_PRIVATEDATA::AddSmall()
-{
- if (!SetPos(fScrollPos + fSmallStep))
- SetPos(ScrollRange.fMax);
-}
-
-void PWL_SCROLL_PRIVATEDATA::SubSmall()
-{
- if (!SetPos(fScrollPos - fSmallStep))
- SetPos(ScrollRange.fMin);
-}
-
-void PWL_SCROLL_PRIVATEDATA::AddBig()
-{
- if (!SetPos(fScrollPos + fBigStep))
- SetPos(ScrollRange.fMax);
-}
-
-void PWL_SCROLL_PRIVATEDATA::SubBig()
-{
- if (!SetPos(fScrollPos - fBigStep))
- SetPos(ScrollRange.fMin);
-}
-
-/* ------------------------------- CPWL_SBButton ------------------------------- */
-
-CPWL_SBButton::CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType,PWL_SBBUTTON_TYPE eButtonType)
-{
- m_eScrollBarType = eScrollBarType;
- m_eSBButtonType = eButtonType;
-
- m_bMouseDown = FALSE;
-}
-
-CPWL_SBButton::~CPWL_SBButton()
-{
-
-}
-
-CFX_ByteString CPWL_SBButton::GetClassName() const
-{
- return "CPWL_SBButton";
-}
-
-void CPWL_SBButton::OnCreate(PWL_CREATEPARAM & cp)
-{
- cp.eCursorType = FXCT_ARROW;
-}
-
-void CPWL_SBButton::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- CPWL_Wnd::GetThisAppearanceStream(sAppStream);
-
- if (!IsVisible()) return;
-
- CFX_ByteTextBuf sButton;
-
- CPDF_Rect rectWnd = GetWindowRect();
-
- if (rectWnd.IsEmpty()) return;
-
- sAppStream << "q\n";
-
- CPDF_Point ptCenter = this->GetCenterPoint();
-
- switch (this->m_eScrollBarType)
- {
- case SBT_HSCROLL:
- switch (this->m_eSBButtonType)
- {
- case PSBT_MIN:
- {
- CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y);
- CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y + PWL_TRIANGLE_HALFLEN);
- CPDF_Point pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y - PWL_TRIANGLE_HALFLEN);
-
- if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
- rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
- {
- sButton << "0 g\n";
- sButton << pt1.x << " " << pt1.y << " m\n";
- sButton << pt2.x << " " << pt2.y << " l\n";
- sButton << pt3.x << " " << pt3.y << " l\n";
- sButton << pt1.x << " " << pt1.y << " l f\n";
-
- sAppStream << sButton;
- }
- }
- break;
- case PSBT_MAX:
- {
- CPDF_Point pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y);
- CPDF_Point pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y + PWL_TRIANGLE_HALFLEN);
- CPDF_Point pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y - PWL_TRIANGLE_HALFLEN);
-
- if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
- rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
- {
- sButton << "0 g\n";
- sButton << pt1.x << " " << pt1.y << " m\n";
- sButton << pt2.x << " " << pt2.y << " l\n";
- sButton << pt3.x << " " << pt3.y << " l\n";
- sButton << pt1.x << " " << pt1.y << " l f\n";
-
- sAppStream << sButton;
- }
- }
- break;
- default:
- break;
- }
- break;
- case SBT_VSCROLL:
- switch(this->m_eSBButtonType)
- {
- case PSBT_MIN:
- {
- CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN,ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f);
- CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN,ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f);
- CPDF_Point pt3(ptCenter.x,ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f);
-
- if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
- rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
- {
- sButton << "0 g\n";
- sButton << pt1.x << " " << pt1.y << " m\n";
- sButton << pt2.x << " " << pt2.y << " l\n";
- sButton << pt3.x << " " << pt3.y << " l\n";
- sButton << pt1.x << " " << pt1.y << " l f\n";
-
- sAppStream << sButton;
- }
- }
- break;
- case PSBT_MAX:
- {
- CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN,ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f);
- CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN,ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f);
- CPDF_Point pt3(ptCenter.x,ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f);
-
- if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
- rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
- {
- sButton << "0 g\n";
- sButton << pt1.x << " " << pt1.y << " m\n";
- sButton << pt2.x << " " << pt2.y << " l\n";
- sButton << pt3.x << " " << pt3.y << " l\n";
- sButton << pt1.x << " " << pt1.y << " l f\n";
-
- sAppStream << sButton;
- }
- }
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-
- sAppStream << "Q\n";
-}
-
-void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- if (!IsVisible()) return;
-
- CPDF_Rect rectWnd = GetWindowRect();
- if (rectWnd.IsEmpty()) return;
-
- CPDF_Point ptCenter = this->GetCenterPoint();
- FX_INT32 nTransparancy = this->GetTransparency();
-
- switch (this->m_eScrollBarType)
- {
- case SBT_HSCROLL:
- CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
- switch (this->m_eSBButtonType)
- {
- case PSBT_MIN:
- {
- CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y);
- CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y + PWL_TRIANGLE_HALFLEN);
- CPDF_Point pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y - PWL_TRIANGLE_HALFLEN);
-
- if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
- rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
- {
- CFX_PathData path;
-
- path.SetPointCount(4);
- path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
- path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
- path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
- path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
-
- pDevice->DrawPath(&path, pUser2Device, NULL,
- CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR,nTransparancy),
- 0, FXFILL_ALTERNATE);
- }
- }
- break;
- case PSBT_MAX:
- {
- CPDF_Point pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y);
- CPDF_Point pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y + PWL_TRIANGLE_HALFLEN);
- CPDF_Point pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y - PWL_TRIANGLE_HALFLEN);
-
- if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
- rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
- {
- CFX_PathData path;
-
- path.SetPointCount(4);
- path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
- path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
- path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
- path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
-
- pDevice->DrawPath(&path, pUser2Device, NULL,
- CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR,nTransparancy),
- 0, FXFILL_ALTERNATE);
- }
- }
- break;
- default:
- break;
- }
- break;
- case SBT_VSCROLL:
- switch(this->m_eSBButtonType)
- {
- case PSBT_MIN:
- {
- //draw border
- CPDF_Rect rcDraw = rectWnd;
- CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
- ArgbEncode(nTransparancy,100,100,100),0.0f);
-
- //draw inner border
- rcDraw = CPWL_Utils::DeflateRect(rectWnd,0.5f);
- CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
- ArgbEncode(nTransparancy,255,255,255),1.0f);
-
- //draw background
-
- rcDraw = CPWL_Utils::DeflateRect(rectWnd,1.0f);
-
- if (this->IsEnabled())
- CPWL_Utils::DrawShadow(pDevice, pUser2Device, TRUE, FALSE, rcDraw, nTransparancy, 80, 220);
- else
- CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, ArgbEncode(255,255,255,255));
-
- //draw arrow
-
- if (rectWnd.top - rectWnd.bottom > 6.0f )
- {
- FX_FLOAT fX = rectWnd.left + 1.5f;
- FX_FLOAT fY = rectWnd.bottom;
- CPDF_Point pts[7] = {
- CPDF_Point(fX+2.5f, fY+4.0f),
- CPDF_Point(fX+2.5f, fY+3.0f),
- CPDF_Point(fX+4.5f, fY+5.0f),
- CPDF_Point(fX+6.5f, fY+3.0f),
- CPDF_Point(fX+6.5f, fY+4.0f),
- CPDF_Point(fX+4.5f, fY+6.0f),
- CPDF_Point(fX+2.5f, fY+4.0f)};
-
-
- if (this->IsEnabled())
- CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7, ArgbEncode(nTransparancy,255,255,255));
- else
- CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7,
- CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_HEAVYGRAYCOLOR,255));
- }
- }
- break;
- case PSBT_MAX:
- {
- //draw border
- CPDF_Rect rcDraw = rectWnd;
- CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
- ArgbEncode(nTransparancy,100,100,100),0.0f);
-
- //draw inner border
- rcDraw = CPWL_Utils::DeflateRect(rectWnd,0.5f);
- CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
- ArgbEncode(nTransparancy,255,255,255),1.0f);
-
- //draw background
- rcDraw = CPWL_Utils::DeflateRect(rectWnd,1.0f);
- if (this->IsEnabled())
- CPWL_Utils::DrawShadow(pDevice, pUser2Device, TRUE, FALSE, rcDraw, nTransparancy, 80, 220);
- else
- CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, ArgbEncode(255,255,255,255));
-
- //draw arrow
-
- if (rectWnd.top - rectWnd.bottom > 6.0f )
- {
- FX_FLOAT fX = rectWnd.left + 1.5f;
- FX_FLOAT fY = rectWnd.bottom;
-
- CPDF_Point pts[7] = {
- CPDF_Point(fX+2.5f, fY+5.0f),
- CPDF_Point(fX+2.5f, fY+6.0f),
- CPDF_Point(fX+4.5f, fY+4.0f),
- CPDF_Point(fX+6.5f, fY+6.0f),
- CPDF_Point(fX+6.5f, fY+5.0f),
- CPDF_Point(fX+4.5f, fY+3.0f),
- CPDF_Point(fX+2.5f, fY+5.0f)};
-
-
- if (this->IsEnabled())
- CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7, ArgbEncode(nTransparancy,255,255,255));
- else
- CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7,
- CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_HEAVYGRAYCOLOR,255));
- }
- }
- break;
- case PSBT_POS:
- {
- //CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
-
- //draw border
- CPDF_Rect rcDraw = rectWnd;
- CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
- ArgbEncode(nTransparancy,100,100,100),0.0f);
-
- //draw inner border
- rcDraw = CPWL_Utils::DeflateRect(rectWnd,0.5f);
- CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
- ArgbEncode(nTransparancy,255,255,255),1.0f);
-
- if (this->IsEnabled())
- {
- //draw shadow effect
-
- CPDF_Point ptTop = CPDF_Point(rectWnd.left,rectWnd.top-1.0f);
- CPDF_Point ptBottom = CPDF_Point(rectWnd.left,rectWnd.bottom+1.0f);
-
- ptTop.x += 1.5f;
- ptBottom.x += 1.5f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,210,210,210),1.0f);
-
- ptTop.x += 1.0f;
- ptBottom.x += 1.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,220,220,220),1.0f);
-
- ptTop.x += 1.0f;
- ptBottom.x += 1.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,240,240,240),1.0f);
-
- ptTop.x += 1.0f;
- ptBottom.x += 1.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,240,240,240),1.0f);
-
- ptTop.x += 1.0f;
- ptBottom.x += 1.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,210,210,210),1.0f);
-
- ptTop.x += 1.0f;
- ptBottom.x += 1.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,180,180,180),1.0f);
-
- ptTop.x += 1.0f;
- ptBottom.x += 1.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,150,150,150),1.0f);
-
- ptTop.x += 1.0f;
- ptBottom.x += 1.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,150,150,150),1.0f);
-
- ptTop.x += 1.0f;
- ptBottom.x += 1.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,180,180,180),1.0f);
-
- ptTop.x += 1.0f;
- ptBottom.x += 1.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
- ArgbEncode(nTransparancy,210,210,210),1.0f);
- }
- else
- {
- CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, ArgbEncode(255,255,255,255));
- }
-
- //draw friction
-
- if (rectWnd.Height() > 8.0f)
- {
- FX_COLORREF crStroke = ArgbEncode(nTransparancy,120,120,120);
- if (!this->IsEnabled())
- crStroke = CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_HEAVYGRAYCOLOR,255);
-
- FX_FLOAT nFrictionWidth = 5.0f;
- FX_FLOAT nFrictionHeight = 5.5f;
-
- CPDF_Point ptLeft = CPDF_Point(ptCenter.x - nFrictionWidth / 2.0f, ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
- CPDF_Point ptRight = CPDF_Point(ptCenter.x + nFrictionWidth / 2.0f, ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
- crStroke,1.0f);
-
- ptLeft.y += 2.0f;
- ptRight.y += 2.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
- crStroke,1.0f);
-
- ptLeft.y += 2.0f;
- ptRight.y += 2.0f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
- crStroke,1.0f);
-
- /*
- ptLeft.y += 1.5f;
- ptRight.y += 1.5f;
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
- ArgbEncode(nTransparancy,150,150,150),1.0f);
- */
- }
- }
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-}
-
-FX_BOOL CPWL_SBButton::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonDown(point,nFlag);
-
- if (CPWL_Wnd * pParent = GetParentWindow())
- pParent->OnNotify(this,PNM_LBUTTONDOWN,0,(FX_INTPTR)&point);
-
- m_bMouseDown = TRUE;
- SetCapture();
-
- return TRUE;
-}
-
-FX_BOOL CPWL_SBButton::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonUp(point,nFlag);
-
- if (CPWL_Wnd * pParent = GetParentWindow())
- pParent->OnNotify(this,PNM_LBUTTONUP,0,(FX_INTPTR)&point);
-
- m_bMouseDown = FALSE;
- ReleaseCapture();
-
- return TRUE;
-}
-
-FX_BOOL CPWL_SBButton::OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnMouseMove(point,nFlag);
-
- if (CPWL_Wnd * pParent = GetParentWindow())
- {
- pParent->OnNotify(this,PNM_MOUSEMOVE,0,(FX_INTPTR)&point);
-
- /*
- if (m_bMouseDown && (m_eSBButtonType == PSBT_MIN || m_eSBButtonType == PSBT_MAX))
- {
- if (!pParent->OnNotify(this,PNM_LBUTTONDOWN,nFlags,(FX_INTPTR)&point))
- return FALSE;
- }
- */
- }
-
- return TRUE;
-}
-
-/* ------------------------------- CPWL_ScrollBar ---------------------------------- */
-
-CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType):
- m_sbType(sbType),
- m_pMinButton(NULL),
- m_pMaxButton(NULL),
- m_pPosButton(NULL),
- m_bMouseDown(FALSE),
- m_bMinOrMax(FALSE),
- m_bNotifyForever(TRUE)
-{
-}
-
-CPWL_ScrollBar::~CPWL_ScrollBar()
-{
-}
-
-CFX_ByteString CPWL_ScrollBar::GetClassName() const
-{
- return "CPWL_ScrollBar";
-}
-
-void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM & cp)
-{
- cp.eCursorType = FXCT_ARROW;
-}
-
-void CPWL_ScrollBar::RePosChildWnd()
-{
- CPDF_Rect rcClient = this->GetClientRect();
-
-/*
- switch(m_sbType)
- {
- case SBT_HSCROLL:
- if (rcClient.right - rcClient.left < PWL_SCROLLBAR_WIDTH ||
- rcClient.top - rcClient.bottom < PWL_SCROLLBAR_WIDTH)
- {
- SetVisible(FALSE);
- }
- break;
- case SBT_VSCROLL:
- if (rcClient.right - rcClient.left < PWL_SCROLLBAR_WIDTH ||
- rcClient.top - rcClient.bottom < PWL_SCROLLBAR_WIDTH)
- {
- SetVisible(FALSE);
- }
- break;
- }
-*/
- CPDF_Rect rcMinButton,rcMaxButton;
-
- FX_FLOAT fBWidth = 0;
-
- switch (m_sbType)
- {
- case SBT_HSCROLL:
- if (rcClient.right - rcClient.left > PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2)
- {
- rcMinButton = CPDF_Rect(rcClient.left,rcClient.bottom,
- rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH,rcClient.top);
- rcMaxButton = CPDF_Rect(rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH,rcClient.bottom,
- rcClient.right,rcClient.top);
- }
- else
- {
- fBWidth = (rcClient.right - rcClient.left - PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / 2;
-
- if (fBWidth > 0)
- {
- rcMinButton = CPDF_Rect(rcClient.left,rcClient.bottom,
- rcClient.left + fBWidth,rcClient.top);
- rcMaxButton = CPDF_Rect(rcClient.right - fBWidth,rcClient.bottom,
- rcClient.right,rcClient.top);
- }
- else SetVisible(FALSE);
- }
- break;
- case SBT_VSCROLL:
- if (IsFloatBigger(rcClient.top - rcClient.bottom, PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2))
- {
- rcMinButton = CPDF_Rect(rcClient.left,rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH,
- rcClient.right,rcClient.top);
- rcMaxButton = CPDF_Rect(rcClient.left,rcClient.bottom,
- rcClient.right,rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH);
- }
- else
- {
- fBWidth = (rcClient.top - rcClient.bottom - PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / 2;
-
- if (IsFloatBigger(fBWidth, 0))
- {
- rcMinButton = CPDF_Rect(rcClient.left,rcClient.top - fBWidth,
- rcClient.right,rcClient.top);
- rcMaxButton = CPDF_Rect(rcClient.left,rcClient.bottom,
- rcClient.right,rcClient.bottom + fBWidth);
- }
- else SetVisible(FALSE);
- }
- break;
- }
-
-// if (IsVisible())
- {
- if (m_pMinButton)
- m_pMinButton->Move(rcMinButton,TRUE,FALSE);
-
- if (m_pMaxButton)
- m_pMaxButton->Move(rcMaxButton,TRUE,FALSE);
-
- MovePosButton(FALSE);
- }
-}
-
-void CPWL_ScrollBar::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- CPDF_Rect rectWnd = GetWindowRect();
-
- if (IsVisible() && !rectWnd.IsEmpty())
- {
- CFX_ByteTextBuf sButton;
-
- sButton << "q\n";
- sButton << "0 w\n" << CPWL_Utils::GetColorAppStream(GetBackgroundColor(),TRUE);
- sButton << rectWnd.left << " " << rectWnd.bottom << " "
- << rectWnd.right - rectWnd.left << " " << rectWnd.top - rectWnd.bottom << " re b Q\n";
-
- sAppStream << sButton;
- }
-}
-
-void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
-// CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
- CPDF_Rect rectWnd = GetWindowRect();
-
- if (IsVisible() && !rectWnd.IsEmpty())
- {
- CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rectWnd, this->GetBackgroundColor(), GetTransparency());
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device,
- CPDF_Point(rectWnd.left+2.0f,rectWnd.top-2.0f), CPDF_Point(rectWnd.left+2.0f,rectWnd.bottom+2.0f),
- ArgbEncode(this->GetTransparency(),100,100,100),1.0f);
-
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device,
- CPDF_Point(rectWnd.right-2.0f,rectWnd.top-2.0f), CPDF_Point(rectWnd.right-2.0f,rectWnd.bottom+2.0f),
- ArgbEncode(this->GetTransparency(),100,100,100),1.0f);
- }
-}
-
-FX_BOOL CPWL_ScrollBar::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonDown(point,nFlag);
-
- //SetFocus();
-
- if (HasFlag(PWS_AUTOTRANSPARENT))
- {
- if (GetTransparency() != 255)
- {
- SetTransparency(255);
- InvalidateRect();
- }
- }
-
- CPDF_Rect rcMinArea,rcMaxArea;
-
- if (m_pPosButton && m_pPosButton->IsVisible())
- {
- CPDF_Rect rcClient = this->GetClientRect();
- CPDF_Rect rcPosButton = m_pPosButton->GetWindowRect();
-
- switch (m_sbType)
- {
- case SBT_HSCROLL:
- rcMinArea = CPDF_Rect(rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH,rcClient.bottom,
- rcPosButton.left,rcClient.top);
- rcMaxArea = CPDF_Rect(rcPosButton.right,rcClient.bottom,
- rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH,rcClient.top);
-
- break;
- case SBT_VSCROLL:
- rcMinArea = CPDF_Rect(rcClient.left,rcPosButton.top,
- rcClient.right,rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH);
- rcMaxArea = CPDF_Rect(rcClient.left,rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH,
- rcClient.right,rcPosButton.bottom);
- break;
- }
-
- rcMinArea.Normalize();
- rcMaxArea.Normalize();
-
- if (rcMinArea.Contains(point.x,point.y))
- {
- m_sData.SubBig();
- MovePosButton(TRUE);
- NotifyScrollWindow();
- }
-
- if (rcMaxArea.Contains(point.x,point.y))
- {
- m_sData.AddBig();
- MovePosButton(TRUE);
- NotifyScrollWindow();
- }
- }
-
- return TRUE;
-}
-
-FX_BOOL CPWL_ScrollBar::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
-{
- CPWL_Wnd::OnLButtonUp(point,nFlag);
-
- if (HasFlag(PWS_AUTOTRANSPARENT))
- {
- if (GetTransparency() != PWL_SCROLLBAR_TRANSPARANCY)
- {
- SetTransparency(PWL_SCROLLBAR_TRANSPARANCY);
- InvalidateRect();
- }
- }
-
- EndTimer();
- m_bMouseDown = FALSE;
-
- return TRUE;
-}
-
-void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
-
- switch (msg)
- {
- case PNM_LBUTTONDOWN:
- if (pWnd == m_pMinButton)
- {
- OnMinButtonLBDown(*(CPDF_Point*)lParam);
- }
-
- if (pWnd == m_pMaxButton)
- {
- OnMaxButtonLBDown(*(CPDF_Point*)lParam);
- }
-
- if (pWnd == m_pPosButton)
- {
- OnPosButtonLBDown(*(CPDF_Point*)lParam);
- }
- break;
- case PNM_LBUTTONUP:
- if (pWnd == m_pMinButton)
- {
- OnMinButtonLBUp(*(CPDF_Point*)lParam);
- }
-
- if (pWnd == m_pMaxButton)
- {
- OnMaxButtonLBUp(*(CPDF_Point*)lParam);
- }
-
- if (pWnd == m_pPosButton)
- {
- OnPosButtonLBUp(*(CPDF_Point*)lParam);
- }
- break;
- case PNM_MOUSEMOVE:
- if (pWnd == m_pMinButton)
- {
- OnMinButtonMouseMove(*(CPDF_Point*)lParam);
- }
-
- if (pWnd == m_pMaxButton)
- {
- OnMaxButtonMouseMove(*(CPDF_Point*)lParam);
- }
-
- if (pWnd == m_pPosButton)
- {
- OnPosButtonMouseMove(*(CPDF_Point*)lParam);
- }
- break;
- case PNM_SETSCROLLINFO:
- {
- if (PWL_SCROLL_INFO * pInfo = (PWL_SCROLL_INFO*)lParam)
- {
- if (FXSYS_memcmp(&m_OriginInfo, pInfo, sizeof(PWL_SCROLL_INFO)) != 0)
- {
- m_OriginInfo = *pInfo;
- FX_FLOAT fMax = pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth;
- fMax = fMax > 0.0f ? fMax : 0.0f;
- this->SetScrollRange(0,fMax, pInfo->fPlateWidth);
- this->SetScrollStep(pInfo->fBigStep,pInfo->fSmallStep);
- }
- }
- }
- break;
- case PNM_SETSCROLLPOS:
- {
- FX_FLOAT fPos = *(FX_FLOAT*)lParam;
- switch (this->m_sbType)
- {
- case SBT_HSCROLL:
- fPos = fPos - m_OriginInfo.fContentMin;
- break;
- case SBT_VSCROLL:
- fPos = m_OriginInfo.fContentMax - fPos;
- break;
- }
- this->SetScrollPos(fPos);
- }
- break;
- }
-}
-
-void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM & cp)
-{
- PWL_CREATEPARAM scp = cp;
- scp.pParentWnd = this;
- scp.dwBorderWidth = 2;
- scp.nBorderStyle = PBS_BEVELED;
-
- scp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP;
-
- if (!m_pMinButton)
- {
- m_pMinButton = new CPWL_SBButton(m_sbType,PSBT_MIN);
- m_pMinButton->Create(scp);
- }
-
- if (!m_pMaxButton)
- {
- m_pMaxButton = new CPWL_SBButton(m_sbType,PSBT_MAX);
- m_pMaxButton->Create(scp);
- }
-
- if (!m_pPosButton)
- {
- m_pPosButton = new CPWL_SBButton(m_sbType,PSBT_POS);
- m_pPosButton->SetVisible(FALSE);
- m_pPosButton->Create(scp);
- }
-}
-
-FX_FLOAT CPWL_ScrollBar::GetScrollBarWidth() const
-{
- if (!IsVisible()) return 0;
-
- return PWL_SCROLLBAR_WIDTH;
-}
-
-void CPWL_ScrollBar::SetScrollRange(FX_FLOAT fMin,FX_FLOAT fMax,FX_FLOAT fClientWidth)
-{
- if (m_pPosButton)
- {
- m_sData.SetScrollRange(fMin,fMax);
- m_sData.SetClientWidth(fClientWidth);
-
- if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f))
- {
- m_pPosButton->SetVisible(FALSE);
- }
- else
- {
- m_pPosButton->SetVisible(TRUE);
- MovePosButton(TRUE);
- }
- }
-}
-
-void CPWL_ScrollBar::SetScrollPos(FX_FLOAT fPos)
-{
- FX_FLOAT fOldPos = m_sData.fScrollPos;
-
- m_sData.SetPos(fPos);
-
- if (!IsFloatEqual(m_sData.fScrollPos, fOldPos))
- MovePosButton(TRUE);
-}
-
-void CPWL_ScrollBar::SetScrollStep(FX_FLOAT fBigStep,FX_FLOAT fSmallStep)
-{
- m_sData.SetBigStep(fBigStep);
- m_sData.SetSmallStep(fSmallStep);
-}
-
-void CPWL_ScrollBar::MovePosButton(FX_BOOL bRefresh)
-{
- ASSERT (m_pPosButton != NULL);
- ASSERT (m_pMinButton != NULL);
- ASSERT (m_pMaxButton != NULL);
-
- if (m_pPosButton->IsVisible())
- {
-
-
-
-
- CPDF_Rect rcClient;
- CPDF_Rect rcPosArea,rcPosButton;
-
- rcClient = this->GetClientRect();
- rcPosArea = GetScrollArea();
-
- FX_FLOAT fLeft,fRight,fTop,fBottom;
-
- switch (m_sbType)
- {
- case SBT_HSCROLL:
- fLeft = TrueToFace(m_sData.fScrollPos);
- fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth);
-
- if (fRight - fLeft < PWL_SCROLLBAR_POSBUTTON_MINWIDTH)
- fRight = fLeft + PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
-
- if (fRight > rcPosArea.right)
- {
- fRight = rcPosArea.right;
- fLeft = fRight - PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
- }
-
- rcPosButton = CPDF_Rect(fLeft ,
- rcPosArea.bottom,
- fRight ,
- rcPosArea.top);
-
- break;
- case SBT_VSCROLL:
- fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth);
- fTop = TrueToFace(m_sData.fScrollPos);
-
- if (IsFloatSmaller(fTop - fBottom, PWL_SCROLLBAR_POSBUTTON_MINWIDTH))
- fBottom = fTop - PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
-
- if (IsFloatSmaller(fBottom, rcPosArea.bottom))
- {
- fBottom = rcPosArea.bottom;
- fTop = fBottom + PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
- }
-
- rcPosButton = CPDF_Rect(rcPosArea.left,
- fBottom,
- rcPosArea.right,
- fTop);
-
- break;
- }
-
- m_pPosButton->Move(rcPosButton,TRUE,bRefresh);
- }
-}
-
-void CPWL_ScrollBar::OnMinButtonLBDown(const CPDF_Point & point)
-{
- m_sData.SubSmall();
- MovePosButton(TRUE);
- NotifyScrollWindow();
-
- m_bMinOrMax = TRUE;
-
- EndTimer();
- BeginTimer(100);
-}
-
-void CPWL_ScrollBar::OnMinButtonLBUp(const CPDF_Point & point)
-{
-}
-
-void CPWL_ScrollBar::OnMinButtonMouseMove(const CPDF_Point & point)
-{
-}
-
-void CPWL_ScrollBar::OnMaxButtonLBDown(const CPDF_Point & point)
-{
- m_sData.AddSmall();
- MovePosButton(TRUE);
- NotifyScrollWindow();
-
- m_bMinOrMax = FALSE;
-
- EndTimer();
- BeginTimer(100);
-}
-
-void CPWL_ScrollBar::OnMaxButtonLBUp(const CPDF_Point & point)
-{
-}
-
-void CPWL_ScrollBar::OnMaxButtonMouseMove(const CPDF_Point & point)
-{
-}
-
-void CPWL_ScrollBar::OnPosButtonLBDown(const CPDF_Point & point)
-{
- m_bMouseDown = TRUE;
-
- if (m_pPosButton)
- {
- CPDF_Rect rcPosButton = m_pPosButton->GetWindowRect();
-
- switch(m_sbType)
- {
- case SBT_HSCROLL:
- m_nOldPos = point.x;
- m_fOldPosButton = rcPosButton.left;
- break;
- case SBT_VSCROLL:
- m_nOldPos = point.y;
- m_fOldPosButton = rcPosButton.top;
- break;
- }
- }
-}
-
-void CPWL_ScrollBar::OnPosButtonLBUp(const CPDF_Point & point)
-{
- if (m_bMouseDown)
- {
- if (!m_bNotifyForever)
- NotifyScrollWindow();
- }
- m_bMouseDown = FALSE;
-}
-
-void CPWL_ScrollBar::OnPosButtonMouseMove(const CPDF_Point & point)
-{
- FX_FLOAT fOldScrollPos = m_sData.fScrollPos;
-
- FX_FLOAT fNewPos = 0;
-
- switch (m_sbType)
- {
- case SBT_HSCROLL:
- if (FXSYS_fabs(point.x - m_nOldPos) < 1) return;
- fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos);
- break;
- case SBT_VSCROLL:
- if (FXSYS_fabs(point.y - m_nOldPos) < 1) return;
- fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos);
- break;
- }
-
- if (m_bMouseDown)
- {
- switch (m_sbType)
- {
- case SBT_HSCROLL:
-
- if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin))
- {
- fNewPos = m_sData.ScrollRange.fMin;
- }
-
- if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax))
- {
- fNewPos = m_sData.ScrollRange.fMax;
- }
-
- m_sData.SetPos(fNewPos);
-
- break;
- case SBT_VSCROLL:
-
- if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin))
- {
- fNewPos = m_sData.ScrollRange.fMin;
- }
-
- if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax))
- {
- fNewPos = m_sData.ScrollRange.fMax;
- }
-
- m_sData.SetPos(fNewPos);
-
- break;
- }
-
- if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos))
- {
- MovePosButton(TRUE);
-
- if (m_bNotifyForever)
- NotifyScrollWindow();
- }
- }
-}
-
-void CPWL_ScrollBar::NotifyScrollWindow()
-{
- if (CPWL_Wnd * pParent = this->GetParentWindow())
- {
- FX_FLOAT fPos;
- switch (this->m_sbType)
- {
- case SBT_HSCROLL:
- fPos = m_OriginInfo.fContentMin + m_sData.fScrollPos;
- break;
- case SBT_VSCROLL:
- fPos = m_OriginInfo.fContentMax - m_sData.fScrollPos;
- break;
- }
- pParent->OnNotify(this,PNM_SCROLLWINDOW,(FX_INTPTR)m_sbType,(FX_INTPTR)&fPos);
- }
-}
-
-CPDF_Rect CPWL_ScrollBar::GetScrollArea() const
-{
- CPDF_Rect rcClient = GetClientRect();
- CPDF_Rect rcArea;
-
- if (!m_pMinButton || !m_pMaxButton)return rcClient;
-
- CPDF_Rect rcMin = m_pMinButton->GetWindowRect();
- CPDF_Rect rcMax = m_pMaxButton->GetWindowRect();
-
- FX_FLOAT fMinWidth = rcMin.right - rcMin.left;
- FX_FLOAT fMinHeight = rcMin.top - rcMin.bottom;
- FX_FLOAT fMaxWidth = rcMax.right - rcMax.left;
- FX_FLOAT fMaxHeight = rcMax.top - rcMax.bottom;
-
- switch(m_sbType)
- {
- case SBT_HSCROLL:
- if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2)
- {
- rcArea = CPDF_Rect(rcClient.left + fMinWidth + 1,rcClient.bottom,
- rcClient.right - fMaxWidth - 1,rcClient.top);
- }
- else
- {
- rcArea = CPDF_Rect(rcClient.left + fMinWidth + 1,rcClient.bottom,
- rcClient.left + fMinWidth + 1,rcClient.top);
- }
- break;
- case SBT_VSCROLL:
- if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2)
- {
- rcArea = CPDF_Rect(rcClient.left,rcClient.bottom + fMinHeight + 1,
- rcClient.right,rcClient.top - fMaxHeight - 1);
- }
- else
- {
- rcArea = CPDF_Rect(rcClient.left,rcClient.bottom + fMinHeight + 1,
- rcClient.right,rcClient.bottom + fMinHeight + 1);
- }
- break;
- }
-
- rcArea.Normalize();
-
- return rcArea;
-}
-
-FX_FLOAT CPWL_ScrollBar::TrueToFace(FX_FLOAT fTrue)
-{
- CPDF_Rect rcPosArea;
- rcPosArea = GetScrollArea();
-
- FX_FLOAT fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth;
- fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
-
- FX_FLOAT fFace = 0;
-
- switch(m_sbType)
- {
- case SBT_HSCROLL:
- fFace = rcPosArea.left + fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth;
- break;
- case SBT_VSCROLL:
- fFace = rcPosArea.top - fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth;
- break;
- }
-
- return fFace;
-}
-
-FX_FLOAT CPWL_ScrollBar::FaceToTrue(FX_FLOAT fFace)
-{
- CPDF_Rect rcPosArea;
- rcPosArea = GetScrollArea();
-
- FX_FLOAT fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth;
- fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
-
- FX_FLOAT fTrue = 0;
-
- switch(m_sbType)
- {
- case SBT_HSCROLL:
- fTrue = (fFace - rcPosArea.left) * fFactWidth / (rcPosArea.right - rcPosArea.left);
- break;
- case SBT_VSCROLL:
- fTrue = (rcPosArea.top - fFace) * fFactWidth / (rcPosArea.top - rcPosArea.bottom);
- break;
- }
-
- return fTrue;
-}
-
-void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- CreateButtons(cp);
-}
-
-void CPWL_ScrollBar::TimerProc()
-{
- PWL_SCROLL_PRIVATEDATA sTemp = m_sData;
-
- if (m_bMinOrMax)m_sData.SubSmall();
- else m_sData.AddSmall();
-
- if (FXSYS_memcmp(&m_sData, &sTemp, sizeof(PWL_SCROLL_PRIVATEDATA)) != 0)
- {
- MovePosButton(TRUE);
- NotifyScrollWindow();
- }
-}
-
-/*
-void CPWL_ScrollBar::OnSetFocus()
-{
- if (GetTransparency() != 255)
- {
- SetTransparency(255);
- InvalidateRect();
- }
-}
-
-void CPWL_ScrollBar::OnKillFocus()
-{
- if (GetTransparency() != PWL_SCROLLBAR_TRANSPARANCY)
- {
- SetTransparency(PWL_SCROLLBAR_TRANSPARANCY);
- InvalidateRect();
- }
-}
-*/
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_ScrollBar.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
+#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
+
+
+/* ------------------------------- PWL_FLOATRANGE ------------------------------- */
+
+PWL_FLOATRANGE::PWL_FLOATRANGE()
+{
+ Default();
+}
+
+PWL_FLOATRANGE::PWL_FLOATRANGE(FX_FLOAT min,FX_FLOAT max)
+{
+ Set(min,max);
+}
+
+void PWL_FLOATRANGE::Default()
+{
+ fMin = 0;
+ fMax = 0;
+}
+
+void PWL_FLOATRANGE::Set(FX_FLOAT min,FX_FLOAT max)
+{
+ if (min > max)
+ {
+ fMin = max;
+ fMax = min;
+ }
+ else
+ {
+ fMin = min;
+ fMax = max;
+ }
+}
+
+FX_BOOL PWL_FLOATRANGE::In(FX_FLOAT x) const
+{
+ return (IsFloatBigger(x,fMin) || IsFloatEqual(x, fMin)) &&
+ (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax));
+}
+
+FX_FLOAT PWL_FLOATRANGE::GetWidth() const
+{
+ return fMax - fMin;
+}
+
+/* ------------------------------- PWL_SCROLL_PRIVATEDATA ------------------------------- */
+
+PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA()
+{
+ Default();
+}
+
+void PWL_SCROLL_PRIVATEDATA::Default()
+{
+ ScrollRange.Default();
+ fScrollPos = ScrollRange.fMin;
+ fClientWidth = 0;
+ fBigStep = 10;
+ fSmallStep = 1;
+}
+
+void PWL_SCROLL_PRIVATEDATA::SetScrollRange(FX_FLOAT min,FX_FLOAT max)
+{
+ ScrollRange.Set(min,max);
+
+ if (IsFloatSmaller(fScrollPos, ScrollRange.fMin))
+ fScrollPos = ScrollRange.fMin;
+ if (IsFloatBigger(fScrollPos, ScrollRange.fMax))
+ fScrollPos = ScrollRange.fMax;
+}
+
+void PWL_SCROLL_PRIVATEDATA::SetClientWidth(FX_FLOAT width)
+{
+ fClientWidth = width;
+}
+
+void PWL_SCROLL_PRIVATEDATA::SetSmallStep(FX_FLOAT step)
+{
+ fSmallStep = step;
+}
+
+void PWL_SCROLL_PRIVATEDATA::SetBigStep(FX_FLOAT step)
+{
+ fBigStep = step;
+}
+
+FX_BOOL PWL_SCROLL_PRIVATEDATA::SetPos(FX_FLOAT pos)
+{
+ if (ScrollRange.In(pos))
+ {
+ fScrollPos = pos;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void PWL_SCROLL_PRIVATEDATA::AddSmall()
+{
+ if (!SetPos(fScrollPos + fSmallStep))
+ SetPos(ScrollRange.fMax);
+}
+
+void PWL_SCROLL_PRIVATEDATA::SubSmall()
+{
+ if (!SetPos(fScrollPos - fSmallStep))
+ SetPos(ScrollRange.fMin);
+}
+
+void PWL_SCROLL_PRIVATEDATA::AddBig()
+{
+ if (!SetPos(fScrollPos + fBigStep))
+ SetPos(ScrollRange.fMax);
+}
+
+void PWL_SCROLL_PRIVATEDATA::SubBig()
+{
+ if (!SetPos(fScrollPos - fBigStep))
+ SetPos(ScrollRange.fMin);
+}
+
+/* ------------------------------- CPWL_SBButton ------------------------------- */
+
+CPWL_SBButton::CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType,PWL_SBBUTTON_TYPE eButtonType)
+{
+ m_eScrollBarType = eScrollBarType;
+ m_eSBButtonType = eButtonType;
+
+ m_bMouseDown = FALSE;
+}
+
+CPWL_SBButton::~CPWL_SBButton()
+{
+
+}
+
+CFX_ByteString CPWL_SBButton::GetClassName() const
+{
+ return "CPWL_SBButton";
+}
+
+void CPWL_SBButton::OnCreate(PWL_CREATEPARAM & cp)
+{
+ cp.eCursorType = FXCT_ARROW;
+}
+
+void CPWL_SBButton::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ CPWL_Wnd::GetThisAppearanceStream(sAppStream);
+
+ if (!IsVisible()) return;
+
+ CFX_ByteTextBuf sButton;
+
+ CPDF_Rect rectWnd = GetWindowRect();
+
+ if (rectWnd.IsEmpty()) return;
+
+ sAppStream << "q\n";
+
+ CPDF_Point ptCenter = this->GetCenterPoint();
+
+ switch (this->m_eScrollBarType)
+ {
+ case SBT_HSCROLL:
+ switch (this->m_eSBButtonType)
+ {
+ case PSBT_MIN:
+ {
+ CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y);
+ CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y + PWL_TRIANGLE_HALFLEN);
+ CPDF_Point pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y - PWL_TRIANGLE_HALFLEN);
+
+ if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
+ rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
+ {
+ sButton << "0 g\n";
+ sButton << pt1.x << " " << pt1.y << " m\n";
+ sButton << pt2.x << " " << pt2.y << " l\n";
+ sButton << pt3.x << " " << pt3.y << " l\n";
+ sButton << pt1.x << " " << pt1.y << " l f\n";
+
+ sAppStream << sButton;
+ }
+ }
+ break;
+ case PSBT_MAX:
+ {
+ CPDF_Point pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y);
+ CPDF_Point pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y + PWL_TRIANGLE_HALFLEN);
+ CPDF_Point pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y - PWL_TRIANGLE_HALFLEN);
+
+ if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
+ rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
+ {
+ sButton << "0 g\n";
+ sButton << pt1.x << " " << pt1.y << " m\n";
+ sButton << pt2.x << " " << pt2.y << " l\n";
+ sButton << pt3.x << " " << pt3.y << " l\n";
+ sButton << pt1.x << " " << pt1.y << " l f\n";
+
+ sAppStream << sButton;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ case SBT_VSCROLL:
+ switch(this->m_eSBButtonType)
+ {
+ case PSBT_MIN:
+ {
+ CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN,ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f);
+ CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN,ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f);
+ CPDF_Point pt3(ptCenter.x,ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f);
+
+ if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
+ rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
+ {
+ sButton << "0 g\n";
+ sButton << pt1.x << " " << pt1.y << " m\n";
+ sButton << pt2.x << " " << pt2.y << " l\n";
+ sButton << pt3.x << " " << pt3.y << " l\n";
+ sButton << pt1.x << " " << pt1.y << " l f\n";
+
+ sAppStream << sButton;
+ }
+ }
+ break;
+ case PSBT_MAX:
+ {
+ CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN,ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f);
+ CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN,ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f);
+ CPDF_Point pt3(ptCenter.x,ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f);
+
+ if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
+ rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
+ {
+ sButton << "0 g\n";
+ sButton << pt1.x << " " << pt1.y << " m\n";
+ sButton << pt2.x << " " << pt2.y << " l\n";
+ sButton << pt3.x << " " << pt3.y << " l\n";
+ sButton << pt1.x << " " << pt1.y << " l f\n";
+
+ sAppStream << sButton;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ sAppStream << "Q\n";
+}
+
+void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ if (!IsVisible()) return;
+
+ CPDF_Rect rectWnd = GetWindowRect();
+ if (rectWnd.IsEmpty()) return;
+
+ CPDF_Point ptCenter = this->GetCenterPoint();
+ FX_INT32 nTransparancy = this->GetTransparency();
+
+ switch (this->m_eScrollBarType)
+ {
+ case SBT_HSCROLL:
+ CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
+ switch (this->m_eSBButtonType)
+ {
+ case PSBT_MIN:
+ {
+ CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y);
+ CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y + PWL_TRIANGLE_HALFLEN);
+ CPDF_Point pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y - PWL_TRIANGLE_HALFLEN);
+
+ if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
+ rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
+ {
+ CFX_PathData path;
+
+ path.SetPointCount(4);
+ path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
+ path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
+ path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
+ path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
+
+ pDevice->DrawPath(&path, pUser2Device, NULL,
+ CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR,nTransparancy),
+ 0, FXFILL_ALTERNATE);
+ }
+ }
+ break;
+ case PSBT_MAX:
+ {
+ CPDF_Point pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y);
+ CPDF_Point pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y + PWL_TRIANGLE_HALFLEN);
+ CPDF_Point pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,ptCenter.y - PWL_TRIANGLE_HALFLEN);
+
+ if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
+ rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN )
+ {
+ CFX_PathData path;
+
+ path.SetPointCount(4);
+ path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
+ path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
+ path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
+ path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
+
+ pDevice->DrawPath(&path, pUser2Device, NULL,
+ CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR,nTransparancy),
+ 0, FXFILL_ALTERNATE);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ case SBT_VSCROLL:
+ switch(this->m_eSBButtonType)
+ {
+ case PSBT_MIN:
+ {
+ //draw border
+ CPDF_Rect rcDraw = rectWnd;
+ CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
+ ArgbEncode(nTransparancy,100,100,100),0.0f);
+
+ //draw inner border
+ rcDraw = CPWL_Utils::DeflateRect(rectWnd,0.5f);
+ CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
+ ArgbEncode(nTransparancy,255,255,255),1.0f);
+
+ //draw background
+
+ rcDraw = CPWL_Utils::DeflateRect(rectWnd,1.0f);
+
+ if (this->IsEnabled())
+ CPWL_Utils::DrawShadow(pDevice, pUser2Device, TRUE, FALSE, rcDraw, nTransparancy, 80, 220);
+ else
+ CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, ArgbEncode(255,255,255,255));
+
+ //draw arrow
+
+ if (rectWnd.top - rectWnd.bottom > 6.0f )
+ {
+ FX_FLOAT fX = rectWnd.left + 1.5f;
+ FX_FLOAT fY = rectWnd.bottom;
+ CPDF_Point pts[7] = {
+ CPDF_Point(fX+2.5f, fY+4.0f),
+ CPDF_Point(fX+2.5f, fY+3.0f),
+ CPDF_Point(fX+4.5f, fY+5.0f),
+ CPDF_Point(fX+6.5f, fY+3.0f),
+ CPDF_Point(fX+6.5f, fY+4.0f),
+ CPDF_Point(fX+4.5f, fY+6.0f),
+ CPDF_Point(fX+2.5f, fY+4.0f)};
+
+
+ if (this->IsEnabled())
+ CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7, ArgbEncode(nTransparancy,255,255,255));
+ else
+ CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7,
+ CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_HEAVYGRAYCOLOR,255));
+ }
+ }
+ break;
+ case PSBT_MAX:
+ {
+ //draw border
+ CPDF_Rect rcDraw = rectWnd;
+ CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
+ ArgbEncode(nTransparancy,100,100,100),0.0f);
+
+ //draw inner border
+ rcDraw = CPWL_Utils::DeflateRect(rectWnd,0.5f);
+ CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
+ ArgbEncode(nTransparancy,255,255,255),1.0f);
+
+ //draw background
+ rcDraw = CPWL_Utils::DeflateRect(rectWnd,1.0f);
+ if (this->IsEnabled())
+ CPWL_Utils::DrawShadow(pDevice, pUser2Device, TRUE, FALSE, rcDraw, nTransparancy, 80, 220);
+ else
+ CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, ArgbEncode(255,255,255,255));
+
+ //draw arrow
+
+ if (rectWnd.top - rectWnd.bottom > 6.0f )
+ {
+ FX_FLOAT fX = rectWnd.left + 1.5f;
+ FX_FLOAT fY = rectWnd.bottom;
+
+ CPDF_Point pts[7] = {
+ CPDF_Point(fX+2.5f, fY+5.0f),
+ CPDF_Point(fX+2.5f, fY+6.0f),
+ CPDF_Point(fX+4.5f, fY+4.0f),
+ CPDF_Point(fX+6.5f, fY+6.0f),
+ CPDF_Point(fX+6.5f, fY+5.0f),
+ CPDF_Point(fX+4.5f, fY+3.0f),
+ CPDF_Point(fX+2.5f, fY+5.0f)};
+
+
+ if (this->IsEnabled())
+ CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7, ArgbEncode(nTransparancy,255,255,255));
+ else
+ CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7,
+ CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_HEAVYGRAYCOLOR,255));
+ }
+ }
+ break;
+ case PSBT_POS:
+ {
+ //CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
+
+ //draw border
+ CPDF_Rect rcDraw = rectWnd;
+ CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
+ ArgbEncode(nTransparancy,100,100,100),0.0f);
+
+ //draw inner border
+ rcDraw = CPWL_Utils::DeflateRect(rectWnd,0.5f);
+ CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
+ ArgbEncode(nTransparancy,255,255,255),1.0f);
+
+ if (this->IsEnabled())
+ {
+ //draw shadow effect
+
+ CPDF_Point ptTop = CPDF_Point(rectWnd.left,rectWnd.top-1.0f);
+ CPDF_Point ptBottom = CPDF_Point(rectWnd.left,rectWnd.bottom+1.0f);
+
+ ptTop.x += 1.5f;
+ ptBottom.x += 1.5f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,210,210,210),1.0f);
+
+ ptTop.x += 1.0f;
+ ptBottom.x += 1.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,220,220,220),1.0f);
+
+ ptTop.x += 1.0f;
+ ptBottom.x += 1.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,240,240,240),1.0f);
+
+ ptTop.x += 1.0f;
+ ptBottom.x += 1.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,240,240,240),1.0f);
+
+ ptTop.x += 1.0f;
+ ptBottom.x += 1.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,210,210,210),1.0f);
+
+ ptTop.x += 1.0f;
+ ptBottom.x += 1.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,180,180,180),1.0f);
+
+ ptTop.x += 1.0f;
+ ptBottom.x += 1.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,150,150,150),1.0f);
+
+ ptTop.x += 1.0f;
+ ptBottom.x += 1.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,150,150,150),1.0f);
+
+ ptTop.x += 1.0f;
+ ptBottom.x += 1.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,180,180,180),1.0f);
+
+ ptTop.x += 1.0f;
+ ptBottom.x += 1.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
+ ArgbEncode(nTransparancy,210,210,210),1.0f);
+ }
+ else
+ {
+ CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, ArgbEncode(255,255,255,255));
+ }
+
+ //draw friction
+
+ if (rectWnd.Height() > 8.0f)
+ {
+ FX_COLORREF crStroke = ArgbEncode(nTransparancy,120,120,120);
+ if (!this->IsEnabled())
+ crStroke = CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_HEAVYGRAYCOLOR,255);
+
+ FX_FLOAT nFrictionWidth = 5.0f;
+ FX_FLOAT nFrictionHeight = 5.5f;
+
+ CPDF_Point ptLeft = CPDF_Point(ptCenter.x - nFrictionWidth / 2.0f, ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
+ CPDF_Point ptRight = CPDF_Point(ptCenter.x + nFrictionWidth / 2.0f, ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
+ crStroke,1.0f);
+
+ ptLeft.y += 2.0f;
+ ptRight.y += 2.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
+ crStroke,1.0f);
+
+ ptLeft.y += 2.0f;
+ ptRight.y += 2.0f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
+ crStroke,1.0f);
+
+ /*
+ ptLeft.y += 1.5f;
+ ptRight.y += 1.5f;
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
+ ArgbEncode(nTransparancy,150,150,150),1.0f);
+ */
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+FX_BOOL CPWL_SBButton::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonDown(point,nFlag);
+
+ if (CPWL_Wnd * pParent = GetParentWindow())
+ pParent->OnNotify(this,PNM_LBUTTONDOWN,0,(FX_INTPTR)&point);
+
+ m_bMouseDown = TRUE;
+ SetCapture();
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_SBButton::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonUp(point,nFlag);
+
+ if (CPWL_Wnd * pParent = GetParentWindow())
+ pParent->OnNotify(this,PNM_LBUTTONUP,0,(FX_INTPTR)&point);
+
+ m_bMouseDown = FALSE;
+ ReleaseCapture();
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_SBButton::OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnMouseMove(point,nFlag);
+
+ if (CPWL_Wnd * pParent = GetParentWindow())
+ {
+ pParent->OnNotify(this,PNM_MOUSEMOVE,0,(FX_INTPTR)&point);
+
+ /*
+ if (m_bMouseDown && (m_eSBButtonType == PSBT_MIN || m_eSBButtonType == PSBT_MAX))
+ {
+ if (!pParent->OnNotify(this,PNM_LBUTTONDOWN,nFlags,(FX_INTPTR)&point))
+ return FALSE;
+ }
+ */
+ }
+
+ return TRUE;
+}
+
+/* ------------------------------- CPWL_ScrollBar ---------------------------------- */
+
+CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType):
+ m_sbType(sbType),
+ m_pMinButton(NULL),
+ m_pMaxButton(NULL),
+ m_pPosButton(NULL),
+ m_bMouseDown(FALSE),
+ m_bMinOrMax(FALSE),
+ m_bNotifyForever(TRUE)
+{
+}
+
+CPWL_ScrollBar::~CPWL_ScrollBar()
+{
+}
+
+CFX_ByteString CPWL_ScrollBar::GetClassName() const
+{
+ return "CPWL_ScrollBar";
+}
+
+void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM & cp)
+{
+ cp.eCursorType = FXCT_ARROW;
+}
+
+void CPWL_ScrollBar::RePosChildWnd()
+{
+ CPDF_Rect rcClient = this->GetClientRect();
+
+/*
+ switch(m_sbType)
+ {
+ case SBT_HSCROLL:
+ if (rcClient.right - rcClient.left < PWL_SCROLLBAR_WIDTH ||
+ rcClient.top - rcClient.bottom < PWL_SCROLLBAR_WIDTH)
+ {
+ SetVisible(FALSE);
+ }
+ break;
+ case SBT_VSCROLL:
+ if (rcClient.right - rcClient.left < PWL_SCROLLBAR_WIDTH ||
+ rcClient.top - rcClient.bottom < PWL_SCROLLBAR_WIDTH)
+ {
+ SetVisible(FALSE);
+ }
+ break;
+ }
+*/
+ CPDF_Rect rcMinButton,rcMaxButton;
+
+ FX_FLOAT fBWidth = 0;
+
+ switch (m_sbType)
+ {
+ case SBT_HSCROLL:
+ if (rcClient.right - rcClient.left > PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2)
+ {
+ rcMinButton = CPDF_Rect(rcClient.left,rcClient.bottom,
+ rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH,rcClient.top);
+ rcMaxButton = CPDF_Rect(rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH,rcClient.bottom,
+ rcClient.right,rcClient.top);
+ }
+ else
+ {
+ fBWidth = (rcClient.right - rcClient.left - PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / 2;
+
+ if (fBWidth > 0)
+ {
+ rcMinButton = CPDF_Rect(rcClient.left,rcClient.bottom,
+ rcClient.left + fBWidth,rcClient.top);
+ rcMaxButton = CPDF_Rect(rcClient.right - fBWidth,rcClient.bottom,
+ rcClient.right,rcClient.top);
+ }
+ else SetVisible(FALSE);
+ }
+ break;
+ case SBT_VSCROLL:
+ if (IsFloatBigger(rcClient.top - rcClient.bottom, PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2))
+ {
+ rcMinButton = CPDF_Rect(rcClient.left,rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH,
+ rcClient.right,rcClient.top);
+ rcMaxButton = CPDF_Rect(rcClient.left,rcClient.bottom,
+ rcClient.right,rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH);
+ }
+ else
+ {
+ fBWidth = (rcClient.top - rcClient.bottom - PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / 2;
+
+ if (IsFloatBigger(fBWidth, 0))
+ {
+ rcMinButton = CPDF_Rect(rcClient.left,rcClient.top - fBWidth,
+ rcClient.right,rcClient.top);
+ rcMaxButton = CPDF_Rect(rcClient.left,rcClient.bottom,
+ rcClient.right,rcClient.bottom + fBWidth);
+ }
+ else SetVisible(FALSE);
+ }
+ break;
+ }
+
+// if (IsVisible())
+ {
+ if (m_pMinButton)
+ m_pMinButton->Move(rcMinButton,TRUE,FALSE);
+
+ if (m_pMaxButton)
+ m_pMaxButton->Move(rcMaxButton,TRUE,FALSE);
+
+ MovePosButton(FALSE);
+ }
+}
+
+void CPWL_ScrollBar::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ CPDF_Rect rectWnd = GetWindowRect();
+
+ if (IsVisible() && !rectWnd.IsEmpty())
+ {
+ CFX_ByteTextBuf sButton;
+
+ sButton << "q\n";
+ sButton << "0 w\n" << CPWL_Utils::GetColorAppStream(GetBackgroundColor(),TRUE);
+ sButton << rectWnd.left << " " << rectWnd.bottom << " "
+ << rectWnd.right - rectWnd.left << " " << rectWnd.top - rectWnd.bottom << " re b Q\n";
+
+ sAppStream << sButton;
+ }
+}
+
+void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+// CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
+ CPDF_Rect rectWnd = GetWindowRect();
+
+ if (IsVisible() && !rectWnd.IsEmpty())
+ {
+ CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rectWnd, this->GetBackgroundColor(), GetTransparency());
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device,
+ CPDF_Point(rectWnd.left+2.0f,rectWnd.top-2.0f), CPDF_Point(rectWnd.left+2.0f,rectWnd.bottom+2.0f),
+ ArgbEncode(this->GetTransparency(),100,100,100),1.0f);
+
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device,
+ CPDF_Point(rectWnd.right-2.0f,rectWnd.top-2.0f), CPDF_Point(rectWnd.right-2.0f,rectWnd.bottom+2.0f),
+ ArgbEncode(this->GetTransparency(),100,100,100),1.0f);
+ }
+}
+
+FX_BOOL CPWL_ScrollBar::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonDown(point,nFlag);
+
+ //SetFocus();
+
+ if (HasFlag(PWS_AUTOTRANSPARENT))
+ {
+ if (GetTransparency() != 255)
+ {
+ SetTransparency(255);
+ InvalidateRect();
+ }
+ }
+
+ CPDF_Rect rcMinArea,rcMaxArea;
+
+ if (m_pPosButton && m_pPosButton->IsVisible())
+ {
+ CPDF_Rect rcClient = this->GetClientRect();
+ CPDF_Rect rcPosButton = m_pPosButton->GetWindowRect();
+
+ switch (m_sbType)
+ {
+ case SBT_HSCROLL:
+ rcMinArea = CPDF_Rect(rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH,rcClient.bottom,
+ rcPosButton.left,rcClient.top);
+ rcMaxArea = CPDF_Rect(rcPosButton.right,rcClient.bottom,
+ rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH,rcClient.top);
+
+ break;
+ case SBT_VSCROLL:
+ rcMinArea = CPDF_Rect(rcClient.left,rcPosButton.top,
+ rcClient.right,rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH);
+ rcMaxArea = CPDF_Rect(rcClient.left,rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH,
+ rcClient.right,rcPosButton.bottom);
+ break;
+ }
+
+ rcMinArea.Normalize();
+ rcMaxArea.Normalize();
+
+ if (rcMinArea.Contains(point.x,point.y))
+ {
+ m_sData.SubBig();
+ MovePosButton(TRUE);
+ NotifyScrollWindow();
+ }
+
+ if (rcMaxArea.Contains(point.x,point.y))
+ {
+ m_sData.AddBig();
+ MovePosButton(TRUE);
+ NotifyScrollWindow();
+ }
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPWL_ScrollBar::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+ CPWL_Wnd::OnLButtonUp(point,nFlag);
+
+ if (HasFlag(PWS_AUTOTRANSPARENT))
+ {
+ if (GetTransparency() != PWL_SCROLLBAR_TRANSPARANCY)
+ {
+ SetTransparency(PWL_SCROLLBAR_TRANSPARANCY);
+ InvalidateRect();
+ }
+ }
+
+ EndTimer();
+ m_bMouseDown = FALSE;
+
+ return TRUE;
+}
+
+void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
+
+ switch (msg)
+ {
+ case PNM_LBUTTONDOWN:
+ if (pWnd == m_pMinButton)
+ {
+ OnMinButtonLBDown(*(CPDF_Point*)lParam);
+ }
+
+ if (pWnd == m_pMaxButton)
+ {
+ OnMaxButtonLBDown(*(CPDF_Point*)lParam);
+ }
+
+ if (pWnd == m_pPosButton)
+ {
+ OnPosButtonLBDown(*(CPDF_Point*)lParam);
+ }
+ break;
+ case PNM_LBUTTONUP:
+ if (pWnd == m_pMinButton)
+ {
+ OnMinButtonLBUp(*(CPDF_Point*)lParam);
+ }
+
+ if (pWnd == m_pMaxButton)
+ {
+ OnMaxButtonLBUp(*(CPDF_Point*)lParam);
+ }
+
+ if (pWnd == m_pPosButton)
+ {
+ OnPosButtonLBUp(*(CPDF_Point*)lParam);
+ }
+ break;
+ case PNM_MOUSEMOVE:
+ if (pWnd == m_pMinButton)
+ {
+ OnMinButtonMouseMove(*(CPDF_Point*)lParam);
+ }
+
+ if (pWnd == m_pMaxButton)
+ {
+ OnMaxButtonMouseMove(*(CPDF_Point*)lParam);
+ }
+
+ if (pWnd == m_pPosButton)
+ {
+ OnPosButtonMouseMove(*(CPDF_Point*)lParam);
+ }
+ break;
+ case PNM_SETSCROLLINFO:
+ {
+ if (PWL_SCROLL_INFO * pInfo = (PWL_SCROLL_INFO*)lParam)
+ {
+ if (FXSYS_memcmp(&m_OriginInfo, pInfo, sizeof(PWL_SCROLL_INFO)) != 0)
+ {
+ m_OriginInfo = *pInfo;
+ FX_FLOAT fMax = pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth;
+ fMax = fMax > 0.0f ? fMax : 0.0f;
+ this->SetScrollRange(0,fMax, pInfo->fPlateWidth);
+ this->SetScrollStep(pInfo->fBigStep,pInfo->fSmallStep);
+ }
+ }
+ }
+ break;
+ case PNM_SETSCROLLPOS:
+ {
+ FX_FLOAT fPos = *(FX_FLOAT*)lParam;
+ switch (this->m_sbType)
+ {
+ case SBT_HSCROLL:
+ fPos = fPos - m_OriginInfo.fContentMin;
+ break;
+ case SBT_VSCROLL:
+ fPos = m_OriginInfo.fContentMax - fPos;
+ break;
+ }
+ this->SetScrollPos(fPos);
+ }
+ break;
+ }
+}
+
+void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM & cp)
+{
+ PWL_CREATEPARAM scp = cp;
+ scp.pParentWnd = this;
+ scp.dwBorderWidth = 2;
+ scp.nBorderStyle = PBS_BEVELED;
+
+ scp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP;
+
+ if (!m_pMinButton)
+ {
+ m_pMinButton = new CPWL_SBButton(m_sbType,PSBT_MIN);
+ m_pMinButton->Create(scp);
+ }
+
+ if (!m_pMaxButton)
+ {
+ m_pMaxButton = new CPWL_SBButton(m_sbType,PSBT_MAX);
+ m_pMaxButton->Create(scp);
+ }
+
+ if (!m_pPosButton)
+ {
+ m_pPosButton = new CPWL_SBButton(m_sbType,PSBT_POS);
+ m_pPosButton->SetVisible(FALSE);
+ m_pPosButton->Create(scp);
+ }
+}
+
+FX_FLOAT CPWL_ScrollBar::GetScrollBarWidth() const
+{
+ if (!IsVisible()) return 0;
+
+ return PWL_SCROLLBAR_WIDTH;
+}
+
+void CPWL_ScrollBar::SetScrollRange(FX_FLOAT fMin,FX_FLOAT fMax,FX_FLOAT fClientWidth)
+{
+ if (m_pPosButton)
+ {
+ m_sData.SetScrollRange(fMin,fMax);
+ m_sData.SetClientWidth(fClientWidth);
+
+ if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f))
+ {
+ m_pPosButton->SetVisible(FALSE);
+ }
+ else
+ {
+ m_pPosButton->SetVisible(TRUE);
+ MovePosButton(TRUE);
+ }
+ }
+}
+
+void CPWL_ScrollBar::SetScrollPos(FX_FLOAT fPos)
+{
+ FX_FLOAT fOldPos = m_sData.fScrollPos;
+
+ m_sData.SetPos(fPos);
+
+ if (!IsFloatEqual(m_sData.fScrollPos, fOldPos))
+ MovePosButton(TRUE);
+}
+
+void CPWL_ScrollBar::SetScrollStep(FX_FLOAT fBigStep,FX_FLOAT fSmallStep)
+{
+ m_sData.SetBigStep(fBigStep);
+ m_sData.SetSmallStep(fSmallStep);
+}
+
+void CPWL_ScrollBar::MovePosButton(FX_BOOL bRefresh)
+{
+ ASSERT (m_pPosButton != NULL);
+ ASSERT (m_pMinButton != NULL);
+ ASSERT (m_pMaxButton != NULL);
+
+ if (m_pPosButton->IsVisible())
+ {
+
+
+
+
+ CPDF_Rect rcClient;
+ CPDF_Rect rcPosArea,rcPosButton;
+
+ rcClient = this->GetClientRect();
+ rcPosArea = GetScrollArea();
+
+ FX_FLOAT fLeft,fRight,fTop,fBottom;
+
+ switch (m_sbType)
+ {
+ case SBT_HSCROLL:
+ fLeft = TrueToFace(m_sData.fScrollPos);
+ fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth);
+
+ if (fRight - fLeft < PWL_SCROLLBAR_POSBUTTON_MINWIDTH)
+ fRight = fLeft + PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
+
+ if (fRight > rcPosArea.right)
+ {
+ fRight = rcPosArea.right;
+ fLeft = fRight - PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
+ }
+
+ rcPosButton = CPDF_Rect(fLeft ,
+ rcPosArea.bottom,
+ fRight ,
+ rcPosArea.top);
+
+ break;
+ case SBT_VSCROLL:
+ fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth);
+ fTop = TrueToFace(m_sData.fScrollPos);
+
+ if (IsFloatSmaller(fTop - fBottom, PWL_SCROLLBAR_POSBUTTON_MINWIDTH))
+ fBottom = fTop - PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
+
+ if (IsFloatSmaller(fBottom, rcPosArea.bottom))
+ {
+ fBottom = rcPosArea.bottom;
+ fTop = fBottom + PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
+ }
+
+ rcPosButton = CPDF_Rect(rcPosArea.left,
+ fBottom,
+ rcPosArea.right,
+ fTop);
+
+ break;
+ }
+
+ m_pPosButton->Move(rcPosButton,TRUE,bRefresh);
+ }
+}
+
+void CPWL_ScrollBar::OnMinButtonLBDown(const CPDF_Point & point)
+{
+ m_sData.SubSmall();
+ MovePosButton(TRUE);
+ NotifyScrollWindow();
+
+ m_bMinOrMax = TRUE;
+
+ EndTimer();
+ BeginTimer(100);
+}
+
+void CPWL_ScrollBar::OnMinButtonLBUp(const CPDF_Point & point)
+{
+}
+
+void CPWL_ScrollBar::OnMinButtonMouseMove(const CPDF_Point & point)
+{
+}
+
+void CPWL_ScrollBar::OnMaxButtonLBDown(const CPDF_Point & point)
+{
+ m_sData.AddSmall();
+ MovePosButton(TRUE);
+ NotifyScrollWindow();
+
+ m_bMinOrMax = FALSE;
+
+ EndTimer();
+ BeginTimer(100);
+}
+
+void CPWL_ScrollBar::OnMaxButtonLBUp(const CPDF_Point & point)
+{
+}
+
+void CPWL_ScrollBar::OnMaxButtonMouseMove(const CPDF_Point & point)
+{
+}
+
+void CPWL_ScrollBar::OnPosButtonLBDown(const CPDF_Point & point)
+{
+ m_bMouseDown = TRUE;
+
+ if (m_pPosButton)
+ {
+ CPDF_Rect rcPosButton = m_pPosButton->GetWindowRect();
+
+ switch(m_sbType)
+ {
+ case SBT_HSCROLL:
+ m_nOldPos = point.x;
+ m_fOldPosButton = rcPosButton.left;
+ break;
+ case SBT_VSCROLL:
+ m_nOldPos = point.y;
+ m_fOldPosButton = rcPosButton.top;
+ break;
+ }
+ }
+}
+
+void CPWL_ScrollBar::OnPosButtonLBUp(const CPDF_Point & point)
+{
+ if (m_bMouseDown)
+ {
+ if (!m_bNotifyForever)
+ NotifyScrollWindow();
+ }
+ m_bMouseDown = FALSE;
+}
+
+void CPWL_ScrollBar::OnPosButtonMouseMove(const CPDF_Point & point)
+{
+ FX_FLOAT fOldScrollPos = m_sData.fScrollPos;
+
+ FX_FLOAT fNewPos = 0;
+
+ switch (m_sbType)
+ {
+ case SBT_HSCROLL:
+ if (FXSYS_fabs(point.x - m_nOldPos) < 1) return;
+ fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos);
+ break;
+ case SBT_VSCROLL:
+ if (FXSYS_fabs(point.y - m_nOldPos) < 1) return;
+ fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos);
+ break;
+ }
+
+ if (m_bMouseDown)
+ {
+ switch (m_sbType)
+ {
+ case SBT_HSCROLL:
+
+ if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin))
+ {
+ fNewPos = m_sData.ScrollRange.fMin;
+ }
+
+ if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax))
+ {
+ fNewPos = m_sData.ScrollRange.fMax;
+ }
+
+ m_sData.SetPos(fNewPos);
+
+ break;
+ case SBT_VSCROLL:
+
+ if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin))
+ {
+ fNewPos = m_sData.ScrollRange.fMin;
+ }
+
+ if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax))
+ {
+ fNewPos = m_sData.ScrollRange.fMax;
+ }
+
+ m_sData.SetPos(fNewPos);
+
+ break;
+ }
+
+ if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos))
+ {
+ MovePosButton(TRUE);
+
+ if (m_bNotifyForever)
+ NotifyScrollWindow();
+ }
+ }
+}
+
+void CPWL_ScrollBar::NotifyScrollWindow()
+{
+ if (CPWL_Wnd * pParent = this->GetParentWindow())
+ {
+ FX_FLOAT fPos;
+ switch (this->m_sbType)
+ {
+ case SBT_HSCROLL:
+ fPos = m_OriginInfo.fContentMin + m_sData.fScrollPos;
+ break;
+ case SBT_VSCROLL:
+ fPos = m_OriginInfo.fContentMax - m_sData.fScrollPos;
+ break;
+ }
+ pParent->OnNotify(this,PNM_SCROLLWINDOW,(FX_INTPTR)m_sbType,(FX_INTPTR)&fPos);
+ }
+}
+
+CPDF_Rect CPWL_ScrollBar::GetScrollArea() const
+{
+ CPDF_Rect rcClient = GetClientRect();
+ CPDF_Rect rcArea;
+
+ if (!m_pMinButton || !m_pMaxButton)return rcClient;
+
+ CPDF_Rect rcMin = m_pMinButton->GetWindowRect();
+ CPDF_Rect rcMax = m_pMaxButton->GetWindowRect();
+
+ FX_FLOAT fMinWidth = rcMin.right - rcMin.left;
+ FX_FLOAT fMinHeight = rcMin.top - rcMin.bottom;
+ FX_FLOAT fMaxWidth = rcMax.right - rcMax.left;
+ FX_FLOAT fMaxHeight = rcMax.top - rcMax.bottom;
+
+ switch(m_sbType)
+ {
+ case SBT_HSCROLL:
+ if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2)
+ {
+ rcArea = CPDF_Rect(rcClient.left + fMinWidth + 1,rcClient.bottom,
+ rcClient.right - fMaxWidth - 1,rcClient.top);
+ }
+ else
+ {
+ rcArea = CPDF_Rect(rcClient.left + fMinWidth + 1,rcClient.bottom,
+ rcClient.left + fMinWidth + 1,rcClient.top);
+ }
+ break;
+ case SBT_VSCROLL:
+ if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2)
+ {
+ rcArea = CPDF_Rect(rcClient.left,rcClient.bottom + fMinHeight + 1,
+ rcClient.right,rcClient.top - fMaxHeight - 1);
+ }
+ else
+ {
+ rcArea = CPDF_Rect(rcClient.left,rcClient.bottom + fMinHeight + 1,
+ rcClient.right,rcClient.bottom + fMinHeight + 1);
+ }
+ break;
+ }
+
+ rcArea.Normalize();
+
+ return rcArea;
+}
+
+FX_FLOAT CPWL_ScrollBar::TrueToFace(FX_FLOAT fTrue)
+{
+ CPDF_Rect rcPosArea;
+ rcPosArea = GetScrollArea();
+
+ FX_FLOAT fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth;
+ fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
+
+ FX_FLOAT fFace = 0;
+
+ switch(m_sbType)
+ {
+ case SBT_HSCROLL:
+ fFace = rcPosArea.left + fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth;
+ break;
+ case SBT_VSCROLL:
+ fFace = rcPosArea.top - fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth;
+ break;
+ }
+
+ return fFace;
+}
+
+FX_FLOAT CPWL_ScrollBar::FaceToTrue(FX_FLOAT fFace)
+{
+ CPDF_Rect rcPosArea;
+ rcPosArea = GetScrollArea();
+
+ FX_FLOAT fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth;
+ fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
+
+ FX_FLOAT fTrue = 0;
+
+ switch(m_sbType)
+ {
+ case SBT_HSCROLL:
+ fTrue = (fFace - rcPosArea.left) * fFactWidth / (rcPosArea.right - rcPosArea.left);
+ break;
+ case SBT_VSCROLL:
+ fTrue = (rcPosArea.top - fFace) * fFactWidth / (rcPosArea.top - rcPosArea.bottom);
+ break;
+ }
+
+ return fTrue;
+}
+
+void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ CreateButtons(cp);
+}
+
+void CPWL_ScrollBar::TimerProc()
+{
+ PWL_SCROLL_PRIVATEDATA sTemp = m_sData;
+
+ if (m_bMinOrMax)m_sData.SubSmall();
+ else m_sData.AddSmall();
+
+ if (FXSYS_memcmp(&m_sData, &sTemp, sizeof(PWL_SCROLL_PRIVATEDATA)) != 0)
+ {
+ MovePosButton(TRUE);
+ NotifyScrollWindow();
+ }
+}
+
+/*
+void CPWL_ScrollBar::OnSetFocus()
+{
+ if (GetTransparency() != 255)
+ {
+ SetTransparency(255);
+ InvalidateRect();
+ }
+}
+
+void CPWL_ScrollBar::OnKillFocus()
+{
+ if (GetTransparency() != PWL_SCROLLBAR_TRANSPARANCY)
+ {
+ SetTransparency(PWL_SCROLLBAR_TRANSPARANCY);
+ InvalidateRect();
+ }
+}
+*/
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_Signature.cpp b/fpdfsdk/src/pdfwindow/PWL_Signature.cpp
index 36297f3d92..5d79ce9cab 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Signature.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Signature.cpp
@@ -1,220 +1,220 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_Icon.h"
-#include "../../include/pdfwindow/PWL_Signature.h"
-#include "../../include/pdfwindow/PWL_Label.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-
-/* --------------------------------- CPWL_Signature_Image --------------------------------- */
-
-CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL)
-{
-}
-
-CPWL_Signature_Image::~CPWL_Signature_Image()
-{
-}
-
-void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage)
-{
- m_pImage = pImage;
-}
-
-CFX_DIBSource* CPWL_Signature_Image::GetImage()
-{
- return m_pImage;
-}
-
-void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
-
- if (m_pImage)
- {
- CPDF_Rect rcClient = GetClientRect();
-
- FX_FLOAT x, y;
- pUser2Device->Transform(rcClient.left, rcClient.top, x, y);
-
- pDevice->StretchDIBits(m_pImage, (FX_INT32)x, (FX_INT32)y,
- (FX_INT32)rcClient.Width(), (FX_INT32)rcClient.Height());
- }
-}
-
-void CPWL_Signature_Image::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- sAppStream << CPWL_Image::GetImageAppStream();
-}
-
-void CPWL_Signature_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
-{
- FX_FLOAT fImageW, fImageH;
-
- GetImageSize(fImageW, fImageH);
-
- CPDF_Rect rcClient = GetClientRect();
-
- fHScale = rcClient.Width() / fImageW;
- fVScale = rcClient.Height() / fImageH;
-}
-
-/* --------------------------------- CPWL_Signature --------------------------------- */
-
-CPWL_Signature::CPWL_Signature() :
- m_pText(NULL),
- m_pDescription(NULL),
- m_pImage(NULL),
- m_bTextExist(TRUE),
- m_bImageExist(FALSE),
- m_bFlagExist(TRUE)
-{
-}
-
-CPWL_Signature::~CPWL_Signature()
-{
-}
-
-void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist)
-{
- m_bTextExist = bTextExist;
-
- RePosChildWnd();
-}
-
-void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist)
-{
- m_bImageExist = bImageExist;
-
- RePosChildWnd();
-}
-
-void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist)
-{
- m_bFlagExist = bFlagExist;
-}
-
-void CPWL_Signature::SetText(FX_LPCWSTR sText)
-{
- m_pText->SetText(sText);
-
- RePosChildWnd();
-}
-
-void CPWL_Signature::SetDescription(FX_LPCWSTR string)
-{
- m_pDescription->SetText(string);
-
- RePosChildWnd();
-}
-
-void CPWL_Signature::SetImage(CFX_DIBSource* pImage)
-{
- m_pImage->SetImage(pImage);
-
- RePosChildWnd();
-}
-
-void CPWL_Signature::SetImageStream(CPDF_Stream * pStream, FX_LPCSTR sImageAlias)
-{
- m_pImage->SetPDFStream(pStream);
- m_pImage->SetImageAlias(sImageAlias);
-
- RePosChildWnd();
-}
-
-void CPWL_Signature::RePosChildWnd()
-{
- CPDF_Rect rcClient = GetClientRect();
-
- CPDF_Rect rcText = rcClient;
- CPDF_Rect rcDescription = rcClient;
-
- FX_BOOL bTextVisible = m_bTextExist && m_pText->GetText().GetLength() > 0;
-
- if ((bTextVisible || m_bImageExist) &&
- m_pDescription->GetText().GetLength() > 0)
- {
- if (rcClient.Width() >= rcClient.Height())
- {
- rcText.right = rcText.left + rcClient.Width() / 2.0f;
- rcDescription.left = rcDescription.right - rcClient.Width() / 2.0f;
- }
- else
- {
- rcText.bottom = rcText.top - rcClient.Height() / 2.0f;
- rcDescription.top = rcDescription.bottom + rcClient.Height() / 2.0f;
- }
- }
-
- m_pText->SetVisible(bTextVisible);
- m_pImage->SetVisible(m_bImageExist);
-
- m_pText->Move(rcText, TRUE, FALSE);
- m_pImage->Move(rcText, TRUE, FALSE);
- m_pDescription->Move(rcDescription, TRUE, FALSE);
-}
-
-void CPWL_Signature::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
- m_pImage = new CPWL_Signature_Image;
- PWL_CREATEPARAM icp = cp;
- icp.pParentWnd = this;
- icp.dwFlags = PWS_CHILD | PWS_VISIBLE;
- icp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
- m_pImage->Create(icp);
-
- m_pText = new CPWL_Label;
- PWL_CREATEPARAM acp = cp;
- acp.pParentWnd = this;
- acp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_MIDDLE | PES_CENTER;
- acp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
- m_pText->Create(acp);
-
- m_pDescription = new CPWL_Label;
- PWL_CREATEPARAM dcp = cp;
- dcp.pParentWnd = this;
- dcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_LEFT | PES_CENTER;
- dcp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
- m_pDescription->Create(dcp);
-}
-
-void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
-
- if (m_bFlagExist)
- CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, PWL_ICONTYPE_FOXIT, CPWL_Utils::GetCenterSquare(GetClientRect()),
- CPWL_Color(COLORTYPE_RGB,0.91f,0.855f,0.92f), CPWL_Color(COLORTYPE_TRANSPARENT), 255);
-
- /*
- CPDF_Rect rcClient = GetClientRect();
-
- CFX_PathData path;
-
- path.SetPointCount(2);
- path.SetPoint(0, rcClient.left, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_MOVETO);
- path.SetPoint(1, rcClient.right, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_LINETO);
-
- CFX_GraphStateData gsd;
- gsd.SetDashCount(2);
- gsd.m_DashArray[0] = 6.0f;
- gsd.m_DashArray[1] = 6.0f;
- gsd.m_DashPhase = 0;
-
- gsd.m_LineWidth = 10.0f;
- pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,255,0,0), FXFILL_ALTERNATE);
- */
-}
-
-void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- CPWL_Wnd::GetThisAppearanceStream(sAppStream);
-}
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Icon.h"
+#include "../../include/pdfwindow/PWL_Signature.h"
+#include "../../include/pdfwindow/PWL_Label.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+/* --------------------------------- CPWL_Signature_Image --------------------------------- */
+
+CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL)
+{
+}
+
+CPWL_Signature_Image::~CPWL_Signature_Image()
+{
+}
+
+void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage)
+{
+ m_pImage = pImage;
+}
+
+CFX_DIBSource* CPWL_Signature_Image::GetImage()
+{
+ return m_pImage;
+}
+
+void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
+
+ if (m_pImage)
+ {
+ CPDF_Rect rcClient = GetClientRect();
+
+ FX_FLOAT x, y;
+ pUser2Device->Transform(rcClient.left, rcClient.top, x, y);
+
+ pDevice->StretchDIBits(m_pImage, (FX_INT32)x, (FX_INT32)y,
+ (FX_INT32)rcClient.Width(), (FX_INT32)rcClient.Height());
+ }
+}
+
+void CPWL_Signature_Image::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ sAppStream << CPWL_Image::GetImageAppStream();
+}
+
+void CPWL_Signature_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
+{
+ FX_FLOAT fImageW, fImageH;
+
+ GetImageSize(fImageW, fImageH);
+
+ CPDF_Rect rcClient = GetClientRect();
+
+ fHScale = rcClient.Width() / fImageW;
+ fVScale = rcClient.Height() / fImageH;
+}
+
+/* --------------------------------- CPWL_Signature --------------------------------- */
+
+CPWL_Signature::CPWL_Signature() :
+ m_pText(NULL),
+ m_pDescription(NULL),
+ m_pImage(NULL),
+ m_bTextExist(TRUE),
+ m_bImageExist(FALSE),
+ m_bFlagExist(TRUE)
+{
+}
+
+CPWL_Signature::~CPWL_Signature()
+{
+}
+
+void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist)
+{
+ m_bTextExist = bTextExist;
+
+ RePosChildWnd();
+}
+
+void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist)
+{
+ m_bImageExist = bImageExist;
+
+ RePosChildWnd();
+}
+
+void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist)
+{
+ m_bFlagExist = bFlagExist;
+}
+
+void CPWL_Signature::SetText(FX_LPCWSTR sText)
+{
+ m_pText->SetText(sText);
+
+ RePosChildWnd();
+}
+
+void CPWL_Signature::SetDescription(FX_LPCWSTR string)
+{
+ m_pDescription->SetText(string);
+
+ RePosChildWnd();
+}
+
+void CPWL_Signature::SetImage(CFX_DIBSource* pImage)
+{
+ m_pImage->SetImage(pImage);
+
+ RePosChildWnd();
+}
+
+void CPWL_Signature::SetImageStream(CPDF_Stream * pStream, FX_LPCSTR sImageAlias)
+{
+ m_pImage->SetPDFStream(pStream);
+ m_pImage->SetImageAlias(sImageAlias);
+
+ RePosChildWnd();
+}
+
+void CPWL_Signature::RePosChildWnd()
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ CPDF_Rect rcText = rcClient;
+ CPDF_Rect rcDescription = rcClient;
+
+ FX_BOOL bTextVisible = m_bTextExist && m_pText->GetText().GetLength() > 0;
+
+ if ((bTextVisible || m_bImageExist) &&
+ m_pDescription->GetText().GetLength() > 0)
+ {
+ if (rcClient.Width() >= rcClient.Height())
+ {
+ rcText.right = rcText.left + rcClient.Width() / 2.0f;
+ rcDescription.left = rcDescription.right - rcClient.Width() / 2.0f;
+ }
+ else
+ {
+ rcText.bottom = rcText.top - rcClient.Height() / 2.0f;
+ rcDescription.top = rcDescription.bottom + rcClient.Height() / 2.0f;
+ }
+ }
+
+ m_pText->SetVisible(bTextVisible);
+ m_pImage->SetVisible(m_bImageExist);
+
+ m_pText->Move(rcText, TRUE, FALSE);
+ m_pImage->Move(rcText, TRUE, FALSE);
+ m_pDescription->Move(rcDescription, TRUE, FALSE);
+}
+
+void CPWL_Signature::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+ m_pImage = new CPWL_Signature_Image;
+ PWL_CREATEPARAM icp = cp;
+ icp.pParentWnd = this;
+ icp.dwFlags = PWS_CHILD | PWS_VISIBLE;
+ icp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
+ m_pImage->Create(icp);
+
+ m_pText = new CPWL_Label;
+ PWL_CREATEPARAM acp = cp;
+ acp.pParentWnd = this;
+ acp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_MIDDLE | PES_CENTER;
+ acp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
+ m_pText->Create(acp);
+
+ m_pDescription = new CPWL_Label;
+ PWL_CREATEPARAM dcp = cp;
+ dcp.pParentWnd = this;
+ dcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_LEFT | PES_CENTER;
+ dcp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
+ m_pDescription->Create(dcp);
+}
+
+void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
+
+ if (m_bFlagExist)
+ CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, PWL_ICONTYPE_FOXIT, CPWL_Utils::GetCenterSquare(GetClientRect()),
+ CPWL_Color(COLORTYPE_RGB,0.91f,0.855f,0.92f), CPWL_Color(COLORTYPE_TRANSPARENT), 255);
+
+ /*
+ CPDF_Rect rcClient = GetClientRect();
+
+ CFX_PathData path;
+
+ path.SetPointCount(2);
+ path.SetPoint(0, rcClient.left, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_MOVETO);
+ path.SetPoint(1, rcClient.right, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_LINETO);
+
+ CFX_GraphStateData gsd;
+ gsd.SetDashCount(2);
+ gsd.m_DashArray[0] = 6.0f;
+ gsd.m_DashArray[1] = 6.0f;
+ gsd.m_DashPhase = 0;
+
+ gsd.m_LineWidth = 10.0f;
+ pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,255,0,0), FXFILL_ALTERNATE);
+ */
+}
+
+void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ CPWL_Wnd::GetThisAppearanceStream(sAppStream);
+}
+
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_SpecialButton.cpp b/fpdfsdk/src/pdfwindow/PWL_SpecialButton.cpp
index aabf503f98..287fec1a55 100644
--- a/fpdfsdk/src/pdfwindow/PWL_SpecialButton.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_SpecialButton.cpp
@@ -1,110 +1,110 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_Button.h"
-#include "../../include/pdfwindow/PWL_SpecialButton.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-
-/* --------------------------- CPWL_PushButton ---------------------------- */
-
-CPWL_PushButton::CPWL_PushButton()
-{
-}
-
-CPWL_PushButton::~CPWL_PushButton()
-{
-}
-
-CFX_ByteString CPWL_PushButton::GetClassName() const
-{
- return "CPWL_PushButton";
-}
-
-CPDF_Rect CPWL_PushButton::GetFocusRect() const
-{
- return CPWL_Utils::DeflateRect(this->GetWindowRect(),(FX_FLOAT)GetBorderWidth());
-}
-
-/* --------------------------- CPWL_CheckBox ---------------------------- */
-
-CPWL_CheckBox::CPWL_CheckBox() : m_bChecked(FALSE)
-{
-}
-
-CPWL_CheckBox::~CPWL_CheckBox()
-{
-}
-
-CFX_ByteString CPWL_CheckBox::GetClassName() const
-{
- return "CPWL_CheckBox";
-}
-
-void CPWL_CheckBox::SetCheck(FX_BOOL bCheck)
-{
- m_bChecked = bCheck;
-}
-
-FX_BOOL CPWL_CheckBox::IsChecked() const
-{
- return m_bChecked;
-}
-
-FX_BOOL CPWL_CheckBox::OnLButtonUp(const CPDF_Point & point)
-{
- if (IsReadOnly()) return FALSE;
-
- SetCheck(!IsChecked());
- return TRUE;
-}
-
-FX_BOOL CPWL_CheckBox::OnChar(FX_WORD nChar)
-{
- SetCheck(!IsChecked());
- return TRUE;
-}
-
-/* --------------------------- CPWL_RadioButton ---------------------------- */
-
-CPWL_RadioButton::CPWL_RadioButton() : m_bChecked(FALSE)
-{
-}
-
-CPWL_RadioButton::~CPWL_RadioButton()
-{
-}
-
-CFX_ByteString CPWL_RadioButton::GetClassName() const
-{
- return "CPWL_RadioButton";
-}
-
-FX_BOOL CPWL_RadioButton::OnLButtonUp(const CPDF_Point & point)
-{
- if (IsReadOnly()) return FALSE;
-
- SetCheck(TRUE);
- return TRUE;
-}
-
-void CPWL_RadioButton::SetCheck(FX_BOOL bCheck)
-{
- m_bChecked = bCheck;
-}
-
-FX_BOOL CPWL_RadioButton::IsChecked() const
-{
- return m_bChecked;
-}
-
-FX_BOOL CPWL_RadioButton::OnChar(FX_WORD nChar)
-{
- SetCheck(TRUE);
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Button.h"
+#include "../../include/pdfwindow/PWL_SpecialButton.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+/* --------------------------- CPWL_PushButton ---------------------------- */
+
+CPWL_PushButton::CPWL_PushButton()
+{
+}
+
+CPWL_PushButton::~CPWL_PushButton()
+{
+}
+
+CFX_ByteString CPWL_PushButton::GetClassName() const
+{
+ return "CPWL_PushButton";
+}
+
+CPDF_Rect CPWL_PushButton::GetFocusRect() const
+{
+ return CPWL_Utils::DeflateRect(this->GetWindowRect(),(FX_FLOAT)GetBorderWidth());
+}
+
+/* --------------------------- CPWL_CheckBox ---------------------------- */
+
+CPWL_CheckBox::CPWL_CheckBox() : m_bChecked(FALSE)
+{
+}
+
+CPWL_CheckBox::~CPWL_CheckBox()
+{
+}
+
+CFX_ByteString CPWL_CheckBox::GetClassName() const
+{
+ return "CPWL_CheckBox";
+}
+
+void CPWL_CheckBox::SetCheck(FX_BOOL bCheck)
+{
+ m_bChecked = bCheck;
+}
+
+FX_BOOL CPWL_CheckBox::IsChecked() const
+{
+ return m_bChecked;
+}
+
+FX_BOOL CPWL_CheckBox::OnLButtonUp(const CPDF_Point & point)
+{
+ if (IsReadOnly()) return FALSE;
+
+ SetCheck(!IsChecked());
+ return TRUE;
+}
+
+FX_BOOL CPWL_CheckBox::OnChar(FX_WORD nChar)
+{
+ SetCheck(!IsChecked());
+ return TRUE;
+}
+
+/* --------------------------- CPWL_RadioButton ---------------------------- */
+
+CPWL_RadioButton::CPWL_RadioButton() : m_bChecked(FALSE)
+{
+}
+
+CPWL_RadioButton::~CPWL_RadioButton()
+{
+}
+
+CFX_ByteString CPWL_RadioButton::GetClassName() const
+{
+ return "CPWL_RadioButton";
+}
+
+FX_BOOL CPWL_RadioButton::OnLButtonUp(const CPDF_Point & point)
+{
+ if (IsReadOnly()) return FALSE;
+
+ SetCheck(TRUE);
+ return TRUE;
+}
+
+void CPWL_RadioButton::SetCheck(FX_BOOL bCheck)
+{
+ m_bChecked = bCheck;
+}
+
+FX_BOOL CPWL_RadioButton::IsChecked() const
+{
+ return m_bChecked;
+}
+
+FX_BOOL CPWL_RadioButton::OnChar(FX_WORD nChar)
+{
+ SetCheck(TRUE);
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_Utils.cpp b/fpdfsdk/src/pdfwindow/PWL_Utils.cpp
index aec1d4db45..1de6b56d5e 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Utils.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Utils.cpp
@@ -1,2844 +1,2844 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-#include "../../include/pdfwindow/PWL_Icon.h"
-
-#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
-#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
-#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
-
-/* ---------------------------- CPWL_Utils ------------------------------ */
-
-CFX_ByteString CPWL_Utils::GetAppStreamFromArray(const CPWL_PathData* pPathData, FX_INT32 nCount)
-{
- CFX_ByteTextBuf csAP;
-
- for (FX_INT32 i=0; i<nCount; i++)
- {
- switch (pPathData[i].type)
- {
- case PWLPT_MOVETO:
- csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " m\n";
- break;
- case PWLPT_LINETO:
- csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " l\n";
- break;
- case PWLPT_BEZIERTO:
- csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " "
- << pPathData[i+1].point.x << " " << pPathData[i+1].point.y << " "
- << pPathData[i+2].point.x << " " << pPathData[i+2].point.y << " c\n";
-
- i += 2;
- break;
- default:
- break;
- }
- }
-
- return csAP.GetByteString();
-}
-
-void CPWL_Utils::GetPathDataFromArray(CFX_PathData& path, const CPWL_PathData* pPathData, FX_INT32 nCount)
-{
- path.SetPointCount(nCount);
-
- for (FX_INT32 i=0; i<nCount; i++)
- {
- switch (pPathData[i].type)
- {
- case PWLPT_MOVETO:
- path.SetPoint(i, pPathData[i].point.x, pPathData[i].point.y, FXPT_MOVETO);
- break;
- case PWLPT_LINETO:
- path.SetPoint(i, pPathData[i].point.x, pPathData[i].point.y, FXPT_LINETO);
- break;
- case PWLPT_BEZIERTO:
- path.SetPoint(i, pPathData[i].point.x, pPathData[i].point.y, FXPT_BEZIERTO);
- break;
- default:
- break;
- }
- }
-}
-
-
-CPDF_Rect CPWL_Utils::MaxRect(const CPDF_Rect & rect1,const CPDF_Rect & rect2)
-{
- CPDF_Rect rcRet;
-
- rcRet.left = PWL_MIN(rect1.left,rect2.left);
- rcRet.bottom = PWL_MIN(rect1.bottom,rect2.bottom);
- rcRet.right = PWL_MAX(rect1.right,rect2.right);
- rcRet.top = PWL_MAX(rect1.top,rect2.top);
-
- return rcRet;
-}
-
-CPDF_Rect CPWL_Utils::OffsetRect(const CPDF_Rect & rect,FX_FLOAT x,FX_FLOAT y)
-{
- return CPDF_Rect(rect.left + x,rect.bottom + y,
- rect.right + x,rect.top + y);
-}
-
-FX_BOOL CPWL_Utils::ContainsRect(const CPDF_Rect& rcParent, const CPDF_Rect& rcChild)
-{
- return rcChild.left >= rcParent.left && rcChild.bottom >= rcParent.bottom &&
- rcChild.right <= rcParent.right && rcChild.top <= rcParent.top;
-}
-
-FX_BOOL CPWL_Utils::IntersectRect(const CPDF_Rect& rect1, const CPDF_Rect& rect2)
-{
- FX_FLOAT left = rect1.left > rect2.left ? rect1.left : rect2.left;
- FX_FLOAT right = rect1.right < rect2.right ? rect1.right : rect2.right;
- FX_FLOAT bottom = rect1.bottom > rect2.bottom ? rect1.bottom : rect2.bottom;
- FX_FLOAT top = rect1.top < rect2.top ? rect1.top : rect2.top;
-
- return left < right && bottom < top;
-}
-
-CPDF_Point CPWL_Utils::OffsetPoint(const CPDF_Point& point,FX_FLOAT x,FX_FLOAT y)
-{
- return CPDF_Point(point.x + x,point.y + y);
-}
-
-CPVT_WordRange CPWL_Utils::OverlapWordRange(const CPVT_WordRange & wr1, const CPVT_WordRange & wr2)
-{
- CPVT_WordRange wrRet;
-
- if (wr2.EndPos.WordCmp(wr1.BeginPos) < 0 || wr2.BeginPos.WordCmp(wr1.EndPos) > 0) return wrRet;
- if (wr1.EndPos.WordCmp(wr2.BeginPos) < 0 || wr1.BeginPos.WordCmp(wr2.EndPos) > 0) return wrRet;
-
- if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0)
- {
- wrRet.BeginPos = wr2.BeginPos;
- }
- else
- {
- wrRet.BeginPos = wr1.BeginPos;
- }
-
- if (wr1.EndPos.WordCmp(wr2.EndPos) < 0)
- {
- wrRet.EndPos = wr1.EndPos;
- }
- else
- {
- wrRet.EndPos = wr2.EndPos;
- }
-
- return wrRet;
-}
-
-CFX_ByteString CPWL_Utils::GetAP_Check(const CPDF_Rect & crBBox)
-{
- CFX_ByteTextBuf csAP;
-
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- const FX_INT32 num = 8;
-
- CPWL_Point pts[num*3] =
- {
- //1
- CPWL_Point(0.28f, 0.52f),
- CPWL_Point(0.27f, 0.48f),
- CPWL_Point(0.29f, 0.40f),
-
- //2
- CPWL_Point(0.30f, 0.33f),
- CPWL_Point(0.31f, 0.29f),
- CPWL_Point(0.31f, 0.28f),
-
- //3
- CPWL_Point(0.39f, 0.28f),
- CPWL_Point(0.49f, 0.29f),
- CPWL_Point(0.77f, 0.67f),
-
- //4
- CPWL_Point(0.76f, 0.68f),
- CPWL_Point(0.78f, 0.69f),
- CPWL_Point(0.76f, 0.75f),
-
- //5
- CPWL_Point(0.76f, 0.75f),
- CPWL_Point(0.73f, 0.80f),
- CPWL_Point(0.68f, 0.75f),
-
- //6
- CPWL_Point(0.68f, 0.74f),
- CPWL_Point(0.68f, 0.74f),
- CPWL_Point(0.44f, 0.47f),
-
- //7
- CPWL_Point(0.43f, 0.47f),
- CPWL_Point(0.40f, 0.47f),
- CPWL_Point(0.41f, 0.58f),
-
- //8
- CPWL_Point(0.40f, 0.60f),
- CPWL_Point(0.28f, 0.66f),
- CPWL_Point(0.30f, 0.56f)
- };
-
- for (FX_INT32 j=0; j<num*3; j++)
- {
- pts[j].x *= fWidth;
- pts[j].x += crBBox.left;
-
- pts[j].y *= fHeight;
- pts[j].y += crBBox.bottom;
- }
-
- csAP << pts[0].x << " " << pts[0].y << " m\n";
-
- for (FX_INT32 i=0; i<num; i++)
- {
- FX_INT32 nCur = i*3;
- FX_INT32 n1 = i*3 + 1;
- FX_INT32 n2 = i*3 + 2;
- FX_INT32 nNext = (i < num-1 ? (i+1)*3 : 0);
-
- FX_FLOAT px1 = pts[n1].x - pts[nCur].x;
- FX_FLOAT py1 = pts[n1].y - pts[nCur].y;
- FX_FLOAT px2 = pts[n2].x - pts[nNext].x;
- FX_FLOAT py2 = pts[n2].y - pts[nNext].y;
-
- csAP << pts[nCur].x + px1 * PWL_BEZIER << " " << pts[nCur].y + py1 * PWL_BEZIER << " "
- << pts[nNext].x + px2 * PWL_BEZIER << " " << pts[nNext].y + py2 * PWL_BEZIER << " "
- << pts[nNext].x << " " << pts[nNext].y << " c\n";
- }
-
- return csAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAP_Circle(const CPDF_Rect & crBBox)
-{
- CFX_ByteTextBuf csAP;
-
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPDF_Point pt1(crBBox.left,crBBox.bottom + fHeight / 2);
- CPDF_Point pt2(crBBox.left + fWidth / 2,crBBox.top);
- CPDF_Point pt3(crBBox.right,crBBox.bottom + fHeight / 2);
- CPDF_Point pt4(crBBox.left + fWidth / 2,crBBox.bottom);
-
- csAP << pt1.x << " " << pt1.y << " m\n";
-
- FX_FLOAT px = pt2.x - pt1.x;
- FX_FLOAT py = pt2.y - pt1.y;
-
- csAP << pt1.x << " " << pt1.y + py * PWL_BEZIER << " "
- << pt2.x - px * PWL_BEZIER << " " << pt2.y << " "
- << pt2.x << " " << pt2.y << " c\n";
-
- px = pt3.x - pt2.x;
- py = pt2.y - pt3.y;
-
- csAP << pt2.x + px * PWL_BEZIER << " " << pt2.y << " "
- << pt3.x << " " << pt3.y + py * PWL_BEZIER << " "
- << pt3.x << " " << pt3.y << " c\n";
-
- px = pt3.x - pt4.x;
- py = pt3.y - pt4.y;
-
- csAP << pt3.x << " " << pt3.y - py * PWL_BEZIER << " "
- << pt4.x + px * PWL_BEZIER << " " << pt4.y << " "
- << pt4.x << " " << pt4.y << " c\n";
-
- px = pt4.x - pt1.x;
- py = pt1.y - pt4.y;
-
- csAP << pt4.x - px * PWL_BEZIER << " " << pt4.y << " "
- << pt1.x << " " << pt1.y - py * PWL_BEZIER << " "
- << pt1.x << " " << pt1.y << " c\n";
-
- return csAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAP_Cross(const CPDF_Rect & crBBox)
-{
- CFX_ByteTextBuf csAP;
-
- csAP << crBBox.left << " " << crBBox.top << " m\n";
- csAP << crBBox.right << " " << crBBox.bottom << " l\n";
- csAP << crBBox.left << " " << crBBox.bottom << " m\n";
- csAP << crBBox.right << " " << crBBox.top << " l\n";
-
- return csAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAP_Diamond(const CPDF_Rect & crBBox)
-{
- CFX_ByteTextBuf csAP;
-
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPDF_Point pt1(crBBox.left,crBBox.bottom + fHeight / 2);
- CPDF_Point pt2(crBBox.left + fWidth / 2,crBBox.top);
- CPDF_Point pt3(crBBox.right,crBBox.bottom + fHeight / 2);
- CPDF_Point pt4(crBBox.left + fWidth / 2,crBBox.bottom);
-
- csAP << pt1.x << " " << pt1.y << " m\n";
- csAP << pt2.x << " " << pt2.y << " l\n";
- csAP << pt3.x << " " << pt3.y << " l\n";
- csAP << pt4.x << " " << pt4.y << " l\n";
- csAP << pt1.x << " " << pt1.y << " l\n";
-
- return csAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAP_Square(const CPDF_Rect & crBBox)
-{
- CFX_ByteTextBuf csAP;
-
- csAP << crBBox.left << " " << crBBox.top << " m\n";
- csAP << crBBox.right << " " << crBBox.top << " l\n";
- csAP << crBBox.right << " " << crBBox.bottom << " l\n";
- csAP << crBBox.left << " " << crBBox.bottom << " l\n";
- csAP << crBBox.left << " " << crBBox.top << " l\n";
-
- return csAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAP_Star(const CPDF_Rect & crBBox)
-{
- CFX_ByteTextBuf csAP;
-
- FX_FLOAT fRadius = (crBBox.top - crBBox.bottom)/(1+(FX_FLOAT)cos(PWL_PI/5.0f));
- CPDF_Point ptCenter = CPDF_Point((crBBox.left + crBBox.right) / 2.0f,(crBBox.top + crBBox.bottom) / 2.0f);
-
- FX_FLOAT px[5],py[5];
-
- FX_FLOAT fAngel = PWL_PI/10.0f;
-
- for (FX_INT32 i=0; i<5; i++)
- {
- px[i] = ptCenter.x + fRadius * (FX_FLOAT)cos(fAngel);
- py[i] = ptCenter.y + fRadius * (FX_FLOAT)sin(fAngel);
-
- fAngel += PWL_PI * 2 / 5.0f;
- }
-
- csAP << px[0] << " " << py[0] << " m\n";
-
- FX_INT32 nNext = 0;
- for (FX_INT32 j=0; j<5; j++)
- {
- nNext += 2;
- if (nNext >= 5) nNext -= 5;
- csAP << px[nNext] << " " << py[nNext] << " l\n";
- }
-
- return csAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAP_HalfCircle(const CPDF_Rect & crBBox,FX_FLOAT fRotate)
-{
- CFX_ByteTextBuf csAP;
-
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPDF_Point pt1(-fWidth/2,0);
- CPDF_Point pt2(0,fHeight/2);
- CPDF_Point pt3(fWidth/2,0);
-
- FX_FLOAT px,py;
-
- csAP << cos(fRotate) << " " << sin(fRotate) << " " << -sin(fRotate) << " " << cos(fRotate) << " "
- << crBBox.left + fWidth / 2 << " " << crBBox.bottom + fHeight / 2 << " cm\n";
-
-
- csAP << pt1.x << " " << pt1.y << " m\n";
-
- px = pt2.x - pt1.x;
- py = pt2.y - pt1.y;
-
- csAP << pt1.x << " " << pt1.y + py * PWL_BEZIER << " "
- << pt2.x - px * PWL_BEZIER << " " << pt2.y << " "
- << pt2.x << " " << pt2.y << " c\n";
-
- px = pt3.x - pt2.x;
- py = pt2.y - pt3.y;
-
- csAP << pt2.x + px * PWL_BEZIER << " " << pt2.y << " "
- << pt3.x << " " << pt3.y + py * PWL_BEZIER << " "
- << pt3.x << " " << pt3.y << " c\n";
-
- return csAP.GetByteString();
-}
-
-
-CPDF_Rect CPWL_Utils::InflateRect(const CPDF_Rect & rcRect, FX_FLOAT fSize)
-{
- if (rcRect.IsEmpty()) return rcRect;
-
- CPDF_Rect rcNew(rcRect.left - fSize,
- rcRect.bottom - fSize,
- rcRect.right + fSize,
- rcRect.top + fSize);
- rcNew.Normalize();
- return rcNew;
-}
-
-CPDF_Rect CPWL_Utils::DeflateRect(const CPDF_Rect & rcRect, FX_FLOAT fSize)
-{
- if (rcRect.IsEmpty()) return rcRect;
-
- CPDF_Rect rcNew(rcRect.left + fSize,
- rcRect.bottom + fSize,
- rcRect.right - fSize,
- rcRect.top - fSize);
- rcNew.Normalize();
- return rcNew;
-}
-
-CPDF_Rect CPWL_Utils::ScaleRect(const CPDF_Rect & rcRect,FX_FLOAT fScale)
-{
- FX_FLOAT fHalfWidth = (rcRect.right - rcRect.left) / 2.0f;
- FX_FLOAT fHalfHeight = (rcRect.top - rcRect.bottom) / 2.0f;
-
- CPDF_Point ptCenter = CPDF_Point((rcRect.left + rcRect.right) / 2,(rcRect.top + rcRect.bottom) / 2);
-
- return CPDF_Rect(ptCenter.x - fHalfWidth * fScale,
- ptCenter.y - fHalfHeight * fScale,
- ptCenter.x + fHalfWidth * fScale,
- ptCenter.y + fHalfHeight * fScale);
-}
-
-CFX_ByteString CPWL_Utils::GetRectFillAppStream(const CPDF_Rect & rect,const CPWL_Color & color)
-{
- CFX_ByteTextBuf sAppStream;
-
- CFX_ByteString sColor = GetColorAppStream(color,TRUE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << sColor;
- sAppStream << rect.left << " " << rect.bottom << " "
- << rect.right - rect.left << " " << rect.top - rect.bottom << " re f\nQ\n";
- }
-
- return sAppStream.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetCircleFillAppStream(const CPDF_Rect & rect,const CPWL_Color & color)
-{
- CFX_ByteTextBuf sAppStream;
-
- CFX_ByteString sColor = GetColorAppStream(color,TRUE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << sColor << CPWL_Utils::GetAP_Circle(rect) << "f\nQ\n";
- }
-
- return sAppStream.GetByteString();
-}
-
-CPDF_Rect CPWL_Utils::GetCenterSquare(const CPDF_Rect & rect)
-{
- FX_FLOAT fWidth = rect.right - rect.left;
- FX_FLOAT fHeight = rect.top - rect.bottom;
-
- FX_FLOAT fCenterX = (rect.left + rect.right)/2.0f;
- FX_FLOAT fCenterY = (rect.top + rect.bottom)/2.0f;
-
- FX_FLOAT fRadius = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2;
-
- return CPDF_Rect(fCenterX - fRadius,fCenterY - fRadius,fCenterX + fRadius,fCenterY + fRadius);
-}
-
-CFX_ByteString CPWL_Utils::GetEditAppStream(IFX_Edit* pEdit, const CPDF_Point & ptOffset, const CPVT_WordRange * pRange,
- FX_BOOL bContinuous, FX_WORD SubWord)
-{
- return IFX_Edit::GetEditAppearanceStream(pEdit,ptOffset,pRange,bContinuous,SubWord);
-}
-
-CFX_ByteString CPWL_Utils::GetEditSelAppStream(IFX_Edit* pEdit, const CPDF_Point & ptOffset,
- const CPVT_WordRange * pRange)
-{
- return IFX_Edit::GetSelectAppearanceStream(pEdit,ptOffset,pRange);
-}
-
-static CFX_ByteString GetSquigglyAppearanceStream(FX_FLOAT fStartX, FX_FLOAT fEndX, FX_FLOAT fY, FX_FLOAT fStep)
-{
- CFX_ByteTextBuf sRet;
-
- sRet << "0 w\n" << fStartX << " " << fY << " m\n";
-
- FX_FLOAT fx;
- FX_INT32 i;
-
- for (i=1,fx=fStartX+fStep; fx<fEndX; fx+=fStep,i++)
- {
- sRet << fx << " " << fY + (i&1)*fStep << " l\n";
- }
-
- sRet << "S\n";
-
- return sRet.GetByteString();
-}
-
-static CFX_ByteString GetWordSpellCheckAppearanceStream(IFX_Edit_Iterator* pIterator, const CPDF_Point & ptOffset,
- const CPVT_WordRange & wrWord)
-{
- CFX_ByteTextBuf sRet;
-
- FX_FLOAT fStartX = 0.0f;
- FX_FLOAT fEndX = 0.0f;
- FX_FLOAT fY = 0.0f;
- FX_FLOAT fStep = 0.0f;
-
- FX_BOOL bBreak = FALSE;
-
- if (pIterator)
- {
- pIterator->SetAt(wrWord.BeginPos);
-
- do
- {
- CPVT_WordPlace place = pIterator->GetAt();
-
- CPVT_Line line;
- if (pIterator->GetLine(line))
- {
- fY = line.ptLine.y;
- fStep = (line.fLineAscent - line.fLineDescent) / 16.0f;
- }
-
- if (place.LineCmp(wrWord.BeginPos) == 0)
- {
- pIterator->SetAt(wrWord.BeginPos);
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- fStartX = word.ptWord.x;
- }
- }
- else
- {
- fStartX = line.ptLine.x;
- }
-
- if (place.LineCmp(wrWord.EndPos) == 0)
- {
- pIterator->SetAt(wrWord.EndPos);
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- fEndX = word.ptWord.x + word.fWidth;
- }
-
- bBreak = TRUE;
- }
- else
- {
- fEndX = line.ptLine.x + line.fLineWidth;
- }
-
- sRet << GetSquigglyAppearanceStream(fStartX + ptOffset.x, fEndX + ptOffset.x, fY + ptOffset.y,fStep);
-
- if (bBreak) break;
- }
- while (pIterator->NextLine());
- }
-
- return sRet.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetSpellCheckAppStream(IFX_Edit* pEdit, IPWL_SpellCheck* pSpellCheck, const CPDF_Point & ptOffset,
- const CPVT_WordRange * pRange)
-{
- ASSERT(pEdit != NULL);
- ASSERT(pSpellCheck != NULL);
-
- CFX_ByteTextBuf sRet;
-
- if (pRange && pRange->IsExist())
- {
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- pIterator->SetAt(pRange->BeginPos);
-
- FX_BOOL bLatinWord = FALSE;
- CPVT_WordPlace wpWordStart;
- CFX_ByteString sWord;
-
- CPVT_WordPlace oldplace;
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- if (FX_EDIT_ISLATINWORD(word.Word))
- {
- if (!bLatinWord)
- {
- wpWordStart = place;
- bLatinWord = TRUE;
- }
-
- sWord += (char)word.Word;
- oldplace = place;
- }
- else
- {
- if (bLatinWord)
- {
- if (!pSpellCheck->CheckWord(sWord))
- {
- sRet << GetWordSpellCheckAppearanceStream(pIterator,ptOffset,CPVT_WordRange(wpWordStart,oldplace));
- pIterator->SetAt(place);
- }
- bLatinWord = FALSE;
- }
-
- sWord.Empty();
- }
- }
- else
- {
- if (bLatinWord)
- {
- if (!pSpellCheck->CheckWord(sWord))
- sRet << GetWordSpellCheckAppearanceStream(pIterator,ptOffset,CPVT_WordRange(wpWordStart,oldplace));
- bLatinWord = FALSE;
- sWord.Empty();
- }
- }
- }
-
- if (bLatinWord)
- {
- if (!pSpellCheck->CheckWord(sWord))
- sRet << GetWordSpellCheckAppearanceStream(pIterator,ptOffset,CPVT_WordRange(wpWordStart,oldplace));
-
- bLatinWord = FALSE;
- sWord.Empty();
- }
- }
- }
-
- return sRet.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetTextAppStream(const CPDF_Rect & rcBBox,IFX_Edit_FontMap * pFontMap,
- const CFX_WideString & sText, FX_INT32 nAlignmentH, FX_INT32 nAlignmentV,
- FX_FLOAT fFontSize, FX_BOOL bMultiLine, FX_BOOL bAutoReturn, const CPWL_Color & crText)
-{
- CFX_ByteTextBuf sRet;
-
- if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
- {
- pEdit->SetFontMap(pFontMap);
-
- pEdit->SetPlateRect(rcBBox);
- pEdit->SetAlignmentH(nAlignmentH);
- pEdit->SetAlignmentV(nAlignmentV);
- pEdit->SetMultiLine(bMultiLine);
- pEdit->SetAutoReturn(bAutoReturn);
- if (IsFloatZero(fFontSize))
- pEdit->SetAutoFontSize(TRUE);
- else
- pEdit->SetFontSize(fFontSize);
- pEdit->Initialize();
-
- pEdit->SetText(sText);
-
- CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit, CPDF_Point(0.0f,0.0f));
- if (sEdit.GetLength() > 0)
- {
- sRet << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n";
- }
-
- IFX_Edit::DelEdit(pEdit);
- }
-
- return sRet.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CPDF_Rect & rcBBox,
- IFX_Edit_FontMap * pFontMap,
- CPDF_Stream * pIconStream,
- CPDF_IconFit & IconFit,
- const CFX_WideString & sLabel,
- const CPWL_Color & crText,
- FX_FLOAT fFontSize,
- FX_INT32 nLayOut)
-{
- const FX_FLOAT fAutoFontScale = 1.0f / 3.0f;
-
- if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
- {
- pEdit->SetFontMap(pFontMap);
-
- pEdit->SetAlignmentH(1);
- pEdit->SetAlignmentV(1);
- pEdit->SetMultiLine(FALSE);
- pEdit->SetAutoReturn(FALSE);
- if (IsFloatZero(fFontSize))
- pEdit->SetAutoFontSize(TRUE);
- else
- pEdit->SetFontSize(fFontSize);
- pEdit->Initialize();
- pEdit->SetText(sLabel);
-
- CPDF_Rect rcLabelContent = pEdit->GetContentRect();
-
- CPWL_Icon Icon;
- PWL_CREATEPARAM cp;
- cp.dwFlags = PWS_VISIBLE;
- Icon.Create(cp);
- Icon.SetIconFit(&IconFit);
- Icon.SetPDFStream(pIconStream);
-
- CPDF_Rect rcLabel = CPDF_Rect(0,0,0,0);
- CPDF_Rect rcIcon = CPDF_Rect(0,0,0,0);
- FX_FLOAT fWidth = 0.0f;
- FX_FLOAT fHeight = 0.0f;
-
- switch (nLayOut)
- {
- case PPBL_LABEL:
- rcLabel = rcBBox;
- rcIcon = CPDF_Rect(0,0,0,0);
- break;
- case PPBL_ICON:
- rcIcon = rcBBox;
- rcLabel = CPDF_Rect(0,0,0,0);
- break;
- case PPBL_ICONTOPLABELBOTTOM:
-
- if (pIconStream)
- {
- if (IsFloatZero(fFontSize))
- {
- fHeight = rcBBox.top - rcBBox.bottom;
- rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.right,rcBBox.bottom + fHeight * fAutoFontScale);
- rcIcon = CPDF_Rect(rcBBox.left,rcLabel.top,rcBBox.right,rcBBox.top);
- }
- else
- {
- fHeight = rcLabelContent.Height();
-
- if (rcBBox.bottom + fHeight > rcBBox.top)
- {
- rcIcon = CPDF_Rect(0,0,0,0);
- rcLabel = rcBBox;
- }
- else
- {
- rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.right,rcBBox.bottom + fHeight);
- rcIcon = CPDF_Rect(rcBBox.left,rcLabel.top,rcBBox.right,rcBBox.top);
- }
- }
- }
- else
- {
- rcLabel = rcBBox;
- rcIcon = CPDF_Rect(0,0,0,0);
- }
-
- break;
- case PPBL_LABELTOPICONBOTTOM:
-
- if (pIconStream)
- {
- if (IsFloatZero(fFontSize))
- {
- fHeight = rcBBox.top - rcBBox.bottom;
- rcLabel = CPDF_Rect(rcBBox.left,rcBBox.top - fHeight * fAutoFontScale ,rcBBox.right,rcBBox.top);
- rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.right,rcLabel.bottom);
- }
- else
- {
- fHeight = rcLabelContent.Height();
-
- if (rcBBox.bottom + fHeight > rcBBox.top)
- {
- rcIcon = CPDF_Rect(0,0,0,0);
- rcLabel = rcBBox;
- }
- else
- {
- rcLabel = CPDF_Rect(rcBBox.left,rcBBox.top - fHeight,rcBBox.right,rcBBox.top);
- rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.right,rcLabel.bottom);
- }
- }
- }
- else
- {
- rcLabel = rcBBox;
- rcIcon = CPDF_Rect(0,0,0,0);
- }
-
- break;
- case PPBL_ICONLEFTLABELRIGHT:
-
- if (pIconStream)
- {
- if (IsFloatZero(fFontSize))
- {
- fWidth = rcBBox.right - rcBBox.left;
- rcLabel = CPDF_Rect(rcBBox.right - fWidth * fAutoFontScale,rcBBox.bottom,rcBBox.right,rcBBox.top);
- rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcLabel.left,rcBBox.top);
-
- if (rcLabelContent.Width() < fWidth * fAutoFontScale)
- {
- }
- else
- {
- if (rcLabelContent.Width() < fWidth)
- {
- rcLabel = CPDF_Rect(rcBBox.right - rcLabelContent.Width(),rcBBox.bottom,rcBBox.right,rcBBox.top);
- rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcLabel.left,rcBBox.top);
- }
- else
- {
- rcLabel = rcBBox;
- rcIcon = CPDF_Rect(0,0,0,0);
- }
- }
- }
- else
- {
- fWidth = rcLabelContent.Width();
-
- if (rcBBox.left + fWidth > rcBBox.right)
- {
- rcLabel = rcBBox;
- rcIcon = CPDF_Rect(0,0,0,0);
- }
- else
- {
- rcLabel = CPDF_Rect(rcBBox.right - fWidth,rcBBox.bottom,rcBBox.right,rcBBox.top);
- rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcLabel.left,rcBBox.top);
- }
- }
- }
- else
- {
- rcLabel = rcBBox;
- rcIcon = CPDF_Rect(0,0,0,0);
- }
-
- break;
- case PPBL_LABELLEFTICONRIGHT:
-
- if (pIconStream)
- {
- if (IsFloatZero(fFontSize))
- {
- fWidth = rcBBox.right - rcBBox.left;
- rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.left + fWidth * fAutoFontScale,rcBBox.top);
- rcIcon = CPDF_Rect(rcLabel.right,rcBBox.bottom,rcBBox.right,rcBBox.top);
-
- if (rcLabelContent.Width() < fWidth * fAutoFontScale)
- {
- }
- else
- {
- if (rcLabelContent.Width() < fWidth)
- {
- rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.left + rcLabelContent.Width(),rcBBox.top);
- rcIcon = CPDF_Rect(rcLabel.right,rcBBox.bottom,rcBBox.right,rcBBox.top);
- }
- else
- {
- rcLabel = rcBBox;
- rcIcon = CPDF_Rect(0,0,0,0);
- }
- }
- }
- else
- {
- fWidth = rcLabelContent.Width();
-
- if (rcBBox.left + fWidth > rcBBox.right)
- {
- rcLabel = rcBBox;
- rcIcon = CPDF_Rect(0,0,0,0);
- }
- else
- {
- rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.left + fWidth,rcBBox.top);
- rcIcon = CPDF_Rect(rcLabel.right,rcBBox.bottom,rcBBox.right,rcBBox.top);
- }
- }
- }
- else
- {
- rcLabel = rcBBox;
- rcIcon = CPDF_Rect(0,0,0,0);
- }
-
- break;
- case PPBL_LABELOVERICON:
- rcLabel = rcBBox;
- rcIcon = rcBBox;
- break;
- }
-
- CFX_ByteTextBuf sAppStream,sTemp;
-
- if (!rcIcon.IsEmpty())
- {
- Icon.Move(rcIcon, FALSE, FALSE);
- sTemp << Icon.GetImageAppStream();
- }
-
- Icon.Destroy();
-
- if (!rcLabel.IsEmpty())
- {
- pEdit->SetPlateRect(rcLabel);
- CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f));
- if (sEdit.GetLength() > 0)
- {
- sTemp << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n";
- }
- }
-
- IFX_Edit::DelEdit(pEdit);
-
- if (sTemp.GetSize() > 0)
- {
- sAppStream << "q\n" << rcBBox.left << " " << rcBBox.bottom << " "
- << rcBBox.right - rcBBox.left << " " << rcBBox.top - rcBBox.bottom << " re W n\n";
- sAppStream << sTemp << "Q\n";
- }
-
- return sAppStream.GetByteString();
- }
-
- return "";
-}
-
-CFX_ByteString CPWL_Utils::GetColorAppStream(const CPWL_Color & color,const FX_BOOL & bFillOrStroke)
-{
- CFX_ByteTextBuf sColorStream;
-
- switch (color.nColorType)
- {
- case COLORTYPE_RGB:
- sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " "
- << (bFillOrStroke ? "rg" : "RG") << "\n";
- break;
- case COLORTYPE_GRAY:
- sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") << "\n";
- break;
- case COLORTYPE_CMYK:
- sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " " << color.fColor4 << " "
- << (bFillOrStroke ? "k" : "K") << "\n";
- break;
- }
-
- return sColorStream.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetBorderAppStream(const CPDF_Rect & rect, FX_FLOAT fWidth,
- const CPWL_Color & color, const CPWL_Color & crLeftTop, const CPWL_Color & crRightBottom,
- FX_INT32 nStyle, const CPWL_Dash & dash)
-{
- CFX_ByteTextBuf sAppStream;
- CFX_ByteString sColor;
-
- FX_FLOAT fLeft = rect.left;
- FX_FLOAT fRight = rect.right;
- FX_FLOAT fTop = rect.top;
- FX_FLOAT fBottom = rect.bottom;
-
- if (fWidth > 0.0f)
- {
- FX_FLOAT fHalfWidth = fWidth / 2.0f;
-
- sAppStream << "q\n";
-
- switch (nStyle)
- {
- default:
- case PBS_SOLID:
- sColor = CPWL_Utils::GetColorAppStream(color,TRUE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << sColor;
- sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " << fTop - fBottom << " re\n";
- sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " "
- << fRight - fLeft - fWidth * 2 << " " << fTop - fBottom - fWidth * 2 << " re\n";
- sAppStream << "f*\n";
- }
- break;
- case PBS_DASH:
- sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << sColor;
- sAppStream << fWidth << " w" << " [" << dash.nDash << " " << dash.nGap << "] " << dash.nPhase << " d\n";
- sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 << " m\n";
- sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2 << " l\n";
- sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2 << " l\n";
- sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2 << " l\n";
- sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 << " l S\n";
- }
- break;
- case PBS_BEVELED:
- case PBS_INSET:
- sColor = CPWL_Utils::GetColorAppStream(crLeftTop,TRUE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << sColor;
- sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " m\n";
- sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth << " l\n";
- sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth << " l\n";
- sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 << " l\n";
- sAppStream << fLeft + fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 << " l\n";
- sAppStream << fLeft + fHalfWidth * 2 << " " << fBottom + fHalfWidth * 2 << " l f\n";
- }
-
- sColor = CPWL_Utils::GetColorAppStream(crRightBottom,TRUE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << sColor;
- sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth << " m\n";
- sAppStream << fRight - fHalfWidth << " " << fBottom + fHalfWidth << " l\n";
- sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " l\n";
- sAppStream << fLeft + fHalfWidth * 2 << " " << fBottom + fHalfWidth * 2 << " l\n";
- sAppStream << fRight - fHalfWidth * 2 << " " << fBottom + fHalfWidth * 2 << " l\n";
- sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 << " l f\n";
- }
-
- sColor = CPWL_Utils::GetColorAppStream(color,TRUE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << sColor;
- sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " << fTop - fBottom << " re\n";
- sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " "
- << fRight - fLeft - fHalfWidth * 2 << " " << fTop - fBottom - fHalfWidth * 2 << " re f*\n";
- }
- break;
- case PBS_UNDERLINED:
- sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << sColor;
- sAppStream << fWidth << " w\n";
- sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n";
- sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n";
- }
- break;
- }
-
- sAppStream << "Q\n";
- }
-
- return sAppStream.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetCircleBorderAppStream(const CPDF_Rect & rect, FX_FLOAT fWidth,
- const CPWL_Color & color, const CPWL_Color & crLeftTop, const CPWL_Color & crRightBottom,
- FX_INT32 nStyle, const CPWL_Dash & dash)
-{
- CFX_ByteTextBuf sAppStream;
- CFX_ByteString sColor;
-
-
-
-
-
-
- if (fWidth > 0.0f)
- {
- sAppStream << "q\n";
-
- switch (nStyle)
- {
- default:
- case PBS_SOLID:
- case PBS_UNDERLINED:
- {
- sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << fWidth << " w\n" << sColor
- << CPWL_Utils::GetAP_Circle(CPWL_Utils::DeflateRect(rect,fWidth / 2.0f))
- << " S\nQ\n";
- }
- }
- break;
- case PBS_DASH:
- {
- sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << fWidth << " w\n"
- << "[" << dash.nDash << " " << dash.nGap << "] " << dash.nPhase << " d\n"
- << sColor << CPWL_Utils::GetAP_Circle(CPWL_Utils::DeflateRect(rect,fWidth / 2.0f))
- << " S\nQ\n";
- }
- }
- break;
- case PBS_BEVELED:
- {
- FX_FLOAT fHalfWidth = fWidth / 2.0f;
-
- sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << fHalfWidth << " w\n"
- << sColor << CPWL_Utils::GetAP_Circle(rect)
- << " S\nQ\n";
- }
-
- sColor = CPWL_Utils::GetColorAppStream(crLeftTop,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << fHalfWidth << " w\n"
- << sColor << CPWL_Utils::GetAP_HalfCircle(CPWL_Utils::DeflateRect(rect,fHalfWidth * 0.75f),PWL_PI/4.0f)
- << " S\nQ\n";
- }
-
- sColor = CPWL_Utils::GetColorAppStream(crRightBottom,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << fHalfWidth << " w\n"
- << sColor << CPWL_Utils::GetAP_HalfCircle(CPWL_Utils::DeflateRect(rect,fHalfWidth * 0.75f),PWL_PI*5/4.0f)
- << " S\nQ\n";
- }
- }
- break;
- case PBS_INSET:
- {
- FX_FLOAT fHalfWidth = fWidth / 2.0f;
-
- sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << fHalfWidth << " w\n"
- << sColor << CPWL_Utils::GetAP_Circle(rect)
- << " S\nQ\n";
- }
-
- sColor = CPWL_Utils::GetColorAppStream(crLeftTop,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << fHalfWidth << " w\n"
- << sColor << CPWL_Utils::GetAP_HalfCircle(CPWL_Utils::DeflateRect(rect,fHalfWidth * 0.75f),PWL_PI/4.0f)
- << " S\nQ\n";
- }
-
- sColor = CPWL_Utils::GetColorAppStream(crRightBottom,FALSE);
- if (sColor.GetLength() > 0)
- {
- sAppStream << "q\n" << fHalfWidth << " w\n"
- << sColor << CPWL_Utils::GetAP_HalfCircle(CPWL_Utils::DeflateRect(rect,fHalfWidth * 0.75f),PWL_PI*5/4.0f)
- << " S\nQ\n";
- }
- }
- break;
- }
-
- sAppStream << "Q\n";
- }
-
- return sAppStream.GetByteString();
-}
-
-CPWL_Color CPWL_Utils::SubstractColor(const CPWL_Color & sColor,FX_FLOAT fColorSub)
-{
- CPWL_Color sRet;
- sRet.nColorType = sColor.nColorType;
-
- switch (sColor.nColorType)
- {
- case COLORTYPE_TRANSPARENT:
- sRet.nColorType = COLORTYPE_RGB;
- sRet.fColor1 = PWL_MAX(1 - fColorSub,0.0f);
- sRet.fColor2 = PWL_MAX(1 - fColorSub,0.0f);
- sRet.fColor3 = PWL_MAX(1 - fColorSub,0.0f);
- break;
- case COLORTYPE_RGB:
- case COLORTYPE_GRAY:
- case COLORTYPE_CMYK:
- sRet.fColor1 = PWL_MAX(sColor.fColor1 - fColorSub,0.0f);
- sRet.fColor2 = PWL_MAX(sColor.fColor2 - fColorSub,0.0f);
- sRet.fColor3 = PWL_MAX(sColor.fColor3 - fColorSub,0.0f);
- sRet.fColor4 = PWL_MAX(sColor.fColor4 - fColorSub,0.0f);
- break;
- }
-
- return sRet;
-}
-
-CPWL_Color CPWL_Utils::DevideColor(const CPWL_Color & sColor,FX_FLOAT fColorDevide)
-{
- CPWL_Color sRet;
- sRet.nColorType = sColor.nColorType;
-
- switch (sColor.nColorType)
- {
- case COLORTYPE_TRANSPARENT:
- sRet.nColorType = COLORTYPE_RGB;
- sRet.fColor1 = 1 / fColorDevide;
- sRet.fColor2 = 1 / fColorDevide;
- sRet.fColor3 = 1 / fColorDevide;
- break;
- case COLORTYPE_RGB:
- case COLORTYPE_GRAY:
- case COLORTYPE_CMYK:
- sRet = sColor;
- sRet.fColor1 /= fColorDevide;
- sRet.fColor2 /= fColorDevide;
- sRet.fColor3 /= fColorDevide;
- sRet.fColor4 /= fColorDevide;
- break;
- }
-
- return sRet;
-}
-
-CFX_ByteString CPWL_Utils::GetAppStream_Check(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
-{
- CFX_ByteTextBuf sAP;
- sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Check(rcBBox) << "f\nQ\n";
- return sAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAppStream_Circle(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
-{
- CFX_ByteTextBuf sAP;
- sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Circle(rcBBox) << "f\nQ\n";
- return sAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAppStream_Cross(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
-{
- CFX_ByteTextBuf sAP;
- sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,FALSE) << CPWL_Utils::GetAP_Cross(rcBBox) << "S\nQ\n";
- return sAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAppStream_Diamond(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
-{
- CFX_ByteTextBuf sAP;
- sAP << "q\n1 w\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Diamond(rcBBox) << "f\nQ\n";
- return sAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAppStream_Square(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
-{
- CFX_ByteTextBuf sAP;
- sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Square(rcBBox) << "f\nQ\n";
- return sAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetAppStream_Star(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
-{
- CFX_ByteTextBuf sAP;
- sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Star(rcBBox) << "f\nQ\n";
- return sAP.GetByteString();
-}
-
-CFX_ByteString CPWL_Utils::GetCheckBoxAppStream(const CPDF_Rect & rcBBox,
- FX_INT32 nStyle,
- const CPWL_Color & crText)
-{
- CPDF_Rect rcCenter = GetCenterSquare(rcBBox);
- switch (nStyle)
- {
- default:
- case PCS_CHECK:
- return GetAppStream_Check(rcCenter,crText);
- case PCS_CIRCLE:
- return GetAppStream_Circle(ScaleRect(rcCenter,2.0f/3.0f),crText);
- case PCS_CROSS:
- return GetAppStream_Cross(rcCenter,crText);
- case PCS_DIAMOND:
- return GetAppStream_Diamond(ScaleRect(rcCenter,2.0f/3.0f),crText);
- case PCS_SQUARE:
- return GetAppStream_Square(ScaleRect(rcCenter,2.0f/3.0f),crText);
- case PCS_STAR:
- return GetAppStream_Star(ScaleRect(rcCenter,2.0f/3.0f),crText);
- }
-}
-
-CFX_ByteString CPWL_Utils::GetRadioButtonAppStream(const CPDF_Rect & rcBBox,
- FX_INT32 nStyle,
- const CPWL_Color & crText)
-{
- CPDF_Rect rcCenter = GetCenterSquare(rcBBox);
- switch (nStyle)
- {
- default:
- case PCS_CHECK:
- return GetAppStream_Check(rcCenter,crText);
- case PCS_CIRCLE:
- return GetAppStream_Circle(ScaleRect(rcCenter,1.0f/2.0f),crText);
- case PCS_CROSS:
- return GetAppStream_Cross(rcCenter,crText);
- case PCS_DIAMOND:
- return GetAppStream_Diamond(ScaleRect(rcCenter,2.0f/3.0f),crText);
- case PCS_SQUARE:
- return GetAppStream_Square(ScaleRect(rcCenter,2.0f/3.0f),crText);
- case PCS_STAR:
- return GetAppStream_Star(ScaleRect(rcCenter,2.0f/3.0f),crText);
- }
-}
-
-CFX_ByteString CPWL_Utils::GetDropButtonAppStream(const CPDF_Rect & rcBBox)
-{
- CFX_ByteTextBuf sAppStream;
-
- if (!rcBBox.IsEmpty())
- {
- sAppStream << "q\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,220.0f/255.0f,220.0f/255.0f,220.0f/255.0f),TRUE);
- sAppStream << rcBBox.left << " " << rcBBox.bottom << " "
- << rcBBox.right - rcBBox.left << " " << rcBBox.top - rcBBox.bottom << " re f\n";
- sAppStream << "Q\n";
-
- sAppStream << "q\n" <<
- CPWL_Utils::GetBorderAppStream(rcBBox,2,CPWL_Color(COLORTYPE_GRAY,0),CPWL_Color(COLORTYPE_GRAY,1),CPWL_Color(COLORTYPE_GRAY,0.5),PBS_BEVELED,CPWL_Dash(3,0,0))
- << "Q\n";
-
- CPDF_Point ptCenter = CPDF_Point((rcBBox.left + rcBBox.right)/2,(rcBBox.top + rcBBox.bottom)/2);
- if (IsFloatBigger(rcBBox.right - rcBBox.left,6) && IsFloatBigger(rcBBox.top - rcBBox.bottom,6))
- {
- sAppStream << "q\n" << " 0 g\n";
- sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n";
- sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n";
- sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n";
- sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n";
- sAppStream << "Q\n";
- }
- }
-
- return sAppStream.GetByteString();
-}
-
-void CPWL_Utils::ConvertCMYK2GRAY(FX_FLOAT dC,FX_FLOAT dM,FX_FLOAT dY,FX_FLOAT dK,FX_FLOAT &dGray)
-{
- if (dC<0 || dC>1 || dM<0 || dM>1 || dY < 0 || dY >1 || dK < 0 || dK >1)
- return;
- dGray = 1.0f - FX_MIN(1.0f,0.3f*dC+0.59f * dM + 0.11f*dY+dK);
-}
-
-void CPWL_Utils::ConvertGRAY2CMYK(FX_FLOAT dGray,FX_FLOAT &dC,FX_FLOAT &dM,FX_FLOAT &dY,FX_FLOAT &dK)
-{
- if (dGray <0 || dGray >1)
- return;
- dC = 0.0f;
- dM = 0.0f;
- dY = 0.0f;
- dK = 1.0f-dGray;
-}
-
-void CPWL_Utils::ConvertGRAY2RGB(FX_FLOAT dGray,FX_FLOAT &dR,FX_FLOAT &dG,FX_FLOAT &dB)
-{
- if (dGray <0 || dGray >1)
- return;
- dR = dGray;
- dG = dGray;
- dB = dGray;
-}
-
-void CPWL_Utils::ConvertRGB2GRAY(FX_FLOAT dR,FX_FLOAT dG,FX_FLOAT dB,FX_FLOAT &dGray)
-{
- if (dR<0 || dR>1 || dG<0 || dG > 0 || dB < 0 || dB >1)
- return;
- dGray = 0.3f*dR+0.59f*dG+0.11f*dB;
-}
-
-void CPWL_Utils::ConvertCMYK2RGB(FX_FLOAT dC,FX_FLOAT dM,FX_FLOAT dY,FX_FLOAT dK,FX_FLOAT &dR,FX_FLOAT &dG,FX_FLOAT &dB)
-{
- if (dC <0 || dC>1 || dM < 0 || dM > 1 || dY < 0 || dY > 1 || dK < 0 || dK > 1 )
- return;
- dR = 1.0f - FX_MIN(1.0f, dC + dK);
- dG = 1.0f - FX_MIN(1.0f, dM + dK);
- dB = 1.0f - FX_MIN(1.0f, dY + dK);
-}
-
-void CPWL_Utils::ConvertRGB2CMYK(FX_FLOAT dR,FX_FLOAT dG,FX_FLOAT dB,FX_FLOAT &dC,FX_FLOAT &dM,FX_FLOAT &dY,FX_FLOAT &dK)
-{
- if (dR<0 || dR>1 || dG<0 || dG>1 || dB<0 || dB>1)
- return;
-
- dC = 1.0f - dR;
- dM = 1.0f - dG;
- dY = 1.0f - dB;
- dK = FX_MIN(dC, FX_MIN(dM, dY));
-}
-
-void CPWL_Utils::PWLColorToARGB(const CPWL_Color& color, FX_INT32& alpha, FX_FLOAT& red, FX_FLOAT& green, FX_FLOAT& blue)
-{
- switch (color.nColorType)
- {
- case COLORTYPE_TRANSPARENT:
- {
- alpha = 0;
- }
- break;
- case COLORTYPE_GRAY:
- {
- ConvertGRAY2RGB(color.fColor1, red, green, blue);
- }
- break;
- case COLORTYPE_RGB:
- {
- red = color.fColor1;
- green = color.fColor2;
- blue = color.fColor3;
- }
- break;
- case COLORTYPE_CMYK:
- {
- ConvertCMYK2RGB(color.fColor1, color.fColor2, color.fColor3, color.fColor4,
- red, green, blue);
- }
- break;
- }
-}
-
-FX_COLORREF CPWL_Utils::PWLColorToFXColor(const CPWL_Color& color, FX_INT32 nTransparancy)
-{
- FX_INT32 nAlpha = nTransparancy;
- FX_FLOAT dRed = 0;
- FX_FLOAT dGreen = 0;
- FX_FLOAT dBlue = 0;
-
- PWLColorToARGB(color, nAlpha, dRed, dGreen, dBlue);
-
- return ArgbEncode(nAlpha, (FX_INT32)(dRed*255), (FX_INT32)(dGreen*255), (FX_INT32)(dBlue*255));
-}
-
-void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,const CPDF_Rect & rect,
- const FX_COLORREF & color)
-{
- CFX_PathData path;
- CPDF_Rect rcTemp(rect);
- path.AppendRect(rcTemp.left,rcTemp.bottom,rcTemp.right,rcTemp.top);
- pDevice->DrawPath(&path, pUser2Device, NULL, color, 0, FXFILL_WINDING);
-}
-
-void CPWL_Utils::DrawFillArea(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- const CPDF_Point* pPts, FX_INT32 nCount, const FX_COLORREF& color)
-{
- CFX_PathData path;
- path.SetPointCount(nCount);
-
- path.SetPoint(0, pPts[0].x, pPts[0].y, FXPT_MOVETO);
- for (FX_INT32 i=1; i<nCount; i++)
- path.SetPoint(i, pPts[i].x, pPts[i].y, FXPT_LINETO);
-
- pDevice->DrawPath(&path, pUser2Device, NULL, color, 0, FXFILL_ALTERNATE);
-}
-
-void CPWL_Utils::DrawStrokeRect(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,const CPDF_Rect & rect,
- const FX_COLORREF & color, FX_FLOAT fWidth)
-{
- CFX_PathData path;
- CPDF_Rect rcTemp(rect);
- path.AppendRect(rcTemp.left,rcTemp.bottom,rcTemp.right,rcTemp.top);
-
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = fWidth;
-
- pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE);
-}
-
-void CPWL_Utils::DrawStrokeLine(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- const CPDF_Point & ptMoveTo, const CPDF_Point & ptLineTo, const FX_COLORREF & color, FX_FLOAT fWidth)
-{
- CFX_PathData path;
- path.SetPointCount(2);
- path.SetPoint(0, ptMoveTo.x, ptMoveTo.y, FXPT_MOVETO);
- path.SetPoint(1, ptLineTo.x, ptLineTo.y, FXPT_LINETO);
-
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = fWidth;
-
- pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE);
-}
-
-void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,const CPDF_Rect & rect,
- const CPWL_Color & color, FX_INT32 nTransparancy)
-{
- CPWL_Utils::DrawFillRect(pDevice,pUser2Device,rect,PWLColorToFXColor(color,nTransparancy));
-}
-
-void CPWL_Utils::DrawShadow(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- FX_BOOL bVertical, FX_BOOL bHorizontal, CPDF_Rect rect,
- FX_INT32 nTransparancy, FX_INT32 nStartGray, FX_INT32 nEndGray)
-{
- FX_FLOAT fStepGray = 1.0f;
-
- if (bVertical)
- {
- fStepGray = (nEndGray - nStartGray) / rect.Height();
-
- for (FX_FLOAT fy=rect.bottom+0.5f; fy<=rect.top-0.5f; fy+=1.0f)
- {
- FX_INT32 nGray = nStartGray + (FX_INT32)(fStepGray * (fy-rect.bottom));
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, CPDF_Point(rect.left, fy),
- CPDF_Point(rect.right, fy), ArgbEncode(nTransparancy, nGray, nGray, nGray), 1.5f);
- }
- }
-
- if (bHorizontal)
- {
- fStepGray = (nEndGray - nStartGray) / rect.Width();
-
- for (FX_FLOAT fx=rect.left+0.5f; fx<=rect.right-0.5f; fx+=1.0f)
- {
- FX_INT32 nGray = nStartGray + (FX_INT32)(fStepGray * (fx-rect.left));
- CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, CPDF_Point(fx, rect.bottom),
- CPDF_Point(fx, rect.top), ArgbEncode(nTransparancy, nGray, nGray, nGray), 1.5f);
- }
- }
-}
-
-void CPWL_Utils::DrawBorder(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- const CPDF_Rect & rect, FX_FLOAT fWidth,
- const CPWL_Color & color, const CPWL_Color & crLeftTop, const CPWL_Color & crRightBottom,
- FX_INT32 nStyle, const CPWL_Dash & dash, FX_INT32 nTransparancy)
-{
- FX_FLOAT fLeft = rect.left;
- FX_FLOAT fRight = rect.right;
- FX_FLOAT fTop = rect.top;
- FX_FLOAT fBottom = rect.bottom;
-
- if (fWidth > 0.0f)
- {
- FX_FLOAT fHalfWidth = fWidth / 2.0f;
-
- switch (nStyle)
- {
- default:
- case PBS_SOLID:
- {
- CFX_PathData path;
- path.AppendRect(fLeft, fBottom, fRight, fTop);
- path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth, fTop - fWidth);
- pDevice->DrawPath(&path, pUser2Device, NULL, PWLColorToFXColor(color,nTransparancy), 0, FXFILL_ALTERNATE);
- }
- break;
- case PBS_DASH:
- {
- CFX_PathData path;
-
- path.SetPointCount(5);
- path.SetPoint(0, fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f, FXPT_MOVETO);
- path.SetPoint(1, fLeft + fWidth / 2.0f, fTop - fWidth / 2.0f, FXPT_LINETO);
- path.SetPoint(2, fRight - fWidth / 2.0f, fTop - fWidth / 2.0f, FXPT_LINETO);
- path.SetPoint(3, fRight - fWidth / 2.0f, fBottom + fWidth / 2.0f, FXPT_LINETO);
- path.SetPoint(4, fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f, FXPT_LINETO);
-
- CFX_GraphStateData gsd;
- gsd.SetDashCount(2);
- gsd.m_DashArray[0] = 3.0f;
- gsd.m_DashArray[1] = 3.0f;
- gsd.m_DashPhase = 0;
-
- gsd.m_LineWidth = fWidth;
- pDevice->DrawPath(&path, pUser2Device, &gsd, 0, PWLColorToFXColor(color,nTransparancy), FXFILL_WINDING);
- }
- break;
- case PBS_BEVELED:
- case PBS_INSET:
- {
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = fHalfWidth;
-
- CFX_PathData pathLT;
-
- pathLT.SetPointCount(7);
- pathLT.SetPoint(0, fLeft + fHalfWidth, fBottom + fHalfWidth, FXPT_MOVETO);
- pathLT.SetPoint(1, fLeft + fHalfWidth, fTop - fHalfWidth, FXPT_LINETO);
- pathLT.SetPoint(2, fRight - fHalfWidth, fTop - fHalfWidth, FXPT_LINETO);
- pathLT.SetPoint(3, fRight - fHalfWidth * 2, fTop - fHalfWidth * 2, FXPT_LINETO);
- pathLT.SetPoint(4, fLeft + fHalfWidth * 2, fTop - fHalfWidth * 2, FXPT_LINETO);
- pathLT.SetPoint(5, fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2, FXPT_LINETO);
- pathLT.SetPoint(6, fLeft + fHalfWidth, fBottom + fHalfWidth, FXPT_LINETO);
-
- pDevice->DrawPath(&pathLT, pUser2Device, &gsd, PWLColorToFXColor(crLeftTop,nTransparancy), 0, FXFILL_ALTERNATE);
-
- CFX_PathData pathRB;
-
- pathRB.SetPointCount(7);
- pathRB.SetPoint(0, fRight - fHalfWidth, fTop - fHalfWidth, FXPT_MOVETO);
- pathRB.SetPoint(1, fRight - fHalfWidth, fBottom + fHalfWidth, FXPT_LINETO);
- pathRB.SetPoint(2, fLeft + fHalfWidth, fBottom + fHalfWidth, FXPT_LINETO);
- pathRB.SetPoint(3, fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2, FXPT_LINETO);
- pathRB.SetPoint(4, fRight - fHalfWidth * 2, fBottom + fHalfWidth * 2, FXPT_LINETO);
- pathRB.SetPoint(5, fRight - fHalfWidth * 2, fTop - fHalfWidth * 2, FXPT_LINETO);
- pathRB.SetPoint(6, fRight - fHalfWidth, fTop - fHalfWidth, FXPT_LINETO);
-
- pDevice->DrawPath(&pathRB, pUser2Device, &gsd, PWLColorToFXColor(crRightBottom,nTransparancy), 0, FXFILL_ALTERNATE);
-
- CFX_PathData path;
-
- path.AppendRect(fLeft, fBottom, fRight, fTop);
- path.AppendRect(fLeft + fHalfWidth, fBottom + fHalfWidth, fRight - fHalfWidth, fTop - fHalfWidth);
-
- pDevice->DrawPath(&path, pUser2Device, &gsd, PWLColorToFXColor(color,nTransparancy), 0, FXFILL_ALTERNATE);
- }
- break;
- case PBS_UNDERLINED:
- {
- CFX_PathData path;
-
- path.SetPointCount(2);
- path.SetPoint(0, fLeft, fBottom + fWidth / 2, FXPT_MOVETO);
- path.SetPoint(1, fRight, fBottom + fWidth / 2, FXPT_LINETO);
-
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = fWidth;
-
- pDevice->DrawPath(&path, pUser2Device, &gsd,0, PWLColorToFXColor(color,nTransparancy), FXFILL_ALTERNATE);
- }
- break;
- case PBS_SHADOW:
- {
- CFX_PathData path;
- path.AppendRect(fLeft, fBottom, fRight, fTop);
- path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth, fTop - fWidth);
- pDevice->DrawPath(&path, pUser2Device, NULL, PWLColorToFXColor(color,nTransparancy/2), 0, FXFILL_ALTERNATE);
- }
- break;
- }
- }
-}
-
-static void AddSquigglyPath(CFX_PathData & PathData, FX_FLOAT fStartX, FX_FLOAT fEndX, FX_FLOAT fY, FX_FLOAT fStep)
-{
- PathData.AddPointCount(1);
- PathData.SetPoint(PathData.GetPointCount() - 1, fStartX, fY, FXPT_MOVETO);
-
- FX_FLOAT fx;
- FX_INT32 i;
-
- for (i=1,fx=fStartX+fStep; fx<fEndX; fx+=fStep,i++)
- {
- PathData.AddPointCount(1);
- PathData.SetPoint(PathData.GetPointCount() - 1, fx, fY + (i&1)*fStep, FXPT_LINETO);
- }
-}
-
-static void AddSpellCheckObj(CFX_PathData & PathData, IFX_Edit* pEdit, const CPVT_WordRange& wrWord)
-{
- FX_FLOAT fStartX = 0.0f;
- FX_FLOAT fEndX = 0.0f;
- FX_FLOAT fY = 0.0f;
- FX_FLOAT fStep = 0.0f;
-
- FX_BOOL bBreak = FALSE;
-
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- pIterator->SetAt(wrWord.BeginPos);
-
- do
- {
- CPVT_WordPlace place = pIterator->GetAt();
-
- CPVT_Line line;
- if (pIterator->GetLine(line))
- {
- fY = line.ptLine.y;
- fStep = (line.fLineAscent - line.fLineDescent) / 16.0f;
- }
-
- if (place.LineCmp(wrWord.BeginPos) == 0)
- {
- pIterator->SetAt(wrWord.BeginPos);
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- fStartX = word.ptWord.x;
- }
- }
- else
- {
- fStartX = line.ptLine.x;
- }
-
- if (place.LineCmp(wrWord.EndPos) == 0)
- {
- pIterator->SetAt(wrWord.EndPos);
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- fEndX = word.ptWord.x + word.fWidth;
- }
-
- bBreak = TRUE;
- }
- else
- {
- fEndX = line.ptLine.x + line.fLineWidth;
- }
-
- AddSquigglyPath(PathData, fStartX, fEndX, fY, fStep);
-
- if (bBreak) break;
- }
- while (pIterator->NextLine());
- }
-}
-
-void CPWL_Utils::DrawEditSpellCheck(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit,
- const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange,
- IPWL_SpellCheck * pSpellCheck)
-{
- const FX_COLORREF crSpell = ArgbEncode(255,255,0,0);
-
- //for spellcheck
- FX_BOOL bLatinWord = FALSE;
- CPVT_WordPlace wpWordStart;
- CFX_ByteString sLatinWord;
-
- CFX_PathData pathSpell;
-
- pDevice->SaveState();
-
- if (!rcClip.IsEmpty())
- {
- CPDF_Rect rcTemp = rcClip;
- pUser2Device->TransformRect(rcTemp);
- FX_RECT rcDevClip;
- rcDevClip.left = (FX_INT32)rcTemp.left;
- rcDevClip.right = (FX_INT32)rcTemp.right;
- rcDevClip.top = (FX_INT32)rcTemp.top;
- rcDevClip.bottom = (FX_INT32)rcTemp.bottom;
- pDevice->SetClip_Rect(&rcDevClip);
- }
-
- if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
- {
- if (pEdit->GetFontMap())
- {
- if (pRange)
- pIterator->SetAt(pRange->BeginPos);
- else
- pIterator->SetAt(0);
-
- CPVT_WordPlace oldplace;
-
- while (pIterator->NextWord())
- {
- CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
-
- CPVT_Word word;
- if (pIterator->GetWord(word))
- {
- if (FX_EDIT_ISLATINWORD(word.Word))
- {
- if (!bLatinWord)
- {
- wpWordStart = place;
- bLatinWord = TRUE;
- }
-
- sLatinWord += (char)word.Word;
- }
- else
- {
- if (bLatinWord)
- {
- if (!sLatinWord.IsEmpty())
- {
- if (pSpellCheck && !pSpellCheck->CheckWord(sLatinWord))
- {
- AddSpellCheckObj(pathSpell,pEdit,CPVT_WordRange(wpWordStart,oldplace));
- pIterator->SetAt(place);
- }
- }
- bLatinWord = FALSE;
- }
-
- sLatinWord.Empty();
- }
-
- oldplace = place;
- }
- else
- {
- if (bLatinWord)
- {
- if (!sLatinWord.IsEmpty())
- {
- if (pSpellCheck && !pSpellCheck->CheckWord(sLatinWord))
- {
- AddSpellCheckObj(pathSpell,pEdit,CPVT_WordRange(wpWordStart,oldplace));
- pIterator->SetAt(place);
- }
- }
- bLatinWord = FALSE;
- }
-
- sLatinWord.Empty();
- }
- }
-
- if (!sLatinWord.IsEmpty())
- {
- if (pSpellCheck && !pSpellCheck->CheckWord(sLatinWord))
- {
- AddSpellCheckObj(pathSpell,pEdit,CPVT_WordRange(wpWordStart,oldplace));
- }
- }
- }
- }
-
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = 0;
- if (pathSpell.GetPointCount() > 0)
- pDevice->DrawPath(&pathSpell, pUser2Device, &gsd, 0, crSpell, FXFILL_ALTERNATE);
-
- pDevice->RestoreState();
-}
-
-FX_BOOL CPWL_Utils::IsBlackOrWhite(const CPWL_Color& color)
-{
- switch (color.nColorType)
- {
- case COLORTYPE_TRANSPARENT:
- return FALSE;
- case COLORTYPE_GRAY:
- return color.fColor1 < 0.5f;
- case COLORTYPE_RGB:
- return color.fColor1 + color.fColor2 + color.fColor3 < 1.5f;
- case COLORTYPE_CMYK:
- return color.fColor1 + color.fColor2 + color.fColor3 + color.fColor4 > 2.0f;
- }
-
- return TRUE;
-}
-
-CPWL_Color CPWL_Utils::GetReverseColor(const CPWL_Color& color)
-{
- CPWL_Color crRet = color;
-
- switch (color.nColorType)
- {
- case COLORTYPE_GRAY:
- crRet.fColor1 = 1.0f - crRet.fColor1;
- break;
- case COLORTYPE_RGB:
- crRet.fColor1 = 1.0f - crRet.fColor1;
- crRet.fColor2 = 1.0f - crRet.fColor2;
- crRet.fColor3 = 1.0f - crRet.fColor3;
- break;
- case COLORTYPE_CMYK:
- crRet.fColor1 = 1.0f - crRet.fColor1;
- crRet.fColor2 = 1.0f - crRet.fColor2;
- crRet.fColor3 = 1.0f - crRet.fColor3;
- crRet.fColor4 = 1.0f - crRet.fColor4;
- break;
- }
-
- return crRet;
-}
-
-CFX_ByteString CPWL_Utils::GetIconAppStream(FX_INT32 nType, const CPDF_Rect& rect, const CPWL_Color& crFill,
- const CPWL_Color& crStroke)
-{
- CFX_ByteString sAppStream = CPWL_Utils::GetColorAppStream(crStroke, FALSE);
- sAppStream += CPWL_Utils::GetColorAppStream(crFill, TRUE);
-
- CFX_ByteString sPath;
- CFX_PathData path;
-
- switch (nType)
- {
- case PWL_ICONTYPE_CHECKMARK:
- GetGraphics_Checkmark(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_CIRCLE:
- GetGraphics_Circle(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_COMMENT:
- GetGraphics_Comment(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_CROSS:
- GetGraphics_Cross(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_HELP:
- GetGraphics_Help(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_INSERTTEXT:
- GetGraphics_InsertText(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_KEY:
- GetGraphics_Key(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_NEWPARAGRAPH:
- GetGraphics_NewParagraph(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_TEXTNOTE:
- GetGraphics_TextNote(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_PARAGRAPH:
- GetGraphics_Paragraph(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_RIGHTARROW:
- GetGraphics_RightArrow(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_RIGHTPOINTER:
- GetGraphics_RightPointer(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_STAR:
- GetGraphics_Star(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_UPARROW:
- GetGraphics_UpArrow(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_UPLEFTARROW:
- GetGraphics_UpLeftArrow(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_GRAPH:
- GetGraphics_Graph(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_PAPERCLIP:
- GetGraphics_Paperclip(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_ATTACHMENT:
- GetGraphics_Attachment(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_TAG:
- GetGraphics_Tag(sPath, path, rect, PWLPT_STREAM);
- break;
- case PWL_ICONTYPE_FOXIT:
- GetGraphics_Foxit(sPath, path, rect, PWLPT_STREAM);
- break;
- }
-
- sAppStream += sPath;
- if (crStroke.nColorType != COLORTYPE_TRANSPARENT)
- sAppStream += "B*\n";
- else
- sAppStream += "f*\n";
-
- return sAppStream;
-}
-
-void CPWL_Utils::DrawIconAppStream(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
- FX_INT32 nType, const CPDF_Rect & rect, const CPWL_Color& crFill, const CPWL_Color& crStroke, const FX_INT32 nTransparancy)
-{
- CFX_GraphStateData gsd;
- gsd.m_LineWidth = 1.0f;
-
- CFX_ByteString sPath;
- CFX_PathData path;
-
- switch (nType)
- {
- case PWL_ICONTYPE_CHECKMARK:
- GetGraphics_Checkmark(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_CIRCLE:
- GetGraphics_Circle(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_COMMENT:
- GetGraphics_Comment(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_CROSS:
- GetGraphics_Cross(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_HELP:
- GetGraphics_Help(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_INSERTTEXT:
- GetGraphics_InsertText(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_KEY:
- GetGraphics_Key(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_NEWPARAGRAPH:
- GetGraphics_NewParagraph(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_TEXTNOTE:
- GetGraphics_TextNote(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_PARAGRAPH:
- GetGraphics_Paragraph(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_RIGHTARROW:
- GetGraphics_RightArrow(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_RIGHTPOINTER:
- GetGraphics_RightPointer(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_STAR:
- GetGraphics_Star(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_UPARROW:
- GetGraphics_UpArrow(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_UPLEFTARROW:
- GetGraphics_UpLeftArrow(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_GRAPH:
- GetGraphics_Graph(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_PAPERCLIP:
- GetGraphics_Paperclip(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_ATTACHMENT:
- GetGraphics_Attachment(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_TAG:
- GetGraphics_Tag(sPath, path, rect, PWLPT_PATHDATA);
- break;
- case PWL_ICONTYPE_FOXIT:
- GetGraphics_Foxit(sPath, path, rect, PWLPT_PATHDATA);
- break;
- default:
- return;
- }
-
- pDevice->DrawPath(&path, pUser2Device, &gsd,
- PWLColorToFXColor(crFill,nTransparancy), PWLColorToFXColor(crStroke,nTransparancy), FXFILL_ALTERNATE);
-}
-
-void CPWL_Utils::GetGraphics_Checkmark(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f, crBBox.bottom + fHeight * 2 / 5.0f),PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f + PWL_BEZIER*(fWidth / 7.0f - fWidth / 15.0f),
- crBBox.bottom + fHeight * 2 / 5.0f + PWL_BEZIER*(fHeight * 2 / 7.0f - fHeight * 2 / 5.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 4.5f + PWL_BEZIER*(fWidth / 5.0f - fWidth / 4.5f),
- crBBox.bottom + fHeight / 16.0f + PWL_BEZIER*(fHeight / 5.0f - fHeight / 16.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 4.5f, crBBox.bottom + fHeight / 16.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 4.5f + PWL_BEZIER*(fWidth / 4.4f - fWidth / 4.5f),
- crBBox.bottom + fHeight / 16.0f - PWL_BEZIER*fHeight / 16.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.0f + PWL_BEZIER*(fWidth / 4.0f - fWidth / 3.0f),
- crBBox.bottom), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.0f, crBBox.bottom), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.0f + PWL_BEZIER*fWidth*(1/7.0f + 2/15.0f),
- crBBox.bottom + PWL_BEZIER*fHeight * 4 / 5.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 14 / 15.0f + PWL_BEZIER*fWidth*(1/7.0f - 7/15.0f),
- crBBox.bottom + fHeight * 15/16.0f + PWL_BEZIER*(fHeight * 4/5.0f - fHeight * 15/16.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 14 / 15.0f,crBBox.bottom + fHeight * 15 / 16.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 14 / 15.0f + PWL_BEZIER*(fWidth * 7 / 15.0f - fWidth * 14 / 15.0f),
- crBBox.bottom + fHeight * 15 / 16.0f + PWL_BEZIER*(fHeight * 8 / 7.0f - fHeight * 15 / 16.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.6f + PWL_BEZIER*(fWidth / 3.4f - fWidth / 3.6f),
- crBBox.bottom + fHeight / 3.5f + PWL_BEZIER*(fHeight / 3.5f - fHeight / 3.5f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.6f,crBBox.bottom + fHeight / 3.5f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.6f,
- crBBox.bottom + fHeight / 3.5f + PWL_BEZIER*(fHeight / 4.0f - fHeight / 3.5f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f + PWL_BEZIER*(fWidth / 3.5f - fWidth / 15.0f),
- crBBox.bottom + fHeight * 2 / 5.0f + PWL_BEZIER*(fHeight * 3.5f / 5.0f - fHeight * 2 / 5.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f,crBBox.bottom + fHeight * 2 / 5.0f), PWLPT_BEZIERTO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 16);
- else
- GetPathDataFromArray(path, PathArray, 16);
-}
-
-void CPWL_Utils::GetGraphics_Circle(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f,crBBox.bottom + fHeight/2.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f,
- crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight*14/15.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth/2.0f - fWidth/15.0f), crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f,crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*(fWidth*14/15.0f - fWidth/2.0f), crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight*14/15.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight/2.0f - PWL_BEZIER*(fHeight/2.0f - fHeight/15.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*(fWidth*14/15.0f - fWidth/2.0f), crBBox.bottom + fHeight/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth/2.0f - fWidth/15.0f), crBBox.bottom + fHeight/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.bottom + fHeight/2.0f - PWL_BEZIER*(fHeight/2.0f - fHeight/15.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f,crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight*4/5.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth/2.0f - fWidth*3/15.0f), crBBox.top - fHeight*3/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight*3/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*(fWidth*4/5.0f - fWidth/2.0f), crBBox.top - fHeight*3/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight*4/5.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f - PWL_BEZIER*(fHeight*4/5.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*(fWidth*4/5.0f - fWidth/2.0f), crBBox.bottom + fHeight*3/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight*3/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth*4/5.0f - fWidth/2.0f), crBBox.bottom + fHeight*3/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f - PWL_BEZIER*(fHeight*4/5.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 26);
- else
- GetPathDataFromArray(path, PathArray, 26);
-}
-
-void CPWL_Utils::GetGraphics_Comment(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.top - fHeight/6.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.top - fHeight/6.0f + PWL_BEZIER*(fHeight/6.0f - fHeight/10.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f - PWL_BEZIER*fWidth/15.0f, crBBox.top - fHeight/10.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f, crBBox.top - fHeight/10.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f, crBBox.top - fHeight/10.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f + PWL_BEZIER*fWidth/15.0f, crBBox.top - fHeight/10.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.top - fHeight/6 + PWL_BEZIER*(fHeight/6.0f - fHeight/10.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.top - fHeight/6.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight/3.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight*4/15.0f + PWL_BEZIER*fHeight/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f + PWL_BEZIER*fWidth/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*5/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*5/15.0f, crBBox.bottom + fHeight*2/15 + PWL_BEZIER*fHeight*2/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*5/15.0f - PWL_BEZIER*fWidth*2/15.0f, crBBox.bottom + fHeight*2/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*6/30.0f, crBBox.bottom + fHeight*2/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*7/30.0f + PWL_BEZIER*fWidth/30.0f, crBBox.bottom + fHeight*2/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*7/30.0f, crBBox.bottom + fHeight*2/15.0f + PWL_BEZIER*fHeight*2/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*7/30.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f - PWL_BEZIER*fWidth/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.bottom + fHeight/3.0f - PWL_BEZIER*fHeight/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.bottom + fHeight/3.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.top - fHeight/6.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f, crBBox.top - fHeight*8/30.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f, crBBox.top - fHeight*8/30.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15, crBBox.top - fHeight*25/60.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f, crBBox.top - fHeight*25/60.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f, crBBox.top - fHeight*17/30.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*4/15.0f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 30);
- else
- GetPathDataFromArray(path, PathArray, 30);
-}
-
-void CPWL_Utils::GetGraphics_Cross(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
- //FX_FLOAT fcatercorner = (FX_FLOAT)sqrt(fWidth*fWidth + fHeight*fHeight);
- CPWL_Point center_point(crBBox.left + fWidth/2, crBBox.bottom + fHeight/2);
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(center_point.x, center_point.y + fHeight/10.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(center_point.x + fWidth*0.3f, center_point.y + fHeight/10.0f + fWidth*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x + fWidth/10.0f + fWidth*0.3f, center_point.y + fHeight*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x + fWidth/10.0f, center_point.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x + fWidth/10.0f + fWidth*0.3f, center_point.y - fHeight*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x + fWidth*0.3f, center_point.y - fHeight/10.0f - fHeight*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x, center_point.y - fHeight/10.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x - fWidth*0.3f, center_point.y - fHeight/10 - fHeight*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x - fWidth/10.0f - fWidth*0.3f, center_point.y - fHeight*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x - fWidth/10, center_point.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x - fWidth/10 - fWidth*0.3f, center_point.y + fHeight*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x - fWidth*0.3f, center_point.y + fHeight/10.0f + fHeight*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(center_point.x, center_point.y + fHeight/10.0f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 13);
- else
- GetPathDataFromArray(path, PathArray, 13);
-}
-
-void CPWL_Utils::GetGraphics_Help(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60.0f, crBBox.bottom + fHeight/2.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight/60.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth/2.0f - fWidth/60.0f), crBBox.bottom + fHeight/60.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight/60.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*fWidth*29/60.0f, crBBox.bottom + fHeight/60.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/60.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight/60.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/60.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/60.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*fHeight*29/60.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*fWidth*29/60.0f, crBBox.top - fHeight/60.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/60.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*fWidth*29/60.0f, crBBox.top - fHeight/60.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*fHeight*29/60.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.27f, crBBox.top - fHeight*0.36f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.27f, crBBox.top - fHeight*0.36f + PWL_BEZIER*fHeight*0.23f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f - PWL_BEZIER*fWidth*0.23f, crBBox.bottom + fHeight*0.87f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.bottom + fHeight*0.87f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f + PWL_BEZIER*fWidth*0.23f, crBBox.bottom + fHeight*0.87f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.27f, crBBox.top - fHeight*0.36f + PWL_BEZIER*fHeight*0.23f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.27f, crBBox.top - fHeight*0.36f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.27f - fWidth*0.08f*0.2f, crBBox.top - fHeight*0.36f - fHeight*0.15f*0.7f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.35f + fWidth*0.08f*0.2f, crBBox.top - fHeight*0.51f + fHeight*0.15f*0.2f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.35f, crBBox.top - fHeight*0.51f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.35f - fWidth*0.1f*0.5f, crBBox.top - fHeight*0.51f - fHeight*0.15f*0.3f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f - fWidth*0.1f*0.5f, crBBox.top - fHeight*0.68f + fHeight*0.15f*0.5f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f, crBBox.top - fHeight*0.68f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f, crBBox.bottom + fHeight*0.30f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f, crBBox.bottom + fHeight*0.30f - fWidth*0.1f*0.7f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.55f, crBBox.bottom + fHeight*0.30f - fWidth*0.1f*0.7f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.55f, crBBox.bottom + fHeight*0.30f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.55f, crBBox.top - fHeight*0.66f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.55f - fWidth*0.1f*0.05f, crBBox.top - fHeight*0.66f + fHeight*0.18f*0.5f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f - fWidth*0.1f*0.05f, crBBox.top - fHeight*0.48f - fHeight*0.18f*0.3f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f, crBBox.top - fHeight*0.48f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f + fWidth*0.08f*0.2f, crBBox.top - fHeight*0.48f + fHeight*0.18f*0.2f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.37f - fWidth*0.08f*0.2f, crBBox.top - fHeight*0.36f - fHeight*0.18f*0.7f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.37f, crBBox.top - fHeight*0.36f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.37f, crBBox.top - fHeight*0.36f + PWL_BEZIER*fHeight*0.13f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f + PWL_BEZIER*fWidth*0.13f, crBBox.bottom + fHeight*0.77f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.bottom + fHeight*0.77f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f - PWL_BEZIER*fWidth*0.13f, crBBox.bottom + fHeight*0.77f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.37f, crBBox.top - fHeight*0.36f + PWL_BEZIER*fHeight*0.13f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.37f, crBBox.top - fHeight*0.36f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.37f, crBBox.top - fHeight*0.36f - fWidth*0.1f*0.6f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.27f, crBBox.top - fHeight*0.36f - fWidth*0.1f*0.6f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.27f, crBBox.top - fHeight*0.36f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.56f, crBBox.bottom + fHeight*0.13f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.56f, crBBox.bottom + fHeight*0.13f + PWL_BEZIER*fHeight*0.055f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f - PWL_BEZIER*fWidth*0.095f, crBBox.bottom + fHeight*0.185f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f, crBBox.bottom + fHeight*0.185f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f + PWL_BEZIER*fWidth*0.065f, crBBox.bottom + fHeight*0.185f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.44f, crBBox.bottom + fHeight*0.13f + PWL_BEZIER*fHeight*0.055f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.44f, crBBox.bottom + fHeight*0.13f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.44f, crBBox.bottom + fHeight*0.13f - PWL_BEZIER*fHeight*0.055f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f + PWL_BEZIER*fWidth*0.065f, crBBox.bottom + fHeight*0.075f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f, crBBox.bottom + fHeight*0.075f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f - PWL_BEZIER*fWidth*0.065f, crBBox.bottom + fHeight*0.075f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.56f, crBBox.bottom + fHeight*0.13f - PWL_BEZIER*fHeight*0.055f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.56f, crBBox.bottom + fHeight*0.13f), PWLPT_BEZIERTO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 59);
- else
- GetPathDataFromArray(path, PathArray, 59);
-}
-
-void CPWL_Utils::GetGraphics_InsertText(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10, crBBox.bottom + fHeight/10), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2, crBBox.top - fHeight*2/15), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10, crBBox.bottom + fHeight/10), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10, crBBox.bottom + fHeight/10), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 4);
- else
- GetPathDataFromArray(path, PathArray, 4);
-}
-
-void CPWL_Utils::GetGraphics_Key(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
- FX_FLOAT k = -fHeight/fWidth;
- CPWL_Point tail;
- CPWL_Point CicleCenter;
- tail.x = crBBox.left + fWidth*0.9f;
- tail.y = k*(tail.x - crBBox.right) + crBBox.bottom;
- CicleCenter.x = crBBox.left + fWidth*0.15f;
- CicleCenter.y = k*(CicleCenter.x - crBBox.right) + crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30.0f, -fWidth/30.0f/k + tail.y), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30.0f - fWidth*0.18f, -k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f + fWidth*0.07f,
- -fWidth*0.07f/k - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 + fWidth*0.07f,
- -fWidth*0.07f/k - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20,
- -k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 - fWidth/15,
- -k*fWidth/15 - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 - fWidth/15 + fWidth*0.07f,
- -fWidth*0.07f/k - k*fWidth/15 - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 - fWidth/15 - fWidth/20 + fWidth*0.07f,
- -fWidth*0.07f/k + -k*fWidth/20 + -k*fWidth/15 - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 - fWidth/15 - fWidth/20,
- -k*fWidth/20 + -k*fWidth/15 - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.45f, -k*fWidth*0.45f - fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.45f + fWidth*0.2f,
- -fWidth*0.4f/k - k*fWidth*0.45f - fWidth/30/k + tail.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.2f, - fWidth*0.1f/k + CicleCenter.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x, CicleCenter.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x - fWidth/60.0f, -k*fWidth/60 + CicleCenter.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x - fWidth/60, -k*fWidth/60 + CicleCenter.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x, CicleCenter.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x - fWidth*0.22f, fWidth*0.35f/k + CicleCenter.y - fHeight*0.05f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(tail.x - fWidth/30 - fWidth*0.45f - fWidth*0.18f, fWidth*0.05f/k - k*fWidth*0.45f + fWidth/30/k + tail.y - fHeight*0.05f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(tail.x - fWidth/30.0f - fWidth*0.45f, -k*fWidth*0.45f + fWidth/30.0f/k + tail.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(tail.x - fWidth/30.0f, fWidth/30.0f/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/30, -fWidth/30/k + tail.y), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.08f, k*fWidth*0.08f + CicleCenter.y), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.08f + fWidth*0.1f, -fWidth*0.1f/k + k*fWidth*0.08f + CicleCenter.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.22f + fWidth*0.1f, k*fWidth*0.22f + CicleCenter.y - fWidth*0.1f/k), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.22f, k*fWidth*0.22f + CicleCenter.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.22f - fWidth*0.1f, fWidth*0.1f/k + k*fWidth*0.22f + CicleCenter.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.08f - fWidth*0.1f, fWidth*0.1f/k + k*fWidth*0.08f + CicleCenter.y), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.08f, k*fWidth*0.08f + CicleCenter.y), PWLPT_BEZIERTO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 28);
- else
- GetPathDataFromArray(path, PathArray, 28);
-}
-
-void CPWL_Utils::GetGraphics_NewParagraph(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/20.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/20.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.12f, crBBox.top - fHeight*17/30.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.12f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.22f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.22f, crBBox.top - fHeight*17/30.0f - fWidth*0.14f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.38f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.48f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.48f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.38f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.38f, crBBox.bottom + fWidth*0.24f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.22f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.12f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.bottom + fHeight/10.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/10.0f + fHeight/7.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.97f, crBBox.bottom + fHeight/10.0f + fHeight/7.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.97f, crBBox.top - fHeight*17/30.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.top - fHeight*17/30.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/7 + fHeight*0.18f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.85f, crBBox.bottom + fHeight/7 + fHeight*0.18f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.85f, crBBox.top - fHeight*17/30.0f - fHeight*0.08f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.top - fHeight*17/30.0f - fHeight*0.08f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/7 + fHeight*0.18f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 28);
- else
- GetPathDataFromArray(path, PathArray, 28);
-}
-
-void CPWL_Utils::GetGraphics_TextNote(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.bottom + fHeight/15.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*7/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.top - fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10.0f, crBBox.top - fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10.0f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/5.0f, crBBox.top - fHeight*4/15.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/5.0f, crBBox.top - fHeight*4/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/5.0f, crBBox.top - fHeight*7/15.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/5.0f, crBBox.top - fHeight*7/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/5.0f, crBBox.top - fHeight*10/15.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.top - fHeight*10/15.0f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 17);
- else
- GetPathDataFromArray(path, PathArray, 17);
-}
-
-void CPWL_Utils::GetGraphics_Paragraph(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.top - fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.634f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.634f, crBBox.top - fHeight*2/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.566f, crBBox.top - fHeight*2/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.566f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f - fHeight*0.4f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.2f, crBBox.top - fHeight/15.0f - fHeight*0.4f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.2f, crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 12);
- else
- GetPathDataFromArray(path, PathArray, 12);
-}
-
-void CPWL_Utils::GetGraphics_RightArrow(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.top - fHeight/2.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + fWidth/8.0f, crBBox.bottom + fHeight/5.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight/5.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f - fWidth*0.15f, crBBox.top - fHeight/2.0f - fWidth/25.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.1f, crBBox.top - fHeight/2.0f - fWidth/25.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.1f, crBBox.top - fHeight/2.0f + fWidth/25.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f - fWidth*0.15f, crBBox.top - fHeight/2.0f + fWidth/25.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/5.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + fWidth/8.0f, crBBox.top - fHeight/5.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 10);
- else
- GetPathDataFromArray(path, PathArray, 10);
-}
-
-void CPWL_Utils::GetGraphics_RightPointer(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30.0f, crBBox.top - fHeight/2.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/30.0f, crBBox.bottom + fHeight/6.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*4/15.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/30.0f, crBBox.top - fHeight/6.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 5);
- else
- GetPathDataFromArray(path, PathArray, 5);
-}
-
-void CPWL_Utils::GetGraphics_Star(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fLongRadius = (crBBox.top - crBBox.bottom)/(1+(FX_FLOAT)cos(PWL_PI/5.0f));
- fLongRadius = fLongRadius * 0.7f;
- FX_FLOAT fShortRadius = fLongRadius * 0.55f;
- CPDF_Point ptCenter = CPDF_Point((crBBox.left + crBBox.right) / 2.0f,(crBBox.top + crBBox.bottom) / 2.0f);
-
- FX_FLOAT px1[5], py1[5];
- FX_FLOAT px2[5], py2[5];
-
- FX_FLOAT fAngel = PWL_PI/10.0f;
-
- for (FX_INT32 i=0; i<5; i++)
- {
- px1[i] = ptCenter.x + fLongRadius * (FX_FLOAT)cos(fAngel);
- py1[i] = ptCenter.y + fLongRadius * (FX_FLOAT)sin(fAngel);
-
- fAngel += PWL_PI * 2 / 5.0f;
- }
-
- fAngel = PWL_PI/5.0f + PWL_PI/10.0f;
-
- for (FX_INT32 j=0; j<5; j++)
- {
- px2[j] = ptCenter.x + fShortRadius * (FX_FLOAT)cos(fAngel);
- py2[j] = ptCenter.y + fShortRadius * (FX_FLOAT)sin(fAngel);
-
- fAngel += PWL_PI * 2 / 5.0f;
- }
-
- CPWL_PathData PathArray[11];
- PathArray[0] = CPWL_PathData(CPWL_Point(px1[0], py1[0]), PWLPT_MOVETO);
- PathArray[1] = CPWL_PathData(CPWL_Point(px2[0], py2[0]), PWLPT_LINETO);
-
- for(FX_INT32 k = 0; k < 4; k++)
- {
- PathArray[(k+1)*2] = CPWL_PathData(CPWL_Point(px1[k+1], py1[k+1]), PWLPT_LINETO);
- PathArray[(k+1)*2 + 1] = CPWL_PathData(CPWL_Point(px2[k+1], py2[k+1]), PWLPT_LINETO);
- }
-
- PathArray[10] = CPWL_PathData(CPWL_Point(px1[0], py1[0]), PWLPT_LINETO);
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 11);
- else
- GetPathDataFromArray(path, PathArray, 11);
-}
-
-void CPWL_Utils::GetGraphics_UpArrow(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.top - fWidth*3/5.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fWidth*3/5.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fWidth*3/5.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10, crBBox.top - fWidth*3/5.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 8);
- else
- GetPathDataFromArray(path, PathArray, 8);
-}
-
-void CPWL_Utils::GetGraphics_UpLeftArrow(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
- CPWL_Point leftup(crBBox.left, crBBox.top);
- CPWL_Point rightdown(crBBox.right, crBBox.bottom);
- FX_FLOAT k = -fHeight/fWidth;
- CPWL_Point tail;
- tail.x = crBBox.left + fWidth*4/5.0f;
- tail.y = k*(tail.x - crBBox.right) + rightdown.y;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/20.0f, k*(crBBox.left + fWidth/20.0f - rightdown.x) + rightdown.y), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(fHeight*17/60.0f/k + tail.x + fWidth/10.0f + fWidth/5.0f,
- -fWidth/5.0f/k + tail.y - fWidth/10.0f/k + fHeight*17/60.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(fHeight*17/60.0f/k + tail.x + fWidth/10.0f,
- tail.y - fWidth/10.0f/k + fHeight*17/60.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x + fWidth/10.0f, tail.y - fWidth/10.0f/k), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(tail.x - fWidth/10.0f, tail.y + fWidth/10.0f/k), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(fHeight*17/60.0f/k + tail.x - fWidth/10.0f, tail.y + fWidth/10.0f/k + fHeight*17/60.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(fHeight*17/60.0f/k + tail.x - fWidth/10.0f - fWidth/5.0f,
- fWidth/5.0f/k + tail.y + fWidth/10.0f/k + fHeight*17/60.0f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/20.0f, k*(crBBox.left + fWidth/20.0f - rightdown.x) + rightdown.y), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 8);
- else
- GetPathDataFromArray(path, PathArray, 8);
-}
-
-void CPWL_Utils::GetGraphics_Graph(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.05f, crBBox.top - fWidth*0.15f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.25f, crBBox.top - fHeight*0.15f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.275f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.05f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.05f, crBBox.top - fWidth*0.15f), PWLPT_LINETO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.275f, crBBox.top - fWidth*0.45f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.475f, crBBox.top - fWidth*0.45f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.475f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.275f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.275f, crBBox.top - fWidth*0.45f), PWLPT_LINETO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.top - fHeight*0.05f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.top - fHeight*0.05f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.top - fHeight*0.05f), PWLPT_LINETO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.725f, crBBox.top - fWidth*0.35f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.925f, crBBox.top - fWidth*0.35f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.925f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.725f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.725f, crBBox.top - fWidth*0.35f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 20);
- else
- GetPathDataFromArray(path, PathArray, 20);
-}
-
-void CPWL_Utils::GetGraphics_Paperclip(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.top - fHeight*0.25f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.bottom + fHeight*0.25f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.bottom + fHeight*0.25f - fWidth*57/60.0f*0.35f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30, crBBox.bottom + fHeight*0.25f - fWidth*57/60.0f*0.35f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30, crBBox.bottom + fHeight*0.25f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30, crBBox.top - fHeight*0.33f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30, crBBox.top - fHeight*0.33f + fHeight/15*0.5f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30 - fWidth*0.12f, crBBox.top - fHeight*0.33f + fHeight/15*0.5f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30 - fWidth*0.12f, crBBox.top - fHeight*0.33f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30 - fWidth*0.12f, crBBox.bottom + fHeight*0.2f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30 - fWidth*0.12f, crBBox.bottom + fHeight*0.2f - (fWidth*57/60.0f - fWidth*0.24f)*0.25f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60 + fWidth*0.12f, crBBox.bottom + fHeight*0.2f - (fWidth*57/60.0f - fWidth*0.24f)*0.25f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60 + fWidth*0.12f, crBBox.bottom + fHeight*0.2f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60 + fWidth*0.12f, crBBox.top - fHeight*0.2f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60 + fWidth*0.12f, crBBox.top - fHeight*0.2f + (fWidth*11/12.0f - fWidth*0.36f)*0.25f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.24f, crBBox.top - fHeight*0.2f + (fWidth*11/12.0f - fWidth*0.36f)*0.25f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.24f, crBBox.top - fHeight*0.2f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.24f, crBBox.bottom + fHeight*0.25f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.24f, crBBox.bottom + fHeight*0.25f - (fWidth*14/15.0f - fWidth*0.53f)*0.25f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.29f, crBBox.bottom + fHeight*0.25f - (fWidth*14/15.0f - fWidth*0.53f)*0.25f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.29f, crBBox.bottom + fHeight*0.25f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.29f, crBBox.top - fHeight*0.33f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.29f, crBBox.top - fHeight*0.33f + fWidth*0.12f*0.35f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.17f, crBBox.top - fHeight*0.33f + fWidth*0.12f*0.35f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.17f, crBBox.top - fHeight*0.33f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.17f, crBBox.bottom + fHeight*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.17f, crBBox.bottom + fHeight*0.3f - fWidth*(14/15.0f - 0.29f)*0.35f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.12f, crBBox.bottom + fHeight*0.3f - fWidth*(14/15.0f - 0.29f)*0.35f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.12f, crBBox.bottom + fHeight*0.3f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.12f, crBBox.top - fHeight*0.25f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.12f, crBBox.top - fHeight*0.25f + fWidth*0.35f*(11/12.0f - 0.12f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.top - fHeight*0.25f + fWidth*0.35f*(11/12.0f - 0.12f)), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.top - fHeight*0.25f), PWLPT_BEZIERTO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 33);
- else
- GetPathDataFromArray(path, PathArray, 33);
-}
-
-void CPWL_Utils::GetGraphics_Attachment(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.25f, crBBox.top - fHeight*0.1f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.23f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f + fWidth*0.04f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.5f + fWidth*0.04f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.23f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.25f, crBBox.top - fHeight*0.1f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.25f, crBBox.top - fHeight*0.1f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.23f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.23f), PWLPT_LINETO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f - fWidth*0.25f*0.4f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.15f, crBBox.top - fHeight*0.65f + fHeight*0.15f*0.4f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.15f, crBBox.top - fHeight*0.65f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.15f, crBBox.top - fHeight*0.65f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.15f, crBBox.top - fHeight*0.65f + fHeight*0.15f*0.4f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f + fWidth*0.25f*0.4f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.5f + fWidth*0.04f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f + fWidth*0.04f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.top - fHeight*0.65f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.bottom + fHeight*0.1f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 24);
- else
- GetPathDataFromArray(path, PathArray, 24);
-}
-
-void CPWL_Utils::GetGraphics_Tag(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fWidth = crBBox.right - crBBox.left;
- FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.1f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.1f, crBBox.top - fHeight*0.5f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.3f, crBBox.bottom + fHeight*0.1f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.1f, crBBox.bottom + fHeight*0.1f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.1f, crBBox.top - fHeight*0.1f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.1f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.3f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.2f, crBBox.top - fHeight*0.3f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.2f, crBBox.top - fHeight*0.5f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.7f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.2f, crBBox.top - fHeight*0.7f), PWLPT_LINETO)
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 12);
- else
- GetPathDataFromArray(path, PathArray, 12);
-}
-
-void CPWL_Utils::GetGraphics_Foxit(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
-{
- FX_FLOAT fOutWidth = crBBox.right - crBBox.left;
- FX_FLOAT fOutHeight = crBBox.top - crBBox.bottom;
-
- CPDF_Rect crInBox = crBBox;
- crInBox.left = crBBox.left + fOutWidth*0.08f;
- crInBox.right = crBBox.right - fOutWidth*0.08f;
- crInBox.top = crBBox.top - fOutHeight*0.08f;
- crInBox.bottom = crBBox.bottom + fOutHeight*0.08f;
-
- FX_FLOAT fWidth = crInBox.right - crInBox.left;
- FX_FLOAT fHeight = crInBox.top - crInBox.bottom;
-
- CPWL_PathData PathArray[] =
- {
- CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.45f, crInBox.top), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.45f, crInBox.top - PWL_BEZIER * fHeight * 0.4f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.45f - PWL_BEZIER * fWidth * 0.45f, crInBox.top - fHeight*0.4f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight*0.4f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top), PWLPT_LINETO),
-
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.60f, crInBox.top), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.75f, crInBox.top), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.75f, crInBox.top - PWL_BEZIER * fHeight * 0.7f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.75f - PWL_BEZIER * fWidth * 0.75f, crInBox.top - fHeight*0.7f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight*0.7f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight*0.55f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crInBox.left + PWL_BEZIER * fWidth*0.60f, crInBox.top - fHeight*0.55f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.60f, crInBox.top - PWL_BEZIER * fHeight * 0.55f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.60f, crInBox.top), PWLPT_BEZIERTO),
-
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.90f, crInBox.top), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.90f, crInBox.top - PWL_BEZIER * fHeight * 0.85f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.90f - PWL_BEZIER * fWidth * 0.90f, crInBox.top - fHeight*0.85f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight*0.85f), PWLPT_BEZIERTO),
- CPWL_PathData(CPWL_Point(crInBox.left, crInBox.bottom), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crInBox.right, crInBox.bottom), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crInBox.right, crInBox.top), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.90f, crInBox.top), PWLPT_LINETO),
-
- /*
- CPWL_PathData(CPWL_Point(crBBox.left, crBBox.top), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right, crBBox.top), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right, crBBox.bottom), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left, crBBox.bottom), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left, crBBox.top), PWLPT_LINETO),
-
- CPWL_PathData(CPWL_Point(crBBox.left+fOutWidth*0.04f, crBBox.top-fOutHeight*0.04f), PWLPT_MOVETO),
- CPWL_PathData(CPWL_Point(crBBox.right-fOutWidth*0.04f, crBBox.top-fOutHeight*0.04f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.right-fOutWidth*0.04f, crBBox.bottom+fOutHeight*0.04f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left+fOutWidth*0.04f, crBBox.bottom+fOutHeight*0.04f), PWLPT_LINETO),
- CPWL_PathData(CPWL_Point(crBBox.left+fOutWidth*0.04f, crBBox.top-fOutHeight*0.04f), PWLPT_LINETO),
- */
- };
-
- if(type == PWLPT_STREAM)
- sPathData = GetAppStreamFromArray(PathArray, 23);
- else
- GetPathDataFromArray(path, PathArray, 23);
-}
-
-void CPWL_Color::ConvertColorType(FX_INT32 nColorType)
-{
- switch (this->nColorType)
- {
- case COLORTYPE_TRANSPARENT:
- break;
- case COLORTYPE_GRAY:
- switch (nColorType)
- {
- case COLORTYPE_RGB:
- CPWL_Utils::ConvertGRAY2RGB(this->fColor1, this->fColor1, this->fColor2, this->fColor3);
- break;
- case COLORTYPE_CMYK:
- CPWL_Utils::ConvertGRAY2CMYK(this->fColor1, this->fColor1, this->fColor2, this->fColor3, this->fColor4);
- break;
- }
- break;
- case COLORTYPE_RGB:
- switch (nColorType)
- {
- case COLORTYPE_GRAY:
- CPWL_Utils::ConvertRGB2GRAY(this->fColor1, this->fColor2, this->fColor3, this->fColor1);
- break;
- case COLORTYPE_CMYK:
- CPWL_Utils::ConvertRGB2CMYK(this->fColor1, this->fColor2, this->fColor3, this->fColor1, this->fColor2, this->fColor3, this->fColor4);
- break;
- }
- break;
- case COLORTYPE_CMYK:
- switch (nColorType)
- {
- case COLORTYPE_GRAY:
- CPWL_Utils::ConvertCMYK2GRAY(this->fColor1, this->fColor2, this->fColor3, this->fColor4, this->fColor1);
- break;
- case COLORTYPE_RGB:
- CPWL_Utils::ConvertCMYK2RGB(this->fColor1, this->fColor2, this->fColor3, this->fColor4, this->fColor1, this->fColor2, this->fColor3);
- break;
- }
- break;
- }
- this->nColorType = nColorType;
-}
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+#include "../../include/pdfwindow/PWL_Icon.h"
+
+#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
+#define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
+
+/* ---------------------------- CPWL_Utils ------------------------------ */
+
+CFX_ByteString CPWL_Utils::GetAppStreamFromArray(const CPWL_PathData* pPathData, FX_INT32 nCount)
+{
+ CFX_ByteTextBuf csAP;
+
+ for (FX_INT32 i=0; i<nCount; i++)
+ {
+ switch (pPathData[i].type)
+ {
+ case PWLPT_MOVETO:
+ csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " m\n";
+ break;
+ case PWLPT_LINETO:
+ csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " l\n";
+ break;
+ case PWLPT_BEZIERTO:
+ csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " "
+ << pPathData[i+1].point.x << " " << pPathData[i+1].point.y << " "
+ << pPathData[i+2].point.x << " " << pPathData[i+2].point.y << " c\n";
+
+ i += 2;
+ break;
+ default:
+ break;
+ }
+ }
+
+ return csAP.GetByteString();
+}
+
+void CPWL_Utils::GetPathDataFromArray(CFX_PathData& path, const CPWL_PathData* pPathData, FX_INT32 nCount)
+{
+ path.SetPointCount(nCount);
+
+ for (FX_INT32 i=0; i<nCount; i++)
+ {
+ switch (pPathData[i].type)
+ {
+ case PWLPT_MOVETO:
+ path.SetPoint(i, pPathData[i].point.x, pPathData[i].point.y, FXPT_MOVETO);
+ break;
+ case PWLPT_LINETO:
+ path.SetPoint(i, pPathData[i].point.x, pPathData[i].point.y, FXPT_LINETO);
+ break;
+ case PWLPT_BEZIERTO:
+ path.SetPoint(i, pPathData[i].point.x, pPathData[i].point.y, FXPT_BEZIERTO);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+
+CPDF_Rect CPWL_Utils::MaxRect(const CPDF_Rect & rect1,const CPDF_Rect & rect2)
+{
+ CPDF_Rect rcRet;
+
+ rcRet.left = PWL_MIN(rect1.left,rect2.left);
+ rcRet.bottom = PWL_MIN(rect1.bottom,rect2.bottom);
+ rcRet.right = PWL_MAX(rect1.right,rect2.right);
+ rcRet.top = PWL_MAX(rect1.top,rect2.top);
+
+ return rcRet;
+}
+
+CPDF_Rect CPWL_Utils::OffsetRect(const CPDF_Rect & rect,FX_FLOAT x,FX_FLOAT y)
+{
+ return CPDF_Rect(rect.left + x,rect.bottom + y,
+ rect.right + x,rect.top + y);
+}
+
+FX_BOOL CPWL_Utils::ContainsRect(const CPDF_Rect& rcParent, const CPDF_Rect& rcChild)
+{
+ return rcChild.left >= rcParent.left && rcChild.bottom >= rcParent.bottom &&
+ rcChild.right <= rcParent.right && rcChild.top <= rcParent.top;
+}
+
+FX_BOOL CPWL_Utils::IntersectRect(const CPDF_Rect& rect1, const CPDF_Rect& rect2)
+{
+ FX_FLOAT left = rect1.left > rect2.left ? rect1.left : rect2.left;
+ FX_FLOAT right = rect1.right < rect2.right ? rect1.right : rect2.right;
+ FX_FLOAT bottom = rect1.bottom > rect2.bottom ? rect1.bottom : rect2.bottom;
+ FX_FLOAT top = rect1.top < rect2.top ? rect1.top : rect2.top;
+
+ return left < right && bottom < top;
+}
+
+CPDF_Point CPWL_Utils::OffsetPoint(const CPDF_Point& point,FX_FLOAT x,FX_FLOAT y)
+{
+ return CPDF_Point(point.x + x,point.y + y);
+}
+
+CPVT_WordRange CPWL_Utils::OverlapWordRange(const CPVT_WordRange & wr1, const CPVT_WordRange & wr2)
+{
+ CPVT_WordRange wrRet;
+
+ if (wr2.EndPos.WordCmp(wr1.BeginPos) < 0 || wr2.BeginPos.WordCmp(wr1.EndPos) > 0) return wrRet;
+ if (wr1.EndPos.WordCmp(wr2.BeginPos) < 0 || wr1.BeginPos.WordCmp(wr2.EndPos) > 0) return wrRet;
+
+ if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0)
+ {
+ wrRet.BeginPos = wr2.BeginPos;
+ }
+ else
+ {
+ wrRet.BeginPos = wr1.BeginPos;
+ }
+
+ if (wr1.EndPos.WordCmp(wr2.EndPos) < 0)
+ {
+ wrRet.EndPos = wr1.EndPos;
+ }
+ else
+ {
+ wrRet.EndPos = wr2.EndPos;
+ }
+
+ return wrRet;
+}
+
+CFX_ByteString CPWL_Utils::GetAP_Check(const CPDF_Rect & crBBox)
+{
+ CFX_ByteTextBuf csAP;
+
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ const FX_INT32 num = 8;
+
+ CPWL_Point pts[num*3] =
+ {
+ //1
+ CPWL_Point(0.28f, 0.52f),
+ CPWL_Point(0.27f, 0.48f),
+ CPWL_Point(0.29f, 0.40f),
+
+ //2
+ CPWL_Point(0.30f, 0.33f),
+ CPWL_Point(0.31f, 0.29f),
+ CPWL_Point(0.31f, 0.28f),
+
+ //3
+ CPWL_Point(0.39f, 0.28f),
+ CPWL_Point(0.49f, 0.29f),
+ CPWL_Point(0.77f, 0.67f),
+
+ //4
+ CPWL_Point(0.76f, 0.68f),
+ CPWL_Point(0.78f, 0.69f),
+ CPWL_Point(0.76f, 0.75f),
+
+ //5
+ CPWL_Point(0.76f, 0.75f),
+ CPWL_Point(0.73f, 0.80f),
+ CPWL_Point(0.68f, 0.75f),
+
+ //6
+ CPWL_Point(0.68f, 0.74f),
+ CPWL_Point(0.68f, 0.74f),
+ CPWL_Point(0.44f, 0.47f),
+
+ //7
+ CPWL_Point(0.43f, 0.47f),
+ CPWL_Point(0.40f, 0.47f),
+ CPWL_Point(0.41f, 0.58f),
+
+ //8
+ CPWL_Point(0.40f, 0.60f),
+ CPWL_Point(0.28f, 0.66f),
+ CPWL_Point(0.30f, 0.56f)
+ };
+
+ for (FX_INT32 j=0; j<num*3; j++)
+ {
+ pts[j].x *= fWidth;
+ pts[j].x += crBBox.left;
+
+ pts[j].y *= fHeight;
+ pts[j].y += crBBox.bottom;
+ }
+
+ csAP << pts[0].x << " " << pts[0].y << " m\n";
+
+ for (FX_INT32 i=0; i<num; i++)
+ {
+ FX_INT32 nCur = i*3;
+ FX_INT32 n1 = i*3 + 1;
+ FX_INT32 n2 = i*3 + 2;
+ FX_INT32 nNext = (i < num-1 ? (i+1)*3 : 0);
+
+ FX_FLOAT px1 = pts[n1].x - pts[nCur].x;
+ FX_FLOAT py1 = pts[n1].y - pts[nCur].y;
+ FX_FLOAT px2 = pts[n2].x - pts[nNext].x;
+ FX_FLOAT py2 = pts[n2].y - pts[nNext].y;
+
+ csAP << pts[nCur].x + px1 * PWL_BEZIER << " " << pts[nCur].y + py1 * PWL_BEZIER << " "
+ << pts[nNext].x + px2 * PWL_BEZIER << " " << pts[nNext].y + py2 * PWL_BEZIER << " "
+ << pts[nNext].x << " " << pts[nNext].y << " c\n";
+ }
+
+ return csAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAP_Circle(const CPDF_Rect & crBBox)
+{
+ CFX_ByteTextBuf csAP;
+
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPDF_Point pt1(crBBox.left,crBBox.bottom + fHeight / 2);
+ CPDF_Point pt2(crBBox.left + fWidth / 2,crBBox.top);
+ CPDF_Point pt3(crBBox.right,crBBox.bottom + fHeight / 2);
+ CPDF_Point pt4(crBBox.left + fWidth / 2,crBBox.bottom);
+
+ csAP << pt1.x << " " << pt1.y << " m\n";
+
+ FX_FLOAT px = pt2.x - pt1.x;
+ FX_FLOAT py = pt2.y - pt1.y;
+
+ csAP << pt1.x << " " << pt1.y + py * PWL_BEZIER << " "
+ << pt2.x - px * PWL_BEZIER << " " << pt2.y << " "
+ << pt2.x << " " << pt2.y << " c\n";
+
+ px = pt3.x - pt2.x;
+ py = pt2.y - pt3.y;
+
+ csAP << pt2.x + px * PWL_BEZIER << " " << pt2.y << " "
+ << pt3.x << " " << pt3.y + py * PWL_BEZIER << " "
+ << pt3.x << " " << pt3.y << " c\n";
+
+ px = pt3.x - pt4.x;
+ py = pt3.y - pt4.y;
+
+ csAP << pt3.x << " " << pt3.y - py * PWL_BEZIER << " "
+ << pt4.x + px * PWL_BEZIER << " " << pt4.y << " "
+ << pt4.x << " " << pt4.y << " c\n";
+
+ px = pt4.x - pt1.x;
+ py = pt1.y - pt4.y;
+
+ csAP << pt4.x - px * PWL_BEZIER << " " << pt4.y << " "
+ << pt1.x << " " << pt1.y - py * PWL_BEZIER << " "
+ << pt1.x << " " << pt1.y << " c\n";
+
+ return csAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAP_Cross(const CPDF_Rect & crBBox)
+{
+ CFX_ByteTextBuf csAP;
+
+ csAP << crBBox.left << " " << crBBox.top << " m\n";
+ csAP << crBBox.right << " " << crBBox.bottom << " l\n";
+ csAP << crBBox.left << " " << crBBox.bottom << " m\n";
+ csAP << crBBox.right << " " << crBBox.top << " l\n";
+
+ return csAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAP_Diamond(const CPDF_Rect & crBBox)
+{
+ CFX_ByteTextBuf csAP;
+
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPDF_Point pt1(crBBox.left,crBBox.bottom + fHeight / 2);
+ CPDF_Point pt2(crBBox.left + fWidth / 2,crBBox.top);
+ CPDF_Point pt3(crBBox.right,crBBox.bottom + fHeight / 2);
+ CPDF_Point pt4(crBBox.left + fWidth / 2,crBBox.bottom);
+
+ csAP << pt1.x << " " << pt1.y << " m\n";
+ csAP << pt2.x << " " << pt2.y << " l\n";
+ csAP << pt3.x << " " << pt3.y << " l\n";
+ csAP << pt4.x << " " << pt4.y << " l\n";
+ csAP << pt1.x << " " << pt1.y << " l\n";
+
+ return csAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAP_Square(const CPDF_Rect & crBBox)
+{
+ CFX_ByteTextBuf csAP;
+
+ csAP << crBBox.left << " " << crBBox.top << " m\n";
+ csAP << crBBox.right << " " << crBBox.top << " l\n";
+ csAP << crBBox.right << " " << crBBox.bottom << " l\n";
+ csAP << crBBox.left << " " << crBBox.bottom << " l\n";
+ csAP << crBBox.left << " " << crBBox.top << " l\n";
+
+ return csAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAP_Star(const CPDF_Rect & crBBox)
+{
+ CFX_ByteTextBuf csAP;
+
+ FX_FLOAT fRadius = (crBBox.top - crBBox.bottom)/(1+(FX_FLOAT)cos(PWL_PI/5.0f));
+ CPDF_Point ptCenter = CPDF_Point((crBBox.left + crBBox.right) / 2.0f,(crBBox.top + crBBox.bottom) / 2.0f);
+
+ FX_FLOAT px[5],py[5];
+
+ FX_FLOAT fAngel = PWL_PI/10.0f;
+
+ for (FX_INT32 i=0; i<5; i++)
+ {
+ px[i] = ptCenter.x + fRadius * (FX_FLOAT)cos(fAngel);
+ py[i] = ptCenter.y + fRadius * (FX_FLOAT)sin(fAngel);
+
+ fAngel += PWL_PI * 2 / 5.0f;
+ }
+
+ csAP << px[0] << " " << py[0] << " m\n";
+
+ FX_INT32 nNext = 0;
+ for (FX_INT32 j=0; j<5; j++)
+ {
+ nNext += 2;
+ if (nNext >= 5) nNext -= 5;
+ csAP << px[nNext] << " " << py[nNext] << " l\n";
+ }
+
+ return csAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAP_HalfCircle(const CPDF_Rect & crBBox,FX_FLOAT fRotate)
+{
+ CFX_ByteTextBuf csAP;
+
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPDF_Point pt1(-fWidth/2,0);
+ CPDF_Point pt2(0,fHeight/2);
+ CPDF_Point pt3(fWidth/2,0);
+
+ FX_FLOAT px,py;
+
+ csAP << cos(fRotate) << " " << sin(fRotate) << " " << -sin(fRotate) << " " << cos(fRotate) << " "
+ << crBBox.left + fWidth / 2 << " " << crBBox.bottom + fHeight / 2 << " cm\n";
+
+
+ csAP << pt1.x << " " << pt1.y << " m\n";
+
+ px = pt2.x - pt1.x;
+ py = pt2.y - pt1.y;
+
+ csAP << pt1.x << " " << pt1.y + py * PWL_BEZIER << " "
+ << pt2.x - px * PWL_BEZIER << " " << pt2.y << " "
+ << pt2.x << " " << pt2.y << " c\n";
+
+ px = pt3.x - pt2.x;
+ py = pt2.y - pt3.y;
+
+ csAP << pt2.x + px * PWL_BEZIER << " " << pt2.y << " "
+ << pt3.x << " " << pt3.y + py * PWL_BEZIER << " "
+ << pt3.x << " " << pt3.y << " c\n";
+
+ return csAP.GetByteString();
+}
+
+
+CPDF_Rect CPWL_Utils::InflateRect(const CPDF_Rect & rcRect, FX_FLOAT fSize)
+{
+ if (rcRect.IsEmpty()) return rcRect;
+
+ CPDF_Rect rcNew(rcRect.left - fSize,
+ rcRect.bottom - fSize,
+ rcRect.right + fSize,
+ rcRect.top + fSize);
+ rcNew.Normalize();
+ return rcNew;
+}
+
+CPDF_Rect CPWL_Utils::DeflateRect(const CPDF_Rect & rcRect, FX_FLOAT fSize)
+{
+ if (rcRect.IsEmpty()) return rcRect;
+
+ CPDF_Rect rcNew(rcRect.left + fSize,
+ rcRect.bottom + fSize,
+ rcRect.right - fSize,
+ rcRect.top - fSize);
+ rcNew.Normalize();
+ return rcNew;
+}
+
+CPDF_Rect CPWL_Utils::ScaleRect(const CPDF_Rect & rcRect,FX_FLOAT fScale)
+{
+ FX_FLOAT fHalfWidth = (rcRect.right - rcRect.left) / 2.0f;
+ FX_FLOAT fHalfHeight = (rcRect.top - rcRect.bottom) / 2.0f;
+
+ CPDF_Point ptCenter = CPDF_Point((rcRect.left + rcRect.right) / 2,(rcRect.top + rcRect.bottom) / 2);
+
+ return CPDF_Rect(ptCenter.x - fHalfWidth * fScale,
+ ptCenter.y - fHalfHeight * fScale,
+ ptCenter.x + fHalfWidth * fScale,
+ ptCenter.y + fHalfHeight * fScale);
+}
+
+CFX_ByteString CPWL_Utils::GetRectFillAppStream(const CPDF_Rect & rect,const CPWL_Color & color)
+{
+ CFX_ByteTextBuf sAppStream;
+
+ CFX_ByteString sColor = GetColorAppStream(color,TRUE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << sColor;
+ sAppStream << rect.left << " " << rect.bottom << " "
+ << rect.right - rect.left << " " << rect.top - rect.bottom << " re f\nQ\n";
+ }
+
+ return sAppStream.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetCircleFillAppStream(const CPDF_Rect & rect,const CPWL_Color & color)
+{
+ CFX_ByteTextBuf sAppStream;
+
+ CFX_ByteString sColor = GetColorAppStream(color,TRUE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << sColor << CPWL_Utils::GetAP_Circle(rect) << "f\nQ\n";
+ }
+
+ return sAppStream.GetByteString();
+}
+
+CPDF_Rect CPWL_Utils::GetCenterSquare(const CPDF_Rect & rect)
+{
+ FX_FLOAT fWidth = rect.right - rect.left;
+ FX_FLOAT fHeight = rect.top - rect.bottom;
+
+ FX_FLOAT fCenterX = (rect.left + rect.right)/2.0f;
+ FX_FLOAT fCenterY = (rect.top + rect.bottom)/2.0f;
+
+ FX_FLOAT fRadius = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2;
+
+ return CPDF_Rect(fCenterX - fRadius,fCenterY - fRadius,fCenterX + fRadius,fCenterY + fRadius);
+}
+
+CFX_ByteString CPWL_Utils::GetEditAppStream(IFX_Edit* pEdit, const CPDF_Point & ptOffset, const CPVT_WordRange * pRange,
+ FX_BOOL bContinuous, FX_WORD SubWord)
+{
+ return IFX_Edit::GetEditAppearanceStream(pEdit,ptOffset,pRange,bContinuous,SubWord);
+}
+
+CFX_ByteString CPWL_Utils::GetEditSelAppStream(IFX_Edit* pEdit, const CPDF_Point & ptOffset,
+ const CPVT_WordRange * pRange)
+{
+ return IFX_Edit::GetSelectAppearanceStream(pEdit,ptOffset,pRange);
+}
+
+static CFX_ByteString GetSquigglyAppearanceStream(FX_FLOAT fStartX, FX_FLOAT fEndX, FX_FLOAT fY, FX_FLOAT fStep)
+{
+ CFX_ByteTextBuf sRet;
+
+ sRet << "0 w\n" << fStartX << " " << fY << " m\n";
+
+ FX_FLOAT fx;
+ FX_INT32 i;
+
+ for (i=1,fx=fStartX+fStep; fx<fEndX; fx+=fStep,i++)
+ {
+ sRet << fx << " " << fY + (i&1)*fStep << " l\n";
+ }
+
+ sRet << "S\n";
+
+ return sRet.GetByteString();
+}
+
+static CFX_ByteString GetWordSpellCheckAppearanceStream(IFX_Edit_Iterator* pIterator, const CPDF_Point & ptOffset,
+ const CPVT_WordRange & wrWord)
+{
+ CFX_ByteTextBuf sRet;
+
+ FX_FLOAT fStartX = 0.0f;
+ FX_FLOAT fEndX = 0.0f;
+ FX_FLOAT fY = 0.0f;
+ FX_FLOAT fStep = 0.0f;
+
+ FX_BOOL bBreak = FALSE;
+
+ if (pIterator)
+ {
+ pIterator->SetAt(wrWord.BeginPos);
+
+ do
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+
+ CPVT_Line line;
+ if (pIterator->GetLine(line))
+ {
+ fY = line.ptLine.y;
+ fStep = (line.fLineAscent - line.fLineDescent) / 16.0f;
+ }
+
+ if (place.LineCmp(wrWord.BeginPos) == 0)
+ {
+ pIterator->SetAt(wrWord.BeginPos);
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ fStartX = word.ptWord.x;
+ }
+ }
+ else
+ {
+ fStartX = line.ptLine.x;
+ }
+
+ if (place.LineCmp(wrWord.EndPos) == 0)
+ {
+ pIterator->SetAt(wrWord.EndPos);
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ fEndX = word.ptWord.x + word.fWidth;
+ }
+
+ bBreak = TRUE;
+ }
+ else
+ {
+ fEndX = line.ptLine.x + line.fLineWidth;
+ }
+
+ sRet << GetSquigglyAppearanceStream(fStartX + ptOffset.x, fEndX + ptOffset.x, fY + ptOffset.y,fStep);
+
+ if (bBreak) break;
+ }
+ while (pIterator->NextLine());
+ }
+
+ return sRet.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetSpellCheckAppStream(IFX_Edit* pEdit, IPWL_SpellCheck* pSpellCheck, const CPDF_Point & ptOffset,
+ const CPVT_WordRange * pRange)
+{
+ ASSERT(pEdit != NULL);
+ ASSERT(pSpellCheck != NULL);
+
+ CFX_ByteTextBuf sRet;
+
+ if (pRange && pRange->IsExist())
+ {
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ pIterator->SetAt(pRange->BeginPos);
+
+ FX_BOOL bLatinWord = FALSE;
+ CPVT_WordPlace wpWordStart;
+ CFX_ByteString sWord;
+
+ CPVT_WordPlace oldplace;
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ if (FX_EDIT_ISLATINWORD(word.Word))
+ {
+ if (!bLatinWord)
+ {
+ wpWordStart = place;
+ bLatinWord = TRUE;
+ }
+
+ sWord += (char)word.Word;
+ oldplace = place;
+ }
+ else
+ {
+ if (bLatinWord)
+ {
+ if (!pSpellCheck->CheckWord(sWord))
+ {
+ sRet << GetWordSpellCheckAppearanceStream(pIterator,ptOffset,CPVT_WordRange(wpWordStart,oldplace));
+ pIterator->SetAt(place);
+ }
+ bLatinWord = FALSE;
+ }
+
+ sWord.Empty();
+ }
+ }
+ else
+ {
+ if (bLatinWord)
+ {
+ if (!pSpellCheck->CheckWord(sWord))
+ sRet << GetWordSpellCheckAppearanceStream(pIterator,ptOffset,CPVT_WordRange(wpWordStart,oldplace));
+ bLatinWord = FALSE;
+ sWord.Empty();
+ }
+ }
+ }
+
+ if (bLatinWord)
+ {
+ if (!pSpellCheck->CheckWord(sWord))
+ sRet << GetWordSpellCheckAppearanceStream(pIterator,ptOffset,CPVT_WordRange(wpWordStart,oldplace));
+
+ bLatinWord = FALSE;
+ sWord.Empty();
+ }
+ }
+ }
+
+ return sRet.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetTextAppStream(const CPDF_Rect & rcBBox,IFX_Edit_FontMap * pFontMap,
+ const CFX_WideString & sText, FX_INT32 nAlignmentH, FX_INT32 nAlignmentV,
+ FX_FLOAT fFontSize, FX_BOOL bMultiLine, FX_BOOL bAutoReturn, const CPWL_Color & crText)
+{
+ CFX_ByteTextBuf sRet;
+
+ if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
+ {
+ pEdit->SetFontMap(pFontMap);
+
+ pEdit->SetPlateRect(rcBBox);
+ pEdit->SetAlignmentH(nAlignmentH);
+ pEdit->SetAlignmentV(nAlignmentV);
+ pEdit->SetMultiLine(bMultiLine);
+ pEdit->SetAutoReturn(bAutoReturn);
+ if (IsFloatZero(fFontSize))
+ pEdit->SetAutoFontSize(TRUE);
+ else
+ pEdit->SetFontSize(fFontSize);
+ pEdit->Initialize();
+
+ pEdit->SetText(sText);
+
+ CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit, CPDF_Point(0.0f,0.0f));
+ if (sEdit.GetLength() > 0)
+ {
+ sRet << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n";
+ }
+
+ IFX_Edit::DelEdit(pEdit);
+ }
+
+ return sRet.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CPDF_Rect & rcBBox,
+ IFX_Edit_FontMap * pFontMap,
+ CPDF_Stream * pIconStream,
+ CPDF_IconFit & IconFit,
+ const CFX_WideString & sLabel,
+ const CPWL_Color & crText,
+ FX_FLOAT fFontSize,
+ FX_INT32 nLayOut)
+{
+ const FX_FLOAT fAutoFontScale = 1.0f / 3.0f;
+
+ if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
+ {
+ pEdit->SetFontMap(pFontMap);
+
+ pEdit->SetAlignmentH(1);
+ pEdit->SetAlignmentV(1);
+ pEdit->SetMultiLine(FALSE);
+ pEdit->SetAutoReturn(FALSE);
+ if (IsFloatZero(fFontSize))
+ pEdit->SetAutoFontSize(TRUE);
+ else
+ pEdit->SetFontSize(fFontSize);
+ pEdit->Initialize();
+ pEdit->SetText(sLabel);
+
+ CPDF_Rect rcLabelContent = pEdit->GetContentRect();
+
+ CPWL_Icon Icon;
+ PWL_CREATEPARAM cp;
+ cp.dwFlags = PWS_VISIBLE;
+ Icon.Create(cp);
+ Icon.SetIconFit(&IconFit);
+ Icon.SetPDFStream(pIconStream);
+
+ CPDF_Rect rcLabel = CPDF_Rect(0,0,0,0);
+ CPDF_Rect rcIcon = CPDF_Rect(0,0,0,0);
+ FX_FLOAT fWidth = 0.0f;
+ FX_FLOAT fHeight = 0.0f;
+
+ switch (nLayOut)
+ {
+ case PPBL_LABEL:
+ rcLabel = rcBBox;
+ rcIcon = CPDF_Rect(0,0,0,0);
+ break;
+ case PPBL_ICON:
+ rcIcon = rcBBox;
+ rcLabel = CPDF_Rect(0,0,0,0);
+ break;
+ case PPBL_ICONTOPLABELBOTTOM:
+
+ if (pIconStream)
+ {
+ if (IsFloatZero(fFontSize))
+ {
+ fHeight = rcBBox.top - rcBBox.bottom;
+ rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.right,rcBBox.bottom + fHeight * fAutoFontScale);
+ rcIcon = CPDF_Rect(rcBBox.left,rcLabel.top,rcBBox.right,rcBBox.top);
+ }
+ else
+ {
+ fHeight = rcLabelContent.Height();
+
+ if (rcBBox.bottom + fHeight > rcBBox.top)
+ {
+ rcIcon = CPDF_Rect(0,0,0,0);
+ rcLabel = rcBBox;
+ }
+ else
+ {
+ rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.right,rcBBox.bottom + fHeight);
+ rcIcon = CPDF_Rect(rcBBox.left,rcLabel.top,rcBBox.right,rcBBox.top);
+ }
+ }
+ }
+ else
+ {
+ rcLabel = rcBBox;
+ rcIcon = CPDF_Rect(0,0,0,0);
+ }
+
+ break;
+ case PPBL_LABELTOPICONBOTTOM:
+
+ if (pIconStream)
+ {
+ if (IsFloatZero(fFontSize))
+ {
+ fHeight = rcBBox.top - rcBBox.bottom;
+ rcLabel = CPDF_Rect(rcBBox.left,rcBBox.top - fHeight * fAutoFontScale ,rcBBox.right,rcBBox.top);
+ rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.right,rcLabel.bottom);
+ }
+ else
+ {
+ fHeight = rcLabelContent.Height();
+
+ if (rcBBox.bottom + fHeight > rcBBox.top)
+ {
+ rcIcon = CPDF_Rect(0,0,0,0);
+ rcLabel = rcBBox;
+ }
+ else
+ {
+ rcLabel = CPDF_Rect(rcBBox.left,rcBBox.top - fHeight,rcBBox.right,rcBBox.top);
+ rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.right,rcLabel.bottom);
+ }
+ }
+ }
+ else
+ {
+ rcLabel = rcBBox;
+ rcIcon = CPDF_Rect(0,0,0,0);
+ }
+
+ break;
+ case PPBL_ICONLEFTLABELRIGHT:
+
+ if (pIconStream)
+ {
+ if (IsFloatZero(fFontSize))
+ {
+ fWidth = rcBBox.right - rcBBox.left;
+ rcLabel = CPDF_Rect(rcBBox.right - fWidth * fAutoFontScale,rcBBox.bottom,rcBBox.right,rcBBox.top);
+ rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcLabel.left,rcBBox.top);
+
+ if (rcLabelContent.Width() < fWidth * fAutoFontScale)
+ {
+ }
+ else
+ {
+ if (rcLabelContent.Width() < fWidth)
+ {
+ rcLabel = CPDF_Rect(rcBBox.right - rcLabelContent.Width(),rcBBox.bottom,rcBBox.right,rcBBox.top);
+ rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcLabel.left,rcBBox.top);
+ }
+ else
+ {
+ rcLabel = rcBBox;
+ rcIcon = CPDF_Rect(0,0,0,0);
+ }
+ }
+ }
+ else
+ {
+ fWidth = rcLabelContent.Width();
+
+ if (rcBBox.left + fWidth > rcBBox.right)
+ {
+ rcLabel = rcBBox;
+ rcIcon = CPDF_Rect(0,0,0,0);
+ }
+ else
+ {
+ rcLabel = CPDF_Rect(rcBBox.right - fWidth,rcBBox.bottom,rcBBox.right,rcBBox.top);
+ rcIcon = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcLabel.left,rcBBox.top);
+ }
+ }
+ }
+ else
+ {
+ rcLabel = rcBBox;
+ rcIcon = CPDF_Rect(0,0,0,0);
+ }
+
+ break;
+ case PPBL_LABELLEFTICONRIGHT:
+
+ if (pIconStream)
+ {
+ if (IsFloatZero(fFontSize))
+ {
+ fWidth = rcBBox.right - rcBBox.left;
+ rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.left + fWidth * fAutoFontScale,rcBBox.top);
+ rcIcon = CPDF_Rect(rcLabel.right,rcBBox.bottom,rcBBox.right,rcBBox.top);
+
+ if (rcLabelContent.Width() < fWidth * fAutoFontScale)
+ {
+ }
+ else
+ {
+ if (rcLabelContent.Width() < fWidth)
+ {
+ rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.left + rcLabelContent.Width(),rcBBox.top);
+ rcIcon = CPDF_Rect(rcLabel.right,rcBBox.bottom,rcBBox.right,rcBBox.top);
+ }
+ else
+ {
+ rcLabel = rcBBox;
+ rcIcon = CPDF_Rect(0,0,0,0);
+ }
+ }
+ }
+ else
+ {
+ fWidth = rcLabelContent.Width();
+
+ if (rcBBox.left + fWidth > rcBBox.right)
+ {
+ rcLabel = rcBBox;
+ rcIcon = CPDF_Rect(0,0,0,0);
+ }
+ else
+ {
+ rcLabel = CPDF_Rect(rcBBox.left,rcBBox.bottom,rcBBox.left + fWidth,rcBBox.top);
+ rcIcon = CPDF_Rect(rcLabel.right,rcBBox.bottom,rcBBox.right,rcBBox.top);
+ }
+ }
+ }
+ else
+ {
+ rcLabel = rcBBox;
+ rcIcon = CPDF_Rect(0,0,0,0);
+ }
+
+ break;
+ case PPBL_LABELOVERICON:
+ rcLabel = rcBBox;
+ rcIcon = rcBBox;
+ break;
+ }
+
+ CFX_ByteTextBuf sAppStream,sTemp;
+
+ if (!rcIcon.IsEmpty())
+ {
+ Icon.Move(rcIcon, FALSE, FALSE);
+ sTemp << Icon.GetImageAppStream();
+ }
+
+ Icon.Destroy();
+
+ if (!rcLabel.IsEmpty())
+ {
+ pEdit->SetPlateRect(rcLabel);
+ CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f));
+ if (sEdit.GetLength() > 0)
+ {
+ sTemp << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n";
+ }
+ }
+
+ IFX_Edit::DelEdit(pEdit);
+
+ if (sTemp.GetSize() > 0)
+ {
+ sAppStream << "q\n" << rcBBox.left << " " << rcBBox.bottom << " "
+ << rcBBox.right - rcBBox.left << " " << rcBBox.top - rcBBox.bottom << " re W n\n";
+ sAppStream << sTemp << "Q\n";
+ }
+
+ return sAppStream.GetByteString();
+ }
+
+ return "";
+}
+
+CFX_ByteString CPWL_Utils::GetColorAppStream(const CPWL_Color & color,const FX_BOOL & bFillOrStroke)
+{
+ CFX_ByteTextBuf sColorStream;
+
+ switch (color.nColorType)
+ {
+ case COLORTYPE_RGB:
+ sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " "
+ << (bFillOrStroke ? "rg" : "RG") << "\n";
+ break;
+ case COLORTYPE_GRAY:
+ sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") << "\n";
+ break;
+ case COLORTYPE_CMYK:
+ sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " " << color.fColor4 << " "
+ << (bFillOrStroke ? "k" : "K") << "\n";
+ break;
+ }
+
+ return sColorStream.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetBorderAppStream(const CPDF_Rect & rect, FX_FLOAT fWidth,
+ const CPWL_Color & color, const CPWL_Color & crLeftTop, const CPWL_Color & crRightBottom,
+ FX_INT32 nStyle, const CPWL_Dash & dash)
+{
+ CFX_ByteTextBuf sAppStream;
+ CFX_ByteString sColor;
+
+ FX_FLOAT fLeft = rect.left;
+ FX_FLOAT fRight = rect.right;
+ FX_FLOAT fTop = rect.top;
+ FX_FLOAT fBottom = rect.bottom;
+
+ if (fWidth > 0.0f)
+ {
+ FX_FLOAT fHalfWidth = fWidth / 2.0f;
+
+ sAppStream << "q\n";
+
+ switch (nStyle)
+ {
+ default:
+ case PBS_SOLID:
+ sColor = CPWL_Utils::GetColorAppStream(color,TRUE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << sColor;
+ sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " << fTop - fBottom << " re\n";
+ sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " "
+ << fRight - fLeft - fWidth * 2 << " " << fTop - fBottom - fWidth * 2 << " re\n";
+ sAppStream << "f*\n";
+ }
+ break;
+ case PBS_DASH:
+ sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << sColor;
+ sAppStream << fWidth << " w" << " [" << dash.nDash << " " << dash.nGap << "] " << dash.nPhase << " d\n";
+ sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 << " m\n";
+ sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2 << " l\n";
+ sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2 << " l\n";
+ sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2 << " l\n";
+ sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 << " l S\n";
+ }
+ break;
+ case PBS_BEVELED:
+ case PBS_INSET:
+ sColor = CPWL_Utils::GetColorAppStream(crLeftTop,TRUE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << sColor;
+ sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " m\n";
+ sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth << " l\n";
+ sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth << " l\n";
+ sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 << " l\n";
+ sAppStream << fLeft + fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 << " l\n";
+ sAppStream << fLeft + fHalfWidth * 2 << " " << fBottom + fHalfWidth * 2 << " l f\n";
+ }
+
+ sColor = CPWL_Utils::GetColorAppStream(crRightBottom,TRUE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << sColor;
+ sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth << " m\n";
+ sAppStream << fRight - fHalfWidth << " " << fBottom + fHalfWidth << " l\n";
+ sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " l\n";
+ sAppStream << fLeft + fHalfWidth * 2 << " " << fBottom + fHalfWidth * 2 << " l\n";
+ sAppStream << fRight - fHalfWidth * 2 << " " << fBottom + fHalfWidth * 2 << " l\n";
+ sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 << " l f\n";
+ }
+
+ sColor = CPWL_Utils::GetColorAppStream(color,TRUE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << sColor;
+ sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " << fTop - fBottom << " re\n";
+ sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " "
+ << fRight - fLeft - fHalfWidth * 2 << " " << fTop - fBottom - fHalfWidth * 2 << " re f*\n";
+ }
+ break;
+ case PBS_UNDERLINED:
+ sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << sColor;
+ sAppStream << fWidth << " w\n";
+ sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n";
+ sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n";
+ }
+ break;
+ }
+
+ sAppStream << "Q\n";
+ }
+
+ return sAppStream.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetCircleBorderAppStream(const CPDF_Rect & rect, FX_FLOAT fWidth,
+ const CPWL_Color & color, const CPWL_Color & crLeftTop, const CPWL_Color & crRightBottom,
+ FX_INT32 nStyle, const CPWL_Dash & dash)
+{
+ CFX_ByteTextBuf sAppStream;
+ CFX_ByteString sColor;
+
+
+
+
+
+
+ if (fWidth > 0.0f)
+ {
+ sAppStream << "q\n";
+
+ switch (nStyle)
+ {
+ default:
+ case PBS_SOLID:
+ case PBS_UNDERLINED:
+ {
+ sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << fWidth << " w\n" << sColor
+ << CPWL_Utils::GetAP_Circle(CPWL_Utils::DeflateRect(rect,fWidth / 2.0f))
+ << " S\nQ\n";
+ }
+ }
+ break;
+ case PBS_DASH:
+ {
+ sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << fWidth << " w\n"
+ << "[" << dash.nDash << " " << dash.nGap << "] " << dash.nPhase << " d\n"
+ << sColor << CPWL_Utils::GetAP_Circle(CPWL_Utils::DeflateRect(rect,fWidth / 2.0f))
+ << " S\nQ\n";
+ }
+ }
+ break;
+ case PBS_BEVELED:
+ {
+ FX_FLOAT fHalfWidth = fWidth / 2.0f;
+
+ sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << fHalfWidth << " w\n"
+ << sColor << CPWL_Utils::GetAP_Circle(rect)
+ << " S\nQ\n";
+ }
+
+ sColor = CPWL_Utils::GetColorAppStream(crLeftTop,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << fHalfWidth << " w\n"
+ << sColor << CPWL_Utils::GetAP_HalfCircle(CPWL_Utils::DeflateRect(rect,fHalfWidth * 0.75f),PWL_PI/4.0f)
+ << " S\nQ\n";
+ }
+
+ sColor = CPWL_Utils::GetColorAppStream(crRightBottom,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << fHalfWidth << " w\n"
+ << sColor << CPWL_Utils::GetAP_HalfCircle(CPWL_Utils::DeflateRect(rect,fHalfWidth * 0.75f),PWL_PI*5/4.0f)
+ << " S\nQ\n";
+ }
+ }
+ break;
+ case PBS_INSET:
+ {
+ FX_FLOAT fHalfWidth = fWidth / 2.0f;
+
+ sColor = CPWL_Utils::GetColorAppStream(color,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << fHalfWidth << " w\n"
+ << sColor << CPWL_Utils::GetAP_Circle(rect)
+ << " S\nQ\n";
+ }
+
+ sColor = CPWL_Utils::GetColorAppStream(crLeftTop,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << fHalfWidth << " w\n"
+ << sColor << CPWL_Utils::GetAP_HalfCircle(CPWL_Utils::DeflateRect(rect,fHalfWidth * 0.75f),PWL_PI/4.0f)
+ << " S\nQ\n";
+ }
+
+ sColor = CPWL_Utils::GetColorAppStream(crRightBottom,FALSE);
+ if (sColor.GetLength() > 0)
+ {
+ sAppStream << "q\n" << fHalfWidth << " w\n"
+ << sColor << CPWL_Utils::GetAP_HalfCircle(CPWL_Utils::DeflateRect(rect,fHalfWidth * 0.75f),PWL_PI*5/4.0f)
+ << " S\nQ\n";
+ }
+ }
+ break;
+ }
+
+ sAppStream << "Q\n";
+ }
+
+ return sAppStream.GetByteString();
+}
+
+CPWL_Color CPWL_Utils::SubstractColor(const CPWL_Color & sColor,FX_FLOAT fColorSub)
+{
+ CPWL_Color sRet;
+ sRet.nColorType = sColor.nColorType;
+
+ switch (sColor.nColorType)
+ {
+ case COLORTYPE_TRANSPARENT:
+ sRet.nColorType = COLORTYPE_RGB;
+ sRet.fColor1 = PWL_MAX(1 - fColorSub,0.0f);
+ sRet.fColor2 = PWL_MAX(1 - fColorSub,0.0f);
+ sRet.fColor3 = PWL_MAX(1 - fColorSub,0.0f);
+ break;
+ case COLORTYPE_RGB:
+ case COLORTYPE_GRAY:
+ case COLORTYPE_CMYK:
+ sRet.fColor1 = PWL_MAX(sColor.fColor1 - fColorSub,0.0f);
+ sRet.fColor2 = PWL_MAX(sColor.fColor2 - fColorSub,0.0f);
+ sRet.fColor3 = PWL_MAX(sColor.fColor3 - fColorSub,0.0f);
+ sRet.fColor4 = PWL_MAX(sColor.fColor4 - fColorSub,0.0f);
+ break;
+ }
+
+ return sRet;
+}
+
+CPWL_Color CPWL_Utils::DevideColor(const CPWL_Color & sColor,FX_FLOAT fColorDevide)
+{
+ CPWL_Color sRet;
+ sRet.nColorType = sColor.nColorType;
+
+ switch (sColor.nColorType)
+ {
+ case COLORTYPE_TRANSPARENT:
+ sRet.nColorType = COLORTYPE_RGB;
+ sRet.fColor1 = 1 / fColorDevide;
+ sRet.fColor2 = 1 / fColorDevide;
+ sRet.fColor3 = 1 / fColorDevide;
+ break;
+ case COLORTYPE_RGB:
+ case COLORTYPE_GRAY:
+ case COLORTYPE_CMYK:
+ sRet = sColor;
+ sRet.fColor1 /= fColorDevide;
+ sRet.fColor2 /= fColorDevide;
+ sRet.fColor3 /= fColorDevide;
+ sRet.fColor4 /= fColorDevide;
+ break;
+ }
+
+ return sRet;
+}
+
+CFX_ByteString CPWL_Utils::GetAppStream_Check(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
+{
+ CFX_ByteTextBuf sAP;
+ sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Check(rcBBox) << "f\nQ\n";
+ return sAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAppStream_Circle(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
+{
+ CFX_ByteTextBuf sAP;
+ sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Circle(rcBBox) << "f\nQ\n";
+ return sAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAppStream_Cross(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
+{
+ CFX_ByteTextBuf sAP;
+ sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,FALSE) << CPWL_Utils::GetAP_Cross(rcBBox) << "S\nQ\n";
+ return sAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAppStream_Diamond(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
+{
+ CFX_ByteTextBuf sAP;
+ sAP << "q\n1 w\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Diamond(rcBBox) << "f\nQ\n";
+ return sAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAppStream_Square(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
+{
+ CFX_ByteTextBuf sAP;
+ sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Square(rcBBox) << "f\nQ\n";
+ return sAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetAppStream_Star(const CPDF_Rect & rcBBox, const CPWL_Color & crText)
+{
+ CFX_ByteTextBuf sAP;
+ sAP << "q\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << CPWL_Utils::GetAP_Star(rcBBox) << "f\nQ\n";
+ return sAP.GetByteString();
+}
+
+CFX_ByteString CPWL_Utils::GetCheckBoxAppStream(const CPDF_Rect & rcBBox,
+ FX_INT32 nStyle,
+ const CPWL_Color & crText)
+{
+ CPDF_Rect rcCenter = GetCenterSquare(rcBBox);
+ switch (nStyle)
+ {
+ default:
+ case PCS_CHECK:
+ return GetAppStream_Check(rcCenter,crText);
+ case PCS_CIRCLE:
+ return GetAppStream_Circle(ScaleRect(rcCenter,2.0f/3.0f),crText);
+ case PCS_CROSS:
+ return GetAppStream_Cross(rcCenter,crText);
+ case PCS_DIAMOND:
+ return GetAppStream_Diamond(ScaleRect(rcCenter,2.0f/3.0f),crText);
+ case PCS_SQUARE:
+ return GetAppStream_Square(ScaleRect(rcCenter,2.0f/3.0f),crText);
+ case PCS_STAR:
+ return GetAppStream_Star(ScaleRect(rcCenter,2.0f/3.0f),crText);
+ }
+}
+
+CFX_ByteString CPWL_Utils::GetRadioButtonAppStream(const CPDF_Rect & rcBBox,
+ FX_INT32 nStyle,
+ const CPWL_Color & crText)
+{
+ CPDF_Rect rcCenter = GetCenterSquare(rcBBox);
+ switch (nStyle)
+ {
+ default:
+ case PCS_CHECK:
+ return GetAppStream_Check(rcCenter,crText);
+ case PCS_CIRCLE:
+ return GetAppStream_Circle(ScaleRect(rcCenter,1.0f/2.0f),crText);
+ case PCS_CROSS:
+ return GetAppStream_Cross(rcCenter,crText);
+ case PCS_DIAMOND:
+ return GetAppStream_Diamond(ScaleRect(rcCenter,2.0f/3.0f),crText);
+ case PCS_SQUARE:
+ return GetAppStream_Square(ScaleRect(rcCenter,2.0f/3.0f),crText);
+ case PCS_STAR:
+ return GetAppStream_Star(ScaleRect(rcCenter,2.0f/3.0f),crText);
+ }
+}
+
+CFX_ByteString CPWL_Utils::GetDropButtonAppStream(const CPDF_Rect & rcBBox)
+{
+ CFX_ByteTextBuf sAppStream;
+
+ if (!rcBBox.IsEmpty())
+ {
+ sAppStream << "q\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,220.0f/255.0f,220.0f/255.0f,220.0f/255.0f),TRUE);
+ sAppStream << rcBBox.left << " " << rcBBox.bottom << " "
+ << rcBBox.right - rcBBox.left << " " << rcBBox.top - rcBBox.bottom << " re f\n";
+ sAppStream << "Q\n";
+
+ sAppStream << "q\n" <<
+ CPWL_Utils::GetBorderAppStream(rcBBox,2,CPWL_Color(COLORTYPE_GRAY,0),CPWL_Color(COLORTYPE_GRAY,1),CPWL_Color(COLORTYPE_GRAY,0.5),PBS_BEVELED,CPWL_Dash(3,0,0))
+ << "Q\n";
+
+ CPDF_Point ptCenter = CPDF_Point((rcBBox.left + rcBBox.right)/2,(rcBBox.top + rcBBox.bottom)/2);
+ if (IsFloatBigger(rcBBox.right - rcBBox.left,6) && IsFloatBigger(rcBBox.top - rcBBox.bottom,6))
+ {
+ sAppStream << "q\n" << " 0 g\n";
+ sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n";
+ sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n";
+ sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n";
+ sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n";
+ sAppStream << "Q\n";
+ }
+ }
+
+ return sAppStream.GetByteString();
+}
+
+void CPWL_Utils::ConvertCMYK2GRAY(FX_FLOAT dC,FX_FLOAT dM,FX_FLOAT dY,FX_FLOAT dK,FX_FLOAT &dGray)
+{
+ if (dC<0 || dC>1 || dM<0 || dM>1 || dY < 0 || dY >1 || dK < 0 || dK >1)
+ return;
+ dGray = 1.0f - FX_MIN(1.0f,0.3f*dC+0.59f * dM + 0.11f*dY+dK);
+}
+
+void CPWL_Utils::ConvertGRAY2CMYK(FX_FLOAT dGray,FX_FLOAT &dC,FX_FLOAT &dM,FX_FLOAT &dY,FX_FLOAT &dK)
+{
+ if (dGray <0 || dGray >1)
+ return;
+ dC = 0.0f;
+ dM = 0.0f;
+ dY = 0.0f;
+ dK = 1.0f-dGray;
+}
+
+void CPWL_Utils::ConvertGRAY2RGB(FX_FLOAT dGray,FX_FLOAT &dR,FX_FLOAT &dG,FX_FLOAT &dB)
+{
+ if (dGray <0 || dGray >1)
+ return;
+ dR = dGray;
+ dG = dGray;
+ dB = dGray;
+}
+
+void CPWL_Utils::ConvertRGB2GRAY(FX_FLOAT dR,FX_FLOAT dG,FX_FLOAT dB,FX_FLOAT &dGray)
+{
+ if (dR<0 || dR>1 || dG<0 || dG > 0 || dB < 0 || dB >1)
+ return;
+ dGray = 0.3f*dR+0.59f*dG+0.11f*dB;
+}
+
+void CPWL_Utils::ConvertCMYK2RGB(FX_FLOAT dC,FX_FLOAT dM,FX_FLOAT dY,FX_FLOAT dK,FX_FLOAT &dR,FX_FLOAT &dG,FX_FLOAT &dB)
+{
+ if (dC <0 || dC>1 || dM < 0 || dM > 1 || dY < 0 || dY > 1 || dK < 0 || dK > 1 )
+ return;
+ dR = 1.0f - FX_MIN(1.0f, dC + dK);
+ dG = 1.0f - FX_MIN(1.0f, dM + dK);
+ dB = 1.0f - FX_MIN(1.0f, dY + dK);
+}
+
+void CPWL_Utils::ConvertRGB2CMYK(FX_FLOAT dR,FX_FLOAT dG,FX_FLOAT dB,FX_FLOAT &dC,FX_FLOAT &dM,FX_FLOAT &dY,FX_FLOAT &dK)
+{
+ if (dR<0 || dR>1 || dG<0 || dG>1 || dB<0 || dB>1)
+ return;
+
+ dC = 1.0f - dR;
+ dM = 1.0f - dG;
+ dY = 1.0f - dB;
+ dK = FX_MIN(dC, FX_MIN(dM, dY));
+}
+
+void CPWL_Utils::PWLColorToARGB(const CPWL_Color& color, FX_INT32& alpha, FX_FLOAT& red, FX_FLOAT& green, FX_FLOAT& blue)
+{
+ switch (color.nColorType)
+ {
+ case COLORTYPE_TRANSPARENT:
+ {
+ alpha = 0;
+ }
+ break;
+ case COLORTYPE_GRAY:
+ {
+ ConvertGRAY2RGB(color.fColor1, red, green, blue);
+ }
+ break;
+ case COLORTYPE_RGB:
+ {
+ red = color.fColor1;
+ green = color.fColor2;
+ blue = color.fColor3;
+ }
+ break;
+ case COLORTYPE_CMYK:
+ {
+ ConvertCMYK2RGB(color.fColor1, color.fColor2, color.fColor3, color.fColor4,
+ red, green, blue);
+ }
+ break;
+ }
+}
+
+FX_COLORREF CPWL_Utils::PWLColorToFXColor(const CPWL_Color& color, FX_INT32 nTransparancy)
+{
+ FX_INT32 nAlpha = nTransparancy;
+ FX_FLOAT dRed = 0;
+ FX_FLOAT dGreen = 0;
+ FX_FLOAT dBlue = 0;
+
+ PWLColorToARGB(color, nAlpha, dRed, dGreen, dBlue);
+
+ return ArgbEncode(nAlpha, (FX_INT32)(dRed*255), (FX_INT32)(dGreen*255), (FX_INT32)(dBlue*255));
+}
+
+void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,const CPDF_Rect & rect,
+ const FX_COLORREF & color)
+{
+ CFX_PathData path;
+ CPDF_Rect rcTemp(rect);
+ path.AppendRect(rcTemp.left,rcTemp.bottom,rcTemp.right,rcTemp.top);
+ pDevice->DrawPath(&path, pUser2Device, NULL, color, 0, FXFILL_WINDING);
+}
+
+void CPWL_Utils::DrawFillArea(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ const CPDF_Point* pPts, FX_INT32 nCount, const FX_COLORREF& color)
+{
+ CFX_PathData path;
+ path.SetPointCount(nCount);
+
+ path.SetPoint(0, pPts[0].x, pPts[0].y, FXPT_MOVETO);
+ for (FX_INT32 i=1; i<nCount; i++)
+ path.SetPoint(i, pPts[i].x, pPts[i].y, FXPT_LINETO);
+
+ pDevice->DrawPath(&path, pUser2Device, NULL, color, 0, FXFILL_ALTERNATE);
+}
+
+void CPWL_Utils::DrawStrokeRect(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,const CPDF_Rect & rect,
+ const FX_COLORREF & color, FX_FLOAT fWidth)
+{
+ CFX_PathData path;
+ CPDF_Rect rcTemp(rect);
+ path.AppendRect(rcTemp.left,rcTemp.bottom,rcTemp.right,rcTemp.top);
+
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = fWidth;
+
+ pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE);
+}
+
+void CPWL_Utils::DrawStrokeLine(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ const CPDF_Point & ptMoveTo, const CPDF_Point & ptLineTo, const FX_COLORREF & color, FX_FLOAT fWidth)
+{
+ CFX_PathData path;
+ path.SetPointCount(2);
+ path.SetPoint(0, ptMoveTo.x, ptMoveTo.y, FXPT_MOVETO);
+ path.SetPoint(1, ptLineTo.x, ptLineTo.y, FXPT_LINETO);
+
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = fWidth;
+
+ pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE);
+}
+
+void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,const CPDF_Rect & rect,
+ const CPWL_Color & color, FX_INT32 nTransparancy)
+{
+ CPWL_Utils::DrawFillRect(pDevice,pUser2Device,rect,PWLColorToFXColor(color,nTransparancy));
+}
+
+void CPWL_Utils::DrawShadow(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ FX_BOOL bVertical, FX_BOOL bHorizontal, CPDF_Rect rect,
+ FX_INT32 nTransparancy, FX_INT32 nStartGray, FX_INT32 nEndGray)
+{
+ FX_FLOAT fStepGray = 1.0f;
+
+ if (bVertical)
+ {
+ fStepGray = (nEndGray - nStartGray) / rect.Height();
+
+ for (FX_FLOAT fy=rect.bottom+0.5f; fy<=rect.top-0.5f; fy+=1.0f)
+ {
+ FX_INT32 nGray = nStartGray + (FX_INT32)(fStepGray * (fy-rect.bottom));
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, CPDF_Point(rect.left, fy),
+ CPDF_Point(rect.right, fy), ArgbEncode(nTransparancy, nGray, nGray, nGray), 1.5f);
+ }
+ }
+
+ if (bHorizontal)
+ {
+ fStepGray = (nEndGray - nStartGray) / rect.Width();
+
+ for (FX_FLOAT fx=rect.left+0.5f; fx<=rect.right-0.5f; fx+=1.0f)
+ {
+ FX_INT32 nGray = nStartGray + (FX_INT32)(fStepGray * (fx-rect.left));
+ CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, CPDF_Point(fx, rect.bottom),
+ CPDF_Point(fx, rect.top), ArgbEncode(nTransparancy, nGray, nGray, nGray), 1.5f);
+ }
+ }
+}
+
+void CPWL_Utils::DrawBorder(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ const CPDF_Rect & rect, FX_FLOAT fWidth,
+ const CPWL_Color & color, const CPWL_Color & crLeftTop, const CPWL_Color & crRightBottom,
+ FX_INT32 nStyle, const CPWL_Dash & dash, FX_INT32 nTransparancy)
+{
+ FX_FLOAT fLeft = rect.left;
+ FX_FLOAT fRight = rect.right;
+ FX_FLOAT fTop = rect.top;
+ FX_FLOAT fBottom = rect.bottom;
+
+ if (fWidth > 0.0f)
+ {
+ FX_FLOAT fHalfWidth = fWidth / 2.0f;
+
+ switch (nStyle)
+ {
+ default:
+ case PBS_SOLID:
+ {
+ CFX_PathData path;
+ path.AppendRect(fLeft, fBottom, fRight, fTop);
+ path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth, fTop - fWidth);
+ pDevice->DrawPath(&path, pUser2Device, NULL, PWLColorToFXColor(color,nTransparancy), 0, FXFILL_ALTERNATE);
+ }
+ break;
+ case PBS_DASH:
+ {
+ CFX_PathData path;
+
+ path.SetPointCount(5);
+ path.SetPoint(0, fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f, FXPT_MOVETO);
+ path.SetPoint(1, fLeft + fWidth / 2.0f, fTop - fWidth / 2.0f, FXPT_LINETO);
+ path.SetPoint(2, fRight - fWidth / 2.0f, fTop - fWidth / 2.0f, FXPT_LINETO);
+ path.SetPoint(3, fRight - fWidth / 2.0f, fBottom + fWidth / 2.0f, FXPT_LINETO);
+ path.SetPoint(4, fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f, FXPT_LINETO);
+
+ CFX_GraphStateData gsd;
+ gsd.SetDashCount(2);
+ gsd.m_DashArray[0] = 3.0f;
+ gsd.m_DashArray[1] = 3.0f;
+ gsd.m_DashPhase = 0;
+
+ gsd.m_LineWidth = fWidth;
+ pDevice->DrawPath(&path, pUser2Device, &gsd, 0, PWLColorToFXColor(color,nTransparancy), FXFILL_WINDING);
+ }
+ break;
+ case PBS_BEVELED:
+ case PBS_INSET:
+ {
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = fHalfWidth;
+
+ CFX_PathData pathLT;
+
+ pathLT.SetPointCount(7);
+ pathLT.SetPoint(0, fLeft + fHalfWidth, fBottom + fHalfWidth, FXPT_MOVETO);
+ pathLT.SetPoint(1, fLeft + fHalfWidth, fTop - fHalfWidth, FXPT_LINETO);
+ pathLT.SetPoint(2, fRight - fHalfWidth, fTop - fHalfWidth, FXPT_LINETO);
+ pathLT.SetPoint(3, fRight - fHalfWidth * 2, fTop - fHalfWidth * 2, FXPT_LINETO);
+ pathLT.SetPoint(4, fLeft + fHalfWidth * 2, fTop - fHalfWidth * 2, FXPT_LINETO);
+ pathLT.SetPoint(5, fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2, FXPT_LINETO);
+ pathLT.SetPoint(6, fLeft + fHalfWidth, fBottom + fHalfWidth, FXPT_LINETO);
+
+ pDevice->DrawPath(&pathLT, pUser2Device, &gsd, PWLColorToFXColor(crLeftTop,nTransparancy), 0, FXFILL_ALTERNATE);
+
+ CFX_PathData pathRB;
+
+ pathRB.SetPointCount(7);
+ pathRB.SetPoint(0, fRight - fHalfWidth, fTop - fHalfWidth, FXPT_MOVETO);
+ pathRB.SetPoint(1, fRight - fHalfWidth, fBottom + fHalfWidth, FXPT_LINETO);
+ pathRB.SetPoint(2, fLeft + fHalfWidth, fBottom + fHalfWidth, FXPT_LINETO);
+ pathRB.SetPoint(3, fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2, FXPT_LINETO);
+ pathRB.SetPoint(4, fRight - fHalfWidth * 2, fBottom + fHalfWidth * 2, FXPT_LINETO);
+ pathRB.SetPoint(5, fRight - fHalfWidth * 2, fTop - fHalfWidth * 2, FXPT_LINETO);
+ pathRB.SetPoint(6, fRight - fHalfWidth, fTop - fHalfWidth, FXPT_LINETO);
+
+ pDevice->DrawPath(&pathRB, pUser2Device, &gsd, PWLColorToFXColor(crRightBottom,nTransparancy), 0, FXFILL_ALTERNATE);
+
+ CFX_PathData path;
+
+ path.AppendRect(fLeft, fBottom, fRight, fTop);
+ path.AppendRect(fLeft + fHalfWidth, fBottom + fHalfWidth, fRight - fHalfWidth, fTop - fHalfWidth);
+
+ pDevice->DrawPath(&path, pUser2Device, &gsd, PWLColorToFXColor(color,nTransparancy), 0, FXFILL_ALTERNATE);
+ }
+ break;
+ case PBS_UNDERLINED:
+ {
+ CFX_PathData path;
+
+ path.SetPointCount(2);
+ path.SetPoint(0, fLeft, fBottom + fWidth / 2, FXPT_MOVETO);
+ path.SetPoint(1, fRight, fBottom + fWidth / 2, FXPT_LINETO);
+
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = fWidth;
+
+ pDevice->DrawPath(&path, pUser2Device, &gsd,0, PWLColorToFXColor(color,nTransparancy), FXFILL_ALTERNATE);
+ }
+ break;
+ case PBS_SHADOW:
+ {
+ CFX_PathData path;
+ path.AppendRect(fLeft, fBottom, fRight, fTop);
+ path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth, fTop - fWidth);
+ pDevice->DrawPath(&path, pUser2Device, NULL, PWLColorToFXColor(color,nTransparancy/2), 0, FXFILL_ALTERNATE);
+ }
+ break;
+ }
+ }
+}
+
+static void AddSquigglyPath(CFX_PathData & PathData, FX_FLOAT fStartX, FX_FLOAT fEndX, FX_FLOAT fY, FX_FLOAT fStep)
+{
+ PathData.AddPointCount(1);
+ PathData.SetPoint(PathData.GetPointCount() - 1, fStartX, fY, FXPT_MOVETO);
+
+ FX_FLOAT fx;
+ FX_INT32 i;
+
+ for (i=1,fx=fStartX+fStep; fx<fEndX; fx+=fStep,i++)
+ {
+ PathData.AddPointCount(1);
+ PathData.SetPoint(PathData.GetPointCount() - 1, fx, fY + (i&1)*fStep, FXPT_LINETO);
+ }
+}
+
+static void AddSpellCheckObj(CFX_PathData & PathData, IFX_Edit* pEdit, const CPVT_WordRange& wrWord)
+{
+ FX_FLOAT fStartX = 0.0f;
+ FX_FLOAT fEndX = 0.0f;
+ FX_FLOAT fY = 0.0f;
+ FX_FLOAT fStep = 0.0f;
+
+ FX_BOOL bBreak = FALSE;
+
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ pIterator->SetAt(wrWord.BeginPos);
+
+ do
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+
+ CPVT_Line line;
+ if (pIterator->GetLine(line))
+ {
+ fY = line.ptLine.y;
+ fStep = (line.fLineAscent - line.fLineDescent) / 16.0f;
+ }
+
+ if (place.LineCmp(wrWord.BeginPos) == 0)
+ {
+ pIterator->SetAt(wrWord.BeginPos);
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ fStartX = word.ptWord.x;
+ }
+ }
+ else
+ {
+ fStartX = line.ptLine.x;
+ }
+
+ if (place.LineCmp(wrWord.EndPos) == 0)
+ {
+ pIterator->SetAt(wrWord.EndPos);
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ fEndX = word.ptWord.x + word.fWidth;
+ }
+
+ bBreak = TRUE;
+ }
+ else
+ {
+ fEndX = line.ptLine.x + line.fLineWidth;
+ }
+
+ AddSquigglyPath(PathData, fStartX, fEndX, fY, fStep);
+
+ if (bBreak) break;
+ }
+ while (pIterator->NextLine());
+ }
+}
+
+void CPWL_Utils::DrawEditSpellCheck(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, IFX_Edit* pEdit,
+ const CPDF_Rect& rcClip, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange,
+ IPWL_SpellCheck * pSpellCheck)
+{
+ const FX_COLORREF crSpell = ArgbEncode(255,255,0,0);
+
+ //for spellcheck
+ FX_BOOL bLatinWord = FALSE;
+ CPVT_WordPlace wpWordStart;
+ CFX_ByteString sLatinWord;
+
+ CFX_PathData pathSpell;
+
+ pDevice->SaveState();
+
+ if (!rcClip.IsEmpty())
+ {
+ CPDF_Rect rcTemp = rcClip;
+ pUser2Device->TransformRect(rcTemp);
+ FX_RECT rcDevClip;
+ rcDevClip.left = (FX_INT32)rcTemp.left;
+ rcDevClip.right = (FX_INT32)rcTemp.right;
+ rcDevClip.top = (FX_INT32)rcTemp.top;
+ rcDevClip.bottom = (FX_INT32)rcTemp.bottom;
+ pDevice->SetClip_Rect(&rcDevClip);
+ }
+
+ if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator())
+ {
+ if (pEdit->GetFontMap())
+ {
+ if (pRange)
+ pIterator->SetAt(pRange->BeginPos);
+ else
+ pIterator->SetAt(0);
+
+ CPVT_WordPlace oldplace;
+
+ while (pIterator->NextWord())
+ {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (pRange && place.WordCmp(pRange->EndPos) > 0) break;
+
+ CPVT_Word word;
+ if (pIterator->GetWord(word))
+ {
+ if (FX_EDIT_ISLATINWORD(word.Word))
+ {
+ if (!bLatinWord)
+ {
+ wpWordStart = place;
+ bLatinWord = TRUE;
+ }
+
+ sLatinWord += (char)word.Word;
+ }
+ else
+ {
+ if (bLatinWord)
+ {
+ if (!sLatinWord.IsEmpty())
+ {
+ if (pSpellCheck && !pSpellCheck->CheckWord(sLatinWord))
+ {
+ AddSpellCheckObj(pathSpell,pEdit,CPVT_WordRange(wpWordStart,oldplace));
+ pIterator->SetAt(place);
+ }
+ }
+ bLatinWord = FALSE;
+ }
+
+ sLatinWord.Empty();
+ }
+
+ oldplace = place;
+ }
+ else
+ {
+ if (bLatinWord)
+ {
+ if (!sLatinWord.IsEmpty())
+ {
+ if (pSpellCheck && !pSpellCheck->CheckWord(sLatinWord))
+ {
+ AddSpellCheckObj(pathSpell,pEdit,CPVT_WordRange(wpWordStart,oldplace));
+ pIterator->SetAt(place);
+ }
+ }
+ bLatinWord = FALSE;
+ }
+
+ sLatinWord.Empty();
+ }
+ }
+
+ if (!sLatinWord.IsEmpty())
+ {
+ if (pSpellCheck && !pSpellCheck->CheckWord(sLatinWord))
+ {
+ AddSpellCheckObj(pathSpell,pEdit,CPVT_WordRange(wpWordStart,oldplace));
+ }
+ }
+ }
+ }
+
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = 0;
+ if (pathSpell.GetPointCount() > 0)
+ pDevice->DrawPath(&pathSpell, pUser2Device, &gsd, 0, crSpell, FXFILL_ALTERNATE);
+
+ pDevice->RestoreState();
+}
+
+FX_BOOL CPWL_Utils::IsBlackOrWhite(const CPWL_Color& color)
+{
+ switch (color.nColorType)
+ {
+ case COLORTYPE_TRANSPARENT:
+ return FALSE;
+ case COLORTYPE_GRAY:
+ return color.fColor1 < 0.5f;
+ case COLORTYPE_RGB:
+ return color.fColor1 + color.fColor2 + color.fColor3 < 1.5f;
+ case COLORTYPE_CMYK:
+ return color.fColor1 + color.fColor2 + color.fColor3 + color.fColor4 > 2.0f;
+ }
+
+ return TRUE;
+}
+
+CPWL_Color CPWL_Utils::GetReverseColor(const CPWL_Color& color)
+{
+ CPWL_Color crRet = color;
+
+ switch (color.nColorType)
+ {
+ case COLORTYPE_GRAY:
+ crRet.fColor1 = 1.0f - crRet.fColor1;
+ break;
+ case COLORTYPE_RGB:
+ crRet.fColor1 = 1.0f - crRet.fColor1;
+ crRet.fColor2 = 1.0f - crRet.fColor2;
+ crRet.fColor3 = 1.0f - crRet.fColor3;
+ break;
+ case COLORTYPE_CMYK:
+ crRet.fColor1 = 1.0f - crRet.fColor1;
+ crRet.fColor2 = 1.0f - crRet.fColor2;
+ crRet.fColor3 = 1.0f - crRet.fColor3;
+ crRet.fColor4 = 1.0f - crRet.fColor4;
+ break;
+ }
+
+ return crRet;
+}
+
+CFX_ByteString CPWL_Utils::GetIconAppStream(FX_INT32 nType, const CPDF_Rect& rect, const CPWL_Color& crFill,
+ const CPWL_Color& crStroke)
+{
+ CFX_ByteString sAppStream = CPWL_Utils::GetColorAppStream(crStroke, FALSE);
+ sAppStream += CPWL_Utils::GetColorAppStream(crFill, TRUE);
+
+ CFX_ByteString sPath;
+ CFX_PathData path;
+
+ switch (nType)
+ {
+ case PWL_ICONTYPE_CHECKMARK:
+ GetGraphics_Checkmark(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_CIRCLE:
+ GetGraphics_Circle(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_COMMENT:
+ GetGraphics_Comment(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_CROSS:
+ GetGraphics_Cross(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_HELP:
+ GetGraphics_Help(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_INSERTTEXT:
+ GetGraphics_InsertText(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_KEY:
+ GetGraphics_Key(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_NEWPARAGRAPH:
+ GetGraphics_NewParagraph(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_TEXTNOTE:
+ GetGraphics_TextNote(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_PARAGRAPH:
+ GetGraphics_Paragraph(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_RIGHTARROW:
+ GetGraphics_RightArrow(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_RIGHTPOINTER:
+ GetGraphics_RightPointer(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_STAR:
+ GetGraphics_Star(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_UPARROW:
+ GetGraphics_UpArrow(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_UPLEFTARROW:
+ GetGraphics_UpLeftArrow(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_GRAPH:
+ GetGraphics_Graph(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_PAPERCLIP:
+ GetGraphics_Paperclip(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_ATTACHMENT:
+ GetGraphics_Attachment(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_TAG:
+ GetGraphics_Tag(sPath, path, rect, PWLPT_STREAM);
+ break;
+ case PWL_ICONTYPE_FOXIT:
+ GetGraphics_Foxit(sPath, path, rect, PWLPT_STREAM);
+ break;
+ }
+
+ sAppStream += sPath;
+ if (crStroke.nColorType != COLORTYPE_TRANSPARENT)
+ sAppStream += "B*\n";
+ else
+ sAppStream += "f*\n";
+
+ return sAppStream;
+}
+
+void CPWL_Utils::DrawIconAppStream(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
+ FX_INT32 nType, const CPDF_Rect & rect, const CPWL_Color& crFill, const CPWL_Color& crStroke, const FX_INT32 nTransparancy)
+{
+ CFX_GraphStateData gsd;
+ gsd.m_LineWidth = 1.0f;
+
+ CFX_ByteString sPath;
+ CFX_PathData path;
+
+ switch (nType)
+ {
+ case PWL_ICONTYPE_CHECKMARK:
+ GetGraphics_Checkmark(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_CIRCLE:
+ GetGraphics_Circle(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_COMMENT:
+ GetGraphics_Comment(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_CROSS:
+ GetGraphics_Cross(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_HELP:
+ GetGraphics_Help(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_INSERTTEXT:
+ GetGraphics_InsertText(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_KEY:
+ GetGraphics_Key(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_NEWPARAGRAPH:
+ GetGraphics_NewParagraph(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_TEXTNOTE:
+ GetGraphics_TextNote(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_PARAGRAPH:
+ GetGraphics_Paragraph(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_RIGHTARROW:
+ GetGraphics_RightArrow(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_RIGHTPOINTER:
+ GetGraphics_RightPointer(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_STAR:
+ GetGraphics_Star(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_UPARROW:
+ GetGraphics_UpArrow(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_UPLEFTARROW:
+ GetGraphics_UpLeftArrow(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_GRAPH:
+ GetGraphics_Graph(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_PAPERCLIP:
+ GetGraphics_Paperclip(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_ATTACHMENT:
+ GetGraphics_Attachment(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_TAG:
+ GetGraphics_Tag(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ case PWL_ICONTYPE_FOXIT:
+ GetGraphics_Foxit(sPath, path, rect, PWLPT_PATHDATA);
+ break;
+ default:
+ return;
+ }
+
+ pDevice->DrawPath(&path, pUser2Device, &gsd,
+ PWLColorToFXColor(crFill,nTransparancy), PWLColorToFXColor(crStroke,nTransparancy), FXFILL_ALTERNATE);
+}
+
+void CPWL_Utils::GetGraphics_Checkmark(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f, crBBox.bottom + fHeight * 2 / 5.0f),PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f + PWL_BEZIER*(fWidth / 7.0f - fWidth / 15.0f),
+ crBBox.bottom + fHeight * 2 / 5.0f + PWL_BEZIER*(fHeight * 2 / 7.0f - fHeight * 2 / 5.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 4.5f + PWL_BEZIER*(fWidth / 5.0f - fWidth / 4.5f),
+ crBBox.bottom + fHeight / 16.0f + PWL_BEZIER*(fHeight / 5.0f - fHeight / 16.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 4.5f, crBBox.bottom + fHeight / 16.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 4.5f + PWL_BEZIER*(fWidth / 4.4f - fWidth / 4.5f),
+ crBBox.bottom + fHeight / 16.0f - PWL_BEZIER*fHeight / 16.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.0f + PWL_BEZIER*(fWidth / 4.0f - fWidth / 3.0f),
+ crBBox.bottom), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.0f, crBBox.bottom), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.0f + PWL_BEZIER*fWidth*(1/7.0f + 2/15.0f),
+ crBBox.bottom + PWL_BEZIER*fHeight * 4 / 5.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 14 / 15.0f + PWL_BEZIER*fWidth*(1/7.0f - 7/15.0f),
+ crBBox.bottom + fHeight * 15/16.0f + PWL_BEZIER*(fHeight * 4/5.0f - fHeight * 15/16.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 14 / 15.0f,crBBox.bottom + fHeight * 15 / 16.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth * 14 / 15.0f + PWL_BEZIER*(fWidth * 7 / 15.0f - fWidth * 14 / 15.0f),
+ crBBox.bottom + fHeight * 15 / 16.0f + PWL_BEZIER*(fHeight * 8 / 7.0f - fHeight * 15 / 16.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.6f + PWL_BEZIER*(fWidth / 3.4f - fWidth / 3.6f),
+ crBBox.bottom + fHeight / 3.5f + PWL_BEZIER*(fHeight / 3.5f - fHeight / 3.5f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.6f,crBBox.bottom + fHeight / 3.5f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 3.6f,
+ crBBox.bottom + fHeight / 3.5f + PWL_BEZIER*(fHeight / 4.0f - fHeight / 3.5f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f + PWL_BEZIER*(fWidth / 3.5f - fWidth / 15.0f),
+ crBBox.bottom + fHeight * 2 / 5.0f + PWL_BEZIER*(fHeight * 3.5f / 5.0f - fHeight * 2 / 5.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth / 15.0f,crBBox.bottom + fHeight * 2 / 5.0f), PWLPT_BEZIERTO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 16);
+ else
+ GetPathDataFromArray(path, PathArray, 16);
+}
+
+void CPWL_Utils::GetGraphics_Circle(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f,crBBox.bottom + fHeight/2.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f,
+ crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight*14/15.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth/2.0f - fWidth/15.0f), crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f,crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*(fWidth*14/15.0f - fWidth/2.0f), crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight*14/15.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight/2.0f - PWL_BEZIER*(fHeight/2.0f - fHeight/15.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*(fWidth*14/15.0f - fWidth/2.0f), crBBox.bottom + fHeight/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth/2.0f - fWidth/15.0f), crBBox.bottom + fHeight/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.bottom + fHeight/2.0f - PWL_BEZIER*(fHeight/2.0f - fHeight/15.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f,crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight*4/5.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth/2.0f - fWidth*3/15.0f), crBBox.top - fHeight*3/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight*3/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*(fWidth*4/5.0f - fWidth/2.0f), crBBox.top - fHeight*3/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight*4/5.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f - PWL_BEZIER*(fHeight*4/5.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*(fWidth*4/5.0f - fWidth/2.0f), crBBox.bottom + fHeight*3/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight*3/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth*4/5.0f - fWidth/2.0f), crBBox.bottom + fHeight*3/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f - PWL_BEZIER*(fHeight*4/5.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*3/15.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 26);
+ else
+ GetPathDataFromArray(path, PathArray, 26);
+}
+
+void CPWL_Utils::GetGraphics_Comment(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.top - fHeight/6.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.top - fHeight/6.0f + PWL_BEZIER*(fHeight/6.0f - fHeight/10.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f - PWL_BEZIER*fWidth/15.0f, crBBox.top - fHeight/10.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f, crBBox.top - fHeight/10.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f, crBBox.top - fHeight/10.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f + PWL_BEZIER*fWidth/15.0f, crBBox.top - fHeight/10.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.top - fHeight/6 + PWL_BEZIER*(fHeight/6.0f - fHeight/10.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.top - fHeight/6.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight/3.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.bottom + fHeight*4/15.0f + PWL_BEZIER*fHeight/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f + PWL_BEZIER*fWidth/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*5/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*5/15.0f, crBBox.bottom + fHeight*2/15 + PWL_BEZIER*fHeight*2/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*5/15.0f - PWL_BEZIER*fWidth*2/15.0f, crBBox.bottom + fHeight*2/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*6/30.0f, crBBox.bottom + fHeight*2/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*7/30.0f + PWL_BEZIER*fWidth/30.0f, crBBox.bottom + fHeight*2/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*7/30.0f, crBBox.bottom + fHeight*2/15.0f + PWL_BEZIER*fHeight*2/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*7/30.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f - PWL_BEZIER*fWidth/15.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.bottom + fHeight/3.0f - PWL_BEZIER*fHeight/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.bottom + fHeight/3.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/15.0f, crBBox.top - fHeight/6.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f, crBBox.top - fHeight*8/30.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f, crBBox.top - fHeight*8/30.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15, crBBox.top - fHeight*25/60.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*2/15.0f, crBBox.top - fHeight*25/60.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*2/15.0f, crBBox.top - fHeight*17/30.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*4/15.0f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 30);
+ else
+ GetPathDataFromArray(path, PathArray, 30);
+}
+
+void CPWL_Utils::GetGraphics_Cross(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+ //FX_FLOAT fcatercorner = (FX_FLOAT)sqrt(fWidth*fWidth + fHeight*fHeight);
+ CPWL_Point center_point(crBBox.left + fWidth/2, crBBox.bottom + fHeight/2);
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(center_point.x, center_point.y + fHeight/10.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(center_point.x + fWidth*0.3f, center_point.y + fHeight/10.0f + fWidth*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x + fWidth/10.0f + fWidth*0.3f, center_point.y + fHeight*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x + fWidth/10.0f, center_point.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x + fWidth/10.0f + fWidth*0.3f, center_point.y - fHeight*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x + fWidth*0.3f, center_point.y - fHeight/10.0f - fHeight*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x, center_point.y - fHeight/10.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x - fWidth*0.3f, center_point.y - fHeight/10 - fHeight*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x - fWidth/10.0f - fWidth*0.3f, center_point.y - fHeight*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x - fWidth/10, center_point.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x - fWidth/10 - fWidth*0.3f, center_point.y + fHeight*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x - fWidth*0.3f, center_point.y + fHeight/10.0f + fHeight*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(center_point.x, center_point.y + fHeight/10.0f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 13);
+ else
+ GetPathDataFromArray(path, PathArray, 13);
+}
+
+void CPWL_Utils::GetGraphics_Help(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60.0f, crBBox.bottom + fHeight/2.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight/60.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*(fWidth/2.0f - fWidth/60.0f), crBBox.bottom + fHeight/60.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight/60.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*fWidth*29/60.0f, crBBox.bottom + fHeight/60.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/60.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*(fHeight/60.0f - fHeight/2.0f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/60.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/60.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*fHeight*29/60.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + PWL_BEZIER*fWidth*29/60.0f, crBBox.top - fHeight/60.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/60.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f - PWL_BEZIER*fWidth*29/60.0f, crBBox.top - fHeight/60.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60.0f, crBBox.bottom + fHeight/2.0f + PWL_BEZIER*fHeight*29/60.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60.0f, crBBox.bottom + fHeight/2.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.27f, crBBox.top - fHeight*0.36f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.27f, crBBox.top - fHeight*0.36f + PWL_BEZIER*fHeight*0.23f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f - PWL_BEZIER*fWidth*0.23f, crBBox.bottom + fHeight*0.87f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.bottom + fHeight*0.87f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f + PWL_BEZIER*fWidth*0.23f, crBBox.bottom + fHeight*0.87f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.27f, crBBox.top - fHeight*0.36f + PWL_BEZIER*fHeight*0.23f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.27f, crBBox.top - fHeight*0.36f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.27f - fWidth*0.08f*0.2f, crBBox.top - fHeight*0.36f - fHeight*0.15f*0.7f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.35f + fWidth*0.08f*0.2f, crBBox.top - fHeight*0.51f + fHeight*0.15f*0.2f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.35f, crBBox.top - fHeight*0.51f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.35f - fWidth*0.1f*0.5f, crBBox.top - fHeight*0.51f - fHeight*0.15f*0.3f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f - fWidth*0.1f*0.5f, crBBox.top - fHeight*0.68f + fHeight*0.15f*0.5f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f, crBBox.top - fHeight*0.68f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f, crBBox.bottom + fHeight*0.30f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f, crBBox.bottom + fHeight*0.30f - fWidth*0.1f*0.7f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.55f, crBBox.bottom + fHeight*0.30f - fWidth*0.1f*0.7f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.55f, crBBox.bottom + fHeight*0.30f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.55f, crBBox.top - fHeight*0.66f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.55f - fWidth*0.1f*0.05f, crBBox.top - fHeight*0.66f + fHeight*0.18f*0.5f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f - fWidth*0.1f*0.05f, crBBox.top - fHeight*0.48f - fHeight*0.18f*0.3f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f, crBBox.top - fHeight*0.48f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.45f + fWidth*0.08f*0.2f, crBBox.top - fHeight*0.48f + fHeight*0.18f*0.2f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.37f - fWidth*0.08f*0.2f, crBBox.top - fHeight*0.36f - fHeight*0.18f*0.7f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.37f, crBBox.top - fHeight*0.36f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.37f, crBBox.top - fHeight*0.36f + PWL_BEZIER*fHeight*0.13f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f + PWL_BEZIER*fWidth*0.13f, crBBox.bottom + fHeight*0.77f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.bottom + fHeight*0.77f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f - PWL_BEZIER*fWidth*0.13f, crBBox.bottom + fHeight*0.77f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.37f, crBBox.top - fHeight*0.36f + PWL_BEZIER*fHeight*0.13f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.37f, crBBox.top - fHeight*0.36f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.37f, crBBox.top - fHeight*0.36f - fWidth*0.1f*0.6f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.27f, crBBox.top - fHeight*0.36f - fWidth*0.1f*0.6f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.27f, crBBox.top - fHeight*0.36f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.56f, crBBox.bottom + fHeight*0.13f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.56f, crBBox.bottom + fHeight*0.13f + PWL_BEZIER*fHeight*0.055f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f - PWL_BEZIER*fWidth*0.095f, crBBox.bottom + fHeight*0.185f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f, crBBox.bottom + fHeight*0.185f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f + PWL_BEZIER*fWidth*0.065f, crBBox.bottom + fHeight*0.185f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.44f, crBBox.bottom + fHeight*0.13f + PWL_BEZIER*fHeight*0.055f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.44f, crBBox.bottom + fHeight*0.13f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.44f, crBBox.bottom + fHeight*0.13f - PWL_BEZIER*fHeight*0.055f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f + PWL_BEZIER*fWidth*0.065f, crBBox.bottom + fHeight*0.075f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f, crBBox.bottom + fHeight*0.075f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.505f - PWL_BEZIER*fWidth*0.065f, crBBox.bottom + fHeight*0.075f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.56f, crBBox.bottom + fHeight*0.13f - PWL_BEZIER*fHeight*0.055f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.56f, crBBox.bottom + fHeight*0.13f), PWLPT_BEZIERTO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 59);
+ else
+ GetPathDataFromArray(path, PathArray, 59);
+}
+
+void CPWL_Utils::GetGraphics_InsertText(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10, crBBox.bottom + fHeight/10), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2, crBBox.top - fHeight*2/15), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10, crBBox.bottom + fHeight/10), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10, crBBox.bottom + fHeight/10), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 4);
+ else
+ GetPathDataFromArray(path, PathArray, 4);
+}
+
+void CPWL_Utils::GetGraphics_Key(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+ FX_FLOAT k = -fHeight/fWidth;
+ CPWL_Point tail;
+ CPWL_Point CicleCenter;
+ tail.x = crBBox.left + fWidth*0.9f;
+ tail.y = k*(tail.x - crBBox.right) + crBBox.bottom;
+ CicleCenter.x = crBBox.left + fWidth*0.15f;
+ CicleCenter.y = k*(CicleCenter.x - crBBox.right) + crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30.0f, -fWidth/30.0f/k + tail.y), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30.0f - fWidth*0.18f, -k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f + fWidth*0.07f,
+ -fWidth*0.07f/k - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 + fWidth*0.07f,
+ -fWidth*0.07f/k - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20,
+ -k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 - fWidth/15,
+ -k*fWidth/15 - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 - fWidth/15 + fWidth*0.07f,
+ -fWidth*0.07f/k - k*fWidth/15 - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 - fWidth/15 - fWidth/20 + fWidth*0.07f,
+ -fWidth*0.07f/k + -k*fWidth/20 + -k*fWidth/15 - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.18f - fWidth/20 - fWidth/15 - fWidth/20,
+ -k*fWidth/20 + -k*fWidth/15 - k*fWidth/20 - k*fWidth*0.18f - fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.45f, -k*fWidth*0.45f - fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30 - fWidth*0.45f + fWidth*0.2f,
+ -fWidth*0.4f/k - k*fWidth*0.45f - fWidth/30/k + tail.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.2f, - fWidth*0.1f/k + CicleCenter.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x, CicleCenter.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x - fWidth/60.0f, -k*fWidth/60 + CicleCenter.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x - fWidth/60, -k*fWidth/60 + CicleCenter.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x, CicleCenter.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x - fWidth*0.22f, fWidth*0.35f/k + CicleCenter.y - fHeight*0.05f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(tail.x - fWidth/30 - fWidth*0.45f - fWidth*0.18f, fWidth*0.05f/k - k*fWidth*0.45f + fWidth/30/k + tail.y - fHeight*0.05f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(tail.x - fWidth/30.0f - fWidth*0.45f, -k*fWidth*0.45f + fWidth/30.0f/k + tail.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(tail.x - fWidth/30.0f, fWidth/30.0f/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/30, -fWidth/30/k + tail.y), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.08f, k*fWidth*0.08f + CicleCenter.y), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.08f + fWidth*0.1f, -fWidth*0.1f/k + k*fWidth*0.08f + CicleCenter.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.22f + fWidth*0.1f, k*fWidth*0.22f + CicleCenter.y - fWidth*0.1f/k), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.22f, k*fWidth*0.22f + CicleCenter.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.22f - fWidth*0.1f, fWidth*0.1f/k + k*fWidth*0.22f + CicleCenter.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.08f - fWidth*0.1f, fWidth*0.1f/k + k*fWidth*0.08f + CicleCenter.y), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(CicleCenter.x + fWidth*0.08f, k*fWidth*0.08f + CicleCenter.y), PWLPT_BEZIERTO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 28);
+ else
+ GetPathDataFromArray(path, PathArray, 28);
+}
+
+void CPWL_Utils::GetGraphics_NewParagraph(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/20.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/20.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.12f, crBBox.top - fHeight*17/30.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.12f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.22f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.22f, crBBox.top - fHeight*17/30.0f - fWidth*0.14f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.38f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.48f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.48f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.38f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.38f, crBBox.bottom + fWidth*0.24f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.22f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.12f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.bottom + fHeight/10.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/10.0f + fHeight/7.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.97f, crBBox.bottom + fHeight/10.0f + fHeight/7.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.97f, crBBox.top - fHeight*17/30.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.top - fHeight*17/30.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*17/30.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.bottom + fHeight/10.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/7 + fHeight*0.18f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.85f, crBBox.bottom + fHeight/7 + fHeight*0.18f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.85f, crBBox.top - fHeight*17/30.0f - fHeight*0.08f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.top - fHeight*17/30.0f - fHeight*0.08f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/7 + fHeight*0.18f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 28);
+ else
+ GetPathDataFromArray(path, PathArray, 28);
+}
+
+void CPWL_Utils::GetGraphics_TextNote(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.bottom + fHeight/15.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*7/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.top - fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10.0f, crBBox.top - fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10.0f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.bottom + fHeight*4/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/5.0f, crBBox.top - fHeight*4/15.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/5.0f, crBBox.top - fHeight*4/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/5.0f, crBBox.top - fHeight*7/15.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/5.0f, crBBox.top - fHeight*7/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/5.0f, crBBox.top - fHeight*10/15.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*3/10.0f, crBBox.top - fHeight*10/15.0f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 17);
+ else
+ GetPathDataFromArray(path, PathArray, 17);
+}
+
+void CPWL_Utils::GetGraphics_Paragraph(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.top - fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.634f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.634f, crBBox.top - fHeight*2/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.566f, crBBox.top - fHeight*2/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.566f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f - fHeight*0.4f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.2f, crBBox.top - fHeight/15.0f - fHeight*0.4f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.2f, crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f), PWLPT_BEZIERTO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 12);
+ else
+ GetPathDataFromArray(path, PathArray, 12);
+}
+
+void CPWL_Utils::GetGraphics_RightArrow(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.top - fHeight/2.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + fWidth/8.0f, crBBox.bottom + fHeight/5.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.bottom + fHeight/5.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f - fWidth*0.15f, crBBox.top - fHeight/2.0f - fWidth/25.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.1f, crBBox.top - fHeight/2.0f - fWidth/25.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.1f, crBBox.top - fHeight/2.0f + fWidth/25.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f - fWidth*0.15f, crBBox.top - fHeight/2.0f + fWidth/25.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/5.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f + fWidth/8.0f, crBBox.top - fHeight/5.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 10);
+ else
+ GetPathDataFromArray(path, PathArray, 10);
+}
+
+void CPWL_Utils::GetGraphics_RightPointer(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30.0f, crBBox.top - fHeight/2.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/30.0f, crBBox.bottom + fHeight/6.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*4/15.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/30.0f, crBBox.top - fHeight/6.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30.0f, crBBox.top - fHeight/2.0f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 5);
+ else
+ GetPathDataFromArray(path, PathArray, 5);
+}
+
+void CPWL_Utils::GetGraphics_Star(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fLongRadius = (crBBox.top - crBBox.bottom)/(1+(FX_FLOAT)cos(PWL_PI/5.0f));
+ fLongRadius = fLongRadius * 0.7f;
+ FX_FLOAT fShortRadius = fLongRadius * 0.55f;
+ CPDF_Point ptCenter = CPDF_Point((crBBox.left + crBBox.right) / 2.0f,(crBBox.top + crBBox.bottom) / 2.0f);
+
+ FX_FLOAT px1[5], py1[5];
+ FX_FLOAT px2[5], py2[5];
+
+ FX_FLOAT fAngel = PWL_PI/10.0f;
+
+ for (FX_INT32 i=0; i<5; i++)
+ {
+ px1[i] = ptCenter.x + fLongRadius * (FX_FLOAT)cos(fAngel);
+ py1[i] = ptCenter.y + fLongRadius * (FX_FLOAT)sin(fAngel);
+
+ fAngel += PWL_PI * 2 / 5.0f;
+ }
+
+ fAngel = PWL_PI/5.0f + PWL_PI/10.0f;
+
+ for (FX_INT32 j=0; j<5; j++)
+ {
+ px2[j] = ptCenter.x + fShortRadius * (FX_FLOAT)cos(fAngel);
+ py2[j] = ptCenter.y + fShortRadius * (FX_FLOAT)sin(fAngel);
+
+ fAngel += PWL_PI * 2 / 5.0f;
+ }
+
+ CPWL_PathData PathArray[11];
+ PathArray[0] = CPWL_PathData(CPWL_Point(px1[0], py1[0]), PWLPT_MOVETO);
+ PathArray[1] = CPWL_PathData(CPWL_Point(px2[0], py2[0]), PWLPT_LINETO);
+
+ for(FX_INT32 k = 0; k < 4; k++)
+ {
+ PathArray[(k+1)*2] = CPWL_PathData(CPWL_Point(px1[k+1], py1[k+1]), PWLPT_LINETO);
+ PathArray[(k+1)*2 + 1] = CPWL_PathData(CPWL_Point(px2[k+1], py2[k+1]), PWLPT_LINETO);
+ }
+
+ PathArray[10] = CPWL_PathData(CPWL_Point(px1[0], py1[0]), PWLPT_LINETO);
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 11);
+ else
+ GetPathDataFromArray(path, PathArray, 11);
+}
+
+void CPWL_Utils::GetGraphics_UpArrow(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/10.0f, crBBox.top - fWidth*3/5.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fWidth*3/5.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.bottom + fHeight/15.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fWidth*3/5.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/10, crBBox.top - fWidth*3/5.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/2.0f, crBBox.top - fHeight/15.0f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 8);
+ else
+ GetPathDataFromArray(path, PathArray, 8);
+}
+
+void CPWL_Utils::GetGraphics_UpLeftArrow(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+ CPWL_Point leftup(crBBox.left, crBBox.top);
+ CPWL_Point rightdown(crBBox.right, crBBox.bottom);
+ FX_FLOAT k = -fHeight/fWidth;
+ CPWL_Point tail;
+ tail.x = crBBox.left + fWidth*4/5.0f;
+ tail.y = k*(tail.x - crBBox.right) + rightdown.y;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/20.0f, k*(crBBox.left + fWidth/20.0f - rightdown.x) + rightdown.y), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(fHeight*17/60.0f/k + tail.x + fWidth/10.0f + fWidth/5.0f,
+ -fWidth/5.0f/k + tail.y - fWidth/10.0f/k + fHeight*17/60.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(fHeight*17/60.0f/k + tail.x + fWidth/10.0f,
+ tail.y - fWidth/10.0f/k + fHeight*17/60.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x + fWidth/10.0f, tail.y - fWidth/10.0f/k), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(tail.x - fWidth/10.0f, tail.y + fWidth/10.0f/k), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(fHeight*17/60.0f/k + tail.x - fWidth/10.0f, tail.y + fWidth/10.0f/k + fHeight*17/60.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(fHeight*17/60.0f/k + tail.x - fWidth/10.0f - fWidth/5.0f,
+ fWidth/5.0f/k + tail.y + fWidth/10.0f/k + fHeight*17/60.0f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/20.0f, k*(crBBox.left + fWidth/20.0f - rightdown.x) + rightdown.y), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 8);
+ else
+ GetPathDataFromArray(path, PathArray, 8);
+}
+
+void CPWL_Utils::GetGraphics_Graph(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.05f, crBBox.top - fWidth*0.15f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.25f, crBBox.top - fHeight*0.15f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.275f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.05f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.05f, crBBox.top - fWidth*0.15f), PWLPT_LINETO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.275f, crBBox.top - fWidth*0.45f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.475f, crBBox.top - fWidth*0.45f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.475f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.275f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.275f, crBBox.top - fWidth*0.45f), PWLPT_LINETO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.top - fHeight*0.05f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.top - fHeight*0.05f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.7f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.top - fHeight*0.05f), PWLPT_LINETO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.725f, crBBox.top - fWidth*0.35f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.925f, crBBox.top - fWidth*0.35f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.925f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.725f, crBBox.bottom + fHeight*0.08f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.725f, crBBox.top - fWidth*0.35f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 20);
+ else
+ GetPathDataFromArray(path, PathArray, 20);
+}
+
+void CPWL_Utils::GetGraphics_Paperclip(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.top - fHeight*0.25f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.bottom + fHeight*0.25f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.bottom + fHeight*0.25f - fWidth*57/60.0f*0.35f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30, crBBox.bottom + fHeight*0.25f - fWidth*57/60.0f*0.35f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30, crBBox.bottom + fHeight*0.25f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30, crBBox.top - fHeight*0.33f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30, crBBox.top - fHeight*0.33f + fHeight/15*0.5f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30 - fWidth*0.12f, crBBox.top - fHeight*0.33f + fHeight/15*0.5f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30 - fWidth*0.12f, crBBox.top - fHeight*0.33f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30 - fWidth*0.12f, crBBox.bottom + fHeight*0.2f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/30 - fWidth*0.12f, crBBox.bottom + fHeight*0.2f - (fWidth*57/60.0f - fWidth*0.24f)*0.25f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60 + fWidth*0.12f, crBBox.bottom + fHeight*0.2f - (fWidth*57/60.0f - fWidth*0.24f)*0.25f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60 + fWidth*0.12f, crBBox.bottom + fHeight*0.2f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60 + fWidth*0.12f, crBBox.top - fHeight*0.2f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60 + fWidth*0.12f, crBBox.top - fHeight*0.2f + (fWidth*11/12.0f - fWidth*0.36f)*0.25f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.24f, crBBox.top - fHeight*0.2f + (fWidth*11/12.0f - fWidth*0.36f)*0.25f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.24f, crBBox.top - fHeight*0.2f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.24f, crBBox.bottom + fHeight*0.25f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.24f, crBBox.bottom + fHeight*0.25f - (fWidth*14/15.0f - fWidth*0.53f)*0.25f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.29f, crBBox.bottom + fHeight*0.25f - (fWidth*14/15.0f - fWidth*0.53f)*0.25f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.29f, crBBox.bottom + fHeight*0.25f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.29f, crBBox.top - fHeight*0.33f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.29f, crBBox.top - fHeight*0.33f + fWidth*0.12f*0.35f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.17f, crBBox.top - fHeight*0.33f + fWidth*0.12f*0.35f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.17f, crBBox.top - fHeight*0.33f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.17f, crBBox.bottom + fHeight*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.17f, crBBox.bottom + fHeight*0.3f - fWidth*(14/15.0f - 0.29f)*0.35f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.12f, crBBox.bottom + fHeight*0.3f - fWidth*(14/15.0f - 0.29f)*0.35f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.12f, crBBox.bottom + fHeight*0.3f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.12f, crBBox.top - fHeight*0.25f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth/15 - fWidth*0.12f, crBBox.top - fHeight*0.25f + fWidth*0.35f*(11/12.0f - 0.12f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.top - fHeight*0.25f + fWidth*0.35f*(11/12.0f - 0.12f)), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth/60, crBBox.top - fHeight*0.25f), PWLPT_BEZIERTO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 33);
+ else
+ GetPathDataFromArray(path, PathArray, 33);
+}
+
+void CPWL_Utils::GetGraphics_Attachment(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.25f, crBBox.top - fHeight*0.1f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.23f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f + fWidth*0.04f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.5f + fWidth*0.04f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.23f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.25f, crBBox.top - fHeight*0.1f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.25f, crBBox.top - fHeight*0.1f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.23f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.23f), PWLPT_LINETO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f - fWidth*0.25f*0.4f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.15f, crBBox.top - fHeight*0.65f + fHeight*0.15f*0.4f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.15f, crBBox.top - fHeight*0.65f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.15f, crBBox.top - fHeight*0.65f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.15f, crBBox.top - fHeight*0.65f + fHeight*0.15f*0.4f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f + fWidth*0.25f*0.4f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.6f, crBBox.top - fHeight*0.5f + fWidth*0.04f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f + fWidth*0.04f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.top - fHeight*0.65f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.5f, crBBox.bottom + fHeight*0.1f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 24);
+ else
+ GetPathDataFromArray(path, PathArray, 24);
+}
+
+void CPWL_Utils::GetGraphics_Tag(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fHeight = crBBox.top - crBBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.1f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.1f, crBBox.top - fHeight*0.5f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.3f, crBBox.bottom + fHeight*0.1f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.1f, crBBox.bottom + fHeight*0.1f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.1f, crBBox.top - fHeight*0.1f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.1f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.3f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.2f, crBBox.top - fHeight*0.3f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.5f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.2f, crBBox.top - fHeight*0.5f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left + fWidth*0.4f, crBBox.top - fHeight*0.7f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right - fWidth*0.2f, crBBox.top - fHeight*0.7f), PWLPT_LINETO)
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 12);
+ else
+ GetPathDataFromArray(path, PathArray, 12);
+}
+
+void CPWL_Utils::GetGraphics_Foxit(CFX_ByteString& sPathData, CFX_PathData& path, const CPDF_Rect& crBBox, const PWL_PATH_TYPE type)
+{
+ FX_FLOAT fOutWidth = crBBox.right - crBBox.left;
+ FX_FLOAT fOutHeight = crBBox.top - crBBox.bottom;
+
+ CPDF_Rect crInBox = crBBox;
+ crInBox.left = crBBox.left + fOutWidth*0.08f;
+ crInBox.right = crBBox.right - fOutWidth*0.08f;
+ crInBox.top = crBBox.top - fOutHeight*0.08f;
+ crInBox.bottom = crBBox.bottom + fOutHeight*0.08f;
+
+ FX_FLOAT fWidth = crInBox.right - crInBox.left;
+ FX_FLOAT fHeight = crInBox.top - crInBox.bottom;
+
+ CPWL_PathData PathArray[] =
+ {
+ CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.45f, crInBox.top), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.45f, crInBox.top - PWL_BEZIER * fHeight * 0.4f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.45f - PWL_BEZIER * fWidth * 0.45f, crInBox.top - fHeight*0.4f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight*0.4f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top), PWLPT_LINETO),
+
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.60f, crInBox.top), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.75f, crInBox.top), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.75f, crInBox.top - PWL_BEZIER * fHeight * 0.7f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.75f - PWL_BEZIER * fWidth * 0.75f, crInBox.top - fHeight*0.7f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight*0.7f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight*0.55f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crInBox.left + PWL_BEZIER * fWidth*0.60f, crInBox.top - fHeight*0.55f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.60f, crInBox.top - PWL_BEZIER * fHeight * 0.55f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth * 0.60f, crInBox.top), PWLPT_BEZIERTO),
+
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.90f, crInBox.top), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.90f, crInBox.top - PWL_BEZIER * fHeight * 0.85f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.90f - PWL_BEZIER * fWidth * 0.90f, crInBox.top - fHeight*0.85f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left, crInBox.top - fHeight*0.85f), PWLPT_BEZIERTO),
+ CPWL_PathData(CPWL_Point(crInBox.left, crInBox.bottom), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crInBox.right, crInBox.bottom), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crInBox.right, crInBox.top), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crInBox.left + fWidth*0.90f, crInBox.top), PWLPT_LINETO),
+
+ /*
+ CPWL_PathData(CPWL_Point(crBBox.left, crBBox.top), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right, crBBox.top), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right, crBBox.bottom), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left, crBBox.bottom), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left, crBBox.top), PWLPT_LINETO),
+
+ CPWL_PathData(CPWL_Point(crBBox.left+fOutWidth*0.04f, crBBox.top-fOutHeight*0.04f), PWLPT_MOVETO),
+ CPWL_PathData(CPWL_Point(crBBox.right-fOutWidth*0.04f, crBBox.top-fOutHeight*0.04f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.right-fOutWidth*0.04f, crBBox.bottom+fOutHeight*0.04f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left+fOutWidth*0.04f, crBBox.bottom+fOutHeight*0.04f), PWLPT_LINETO),
+ CPWL_PathData(CPWL_Point(crBBox.left+fOutWidth*0.04f, crBBox.top-fOutHeight*0.04f), PWLPT_LINETO),
+ */
+ };
+
+ if(type == PWLPT_STREAM)
+ sPathData = GetAppStreamFromArray(PathArray, 23);
+ else
+ GetPathDataFromArray(path, PathArray, 23);
+}
+
+void CPWL_Color::ConvertColorType(FX_INT32 nColorType)
+{
+ switch (this->nColorType)
+ {
+ case COLORTYPE_TRANSPARENT:
+ break;
+ case COLORTYPE_GRAY:
+ switch (nColorType)
+ {
+ case COLORTYPE_RGB:
+ CPWL_Utils::ConvertGRAY2RGB(this->fColor1, this->fColor1, this->fColor2, this->fColor3);
+ break;
+ case COLORTYPE_CMYK:
+ CPWL_Utils::ConvertGRAY2CMYK(this->fColor1, this->fColor1, this->fColor2, this->fColor3, this->fColor4);
+ break;
+ }
+ break;
+ case COLORTYPE_RGB:
+ switch (nColorType)
+ {
+ case COLORTYPE_GRAY:
+ CPWL_Utils::ConvertRGB2GRAY(this->fColor1, this->fColor2, this->fColor3, this->fColor1);
+ break;
+ case COLORTYPE_CMYK:
+ CPWL_Utils::ConvertRGB2CMYK(this->fColor1, this->fColor2, this->fColor3, this->fColor1, this->fColor2, this->fColor3, this->fColor4);
+ break;
+ }
+ break;
+ case COLORTYPE_CMYK:
+ switch (nColorType)
+ {
+ case COLORTYPE_GRAY:
+ CPWL_Utils::ConvertCMYK2GRAY(this->fColor1, this->fColor2, this->fColor3, this->fColor4, this->fColor1);
+ break;
+ case COLORTYPE_RGB:
+ CPWL_Utils::ConvertCMYK2RGB(this->fColor1, this->fColor2, this->fColor3, this->fColor4, this->fColor1, this->fColor2, this->fColor3);
+ break;
+ }
+ break;
+ }
+ this->nColorType = nColorType;
+}
+
+
diff --git a/fpdfsdk/src/pdfwindow/PWL_Wnd.cpp b/fpdfsdk/src/pdfwindow/PWL_Wnd.cpp
index 035ffbbf4d..9bb784c8a6 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Wnd.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Wnd.cpp
@@ -1,1342 +1,1342 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/pdfwindow/PDFWindow.h"
-#include "../../include/pdfwindow/PWL_Wnd.h"
-#include "../../include/pdfwindow/PWL_Utils.h"
-#include "../../include/pdfwindow/PWL_ScrollBar.h"
-
-/* -------------------------- CPWL_Timer -------------------------- */
-
-static CFX_MapPtrTemplate<FX_INT32, CPWL_Timer*> g_TimeMap;
-
-CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached, IFX_SystemHandler* pSystemHandler) :
- m_pAttached(pAttached),
- m_nTimerID(0),
- m_pSystemHandler(pSystemHandler)
-{
- ASSERT(m_pAttached != NULL);
- ASSERT(m_pSystemHandler != NULL);
-}
-
-CPWL_Timer::~CPWL_Timer()
-{
- KillPWLTimer();
-}
-
-FX_INT32 CPWL_Timer::SetPWLTimer(FX_INT32 nElapse)
-{
- if (m_nTimerID != 0) KillPWLTimer();
- m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
- g_TimeMap.SetAt(m_nTimerID, this);
- return m_nTimerID;
-}
-
-void CPWL_Timer::KillPWLTimer()
-{
- if (m_nTimerID != 0)
- {
- m_pSystemHandler->KillTimer(m_nTimerID);
- g_TimeMap.RemoveKey(m_nTimerID);
- m_nTimerID = 0;
- }
-}
-
-void CPWL_Timer::TimerProc(FX_INT32 idEvent)
-{
- CPWL_Timer* pTimer = NULL;
- if (g_TimeMap.Lookup(idEvent, pTimer))
- {
- if (pTimer)
- {
- if (pTimer->m_pAttached)
- pTimer->m_pAttached->TimerProc();
- }
- }
-}
-
-/* -------------------------- CPWL_TimerHandler -------------------------- */
-
-CPWL_TimerHandler::CPWL_TimerHandler() : m_pTimer(NULL)
-{
-}
-
-CPWL_TimerHandler::~CPWL_TimerHandler()
-{
- if (m_pTimer) delete m_pTimer;
-}
-
-void CPWL_TimerHandler::BeginTimer(FX_INT32 nElapse)
-{
- if (!m_pTimer)
- m_pTimer = new CPWL_Timer(this, GetSystemHandler());
-
- if (m_pTimer)
- m_pTimer->SetPWLTimer(nElapse);
-}
-
-void CPWL_TimerHandler::EndTimer()
-{
- if (m_pTimer)
- m_pTimer->KillPWLTimer();
-}
-
-void CPWL_TimerHandler::TimerProc()
-{
-}
-
-/* --------------------------- CPWL_MsgControl ---------------------------- */
-
-class CPWL_MsgControl
-{
- friend class CPWL_Wnd;
-
-public:
- CPWL_MsgControl(CPWL_Wnd * pWnd)
- {
-// PWL_TRACE("new CPWL_MsgControl\n");
- m_pCreatedWnd = pWnd;
- Default();
- }
-
- ~CPWL_MsgControl()
- {
-// PWL_TRACE("~CPWL_MsgControl\n");
- Default();
- }
-
- void Default()
- {
- m_aMousePath.RemoveAll();
- m_aKeyboardPath.RemoveAll();
- m_pMainMouseWnd = NULL;
- m_pMainKeyboardWnd = NULL;
- }
-
- FX_BOOL IsWndCreated(const CPWL_Wnd * pWnd) const
- {
- return m_pCreatedWnd == pWnd;
- }
-
- FX_BOOL IsMainCaptureMouse(const CPWL_Wnd * pWnd) const
- {
- return pWnd == m_pMainMouseWnd;
- }
-
- FX_BOOL IsWndCaptureMouse(const CPWL_Wnd * pWnd) const
- {
- if (pWnd)
- for( FX_INT32 i=0,sz=m_aMousePath.GetSize(); i<sz; i++)
- if (m_aMousePath.GetAt(i) == pWnd)
- return TRUE;
-
- return FALSE;
- }
-
- FX_BOOL IsMainCaptureKeyboard(const CPWL_Wnd * pWnd) const
- {
- return pWnd == m_pMainKeyboardWnd;
- }
-
-
- FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd * pWnd) const
- {
- if (pWnd)
- for( FX_INT32 i=0,sz=m_aKeyboardPath.GetSize(); i<sz; i++)
- if (m_aKeyboardPath.GetAt(i) == pWnd)
- return TRUE;
-
- return FALSE;
- }
-
- void SetFocus(CPWL_Wnd * pWnd)
- {
- m_aKeyboardPath.RemoveAll();
-
- if (pWnd)
- {
- m_pMainKeyboardWnd = pWnd;
-
- CPWL_Wnd * pParent = pWnd;
- while (pParent)
- {
- m_aKeyboardPath.Add(pParent);
- pParent = pParent->GetParentWindow();
- }
-
- pWnd->OnSetFocus();
- }
- }
-
- void KillFocus()
- {
- if (m_aKeyboardPath.GetSize() > 0)
- if (CPWL_Wnd* pWnd = m_aKeyboardPath.GetAt(0))
- pWnd->OnKillFocus();
-
- m_pMainKeyboardWnd = NULL;
- m_aKeyboardPath.RemoveAll();
- }
-
- void SetCapture(CPWL_Wnd * pWnd)
- {
- m_aMousePath.RemoveAll();
-
- if (pWnd)
- {
- m_pMainMouseWnd = pWnd;
-
- CPWL_Wnd * pParent = pWnd;
- while (pParent)
- {
- m_aMousePath.Add(pParent);
- pParent = pParent->GetParentWindow();
- }
- }
- }
-
- void ReleaseCapture()
- {
- m_pMainMouseWnd = NULL;
- m_aMousePath.RemoveAll();
- }
-
-private:
- CFX_ArrayTemplate<CPWL_Wnd*> m_aMousePath;
- CFX_ArrayTemplate<CPWL_Wnd*> m_aKeyboardPath;
- CPWL_Wnd* m_pCreatedWnd;
- CPWL_Wnd* m_pMainMouseWnd;
- CPWL_Wnd* m_pMainKeyboardWnd;
-};
-
-/* --------------------------- CPWL_Wnd ---------------------------- */
-
-CPWL_Wnd::CPWL_Wnd() :
- m_pVScrollBar(NULL),
- m_rcWindow(),
- m_rcClip(),
- m_bCreated(FALSE),
- m_bVisible(FALSE),
- m_bNotifying(FALSE),
- m_bEnabled(TRUE)
-{
-}
-
-CPWL_Wnd::~CPWL_Wnd()
-{
- ASSERT(m_bCreated == FALSE);
-}
-
-CFX_ByteString CPWL_Wnd::GetClassName() const
-{
- return "CPWL_Wnd";
-}
-
-void CPWL_Wnd::Create(const PWL_CREATEPARAM & cp)
-{
- if (!IsValid())
- {
- m_sPrivateParam = cp;
-
- OnCreate(m_sPrivateParam);
-
- m_sPrivateParam.rcRectWnd.Normalize();
- m_rcWindow = m_sPrivateParam.rcRectWnd;
- m_rcClip = CPWL_Utils::InflateRect(m_rcWindow,1.0f);
-
- CreateMsgControl();
-
- if (m_sPrivateParam.pParentWnd)
- m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD);
-
- PWL_CREATEPARAM ccp = m_sPrivateParam;
-
- ccp.dwFlags &= 0xFFFF0000L; //remove sub styles
- ccp.mtChild = CPDF_Matrix(1,0,0,1,0,0);
-
- CreateScrollBar(ccp);
- CreateChildWnd(ccp);
-
- m_bVisible = HasFlag(PWS_VISIBLE);
-
- OnCreated();
-
- RePosChildWnd();
- m_bCreated = TRUE;
- }
-}
-
-void CPWL_Wnd::OnCreate(PWL_CREATEPARAM & cp)
-{
-}
-
-void CPWL_Wnd::OnCreated()
-{
-}
-
-void CPWL_Wnd::OnDestroy()
-{
-}
-
-void CPWL_Wnd::Destroy()
-{
- KillFocus();
-
- OnDestroy();
-
- if (m_bCreated)
- {
- for (FX_INT32 i = m_aChildren.GetSize()-1; i >= 0; i --)
- {
- if (CPWL_Wnd * pChild = m_aChildren[i])
- {
- pChild->Destroy();
- delete pChild;
- pChild = NULL;
- }
- }
-
- if (m_sPrivateParam.pParentWnd)
- m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
- m_bCreated = FALSE;
- }
-
- DestroyMsgControl();
-
- FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
- m_aChildren.RemoveAll();
- m_pVScrollBar = NULL;
-}
-
-void CPWL_Wnd::Move(const CPDF_Rect & rcNew, FX_BOOL bReset,FX_BOOL bRefresh)
-{
- if (IsValid())
- {
- CPDF_Rect rcOld = this->GetWindowRect();
-
- m_rcWindow = rcNew;
- m_rcWindow.Normalize();
- //m_rcClip = CPWL_Utils::InflateRect(m_rcWindow,1.0f); //for special caret
-
- if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
- rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom)
- {
- if (bReset)
- {
- RePosChildWnd();
- }
-
- }
- if (bRefresh)
- {
- InvalidateRectMove(rcOld,rcNew);
- }
-
- m_sPrivateParam.rcRectWnd = m_rcWindow;
- }
-}
-
-void CPWL_Wnd::InvalidateRectMove(const CPDF_Rect & rcOld, const CPDF_Rect & rcNew)
-{
- CPDF_Rect rcUnion = rcOld;
- rcUnion.Union(rcNew);
-
- InvalidateRect(&rcUnion);
-
- /*
- CPDF_Rect SubArray[4];
-
- rcOld.Substract4(rcNew,SubArray);
- for (FX_INT32 i=0;i<4;i++)
- {
- if (SubArray[i].left == 0 &&
- SubArray[i].right == 0 &&
- SubArray[i].top == 0 &&
- SubArray[i].bottom == 0)continue;
-
- InvalidateRect(&CPWL_Utils::InflateRect(SubArray[i],2));
- }
-
- rcNew.Substract4(rcOld,SubArray);
- for (FX_INT32 j=0;j<4;j++)
- {
- if (SubArray[j].left == 0 &&
- SubArray[j].right == 0 &&
- SubArray[j].top == 0 &&
- SubArray[j].bottom == 0)continue;
-
- InvalidateRect(&CPWL_Utils::InflateRect(SubArray[j],2));
- }
- */
-}
-
-void CPWL_Wnd::GetAppearanceStream(CFX_ByteString & sAppStream)
-{
- if (IsValid())
- {
- CFX_ByteTextBuf sTextBuf;
- GetAppearanceStream(sTextBuf);
- sAppStream += sTextBuf.GetByteString();
- }
-}
-
-void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- if (IsValid() && IsVisible())
- {
- GetThisAppearanceStream(sAppStream);
- GetChildAppearanceStream(sAppStream);
- }
-}
-
-//if don't set,Get default apperance stream
-void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- CPDF_Rect rectWnd = GetWindowRect();
- if (!rectWnd.IsEmpty())
- {
- CFX_ByteTextBuf sThis;
-
- if (HasFlag(PWS_BACKGROUND))
- sThis << CPWL_Utils::GetRectFillAppStream(rectWnd,this->GetBackgroundColor());
-
- if (HasFlag(PWS_BORDER))
- sThis << CPWL_Utils::GetBorderAppStream(rectWnd,
- (FX_FLOAT)GetBorderWidth(),
- GetBorderColor(),
- this->GetBorderLeftTopColor(this->GetBorderStyle()),
- this->GetBorderRightBottomColor(this->GetBorderStyle()),
- this->GetBorderStyle(),
- this->GetBorderDash());
-
- sAppStream << sThis;
- }
-}
-
-void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf & sAppStream)
-{
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
- {
- pChild->GetAppearanceStream(sAppStream);
- }
- }
-}
-
-void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- if (IsValid() && IsVisible())
- {
- DrawThisAppearance(pDevice,pUser2Device);
- DrawChildAppearance(pDevice,pUser2Device);
- }
-}
-
-void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- CPDF_Rect rectWnd = GetWindowRect();
- if (!rectWnd.IsEmpty())
- {
- if (HasFlag(PWS_BACKGROUND))
- {
- CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rectWnd,(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
- CPWL_Utils::DrawFillRect(pDevice,pUser2Device,rcClient,this->GetBackgroundColor(),GetTransparency());
- }
-
- if (HasFlag(PWS_BORDER))
- CPWL_Utils::DrawBorder(pDevice,
- pUser2Device,
- rectWnd,
- (FX_FLOAT)GetBorderWidth(),
- GetBorderColor(),
- this->GetBorderLeftTopColor(this->GetBorderStyle()),
- this->GetBorderRightBottomColor(this->GetBorderStyle()),
- this->GetBorderStyle(),
- this->GetBorderDash(),
- GetTransparency());
- }
-}
-
-void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
-{
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
- {
- CPDF_Matrix mt = pChild->GetChildMatrix();
- if (mt.IsIdentity())
- {
- pChild->DrawAppearance(pDevice,pUser2Device);
- }
- else
- {
- mt.Concat(*pUser2Device);
- pChild->DrawAppearance(pDevice,&mt);
- }
- }
- }
-}
-
-void CPWL_Wnd::InvalidateRect(CPDF_Rect* pRect)
-{
- if (IsValid())
- {
- CPDF_Rect rcRefresh = pRect ? *pRect : GetWindowRect();
-
- if (!HasFlag(PWS_NOREFRESHCLIP))
- {
- CPDF_Rect rcClip = GetClipRect();
- if (!rcClip.IsEmpty())
- {
- rcRefresh.Intersect(rcClip);
- }
- }
-
- FX_RECT rcWin = PWLtoWnd(rcRefresh);
- rcWin.left -= PWL_INVALIDATE_INFLATE;
- rcWin.top -= PWL_INVALIDATE_INFLATE;
- rcWin.right += PWL_INVALIDATE_INFLATE;
- rcWin.bottom += PWL_INVALIDATE_INFLATE;
-
- if (IFX_SystemHandler* pSH = GetSystemHandler())
- {
- if (FX_HWND hWnd = GetAttachedHWnd())
- {
- pSH->InvalidateRect(hWnd, rcWin);
- }
- }
- }
-}
-
-#define PWL_IMPLEMENT_KEY_METHOD(key_method_name)\
-FX_BOOL CPWL_Wnd::key_method_name(FX_WORD nChar, FX_DWORD nFlag)\
-{\
- if (IsValid() && IsVisible() && IsEnabled())\
- {\
- if (IsWndCaptureKeyboard(this))\
- {\
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)\
- {\
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))\
- {\
- if (IsWndCaptureKeyboard(pChild))\
- {\
- return pChild->key_method_name(nChar,nFlag);\
- }\
- }\
- }\
- }\
- }\
- return FALSE;\
-}
-
-#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name)\
-FX_BOOL CPWL_Wnd::mouse_method_name(const CPDF_Point & point, FX_DWORD nFlag)\
-{\
- if (IsValid() && IsVisible() && IsEnabled())\
- {\
- if (IsWndCaptureMouse(this))\
- {\
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)\
- {\
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))\
- {\
- if (IsWndCaptureMouse(pChild))\
- {\
- return pChild->mouse_method_name(pChild->ParentToChild(point),nFlag);\
- }\
- }\
- }\
- SetCursor();\
- }\
- else\
- {\
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)\
- {\
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))\
- {\
- if (pChild->WndHitTest(pChild->ParentToChild(point)))\
- {\
- return pChild->mouse_method_name(pChild->ParentToChild(point),nFlag);\
- }\
- }\
- }\
- if (this->WndHitTest(point))\
- SetCursor();\
- }\
- }\
- return FALSE;\
-}
-
-PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
-PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
-PWL_IMPLEMENT_KEY_METHOD(OnChar)
-
-PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
-PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
-PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
-PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
-PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
-PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
-PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDblClk)
-PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
-PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
-PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
-
-FX_BOOL CPWL_Wnd::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag)
-{
- if (IsValid() && IsVisible() && IsEnabled())
- {
- SetCursor();
- if (IsWndCaptureKeyboard(this))
- {
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
- {
- if (IsWndCaptureKeyboard(pChild))
- {
- return pChild->OnMouseWheel(zDelta,pChild->ParentToChild(point), nFlag);
- }
- }
- }
- }
- }
- return FALSE;
-}
-
-void CPWL_Wnd::AddChild(CPWL_Wnd * pWnd)
-{
- m_aChildren.Add(pWnd);
-}
-
-void CPWL_Wnd::RemoveChild(CPWL_Wnd * pWnd)
-{
- for (FX_INT32 i = m_aChildren.GetSize()-1; i >= 0; i --)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- if (pChild == pWnd)
- {
- m_aChildren.RemoveAt(i);
- break;
- }
- }
- }
-}
-
-void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
-{
- switch (msg)
- {
- case PNM_ADDCHILD:
- this->AddChild(pWnd);
- break;
- case PNM_REMOVECHILD:
- this->RemoveChild(pWnd);
- break;
- default:
- break;
- }
-}
-
-FX_BOOL CPWL_Wnd::IsValid() const
-{
- return m_bCreated;
-}
-
-PWL_CREATEPARAM CPWL_Wnd::GetCreationParam() const
-{
- return m_sPrivateParam;
-}
-
-CPWL_Wnd* CPWL_Wnd::GetParentWindow() const
-{
- return m_sPrivateParam.pParentWnd;
-}
-
-CPDF_Rect CPWL_Wnd::GetOriginWindowRect() const
-{
- return m_sPrivateParam.rcRectWnd;
-}
-
-CPDF_Rect CPWL_Wnd::GetWindowRect() const
-{
- return m_rcWindow;
-}
-
-CPDF_Rect CPWL_Wnd::GetClientRect() const
-{
- CPDF_Rect rcWindow = GetWindowRect();
- CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
-
- if (CPWL_ScrollBar * pVSB = this->GetVScrollBar())
- rcClient.right -= pVSB->GetScrollBarWidth();
-
- rcClient.Normalize();
-
- if (rcWindow.Contains(rcClient))
- return rcClient;
- else
- return CPDF_Rect();
-}
-
-CPDF_Point CPWL_Wnd::GetCenterPoint() const
-{
- CPDF_Rect rcClient = GetClientRect();
-
- return CPDF_Point((rcClient.left + rcClient.right) * 0.5f,
- (rcClient.top + rcClient.bottom) * 0.5f);
-}
-
-CPDF_Rect CPWL_Wnd::GetClientCenterSquare() const
-{
- return CPWL_Utils::GetCenterSquare(GetClientRect());
-}
-
-CPDF_Rect CPWL_Wnd::GetWindowCenterSquare() const
-{
- return CPWL_Utils::GetCenterSquare(CPWL_Utils::DeflateRect(GetWindowRect(),0.1f));
-}
-
-FX_BOOL CPWL_Wnd::HasFlag(FX_DWORD dwFlags) const
-{
- return (m_sPrivateParam.dwFlags & dwFlags) != 0;
-}
-
-void CPWL_Wnd::RemoveFlag(FX_DWORD dwFlags)
-{
- m_sPrivateParam.dwFlags &= ~dwFlags;
-}
-
-void CPWL_Wnd::AddFlag(FX_DWORD dwFlags)
-{
- m_sPrivateParam.dwFlags |= dwFlags;
-}
-
-CPWL_Color CPWL_Wnd::GetBackgroundColor() const
-{
- return m_sPrivateParam.sBackgroundColor;
-}
-
-void CPWL_Wnd::SetBackgroundColor(const CPWL_Color & color)
-{
- m_sPrivateParam.sBackgroundColor = color;
-}
-
-void CPWL_Wnd::SetTextColor(const CPWL_Color & color)
-{
- m_sPrivateParam.sTextColor = color;
-}
-
-void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color & color)
-{
- m_sPrivateParam.sTextStrokeColor = color;
-}
-
-CPWL_Color CPWL_Wnd::GetTextColor() const
-{
- return m_sPrivateParam.sTextColor;
-}
-
-CPWL_Color CPWL_Wnd::GetTextStrokeColor() const
-{
- return m_sPrivateParam.sTextStrokeColor;
-}
-
-FX_INT32 CPWL_Wnd::GetBorderStyle() const
-{
- return m_sPrivateParam.nBorderStyle;
-}
-
-void CPWL_Wnd::SetBorderStyle(FX_INT32 nBorderStyle)
-{
- if (HasFlag(PWS_BORDER))
- m_sPrivateParam.nBorderStyle = nBorderStyle;
-}
-
-FX_INT32 CPWL_Wnd::GetBorderWidth() const
-{
- if (HasFlag(PWS_BORDER))
- return m_sPrivateParam.dwBorderWidth;
-
- return 0;
-}
-
-FX_INT32 CPWL_Wnd::GetInnerBorderWidth() const
-{
- /*
- switch (GetBorderStyle())
- {
- case PBS_BEVELED:
- case PBS_INSET:
- return GetBorderWidth() / 2;
- }
- */
- return 0;
-}
-
-void CPWL_Wnd::SetBorderWidth(FX_INT32 nBorderWidth)
-{
- if (HasFlag(PWS_BORDER))
- m_sPrivateParam.dwBorderWidth = nBorderWidth;
-}
-
-CPWL_Color CPWL_Wnd::GetBorderColor() const
-{
- if (HasFlag(PWS_BORDER))
- return m_sPrivateParam.sBorderColor;
-
- return CPWL_Color();
-}
-
-void CPWL_Wnd::SetBorderColor(const CPWL_Color & color)
-{
- if (HasFlag(PWS_BORDER))
- m_sPrivateParam.sBorderColor = color;
-}
-
-CPWL_Dash CPWL_Wnd::GetBorderDash() const
-{
- return m_sPrivateParam.sDash;
-}
-
-void* CPWL_Wnd::GetAttachedData() const
-{
- return m_sPrivateParam.pAttachedData;
-}
-
-void CPWL_Wnd::SetBorderDash(const CPWL_Dash & sDash)
-{
- if (HasFlag(PWS_BORDER))
- m_sPrivateParam.sDash = sDash;
-}
-
-CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const
-{
- if (HasFlag(PWS_VSCROLL))
- return m_pVScrollBar;
-
- return NULL;
-}
-
-void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM & cp)
-{
- CreateVScrollBar(cp);
-}
-
-void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM & cp)
-{
- if (!m_pVScrollBar && HasFlag(PWS_VSCROLL))
- {
- PWL_CREATEPARAM scp = cp;
-
- //flags
- scp.dwFlags = PWS_CHILD| PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
-
- scp.pParentWnd = this;
- scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
- scp.eCursorType = FXCT_ARROW;
- scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
-
- if ((m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL)))
- m_pVScrollBar->Create(scp);
- }
-}
-
-void CPWL_Wnd::SetCapture()
-{
- if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
- pMsgCtrl->SetCapture(this);
-}
-
-void CPWL_Wnd::ReleaseCapture()
-{
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- pChild->ReleaseCapture();
-
- if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
- pMsgCtrl->ReleaseCapture();
-}
-
-void CPWL_Wnd::SetFocus()
-{
- if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
- {
- if (!pMsgCtrl->IsMainCaptureKeyboard(this))
- pMsgCtrl->KillFocus();
- pMsgCtrl->SetFocus(this);
- }
-}
-
-void CPWL_Wnd::KillFocus()
-{
- if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
- {
- if (pMsgCtrl->IsWndCaptureKeyboard(this))
- pMsgCtrl->KillFocus();
- }
-}
-
-void CPWL_Wnd::OnSetFocus()
-{
-}
-
-void CPWL_Wnd::OnKillFocus()
-{
-}
-
-FX_BOOL CPWL_Wnd::WndHitTest(const CPDF_Point & point) const
-{
- return IsValid() && IsVisible() && GetWindowRect().Contains(point.x,point.y);
-}
-
-FX_BOOL CPWL_Wnd::ClientHitTest(const CPDF_Point & point) const
-{
- return IsValid() && IsVisible() && GetClientRect().Contains(point.x,point.y);
-}
-
-const CPWL_Wnd * CPWL_Wnd::GetRootWnd() const
-{
- if (m_sPrivateParam.pParentWnd)
- return m_sPrivateParam.pParentWnd->GetRootWnd();
- else
- return this;
-}
-
-void CPWL_Wnd::SetVisible(FX_BOOL bVisible)
-{
- if (IsValid())
- {
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- pChild->SetVisible(bVisible);
- }
- }
-
- if (bVisible != m_bVisible)
- {
- m_bVisible = bVisible;
- RePosChildWnd();
- InvalidateRect();
- }
- }
-}
-
-void CPWL_Wnd::SetClipRect(const CPDF_Rect & rect)
-{
- m_rcClip = rect;
- m_rcClip.Normalize();
-}
-
-CPDF_Rect CPWL_Wnd::GetClipRect() const
-{
- return m_rcClip;
-}
-
-FX_BOOL CPWL_Wnd::IsReadOnly() const
-{
- return HasFlag(PWS_READONLY);
-}
-
-void CPWL_Wnd::RePosChildWnd()
-{
- CPDF_Rect rcContent = CPWL_Utils::DeflateRect(GetWindowRect(),(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
-
- CPWL_ScrollBar * pVSB = this->GetVScrollBar();
-
- CPDF_Rect rcVScroll = CPDF_Rect(rcContent.right - PWL_SCROLLBAR_WIDTH,
- rcContent.bottom,
- rcContent.right-1.0f,
- rcContent.top);
-
- if (pVSB) pVSB->Move(rcVScroll,TRUE,FALSE);
-}
-
-void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM & cp)
-{
-}
-
-void CPWL_Wnd::SetCursor()
-{
- if (IsValid())
- {
- if (IFX_SystemHandler* pSH = GetSystemHandler())
- {
- FX_INT32 nCursorType = this->GetCreationParam().eCursorType;
- pSH->SetCursor(nCursorType);
- }
- }
-}
-
-void CPWL_Wnd::CreateMsgControl()
-{
- if (!m_sPrivateParam.pMsgControl)
- m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
-}
-
-void CPWL_Wnd::DestroyMsgControl()
-{
- if (CPWL_MsgControl* pMsgControl = GetMsgControl())
- if (pMsgControl->IsWndCreated(this))
- delete pMsgControl;
-}
-
-CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const
-{
- return m_sPrivateParam.pMsgControl;
-}
-
-FX_BOOL CPWL_Wnd::IsCaptureMouse() const
-{
- return IsWndCaptureMouse(this);
-}
-
-FX_BOOL CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd * pWnd) const
-{
- if (CPWL_MsgControl * pCtrl = GetMsgControl())
- return pCtrl->IsWndCaptureMouse(pWnd);
-
- return FALSE;
-}
-
-FX_BOOL CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd * pWnd) const
-{
- if (CPWL_MsgControl * pCtrl = GetMsgControl())
- return pCtrl->IsWndCaptureKeyboard(pWnd);
-
- return FALSE;
-}
-
-FX_BOOL CPWL_Wnd::IsFocused() const
-{
- if (CPWL_MsgControl * pCtrl = GetMsgControl())
- return pCtrl->IsMainCaptureKeyboard(this);
-
- return FALSE;
-}
-
-CPDF_Rect CPWL_Wnd::GetFocusRect() const
-{
- return CPWL_Utils::InflateRect(this->GetWindowRect(),1);
-}
-
-FX_FLOAT CPWL_Wnd::GetFontSize() const
-{
- return this->m_sPrivateParam.fFontSize;
-}
-
-void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize)
-{
- this->m_sPrivateParam.fFontSize = fFontSize;
-}
-
-IFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const
-{
- return m_sPrivateParam.pSystemHandler;
-}
-
-IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const
-{
- return m_sPrivateParam.pFocusHandler;
-}
-
-IPWL_Provider* CPWL_Wnd::GetProvider() const
-{
- return m_sPrivateParam.pProvider;
-}
-
-IFX_Edit_FontMap* CPWL_Wnd::GetFontMap() const
-{
- return m_sPrivateParam.pFontMap;
-}
-
-CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(FX_INT32 nBorderStyle) const
-{
- CPWL_Color color;
-
- switch (nBorderStyle)
- {
- case PBS_SOLID:
- break;
- case PBS_DASH:
- break;
- case PBS_BEVELED:
- color = CPWL_Color(COLORTYPE_GRAY,1);
- break;
- case PBS_INSET:
- color = CPWL_Color(COLORTYPE_GRAY,0.5f);
- break;
- case PBS_UNDERLINED:
- break;
- }
-
- return color;
-}
-
-CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(FX_INT32 nBorderStyle) const
-{
- CPWL_Color color;
-
- switch (nBorderStyle)
- {
- case PBS_SOLID:
- break;
- case PBS_DASH:
- break;
- case PBS_BEVELED:
- color = CPWL_Utils::DevideColor(GetBackgroundColor(),2);
- break;
- case PBS_INSET:
- color = CPWL_Color(COLORTYPE_GRAY,0.75f);
- break;
- case PBS_UNDERLINED:
- break;
- }
-
- return color;
-}
-
-/* ----------------------------------------------------------------- */
-
-FX_INT32 CPWL_Wnd::GetTransparency()
-{
- return m_sPrivateParam.nTransparency;
-}
-
-void CPWL_Wnd::SetTransparency(FX_INT32 nTransparency)
-{
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- pChild->SetTransparency(nTransparency);
- }
- }
-
- m_sPrivateParam.nTransparency = nTransparency;
-}
-
-CPDF_Matrix CPWL_Wnd::GetWindowMatrix() const
-{
- CPDF_Matrix mt = this->GetChildToRoot();
-
- if (IPWL_Provider* pProvider = GetProvider())
- {
- mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
- return mt;
- }
-
-/*
- if (CReader_App* pApp = CPWL_Module::GetReaderApp())
- if (CReader_Document* pDocument = pApp->GetCurrentDocument())
- if (CReader_DocView* pDocView = pDocument->GetCurrentDocView())
- {
- CPDF_Matrix mtPageView;
- pDocView->GetCurrentMatrix(mtPageView);
- mt.Concat(mtPageView);
- return mt;
- }
-
-*/
-
- return mt;
-}
-
-void CPWL_Wnd::PWLtoWnd(const CPDF_Point& point, FX_INT32& x, FX_INT32& y) const
-{
- CPDF_Matrix mt = GetWindowMatrix();
- CPDF_Point pt = point;
- mt.Transform(pt.x,pt.y);
- x = (FX_INT32)(pt.x+0.5);
- y = (FX_INT32)(pt.y+0.5);
-}
-
-FX_RECT CPWL_Wnd::PWLtoWnd(const CPDF_Rect & rect) const
-{
- CPDF_Rect rcTemp = rect;
- CPDF_Matrix mt = GetWindowMatrix();
- mt.TransformRect(rcTemp);
- return FX_RECT((FX_INT32)(rcTemp.left+0.5), (FX_INT32)(rcTemp.bottom+0.5), (FX_INT32)(rcTemp.right+0.5), (FX_INT32)(rcTemp.top+0.5));
-}
-
-FX_HWND CPWL_Wnd::GetAttachedHWnd() const
-{
- return m_sPrivateParam.hAttachedWnd;
-}
-
-CPDF_Point CPWL_Wnd::ChildToParent(const CPDF_Point& point) const
-{
- CPDF_Matrix mt = GetChildMatrix();
- if (mt.IsIdentity())
- return point;
- else
- {
- CPDF_Point pt = point;
- mt.Transform(pt.x,pt.y);
- return pt;
- }
-}
-
-CPDF_Rect CPWL_Wnd::ChildToParent(const CPDF_Rect& rect) const
-{
- CPDF_Matrix mt = GetChildMatrix();
- if (mt.IsIdentity())
- return rect;
- else
- {
- CPDF_Rect rc = rect;
- mt.TransformRect(rc);
- return rc;
- }
-}
-
-CPDF_Point CPWL_Wnd::ParentToChild(const CPDF_Point& point) const
-{
- CPDF_Matrix mt = GetChildMatrix();
- if (mt.IsIdentity())
- return point;
- else
- {
- mt.SetReverse(mt);
- CPDF_Point pt = point;
- mt.Transform(pt.x,pt.y);
- return pt;
- }
-}
-
-CPDF_Rect CPWL_Wnd::ParentToChild(const CPDF_Rect& rect) const
-{
- CPDF_Matrix mt = GetChildMatrix();
- if (mt.IsIdentity())
- return rect;
- else
- {
- mt.SetReverse(mt);
- CPDF_Rect rc = rect;
- mt.TransformRect(rc);
- return rc;
- }
-}
-
-CPDF_Matrix CPWL_Wnd::GetChildToRoot() const
-{
- CPDF_Matrix mt(1,0,0,1,0,0);
-
- if (HasFlag(PWS_CHILD))
- {
- const CPWL_Wnd* pParent = this;
- while (pParent)
- {
- mt.Concat(pParent->GetChildMatrix());
- pParent = pParent->GetParentWindow();
- }
- }
-
- return mt;
-}
-
-CPDF_Matrix CPWL_Wnd::GetChildMatrix() const
-{
- if (HasFlag(PWS_CHILD))
- return m_sPrivateParam.mtChild;
-
- return CPDF_Matrix(1,0,0,1,0,0);
-}
-
-void CPWL_Wnd::SetChildMatrix(const CPDF_Matrix& mt)
-{
- m_sPrivateParam.mtChild = mt;
-}
-
-const CPWL_Wnd* CPWL_Wnd::GetFocused() const
-{
- if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
- {
- return pMsgCtrl->m_pMainKeyboardWnd;
- }
-
- return NULL;
-}
-
-void CPWL_Wnd::EnableWindow(FX_BOOL bEnable)
-{
- if (m_bEnabled != bEnable)
- {
- for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
- {
- if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
- {
- pChild->EnableWindow(bEnable);
- }
- }
-
- this->m_bEnabled = bEnable;
-
- if (bEnable)
- this->OnEnabled();
- else
- this->OnDisabled();
- }
-}
-
-FX_BOOL CPWL_Wnd::IsEnabled()
-{
- return m_bEnabled;
-}
-
-void CPWL_Wnd::OnEnabled()
-{
-}
-
-void CPWL_Wnd::OnDisabled()
-{
-}
-
-FX_BOOL CPWL_Wnd::IsCTRLpressed(FX_DWORD nFlag) const
-{
- if (IFX_SystemHandler* pSystemHandler = GetSystemHandler())
- {
- return pSystemHandler->IsCTRLKeyDown(nFlag);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPWL_Wnd::IsSHIFTpressed(FX_DWORD nFlag) const
-{
- if (IFX_SystemHandler* pSystemHandler = GetSystemHandler())
- {
- return pSystemHandler->IsSHIFTKeyDown(nFlag);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPWL_Wnd::IsALTpressed(FX_DWORD nFlag) const
-{
- if (IFX_SystemHandler* pSystemHandler = GetSystemHandler())
- {
- return pSystemHandler->IsALTKeyDown(nFlag);
- }
-
- return FALSE;
-}
-
-FX_BOOL CPWL_Wnd::IsINSERTpressed(FX_DWORD nFlag) const
-{
- if (IFX_SystemHandler* pSystemHandler = GetSystemHandler())
- {
- return pSystemHandler->IsINSERTKeyDown(nFlag);
- }
-
- return FALSE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+#include "../../include/pdfwindow/PWL_ScrollBar.h"
+
+/* -------------------------- CPWL_Timer -------------------------- */
+
+static CFX_MapPtrTemplate<FX_INT32, CPWL_Timer*> g_TimeMap;
+
+CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached, IFX_SystemHandler* pSystemHandler) :
+ m_pAttached(pAttached),
+ m_nTimerID(0),
+ m_pSystemHandler(pSystemHandler)
+{
+ ASSERT(m_pAttached != NULL);
+ ASSERT(m_pSystemHandler != NULL);
+}
+
+CPWL_Timer::~CPWL_Timer()
+{
+ KillPWLTimer();
+}
+
+FX_INT32 CPWL_Timer::SetPWLTimer(FX_INT32 nElapse)
+{
+ if (m_nTimerID != 0) KillPWLTimer();
+ m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
+ g_TimeMap.SetAt(m_nTimerID, this);
+ return m_nTimerID;
+}
+
+void CPWL_Timer::KillPWLTimer()
+{
+ if (m_nTimerID != 0)
+ {
+ m_pSystemHandler->KillTimer(m_nTimerID);
+ g_TimeMap.RemoveKey(m_nTimerID);
+ m_nTimerID = 0;
+ }
+}
+
+void CPWL_Timer::TimerProc(FX_INT32 idEvent)
+{
+ CPWL_Timer* pTimer = NULL;
+ if (g_TimeMap.Lookup(idEvent, pTimer))
+ {
+ if (pTimer)
+ {
+ if (pTimer->m_pAttached)
+ pTimer->m_pAttached->TimerProc();
+ }
+ }
+}
+
+/* -------------------------- CPWL_TimerHandler -------------------------- */
+
+CPWL_TimerHandler::CPWL_TimerHandler() : m_pTimer(NULL)
+{
+}
+
+CPWL_TimerHandler::~CPWL_TimerHandler()
+{
+ if (m_pTimer) delete m_pTimer;
+}
+
+void CPWL_TimerHandler::BeginTimer(FX_INT32 nElapse)
+{
+ if (!m_pTimer)
+ m_pTimer = new CPWL_Timer(this, GetSystemHandler());
+
+ if (m_pTimer)
+ m_pTimer->SetPWLTimer(nElapse);
+}
+
+void CPWL_TimerHandler::EndTimer()
+{
+ if (m_pTimer)
+ m_pTimer->KillPWLTimer();
+}
+
+void CPWL_TimerHandler::TimerProc()
+{
+}
+
+/* --------------------------- CPWL_MsgControl ---------------------------- */
+
+class CPWL_MsgControl
+{
+ friend class CPWL_Wnd;
+
+public:
+ CPWL_MsgControl(CPWL_Wnd * pWnd)
+ {
+// PWL_TRACE("new CPWL_MsgControl\n");
+ m_pCreatedWnd = pWnd;
+ Default();
+ }
+
+ ~CPWL_MsgControl()
+ {
+// PWL_TRACE("~CPWL_MsgControl\n");
+ Default();
+ }
+
+ void Default()
+ {
+ m_aMousePath.RemoveAll();
+ m_aKeyboardPath.RemoveAll();
+ m_pMainMouseWnd = NULL;
+ m_pMainKeyboardWnd = NULL;
+ }
+
+ FX_BOOL IsWndCreated(const CPWL_Wnd * pWnd) const
+ {
+ return m_pCreatedWnd == pWnd;
+ }
+
+ FX_BOOL IsMainCaptureMouse(const CPWL_Wnd * pWnd) const
+ {
+ return pWnd == m_pMainMouseWnd;
+ }
+
+ FX_BOOL IsWndCaptureMouse(const CPWL_Wnd * pWnd) const
+ {
+ if (pWnd)
+ for( FX_INT32 i=0,sz=m_aMousePath.GetSize(); i<sz; i++)
+ if (m_aMousePath.GetAt(i) == pWnd)
+ return TRUE;
+
+ return FALSE;
+ }
+
+ FX_BOOL IsMainCaptureKeyboard(const CPWL_Wnd * pWnd) const
+ {
+ return pWnd == m_pMainKeyboardWnd;
+ }
+
+
+ FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd * pWnd) const
+ {
+ if (pWnd)
+ for( FX_INT32 i=0,sz=m_aKeyboardPath.GetSize(); i<sz; i++)
+ if (m_aKeyboardPath.GetAt(i) == pWnd)
+ return TRUE;
+
+ return FALSE;
+ }
+
+ void SetFocus(CPWL_Wnd * pWnd)
+ {
+ m_aKeyboardPath.RemoveAll();
+
+ if (pWnd)
+ {
+ m_pMainKeyboardWnd = pWnd;
+
+ CPWL_Wnd * pParent = pWnd;
+ while (pParent)
+ {
+ m_aKeyboardPath.Add(pParent);
+ pParent = pParent->GetParentWindow();
+ }
+
+ pWnd->OnSetFocus();
+ }
+ }
+
+ void KillFocus()
+ {
+ if (m_aKeyboardPath.GetSize() > 0)
+ if (CPWL_Wnd* pWnd = m_aKeyboardPath.GetAt(0))
+ pWnd->OnKillFocus();
+
+ m_pMainKeyboardWnd = NULL;
+ m_aKeyboardPath.RemoveAll();
+ }
+
+ void SetCapture(CPWL_Wnd * pWnd)
+ {
+ m_aMousePath.RemoveAll();
+
+ if (pWnd)
+ {
+ m_pMainMouseWnd = pWnd;
+
+ CPWL_Wnd * pParent = pWnd;
+ while (pParent)
+ {
+ m_aMousePath.Add(pParent);
+ pParent = pParent->GetParentWindow();
+ }
+ }
+ }
+
+ void ReleaseCapture()
+ {
+ m_pMainMouseWnd = NULL;
+ m_aMousePath.RemoveAll();
+ }
+
+private:
+ CFX_ArrayTemplate<CPWL_Wnd*> m_aMousePath;
+ CFX_ArrayTemplate<CPWL_Wnd*> m_aKeyboardPath;
+ CPWL_Wnd* m_pCreatedWnd;
+ CPWL_Wnd* m_pMainMouseWnd;
+ CPWL_Wnd* m_pMainKeyboardWnd;
+};
+
+/* --------------------------- CPWL_Wnd ---------------------------- */
+
+CPWL_Wnd::CPWL_Wnd() :
+ m_pVScrollBar(NULL),
+ m_rcWindow(),
+ m_rcClip(),
+ m_bCreated(FALSE),
+ m_bVisible(FALSE),
+ m_bNotifying(FALSE),
+ m_bEnabled(TRUE)
+{
+}
+
+CPWL_Wnd::~CPWL_Wnd()
+{
+ ASSERT(m_bCreated == FALSE);
+}
+
+CFX_ByteString CPWL_Wnd::GetClassName() const
+{
+ return "CPWL_Wnd";
+}
+
+void CPWL_Wnd::Create(const PWL_CREATEPARAM & cp)
+{
+ if (!IsValid())
+ {
+ m_sPrivateParam = cp;
+
+ OnCreate(m_sPrivateParam);
+
+ m_sPrivateParam.rcRectWnd.Normalize();
+ m_rcWindow = m_sPrivateParam.rcRectWnd;
+ m_rcClip = CPWL_Utils::InflateRect(m_rcWindow,1.0f);
+
+ CreateMsgControl();
+
+ if (m_sPrivateParam.pParentWnd)
+ m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD);
+
+ PWL_CREATEPARAM ccp = m_sPrivateParam;
+
+ ccp.dwFlags &= 0xFFFF0000L; //remove sub styles
+ ccp.mtChild = CPDF_Matrix(1,0,0,1,0,0);
+
+ CreateScrollBar(ccp);
+ CreateChildWnd(ccp);
+
+ m_bVisible = HasFlag(PWS_VISIBLE);
+
+ OnCreated();
+
+ RePosChildWnd();
+ m_bCreated = TRUE;
+ }
+}
+
+void CPWL_Wnd::OnCreate(PWL_CREATEPARAM & cp)
+{
+}
+
+void CPWL_Wnd::OnCreated()
+{
+}
+
+void CPWL_Wnd::OnDestroy()
+{
+}
+
+void CPWL_Wnd::Destroy()
+{
+ KillFocus();
+
+ OnDestroy();
+
+ if (m_bCreated)
+ {
+ for (FX_INT32 i = m_aChildren.GetSize()-1; i >= 0; i --)
+ {
+ if (CPWL_Wnd * pChild = m_aChildren[i])
+ {
+ pChild->Destroy();
+ delete pChild;
+ pChild = NULL;
+ }
+ }
+
+ if (m_sPrivateParam.pParentWnd)
+ m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
+ m_bCreated = FALSE;
+ }
+
+ DestroyMsgControl();
+
+ FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
+ m_aChildren.RemoveAll();
+ m_pVScrollBar = NULL;
+}
+
+void CPWL_Wnd::Move(const CPDF_Rect & rcNew, FX_BOOL bReset,FX_BOOL bRefresh)
+{
+ if (IsValid())
+ {
+ CPDF_Rect rcOld = this->GetWindowRect();
+
+ m_rcWindow = rcNew;
+ m_rcWindow.Normalize();
+ //m_rcClip = CPWL_Utils::InflateRect(m_rcWindow,1.0f); //for special caret
+
+ if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
+ rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom)
+ {
+ if (bReset)
+ {
+ RePosChildWnd();
+ }
+
+ }
+ if (bRefresh)
+ {
+ InvalidateRectMove(rcOld,rcNew);
+ }
+
+ m_sPrivateParam.rcRectWnd = m_rcWindow;
+ }
+}
+
+void CPWL_Wnd::InvalidateRectMove(const CPDF_Rect & rcOld, const CPDF_Rect & rcNew)
+{
+ CPDF_Rect rcUnion = rcOld;
+ rcUnion.Union(rcNew);
+
+ InvalidateRect(&rcUnion);
+
+ /*
+ CPDF_Rect SubArray[4];
+
+ rcOld.Substract4(rcNew,SubArray);
+ for (FX_INT32 i=0;i<4;i++)
+ {
+ if (SubArray[i].left == 0 &&
+ SubArray[i].right == 0 &&
+ SubArray[i].top == 0 &&
+ SubArray[i].bottom == 0)continue;
+
+ InvalidateRect(&CPWL_Utils::InflateRect(SubArray[i],2));
+ }
+
+ rcNew.Substract4(rcOld,SubArray);
+ for (FX_INT32 j=0;j<4;j++)
+ {
+ if (SubArray[j].left == 0 &&
+ SubArray[j].right == 0 &&
+ SubArray[j].top == 0 &&
+ SubArray[j].bottom == 0)continue;
+
+ InvalidateRect(&CPWL_Utils::InflateRect(SubArray[j],2));
+ }
+ */
+}
+
+void CPWL_Wnd::GetAppearanceStream(CFX_ByteString & sAppStream)
+{
+ if (IsValid())
+ {
+ CFX_ByteTextBuf sTextBuf;
+ GetAppearanceStream(sTextBuf);
+ sAppStream += sTextBuf.GetByteString();
+ }
+}
+
+void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ if (IsValid() && IsVisible())
+ {
+ GetThisAppearanceStream(sAppStream);
+ GetChildAppearanceStream(sAppStream);
+ }
+}
+
+//if don't set,Get default apperance stream
+void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ CPDF_Rect rectWnd = GetWindowRect();
+ if (!rectWnd.IsEmpty())
+ {
+ CFX_ByteTextBuf sThis;
+
+ if (HasFlag(PWS_BACKGROUND))
+ sThis << CPWL_Utils::GetRectFillAppStream(rectWnd,this->GetBackgroundColor());
+
+ if (HasFlag(PWS_BORDER))
+ sThis << CPWL_Utils::GetBorderAppStream(rectWnd,
+ (FX_FLOAT)GetBorderWidth(),
+ GetBorderColor(),
+ this->GetBorderLeftTopColor(this->GetBorderStyle()),
+ this->GetBorderRightBottomColor(this->GetBorderStyle()),
+ this->GetBorderStyle(),
+ this->GetBorderDash());
+
+ sAppStream << sThis;
+ }
+}
+
+void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
+ {
+ pChild->GetAppearanceStream(sAppStream);
+ }
+ }
+}
+
+void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ if (IsValid() && IsVisible())
+ {
+ DrawThisAppearance(pDevice,pUser2Device);
+ DrawChildAppearance(pDevice,pUser2Device);
+ }
+}
+
+void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ CPDF_Rect rectWnd = GetWindowRect();
+ if (!rectWnd.IsEmpty())
+ {
+ if (HasFlag(PWS_BACKGROUND))
+ {
+ CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rectWnd,(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
+ CPWL_Utils::DrawFillRect(pDevice,pUser2Device,rcClient,this->GetBackgroundColor(),GetTransparency());
+ }
+
+ if (HasFlag(PWS_BORDER))
+ CPWL_Utils::DrawBorder(pDevice,
+ pUser2Device,
+ rectWnd,
+ (FX_FLOAT)GetBorderWidth(),
+ GetBorderColor(),
+ this->GetBorderLeftTopColor(this->GetBorderStyle()),
+ this->GetBorderRightBottomColor(this->GetBorderStyle()),
+ this->GetBorderStyle(),
+ this->GetBorderDash(),
+ GetTransparency());
+ }
+}
+
+void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
+ {
+ CPDF_Matrix mt = pChild->GetChildMatrix();
+ if (mt.IsIdentity())
+ {
+ pChild->DrawAppearance(pDevice,pUser2Device);
+ }
+ else
+ {
+ mt.Concat(*pUser2Device);
+ pChild->DrawAppearance(pDevice,&mt);
+ }
+ }
+ }
+}
+
+void CPWL_Wnd::InvalidateRect(CPDF_Rect* pRect)
+{
+ if (IsValid())
+ {
+ CPDF_Rect rcRefresh = pRect ? *pRect : GetWindowRect();
+
+ if (!HasFlag(PWS_NOREFRESHCLIP))
+ {
+ CPDF_Rect rcClip = GetClipRect();
+ if (!rcClip.IsEmpty())
+ {
+ rcRefresh.Intersect(rcClip);
+ }
+ }
+
+ FX_RECT rcWin = PWLtoWnd(rcRefresh);
+ rcWin.left -= PWL_INVALIDATE_INFLATE;
+ rcWin.top -= PWL_INVALIDATE_INFLATE;
+ rcWin.right += PWL_INVALIDATE_INFLATE;
+ rcWin.bottom += PWL_INVALIDATE_INFLATE;
+
+ if (IFX_SystemHandler* pSH = GetSystemHandler())
+ {
+ if (FX_HWND hWnd = GetAttachedHWnd())
+ {
+ pSH->InvalidateRect(hWnd, rcWin);
+ }
+ }
+ }
+}
+
+#define PWL_IMPLEMENT_KEY_METHOD(key_method_name)\
+FX_BOOL CPWL_Wnd::key_method_name(FX_WORD nChar, FX_DWORD nFlag)\
+{\
+ if (IsValid() && IsVisible() && IsEnabled())\
+ {\
+ if (IsWndCaptureKeyboard(this))\
+ {\
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)\
+ {\
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))\
+ {\
+ if (IsWndCaptureKeyboard(pChild))\
+ {\
+ return pChild->key_method_name(nChar,nFlag);\
+ }\
+ }\
+ }\
+ }\
+ }\
+ return FALSE;\
+}
+
+#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name)\
+FX_BOOL CPWL_Wnd::mouse_method_name(const CPDF_Point & point, FX_DWORD nFlag)\
+{\
+ if (IsValid() && IsVisible() && IsEnabled())\
+ {\
+ if (IsWndCaptureMouse(this))\
+ {\
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)\
+ {\
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))\
+ {\
+ if (IsWndCaptureMouse(pChild))\
+ {\
+ return pChild->mouse_method_name(pChild->ParentToChild(point),nFlag);\
+ }\
+ }\
+ }\
+ SetCursor();\
+ }\
+ else\
+ {\
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)\
+ {\
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))\
+ {\
+ if (pChild->WndHitTest(pChild->ParentToChild(point)))\
+ {\
+ return pChild->mouse_method_name(pChild->ParentToChild(point),nFlag);\
+ }\
+ }\
+ }\
+ if (this->WndHitTest(point))\
+ SetCursor();\
+ }\
+ }\
+ return FALSE;\
+}
+
+PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
+PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
+PWL_IMPLEMENT_KEY_METHOD(OnChar)
+
+PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
+PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
+PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
+PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
+PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
+PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
+PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDblClk)
+PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
+PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
+PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
+
+FX_BOOL CPWL_Wnd::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag)
+{
+ if (IsValid() && IsVisible() && IsEnabled())
+ {
+ SetCursor();
+ if (IsWndCaptureKeyboard(this))
+ {
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
+ {
+ if (IsWndCaptureKeyboard(pChild))
+ {
+ return pChild->OnMouseWheel(zDelta,pChild->ParentToChild(point), nFlag);
+ }
+ }
+ }
+ }
+ }
+ return FALSE;
+}
+
+void CPWL_Wnd::AddChild(CPWL_Wnd * pWnd)
+{
+ m_aChildren.Add(pWnd);
+}
+
+void CPWL_Wnd::RemoveChild(CPWL_Wnd * pWnd)
+{
+ for (FX_INT32 i = m_aChildren.GetSize()-1; i >= 0; i --)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ if (pChild == pWnd)
+ {
+ m_aChildren.RemoveAt(i);
+ break;
+ }
+ }
+ }
+}
+
+void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+ switch (msg)
+ {
+ case PNM_ADDCHILD:
+ this->AddChild(pWnd);
+ break;
+ case PNM_REMOVECHILD:
+ this->RemoveChild(pWnd);
+ break;
+ default:
+ break;
+ }
+}
+
+FX_BOOL CPWL_Wnd::IsValid() const
+{
+ return m_bCreated;
+}
+
+PWL_CREATEPARAM CPWL_Wnd::GetCreationParam() const
+{
+ return m_sPrivateParam;
+}
+
+CPWL_Wnd* CPWL_Wnd::GetParentWindow() const
+{
+ return m_sPrivateParam.pParentWnd;
+}
+
+CPDF_Rect CPWL_Wnd::GetOriginWindowRect() const
+{
+ return m_sPrivateParam.rcRectWnd;
+}
+
+CPDF_Rect CPWL_Wnd::GetWindowRect() const
+{
+ return m_rcWindow;
+}
+
+CPDF_Rect CPWL_Wnd::GetClientRect() const
+{
+ CPDF_Rect rcWindow = GetWindowRect();
+ CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
+
+ if (CPWL_ScrollBar * pVSB = this->GetVScrollBar())
+ rcClient.right -= pVSB->GetScrollBarWidth();
+
+ rcClient.Normalize();
+
+ if (rcWindow.Contains(rcClient))
+ return rcClient;
+ else
+ return CPDF_Rect();
+}
+
+CPDF_Point CPWL_Wnd::GetCenterPoint() const
+{
+ CPDF_Rect rcClient = GetClientRect();
+
+ return CPDF_Point((rcClient.left + rcClient.right) * 0.5f,
+ (rcClient.top + rcClient.bottom) * 0.5f);
+}
+
+CPDF_Rect CPWL_Wnd::GetClientCenterSquare() const
+{
+ return CPWL_Utils::GetCenterSquare(GetClientRect());
+}
+
+CPDF_Rect CPWL_Wnd::GetWindowCenterSquare() const
+{
+ return CPWL_Utils::GetCenterSquare(CPWL_Utils::DeflateRect(GetWindowRect(),0.1f));
+}
+
+FX_BOOL CPWL_Wnd::HasFlag(FX_DWORD dwFlags) const
+{
+ return (m_sPrivateParam.dwFlags & dwFlags) != 0;
+}
+
+void CPWL_Wnd::RemoveFlag(FX_DWORD dwFlags)
+{
+ m_sPrivateParam.dwFlags &= ~dwFlags;
+}
+
+void CPWL_Wnd::AddFlag(FX_DWORD dwFlags)
+{
+ m_sPrivateParam.dwFlags |= dwFlags;
+}
+
+CPWL_Color CPWL_Wnd::GetBackgroundColor() const
+{
+ return m_sPrivateParam.sBackgroundColor;
+}
+
+void CPWL_Wnd::SetBackgroundColor(const CPWL_Color & color)
+{
+ m_sPrivateParam.sBackgroundColor = color;
+}
+
+void CPWL_Wnd::SetTextColor(const CPWL_Color & color)
+{
+ m_sPrivateParam.sTextColor = color;
+}
+
+void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color & color)
+{
+ m_sPrivateParam.sTextStrokeColor = color;
+}
+
+CPWL_Color CPWL_Wnd::GetTextColor() const
+{
+ return m_sPrivateParam.sTextColor;
+}
+
+CPWL_Color CPWL_Wnd::GetTextStrokeColor() const
+{
+ return m_sPrivateParam.sTextStrokeColor;
+}
+
+FX_INT32 CPWL_Wnd::GetBorderStyle() const
+{
+ return m_sPrivateParam.nBorderStyle;
+}
+
+void CPWL_Wnd::SetBorderStyle(FX_INT32 nBorderStyle)
+{
+ if (HasFlag(PWS_BORDER))
+ m_sPrivateParam.nBorderStyle = nBorderStyle;
+}
+
+FX_INT32 CPWL_Wnd::GetBorderWidth() const
+{
+ if (HasFlag(PWS_BORDER))
+ return m_sPrivateParam.dwBorderWidth;
+
+ return 0;
+}
+
+FX_INT32 CPWL_Wnd::GetInnerBorderWidth() const
+{
+ /*
+ switch (GetBorderStyle())
+ {
+ case PBS_BEVELED:
+ case PBS_INSET:
+ return GetBorderWidth() / 2;
+ }
+ */
+ return 0;
+}
+
+void CPWL_Wnd::SetBorderWidth(FX_INT32 nBorderWidth)
+{
+ if (HasFlag(PWS_BORDER))
+ m_sPrivateParam.dwBorderWidth = nBorderWidth;
+}
+
+CPWL_Color CPWL_Wnd::GetBorderColor() const
+{
+ if (HasFlag(PWS_BORDER))
+ return m_sPrivateParam.sBorderColor;
+
+ return CPWL_Color();
+}
+
+void CPWL_Wnd::SetBorderColor(const CPWL_Color & color)
+{
+ if (HasFlag(PWS_BORDER))
+ m_sPrivateParam.sBorderColor = color;
+}
+
+CPWL_Dash CPWL_Wnd::GetBorderDash() const
+{
+ return m_sPrivateParam.sDash;
+}
+
+void* CPWL_Wnd::GetAttachedData() const
+{
+ return m_sPrivateParam.pAttachedData;
+}
+
+void CPWL_Wnd::SetBorderDash(const CPWL_Dash & sDash)
+{
+ if (HasFlag(PWS_BORDER))
+ m_sPrivateParam.sDash = sDash;
+}
+
+CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const
+{
+ if (HasFlag(PWS_VSCROLL))
+ return m_pVScrollBar;
+
+ return NULL;
+}
+
+void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM & cp)
+{
+ CreateVScrollBar(cp);
+}
+
+void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM & cp)
+{
+ if (!m_pVScrollBar && HasFlag(PWS_VSCROLL))
+ {
+ PWL_CREATEPARAM scp = cp;
+
+ //flags
+ scp.dwFlags = PWS_CHILD| PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
+
+ scp.pParentWnd = this;
+ scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
+ scp.eCursorType = FXCT_ARROW;
+ scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
+
+ if ((m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL)))
+ m_pVScrollBar->Create(scp);
+ }
+}
+
+void CPWL_Wnd::SetCapture()
+{
+ if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
+ pMsgCtrl->SetCapture(this);
+}
+
+void CPWL_Wnd::ReleaseCapture()
+{
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ pChild->ReleaseCapture();
+
+ if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
+ pMsgCtrl->ReleaseCapture();
+}
+
+void CPWL_Wnd::SetFocus()
+{
+ if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
+ {
+ if (!pMsgCtrl->IsMainCaptureKeyboard(this))
+ pMsgCtrl->KillFocus();
+ pMsgCtrl->SetFocus(this);
+ }
+}
+
+void CPWL_Wnd::KillFocus()
+{
+ if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
+ {
+ if (pMsgCtrl->IsWndCaptureKeyboard(this))
+ pMsgCtrl->KillFocus();
+ }
+}
+
+void CPWL_Wnd::OnSetFocus()
+{
+}
+
+void CPWL_Wnd::OnKillFocus()
+{
+}
+
+FX_BOOL CPWL_Wnd::WndHitTest(const CPDF_Point & point) const
+{
+ return IsValid() && IsVisible() && GetWindowRect().Contains(point.x,point.y);
+}
+
+FX_BOOL CPWL_Wnd::ClientHitTest(const CPDF_Point & point) const
+{
+ return IsValid() && IsVisible() && GetClientRect().Contains(point.x,point.y);
+}
+
+const CPWL_Wnd * CPWL_Wnd::GetRootWnd() const
+{
+ if (m_sPrivateParam.pParentWnd)
+ return m_sPrivateParam.pParentWnd->GetRootWnd();
+ else
+ return this;
+}
+
+void CPWL_Wnd::SetVisible(FX_BOOL bVisible)
+{
+ if (IsValid())
+ {
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ pChild->SetVisible(bVisible);
+ }
+ }
+
+ if (bVisible != m_bVisible)
+ {
+ m_bVisible = bVisible;
+ RePosChildWnd();
+ InvalidateRect();
+ }
+ }
+}
+
+void CPWL_Wnd::SetClipRect(const CPDF_Rect & rect)
+{
+ m_rcClip = rect;
+ m_rcClip.Normalize();
+}
+
+CPDF_Rect CPWL_Wnd::GetClipRect() const
+{
+ return m_rcClip;
+}
+
+FX_BOOL CPWL_Wnd::IsReadOnly() const
+{
+ return HasFlag(PWS_READONLY);
+}
+
+void CPWL_Wnd::RePosChildWnd()
+{
+ CPDF_Rect rcContent = CPWL_Utils::DeflateRect(GetWindowRect(),(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
+
+ CPWL_ScrollBar * pVSB = this->GetVScrollBar();
+
+ CPDF_Rect rcVScroll = CPDF_Rect(rcContent.right - PWL_SCROLLBAR_WIDTH,
+ rcContent.bottom,
+ rcContent.right-1.0f,
+ rcContent.top);
+
+ if (pVSB) pVSB->Move(rcVScroll,TRUE,FALSE);
+}
+
+void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+}
+
+void CPWL_Wnd::SetCursor()
+{
+ if (IsValid())
+ {
+ if (IFX_SystemHandler* pSH = GetSystemHandler())
+ {
+ FX_INT32 nCursorType = this->GetCreationParam().eCursorType;
+ pSH->SetCursor(nCursorType);
+ }
+ }
+}
+
+void CPWL_Wnd::CreateMsgControl()
+{
+ if (!m_sPrivateParam.pMsgControl)
+ m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
+}
+
+void CPWL_Wnd::DestroyMsgControl()
+{
+ if (CPWL_MsgControl* pMsgControl = GetMsgControl())
+ if (pMsgControl->IsWndCreated(this))
+ delete pMsgControl;
+}
+
+CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const
+{
+ return m_sPrivateParam.pMsgControl;
+}
+
+FX_BOOL CPWL_Wnd::IsCaptureMouse() const
+{
+ return IsWndCaptureMouse(this);
+}
+
+FX_BOOL CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd * pWnd) const
+{
+ if (CPWL_MsgControl * pCtrl = GetMsgControl())
+ return pCtrl->IsWndCaptureMouse(pWnd);
+
+ return FALSE;
+}
+
+FX_BOOL CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd * pWnd) const
+{
+ if (CPWL_MsgControl * pCtrl = GetMsgControl())
+ return pCtrl->IsWndCaptureKeyboard(pWnd);
+
+ return FALSE;
+}
+
+FX_BOOL CPWL_Wnd::IsFocused() const
+{
+ if (CPWL_MsgControl * pCtrl = GetMsgControl())
+ return pCtrl->IsMainCaptureKeyboard(this);
+
+ return FALSE;
+}
+
+CPDF_Rect CPWL_Wnd::GetFocusRect() const
+{
+ return CPWL_Utils::InflateRect(this->GetWindowRect(),1);
+}
+
+FX_FLOAT CPWL_Wnd::GetFontSize() const
+{
+ return this->m_sPrivateParam.fFontSize;
+}
+
+void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize)
+{
+ this->m_sPrivateParam.fFontSize = fFontSize;
+}
+
+IFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const
+{
+ return m_sPrivateParam.pSystemHandler;
+}
+
+IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const
+{
+ return m_sPrivateParam.pFocusHandler;
+}
+
+IPWL_Provider* CPWL_Wnd::GetProvider() const
+{
+ return m_sPrivateParam.pProvider;
+}
+
+IFX_Edit_FontMap* CPWL_Wnd::GetFontMap() const
+{
+ return m_sPrivateParam.pFontMap;
+}
+
+CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(FX_INT32 nBorderStyle) const
+{
+ CPWL_Color color;
+
+ switch (nBorderStyle)
+ {
+ case PBS_SOLID:
+ break;
+ case PBS_DASH:
+ break;
+ case PBS_BEVELED:
+ color = CPWL_Color(COLORTYPE_GRAY,1);
+ break;
+ case PBS_INSET:
+ color = CPWL_Color(COLORTYPE_GRAY,0.5f);
+ break;
+ case PBS_UNDERLINED:
+ break;
+ }
+
+ return color;
+}
+
+CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(FX_INT32 nBorderStyle) const
+{
+ CPWL_Color color;
+
+ switch (nBorderStyle)
+ {
+ case PBS_SOLID:
+ break;
+ case PBS_DASH:
+ break;
+ case PBS_BEVELED:
+ color = CPWL_Utils::DevideColor(GetBackgroundColor(),2);
+ break;
+ case PBS_INSET:
+ color = CPWL_Color(COLORTYPE_GRAY,0.75f);
+ break;
+ case PBS_UNDERLINED:
+ break;
+ }
+
+ return color;
+}
+
+/* ----------------------------------------------------------------- */
+
+FX_INT32 CPWL_Wnd::GetTransparency()
+{
+ return m_sPrivateParam.nTransparency;
+}
+
+void CPWL_Wnd::SetTransparency(FX_INT32 nTransparency)
+{
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ pChild->SetTransparency(nTransparency);
+ }
+ }
+
+ m_sPrivateParam.nTransparency = nTransparency;
+}
+
+CPDF_Matrix CPWL_Wnd::GetWindowMatrix() const
+{
+ CPDF_Matrix mt = this->GetChildToRoot();
+
+ if (IPWL_Provider* pProvider = GetProvider())
+ {
+ mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
+ return mt;
+ }
+
+/*
+ if (CReader_App* pApp = CPWL_Module::GetReaderApp())
+ if (CReader_Document* pDocument = pApp->GetCurrentDocument())
+ if (CReader_DocView* pDocView = pDocument->GetCurrentDocView())
+ {
+ CPDF_Matrix mtPageView;
+ pDocView->GetCurrentMatrix(mtPageView);
+ mt.Concat(mtPageView);
+ return mt;
+ }
+
+*/
+
+ return mt;
+}
+
+void CPWL_Wnd::PWLtoWnd(const CPDF_Point& point, FX_INT32& x, FX_INT32& y) const
+{
+ CPDF_Matrix mt = GetWindowMatrix();
+ CPDF_Point pt = point;
+ mt.Transform(pt.x,pt.y);
+ x = (FX_INT32)(pt.x+0.5);
+ y = (FX_INT32)(pt.y+0.5);
+}
+
+FX_RECT CPWL_Wnd::PWLtoWnd(const CPDF_Rect & rect) const
+{
+ CPDF_Rect rcTemp = rect;
+ CPDF_Matrix mt = GetWindowMatrix();
+ mt.TransformRect(rcTemp);
+ return FX_RECT((FX_INT32)(rcTemp.left+0.5), (FX_INT32)(rcTemp.bottom+0.5), (FX_INT32)(rcTemp.right+0.5), (FX_INT32)(rcTemp.top+0.5));
+}
+
+FX_HWND CPWL_Wnd::GetAttachedHWnd() const
+{
+ return m_sPrivateParam.hAttachedWnd;
+}
+
+CPDF_Point CPWL_Wnd::ChildToParent(const CPDF_Point& point) const
+{
+ CPDF_Matrix mt = GetChildMatrix();
+ if (mt.IsIdentity())
+ return point;
+ else
+ {
+ CPDF_Point pt = point;
+ mt.Transform(pt.x,pt.y);
+ return pt;
+ }
+}
+
+CPDF_Rect CPWL_Wnd::ChildToParent(const CPDF_Rect& rect) const
+{
+ CPDF_Matrix mt = GetChildMatrix();
+ if (mt.IsIdentity())
+ return rect;
+ else
+ {
+ CPDF_Rect rc = rect;
+ mt.TransformRect(rc);
+ return rc;
+ }
+}
+
+CPDF_Point CPWL_Wnd::ParentToChild(const CPDF_Point& point) const
+{
+ CPDF_Matrix mt = GetChildMatrix();
+ if (mt.IsIdentity())
+ return point;
+ else
+ {
+ mt.SetReverse(mt);
+ CPDF_Point pt = point;
+ mt.Transform(pt.x,pt.y);
+ return pt;
+ }
+}
+
+CPDF_Rect CPWL_Wnd::ParentToChild(const CPDF_Rect& rect) const
+{
+ CPDF_Matrix mt = GetChildMatrix();
+ if (mt.IsIdentity())
+ return rect;
+ else
+ {
+ mt.SetReverse(mt);
+ CPDF_Rect rc = rect;
+ mt.TransformRect(rc);
+ return rc;
+ }
+}
+
+CPDF_Matrix CPWL_Wnd::GetChildToRoot() const
+{
+ CPDF_Matrix mt(1,0,0,1,0,0);
+
+ if (HasFlag(PWS_CHILD))
+ {
+ const CPWL_Wnd* pParent = this;
+ while (pParent)
+ {
+ mt.Concat(pParent->GetChildMatrix());
+ pParent = pParent->GetParentWindow();
+ }
+ }
+
+ return mt;
+}
+
+CPDF_Matrix CPWL_Wnd::GetChildMatrix() const
+{
+ if (HasFlag(PWS_CHILD))
+ return m_sPrivateParam.mtChild;
+
+ return CPDF_Matrix(1,0,0,1,0,0);
+}
+
+void CPWL_Wnd::SetChildMatrix(const CPDF_Matrix& mt)
+{
+ m_sPrivateParam.mtChild = mt;
+}
+
+const CPWL_Wnd* CPWL_Wnd::GetFocused() const
+{
+ if (CPWL_MsgControl * pMsgCtrl = GetMsgControl())
+ {
+ return pMsgCtrl->m_pMainKeyboardWnd;
+ }
+
+ return NULL;
+}
+
+void CPWL_Wnd::EnableWindow(FX_BOOL bEnable)
+{
+ if (m_bEnabled != bEnable)
+ {
+ for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)
+ {
+ if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
+ {
+ pChild->EnableWindow(bEnable);
+ }
+ }
+
+ this->m_bEnabled = bEnable;
+
+ if (bEnable)
+ this->OnEnabled();
+ else
+ this->OnDisabled();
+ }
+}
+
+FX_BOOL CPWL_Wnd::IsEnabled()
+{
+ return m_bEnabled;
+}
+
+void CPWL_Wnd::OnEnabled()
+{
+}
+
+void CPWL_Wnd::OnDisabled()
+{
+}
+
+FX_BOOL CPWL_Wnd::IsCTRLpressed(FX_DWORD nFlag) const
+{
+ if (IFX_SystemHandler* pSystemHandler = GetSystemHandler())
+ {
+ return pSystemHandler->IsCTRLKeyDown(nFlag);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPWL_Wnd::IsSHIFTpressed(FX_DWORD nFlag) const
+{
+ if (IFX_SystemHandler* pSystemHandler = GetSystemHandler())
+ {
+ return pSystemHandler->IsSHIFTKeyDown(nFlag);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPWL_Wnd::IsALTpressed(FX_DWORD nFlag) const
+{
+ if (IFX_SystemHandler* pSystemHandler = GetSystemHandler())
+ {
+ return pSystemHandler->IsALTKeyDown(nFlag);
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPWL_Wnd::IsINSERTpressed(FX_DWORD nFlag) const
+{
+ if (IFX_SystemHandler* pSystemHandler = GetSystemHandler())
+ {
+ return pSystemHandler->IsINSERTKeyDown(nFlag);
+ }
+
+ return FALSE;
+}
+
diff --git a/fpdfsdk/src/resource.h b/fpdfsdk/src/resource.h
index e97d1d5451..b58f09272f 100644
--- a/fpdfsdk/src/resource.h
+++ b/fpdfsdk/src/resource.h
@@ -1,21 +1,21 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-//{{NO_DEPENDENCIES}}
-// Microsoft Developer Studio generated include file.
-// Used by fpdfsdkdll.rc
-//
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 104
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1000
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by fpdfsdkdll.rc
+//
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 104
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1000
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif