diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-04-14 17:07:09 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-18 14:11:29 +0000 |
commit | 5f28b86694455e5ef37736b73fe17d2c271ac721 (patch) | |
tree | 46c93dd9028d12f813f56ad8d1b12fee818de7a4 /xfa/fxfa/app | |
parent | 0f9b0a9d72a46cf708866aebc5f1103087b3d2c2 (diff) | |
download | pdfium-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')
-rw-r--r-- | xfa/fxfa/app/xfa_ffbarcode.cpp | 21 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffcheckbutton.cpp | 28 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffchoicelist.cpp | 163 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_fffield.cpp | 107 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_fffield.h | 6 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffimageedit.cpp | 27 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffpushbutton.cpp | 16 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_fftextedit.cpp | 141 |
8 files changed, 287 insertions, 222 deletions
diff --git a/xfa/fxfa/app/xfa_ffbarcode.cpp b/xfa/fxfa/app/xfa_ffbarcode.cpp index 72adb3c96b..92d687781d 100644 --- a/xfa/fxfa/app/xfa_ffbarcode.cpp +++ b/xfa/fxfa/app/xfa_ffbarcode.cpp @@ -6,7 +6,10 @@ #include "xfa/fxfa/app/xfa_ffbarcode.h" +#include <utility> + #include "core/fxcrt/fx_ext.h" +#include "third_party/base/ptr_util.h" #include "xfa/fwl/cfwl_app.h" #include "xfa/fwl/cfwl_barcode.h" #include "xfa/fwl/cfwl_notedriver.h" @@ -122,14 +125,15 @@ CXFA_FFBarcode::CXFA_FFBarcode(CXFA_WidgetAcc* pDataAcc) CXFA_FFBarcode::~CXFA_FFBarcode() {} bool CXFA_FFBarcode::LoadWidget() { - CFWL_Barcode* pFWLBarcode = new CFWL_Barcode(GetFWLApp()); - - m_pNormalWidget = pFWLBarcode; + auto pNew = pdfium::MakeUnique<CFWL_Barcode>(GetFWLApp()); + CFWL_Barcode* pFWLBarcode = 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(); @@ -141,6 +145,7 @@ bool CXFA_FFBarcode::LoadWidget() { m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } + void CXFA_FFBarcode::RenderWidget(CFX_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { @@ -164,7 +169,7 @@ void CXFA_FFBarcode::RenderWidget(CFX_Graphics* pGS, void CXFA_FFBarcode::UpdateWidgetProperty() { CXFA_FFTextEdit::UpdateWidgetProperty(); - CFWL_Barcode* pBarCodeWidget = (CFWL_Barcode*)m_pNormalWidget; + auto* pBarCodeWidget = static_cast<CFWL_Barcode*>(m_pNormalWidget.get()); CFX_WideString wsType = GetDataAcc()->GetBarcodeType(); const XFA_BARCODETYPEENUMINFO* pBarcodeTypeInfo = XFA_GetBarcodeTypeByName(wsType.AsStringC()); @@ -222,7 +227,7 @@ void CXFA_FFBarcode::UpdateWidgetProperty() { } bool CXFA_FFBarcode::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - CFWL_Barcode* pBarCodeWidget = (CFWL_Barcode*)m_pNormalWidget; + auto* pBarCodeWidget = static_cast<CFWL_Barcode*>(m_pNormalWidget.get()); if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) return false; if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) @@ -231,7 +236,7 @@ bool CXFA_FFBarcode::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { } bool CXFA_FFBarcode::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - CFWL_Barcode* pBarCodeWidget = (CFWL_Barcode*)m_pNormalWidget; + auto* pBarCodeWidget = static_cast<CFWL_Barcode*>(m_pNormalWidget.get()); if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) return false; return CXFA_FFTextEdit::OnRButtonDown(dwFlags, point); diff --git a/xfa/fxfa/app/xfa_ffcheckbutton.cpp b/xfa/fxfa/app/xfa_ffcheckbutton.cpp index 9f003ad3a1..bc4eda0e35 100644 --- a/xfa/fxfa/app/xfa_ffcheckbutton.cpp +++ b/xfa/fxfa/app/xfa_ffcheckbutton.cpp @@ -6,6 +6,8 @@ #include "xfa/fxfa/app/xfa_ffcheckbutton.h" +#include <utility> +#include "third_party/base/ptr_util.h" #include "xfa/fwl/cfwl_checkbox.h" #include "xfa/fwl/cfwl_messagemouse.h" #include "xfa/fwl/cfwl_notedriver.h" @@ -24,17 +26,17 @@ CXFA_FFCheckButton::CXFA_FFCheckButton(CXFA_WidgetAcc* pDataAcc) CXFA_FFCheckButton::~CXFA_FFCheckButton() {} bool CXFA_FFCheckButton::LoadWidget() { - CFWL_CheckBox* pCheckBox = new CFWL_CheckBox(GetFWLApp()); - m_pNormalWidget = pCheckBox; + auto pNew = pdfium::MakeUnique<CFWL_CheckBox>(GetFWLApp()); + CFWL_CheckBox* pCheckBox = 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); - if (m_pDataAcc->IsRadioButton()) pCheckBox->ModifyStylesEx(FWL_STYLEEXT_CKB_RadioButton, 0xFFFFFFFF); @@ -44,13 +46,13 @@ bool CXFA_FFCheckButton::LoadWidget() { m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } + void CXFA_FFCheckButton::UpdateWidgetProperty() { - CFWL_CheckBox* pCheckBox = (CFWL_CheckBox*)m_pNormalWidget; - if (!m_pNormalWidget) { + auto* pCheckBox = static_cast<CFWL_CheckBox*>(m_pNormalWidget.get()); + if (!pCheckBox) return; - } - float fSize = m_pDataAcc->GetCheckButtonSize(); - pCheckBox->SetBoxSize(fSize); + + pCheckBox->SetBoxSize(m_pDataAcc->GetCheckButtonSize()); uint32_t dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCross; int32_t iCheckMark = m_pDataAcc->GetCheckButtonMark(); switch (iCheckMark) { @@ -229,15 +231,17 @@ void CXFA_FFCheckButton::RenderWidget(CFX_Graphics* pGS, m_pDataAcc->GetCheckButtonShape() == XFA_ATTRIBUTEENUM_Round); CFX_Matrix mt(1, 0, 0, 1, m_rtCheckBox.left, m_rtCheckBox.top); mt.Concat(mtRotate); - GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget, pGS, &mt); + GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget.get(), pGS, + &mt); } + bool CXFA_FFCheckButton::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { if (!m_pNormalWidget || !IsButtonDown()) return false; SetButtonDown(false); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); 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: diff --git a/xfa/fxfa/app/xfa_fffield.cpp b/xfa/fxfa/app/xfa_fffield.cpp index 4193af82b4..a480b3991f 100644 --- a/xfa/fxfa/app/xfa_fffield.cpp +++ b/xfa/fxfa/app/xfa_fffield.cpp @@ -68,7 +68,8 @@ void CXFA_FFField::RenderWidget(CFX_Graphics* pGS, CFX_RectF rtWidget = m_pNormalWidget->GetWidgetRect(); CFX_Matrix mt(1, 0, 0, 1, rtWidget.left, rtWidget.top); mt.Concat(mtRotate); - GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget, pGS, &mt); + GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget.get(), pGS, + &mt); } void CXFA_FFField::DrawHighlight(CFX_Graphics* pGS, CFX_Matrix* pMatrix, @@ -117,10 +118,11 @@ bool CXFA_FFField::LoadWidget() { PerformLayout(); return true; } + void CXFA_FFField::UnloadWidget() { - delete m_pNormalWidget; - m_pNormalWidget = nullptr; + m_pNormalWidget.reset(); } + void CXFA_FFField::SetEditScrollOffset() { XFA_Element eType = m_pDataAcc->GetUIType(); if (eType == XFA_Element::TextEdit || eType == XFA_Element::NumericEdit || @@ -135,20 +137,22 @@ void CXFA_FFField::SetEditScrollOffset() { fScrollOffset += pPrev->m_rtUI.height; pPrev = static_cast<CXFA_FFField*>(pPrev->GetPrev()); } - ((CFWL_Edit*)m_pNormalWidget)->SetScrollOffset(fScrollOffset); + static_cast<CFWL_Edit*>(m_pNormalWidget.get()) + ->SetScrollOffset(fScrollOffset); } } + bool CXFA_FFField::PerformLayout() { CXFA_FFWidget::PerformLayout(); CapPlacement(); LayoutCaption(); SetFWLRect(); SetEditScrollOffset(); - if (m_pNormalWidget) { + if (m_pNormalWidget) m_pNormalWidget->Update(); - } return true; } + void CXFA_FFField::CapPlacement() { CFX_RectF rtWidget = GetRectWithoutRotate(); CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); @@ -303,48 +307,51 @@ void CXFA_FFField::CapLeftRightPlacement(CXFA_Caption caption, m_rtUI.height += fHeight - rtWidget.height; } } + void CXFA_FFField::UpdateFWL() { - if (m_pNormalWidget) { + if (m_pNormalWidget) m_pNormalWidget->Update(); - } } + uint32_t CXFA_FFField::UpdateUIProperty() { CXFA_Node* pUiNode = m_pDataAcc->GetUIChild(); uint32_t dwStyle = 0; - if (pUiNode && pUiNode->GetElementType() == XFA_Element::DefaultUi) { + if (pUiNode && pUiNode->GetElementType() == XFA_Element::DefaultUi) dwStyle = FWL_STYLEEXT_EDT_ReadOnly; - } + return dwStyle; } + void CXFA_FFField::SetFWLRect() { - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return; - } + CFX_RectF rtUi = m_rtUI; if (rtUi.width < 1.0) rtUi.width = 1.0; if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { float fFontSize = m_pDataAcc->GetFontSize(); - if (rtUi.height < fFontSize) { + if (rtUi.height < fFontSize) rtUi.height = fFontSize; - } } m_pNormalWidget->SetWidgetRect(rtUi); } + bool CXFA_FFField::OnMouseEnter() { - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return false; - } - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::Enter; TranslateFWLMessage(&ms); return true; } + bool CXFA_FFField::OnMouseExit() { - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return false; - } - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::Leave; TranslateFWLMessage(&ms); return true; @@ -366,7 +373,7 @@ bool CXFA_FFField::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { return false; SetButtonDown(true); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); @@ -381,7 +388,7 @@ bool CXFA_FFField::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { return false; SetButtonDown(false); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); @@ -393,7 +400,7 @@ bool CXFA_FFField::OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) { if (!m_pNormalWidget) return false; - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::LeftButtonDblClk; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); @@ -405,7 +412,7 @@ bool CXFA_FFField::OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) { if (!m_pNormalWidget) return false; - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::Move; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); @@ -419,7 +426,7 @@ bool CXFA_FFField::OnMouseWheel(uint32_t dwFlags, if (!m_pNormalWidget) return false; - CFWL_MessageMouseWheel ms(nullptr, m_pNormalWidget); + CFWL_MessageMouseWheel ms(nullptr, m_pNormalWidget.get()); ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); ms.m_delta = CFX_PointF(zDelta, 0); @@ -439,7 +446,7 @@ bool CXFA_FFField::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { SetButtonDown(true); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); @@ -454,7 +461,7 @@ bool CXFA_FFField::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { return false; SetButtonDown(false); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::RightButtonUp; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); @@ -466,7 +473,7 @@ bool CXFA_FFField::OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) { if (!m_pNormalWidget) return false; - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::RightButtonDblClk; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); @@ -476,68 +483,70 @@ bool CXFA_FFField::OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) { bool CXFA_FFField::OnSetFocus(CXFA_FFWidget* pOldWidget) { CXFA_FFWidget::OnSetFocus(pOldWidget); - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return false; - } - CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget); + + CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget.get()); TranslateFWLMessage(&ms); m_dwStatus |= XFA_WidgetStatus_Focused; AddInvalidateRect(); return true; } + bool CXFA_FFField::OnKillFocus(CXFA_FFWidget* pNewWidget) { - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return CXFA_FFWidget::OnKillFocus(pNewWidget); - } - CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget); + + CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget.get()); TranslateFWLMessage(&ms); m_dwStatus &= ~XFA_WidgetStatus_Focused; AddInvalidateRect(); CXFA_FFWidget::OnKillFocus(pNewWidget); return true; } + bool CXFA_FFField::OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) { - if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) return false; - } - CFWL_MessageKey ms(nullptr, m_pNormalWidget); + + CFWL_MessageKey ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_KeyCommand::KeyDown; ms.m_dwFlags = dwFlags; ms.m_dwKeyCode = dwKeyCode; TranslateFWLMessage(&ms); return true; } + bool CXFA_FFField::OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) { - if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) return false; - } - CFWL_MessageKey ms(nullptr, m_pNormalWidget); + + CFWL_MessageKey ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_KeyCommand::KeyUp; ms.m_dwFlags = dwFlags; ms.m_dwKeyCode = dwKeyCode; TranslateFWLMessage(&ms); return true; } + bool CXFA_FFField::OnChar(uint32_t dwChar, uint32_t dwFlags) { - if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) return false; - } - if (dwChar == FWL_VKEY_Tab) { + if (dwChar == FWL_VKEY_Tab) return true; - } - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return false; - } - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) { + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) return false; - } - CFWL_MessageKey ms(nullptr, m_pNormalWidget); + + CFWL_MessageKey ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_KeyCommand::Char; ms.m_dwFlags = dwFlags; ms.m_dwKeyCode = dwChar; TranslateFWLMessage(&ms); return true; } + FWL_WidgetHit CXFA_FFField::OnHitTest(const CFX_PointF& point) { if (m_pNormalWidget && m_pNormalWidget->HitTest(FWLToClient(point)) != FWL_WidgetHit::Unknown) { diff --git a/xfa/fxfa/app/xfa_fffield.h b/xfa/fxfa/app/xfa_fffield.h index 0e9ac8661c..902a84ba08 100644 --- a/xfa/fxfa/app/xfa_fffield.h +++ b/xfa/fxfa/app/xfa_fffield.h @@ -7,6 +7,8 @@ #ifndef XFA_FXFA_APP_XFA_FFFIELD_H_ #define XFA_FXFA_APP_XFA_FFFIELD_H_ +#include <memory> + #include "xfa/fwl/cfwl_widget.h" #include "xfa/fwl/ifwl_widgetdelegate.h" #include "xfa/fxfa/cxfa_ffpageview.h" @@ -64,7 +66,7 @@ class CXFA_FFField : public CXFA_FFWidget, public IFWL_WidgetDelegate { virtual void SetFWLRect(); void SetFWLThemeProvider(); - CFWL_Widget* GetNormalWidget() { return m_pNormalWidget; } + CFWL_Widget* GetNormalWidget() { return m_pNormalWidget.get(); } CFX_PointF FWLToClient(const CFX_PointF& point); void LayoutCaption(); void RenderCaption(CFX_Graphics* pGS, CFX_Matrix* pMatrix = nullptr); @@ -89,7 +91,7 @@ class CXFA_FFField : public CXFA_FFWidget, public IFWL_WidgetDelegate { int32_t iCapPlacement); void SetEditScrollOffset(); - CFWL_Widget* m_pNormalWidget; + std::unique_ptr<CFWL_Widget> m_pNormalWidget; CFX_RectF m_rtUI; CFX_RectF m_rtCaption; }; diff --git a/xfa/fxfa/app/xfa_ffimageedit.cpp b/xfa/fxfa/app/xfa_ffimageedit.cpp index 624ef3f442..dfc7e117d9 100644 --- a/xfa/fxfa/app/xfa_ffimageedit.cpp +++ b/xfa/fxfa/app/xfa_ffimageedit.cpp @@ -6,6 +6,9 @@ #include "xfa/fxfa/app/xfa_ffimageedit.h" +#include <utility> + +#include "third_party/base/ptr_util.h" #include "xfa/fwl/cfwl_app.h" #include "xfa/fwl/cfwl_messagemouse.h" #include "xfa/fwl/cfwl_notedriver.h" @@ -24,28 +27,30 @@ CXFA_FFImageEdit::~CXFA_FFImageEdit() { } bool CXFA_FFImageEdit::LoadWidget() { - CFWL_PictureBox* pPictureBox = new CFWL_PictureBox(GetFWLApp()); - m_pNormalWidget = pPictureBox; + auto pNew = pdfium::MakeUnique<CFWL_PictureBox>(GetFWLApp()); + CFWL_PictureBox* pPictureBox = 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 = pPictureBox->GetDelegate(); pPictureBox->SetDelegate(this); CXFA_FFField::LoadWidget(); - if (m_pDataAcc->GetImageEditImage()) { - return true; - } - UpdateFWLData(); + if (!m_pDataAcc->GetImageEditImage()) + UpdateFWLData(); + return true; } + void CXFA_FFImageEdit::UnloadWidget() { m_pDataAcc->SetImageEditImage(nullptr); CXFA_FFField::UnloadWidget(); } + void CXFA_FFImageEdit::RenderWidget(CFX_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { @@ -94,7 +99,7 @@ bool CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags, SetButtonDown(true); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); @@ -103,9 +108,9 @@ bool CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags, } void CXFA_FFImageEdit::SetFWLRect() { - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return; - } + CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); CFX_RectF rtImage(m_rtUI); rtImage.Deflate(rtUIMargin.left, rtUIMargin.top, rtUIMargin.width, diff --git a/xfa/fxfa/app/xfa_ffpushbutton.cpp b/xfa/fxfa/app/xfa_ffpushbutton.cpp index fa5c0dc9a1..5e9c33db14 100644 --- a/xfa/fxfa/app/xfa_ffpushbutton.cpp +++ b/xfa/fxfa/app/xfa_ffpushbutton.cpp @@ -6,6 +6,9 @@ #include "xfa/fxfa/app/xfa_ffpushbutton.h" +#include <utility> + +#include "third_party/base/ptr_util.h" #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_pushbutton.h" #include "xfa/fwl/cfwl_widgetmgr.h" @@ -41,27 +44,30 @@ void CXFA_FFPushButton::RenderWidget(CFX_Graphics* pGS, CFX_RectF rtWidget = GetRectWithoutRotate(); CFX_Matrix mt(1, 0, 0, 1, rtWidget.left, rtWidget.top); mt.Concat(mtRotate); - GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget, pGS, &mt); + GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget.get(), pGS, + &mt); } bool CXFA_FFPushButton::LoadWidget() { ASSERT(!m_pNormalWidget); - CFWL_PushButton* pPushButton = new CFWL_PushButton(GetFWLApp()); + auto pNew = pdfium::MakeUnique<CFWL_PushButton>(GetFWLApp()); + CFWL_PushButton* pPushButton = pNew.get(); m_pOldDelegate = pPushButton->GetDelegate(); pPushButton->SetDelegate(this); - - m_pNormalWidget = pPushButton; + 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_pNormalWidget->LockUpdate(); UpdateWidgetProperty(); LoadHighlightCaption(); m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } + void CXFA_FFPushButton::UpdateWidgetProperty() { uint32_t dwStyleEx = 0; switch (m_pDataAcc->GetButtonHighlight()) { diff --git a/xfa/fxfa/app/xfa_fftextedit.cpp b/xfa/fxfa/app/xfa_fftextedit.cpp index 2658758718..ccb52d36a6 100644 --- a/xfa/fxfa/app/xfa_fftextedit.cpp +++ b/xfa/fxfa/app/xfa_fftextedit.cpp @@ -6,6 +6,7 @@ #include "xfa/fxfa/app/xfa_fftextedit.h" +#include <utility> #include <vector> #include "xfa/fwl/cfwl_datetimepicker.h" @@ -36,36 +37,38 @@ CXFA_FFTextEdit::~CXFA_FFTextEdit() { if (m_pNormalWidget) { CFWL_NoteDriver* pNoteDriver = m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->UnregisterEventTarget(m_pNormalWidget); + pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); } } bool CXFA_FFTextEdit::LoadWidget() { - CFWL_Edit* pFWLEdit = new CFWL_Edit( + auto pNewWidget = pdfium::MakeUnique<CFWL_Edit>( GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); - m_pNormalWidget = pFWLEdit; + CFWL_Edit* pFWLEdit = pNewWidget.get(); + m_pNormalWidget = std::move(pNewWidget); 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(); - UpdateWidgetProperty(); + CFX_WideString wsText; m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); pFWLEdit->SetText(wsText); m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } + void CXFA_FFTextEdit::UpdateWidgetProperty() { - CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget; - if (!pWidget) { + CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); + if (!pWidget) return; - } + uint32_t dwStyle = 0; uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | @@ -115,7 +118,7 @@ bool CXFA_FFTextEdit::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { } SetButtonDown(true); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; ms.m_dwFlags = dwFlags; ms.m_pos = FWLToClient(point); @@ -159,12 +162,12 @@ bool CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) { AddInvalidateRect(); } CXFA_FFWidget::OnSetFocus(pOldWidget); - CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget); + CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget.get()); TranslateFWLMessage(&ms); return true; } bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { - CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget); + CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget.get()); TranslateFWLMessage(&ms); m_dwStatus &= ~XFA_WidgetStatus_Focused; SetEditScrollOffset(); @@ -176,7 +179,8 @@ bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { return true; } bool CXFA_FFTextEdit::CommitData() { - CFX_WideString wsText = static_cast<CFWL_Edit*>(m_pNormalWidget)->GetText(); + CFX_WideString wsText = + static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetText(); if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) { m_pDataAcc->UpdateUIDisplay(this); return true; @@ -256,8 +260,9 @@ bool CXFA_FFTextEdit::UpdateFWLData() { if (elementType == XFA_Element::ExData) { iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0; } - if (((CFWL_Edit*)m_pNormalWidget)->GetLimit() != iMaxChars) { - ((CFWL_Edit*)m_pNormalWidget)->SetLimit(iMaxChars); + if (static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetLimit() != + iMaxChars) { + static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetLimit(iMaxChars); bUpdate = true; } } @@ -265,15 +270,15 @@ bool CXFA_FFTextEdit::UpdateFWLData() { int32_t nDataLen = 0; if (eType == XFA_VALUEPICTURE_Edit) m_pDataAcc->GetBarcodeAttribute_DataLength(nDataLen); - static_cast<CFWL_Edit*>(m_pNormalWidget)->SetLimit(nDataLen); + static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetLimit(nDataLen); bUpdate = true; } CFX_WideString wsText; m_pDataAcc->GetValue(wsText, eType); CFX_WideString wsOldText = - static_cast<CFWL_Edit*>(m_pNormalWidget)->GetText(); + static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetText(); if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) { - ((CFWL_Edit*)m_pNormalWidget)->SetText(wsText); + static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetText(wsText); bUpdate = true; } if (bUpdate) { @@ -290,7 +295,7 @@ void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget, eParam.m_wsChange = wsChanged; eParam.m_pTarget = m_pDataAcc; eParam.m_wsPrevText = wsPrevText; - CFWL_Edit* pEdit = ((CFWL_Edit*)m_pNormalWidget); + CFWL_Edit* pEdit = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); if (m_pDataAcc->GetUIType() == XFA_Element::DateTimeEdit) { CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit; eParam.m_wsNewText = pDateTime->GetEditText(); @@ -331,11 +336,11 @@ void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { CFWL_EventTextChanged* event = static_cast<CFWL_EventTextChanged*>(pEvent); CFX_WideString wsChange; - OnTextChanged(m_pNormalWidget, wsChange, event->wsPrevText); + OnTextChanged(m_pNormalWidget.get(), wsChange, event->wsPrevText); break; } case CFWL_Event::Type::TextFull: { - OnTextFull(m_pNormalWidget); + OnTextFull(m_pNormalWidget.get()); break; } case CFWL_Event::Type::CheckWord: { @@ -361,15 +366,16 @@ CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc) CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {} bool CXFA_FFNumericEdit::LoadWidget() { - CFWL_Edit* pWidget = new CFWL_Edit( + auto pNewEdit = pdfium::MakeUnique<CFWL_Edit>( GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); - m_pNormalWidget = pWidget; - + CFWL_Edit* pWidget = pNewEdit.get(); + m_pNormalWidget = std::move(pNewEdit); 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(); @@ -382,18 +388,18 @@ bool CXFA_FFNumericEdit::LoadWidget() { return CXFA_FFField::LoadWidget(); } void CXFA_FFNumericEdit::UpdateWidgetProperty() { - CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget; - if (!pWidget) { + CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); + if (!pWidget) return; - } + uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number | FWL_STYLEEXT_EDT_LastLineHeight; dwExtendedStyle |= UpdateUIProperty(); - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; - } + int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); if (iNumCells > 0) { dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; @@ -410,7 +416,7 @@ void CXFA_FFNumericEdit::UpdateWidgetProperty() { void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) { if (pEvent->GetType() == CFWL_Event::Type::Validate) { CFWL_EventValidate* event = static_cast<CFWL_EventValidate*>(pEvent); - event->bValidate = OnValidate(m_pNormalWidget, event->wsInsert); + event->bValidate = OnValidate(m_pNormalWidget.get(), event->wsInsert); return; } CXFA_FFTextEdit::OnProcessEvent(pEvent); @@ -440,15 +446,16 @@ CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc) CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {} bool CXFA_FFPasswordEdit::LoadWidget() { - CFWL_Edit* pWidget = new CFWL_Edit( + auto pNewEdit = pdfium::MakeUnique<CFWL_Edit>( GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); - m_pNormalWidget = pWidget; + CFWL_Edit* pWidget = pNewEdit.get(); + m_pNormalWidget = std::move(pNewEdit); 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(); @@ -460,11 +467,12 @@ bool CXFA_FFPasswordEdit::LoadWidget() { m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } + void CXFA_FFPasswordEdit::UpdateWidgetProperty() { - CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget; - if (!pWidget) { + CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); + if (!pWidget) return; - } + uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight; @@ -496,20 +504,20 @@ CFX_RectF CXFA_FFDateTimeEdit::GetBBox(uint32_t dwStatus, bool bDrawFocus) { } bool CXFA_FFDateTimeEdit::PtInActiveRect(const CFX_PointF& point) { - return m_pNormalWidget && - static_cast<CFWL_DateTimePicker*>(m_pNormalWidget) - ->GetBBox() - .Contains(point); + auto* pPicker = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); + return pPicker && pPicker->GetBBox().Contains(point); } bool CXFA_FFDateTimeEdit::LoadWidget() { - CFWL_DateTimePicker* pWidget = new CFWL_DateTimePicker(GetFWLApp()); - m_pNormalWidget = pWidget; + auto pNewPicker = pdfium::MakeUnique<CFWL_DateTimePicker>(GetFWLApp()); + CFWL_DateTimePicker* pWidget = pNewPicker.get(); + m_pNormalWidget = std::move(pNewPicker); 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(); @@ -536,10 +544,11 @@ bool CXFA_FFDateTimeEdit::LoadWidget() { return CXFA_FFField::LoadWidget(); } void CXFA_FFDateTimeEdit::UpdateWidgetProperty() { - CFWL_DateTimePicker* pWidget = (CFWL_DateTimePicker*)m_pNormalWidget; - if (!pWidget) { + CFWL_DateTimePicker* pWidget = + static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); + if (!pWidget) return; - } + uint32_t dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat; dwExtendedStyle |= UpdateUIProperty(); dwExtendedStyle |= GetAlignment(); @@ -596,15 +605,16 @@ uint32_t CXFA_FFDateTimeEdit::GetAlignment() { } return dwExtendedStyle; } + bool CXFA_FFDateTimeEdit::CommitData() { - CFX_WideString wsText = - static_cast<CFWL_DateTimePicker*>(m_pNormalWidget)->GetEditText(); - if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) { - m_pDataAcc->UpdateUIDisplay(this); - return true; - } - return false; + auto* pPicker = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); + if (!m_pDataAcc->SetValue(pPicker->GetEditText(), XFA_VALUEPICTURE_Edit)) + return false; + + m_pDataAcc->UpdateUIDisplay(this); + return true; } + bool CXFA_FFDateTimeEdit::UpdateFWLData() { if (!m_pNormalWidget) { return false; @@ -615,13 +625,13 @@ bool CXFA_FFDateTimeEdit::UpdateFWLData() { } CFX_WideString wsText; m_pDataAcc->GetValue(wsText, eType); - ((CFWL_DateTimePicker*)m_pNormalWidget)->SetEditText(wsText); + static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get())->SetEditText(wsText); if (IsFocused() && !wsText.IsEmpty()) { CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc); CFX_DateTime date = lcValue.GetDate(); if (lcValue.IsValid()) { if (date.IsSet()) { - static_cast<CFWL_DateTimePicker*>(m_pNormalWidget) + static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()) ->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); } } @@ -634,7 +644,7 @@ bool CXFA_FFDateTimeEdit::IsDataChanged() { return true; } CFX_WideString wsText = - static_cast<CFWL_DateTimePicker*>(m_pNormalWidget)->GetEditText(); + static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get())->GetEditText(); CFX_WideString wsOldValue; m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit); return wsOldValue != wsText; @@ -646,16 +656,19 @@ void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, int32_t iDay) { CFX_WideString wsPicture; m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit); + CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocalMgr()); date.SetDate(CFX_DateTime(iYear, iMonth, iDay, 0, 0, 0, 0)); CFX_WideString wsDate; date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(), XFA_VALUEPICTURE_Edit); - CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)m_pNormalWidget; + + auto* pDateTime = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); pDateTime->SetEditText(wsDate); pDateTime->Update(); GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr); + CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Change; eParam.m_pTarget = m_pDataAcc; @@ -665,9 +678,9 @@ void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) { if (pEvent->GetType() == CFWL_Event::Type::SelectChanged) { - CFWL_EventSelectChanged* event = - static_cast<CFWL_EventSelectChanged*>(pEvent); - OnSelectChanged(m_pNormalWidget, event->iYear, event->iMonth, event->iDay); + auto* event = static_cast<CFWL_EventSelectChanged*>(pEvent); + OnSelectChanged(m_pNormalWidget.get(), event->iYear, event->iMonth, + event->iDay); return; } CXFA_FFTextEdit::OnProcessEvent(pEvent); |