Make CFX_FontMgr member variables private. (try 2)
[pdfium.git] / fpdfsdk / src / fsdk_baseform.cpp
index 23d9ec9..b4aa822 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../include/fsdk_define.h"\r
-#include "../include/fsdk_mgr.h"\r
-#include "../include/fsdk_baseannot.h"\r
-#include "../include/fsdk_baseform.h"\r
-#include "../include/formfiller/FFL_FormFiller.h"\r
-#include "../include/fsdk_actionhandler.h"\r
-\r
-#include "../include/javascript/IJavaScript.h"\r
-\r
-//------------------------------------------------------------------------------------\r
-//*                                                                            CPDFSDK_Widget \r
-//------------------------------------------------------------------------------------\r
-\r
-#define IsFloatZero(f)                                         ((f) < 0.01 && (f) > -0.01)\r
-#define IsFloatBigger(fa,fb)                           ((fa) > (fb) && !IsFloatZero((fa) - (fb)))\r
-#define IsFloatSmaller(fa,fb)                          ((fa) < (fb) && !IsFloatZero((fa) - (fb)))\r
-#define IsFloatEqual(fa,fb)                                    IsFloatZero((fa)-(fb))\r
-\r
-CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) :\r
-                                       CPDFSDK_Annot(pAnnot, pPageView),\r
-                                       m_pInterForm(pInterForm),\r
-                                       m_nAppAge(0),\r
-                                       m_nValueAge(0)\r
-{\r
-       ASSERT(m_pInterForm != NULL);\r
-}\r
-\r
-CPDFSDK_Widget::~CPDFSDK_Widget()\r
-{\r
-\r
-}\r
-\r
-FX_BOOL                CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode)\r
-{\r
-       ASSERT(m_pAnnot != NULL);\r
-       ASSERT(m_pAnnot->m_pAnnotDict != NULL);\r
-       \r
-       CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP");\r
-       if (pAP == NULL) return FALSE;\r
-       \r
-       // Choose the right sub-ap\r
-       const FX_CHAR* ap_entry = "N";\r
-       if (mode == CPDF_Annot::Down)\r
-               ap_entry = "D";\r
-       else if (mode == CPDF_Annot::Rollover)\r
-               ap_entry = "R";\r
-       if (!pAP->KeyExist(ap_entry))\r
-               ap_entry = "N";\r
-       \r
-       // Get the AP stream or subdirectory\r
-       CPDF_Object* psub = pAP->GetElementValue(ap_entry);\r
-       if (psub == NULL) return FALSE;\r
-       \r
-       int nFieldType = GetFieldType();\r
-       switch (nFieldType)\r
-       {\r
-       case FIELDTYPE_PUSHBUTTON:\r
-       case FIELDTYPE_COMBOBOX:\r
-       case FIELDTYPE_LISTBOX:\r
-       case FIELDTYPE_TEXTFIELD:\r
-       case FIELDTYPE_SIGNATURE:\r
-               return psub->GetType() == PDFOBJ_STREAM;\r
-       case FIELDTYPE_CHECKBOX:\r
-       case FIELDTYPE_RADIOBUTTON:\r
-               if (psub->GetType() == PDFOBJ_DICTIONARY) \r
-               {\r
-                       CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;\r
-                       \r
-                       return pSubDict->GetStream(this->GetAppState()) != NULL;\r
-               }\r
-               else\r
-                       return FALSE;\r
-               break;\r
-       }\r
-       \r
-       return TRUE;\r
-}\r
-\r
-int    CPDFSDK_Widget::GetFieldType() const\r
-{\r
-       CPDF_FormField* pField = GetFormField();\r
-       ASSERT(pField != NULL);\r
-       \r
-       return pField->GetFieldType();\r
-}\r
-\r
-int CPDFSDK_Widget::GetFieldFlags() const\r
-{\r
-       CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();\r
-       ASSERT(pPDFInterForm != NULL);\r
-\r
-       CPDF_FormControl* pFormControl = pPDFInterForm->GetControlByDict(m_pAnnot->m_pAnnotDict);\r
-       CPDF_FormField* pFormField = pFormControl->GetField();\r
-       return pFormField->GetFieldFlags();\r
-}\r
-\r
-CFX_ByteString CPDFSDK_Widget::GetSubType() const\r
-{\r
-       int nType = GetFieldType();\r
-       \r
-       if (nType == FIELDTYPE_SIGNATURE)\r
-               return BFFT_SIGNATURE;\r
-       return CPDFSDK_Annot::GetSubType();\r
-}\r
-\r
-CPDF_FormField*        CPDFSDK_Widget::GetFormField() const\r
-{\r
-       ASSERT(m_pInterForm != NULL);\r
-       \r
-       CPDF_FormControl* pCtrl = GetFormControl();     \r
-       ASSERT(pCtrl != NULL);\r
-       \r
-       return pCtrl->GetField();\r
-}\r
-\r
-CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const\r
-{\r
-       ASSERT(m_pInterForm != NULL);\r
-       \r
-       CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();\r
-       ASSERT(pPDFInterForm != NULL);\r
-       \r
-       return pPDFInterForm->GetControlByDict(GetAnnotDict());\r
-}\r
-static CPDF_Dictionary* BF_GetField(CPDF_Dictionary* pFieldDict, const FX_CHAR* name)\r
-{\r
-       if (pFieldDict == NULL) return NULL;\r
-       // First check the dictionary itself\r
-       CPDF_Object* pAttr = pFieldDict->GetElementValue(name);\r
-       if (pAttr) return pFieldDict;\r
-       \r
-       // Now we need to search from parents\r
-       CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent");\r
-       if (pParent == NULL) return NULL;\r
-       \r
-       return BF_GetField(pParent, name);\r
-}\r
-\r
-CPDF_FormControl* CPDFSDK_Widget::GetFormControl(CPDF_InterForm* pInterForm, CPDF_Dictionary* pAnnotDict)\r
-{\r
-       ASSERT(pInterForm != NULL);\r
-       ASSERT(pAnnotDict != NULL);\r
-       \r
-       CPDF_FormControl* pControl = pInterForm->GetControlByDict(pAnnotDict);\r
-       \r
-       return pControl;\r
-}\r
-\r
-int CPDFSDK_Widget::GetRotate() const\r
-{\r
-       CPDF_FormControl* pCtrl = this->GetFormControl();\r
-       ASSERT(pCtrl != NULL);\r
-       \r
-       return pCtrl->GetRotation() % 360;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const\r
-{\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-       \r
-       int iColorType = 0;     \r
-       color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType));\r
-       \r
-       return iColorType != COLORTYPE_TRANSPARENT;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const\r
-{\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-       \r
-       int iColorType = 0;     \r
-       color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType));\r
-       \r
-       return iColorType != COLORTYPE_TRANSPARENT;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const\r
-{\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-       \r
-       CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();\r
-       if (da.HasColor())\r
-       {\r
-               FX_ARGB argb;\r
-               int iColorType = COLORTYPE_TRANSPARENT; \r
-               da.GetColor(argb, iColorType);\r
-               color = FX_ARGBTOCOLORREF(argb);\r
-               \r
-               return iColorType != COLORTYPE_TRANSPARENT;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-FX_FLOAT CPDFSDK_Widget::GetFontSize() const\r
-{\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-       \r
-       CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();\r
-       CFX_ByteString csFont = "";\r
-       FX_FLOAT fFontSize = 0.0f;\r
-       pDa.GetFont(csFont, fFontSize);\r
-       \r
-       return fFontSize;\r
-}\r
-\r
-int    CPDFSDK_Widget::GetSelectedIndex(int nIndex) const\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       return pFormField->GetSelectedIndex(nIndex);\r
-}\r
-\r
-CFX_WideString CPDFSDK_Widget::GetValue() const\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       return pFormField->GetValue();\r
-}\r
-\r
-CFX_WideString CPDFSDK_Widget::GetDefaultValue() const\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       return pFormField->GetDefaultValue();\r
-}\r
-\r
-CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       return pFormField->GetOptionLabel(nIndex);\r
-}\r
-\r
-int    CPDFSDK_Widget::CountOptions() const\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       return pFormField->CountOptions();\r
-}\r
-\r
-FX_BOOL        CPDFSDK_Widget::IsOptionSelected(int nIndex) const\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       return pFormField->IsItemSelected(nIndex);\r
-}\r
-\r
-int    CPDFSDK_Widget::GetTopVisibleIndex() const\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       return pFormField->GetTopVisibleIndex();\r
-}\r
-\r
-FX_BOOL        CPDFSDK_Widget::IsChecked() const\r
-{\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-       \r
-       return pFormCtrl->IsChecked();\r
-}\r
-\r
-int    CPDFSDK_Widget::GetAlignment() const\r
-{\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-       \r
-       return pFormCtrl->GetControlAlignment();\r
-}\r
-\r
-int    CPDFSDK_Widget::GetMaxLen() const\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       return pFormField->GetMaxLen();\r
-}\r
-\r
-void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify)\r
-{\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-       \r
-       CPDF_FormField* pFormField = pFormCtrl->GetField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, bNotify);\r
-}\r
-\r
-void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify)\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       pFormField->SetValue(sValue, bNotify);\r
-}\r
-\r
-void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue)\r
-{\r
-}\r
-void CPDFSDK_Widget::SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify)\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       pFormField->SetItemSelection(index, bSelected, bNotify);\r
-}\r
-\r
-void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify)\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       pFormField->ClearSelection(bNotify);\r
-}\r
-\r
-void CPDFSDK_Widget::SetTopVisibleIndex(int index)\r
-{\r
-}\r
-\r
-void CPDFSDK_Widget::SetAppModified()\r
-{\r
-       m_bAppModified = TRUE;\r
-}\r
-\r
-void CPDFSDK_Widget::ClearAppModified()\r
-{\r
-       m_bAppModified = FALSE;\r
-}\r
-\r
-FX_BOOL CPDFSDK_Widget::IsAppModified() const\r
-{\r
-       return m_bAppModified;\r
-}\r
-\r
-void CPDFSDK_Widget::ResetAppearance(FX_LPCWSTR sValue, FX_BOOL bValueChanged)\r
-{\r
-       SetAppModified();\r
-\r
-       m_nAppAge++;\r
-       if (m_nAppAge > 999999)\r
-               m_nAppAge = 0;\r
-       if (bValueChanged)\r
-               m_nValueAge++;\r
-\r
-       int nFieldType = GetFieldType();\r
-       \r
-       switch (nFieldType)\r
-       {\r
-       case FIELDTYPE_PUSHBUTTON:\r
-               ResetAppearance_PushButton();\r
-               break;\r
-       case FIELDTYPE_CHECKBOX:\r
-               ResetAppearance_CheckBox();\r
-               break;\r
-       case FIELDTYPE_RADIOBUTTON:\r
-               ResetAppearance_RadioButton();\r
-               break;\r
-       case FIELDTYPE_COMBOBOX:\r
-               ResetAppearance_ComboBox(sValue);\r
-               break;\r
-       case FIELDTYPE_LISTBOX:\r
-               ResetAppearance_ListBox();\r
-               break;\r
-       case FIELDTYPE_TEXTFIELD:\r
-               ResetAppearance_TextField(sValue);\r
-               break;\r
-       }\r
-       \r
-       ASSERT(m_pAnnot != NULL);\r
-       m_pAnnot->ClearCachedAP();\r
-}\r
-\r
-CFX_WideString CPDFSDK_Widget::OnFormat(int nCommitKey, FX_BOOL& bFormated)\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       ASSERT(m_pInterForm != NULL);\r
-       \r
-       return m_pInterForm->OnFormat(pFormField, nCommitKey, bFormated);\r
-\r
-}\r
-\r
-void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged)\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       ASSERT(m_pInterForm != NULL);\r
-\r
-       m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged);\r
-}\r
-\r
-void   CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,\r
-               CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)\r
-{\r
-       int nFieldType = GetFieldType();\r
-       \r
-       if ((nFieldType == FIELDTYPE_CHECKBOX || nFieldType == FIELDTYPE_RADIOBUTTON) &&\r
-               mode == CPDF_Annot::Normal && \r
-               !this->IsWidgetAppearanceValid(CPDF_Annot::Normal))\r
-       {\r
-               CFX_PathData pathData;\r
-               \r
-               CPDF_Rect rcAnnot = this->GetRect();\r
-               \r
-               pathData.AppendRect(rcAnnot.left, rcAnnot.bottom,\r
-                       rcAnnot.right, rcAnnot.top);\r
-               \r
-               CFX_GraphStateData gsd;\r
-               gsd.m_LineWidth = 0.0f;\r
-               \r
-               pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, FXFILL_ALTERNATE);\r
-       }\r
-       else\r
-       {\r
-               CPDFSDK_Annot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);\r
-       }\r
-}\r
-\r
-void CPDFSDK_Widget::UpdateField()\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-       \r
-       ASSERT(m_pInterForm != NULL);\r
-       m_pInterForm->UpdateField(pFormField);\r
-}\r
-\r
-void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView)\r
-{\r
-       ASSERT(m_pInterForm != NULL);\r
\r
-       int nFieldType = GetFieldType();\r
-       if (m_pInterForm->IsNeedHighLight(nFieldType))\r
-       {\r
\r
-//             if (nFieldType != FIELDTYPE_PUSHBUTTON)\r
-//             {\r
-                       CPDF_Rect rc  = GetRect();\r
-                       FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);\r
-                       FX_BYTE alpha = m_pInterForm->GetHighlightAlpha();\r
-\r
-                       CFX_FloatRect rcDevice;\r
-                       ASSERT(m_pInterForm->GetDocument());\r
-                       CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();\r
-                       if(!pEnv)\r
-                               return;\r
-                       CFX_AffineMatrix page2device;\r
-                       pPageView->GetCurrentMatrix(page2device);\r
-                       page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), rcDevice.left, rcDevice.bottom);\r
-//                     pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.left, rc.bottom, &rcDevice.left, &rcDevice.bottom);\r
-//                     pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.right, rc.top, &rcDevice.right, &rcDevice.top);\r
-                       page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), rcDevice.right, rcDevice.top);\r
-\r
-                       rcDevice.Normalize();\r
-\r
-                       FX_ARGB argb = ArgbEncode((int)alpha, color);\r
-                       FX_RECT rcDev((int)rcDevice.left,(int)rcDevice.top,(int)rcDevice.right,(int)rcDevice.bottom);\r
-                       pDevice->FillRect(&rcDev, argb);        \r
-                       /*              }*/\r
-       }\r
-}\r
-\r
-void CPDFSDK_Widget::ResetAppearance_PushButton()\r
-{\r
-       CPDF_FormControl* pControl = GetFormControl();\r
-       ASSERT(pControl != NULL);\r
-\r
-\r
-       \r
-       CPDF_Rect rcWindow = GetRotatedRect();  \r
-\r
-       FX_INT32 nLayout = 0;\r
-\r
-       switch (pControl->GetTextPosition())\r
-       {\r
-       case TEXTPOS_ICON:\r
-               nLayout = PPBL_ICON;\r
-               break;\r
-       case TEXTPOS_BELOW:\r
-               nLayout = PPBL_ICONTOPLABELBOTTOM;\r
-               break;\r
-       case TEXTPOS_ABOVE:\r
-               nLayout = PPBL_LABELTOPICONBOTTOM;\r
-               break;\r
-       case TEXTPOS_RIGHT:\r
-               nLayout = PPBL_ICONLEFTLABELRIGHT;\r
-               break;\r
-       case TEXTPOS_LEFT:\r
-               nLayout = PPBL_LABELLEFTICONRIGHT;\r
-               break;\r
-       case TEXTPOS_OVERLAID:\r
-               nLayout = PPBL_LABELOVERICON;\r
-               break;\r
-       default:\r
-               nLayout = PPBL_LABEL;\r
-               break;\r
-       }\r
-\r
-       CPWL_Color crBackground, crBorder;\r
-\r
-       int iColorType;\r
-       FX_FLOAT fc[4];\r
-\r
-       pControl->GetOriginalBackgroundColor(iColorType, fc);\r
-       if (iColorType > 0)\r
-               crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-\r
-       pControl->GetOriginalBorderColor(iColorType, fc);\r
-       if (iColorType > 0)\r
-               crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-\r
-       FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
-       FX_INT32 nBorderStyle = 0;\r
-       CPWL_Dash dsBorder(3,0,0);\r
-       CPWL_Color crLeftTop,crRightBottom;\r
-\r
-       switch (GetBorderStyle())\r
-       {\r
-       case BBS_DASH:\r
-               nBorderStyle = PBS_DASH;\r
-               dsBorder = CPWL_Dash(3, 3, 0);\r
-               break;\r
-       case BBS_BEVELED:\r
-               nBorderStyle = PBS_BEVELED;\r
-               fBorderWidth *= 2;\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);\r
-               crRightBottom = CPWL_Utils::DevideColor(crBackground,2);\r
-               break;\r
-       case BBS_INSET:\r
-               nBorderStyle = PBS_INSET;\r
-               fBorderWidth *= 2;\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);\r
-               crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);\r
-               break;\r
-       case BBS_UNDERLINE:\r
-               nBorderStyle = PBS_UNDERLINED;\r
-               break;\r
-       default: \r
-               nBorderStyle = PBS_SOLID;\r
-               break;\r
-       }\r
-\r
-       CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);    \r
-\r
-       CPWL_Color crText(COLORTYPE_GRAY,0);\r
-\r
-       FX_FLOAT fFontSize = 12.0f;\r
-       CFX_ByteString csNameTag;\r
-\r
-       CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();\r
-       if (da.HasColor())\r
-       {\r
-               da.GetColor(iColorType, fc);\r
-               crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-       }\r
-\r
-       if (da.HasFont()) \r
-               da.GetFont(csNameTag, fFontSize);\r
-\r
-       CFX_WideString csWCaption;\r
-       CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;\r
-\r
-       if (pControl->HasMKEntry("CA"))\r
-       {\r
-               csNormalCaption = pControl->GetNormalCaption();\r
-       }\r
-       if (pControl->HasMKEntry("RC"))\r
-       {\r
-               csRolloverCaption = pControl->GetRolloverCaption();\r
-       }\r
-       if (pControl->HasMKEntry("AC"))\r
-       {\r
-               csDownCaption = pControl->GetDownCaption();\r
-       }\r
-\r
-       CPDF_Stream* pNormalIcon = NULL;\r
-       CPDF_Stream* pRolloverIcon = NULL;\r
-       CPDF_Stream* pDownIcon = NULL;\r
-\r
-       if (pControl->HasMKEntry("I"))\r
-       {\r
-               pNormalIcon = pControl->GetNormalIcon();\r
-       }\r
-       if (pControl->HasMKEntry("RI"))\r
-       {\r
-               pRolloverIcon = pControl->GetRolloverIcon();\r
-       }\r
-       if (pControl->HasMKEntry("IX"))\r
-       {\r
-               pDownIcon = pControl->GetDownIcon();\r
-       }\r
-\r
-       if (pNormalIcon)\r
-       {\r
-               if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict())\r
-               {\r
-                       if (pImageDict->GetString("Name").IsEmpty())\r
-                               pImageDict->SetAtString("Name", "ImgA");\r
-               }\r
-       }\r
-\r
-       if (pRolloverIcon)\r
-       {\r
-               if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict())\r
-               {\r
-                       if (pImageDict->GetString("Name").IsEmpty())\r
-                               pImageDict->SetAtString("Name", "ImgB");\r
-               }\r
-       }\r
-\r
-       if (pDownIcon)\r
-       {\r
-               if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict())\r
-               {\r
-                       if (pImageDict->GetString("Name").IsEmpty())\r
-                               pImageDict->SetAtString("Name", "ImgC");\r
-               }\r
-       }\r
-\r
-       CPDF_IconFit iconFit = pControl->GetIconFit();\r
-\r
-//     ASSERT(this->m_pBaseForm != NULL);\r
-       ASSERT(this->m_pInterForm != NULL);\r
-       CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();\r
-       ASSERT(pDoc != NULL);\r
-       CPDFDoc_Environment* pEnv = pDoc->GetEnv();\r
-\r
-       CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));\r
-       FontMap.Initial();\r
-\r
-       FontMap.SetAPType("N");\r
-\r
-       CFX_ByteString csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + \r
-               CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +\r
-               CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);\r
-\r
-       WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);\r
-       if (pNormalIcon)\r
-               AddImageToAppearance("N", pNormalIcon);\r
-\r
-       CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();\r
-       if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle)\r
-       {\r
-               if (csRolloverCaption.IsEmpty() && !pRolloverIcon)                      \r
-               {\r
-                       csRolloverCaption = csNormalCaption;\r
-                       pRolloverIcon = pNormalIcon;\r
-               }\r
-\r
-               FontMap.SetAPType("R");\r
-\r
-               csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + \r
-                               CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +\r
-                               CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, nLayout);\r
-\r
-               WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);\r
-               if (pRolloverIcon)\r
-                       AddImageToAppearance("R", pRolloverIcon);\r
-\r
-               if (csDownCaption.IsEmpty() && !pDownIcon)\r
-               {\r
-                       csDownCaption = csNormalCaption;\r
-                       pDownIcon = pNormalIcon;\r
-               }\r
-\r
-               switch (nBorderStyle)\r
-               {\r
-               case PBS_BEVELED:\r
-                       {\r
-                               CPWL_Color crTemp = crLeftTop;\r
-                               crLeftTop = crRightBottom;\r
-                               crRightBottom = crTemp;\r
-                       }\r
-                       break;\r
-               case PBS_INSET:\r
-                       crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);\r
-                       crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);\r
-                       break;\r
-               }\r
-               \r
-               FontMap.SetAPType("D");\r
-\r
-               csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, CPWL_Utils::SubstractColor(crBackground,0.25f)) + \r
-                       CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) + \r
-                       CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);\r
-\r
-               WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);\r
-               if (pDownIcon)\r
-                       AddImageToAppearance("D", pDownIcon);\r
-       }\r
-       else\r
-       {\r
-               RemoveAppearance("D");\r
-               RemoveAppearance("R");\r
-       }\r
-}\r
-\r
-void CPDFSDK_Widget::ResetAppearance_CheckBox()\r
-{\r
-       CPDF_FormControl* pControl = GetFormControl();\r
-       ASSERT(pControl != NULL);\r
-\r
-\r
-\r
-       CPWL_Color crBackground, crBorder, crText;\r
-       \r
-       int iColorType;\r
-       FX_FLOAT fc[4];\r
-\r
-       pControl->GetOriginalBackgroundColor(iColorType, fc);\r
-       if (iColorType > 0)\r
-               crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-\r
-       pControl->GetOriginalBorderColor(iColorType, fc);\r
-       if (iColorType > 0)\r
-               crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-\r
-       FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
-       FX_INT32 nBorderStyle = 0;\r
-       CPWL_Dash dsBorder(3,0,0);\r
-       CPWL_Color crLeftTop,crRightBottom;\r
-\r
-       switch (GetBorderStyle())\r
-       {\r
-       case BBS_DASH:\r
-               nBorderStyle = PBS_DASH;\r
-               dsBorder = CPWL_Dash(3, 3, 0);\r
-               break;\r
-       case BBS_BEVELED:\r
-               nBorderStyle = PBS_BEVELED;\r
-               fBorderWidth *= 2;\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);\r
-               crRightBottom = CPWL_Utils::DevideColor(crBackground,2);\r
-               break;\r
-       case BBS_INSET:\r
-               nBorderStyle = PBS_INSET;\r
-               fBorderWidth *= 2;\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);\r
-               crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);\r
-               break;\r
-       case BBS_UNDERLINE:\r
-               nBorderStyle = PBS_UNDERLINED;\r
-               break;\r
-       default: \r
-               nBorderStyle = PBS_SOLID;\r
-               break;\r
-       }\r
-\r
-       CPDF_Rect rcWindow = GetRotatedRect();\r
-       CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);\r
-\r
-       CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();\r
-       if (da.HasColor())\r
-       {\r
-               da.GetColor(iColorType, fc);\r
-               crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-       }\r
-\r
-       FX_INT32 nStyle = 0;\r
-\r
-       CFX_WideString csWCaption = pControl->GetNormalCaption();\r
-       if (csWCaption.GetLength() > 0)\r
-       {\r
-               switch (csWCaption[0])\r
-               {\r
-               case L'l':\r
-                       nStyle = PCS_CIRCLE;                    \r
-                       break;\r
-               case L'8':\r
-                       nStyle = PCS_CROSS;\r
-                       break;\r
-               case L'u':\r
-                       nStyle = PCS_DIAMOND;\r
-                       break;\r
-               case L'n':\r
-                       nStyle = PCS_SQUARE;\r
-                       break;\r
-               case L'H':\r
-                       nStyle = PCS_STAR;\r
-                       break;\r
-               default: //L'4'\r
-                       nStyle = PCS_CHECK;\r
-                       break;\r
-               }\r
-       }\r
-       else\r
-       {\r
-               nStyle = PCS_CHECK;\r
-       }\r
-\r
-       CFX_ByteString csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +\r
-               CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
-\r
-       CFX_ByteString csAP_N_OFF = csAP_N_ON;\r
-\r
-       switch (nBorderStyle)\r
-       {\r
-       case PBS_BEVELED:\r
-               {\r
-                       CPWL_Color crTemp = crLeftTop;\r
-                       crLeftTop = crRightBottom;\r
-                       crRightBottom = crTemp;\r
-               }\r
-               break;\r
-       case PBS_INSET:\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);\r
-               crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);\r
-               break;\r
-       }\r
-\r
-       CFX_ByteString csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) + \r
-               CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
-\r
-       CFX_ByteString csAP_D_OFF = csAP_D_ON;\r
-\r
-       csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);\r
-       csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);\r
-\r
-       WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());\r
-       WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");\r
-\r
-       WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());\r
-       WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");\r
-\r
-       CFX_ByteString csAS = GetAppState();\r
-       if (csAS.IsEmpty())\r
-               SetAppState("Off");\r
-}\r
-\r
-void CPDFSDK_Widget::ResetAppearance_RadioButton()\r
-{\r
-       CPDF_FormControl* pControl = GetFormControl();\r
-       ASSERT(pControl != NULL);\r
-       \r
-\r
-\r
-       CPWL_Color crBackground, crBorder, crText;\r
-       \r
-       int iColorType;\r
-       FX_FLOAT fc[4];\r
-\r
-       pControl->GetOriginalBackgroundColor(iColorType, fc);\r
-       if (iColorType > 0)\r
-               crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-\r
-       pControl->GetOriginalBorderColor(iColorType, fc);\r
-       if (iColorType > 0)\r
-               crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-\r
-       FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
-       FX_INT32 nBorderStyle = 0;\r
-       CPWL_Dash dsBorder(3,0,0);\r
-       CPWL_Color crLeftTop,crRightBottom;\r
-\r
-       switch (GetBorderStyle())\r
-       {\r
-       case BBS_DASH:\r
-               nBorderStyle = PBS_DASH;\r
-               dsBorder = CPWL_Dash(3, 3, 0);\r
-               break;\r
-       case BBS_BEVELED:\r
-               nBorderStyle = PBS_BEVELED;\r
-               fBorderWidth *= 2;\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);\r
-               crRightBottom = CPWL_Utils::DevideColor(crBackground,2);\r
-               break;\r
-       case BBS_INSET:\r
-               nBorderStyle = PBS_INSET;\r
-               fBorderWidth *= 2;\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);\r
-               crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);\r
-               break;\r
-       case BBS_UNDERLINE:\r
-               nBorderStyle = PBS_UNDERLINED;\r
-               break;\r
-       default: \r
-               nBorderStyle = PBS_SOLID;\r
-               break;\r
-       }\r
-\r
-       CPDF_Rect rcWindow = GetRotatedRect();\r
-       CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);\r
-\r
-       CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();\r
-       if (da.HasColor())\r
-       {\r
-               da.GetColor(iColorType, fc);\r
-               crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-       }\r
-\r
-       FX_INT32 nStyle = 0;\r
-\r
-       CFX_WideString csWCaption = pControl->GetNormalCaption();\r
-       if (csWCaption.GetLength() > 0)\r
-       {\r
-               switch (csWCaption[0])\r
-               {\r
-               default: //L'l':\r
-                       nStyle = PCS_CIRCLE;                    \r
-                       break;\r
-               case L'8':\r
-                       nStyle = PCS_CROSS;\r
-                       break;\r
-               case L'u':\r
-                       nStyle = PCS_DIAMOND;\r
-                       break;\r
-               case L'n':\r
-                       nStyle = PCS_SQUARE;\r
-                       break;\r
-               case L'H':\r
-                       nStyle = PCS_STAR;\r
-                       break;\r
-               case L'4':\r
-                       nStyle = PCS_CHECK;\r
-                       break;\r
-               }\r
-       }\r
-       else\r
-       {\r
-               nStyle = PCS_CIRCLE;\r
-       }\r
-\r
-       CFX_ByteString csAP_N_ON;\r
-\r
-       CPDF_Rect rcCenter = CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);\r
-       \r
-       if (nStyle == PCS_CIRCLE)\r
-       {\r
-               if (nBorderStyle == PBS_BEVELED)\r
-               {\r
-                       crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);\r
-                       crRightBottom = CPWL_Utils::SubstractColor(crBackground,0.25f);\r
-               }\r
-               else if (nBorderStyle == PBS_INSET)\r
-               {\r
-                       crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5f);\r
-                       crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75f);\r
-               }\r
-\r
-               csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBackground) + \r
-                       CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
-       }\r
-       else\r
-       {\r
-               csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) + \r
-                       CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
-       }\r
-\r
-       CFX_ByteString csAP_N_OFF = csAP_N_ON;\r
-\r
-       switch (nBorderStyle)\r
-       {\r
-       case PBS_BEVELED:\r
-               {\r
-                       CPWL_Color crTemp = crLeftTop;\r
-                       crLeftTop = crRightBottom;\r
-                       crRightBottom = crTemp;\r
-               }\r
-               break;\r
-       case PBS_INSET:\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);\r
-               crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);\r
-               break;\r
-       }\r
-\r
-       CFX_ByteString csAP_D_ON;\r
-\r
-       if (nStyle == PCS_CIRCLE)\r
-       {\r
-               CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground,0.25f);\r
-               if (nBorderStyle == PBS_BEVELED)\r
-               {\r
-                       crLeftTop = CPWL_Utils::SubstractColor(crBackground,0.25f);\r
-                       crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);\r
-                       crBK = crBackground;\r
-               }\r
-               else if (nBorderStyle == PBS_INSET)\r
-               {\r
-                       crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);\r
-                       crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);\r
-               }\r
-\r
-               csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBK)\r
-                       + CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
-       }\r
-       else\r
-       {\r
-               csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) + \r
-                       CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);           \r
-       }\r
-\r
-       CFX_ByteString csAP_D_OFF = csAP_D_ON;\r
-\r
-       csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);\r
-       csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);\r
-\r
-       WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());\r
-       WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");\r
-\r
-       WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());\r
-       WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");\r
-\r
-       CFX_ByteString csAS = GetAppState();\r
-       if (csAS.IsEmpty())\r
-               SetAppState("Off");\r
-}\r
-\r
-void CPDFSDK_Widget::ResetAppearance_ComboBox(FX_LPCWSTR sValue)\r
-{\r
-       CPDF_FormControl* pControl = GetFormControl();\r
-       ASSERT(pControl != NULL);\r
-       CPDF_FormField* pField = pControl->GetField();\r
-       ASSERT(pField != NULL);\r
-\r
-       CFX_ByteTextBuf sBody, sLines;\r
-\r
-       CPDF_Rect rcClient = GetClientRect();\r
-       CPDF_Rect rcButton = rcClient;\r
-       rcButton.left = rcButton.right - 13;\r
-       rcButton.Normalize();\r
-\r
-       if (IFX_Edit * pEdit = IFX_Edit::NewEdit())\r
-       {\r
-               pEdit->EnableRefresh(FALSE);\r
-\r
-               ASSERT(this->m_pInterForm != NULL);\r
-               CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();\r
-               ASSERT(pDoc != NULL);\r
-               CPDFDoc_Environment* pEnv = pDoc->GetEnv();\r
-               CBA_FontMap FontMap(this,pEnv->GetSysHandler());\r
-               FontMap.Initial();\r
-               pEdit->SetFontMap(&FontMap);\r
-\r
-               CPDF_Rect rcEdit = rcClient;\r
-               rcEdit.right = rcButton.left;\r
-               rcEdit.Normalize();\r
-               \r
-               pEdit->SetPlateRect(rcEdit);\r
-               pEdit->SetAlignmentV(1);\r
-\r
-               FX_FLOAT fFontSize = this->GetFontSize();\r
-               if (IsFloatZero(fFontSize))\r
-                       pEdit->SetAutoFontSize(TRUE);\r
-               else\r
-                       pEdit->SetFontSize(fFontSize);\r
-               \r
-               pEdit->Initialize();\r
-               \r
-               if (sValue)\r
-                       pEdit->SetText(sValue);\r
-               else\r
-               {\r
-                       FX_INT32 nCurSel = pField->GetSelectedIndex(0);\r
-\r
-                       if (nCurSel < 0)\r
-                               pEdit->SetText((FX_LPCWSTR)pField->GetValue());\r
-                       else\r
-                               pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(nCurSel));\r
-               }\r
-\r
-               CPDF_Rect rcContent = pEdit->GetContentRect();\r
-\r
-               CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f));\r
-               if (sEdit.GetLength() > 0)\r
-               {\r
-                       sBody << "/Tx BMC\n" << "q\n";\r
-                       if (rcContent.Width() > rcEdit.Width() ||\r
-                               rcContent.Height() > rcEdit.Height())\r
-                       {\r
-                               sBody << rcEdit.left << " " << rcEdit.bottom << " " \r
-                                       << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n";\r
-                       }\r
-\r
-                       CPWL_Color crText = GetTextPWLColor();  \r
-                       sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";\r
-               }\r
-\r
-               IFX_Edit::DelEdit(pEdit);\r
-       }\r
-\r
-       sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);\r
-\r
-       CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();\r
-\r
-       WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);\r
-}\r
-\r
-void CPDFSDK_Widget::ResetAppearance_ListBox()\r
-{\r
-       CPDF_FormControl* pControl = GetFormControl();\r
-       ASSERT(pControl != NULL);\r
-       CPDF_FormField* pField = pControl->GetField();\r
-       ASSERT(pField != NULL);\r
-\r
-       CPDF_Rect rcClient = GetClientRect();\r
-\r
-       CFX_ByteTextBuf sBody, sLines;\r
-\r
-       if (IFX_Edit * pEdit = IFX_Edit::NewEdit())\r
-       {\r
-               pEdit->EnableRefresh(FALSE);\r
-\r
-//             ASSERT(this->m_pBaseForm != NULL);\r
-               ASSERT(this->m_pInterForm != NULL);\r
-               CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();\r
-               ASSERT(pDoc != NULL);\r
-               CPDFDoc_Environment* pEnv = pDoc->GetEnv();\r
-\r
-               CBA_FontMap FontMap(this,pEnv->GetSysHandler());\r
-               FontMap.Initial();\r
-               pEdit->SetFontMap(&FontMap);\r
-\r
-               pEdit->SetPlateRect(CPDF_Rect(rcClient.left,0.0f,rcClient.right,0.0f)); \r
-               \r
-               FX_FLOAT fFontSize = GetFontSize();\r
-\r
-               if (IsFloatZero(fFontSize))\r
-                       pEdit->SetFontSize(12.0f);\r
-               else\r
-                       pEdit->SetFontSize(fFontSize);\r
-               \r
-               pEdit->Initialize();\r
-\r
-               CFX_ByteTextBuf sList;\r
-               FX_FLOAT fy = rcClient.top;\r
-\r
-               FX_INT32 nTop = pField->GetTopVisibleIndex();\r
-               FX_INT32 nCount = pField->CountOptions();\r
-               FX_INT32 nSelCount = pField->CountSelectedItems();\r
-\r
-               for (FX_INT32 i=nTop; i<nCount; i++)\r
-               {\r
-                       FX_BOOL bSelected = FALSE;                              \r
-                       for (FX_INT32 j=0; j<nSelCount; j++)\r
-                       {\r
-                               if (pField->GetSelectedIndex(j) == i)\r
-                               {\r
-                                       bSelected = TRUE;\r
-                                       break;\r
-                               }\r
-                       }\r
-\r
-                       pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(i));\r
-\r
-                       CPDF_Rect rcContent = pEdit->GetContentRect();\r
-                       FX_FLOAT fItemHeight = rcContent.Height();\r
-\r
-                       if (bSelected)\r
-                       {\r
-                               CPDF_Rect rcItem = CPDF_Rect(rcClient.left,fy-fItemHeight,rcClient.right,fy);\r
-                               sList << "q\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,0,51.0f/255.0f,113.0f/255.0f),TRUE)\r
-                                       << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() << " " << rcItem.Height() << " re f\n" << "Q\n";\r
-\r
-                               sList << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY,1),TRUE) << \r
-                                       CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";\r
-                       }\r
-                       else\r
-                       {\r
-                               CPWL_Color crText = GetTextPWLColor();\r
-                               sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << \r
-                               CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";\r
-                       }\r
-\r
-                       fy -= fItemHeight;\r
-               }\r
-                                       \r
-               if (sList.GetSize() > 0)\r
-               {\r
-                       sBody << "/Tx BMC\n" << "q\n" << rcClient.left << " " << rcClient.bottom << " " \r
-                                       << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";\r
-                       sBody << sList << "Q\nEMC\n";\r
-               }\r
-\r
-               IFX_Edit::DelEdit(pEdit);\r
-       }\r
-\r
-       CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();\r
-\r
-       WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);\r
-}\r
-\r
-void CPDFSDK_Widget::ResetAppearance_TextField(FX_LPCWSTR sValue)\r
-{\r
-       CPDF_FormControl* pControl = GetFormControl();\r
-       ASSERT(pControl != NULL);\r
-       CPDF_FormField* pField = pControl->GetField();\r
-       ASSERT(pField != NULL);\r
-\r
-       CFX_ByteTextBuf sBody, sLines;\r
-       \r
-       if (IFX_Edit * pEdit = IFX_Edit::NewEdit())\r
-       {\r
-               pEdit->EnableRefresh(FALSE);\r
-\r
-//             ASSERT(this->m_pBaseForm != NULL);\r
-               ASSERT(this->m_pInterForm != NULL);\r
-               CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();\r
-               ASSERT(pDoc != NULL);\r
-               CPDFDoc_Environment* pEnv = pDoc->GetEnv();\r
-\r
-               CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));\r
-               FontMap.Initial();\r
-               pEdit->SetFontMap(&FontMap);\r
-\r
-               CPDF_Rect rcClient = GetClientRect();\r
-               pEdit->SetPlateRect(rcClient);\r
-               pEdit->SetAlignmentH(pControl->GetControlAlignment());\r
-               \r
-               FX_DWORD dwFieldFlags = pField->GetFieldFlags();\r
-               FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;\r
-\r
-               if (bMultiLine)\r
-               {\r
-                       pEdit->SetMultiLine(TRUE);\r
-                       pEdit->SetAutoReturn(TRUE);\r
-               }\r
-               else\r
-               {\r
-                       pEdit->SetAlignmentV(1);\r
-               }\r
-\r
-               FX_WORD subWord = 0;\r
-               if ((dwFieldFlags >> 13) & 1)\r
-               {\r
-                       subWord = '*';\r
-                       pEdit->SetPasswordChar(subWord);\r
-               }\r
-\r
-               int nMaxLen = pField->GetMaxLen();\r
-               FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;\r
-               FX_FLOAT fFontSize = GetFontSize();     \r
-\r
-               if (nMaxLen > 0)\r
-               {\r
-                       if (bCharArray)\r
-                       {\r
-                               pEdit->SetCharArray(nMaxLen);\r
-\r
-                               if (IsFloatZero(fFontSize))\r
-                               {\r
-                                       fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetPDFFont(0),rcClient,nMaxLen);\r
-                               }\r
-                       }\r
-                       else\r
-                       {\r
-                               if (sValue)\r
-                                       nMaxLen = wcslen((const wchar_t*)sValue); \r
-                               pEdit->SetLimitChar(nMaxLen);\r
-                       }\r
-               }\r
-\r
-               if (IsFloatZero(fFontSize))\r
-                       pEdit->SetAutoFontSize(TRUE);\r
-               else\r
-                       pEdit->SetFontSize(fFontSize);\r
-\r
-               pEdit->Initialize();\r
-               \r
-               if (sValue)\r
-                       pEdit->SetText(sValue);\r
-               else\r
-                       pEdit->SetText((FX_LPCWSTR)pField->GetValue());\r
-\r
-               CPDF_Rect rcContent = pEdit->GetContentRect();\r
-\r
-               CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f),\r
-                                                                                                                                       NULL,!bCharArray,subWord);\r
-\r
-               if (sEdit.GetLength() > 0)\r
-               {\r
-                       sBody << "/Tx BMC\n" << "q\n";\r
-                       if (rcContent.Width() > rcClient.Width() ||\r
-                               rcContent.Height() > rcClient.Height())\r
-                       {\r
-                               sBody << rcClient.left << " " << rcClient.bottom << " " \r
-                                       << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";\r
-                       }\r
-                       CPWL_Color crText = GetTextPWLColor();  \r
-                       sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";\r
-               }\r
-\r
-               if (bCharArray)\r
-               {\r
-                       switch (GetBorderStyle())\r
-                       {\r
-                       case BBS_SOLID:\r
-                               {\r
-                                       CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);\r
-                                       if (sColor.GetLength() > 0)\r
-                                       {\r
-                                               sLines << "q\n" << GetBorderWidth() << " w\n" \r
-                                                       << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE) << " 2 J 0 j\n";                                    \r
-\r
-                                               for (FX_INT32 i=1;i<nMaxLen;i++)\r
-                                               {\r
-                                                       sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "\r
-                                                               << rcClient.bottom << " m\n"\r
-                                                               << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "\r
-                                                               << rcClient.top << " l S\n";                                            \r
-                                               }\r
-\r
-                                               sLines << "Q\n";                \r
-                                       }\r
-                               }\r
-                               break;\r
-                       case BBS_DASH:\r
-                               {\r
-                                       CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);\r
-                                       if (sColor.GetLength() > 0)\r
-                                       {\r
-                                               CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);\r
-\r
-                                               sLines << "q\n" << GetBorderWidth() << " w\n" \r
-                                                       << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE)\r
-                                                       << "[" << dsBorder.nDash << " " \r
-                                                       << dsBorder.nGap << "] " \r
-                                                       << dsBorder.nPhase << " d\n";\r
-\r
-                                               for (FX_INT32 i=1;i<nMaxLen;i++)                                        \r
-                                               {\r
-                                                       sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "\r
-                                                               << rcClient.bottom << " m\n"\r
-                                                               << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "\r
-                                                               << rcClient.top << " l S\n";    \r
-                                               }\r
-\r
-                                               sLines << "Q\n";\r
-                                       }\r
-                               }\r
-                               break;\r
-                       }\r
-               }\r
-\r
-               IFX_Edit::DelEdit(pEdit);\r
-       }\r
-\r
-       CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();\r
-       WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);\r
-}\r
-\r
-CPDF_Rect CPDFSDK_Widget::GetClientRect() const\r
-{\r
-       CPDF_Rect rcWindow = GetRotatedRect();\r
-       FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
-       switch (GetBorderStyle())\r
-       {\r
-       case BBS_BEVELED:\r
-       case BBS_INSET:\r
-               fBorderWidth *= 2.0f;\r
-               break;\r
-       }\r
-\r
-       return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);\r
-}\r
-\r
-CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const\r
-{\r
-       CPDF_Rect rectAnnot = GetRect();\r
-       FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;\r
-       FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;\r
-\r
-       CPDF_FormControl* pControl = GetFormControl();\r
-       ASSERT(pControl != NULL);\r
-\r
-       CPDF_Rect rcPDFWindow;\r
-       switch(abs(pControl->GetRotation() % 360))\r
-       {\r
-               case 0:\r
-               case 180:\r
-               default:\r
-                       rcPDFWindow = CPDF_Rect(0, 0, fWidth, fHeight); \r
-                       break;\r
-               case 90:\r
-               case 270:\r
-                       rcPDFWindow = CPDF_Rect(0, 0, fHeight, fWidth);\r
-                       break;\r
-       }\r
-\r
-       return rcPDFWindow;\r
-}\r
-\r
-CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const\r
-{\r
-       CPWL_Color crBackground = GetFillPWLColor();\r
-       if (crBackground.nColorType != COLORTYPE_TRANSPARENT)\r
-               return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);\r
-       else\r
-               return "";\r
-}\r
-\r
-CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const\r
-{\r
-       CPDF_Rect rcWindow = GetRotatedRect();\r
-       CPWL_Color crBorder = GetBorderPWLColor();\r
-       CPWL_Color crBackground = GetFillPWLColor();\r
-       CPWL_Color crLeftTop, crRightBottom;\r
-\r
-       FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
-       FX_INT32 nBorderStyle = 0;\r
-       CPWL_Dash dsBorder(3,0,0);\r
-\r
-       switch (GetBorderStyle())\r
-       {\r
-       case BBS_DASH:\r
-               nBorderStyle = PBS_DASH;\r
-               dsBorder = CPWL_Dash(3, 3, 0);\r
-               break;\r
-       case BBS_BEVELED:\r
-               nBorderStyle = PBS_BEVELED;\r
-               fBorderWidth *= 2;\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);\r
-               crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);\r
-               break;\r
-       case BBS_INSET:\r
-               nBorderStyle = PBS_INSET;\r
-               fBorderWidth *= 2;\r
-               crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);\r
-               crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);\r
-               break;\r
-       case BBS_UNDERLINE:\r
-               nBorderStyle = PBS_UNDERLINED;\r
-               break;\r
-       default: \r
-               nBorderStyle = PBS_SOLID;\r
-               break;\r
-       }\r
-\r
-       return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, \r
-               crRightBottom, nBorderStyle, dsBorder);\r
-}\r
-\r
-CPDF_Matrix CPDFSDK_Widget::GetMatrix() const\r
-{\r
-       CPDF_Matrix mt;\r
-       CPDF_FormControl* pControl = GetFormControl();\r
-       ASSERT(pControl != NULL);\r
-\r
-       CPDF_Rect rcAnnot = GetRect();\r
-       FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;\r
-       FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;\r
-       \r
-\r
-\r
-       switch (abs(pControl->GetRotation() % 360))\r
-       {\r
-               case 0:\r
-               default:\r
-                       mt = CPDF_Matrix(1, 0, 0, 1, 0, 0);\r
-                       break;\r
-               case 90:\r
-                       mt = CPDF_Matrix(0, 1, -1, 0, fWidth, 0);\r
-                       break;\r
-               case 180:\r
-                       mt = CPDF_Matrix(-1, 0, 0, -1, fWidth, fHeight);\r
-                       break;\r
-               case 270:\r
-                       mt = CPDF_Matrix(0, -1, 1, 0, 0, fHeight);\r
-                       break;\r
-       }\r
-\r
-       return mt;\r
-}\r
-\r
-CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const\r
-{\r
-       CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);\r
-\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-\r
-       CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();\r
-       if (da.HasColor())\r
-       {\r
-               FX_INT32 iColorType;\r
-               FX_FLOAT fc[4];\r
-               da.GetColor(iColorType, fc);\r
-               crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-       }\r
-\r
-       return crText;\r
-}\r
-\r
-CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const\r
-{\r
-       CPWL_Color crBorder;\r
-\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-\r
-       FX_INT32 iColorType;\r
-       FX_FLOAT fc[4];\r
-       pFormCtrl->GetOriginalBorderColor(iColorType, fc);\r
-       if (iColorType > 0)\r
-               crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-\r
-       return crBorder;\r
-}\r
-\r
-CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const\r
-{\r
-       CPWL_Color crFill;\r
-\r
-       CPDF_FormControl* pFormCtrl = GetFormControl();\r
-       ASSERT(pFormCtrl != NULL);\r
-\r
-       FX_INT32 iColorType;\r
-       FX_FLOAT fc[4];\r
-       pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);\r
-       if (iColorType > 0)\r
-               crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
-\r
-       return crFill;\r
-}\r
-\r
-void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage)\r
-{\r
-       ASSERT(pImage != NULL);\r
-\r
-       ASSERT(m_pAnnot != NULL);\r
-       ASSERT(m_pAnnot->m_pAnnotDict != NULL);\r
-\r
-       CPDF_Document* pDoc = m_pPageView->GetPDFDocument();//pDocument->GetDocument();\r
-       ASSERT(pDoc != NULL);\r
-\r
-       CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP");\r
-       ASSERT(pAPDict != NULL);\r
-\r
-       CPDF_Stream* pStream = pAPDict->GetStream(sAPType);\r
-       ASSERT(pStream != NULL);\r
-\r
-       CPDF_Dictionary* pStreamDict = pStream->GetDict();\r
-       ASSERT(pStreamDict != NULL);\r
-\r
-       CFX_ByteString sImageAlias = "IMG";\r
-\r
-       if (CPDF_Dictionary* pImageDict = pImage->GetDict())\r
-       {\r
-               sImageAlias = pImageDict->GetString("Name");\r
-               if (sImageAlias.IsEmpty())\r
-                       sImageAlias = "IMG";\r
-       }       \r
-\r
-       CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");\r
-       if (!pStreamResList)\r
-       {\r
-               pStreamResList = FX_NEW CPDF_Dictionary();\r
-               pStreamDict->SetAt("Resources", pStreamResList);\r
-       }\r
-\r
-       if (pStreamResList) \r
-       {\r
-               CPDF_Dictionary* pXObject = FX_NEW CPDF_Dictionary;                     \r
-               pXObject->SetAtReference(sImageAlias, pDoc, pImage);\r
-               pStreamResList->SetAt("XObject", pXObject);\r
-       }\r
-}\r
-\r
-void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType)\r
-{\r
-       ASSERT(m_pAnnot != NULL);\r
-       ASSERT(m_pAnnot->m_pAnnotDict != NULL);\r
-\r
-       if (CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP"))\r
-       {\r
-               pAPDict->RemoveAt(sAPType);\r
-       }\r
-}\r
-\r
-FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView)\r
-{\r
-       CPDF_Action action = GetAAction(type);\r
-\r
-       if (action && action.GetType() != CPDF_Action::Unknown)\r
-       {\r
-               CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();\r
-               ASSERT(pDocument != NULL);\r
\r
-               CPDFDoc_Environment* pEnv = pDocument->GetEnv();\r
-               ASSERT(pEnv != NULL);\r
-\r
-               CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();/*(CPDFSDK_ActionHandler*)pApp->GetActionHandler();*/\r
-               ASSERT(pActionHandler != NULL);\r
\r
-               return pActionHandler->DoAction_Field(action, type, pDocument, GetFormField(), data);\r
-       }\r
-\r
-       return FALSE;\r
-}\r
-\r
-CPDF_Action    CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT)\r
-{\r
-       switch (eAAT)\r
-       {\r
-       case CPDF_AAction::CursorEnter:\r
-       case CPDF_AAction::CursorExit:\r
-       case CPDF_AAction::ButtonDown:\r
-       case CPDF_AAction::ButtonUp:\r
-       case CPDF_AAction::GetFocus:\r
-       case CPDF_AAction::LoseFocus:\r
-       case CPDF_AAction::PageOpen:\r
-       case CPDF_AAction::PageClose:\r
-       case CPDF_AAction::PageVisible:\r
-       case CPDF_AAction::PageInvisible:\r
-               return CPDFSDK_Annot::GetAAction(eAAT);\r
-       case CPDF_AAction::KeyStroke:\r
-       case CPDF_AAction::Format:\r
-       case CPDF_AAction::Validate:\r
-       case CPDF_AAction::Calculate:\r
-               {\r
-                       CPDF_FormField* pField = this->GetFormField();\r
-                       ASSERT(pField != NULL);\r
-\r
-                       if (CPDF_AAction aa = pField->GetAdditionalAction())\r
-                               return aa.GetAction(eAAT);\r
-                       else \r
-                               return CPDFSDK_Annot::GetAAction(eAAT);\r
-               }\r
-       default:\r
-               return NULL;\r
-       }\r
-\r
-       return NULL;\r
-}\r
-\r
-\r
-CFX_WideString CPDFSDK_Widget::GetAlternateName() const\r
-{\r
-       CPDF_FormField* pFormField = GetFormField();\r
-       ASSERT(pFormField != NULL);\r
-\r
-       return pFormField->GetAlternateName();\r
-}\r
-\r
-FX_INT32       CPDFSDK_Widget::GetAppearanceAge() const\r
-{\r
-       return m_nAppAge;\r
-}\r
-\r
-FX_INT32 CPDFSDK_Widget::GetValueAge() const\r
-{\r
-       return m_nValueAge;\r
-}\r
-\r
-\r
-FX_BOOL        CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY)\r
-{\r
-       CPDF_Annot* pAnnot = GetPDFAnnot();\r
-       CFX_FloatRect annotRect;\r
-       pAnnot->GetRect(annotRect);\r
-       if(annotRect.Contains(pageX, pageY))\r
-       {\r
-               if (!IsVisible()) return FALSE;\r
-               \r
-               int nFieldFlags = GetFieldFlags();\r
-               if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) \r
-                       return FALSE;\r
-               \r
-               return TRUE;\r
-       }\r
-       return FALSE;\r
-}\r
-\r
-CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)\r
-       :m_pDocument(pDocument),\r
-       m_pInterForm(NULL),\r
-       m_bCalculate(TRUE),\r
-       m_bBusy(FALSE)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-       m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument(), FALSE);\r
-       ASSERT(m_pInterForm != NULL);\r
-       m_pInterForm->SetFormNotify(this);\r
-\r
-       for(int i=0; i<6; i++)\r
-               m_bNeedHightlight[i] = FALSE;\r
-       m_iHighlightAlpha = 0;\r
-}\r
-\r
-CPDFSDK_InterForm::~CPDFSDK_InterForm()\r
-{\r
-       ASSERT(m_pInterForm != NULL);\r
-       delete m_pInterForm;\r
-       m_pInterForm = NULL;\r
-\r
-       m_Map.RemoveAll();\r
-}\r
-\r
-void CPDFSDK_InterForm::Destroy()\r
-{\r
-       delete this;\r
-}\r
-\r
-CPDF_InterForm* CPDFSDK_InterForm::GetInterForm()\r
-{\r
-       return m_pInterForm;\r
-}\r
-\r
-CPDFSDK_Document* CPDFSDK_InterForm::GetDocument()\r
-{\r
-       return m_pDocument;\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::HighlightWidgets()\r
-{\r
-       return FALSE;\r
-}\r
-\r
-CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL bNext) const\r
-{\r
-       ASSERT(pWidget != NULL);\r
-\r
-       CBA_AnnotIterator* pIterator = new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "");\r
-       ASSERT(pIterator != NULL);\r
-\r
-       CPDFSDK_Widget* pRet = NULL;\r
-\r
-       if (bNext)\r
-               pRet = (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);\r
-       else\r
-               pRet = (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);\r
-\r
-       pIterator->Release();\r
-       \r
-       return pRet;\r
-\r
-}\r
-\r
-CPDFSDK_Widget*        CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const\r
-{\r
-       if(!pControl || !m_pInterForm) return NULL;\r
-       \r
-       CPDFSDK_Widget* pWidget = NULL;\r
-       m_Map.Lookup(pControl, pWidget);\r
-\r
-       if (pWidget) return pWidget;\r
-\r
-       CPDF_Dictionary* pControlDict = pControl->GetWidget();\r
-       ASSERT(pControlDict != NULL);\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-       CPDF_Document* pDocument = m_pDocument->GetDocument();\r
-\r
-       CPDFSDK_PageView* pPage = NULL;\r
-\r
-       if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P"))\r
-       {\r
-               int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());\r
-               if (nPageIndex >= 0)\r
-               {\r
-                       pPage = m_pDocument->GetPageView(nPageIndex);\r
-               }\r
-       }\r
-\r
-       if (!pPage) \r
-       {\r
-               int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);\r
-               if (nPageIndex >= 0)\r
-               {\r
-                       pPage = m_pDocument->GetPageView(nPageIndex);\r
-               }\r
-       }\r
-\r
-       if (pPage)\r
-               return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);\r
-\r
-       return NULL;\r
-}\r
-\r
-void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets)\r
-{\r
-       ASSERT(m_pInterForm != NULL);\r
-\r
-       for (int i=0,sz=m_pInterForm->CountFields(sFieldName); i<sz; i++)\r
-       {\r
-               CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);\r
-               ASSERT(pFormField != NULL);\r
-\r
-               GetWidgets(pFormField, widgets);        \r
-       }\r
-}\r
-\r
-void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets)\r
-{\r
-       ASSERT(pField != NULL);\r
-\r
-       for (int i=0,isz=pField->CountControls(); i<isz; i++)\r
-       {\r
-               CPDF_FormControl* pFormCtrl = pField->GetControl(i);\r
-               ASSERT(pFormCtrl != NULL);\r
-\r
-               CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);\r
-\r
-               if (pWidget)\r
-                       widgets.Add(pWidget);\r
-       }\r
-}\r
-\r
-int CPDFSDK_InterForm::GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const\r
-{\r
-       ASSERT(pDocument != NULL);\r
-       ASSERT(pAnnotDict != NULL);\r
-\r
-       for (int i=0,sz=pDocument->GetPageCount(); i<sz; i++)\r
-       {\r
-               if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i))\r
-               {                       \r
-                       if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots"))\r
-                       {\r
-                               for (int j=0,jsz=pAnnots->GetCount(); j<jsz; j++)\r
-                               {\r
-                                       CPDF_Object* pDict = pAnnots->GetElementValue(j);\r
-                                       if (pAnnotDict == pDict)\r
-                                       {\r
-                                               return i;\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       return -1;\r
-}\r
-\r
-void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget)\r
-{\r
-       m_Map.SetAt(pControl, pWidget);\r
-}\r
-\r
-void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl)\r
-{\r
-       m_Map.RemoveKey(pControl);\r
-}\r
-\r
-void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled)\r
-{\r
-       m_bCalculate = bEnabled;\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const\r
-{\r
-       return m_bCalculate;\r
-}\r
-\r
-#ifdef _WIN32\r
-CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-       CPDF_Document* pDocument = m_pDocument->GetDocument();\r
-       ASSERT(pDocument != NULL);\r
-\r
-       CPDF_Stream* pRetStream = NULL;\r
-\r
-       if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile))\r
-       {\r
-               int nWidth = pBmp->GetWidth();\r
-               int nHeight = pBmp->GetHeight();\r
-\r
-               CPDF_Image Image(pDocument);\r
-               Image.SetImage(pBmp, FALSE);\r
-               CPDF_Stream* pImageStream = Image.GetStream();\r
-               if (pImageStream)\r
-               {\r
-                       if (pImageStream->GetObjNum() == 0)\r
-                               pDocument->AddIndirectObject(pImageStream);\r
-\r
-                       CPDF_Dictionary* pStreamDict = new CPDF_Dictionary();\r
-                       pStreamDict->SetAtName("Subtype", "Form");\r
-                       pStreamDict->SetAtName("Name", "IMG");\r
-                       CPDF_Array* pMatrix = new CPDF_Array();\r
-                       pStreamDict->SetAt("Matrix", pMatrix);\r
-                       pMatrix->AddInteger(1);\r
-                       pMatrix->AddInteger(0);\r
-                       pMatrix->AddInteger(0);\r
-                       pMatrix->AddInteger(1);\r
-                       pMatrix->AddInteger(-nWidth / 2);\r
-                       pMatrix->AddInteger(-nHeight / 2);\r
-                       CPDF_Dictionary* pResource = new CPDF_Dictionary();\r
-                       pStreamDict->SetAt("Resources", pResource);\r
-                       CPDF_Dictionary* pXObject = new CPDF_Dictionary();\r
-                       pResource->SetAt("XObject", pXObject);\r
-                       pXObject->SetAtReference("Img", pDocument, pImageStream);\r
-                       CPDF_Array* pProcSet = new CPDF_Array();\r
-                       pResource->SetAt("ProcSet", pProcSet);\r
-                       pProcSet->AddName("PDF");\r
-                       pProcSet->AddName("ImageC");\r
-                       pStreamDict->SetAtName("Type", "XObject");\r
-                       CPDF_Array* pBBox = new CPDF_Array();\r
-                       pStreamDict->SetAt("BBox", pBBox);\r
-                       pBBox->AddInteger(0);\r
-                       pBBox->AddInteger(0);\r
-                       pBBox->AddInteger(nWidth);\r
-                       pBBox->AddInteger(nHeight);\r
-                       pStreamDict->SetAtInteger("FormType", 1);\r
-\r
-                       pRetStream = new CPDF_Stream(NULL, 0, NULL);\r
-                       CFX_ByteString csStream;\r
-                       csStream.Format("q\n%d 0 0 %d 0 0 cm\n/Img Do\nQ", nWidth, nHeight);\r
-                       pRetStream->InitStream((FX_BYTE*)(FX_LPCSTR)csStream, csStream.GetLength(), pStreamDict);\r
-                       pDocument->AddIndirectObject(pRetStream);\r
-               }\r
-\r
-               delete pBmp;\r
-       }\r
-\r
-       return pRetStream;\r
-}\r
-#endif\r
-\r
-void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-       CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-       ASSERT(pEnv);\r
-       if(!pEnv->IsJSInitiated())\r
-               return;\r
-\r
-       if (m_bBusy) return;\r
-\r
-       m_bBusy = TRUE;\r
-\r
-       if (this->IsCalculateEnabled())\r
-       {\r
-               IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();\r
-               ASSERT(pRuntime != NULL);\r
-\r
-               pRuntime->SetReaderDocument(m_pDocument);\r
-\r
-               int nSize = m_pInterForm->CountFieldsInCalculationOrder();\r
-               for (int i=0; i<nSize; i++)\r
-               {\r
-                       if(CPDF_FormField* pField = m_pInterForm->GetFieldInCalculationOrder(i))\r
-                       {\r
-//                     ASSERT(pField != NULL);\r
-                               int nType = pField->GetFieldType();\r
-                               if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)\r
-                               {\r
-                                       CPDF_AAction aAction = pField->GetAdditionalAction();\r
-                                       if (aAction && aAction.ActionExist(CPDF_AAction::Calculate))\r
-                                       {\r
-                                               CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate);\r
-                                               if (action)\r
-                                               {\r
-                                                       CFX_WideString csJS = action.GetJavaScript();\r
-                                                       if (!csJS.IsEmpty())\r
-                                                       {\r
-                                                               IFXJS_Context* pContext = pRuntime->NewContext();\r
-                                                               ASSERT(pContext != NULL);\r
-                                                               \r
-                                                               CFX_WideString sOldValue = pField->GetValue();\r
-                                                               CFX_WideString sValue = sOldValue;\r
-                                                               FX_BOOL bRC = TRUE;\r
-                                                               pContext->OnField_Calculate(pFormField, pField, sValue, bRC);\r
-                                                               \r
-                                                               CFX_WideString sInfo;\r
-                                                               FX_BOOL bRet = pContext->RunScript(csJS, sInfo);\r
-                                                               pRuntime->ReleaseContext(pContext);\r
-                                                               \r
-                                                               if (bRet)\r
-                                                               {\r
-                                                                       if (bRC)\r
-                                                                       {\r
-                                                                               if (sValue.Compare(sOldValue) != 0)\r
-                                                                                       pField->SetValue(sValue, TRUE);\r
-                                                                       }\r
-                                                               }\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-\r
-               \r
-       }\r
-\r
-       m_bBusy = FALSE;\r
-}\r
-\r
-CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, int nCommitKey, FX_BOOL& bFormated)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-       ASSERT(pFormField != NULL);\r
-\r
-       CFX_WideString sValue = pFormField->GetValue();\r
-       CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-       ASSERT(pEnv);\r
-       if(!pEnv->IsJSInitiated())\r
-       {\r
-               bFormated = FALSE;\r
-               return sValue;\r
-       } \r
-\r
-       IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-       \r
-       pRuntime->SetReaderDocument(m_pDocument);\r
-\r
-       if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)\r
-       {\r
-               if (pFormField->CountSelectedItems() > 0)\r
-               {\r
-                       int index = pFormField->GetSelectedIndex(0);\r
-                       if (index >= 0)\r
-                               sValue = pFormField->GetOptionLabel(index);\r
-               }\r
-       }\r
-\r
-       bFormated = FALSE;\r
-\r
-       CPDF_AAction aAction = pFormField->GetAdditionalAction();\r
-       if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format)) \r
-       {\r
-               CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);\r
-               if (action)\r
-               {                       \r
-                       CFX_WideString script = action.GetJavaScript();\r
-                       if (!script.IsEmpty())\r
-                       {\r
-                               CFX_WideString Value = sValue;\r
-\r
-                               IFXJS_Context* pContext = pRuntime->NewContext();\r
-                               ASSERT(pContext != NULL);\r
-\r
-                               pContext->OnField_Format(nCommitKey, pFormField, Value, TRUE);\r
-                       \r
-                               CFX_WideString sInfo;\r
-                               FX_BOOL bRet = pContext->RunScript(script, sInfo);\r
-                               pRuntime->ReleaseContext(pContext);\r
-\r
-                               if (bRet)\r
-                               {\r
-                                       sValue = Value;\r
-                                       bFormated = TRUE;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       return sValue;\r
-}\r
-\r
-void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, FX_LPCWSTR sValue, FX_BOOL bValueChanged)\r
-{\r
-       ASSERT(pFormField != NULL);\r
-\r
-       for (int i=0,sz=pFormField->CountControls(); i<sz; i++)\r
-       {\r
-               CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);\r
-               ASSERT(pFormCtrl != NULL);\r
-\r
-               ASSERT(m_pInterForm != NULL);\r
-               if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))\r
-                       pWidget->ResetAppearance(sValue, bValueChanged);\r
-       }\r
-}\r
-\r
-void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField)\r
-{\r
-       ASSERT(pFormField != NULL);\r
-\r
-       for (int i=0,sz=pFormField->CountControls(); i<sz; i++)\r
-       {\r
-               CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);\r
-               ASSERT(pFormCtrl != NULL);\r
-\r
-               if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))\r
-               {\r
-                       CPDFDoc_Environment * pEnv = m_pDocument->GetEnv();\r
-                       CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();\r
-                       \r
-                       CPDF_Page * pPage = pWidget->GetPDFPage();\r
-                       CPDFSDK_PageView * pPageView = m_pDocument->GetPageView(pPage,FALSE);\r
-\r
-                       FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);\r
-\r
-                       pEnv->FFI_Invalidate(pPage,rcBBox.left, rcBBox.top, rcBBox.right, rcBBox.bottom);\r
-               }\r
-       }\r
-}\r
-\r
-void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)\r
-{\r
-       ASSERT(pFormField != NULL);\r
-\r
-       CPDF_AAction aAction = pFormField->GetAdditionalAction();\r
-       if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke)) \r
-       {\r
-               CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);\r
-               if (action)\r
-               {                        \r
-                       ASSERT(m_pDocument != NULL);\r
-                       CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-                       ASSERT(pEnv != NULL);\r
-\r
-                       CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();\r
-                       ASSERT(pActionHandler != NULL);\r
-       \r
-                       PDFSDK_FieldAction fa;\r
-                       fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);\r
-                       fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);\r
-                       fa.sValue = csValue;\r
-\r
-                       pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, \r
-                               m_pDocument, pFormField, fa);\r
-                       bRC = fa.bRC;\r
-               }\r
-       }\r
-}\r
-\r
-void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)\r
-{\r
-       ASSERT(pFormField != NULL);\r
-\r
-       CPDF_AAction aAction = pFormField->GetAdditionalAction();\r
-       if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate)) \r
-       {\r
-               CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);\r
-               if (action)\r
-               {               \r
-                       ASSERT(m_pDocument != NULL);\r
-                       CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-                       ASSERT(pEnv != NULL);\r
-                       \r
-                       CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();\r
-                       ASSERT(pActionHandler != NULL);\r
-\r
-                       PDFSDK_FieldAction fa;\r
-                       fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);\r
-                       fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);\r
-                       fa.sValue = csValue;\r
-\r
-                       pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, m_pDocument, pFormField, fa);\r
-                       bRC = fa.bRC;\r
-        \r
-               }\r
-       }\r
-}\r
-\r
-/* ----------------------------- action ----------------------------- */\r
-\r
-FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action)\r
-{\r
-       ASSERT(action != NULL);\r
-\r
-       CPDF_ActionFields af = action.GetWidgets();\r
-       CFX_PtrArray fieldObjects;\r
-       af.GetAllFields(fieldObjects);\r
-       CFX_PtrArray widgetArray;\r
-       CFX_PtrArray fields;\r
-       GetFieldFromObjects(fieldObjects, fields);\r
-\r
-       FX_BOOL bHide = action.GetHideStatus();\r
-\r
-       FX_BOOL bChanged = FALSE;\r
-       \r
-       for (int i=0, sz=fields.GetSize(); i<sz; i++)\r
-       {\r
-               CPDF_FormField* pField = (CPDF_FormField*)fields[i];\r
-               ASSERT(pField != NULL);\r
-\r
-       \r
-               for (int j=0,jsz=pField->CountControls(); j<jsz; j++)\r
-               {\r
-                       CPDF_FormControl* pControl = pField->GetControl(j);\r
-                       ASSERT(pControl != NULL);\r
-\r
-                       if (CPDFSDK_Widget* pWidget = GetWidget(pControl))\r
-                       {\r
-                               int nFlags = pWidget->GetFlags();\r
-                               if (bHide)\r
-                               {\r
-                                       nFlags &= (~ANNOTFLAG_INVISIBLE);\r
-                                       nFlags &= (~ANNOTFLAG_NOVIEW);\r
-                                       nFlags |= (ANNOTFLAG_HIDDEN);\r
-                               }\r
-                               else\r
-                               {\r
-                                       nFlags &= (~ANNOTFLAG_INVISIBLE);\r
-                                       nFlags &= (~ANNOTFLAG_HIDDEN);\r
-                                       nFlags &= (~ANNOTFLAG_NOVIEW);\r
-                               }\r
-                               pWidget->SetFlags(nFlags);\r
-\r
-                               CPDFSDK_PageView* pPageView = pWidget->GetPageView();\r
-                               ASSERT(pPageView != NULL);\r
\r
-                               pPageView->UpdateView(pWidget);\r
-\r
-                               bChanged = TRUE;\r
-                       }\r
-               }\r
-       }\r
-\r
-       return bChanged;\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action)\r
-{\r
-       ASSERT(action != NULL);\r
-       ASSERT(m_pInterForm != NULL);\r
-\r
-       CFX_WideString sDestination = action.GetFilePath();\r
-       if (sDestination.IsEmpty()) return FALSE;\r
-\r
-       CPDF_Dictionary* pActionDict = action;\r
-       if (pActionDict->KeyExist("Fields"))\r
-       {\r
-               CPDF_ActionFields af = action.GetWidgets();\r
-               FX_DWORD dwFlags = action.GetFlags();\r
-               \r
-               CFX_PtrArray fieldObjects;\r
-               af.GetAllFields(fieldObjects);\r
-               CFX_PtrArray fields;\r
-               GetFieldFromObjects(fieldObjects, fields);\r
-               \r
-               if (fields.GetSize() != 0)\r
-               {\r
-                       FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01);\r
-                       if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))\r
-                       {\r
-                               return FALSE;\r
-                       }\r
-                       return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE);\r
-               }\r
-               else\r
-               {\r
-                       if ( m_pInterForm->CheckRequiredFields())\r
-                       {\r
-                               return FALSE;\r
-                       }\r
-\r
-                       return SubmitForm(sDestination, FALSE);\r
-               }\r
-       }\r
-       else\r
-       {\r
-               if ( m_pInterForm->CheckRequiredFields())\r
-               {\r
-                       return FALSE;\r
-               }\r
-\r
-               return SubmitForm(sDestination, FALSE);\r
-       }\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields,\r
-                                                                       FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncoded)\r
-{\r
-       CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-       ASSERT(pEnv != NULL);\r
-\r
-       CFX_ByteTextBuf textBuf;\r
-       ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);\r
-\r
-       FX_LPBYTE pBuffer = textBuf.GetBuffer();\r
-       FX_STRSIZE nBufSize = textBuf.GetLength();\r
-       \r
-       if (bUrlEncoded)\r
-       {\r
-               if(!FDFToURLEncodedData(pBuffer, nBufSize))\r
-                       return FALSE;\r
-       }\r
-\r
-       pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)csDestination);\r
-       \r
-       if (bUrlEncoded && pBuffer)\r
-       {\r
-               FX_Free(pBuffer);\r
-               pBuffer = NULL; \r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-void CPDFSDK_InterForm::DoFDFBuffer(CFX_ByteString sBuffer)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (CFDF_Document *pFDFDocument = CFDF_Document::ParseMemory((const unsigned char *)sBuffer.GetBuffer(sBuffer.GetLength()), sBuffer.GetLength()))\r
-       {                                               \r
-               CPDF_Dictionary* pRootDic = pFDFDocument->GetRoot();\r
-               if(pRootDic)\r
-               {\r
-                       CPDF_Dictionary * pFDFDict=pRootDic->GetDict("FDF");\r
-                       if(pFDFDict)\r
-                       {               \r
-                               CPDF_Dictionary * pJSDict = pFDFDict->GetDict("JavaScript");\r
-                               if(pJSDict)\r
-                               {\r
-                                       CFX_WideString csJS;\r
-                               \r
-                                       CPDF_Object* pJS = pJSDict->GetElementValue("Before");\r
-                                       if (pJS != NULL)\r
-                                       {\r
-                                               int iType = pJS->GetType();\r
-                                               if (iType == PDFOBJ_STRING)\r
-                                                       csJS = pJSDict->GetUnicodeText("Before");\r
-                                               else if (iType == PDFOBJ_STREAM)\r
-                                                       csJS = pJS->GetUnicodeText();\r
-                                       }\r
-                                       \r
-                               }\r
-                       }\r
-               }\r
-               delete pFDFDocument;\r
-       }\r
-\r
-       sBuffer.ReleaseBuffer();\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(FX_LPBYTE& pBuf, FX_STRSIZE& nBufSize)\r
-{\r
-       CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);\r
-       if (pFDF)\r
-       {\r
-               CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");\r
-               if (pMainDict == NULL) return FALSE;\r
-               \r
-               // Get fields\r
-               CPDF_Array* pFields = pMainDict->GetArray("Fields");\r
-               if (pFields == NULL) return FALSE;\r
-               \r
-               CFX_ByteTextBuf fdfEncodedData;\r
-\r
-               for (FX_DWORD i = 0; i < pFields->GetCount(); i ++) \r
-               {\r
-                       CPDF_Dictionary* pField = pFields->GetDict(i);\r
-                       if (pField == NULL) continue;\r
-                       CFX_WideString name;\r
-                       name = pField->GetUnicodeText("T");\r
-                       CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);\r
-                       CFX_ByteString csBValue = pField->GetString("V");\r
-                       CFX_WideString csWValue = PDF_DecodeText(csBValue);\r
-                       CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);\r
-\r
-                       fdfEncodedData = fdfEncodedData<<name_b.GetBuffer(name_b.GetLength());\r
-                       name_b.ReleaseBuffer();\r
-                       fdfEncodedData = fdfEncodedData<<"=";\r
-                       fdfEncodedData = fdfEncodedData<<csValue_b.GetBuffer(csValue_b.GetLength());\r
-                       csValue_b.ReleaseBuffer();\r
-                       if(i != pFields->GetCount()-1)\r
-                               fdfEncodedData = fdfEncodedData<<"&";\r
-               }\r
-               \r
-               nBufSize = fdfEncodedData.GetLength();\r
-               pBuf = FX_Alloc(FX_BYTE, nBufSize);\r
-               if(!pBuf)\r
-                       return FALSE;\r
-               FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);\r
-               \r
-       }\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFFile(const CFX_WideString& sFDFFileName, \r
-                                                                                                const CFX_PtrArray& fields, FX_BOOL bIncludeOrExclude)\r
-{\r
-       if (sFDFFileName.IsEmpty()) return FALSE;\r
-       ASSERT(m_pDocument != NULL);\r
-       ASSERT(m_pInterForm != NULL);\r
-\r
-       CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);\r
-       if (!pFDF) return FALSE;\r
-       FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode()); // = FALSE;//\r
-       delete pFDF;\r
-\r
-       return bRet;\r
-}\r
-FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-       ASSERT(m_pInterForm != NULL);\r
-       \r
-       CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);\r
-       if (!pFDF) return FALSE;\r
-       FX_BOOL bRet = pFDF->WriteBuf(textBuf); // = FALSE;//\r
-       delete pFDF;\r
-       \r
-       return bRet;\r
-}\r
-\r
-CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(const CFX_WideString& sFileExt)\r
-{\r
-       CFX_WideString sFileName;\r
-       return L"";\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded)\r
-{\r
-       if (sDestination.IsEmpty()) return FALSE;\r
-\r
-       CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-       ASSERT(pEnv != NULL);\r
-\r
-       if(NULL == m_pDocument) return FALSE;\r
-       CFX_WideString wsPDFFilePath = m_pDocument->GetPath();\r
-       \r
-       if(NULL == m_pInterForm) return FALSE;\r
-       CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);\r
-       if (NULL == pFDFDoc) return FALSE;\r
-\r
-       CFX_ByteTextBuf FdfBuffer;\r
-       FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);\r
-       delete pFDFDoc;\r
-       if (!bRet) return FALSE;\r
-\r
-       FX_LPBYTE pBuffer = FdfBuffer.GetBuffer();\r
-       FX_STRSIZE nBufSize = FdfBuffer.GetLength();\r
-       \r
-       if (bUrlEncoded)\r
-       {\r
-               if(!FDFToURLEncodedData(pBuffer, nBufSize))\r
-                       return FALSE;\r
-       }\r
-\r
-       pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)sDestination);\r
-       \r
-       if (bUrlEncoded && pBuffer)\r
-       {\r
-               FX_Free(pBuffer);\r
-               pBuffer = NULL; \r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_InterForm::ExportFormToFDFFile(const CFX_WideString& sFDFFileName)\r
-{\r
-       if (sFDFFileName.IsEmpty()) return FALSE;\r
-\r
-       ASSERT(m_pInterForm != NULL);\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());\r
-       if (!pFDF) return FALSE;\r
-\r
-       FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode());\r
-       delete pFDF;\r
-\r
-       return bRet;\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf)\r
-{\r
-\r
-       ASSERT(m_pInterForm != NULL);\r
-       ASSERT(m_pDocument != NULL);\r
-       \r
-       CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());\r
-       if (!pFDF) return FALSE;\r
-       \r
-       FX_BOOL bRet = pFDF->WriteBuf(textBuf);\r
-       delete pFDF;\r
-       \r
-       return bRet;\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::ExportFormToTxtFile(const CFX_WideString& sTxtFileName)\r
-{\r
-       ASSERT(m_pInterForm != NULL);\r
-\r
-       CFX_WideString sFieldNames;\r
-       CFX_WideString sFieldValues;\r
-\r
-       int nSize = m_pInterForm->CountFields();\r
-\r
-       if (nSize > 0)\r
-       {\r
-               for (int i=0; i<nSize; i++)\r
-               {\r
-                       CPDF_FormField* pField = m_pInterForm->GetField(i);\r
-                       ASSERT(pField != NULL);\r
-\r
-                       if (i != 0)\r
-                       {\r
-                               sFieldNames += L"\t";\r
-                               sFieldValues += L"\t";\r
-                       }\r
-                       sFieldNames += pField->GetFullName();\r
-                       sFieldValues += pField->GetValue();\r
-               }\r
-\r
-               return TRUE;\r
-       }\r
-\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_InterForm::ImportFormFromTxtFile(const CFX_WideString& sTxtFileName)\r
-{\r
-       ASSERT(m_pInterForm != NULL);\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action)\r
-{\r
-       ASSERT(action != NULL);\r
-\r
-       CPDF_Dictionary* pActionDict = action;\r
-\r
-       if (pActionDict->KeyExist("Fields"))\r
-       {\r
-               CPDF_ActionFields af = action.GetWidgets();\r
-               FX_DWORD dwFlags = action.GetFlags();\r
-               \r
-               CFX_PtrArray fieldObjects;\r
-               af.GetAllFields(fieldObjects);\r
-               CFX_PtrArray fields;\r
-               GetFieldFromObjects(fieldObjects, fields);\r
-               \r
-               ASSERT(m_pInterForm != NULL);\r
-\r
-               return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE);\r
-       }\r
-       else\r
-       {\r
-               ASSERT(m_pInterForm != NULL);\r
-               return m_pInterForm->ResetForm(TRUE);\r
-       }\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action)\r
-{\r
-       ASSERT(action != NULL);\r
-\r
-       CFX_WideString sFilePath = action.GetFilePath();\r
-       if (sFilePath.IsEmpty())\r
-               return FALSE;\r
-\r
-       if (!ImportFormFromFDFFile(sFilePath, TRUE))\r
-       {\r
-               return FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL        CPDFSDK_InterForm::ImportFormFromFDFFile(const CFX_WideString& csFDFFileName,\r
-                                                                                                FX_BOOL bNotify)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, CFX_PtrArray& fields)\r
-{\r
-       ASSERT(m_pInterForm != NULL);\r
-\r
-       int iCount = objects.GetSize();\r
-       for (int i = 0; i < iCount; i ++)\r
-       {\r
-               CPDF_Object* pObject = (CPDF_Object*)objects[i];\r
-               if (pObject == NULL) continue;\r
-               \r
-               int iType = pObject->GetType();\r
-               if (iType == PDFOBJ_STRING)\r
-               {\r
-                       CFX_WideString csName = pObject->GetUnicodeText();\r
-                       CPDF_FormField* pField = m_pInterForm->GetField(0, csName);\r
-                       if (pField != NULL)\r
-                               fields.Add(pField);\r
-               }\r
-               else if (iType == PDFOBJ_DICTIONARY)\r
-               {\r
-                       if (m_pInterForm->IsValidFormField(pObject))\r
-                               fields.Add(pObject);\r
-               }\r
-       }\r
-}\r
-\r
-/* ----------------------------- CPDF_FormNotify ----------------------------- */\r
-\r
-int    CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue)\r
-{\r
-       ASSERT(pField != NULL);\r
-\r
-       CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
-\r
-       int nType = pFormField->GetFieldType();\r
-       if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)\r
-       {\r
-               FX_BOOL bRC = TRUE;\r
-               OnKeyStrokeCommit(pFormField, csValue, bRC);\r
-               if (bRC) \r
-               {\r
-                       OnValidate(pFormField, csValue, bRC);\r
-                       if (bRC)\r
-                               return 1;\r
-                       else\r
-                               return -1;\r
-               }\r
-               else\r
-                       return -1;\r
-       }\r
-       else\r
-               return 0;\r
-}\r
-\r
-int    CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField)\r
-{\r
-       ASSERT(pField != NULL);\r
-\r
-       CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
-       int nType = pFormField->GetFieldType();\r
-\r
-       if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)\r
-       {\r
-               this->OnCalculate(pFormField);\r
-               FX_BOOL bFormated = FALSE;\r
-               CFX_WideString sValue = this->OnFormat(pFormField, 0, bFormated);\r
-               if (bFormated)\r
-                       this->ResetFieldAppearance(pFormField, sValue, TRUE);\r
-               else\r
-                       this->ResetFieldAppearance(pFormField, NULL, TRUE);\r
-               this->UpdateField(pFormField);\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-int    CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, CFX_WideString& csValue)\r
-{\r
-       ASSERT(pField != NULL);\r
-\r
-       CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
-\r
-       int nType = pFormField->GetFieldType();\r
-       if (nType == FIELDTYPE_LISTBOX)\r
-       {\r
-               FX_BOOL bRC = TRUE;\r
-               OnKeyStrokeCommit(pFormField, csValue, bRC);\r
-               if (bRC) \r
-               {\r
-                       OnValidate(pFormField, csValue, bRC);\r
-                       if (bRC)\r
-                               return 1;\r
-                       else\r
-                               return -1;\r
-               }\r
-               else\r
-                       return -1;\r
-       }\r
-       else\r
-               return 0;\r
-}\r
-\r
-int    CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField)\r
-{\r
-       ASSERT(pField != NULL);\r
-\r
-       CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
-       int nType = pFormField->GetFieldType();\r
-\r
-       if (nType == FIELDTYPE_LISTBOX)\r
-       {\r
-               this->OnCalculate(pFormField);\r
-               this->ResetFieldAppearance(pFormField, NULL, TRUE);\r
-               this->UpdateField(pFormField);\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-int    CPDFSDK_InterForm::AfterCheckedStatusChange(const CPDF_FormField* pField, const CFX_ByteArray& statusArray)\r
-{\r
-       ASSERT(pField != NULL);\r
-\r
-       CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
-       int nType = pFormField->GetFieldType();\r
-\r
-       if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON)\r
-       {\r
-               this->OnCalculate(pFormField);\r
-               //this->ResetFieldAppearance(pFormField, NULL);\r
-               this->UpdateField(pFormField);\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-int    CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm)\r
-{\r
-       return 0;\r
-}\r
-\r
-int    CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm)\r
-{\r
-       this->OnCalculate(NULL);\r
-\r
-       return 0;\r
-}\r
-\r
-int    CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm)\r
-{\r
-       return 0;\r
-}\r
-\r
-int    CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm)\r
-{\r
-       this->OnCalculate(NULL);\r
-\r
-       return 0;\r
-}\r
-\r
-FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType)\r
-{\r
-       if(nFieldType <1 || nFieldType > 6)\r
-               return FALSE;\r
-       return m_bNeedHightlight[nFieldType-1];\r
-}\r
-\r
-void CPDFSDK_InterForm::RemoveAllHighLight()\r
-{\r
-       memset((void*)m_bNeedHightlight, 0, 6*sizeof(FX_BOOL));\r
-}\r
-void   CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)\r
-{\r
-       if(nFieldType <0 || nFieldType > 6) return;\r
-       switch(nFieldType)\r
-       {\r
-       case 0:\r
-               {\r
-                       for(int i=0; i<6; i++)\r
-                       {\r
-                               m_aHighlightColor[i] = clr;\r
-                               m_bNeedHightlight[i] = TRUE;\r
-                       }\r
-                       break;\r
-               }\r
-       default:\r
-               {\r
-                       m_aHighlightColor[nFieldType-1] = clr;\r
-                       m_bNeedHightlight[nFieldType-1] = TRUE;\r
-                       break;\r
-               }\r
-       }\r
-       \r
-}\r
-\r
-FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType)\r
-{\r
-       if(nFieldType <0 || nFieldType >6) return FXSYS_RGB(255,255,255);\r
-       if(nFieldType == 0)\r
-               return m_aHighlightColor[0];\r
-       else\r
-               return m_aHighlightColor[nFieldType-1];\r
-}\r
-\r
-/* ------------------------- CBA_AnnotIterator ------------------------- */\r
-\r
-CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, const CFX_ByteString& sType, const CFX_ByteString& sSubType)\r
-       :m_pPageView(pPageView),\r
-       m_sType(sType),\r
-       m_sSubType(sSubType),\r
-       m_nTabs(BAI_STRUCTURE)\r
-{\r
-       ASSERT(m_pPageView != NULL);\r
-\r
-       CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();\r
-       ASSERT(pPDFPage != NULL);\r
-       ASSERT(pPDFPage->m_pFormDict != NULL);\r
-\r
-       CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs");\r
-\r
-       if (sTabs == "R")\r
-       {\r
-               m_nTabs = BAI_ROW;\r
-       }\r
-       else if (sTabs == "C")\r
-       {\r
-               m_nTabs = BAI_COLUMN;\r
-       }\r
-       else\r
-       {\r
-               m_nTabs = BAI_STRUCTURE;\r
-       }\r
-\r
-       GenerateResults();\r
-}\r
-\r
-CBA_AnnotIterator::~CBA_AnnotIterator()\r
-{\r
-       m_Annots.RemoveAll();\r
-}\r
-\r
-CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot()\r
-{\r
-       if (m_Annots.GetSize() > 0)\r
-               return m_Annots[0];\r
-       \r
-       return NULL;\r
-}\r
-\r
-CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot()\r
-{\r
-       if (m_Annots.GetSize() > 0)\r
-               return m_Annots[m_Annots.GetSize() - 1];\r
-\r
-       return NULL;\r
-}\r
-\r
-CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot)\r
-{\r
-       for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)\r
-       {\r
-               if (m_Annots[i] == pAnnot)\r
-               {\r
-                       if (i+1 < sz)\r
-                               return m_Annots[i+1];\r
-                       else\r
-                               return m_Annots[0];\r
-               }\r
-       }\r
-\r
-       return NULL;\r
-}\r
-\r
-CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot)\r
-{\r
-       for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)\r
-       {\r
-               if (m_Annots[i] == pAnnot)\r
-               {\r
-                       if (i-1 >= 0)\r
-                               return m_Annots[i-1];\r
-                       else\r
-                               return m_Annots[sz-1];\r
-               }\r
-       }\r
-\r
-       return NULL;\r
-}\r
-\r
-int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)\r
-{\r
-       ASSERT(p1 != NULL);\r
-       ASSERT(p2 != NULL);\r
-\r
-       CPDF_Rect rcAnnot1 = GetAnnotRect(p1);\r
-       CPDF_Rect rcAnnot2 = GetAnnotRect(p2);\r
-\r
-       if (rcAnnot1.left < rcAnnot2.left)\r
-               return -1;\r
-       if (rcAnnot1.left > rcAnnot2.left)\r
-               return 1;\r
-       return 0;\r
-}\r
-\r
-\r
-int CBA_AnnotIterator::CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)\r
-{\r
-       ASSERT(p1 != NULL);\r
-       ASSERT(p2 != NULL);\r
-\r
-       CPDF_Rect rcAnnot1 = GetAnnotRect(p1);\r
-       CPDF_Rect rcAnnot2 = GetAnnotRect(p2);\r
-\r
-       if (rcAnnot1.top < rcAnnot2.top)\r
-               return -1;\r
-       if (rcAnnot1.top > rcAnnot2.top)\r
-               return 1;\r
-       return 0;\r
-}\r
-\r
-void CBA_AnnotIterator::GenerateResults()\r
-{\r
-       ASSERT(m_pPageView != NULL);\r
-\r
-       switch (m_nTabs)\r
-       {\r
-       case BAI_STRUCTURE:\r
-               {\r
-                       for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)\r
-                       {\r
-                               CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);\r
-                               ASSERT(pAnnot != NULL);\r
-\r
-                               if (pAnnot->GetType() == m_sType \r
-                                       && pAnnot->GetSubType() == m_sSubType)\r
-                                       m_Annots.Add(pAnnot);\r
-                       }\r
-               }\r
-               break;\r
-       case BAI_ROW:\r
-               {\r
-                       CPDFSDK_SortAnnots sa;\r
-\r
-                       {\r
-                               \r
-                               for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)\r
-                               {\r
-                                       CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);\r
-                                       ASSERT(pAnnot != NULL);\r
-\r
-                                       if (pAnnot->GetType() == m_sType \r
-                                               && pAnnot->GetSubType() == m_sSubType)\r
-                                               sa.Add(pAnnot);\r
-                               }\r
-                       }\r
-\r
-                       if (sa.GetSize() > 0)\r
-                       {\r
-                               sa.Sort(CBA_AnnotIterator::CompareByLeft);\r
-                       }\r
-\r
-                       while (sa.GetSize() > 0)\r
-                       {\r
-                               int nLeftTopIndex = -1;\r
-\r
-                               {\r
-                                       FX_FLOAT fTop = 0.0f;\r
-\r
-                                       for (int i=sa.GetSize()-1; i>=0; i--)\r
-                                       {\r
-                                               CPDFSDK_Annot* pAnnot = sa.GetAt(i);\r
-                                               ASSERT(pAnnot != NULL);\r
-\r
-                                               CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);\r
-\r
-                                               if (rcAnnot.top > fTop)\r
-                                               {\r
-                                                       nLeftTopIndex = i;\r
-                                                       fTop = rcAnnot.top;\r
-                                               }\r
-                                       }\r
-                               }\r
-\r
-                               if (nLeftTopIndex >= 0)\r
-                               {\r
-                                       CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);\r
-                                       ASSERT(pLeftTopAnnot != NULL);\r
-\r
-                                       CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);\r
-                                       \r
-                                       m_Annots.Add(pLeftTopAnnot);\r
-                                       sa.RemoveAt(nLeftTopIndex);\r
-\r
-                                       CFX_ArrayTemplate<int> aSelect;\r
-\r
-                                       {\r
-                                               for (int i=0,sz=sa.GetSize(); i<sz; i++)\r
-                                               {\r
-                                                       CPDFSDK_Annot* pAnnot = sa.GetAt(i);\r
-                                                       ASSERT(pAnnot != NULL);\r
-\r
-                                                       CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);\r
-\r
-                                                       FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;\r
-\r
-                                                       if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)\r
-                                                               aSelect.Add(i);\r
-                                               }\r
-                                       }\r
-\r
-                                       {\r
-                                               for (int i=0,sz=aSelect.GetSize(); i<sz; i++)\r
-                                               {\r
-                                                       m_Annots.Add(sa[aSelect[i]]);\r
-                                               }\r
-                                       }\r
-\r
-                                       {\r
-                                               for (int i=aSelect.GetSize()-1; i>=0; i--)\r
-                                               {\r
-                                                       sa.RemoveAt(aSelect[i]);\r
-                                               }\r
-                                       }\r
-\r
-                                       aSelect.RemoveAll();\r
-                               }\r
-                       }\r
-                       sa.RemoveAll();\r
-               }\r
-               break;\r
-       case BAI_COLUMN:\r
-               {\r
-                       CPDFSDK_SortAnnots sa;\r
-\r
-                       {\r
-                               for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)\r
-                               {\r
-                                       CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);\r
-                                       ASSERT(pAnnot != NULL);\r
-\r
-                                       if (pAnnot->GetType() == m_sType \r
-                                               && pAnnot->GetSubType() == m_sSubType)\r
-                                               sa.Add(pAnnot);\r
-                               }\r
-                       }\r
-\r
-                       if (sa.GetSize() > 0)\r
-                       {\r
-                               sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE);\r
-                       }\r
-\r
-                       while (sa.GetSize() > 0)\r
-                       {\r
-                               int nLeftTopIndex = -1;\r
-\r
-                               {\r
-                                       FX_FLOAT fLeft = -1.0f;\r
-\r
-                                       for (int i=sa.GetSize()-1; i>=0; i--)\r
-                                       {\r
-                                               CPDFSDK_Annot* pAnnot = sa.GetAt(i);\r
-                                               ASSERT(pAnnot != NULL);\r
-\r
-                                               CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);\r
-\r
-                                               if (fLeft < 0)\r
-                                               {\r
-                                                       nLeftTopIndex = 0;\r
-                                                       fLeft = rcAnnot.left;\r
-                                               }\r
-                                               else if (rcAnnot.left < fLeft)\r
-                                               {\r
-                                                       nLeftTopIndex = i;\r
-                                                       fLeft = rcAnnot.left;\r
-                                               }\r
-                                       }\r
-                               }\r
-\r
-                               if (nLeftTopIndex >= 0)\r
-                               {\r
-                                       CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);\r
-                                       ASSERT(pLeftTopAnnot != NULL);\r
-\r
-                                       CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);\r
-                                       \r
-                                       m_Annots.Add(pLeftTopAnnot);\r
-                                       sa.RemoveAt(nLeftTopIndex);\r
-\r
-                                       CFX_ArrayTemplate<int> aSelect;\r
-\r
-                                       {\r
-                                               for (int i=0,sz=sa.GetSize(); i<sz; i++)\r
-                                               {\r
-                                                       CPDFSDK_Annot* pAnnot = sa.GetAt(i);\r
-                                                       ASSERT(pAnnot != NULL);\r
-\r
-                                                       CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);\r
-\r
-                                                       FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;\r
-\r
-                                                       if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)\r
-                                                               aSelect.Add(i);\r
-                                               }\r
-                                       }\r
-\r
-                                       {\r
-                                               for (int i=0,sz=aSelect.GetSize(); i<sz; i++)\r
-                                               {\r
-                                                       m_Annots.Add(sa[aSelect[i]]);\r
-                                               }\r
-                                       }\r
-\r
-                                       {\r
-                                               for (int i=aSelect.GetSize()-1; i>=0; i--)\r
-                                               {\r
-                                                       sa.RemoveAt(aSelect[i]);\r
-                                               }\r
-                                       }\r
-\r
-                                       aSelect.RemoveAll();\r
-                               }\r
-                       }\r
-                       sa.RemoveAll();\r
-               }\r
-               break;\r
-       }\r
-}\r
-\r
-CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot)\r
-{\r
-       ASSERT(pAnnot != NULL);\r
-\r
-       CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();\r
-       ASSERT(pPDFAnnot != NULL);\r
-\r
-       CPDF_Rect rcAnnot;\r
-       pPDFAnnot->GetRect(rcAnnot);\r
-\r
-       return rcAnnot;\r
-}\r
-\r
+// 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 "../../third_party/base/nonstd_unique_ptr.h"
+#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) {
+  CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
+  if (!pAP)
+    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)
+    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 (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
+        return pSubDict->GetStream(GetAppState()) != NULL;
+      }
+      return FALSE;
+  }
+  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->GetAnnotDict());
+  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());
+}
+
+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 = 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();
+  return pFormField->GetSelectedIndex(nIndex);
+}
+
+CFX_WideString CPDFSDK_Widget::GetValue() const {
+  CPDF_FormField* pFormField = GetFormField();
+  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();
+  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(const FX_WCHAR* 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(FX_BOOL& bFormated) {
+  CPDF_FormField* pFormField = GetFormField();
+  ASSERT(pFormField != NULL);
+  return m_pInterForm->OnFormat(pFormField, 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 &&
+      !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
+    CFX_PathData pathData;
+
+    CPDF_Rect rcAnnot = 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)) {
+    CPDF_Rect rc = GetRect();
+    FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
+    uint8_t 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);
+    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();
+
+  int32_t 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();
+  int32_t 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();
+
+  CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
+  ASSERT(pDoc != NULL);
+  CPDFDoc_Environment* pEnv = pDoc->GetEnv();
+
+  CBA_FontMap FontMap(this, pEnv->GetSysHandler());
+  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();
+  int32_t 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]);
+  }
+
+  int32_t 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();
+  int32_t 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]);
+  }
+
+  int32_t 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(const FX_WCHAR* 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);
+
+    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 = GetFontSize();
+    if (IsFloatZero(fFontSize))
+      pEdit->SetAutoFontSize(TRUE);
+    else
+      pEdit->SetFontSize(fFontSize);
+
+    pEdit->Initialize();
+
+    if (sValue)
+      pEdit->SetText(sValue);
+    else {
+      int32_t nCurSel = pField->GetSelectedIndex(0);
+
+      if (nCurSel < 0)
+        pEdit->SetText(pField->GetValue().c_str());
+      else
+        pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str());
+    }
+
+    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);
+
+    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;
+
+    int32_t nTop = pField->GetTopVisibleIndex();
+    int32_t nCount = pField->CountOptions();
+    int32_t nSelCount = pField->CountSelectedItems();
+
+    for (int32_t i = nTop; i < nCount; i++) {
+      FX_BOOL bSelected = FALSE;
+      for (int32_t j = 0; j < nSelCount; j++) {
+        if (pField->GetSelectedIndex(j) == i) {
+          bSelected = TRUE;
+          break;
+        }
+      }
+
+      pEdit->SetText(pField->GetOptionLabel(i).c_str());
+
+      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(const FX_WCHAR* 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);
+
+    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 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(pField->GetValue().c_str());
+
+    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 (int32_t 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 (int32_t 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();
+  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);
+  }
+  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();
+  int32_t 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()) {
+    int32_t 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);
+
+  int32_t 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);
+
+  int32_t 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);
+
+  CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
+  ASSERT(pDoc != NULL);
+
+  CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->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 = new CPDF_Dictionary();
+    pStreamDict->SetAt("Resources", pStreamResList);
+  }
+
+  if (pStreamResList) {
+    CPDF_Dictionary* pXObject = new CPDF_Dictionary;
+    pXObject->SetAtReference(sImageAlias, pDoc, pImage);
+    pStreamResList->SetAt("XObject", pXObject);
+  }
+}
+
+void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
+  if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->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();
+    CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+    CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
+    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 = GetFormField();
+      if (CPDF_AAction aa = pField->GetAdditionalAction())
+        return aa.GetAction(eAAT);
+
+      return CPDFSDK_Annot::GetAAction(eAAT);
+    }
+    default:
+      break;
+  }
+
+  return CPDF_Action();
+}
+
+CFX_WideString CPDFSDK_Widget::GetAlternateName() const {
+  CPDF_FormField* pFormField = GetFormField();
+  ASSERT(pFormField != NULL);
+
+  return pFormField->GetAlternateName();
+}
+
+int32_t CPDFSDK_Widget::GetAppearanceAge() const {
+  return m_nAppAge;
+}
+
+int32_t 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() {
+  delete m_pInterForm;
+  m_pInterForm = nullptr;
+  m_Map.clear();
+}
+
+FX_BOOL CPDFSDK_InterForm::HighlightWidgets() {
+  return FALSE;
+}
+
+CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget,
+                                              FX_BOOL bNext) const {
+  nonstd::unique_ptr<CBA_AnnotIterator> pIterator(
+      new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", ""));
+
+  if (bNext) {
+    return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);
+  }
+  return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
+}
+
+CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const {
+  if (!pControl || !m_pInterForm)
+    return nullptr;
+
+  CPDFSDK_Widget* pWidget = nullptr;
+  const auto it = m_Map.find(pControl);
+  if (it != m_Map.end())
+    pWidget = it->second;
+
+  if (pWidget)
+    return pWidget;
+
+  CPDF_Dictionary* pControlDict = pControl->GetWidget();
+  CPDF_Document* pDocument = m_pDocument->GetDocument();
+  CPDFSDK_PageView* pPage = nullptr;
+
+  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 nullptr;
+  return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
+}
+
+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[pControl] = pWidget;
+}
+
+void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) {
+  m_Map.erase(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.c_str())) {
+    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((uint8_t*)csStream.c_str(), 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 (IsCalculateEnabled()) {
+    IJS_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)) {
+        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()) {
+                IJS_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,
+                                           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;
+  }
+
+  IJS_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;
+
+        IJS_Context* pContext = pRuntime->NewContext();
+        ASSERT(pContext != NULL);
+
+        pContext->OnField_Format(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,
+                                             const FX_WCHAR* 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);
+
+  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(m_pInterForm != NULL);
+  CFX_WideString sDestination = action.GetFilePath();
+  if (sDestination.IsEmpty())
+    return FALSE;
+
+  CPDF_Dictionary* pActionDict = action.GetDict();
+  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);
+    }
+  }
+  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);
+
+  uint8_t* pBuffer = textBuf.GetBuffer();
+  FX_STRSIZE nBufSize = textBuf.GetLength();
+
+  if (bUrlEncoded) {
+    if (!FDFToURLEncodedData(pBuffer, nBufSize))
+      return FALSE;
+  }
+
+  pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str());
+
+  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(uint8_t*& 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(uint8_t, nBufSize);
+    FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
+  }
+  return TRUE;
+}
+
+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);
+  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;
+
+  uint8_t* pBuffer = FdfBuffer.GetBuffer();
+  FX_STRSIZE nBufSize = FdfBuffer.GetLength();
+
+  if (bUrlEncoded) {
+    if (!FDFToURLEncodedData(pBuffer, nBufSize))
+      return FALSE;
+  }
+
+  pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str());
+
+  if (bUrlEncoded) {
+    FX_Free(pBuffer);
+    pBuffer = NULL;
+  }
+
+  return TRUE;
+}
+
+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::DoAction_ResetForm(const CPDF_Action& action) {
+  ASSERT(action);
+
+  CPDF_Dictionary* pActionDict = action.GetDict();
+  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);
+    return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE);
+  }
+
+  return m_pInterForm->ResetForm(TRUE);
+}
+
+FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) {
+  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) {
+  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);
+      return bRC ? 1 : -1;
+    }
+    return -1;
+  }
+  return 0;
+}
+
+int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) {
+  CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+  int nType = pFormField->GetFieldType();
+  if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
+    OnCalculate(pFormField);
+    FX_BOOL bFormated = FALSE;
+    CFX_WideString sValue = OnFormat(pFormField, bFormated);
+    if (bFormated)
+      ResetFieldAppearance(pFormField, sValue.c_str(), TRUE);
+    else
+      ResetFieldAppearance(pFormField, NULL, TRUE);
+    UpdateField(pFormField);
+  }
+  return 0;
+}
+
+int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField,
+                                             CFX_WideString& csValue) {
+  CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+  if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+    return 0;
+
+  FX_BOOL bRC = TRUE;
+  OnKeyStrokeCommit(pFormField, csValue, bRC);
+  if (!bRC)
+    return -1;
+
+  OnValidate(pFormField, csValue, bRC);
+  if (!bRC)
+    return -1;
+
+  return 1;
+}
+
+int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField) {
+  CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+  if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX) {
+    OnCalculate(pFormField);
+    ResetFieldAppearance(pFormField, NULL, TRUE);
+    UpdateField(pFormField);
+  }
+  return 0;
+}
+
+int CPDFSDK_InterForm::AfterCheckedStatusChange(
+    const CPDF_FormField* pField,
+    const CFX_ByteArray& statusArray) {
+  CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+  int nType = pFormField->GetFieldType();
+  if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) {
+    OnCalculate(pFormField);
+    UpdateField(pFormField);
+  }
+  return 0;
+}
+
+int CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm) {
+  return 0;
+}
+
+int CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm) {
+  OnCalculate(nullptr);
+  return 0;
+}
+
+int CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm) {
+  return 0;
+}
+
+int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm) {
+  OnCalculate(nullptr);
+  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];
+  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)
+      return (i + 1 < sz) ? m_Annots[i + 1] : 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)
+      return (i - 1 >= 0) ? m_Annots[i - 1] : m_Annots[sz - 1];
+  }
+  return NULL;
+}
+
+int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
+  ASSERT(p1);
+  ASSERT(p2);
+
+  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;
+}