Make CFX_FontMgr member variables private. (try 2)
[pdfium.git] / fpdfsdk / src / fsdk_baseform.cpp
index bc041fd..b4aa822 100644 (file)
@@ -38,7 +38,7 @@ CPDFSDK_Widget::~CPDFSDK_Widget() {}
 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
     CPDF_Annot::AppearanceMode mode) {
   CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
-  if (pAP == NULL)
+  if (!pAP)
     return FALSE;
 
   // Choose the right sub-ap
@@ -52,7 +52,7 @@ FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
 
   // Get the AP stream or subdirectory
   CPDF_Object* psub = pAP->GetElementValue(ap_entry);
-  if (psub == NULL)
+  if (!psub)
     return FALSE;
 
   int nFieldType = GetFieldType();
@@ -65,13 +65,11 @@ FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
       return psub->GetType() == PDFOBJ_STREAM;
     case FIELDTYPE_CHECKBOX:
     case FIELDTYPE_RADIOBUTTON:
-      if (psub->GetType() == PDFOBJ_DICTIONARY) {
-        CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;
+      if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
         return pSubDict->GetStream(GetAppState()) != NULL;
       }
       return FALSE;
   }
-
   return TRUE;
 }
 
@@ -186,15 +184,11 @@ FX_FLOAT CPDFSDK_Widget::GetFontSize() const {
 
 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
   CPDF_FormField* pFormField = GetFormField();
-  ASSERT(pFormField != NULL);
-
   return pFormField->GetSelectedIndex(nIndex);
 }
 
 CFX_WideString CPDFSDK_Widget::GetValue() const {
   CPDF_FormField* pFormField = GetFormField();
-  ASSERT(pFormField != NULL);
-
   return pFormField->GetValue();
 }
 
@@ -221,8 +215,6 @@ int CPDFSDK_Widget::CountOptions() const {
 
 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
   CPDF_FormField* pFormField = GetFormField();
-  ASSERT(pFormField != NULL);
-
   return pFormField->IsItemSelected(nIndex);
 }
 
@@ -396,8 +388,6 @@ void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
 
   int nFieldType = GetFieldType();
   if (m_pInterForm->IsNeedHighLight(nFieldType)) {
-    //          if (nFieldType != FIELDTYPE_PUSHBUTTON)
-    //          {
     CPDF_Rect rc = GetRect();
     FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
     uint8_t alpha = m_pInterForm->GetHighlightAlpha();
@@ -411,10 +401,6 @@ void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
     pPageView->GetCurrentMatrix(page2device);
     page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom),
                           rcDevice.left, rcDevice.bottom);
-    //          pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.left,
-    //          rc.bottom, &rcDevice.left, &rcDevice.bottom);
-    //          pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.right,
-    //          rc.top, &rcDevice.right, &rcDevice.top);
     page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top),
                           rcDevice.right, rcDevice.top);
 
@@ -424,7 +410,6 @@ void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
     FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right,
                   (int)rcDevice.bottom);
     pDevice->FillRect(&rcDev, argb);
-    /*      }*/
   }
 }
 
@@ -573,10 +558,7 @@ void CPDFSDK_Widget::ResetAppearance_PushButton() {
   ASSERT(pDoc != NULL);
   CPDFDoc_Environment* pEnv = pDoc->GetEnv();
 
-  CBA_FontMap FontMap(
-      this,
-      pEnv->GetSysHandler());  //,
-                               //ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
+  CBA_FontMap FontMap(this, pEnv->GetSysHandler());
   FontMap.Initial();
 
   FontMap.SetAPType("N");
@@ -1136,10 +1118,7 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) {
     ASSERT(pDoc != NULL);
     CPDFDoc_Environment* pEnv = pDoc->GetEnv();
 
-    CBA_FontMap FontMap(
-        this,
-        pEnv->GetSysHandler());  //,
-                                 //ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
+    CBA_FontMap FontMap(this, pEnv->GetSysHandler());
     FontMap.Initial();
     pEdit->SetFontMap(&FontMap);
 
@@ -1431,8 +1410,7 @@ void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
                                           CPDF_Stream* pImage) {
   ASSERT(pImage != NULL);
 
-  CPDF_Document* pDoc =
-      m_pPageView->GetPDFDocument();  // pDocument->GetDocument();
+  CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
   ASSERT(pDoc != NULL);
 
   CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
@@ -1478,19 +1456,11 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
 
   if (action && action.GetType() != CPDF_Action::Unknown) {
     CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
-    ASSERT(pDocument != NULL);
-
     CPDFDoc_Environment* pEnv = pDocument->GetEnv();
-    ASSERT(pEnv != NULL);
-
-    CPDFSDK_ActionHandler* pActionHandler =
-        pEnv->GetActionHander(); /*(CPDFSDK_ActionHandler*)pApp->GetActionHandler();*/
-    ASSERT(pActionHandler != NULL);
-
+    CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
     return pActionHandler->DoAction_Field(action, type, pDocument,
                                           GetFormField(), data);
   }
-
   return FALSE;
 }
 
@@ -1770,7 +1740,7 @@ void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
   m_bBusy = TRUE;
 
   if (IsCalculateEnabled()) {
-    IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
+    IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
     ASSERT(pRuntime != NULL);
 
     pRuntime->SetReaderDocument(m_pDocument);
@@ -1779,7 +1749,6 @@ void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
     for (int i = 0; i < nSize; i++) {
       if (CPDF_FormField* pField =
               m_pInterForm->GetFieldInCalculationOrder(i)) {
-        //          ASSERT(pField != NULL);
         int nType = pField->GetFieldType();
         if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
           CPDF_AAction aAction = pField->GetAdditionalAction();
@@ -1788,7 +1757,7 @@ void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
             if (action) {
               CFX_WideString csJS = action.GetJavaScript();
               if (!csJS.IsEmpty()) {
-                IFXJS_Context* pContext = pRuntime->NewContext();
+                IJS_Context* pContext = pRuntime->NewContext();
                 ASSERT(pContext != NULL);
 
                 CFX_WideString sOldValue = pField->GetValue();
@@ -1797,7 +1766,7 @@ void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
                 pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
 
                 CFX_WideString sInfo;
-                FX_BOOL bRet = pContext->RunScript(csJS, sInfo);
+                FX_BOOL bRet = pContext->RunScript(csJS, &sInfo);
                 pRuntime->ReleaseContext(pContext);
 
                 if (bRet) {
@@ -1830,7 +1799,7 @@ CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
     return sValue;
   }
 
-  IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
+  IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
   ASSERT(pRuntime != NULL);
 
   pRuntime->SetReaderDocument(m_pDocument);
@@ -1853,13 +1822,13 @@ CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
       if (!script.IsEmpty()) {
         CFX_WideString Value = sValue;
 
-        IFXJS_Context* pContext = pRuntime->NewContext();
+        IJS_Context* pContext = pRuntime->NewContext();
         ASSERT(pContext != NULL);
 
         pContext->OnField_Format(pFormField, Value, TRUE);
 
         CFX_WideString sInfo;
-        FX_BOOL bRet = pContext->RunScript(script, sInfo);
+        FX_BOOL bRet = pContext->RunScript(script, &sInfo);
         pRuntime->ReleaseContext(pContext);
 
         if (bRet) {
@@ -2157,7 +2126,7 @@ FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,
       m_pDocument->GetPath(), (CFX_PtrArray&)fields, bIncludeOrExclude);
   if (!pFDF)
     return FALSE;
-  FX_BOOL bRet = pFDF->WriteBuf(textBuf);  // = FALSE;//
+  FX_BOOL bRet = pFDF->WriteBuf(textBuf);
   delete pFDF;
 
   return bRet;
@@ -2203,7 +2172,7 @@ FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
 
   pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str());
 
-  if (bUrlEncoded && pBuffer) {
+  if (bUrlEncoded) {
     FX_Free(pBuffer);
     pBuffer = NULL;
   }