summaryrefslogtreecommitdiff
path: root/xfa/fxfa/app/xfa_ffchoicelist.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-14 17:07:09 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-18 14:11:29 +0000
commit5f28b86694455e5ef37736b73fe17d2c271ac721 (patch)
tree46c93dd9028d12f813f56ad8d1b12fee818de7a4 /xfa/fxfa/app/xfa_ffchoicelist.cpp
parent0f9b0a9d72a46cf708866aebc5f1103087b3d2c2 (diff)
downloadpdfium-5f28b86694455e5ef37736b73fe17d2c271ac721.tar.xz
Use unique_ptr for m_pNormalWidget
Change-Id: I8f28171b55c625061bb047899dbfcd4a61004e09 Reviewed-on: https://pdfium-review.googlesource.com/4253 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/app/xfa_ffchoicelist.cpp')
-rw-r--r--xfa/fxfa/app/xfa_ffchoicelist.cpp163
1 files changed, 92 insertions, 71 deletions
diff --git a/xfa/fxfa/app/xfa_ffchoicelist.cpp b/xfa/fxfa/app/xfa_ffchoicelist.cpp
index c628d2e47f..061e9aa842 100644
--- a/xfa/fxfa/app/xfa_ffchoicelist.cpp
+++ b/xfa/fxfa/app/xfa_ffchoicelist.cpp
@@ -7,6 +7,7 @@
#include "xfa/fxfa/app/xfa_ffchoicelist.h"
#include <algorithm>
+#include <utility>
#include <vector>
#include "third_party/base/ptr_util.h"
@@ -33,22 +34,23 @@ CXFA_FFListBox::~CXFA_FFListBox() {
if (m_pNormalWidget) {
CFWL_NoteDriver* pNoteDriver =
m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
- pNoteDriver->UnregisterEventTarget(m_pNormalWidget);
+ pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get());
}
}
bool CXFA_FFListBox::LoadWidget() {
- CFWL_ListBox* pListBox = new CFWL_ListBox(
+ auto pNew = pdfium::MakeUnique<CFWL_ListBox>(
GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr);
+ CFWL_ListBox* pListBox = pNew.get();
pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll | FWL_WGTSTYLE_NoBackground,
0xFFFFFFFF);
- m_pNormalWidget = (CFWL_Widget*)pListBox;
+ m_pNormalWidget = std::move(pNew);
m_pNormalWidget->SetLayoutItem(this);
CFWL_NoteDriver* pNoteDriver =
m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
- pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget);
-
+ pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(),
+ m_pNormalWidget.get());
m_pOldDelegate = m_pNormalWidget->GetDelegate();
m_pNormalWidget->SetDelegate(this);
m_pNormalWidget->LockUpdate();
@@ -77,7 +79,7 @@ bool CXFA_FFListBox::OnKillFocus(CXFA_FFWidget* pNewFocus) {
}
bool CXFA_FFListBox::CommitData() {
- CFWL_ListBox* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget);
+ auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get());
std::vector<int32_t> iSelArray;
int32_t iSels = pListBox->CountSelItems();
for (int32_t i = 0; i < iSels; ++i)
@@ -89,7 +91,7 @@ bool CXFA_FFListBox::CommitData() {
bool CXFA_FFListBox::IsDataChanged() {
std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems();
int32_t iOldSels = pdfium::CollectionSize<int32_t>(iSelArray);
- auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget);
+ auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get());
int32_t iSels = pListBox->CountSelItems();
if (iOldSels != iSels)
return true;
@@ -130,7 +132,7 @@ bool CXFA_FFListBox::UpdateFWLData() {
if (!m_pNormalWidget)
return false;
- auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget);
+ auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get());
std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems();
std::vector<CFWL_ListItem*> selItemArray(iSelArray.size());
std::transform(iSelArray.begin(), iSelArray.end(), selItemArray.begin(),
@@ -143,42 +145,46 @@ bool CXFA_FFListBox::UpdateFWLData() {
m_pNormalWidget->Update();
return true;
}
+
void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget,
const std::vector<int32_t>& arrSels) {
CXFA_EventParam eParam;
eParam.m_eType = XFA_EVENT_Change;
eParam.m_pTarget = m_pDataAcc;
m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw);
- CFWL_ListBox* pListBox = (CFWL_ListBox*)m_pNormalWidget;
+ auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get());
int32_t iSels = pListBox->CountSelItems();
if (iSels > 0) {
CFWL_ListItem* item = pListBox->GetSelItem(0);
eParam.m_wsNewText = item ? item->GetText() : L"";
}
-
m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam);
}
+
void CXFA_FFListBox::SetItemState(int32_t nIndex, bool bSelected) {
- CFWL_ListItem* item = ((CFWL_ListBox*)m_pNormalWidget)->GetSelItem(nIndex);
- ((CFWL_ListBox*)m_pNormalWidget)->SetSelItem(item, bSelected);
+ auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get());
+ pListBox->SetSelItem(pListBox->GetSelItem(nIndex), bSelected);
m_pNormalWidget->Update();
AddInvalidateRect();
}
+
void CXFA_FFListBox::InsertItem(const CFX_WideStringC& wsLabel,
int32_t nIndex) {
CFX_WideString wsTemp(wsLabel);
- ((CFWL_ListBox*)m_pNormalWidget)->AddString(wsTemp.AsStringC());
+ static_cast<CFWL_ListBox*>(m_pNormalWidget.get())
+ ->AddString(wsTemp.AsStringC());
m_pNormalWidget->Update();
AddInvalidateRect();
}
+
void CXFA_FFListBox::DeleteItem(int32_t nIndex) {
- CFWL_ListBox* listBox = static_cast<CFWL_ListBox*>(m_pNormalWidget);
+ auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get());
if (nIndex < 0)
- listBox->DeleteAll();
+ pListBox->DeleteAll();
else
- listBox->DeleteString(listBox->GetItem(nullptr, nIndex));
+ pListBox->DeleteString(pListBox->GetItem(nullptr, nIndex));
- listBox->Update();
+ pListBox->Update();
AddInvalidateRect();
}
@@ -191,7 +197,7 @@ void CXFA_FFListBox::OnProcessEvent(CFWL_Event* pEvent) {
switch (pEvent->GetType()) {
case CFWL_Event::Type::SelectChanged: {
std::vector<int32_t> arrSels;
- OnSelectChanged(m_pNormalWidget, arrSels);
+ OnSelectChanged(m_pNormalWidget.get(), arrSels);
break;
}
default:
@@ -216,19 +222,20 @@ CFX_RectF CXFA_FFComboBox::GetBBox(uint32_t dwStatus, bool bDrawFocus) {
}
bool CXFA_FFComboBox::PtInActiveRect(const CFX_PointF& point) {
- auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget);
+ auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get());
return pComboBox && pComboBox->GetBBox().Contains(point);
}
bool CXFA_FFComboBox::LoadWidget() {
- CFWL_ComboBox* pComboBox = new CFWL_ComboBox(GetFWLApp());
- m_pNormalWidget = (CFWL_Widget*)pComboBox;
+ auto pNew = pdfium::MakeUnique<CFWL_ComboBox>(GetFWLApp());
+ CFWL_ComboBox* pComboBox = pNew.get();
+ m_pNormalWidget = std::move(pNew);
m_pNormalWidget->SetLayoutItem(this);
CFWL_NoteDriver* pNoteDriver =
m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
- pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget);
-
+ pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(),
+ m_pNormalWidget.get());
m_pOldDelegate = m_pNormalWidget->GetDelegate();
m_pNormalWidget->SetDelegate(this);
m_pNormalWidget->LockUpdate();
@@ -248,11 +255,12 @@ bool CXFA_FFComboBox::LoadWidget() {
m_pNormalWidget->UnlockUpdate();
return CXFA_FFField::LoadWidget();
}
+
void CXFA_FFComboBox::UpdateWidgetProperty() {
- CFWL_ComboBox* pComboBox = (CFWL_ComboBox*)m_pNormalWidget;
- if (!pComboBox) {
+ auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get());
+ if (!pComboBox)
return;
- }
+
uint32_t dwExtendedStyle = 0;
uint32_t dwEditStyles =
FWL_STYLEEXT_EDT_ReadOnly | FWL_STYLEEXT_EDT_LastLineHeight;
@@ -283,21 +291,23 @@ bool CXFA_FFComboBox::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) {
}
bool CXFA_FFComboBox::OnKillFocus(CXFA_FFWidget* pNewWidget) {
- bool flag = ProcessCommittedData();
- if (!flag) {
+ if (!ProcessCommittedData())
UpdateFWLData();
- }
+
CXFA_FFField::OnKillFocus(pNewWidget);
return true;
}
+
void CXFA_FFComboBox::OpenDropDownList() {
- ((CFWL_ComboBox*)m_pNormalWidget)->OpenDropDownList(true);
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->OpenDropDownList(true);
}
+
bool CXFA_FFComboBox::CommitData() {
return m_pDataAcc->SetValue(m_wsNewValue, XFA_VALUEPICTURE_Raw);
}
+
bool CXFA_FFComboBox::IsDataChanged() {
- CFWL_ComboBox* pFWLcombobox = ((CFWL_ComboBox*)m_pNormalWidget);
+ auto* pFWLcombobox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get());
CFX_WideString wsText = pFWLcombobox->GetEditText();
int32_t iCursel = pFWLcombobox->GetCurSel();
if (iCursel >= 0) {
@@ -305,19 +315,19 @@ bool CXFA_FFComboBox::IsDataChanged() {
if (wsSel == wsText)
m_pDataAcc->GetChoiceListItem(wsText, iCursel, true);
}
-
CFX_WideString wsOldValue;
m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Raw);
- if (wsOldValue != wsText) {
- m_wsNewValue = wsText;
- return true;
- }
- return false;
+ if (wsOldValue == wsText)
+ return false;
+
+ m_wsNewValue = wsText;
+ return true;
}
+
void CXFA_FFComboBox::FWLEventSelChange(CXFA_EventParam* pParam) {
pParam->m_eType = XFA_EVENT_Change;
pParam->m_pTarget = m_pDataAcc;
- CFWL_ComboBox* pFWLcombobox = ((CFWL_ComboBox*)m_pNormalWidget);
+ auto* pFWLcombobox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get());
pParam->m_wsNewText = pFWLcombobox->GetEditText();
m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, pParam);
}
@@ -361,7 +371,7 @@ uint32_t CXFA_FFComboBox::GetAlignment() {
}
bool CXFA_FFComboBox::UpdateFWLData() {
- auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget);
+ auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get());
if (!pComboBox)
return false;
@@ -380,81 +390,93 @@ bool CXFA_FFComboBox::UpdateFWLData() {
bool CXFA_FFComboBox::CanUndo() {
return m_pDataAcc->IsChoiceListAllowTextEntry() &&
- ((CFWL_ComboBox*)m_pNormalWidget)->EditCanUndo();
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanUndo();
}
+
bool CXFA_FFComboBox::CanRedo() {
return m_pDataAcc->IsChoiceListAllowTextEntry() &&
- ((CFWL_ComboBox*)m_pNormalWidget)->EditCanRedo();
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanRedo();
}
+
bool CXFA_FFComboBox::Undo() {
return m_pDataAcc->IsChoiceListAllowTextEntry() &&
- ((CFWL_ComboBox*)m_pNormalWidget)->EditUndo();
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditUndo();
}
+
bool CXFA_FFComboBox::Redo() {
return m_pDataAcc->IsChoiceListAllowTextEntry() &&
- ((CFWL_ComboBox*)m_pNormalWidget)->EditRedo();
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditRedo();
}
+
bool CXFA_FFComboBox::CanCopy() {
- return ((CFWL_ComboBox*)m_pNormalWidget)->EditCanCopy();
+ return static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanCopy();
}
+
bool CXFA_FFComboBox::CanCut() {
- if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) {
- return false;
- }
- return m_pDataAcc->IsChoiceListAllowTextEntry() &&
- ((CFWL_ComboBox*)m_pNormalWidget)->EditCanCut();
+ return m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open &&
+ m_pDataAcc->IsChoiceListAllowTextEntry() &&
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanCut();
}
+
bool CXFA_FFComboBox::CanPaste() {
return m_pDataAcc->IsChoiceListAllowTextEntry() &&
- (m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open);
+ m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open;
}
+
bool CXFA_FFComboBox::CanSelectAll() {
- return ((CFWL_ComboBox*)m_pNormalWidget)->EditCanSelectAll();
+ return static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanSelectAll();
}
+
bool CXFA_FFComboBox::Copy(CFX_WideString& wsCopy) {
- return ((CFWL_ComboBox*)m_pNormalWidget)->EditCopy(wsCopy);
+ return static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCopy(wsCopy);
}
+
bool CXFA_FFComboBox::Cut(CFX_WideString& wsCut) {
return m_pDataAcc->IsChoiceListAllowTextEntry() &&
- ((CFWL_ComboBox*)m_pNormalWidget)->EditCut(wsCut);
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCut(wsCut);
}
+
bool CXFA_FFComboBox::Paste(const CFX_WideString& wsPaste) {
return m_pDataAcc->IsChoiceListAllowTextEntry() &&
- ((CFWL_ComboBox*)m_pNormalWidget)->EditPaste(wsPaste);
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditPaste(wsPaste);
}
+
void CXFA_FFComboBox::SelectAll() {
- ((CFWL_ComboBox*)m_pNormalWidget)->EditSelectAll();
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditSelectAll();
}
+
void CXFA_FFComboBox::Delete() {
- ((CFWL_ComboBox*)m_pNormalWidget)->EditDelete();
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditDelete();
}
+
void CXFA_FFComboBox::DeSelect() {
- ((CFWL_ComboBox*)m_pNormalWidget)->EditDeSelect();
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditDeSelect();
}
+
void CXFA_FFComboBox::SetItemState(int32_t nIndex, bool bSelected) {
- if (bSelected) {
- ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(nIndex);
- } else {
- ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(-1);
- }
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())
+ ->SetCurSel(bSelected ? nIndex : -1);
m_pNormalWidget->Update();
AddInvalidateRect();
}
+
void CXFA_FFComboBox::InsertItem(const CFX_WideStringC& wsLabel,
int32_t nIndex) {
- ((CFWL_ComboBox*)m_pNormalWidget)->AddString(wsLabel);
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->AddString(wsLabel);
m_pNormalWidget->Update();
AddInvalidateRect();
}
+
void CXFA_FFComboBox::DeleteItem(int32_t nIndex) {
if (nIndex < 0) {
- ((CFWL_ComboBox*)m_pNormalWidget)->RemoveAll();
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->RemoveAll();
} else {
- ((CFWL_ComboBox*)m_pNormalWidget)->RemoveAt(nIndex);
+ static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->RemoveAt(nIndex);
}
m_pNormalWidget->Update();
AddInvalidateRect();
}
+
void CXFA_FFComboBox::OnTextChanged(CFWL_Widget* pWidget,
const CFX_WideString& wsChanged) {
CXFA_EventParam eParam;
@@ -492,22 +514,21 @@ void CXFA_FFComboBox::OnProcessEvent(CFWL_Event* pEvent) {
CXFA_FFField::OnProcessEvent(pEvent);
switch (pEvent->GetType()) {
case CFWL_Event::Type::SelectChanged: {
- CFWL_EventSelectChanged* postEvent =
- static_cast<CFWL_EventSelectChanged*>(pEvent);
- OnSelectChanged(m_pNormalWidget, postEvent->bLButtonUp);
+ auto* postEvent = static_cast<CFWL_EventSelectChanged*>(pEvent);
+ OnSelectChanged(m_pNormalWidget.get(), postEvent->bLButtonUp);
break;
}
case CFWL_Event::Type::EditChanged: {
CFX_WideString wsChanged;
- OnTextChanged(m_pNormalWidget, wsChanged);
+ OnTextChanged(m_pNormalWidget.get(), wsChanged);
break;
}
case CFWL_Event::Type::PreDropDown: {
- OnPreOpen(m_pNormalWidget);
+ OnPreOpen(m_pNormalWidget.get());
break;
}
case CFWL_Event::Type::PostDropDown: {
- OnPostOpen(m_pNormalWidget);
+ OnPostOpen(m_pNormalWidget.get());
break;
}
default: