Replace CFX_PtryArray with typesafe CFX_ArrayTemplate, Part 7

Remaining uses are all in fxbarcode/.

Review-Url: https://codereview.chromium.org/1937453002
diff --git a/xfa/fgas/crt/fgas_utils.cpp b/xfa/fgas/crt/fgas_utils.cpp
index 01792b8..4f15fc4 100644
--- a/xfa/fgas/crt/fgas_utils.cpp
+++ b/xfa/fgas/crt/fgas_utils.cpp
@@ -141,9 +141,9 @@
     : m_iChunkSize(iChunkSize),
       m_iBlockSize(iBlockSize),
       m_iChunkCount(0),
-      m_iBlockCount(0) {
+      m_iBlockCount(0),
+      m_pData(new CFX_ArrayTemplate<void*>()) {
   ASSERT(m_iChunkSize > 0 && m_iBlockSize > 0);
-  m_pData = new CFX_PtrArray;
   m_pData->SetSize(16);
 }
 CFX_BaseMassArrayImp::~CFX_BaseMassArrayImp() {
@@ -335,7 +335,7 @@
   int32_t iBlockSize;
   int32_t iChunkSize;
   int32_t iChunkCount;
-  CFX_PtrArray ChunkBuffer;
+  CFX_ArrayTemplate<uint8_t*> ChunkBuffer;
 };
 
 CFX_BaseDiscreteArray::CFX_BaseDiscreteArray(int32_t iChunkSize,
@@ -360,7 +360,7 @@
   uint8_t* pChunk = NULL;
   int32_t iChunk = index / iChunkSize;
   if (iChunk < iChunkCount) {
-    pChunk = (uint8_t*)pData->ChunkBuffer.GetAt(iChunk);
+    pChunk = pData->ChunkBuffer.GetAt(iChunk);
   }
   if (!pChunk) {
     pChunk = FX_Alloc2D(uint8_t, iChunkSize, pData->iBlockSize);
@@ -373,30 +373,26 @@
   return pChunk + (index % iChunkSize) * pData->iBlockSize;
 }
 uint8_t* CFX_BaseDiscreteArray::GetAt(int32_t index) const {
-  ASSERT(index > -1);
+  ASSERT(index >= 0);
   FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData;
   int32_t iChunkSize = pData->iChunkSize;
   int32_t iChunk = index / iChunkSize;
-  if (iChunk >= pData->iChunkCount) {
-    return NULL;
-  }
-  uint8_t* pChunk = (uint8_t*)pData->ChunkBuffer.GetAt(iChunk);
-  if (pChunk == NULL) {
-    return NULL;
-  }
+  if (iChunk >= pData->iChunkCount)
+    return nullptr;
+
+  uint8_t* pChunk = pData->ChunkBuffer.GetAt(iChunk);
+  if (!pChunk)
+    return nullptr;
+
   return pChunk + (index % iChunkSize) * pData->iBlockSize;
 }
 void CFX_BaseDiscreteArray::RemoveAll() {
   FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData;
-  CFX_PtrArray& ChunkBuffer = pData->ChunkBuffer;
+  CFX_ArrayTemplate<uint8_t*>& ChunkBuffer = pData->ChunkBuffer;
   int32_t& iChunkCount = pData->iChunkCount;
-  for (int32_t i = 0; i < iChunkCount; i++) {
-    void* p = ChunkBuffer.GetAt(i);
-    if (p == NULL) {
-      continue;
-    }
-    FX_Free(p);
-  }
+  for (int32_t i = 0; i < iChunkCount; i++)
+    FX_Free(ChunkBuffer.GetAt(i));
+
   ChunkBuffer.RemoveAll();
   iChunkCount = 0;
 }
diff --git a/xfa/fgas/crt/fgas_utils.h b/xfa/fgas/crt/fgas_utils.h
index ebbcf4b..ab94f6e 100644
--- a/xfa/fgas/crt/fgas_utils.h
+++ b/xfa/fgas/crt/fgas_utils.h
@@ -202,11 +202,12 @@
                int32_t iCount = -1);
   int32_t RemoveLast(int32_t iCount = -1);
   void RemoveAll(FX_BOOL bLeaveMemory = FALSE);
+
   int32_t m_iChunkSize;
   int32_t m_iBlockSize;
   int32_t m_iChunkCount;
   int32_t m_iBlockCount;
-  CFX_PtrArray* m_pData;
+  CFX_ArrayTemplate<void*>* m_pData;
 
  protected:
   void Append(int32_t iDstStart,
diff --git a/xfa/fwl/basewidget/fwl_checkboximp.cpp b/xfa/fwl/basewidget/fwl_checkboximp.cpp
index 76d5b8f..f11a917 100644
--- a/xfa/fwl/basewidget/fwl_checkboximp.cpp
+++ b/xfa/fwl/basewidget/fwl_checkboximp.cpp
@@ -361,7 +361,7 @@
       CFWL_WidgetMgr* pWidgetMgr =
           static_cast<CFWL_WidgetMgr*>(FWL_GetWidgetMgr());
       if (!pWidgetMgr->IsFormDisabled()) {
-        CFX_PtrArray radioarr;
+        CFX_ArrayTemplate<IFWL_Widget*> radioarr;
         pWidgetMgr->GetSameGroupRadioButton(m_pInterface, radioarr);
         IFWL_CheckBox* pCheckBox = NULL;
         int32_t iCount = radioarr.GetSize();
diff --git a/xfa/fwl/core/fwl_formimp.cpp b/xfa/fwl/core/fwl_formimp.cpp
index 2fd85a8..bbec673 100644
--- a/xfa/fwl/core/fwl_formimp.cpp
+++ b/xfa/fwl/core/fwl_formimp.cpp
@@ -526,32 +526,32 @@
   return NULL;
 }
 CFWL_SysBtn* CFWL_FormImp::GetSysBtnByIndex(int32_t nIndex) {
-  if (nIndex < 0) {
-    return NULL;
-  }
-  CFX_PtrArray arrBtn;
-  if (m_pMinBox) {
+  if (nIndex < 0)
+    return nullptr;
+
+  CFX_ArrayTemplate<CFWL_SysBtn*> arrBtn;
+  if (m_pMinBox)
     arrBtn.Add(m_pMinBox);
-  }
-  if (m_pMaxBox) {
+
+  if (m_pMaxBox)
     arrBtn.Add(m_pMaxBox);
-  }
-  if (m_pCloseBox) {
+
+  if (m_pCloseBox)
     arrBtn.Add(m_pCloseBox);
-  }
-  return static_cast<CFWL_SysBtn*>(arrBtn[nIndex]);
+
+  return arrBtn[nIndex];
 }
 int32_t CFWL_FormImp::GetSysBtnIndex(CFWL_SysBtn* pBtn) {
-  CFX_PtrArray arrBtn;
-  if (m_pMinBox) {
+  CFX_ArrayTemplate<CFWL_SysBtn*> arrBtn;
+  if (m_pMinBox)
     arrBtn.Add(m_pMinBox);
-  }
-  if (m_pMaxBox) {
+
+  if (m_pMaxBox)
     arrBtn.Add(m_pMaxBox);
-  }
-  if (m_pCloseBox) {
+
+  if (m_pCloseBox)
     arrBtn.Add(m_pCloseBox);
-  }
+
   return arrBtn.Find(pBtn);
 }
 FX_FLOAT CFWL_FormImp::GetCaptionHeight() {
diff --git a/xfa/fwl/core/fwl_widgetimp.cpp b/xfa/fwl/core/fwl_widgetimp.cpp
index c9d91c4..38516c6 100644
--- a/xfa/fwl/core/fwl_widgetimp.cpp
+++ b/xfa/fwl/core/fwl_widgetimp.cpp
@@ -473,7 +473,7 @@
     return FWL_ERR_Indefinite;
   if (bGlobal) {
     IFWL_Widget* parent = GetParent();
-    CFX_PtrArray parents;
+    CFX_ArrayTemplate<IFWL_Widget*> parents;
     while (parent) {
       parents.Add(parent);
       parent = parent->GetParent();
@@ -483,7 +483,7 @@
     CFX_RectF rect;
     int32_t count = parents.GetSize();
     for (int32_t i = count - 2; i >= 0; i--) {
-      parent = static_cast<IFWL_Widget*>(parents.GetAt(i));
+      parent = parents.GetAt(i);
       parent->GetMatrix(ctmOnParent, FALSE);
       parent->GetWidgetRect(rect);
       matrix.Concat(ctmOnParent, TRUE);
diff --git a/xfa/fwl/core/fwl_widgetmgrimp.cpp b/xfa/fwl/core/fwl_widgetmgrimp.cpp
index 0ce452e..02b6386 100644
--- a/xfa/fwl/core/fwl_widgetmgrimp.cpp
+++ b/xfa/fwl/core/fwl_widgetmgrimp.cpp
@@ -564,8 +564,9 @@
   }
   return GetSiblingRadioButton(pNext, TRUE);
 }
-void CFWL_WidgetMgr::GetSameGroupRadioButton(IFWL_Widget* pRadioButton,
-                                             CFX_PtrArray& group) {
+void CFWL_WidgetMgr::GetSameGroupRadioButton(
+    IFWL_Widget* pRadioButton,
+    CFX_ArrayTemplate<IFWL_Widget*>& group) {
   IFWL_Widget* pFirst = GetWidget(pRadioButton, FWL_WGTRELATION_FirstSibling);
   if (!pFirst) {
     pFirst = pRadioButton;
diff --git a/xfa/fwl/core/fwl_widgetmgrimp.h b/xfa/fwl/core/fwl_widgetmgrimp.h
index 528ecdb..0b4e2bf 100644
--- a/xfa/fwl/core/fwl_widgetmgrimp.h
+++ b/xfa/fwl/core/fwl_widgetmgrimp.h
@@ -112,7 +112,8 @@
   int32_t CountRadioButtonGroup(IFWL_Widget* pFirst);
   IFWL_Widget* GetSiblingRadioButton(IFWL_Widget* pWidget, FX_BOOL bNext);
   IFWL_Widget* GetRadioButtonGroupHeader(IFWL_Widget* pRadioButton);
-  void GetSameGroupRadioButton(IFWL_Widget* pRadioButton, CFX_PtrArray& group);
+  void GetSameGroupRadioButton(IFWL_Widget* pRadioButton,
+                               CFX_ArrayTemplate<IFWL_Widget*>& group);
   IFWL_Widget* GetDefaultButton(IFWL_Widget* pParent);
   void AddRedrawCounts(IFWL_Widget* pWidget);
   void ResetRedrawCounts(IFWL_Widget* pWidget);
diff --git a/xfa/fxfa/app/xfa_ffpageview.cpp b/xfa/fxfa/app/xfa_ffpageview.cpp
index 11628aa..f1898c8 100644
--- a/xfa/fxfa/app/xfa_ffpageview.cpp
+++ b/xfa/fxfa/app/xfa_ffpageview.cpp
@@ -351,7 +351,7 @@
     FX_BOOL& bCurrentItem,
     FX_BOOL& bContentArea,
     FX_BOOL bMarsterPage) {
-  CFX_PtrArray tabParams;
+  CFX_ArrayTemplate<CXFA_TabParam*> tabParams;
   CXFA_LayoutItem* pSearchItem = sIterator->MoveToNext();
   while (pSearchItem) {
     if (!pSearchItem->IsContentLayoutItem()) {
@@ -393,7 +393,7 @@
                 XFA_TabOrderWidgetComparator);
   }
   for (int32_t iStart = 0; iStart < iChildren; iStart++) {
-    CXFA_TabParam* pParam = (CXFA_TabParam*)tabParams[iStart];
+    CXFA_TabParam* pParam = tabParams[iStart];
     pContainer->m_Children.Add(pParam->m_pWidget);
     if (pParam->m_Children.GetSize() > 0) {
       pContainer->m_Children.Append(pParam->m_Children);