summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-11-01 18:48:19 -0700
committerCommit bot <commit-bot@chromium.org>2016-11-01 18:48:20 -0700
commit6fe8795d9022105a0061a0a81be9a49d49fda345 (patch)
treeb1fc8d51560fbf0a9e4a163f887e763f565d5234
parent919e48d877e503f1ca250bc37324c9f7dc96d7a9 (diff)
downloadpdfium-6fe8795d9022105a0061a0a81be9a49d49fda345.tar.xz
Fold IFWL*::{Initialize|Finalize} into constructor/destructor
This Cl moves the ::Initialize method into the constructors and the ::Finalize method into the destructors. The |m_pDelegate| is made private and a unique_ptr. A |SetDelegate| and |GetDelegate| method are added. Review-Url: https://codereview.chromium.org/2464703006
-rw-r--r--xfa/fwl/core/cfwl_barcode.cpp9
-rw-r--r--xfa/fwl/core/cfwl_checkbox.cpp7
-rw-r--r--xfa/fwl/core/cfwl_combobox.cpp7
-rw-r--r--xfa/fwl/core/cfwl_datetimepicker.cpp7
-rw-r--r--xfa/fwl/core/cfwl_edit.cpp8
-rw-r--r--xfa/fwl/core/cfwl_listbox.cpp7
-rw-r--r--xfa/fwl/core/cfwl_picturebox.cpp8
-rw-r--r--xfa/fwl/core/cfwl_pushbutton.cpp8
-rw-r--r--xfa/fwl/core/cfwl_widget.cpp5
-rw-r--r--xfa/fwl/core/fwl_noteimp.cpp10
-rw-r--r--xfa/fwl/core/fwl_noteimp.h1
-rw-r--r--xfa/fwl/core/ifwl_barcode.cpp19
-rw-r--r--xfa/fwl/core/ifwl_barcode.h2
-rw-r--r--xfa/fwl/core/ifwl_caret.cpp22
-rw-r--r--xfa/fwl/core/ifwl_caret.h2
-rw-r--r--xfa/fwl/core/ifwl_checkbox.cpp14
-rw-r--r--xfa/fwl/core/ifwl_checkbox.h2
-rw-r--r--xfa/fwl/core/ifwl_combobox.cpp24
-rw-r--r--xfa/fwl/core/ifwl_combobox.h2
-rw-r--r--xfa/fwl/core/ifwl_combolist.cpp22
-rw-r--r--xfa/fwl/core/ifwl_combolist.h4
-rw-r--r--xfa/fwl/core/ifwl_datetimecalendar.cpp17
-rw-r--r--xfa/fwl/core/ifwl_datetimecalendar.h4
-rw-r--r--xfa/fwl/core/ifwl_datetimeedit.cpp17
-rw-r--r--xfa/fwl/core/ifwl_datetimeedit.h4
-rw-r--r--xfa/fwl/core/ifwl_datetimepicker.cpp55
-rw-r--r--xfa/fwl/core/ifwl_datetimepicker.h2
-rw-r--r--xfa/fwl/core/ifwl_edit.cpp32
-rw-r--r--xfa/fwl/core/ifwl_edit.h2
-rw-r--r--xfa/fwl/core/ifwl_form.cpp17
-rw-r--r--xfa/fwl/core/ifwl_form.h2
-rw-r--r--xfa/fwl/core/ifwl_formproxy.cpp16
-rw-r--r--xfa/fwl/core/ifwl_formproxy.h2
-rw-r--r--xfa/fwl/core/ifwl_listbox.cpp24
-rw-r--r--xfa/fwl/core/ifwl_listbox.h2
-rw-r--r--xfa/fwl/core/ifwl_monthcalendar.cpp14
-rw-r--r--xfa/fwl/core/ifwl_monthcalendar.h2
-rw-r--r--xfa/fwl/core/ifwl_picturebox.cpp14
-rw-r--r--xfa/fwl/core/ifwl_picturebox.h2
-rw-r--r--xfa/fwl/core/ifwl_pushbutton.cpp14
-rw-r--r--xfa/fwl/core/ifwl_pushbutton.h2
-rw-r--r--xfa/fwl/core/ifwl_scrollbar.cpp14
-rw-r--r--xfa/fwl/core/ifwl_scrollbar.h2
-rw-r--r--xfa/fwl/core/ifwl_spinbutton.cpp14
-rw-r--r--xfa/fwl/core/ifwl_spinbutton.h2
-rw-r--r--xfa/fwl/core/ifwl_tooltip.cpp18
-rw-r--r--xfa/fwl/core/ifwl_tooltip.h2
-rw-r--r--xfa/fwl/core/ifwl_widget.cpp20
-rw-r--r--xfa/fwl/core/ifwl_widget.h13
49 files changed, 134 insertions, 385 deletions
diff --git a/xfa/fwl/core/cfwl_barcode.cpp b/xfa/fwl/core/cfwl_barcode.cpp
index bf7baa37e8..a23bd16df3 100644
--- a/xfa/fwl/core/cfwl_barcode.cpp
+++ b/xfa/fwl/core/cfwl_barcode.cpp
@@ -8,6 +8,8 @@
#include <memory>
+#include "third_party/base/ptr_util.h"
+
namespace {
IFWL_Barcode* ToBarcode(IFWL_Widget* widget) {
@@ -22,11 +24,10 @@ CFWL_Barcode::~CFWL_Barcode() {}
void CFWL_Barcode::Initialize() {
ASSERT(!m_pIface);
- std::unique_ptr<IFWL_Barcode> pBarcode(new IFWL_Barcode(
- m_pApp, m_pProperties->MakeWidgetImpProperties(&m_barcodeData)));
- pBarcode->Initialize();
- m_pIface = std::move(pBarcode);
+ m_pIface = pdfium::MakeUnique<IFWL_Barcode>(
+ m_pApp, m_pProperties->MakeWidgetImpProperties(&m_barcodeData));
+
CFWL_Widget::Initialize();
}
diff --git a/xfa/fwl/core/cfwl_checkbox.cpp b/xfa/fwl/core/cfwl_checkbox.cpp
index 3a26c8ed87..4fbb04891d 100644
--- a/xfa/fwl/core/cfwl_checkbox.cpp
+++ b/xfa/fwl/core/cfwl_checkbox.cpp
@@ -8,6 +8,7 @@
#include <memory>
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/fwl_error.h"
namespace {
@@ -25,11 +26,9 @@ CFWL_CheckBox::~CFWL_CheckBox() {}
void CFWL_CheckBox::Initialize() {
ASSERT(!m_pIface);
- std::unique_ptr<IFWL_CheckBox> pCheckBox(new IFWL_CheckBox(
- m_pApp, m_pProperties->MakeWidgetImpProperties(&m_checkboxData)));
- pCheckBox->Initialize();
+ m_pIface = pdfium::MakeUnique<IFWL_CheckBox>(
+ m_pApp, m_pProperties->MakeWidgetImpProperties(&m_checkboxData));
- m_pIface = std::move(pCheckBox);
CFWL_Widget::Initialize();
}
diff --git a/xfa/fwl/core/cfwl_combobox.cpp b/xfa/fwl/core/cfwl_combobox.cpp
index ed5262ee29..3d45842872 100644
--- a/xfa/fwl/core/cfwl_combobox.cpp
+++ b/xfa/fwl/core/cfwl_combobox.cpp
@@ -8,6 +8,7 @@
#include <utility>
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/fwl_error.h"
#include "xfa/fwl/core/ifwl_widget.h"
@@ -30,11 +31,9 @@ CFWL_ComboBox::~CFWL_ComboBox() {}
void CFWL_ComboBox::Initialize() {
ASSERT(!m_pIface);
- std::unique_ptr<IFWL_ComboBox> pComboBox(new IFWL_ComboBox(
- m_pApp, m_pProperties->MakeWidgetImpProperties(&m_comboBoxData)));
- pComboBox->Initialize();
+ m_pIface = pdfium::MakeUnique<IFWL_ComboBox>(
+ m_pApp, m_pProperties->MakeWidgetImpProperties(&m_comboBoxData));
- m_pIface = std::move(pComboBox);
CFWL_Widget::Initialize();
}
diff --git a/xfa/fwl/core/cfwl_datetimepicker.cpp b/xfa/fwl/core/cfwl_datetimepicker.cpp
index f794317279..973e06ea4b 100644
--- a/xfa/fwl/core/cfwl_datetimepicker.cpp
+++ b/xfa/fwl/core/cfwl_datetimepicker.cpp
@@ -8,6 +8,7 @@
#include <memory>
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/fwl_error.h"
#include "xfa/fwl/core/ifwl_datetimepicker.h"
#include "xfa/fwl/core/ifwl_widget.h"
@@ -28,11 +29,9 @@ CFWL_DateTimePicker::~CFWL_DateTimePicker() {}
void CFWL_DateTimePicker::Initialize() {
ASSERT(!m_pIface);
- std::unique_ptr<IFWL_DateTimePicker> pDateTimePicker(new IFWL_DateTimePicker(
- m_pApp, m_pProperties->MakeWidgetImpProperties(&m_DateTimePickerDP)));
- pDateTimePicker->Initialize();
+ m_pIface = pdfium::MakeUnique<IFWL_DateTimePicker>(
+ m_pApp, m_pProperties->MakeWidgetImpProperties(&m_DateTimePickerDP));
- m_pIface = std::move(pDateTimePicker);
CFWL_Widget::Initialize();
}
diff --git a/xfa/fwl/core/cfwl_edit.cpp b/xfa/fwl/core/cfwl_edit.cpp
index 3ce1bcf247..4b6769e2b1 100644
--- a/xfa/fwl/core/cfwl_edit.cpp
+++ b/xfa/fwl/core/cfwl_edit.cpp
@@ -9,6 +9,8 @@
#include <memory>
#include <vector>
+#include "third_party/base/ptr_util.h"
+
namespace {
IFWL_Edit* ToEdit(IFWL_Widget* widget) {
@@ -28,11 +30,9 @@ CFWL_Edit::~CFWL_Edit() {}
void CFWL_Edit::Initialize() {
ASSERT(!m_pIface);
- std::unique_ptr<IFWL_Edit> pEdit(new IFWL_Edit(
- m_pApp, m_pProperties->MakeWidgetImpProperties(nullptr), nullptr));
- pEdit->Initialize();
+ m_pIface = pdfium::MakeUnique<IFWL_Edit>(
+ m_pApp, m_pProperties->MakeWidgetImpProperties(nullptr), nullptr);
- m_pIface = std::move(pEdit);
CFWL_Widget::Initialize();
}
diff --git a/xfa/fwl/core/cfwl_listbox.cpp b/xfa/fwl/core/cfwl_listbox.cpp
index 139c488830..800dd2e570 100644
--- a/xfa/fwl/core/cfwl_listbox.cpp
+++ b/xfa/fwl/core/cfwl_listbox.cpp
@@ -8,6 +8,7 @@
#include <memory>
+#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
namespace {
@@ -25,11 +26,9 @@ CFWL_ListBox::~CFWL_ListBox() {}
void CFWL_ListBox::Initialize() {
ASSERT(!m_pIface);
- std::unique_ptr<IFWL_ListBox> pListBox(new IFWL_ListBox(
- m_pApp, m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr));
- pListBox->Initialize();
+ m_pIface = pdfium::MakeUnique<IFWL_ListBox>(
+ m_pApp, m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr);
- m_pIface = std::move(pListBox);
CFWL_Widget::Initialize();
}
diff --git a/xfa/fwl/core/cfwl_picturebox.cpp b/xfa/fwl/core/cfwl_picturebox.cpp
index 51f9d77ca1..dcd716ca02 100644
--- a/xfa/fwl/core/cfwl_picturebox.cpp
+++ b/xfa/fwl/core/cfwl_picturebox.cpp
@@ -8,6 +8,8 @@
#include <memory>
+#include "third_party/base/ptr_util.h"
+
CFWL_PictureBox::CFWL_PictureBox(const IFWL_App* app) : CFWL_Widget(app) {}
CFWL_PictureBox::~CFWL_PictureBox() {}
@@ -15,11 +17,9 @@ CFWL_PictureBox::~CFWL_PictureBox() {}
void CFWL_PictureBox::Initialize() {
ASSERT(!m_pIface);
- std::unique_ptr<IFWL_PictureBox> pPictureBox(new IFWL_PictureBox(
- m_pApp, m_pProperties->MakeWidgetImpProperties(&m_PictureBoxDP)));
- pPictureBox->Initialize();
+ m_pIface = pdfium::MakeUnique<IFWL_PictureBox>(
+ m_pApp, m_pProperties->MakeWidgetImpProperties(&m_PictureBoxDP));
- m_pIface = std::move(pPictureBox);
CFWL_Widget::Initialize();
}
diff --git a/xfa/fwl/core/cfwl_pushbutton.cpp b/xfa/fwl/core/cfwl_pushbutton.cpp
index 3f81d8c449..1510cc1a05 100644
--- a/xfa/fwl/core/cfwl_pushbutton.cpp
+++ b/xfa/fwl/core/cfwl_pushbutton.cpp
@@ -8,6 +8,8 @@
#include <memory>
+#include "third_party/base/ptr_util.h"
+
CFWL_PushButton::CFWL_PushButton(const IFWL_App* app) : CFWL_Widget(app) {}
CFWL_PushButton::~CFWL_PushButton() {}
@@ -15,11 +17,9 @@ CFWL_PushButton::~CFWL_PushButton() {}
void CFWL_PushButton::Initialize() {
ASSERT(!m_pIface);
- std::unique_ptr<IFWL_PushButton> pPushButton(new IFWL_PushButton(
- m_pApp, m_pProperties->MakeWidgetImpProperties(&m_buttonData)));
- pPushButton->Initialize();
+ m_pIface = pdfium::MakeUnique<IFWL_PushButton>(
+ m_pApp, m_pProperties->MakeWidgetImpProperties(&m_buttonData));
- m_pIface = std::move(pPushButton);
CFWL_Widget::Initialize();
}
diff --git a/xfa/fwl/core/cfwl_widget.cpp b/xfa/fwl/core/cfwl_widget.cpp
index d277f26a76..999a5a8443 100644
--- a/xfa/fwl/core/cfwl_widget.cpp
+++ b/xfa/fwl/core/cfwl_widget.cpp
@@ -25,10 +25,7 @@ CFWL_Widget::CFWL_Widget(const IFWL_App* app)
ASSERT(m_pWidgetMgr);
}
-CFWL_Widget::~CFWL_Widget() {
- if (m_pIface)
- m_pIface->Finalize();
-}
+CFWL_Widget::~CFWL_Widget() {}
void CFWL_Widget::Initialize() {
ASSERT(m_pIface);
diff --git a/xfa/fwl/core/fwl_noteimp.cpp b/xfa/fwl/core/fwl_noteimp.cpp
index 22579571d4..2ca34f9619 100644
--- a/xfa/fwl/core/fwl_noteimp.cpp
+++ b/xfa/fwl/core/fwl_noteimp.cpp
@@ -760,15 +760,9 @@ FX_BOOL CFWL_EventTarget::IsFilterEvent(CFWL_Event* pEvent, uint32_t dwFilter) {
CFWL_ToolTipContainer* CFWL_ToolTipContainer::s_pInstance = nullptr;
CFWL_ToolTipContainer::CFWL_ToolTipContainer()
- : m_pToolTipImp(nullptr), m_pToolTipDp(new CFWL_CoreToolTipDP(0, 2000)) {}
+ : m_pToolTipDp(new CFWL_CoreToolTipDP(0, 2000)) {}
-CFWL_ToolTipContainer::~CFWL_ToolTipContainer() {
- if (m_pToolTipImp) {
- IFWL_ToolTip* pToolTip = static_cast<IFWL_ToolTip*>(m_pToolTipImp);
- pToolTip->Finalize();
- delete pToolTip;
- }
-}
+CFWL_ToolTipContainer::~CFWL_ToolTipContainer() {}
// static
CFWL_ToolTipContainer* CFWL_ToolTipContainer::getInstance() {
diff --git a/xfa/fwl/core/fwl_noteimp.h b/xfa/fwl/core/fwl_noteimp.h
index 85b44c7ed5..db967fcc15 100644
--- a/xfa/fwl/core/fwl_noteimp.h
+++ b/xfa/fwl/core/fwl_noteimp.h
@@ -136,7 +136,6 @@ class CFWL_ToolTipContainer final {
CFWL_ToolTipContainer();
~CFWL_ToolTipContainer();
- IFWL_ToolTip* m_pToolTipImp;
std::unique_ptr<CFWL_CoreToolTipDP> m_pToolTipDp;
private:
diff --git a/xfa/fwl/core/ifwl_barcode.cpp b/xfa/fwl/core/ifwl_barcode.cpp
index 779b44ab3e..9a2d91a459 100644
--- a/xfa/fwl/core/ifwl_barcode.cpp
+++ b/xfa/fwl/core/ifwl_barcode.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_barcode.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fgas/font/fgas_gefont.h"
#include "xfa/fwl/core/cfwl_themepart.h"
#include "xfa/fwl/core/cfx_barcode.h"
@@ -14,7 +15,9 @@
IFWL_Barcode::IFWL_Barcode(const IFWL_App* app,
const CFWL_WidgetImpProperties& properties)
- : IFWL_Edit(app, properties, nullptr), m_dwStatus(0), m_type(BC_UNKNOWN) {}
+ : IFWL_Edit(app, properties, nullptr), m_dwStatus(0), m_type(BC_UNKNOWN) {
+ SetDelegate(pdfium::MakeUnique<CFWL_BarcodeImpDelegate>(this));
+}
IFWL_Barcode::~IFWL_Barcode() {}
@@ -22,20 +25,6 @@ FWL_Type IFWL_Barcode::GetClassID() const {
return FWL_Type::Barcode;
}
-void IFWL_Barcode::Initialize() {
- if (!m_pDelegate)
- m_pDelegate = new CFWL_BarcodeImpDelegate(this);
-
- IFWL_Edit::Initialize();
-}
-
-void IFWL_Barcode::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- m_pBarcodeEngine.reset();
- IFWL_Edit::Finalize();
-}
-
FWL_Error IFWL_Barcode::Update() {
if (IsLocked()) {
return FWL_Error::Indefinite;
diff --git a/xfa/fwl/core/ifwl_barcode.h b/xfa/fwl/core/ifwl_barcode.h
index 7ca6dbeb6f..f7f28428f5 100644
--- a/xfa/fwl/core/ifwl_barcode.h
+++ b/xfa/fwl/core/ifwl_barcode.h
@@ -63,8 +63,6 @@ class IFWL_Barcode : public IFWL_Edit {
~IFWL_Barcode() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error Update() override;
FWL_Error DrawWidget(CFX_Graphics* pGraphics,
diff --git a/xfa/fwl/core/ifwl_caret.cpp b/xfa/fwl/core/ifwl_caret.cpp
index b6f799633b..2dd1866642 100644
--- a/xfa/fwl/core/ifwl_caret.cpp
+++ b/xfa/fwl/core/ifwl_caret.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_caret.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
#include "xfa/fwl/core/cfwl_widgetimpproperties.h"
#include "xfa/fwl/core/fwl_noteimp.h"
@@ -21,27 +22,18 @@ IFWL_Caret::IFWL_Caret(const IFWL_App* app,
m_dwElapse(400),
m_bSetColor(FALSE) {
SetStates(FWL_STATE_CAT_HightLight);
+ SetDelegate(pdfium::MakeUnique<CFWL_CaretImpDelegate>(this));
}
-IFWL_Caret::~IFWL_Caret() {}
-
-FWL_Type IFWL_Caret::GetClassID() const {
- return FWL_Type::Caret;
-}
-
-void IFWL_Caret::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_CaretImpDelegate(this);
-}
-
-void IFWL_Caret::Finalize() {
+IFWL_Caret::~IFWL_Caret() {
if (m_pTimerInfo) {
m_pTimerInfo->StopTimer();
m_pTimerInfo = nullptr;
}
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
+}
+
+FWL_Type IFWL_Caret::GetClassID() const {
+ return FWL_Type::Caret;
}
FWL_Error IFWL_Caret::DrawWidget(CFX_Graphics* pGraphics,
diff --git a/xfa/fwl/core/ifwl_caret.h b/xfa/fwl/core/ifwl_caret.h
index 351c8461a9..022cadad27 100644
--- a/xfa/fwl/core/ifwl_caret.h
+++ b/xfa/fwl/core/ifwl_caret.h
@@ -27,8 +27,6 @@ class IFWL_Caret : public IFWL_Widget {
~IFWL_Caret() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error DrawWidget(CFX_Graphics* pGraphics,
const CFX_Matrix* pMatrix = nullptr) override;
diff --git a/xfa/fwl/core/ifwl_checkbox.cpp b/xfa/fwl/core/ifwl_checkbox.cpp
index 8af413e602..d62b3bafeb 100644
--- a/xfa/fwl/core/ifwl_checkbox.cpp
+++ b/xfa/fwl/core/ifwl_checkbox.cpp
@@ -8,6 +8,7 @@
#include <algorithm>
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/tto/fde_textout.h"
#include "xfa/fwl/core/cfwl_message.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
@@ -34,20 +35,11 @@ IFWL_CheckBox::IFWL_CheckBox(const IFWL_App* app,
m_rtBox.Reset();
m_rtCaption.Reset();
m_rtFocus.Reset();
-}
-
-IFWL_CheckBox::~IFWL_CheckBox() {}
-void IFWL_CheckBox::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_CheckBoxImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_CheckBoxImpDelegate>(this));
}
-void IFWL_CheckBox::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
+IFWL_CheckBox::~IFWL_CheckBox() {}
FWL_Type IFWL_CheckBox::GetClassID() const {
return FWL_Type::CheckBox;
diff --git a/xfa/fwl/core/ifwl_checkbox.h b/xfa/fwl/core/ifwl_checkbox.h
index b290f04839..4d112c3723 100644
--- a/xfa/fwl/core/ifwl_checkbox.h
+++ b/xfa/fwl/core/ifwl_checkbox.h
@@ -62,8 +62,6 @@ class IFWL_CheckBox : public IFWL_Widget {
~IFWL_CheckBox() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error Update() override;
diff --git a/xfa/fwl/core/ifwl_combobox.cpp b/xfa/fwl/core/ifwl_combobox.cpp
index 123dc9bea9..28a5977425 100644
--- a/xfa/fwl/core/ifwl_combobox.cpp
+++ b/xfa/fwl/core/ifwl_combobox.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_combobox.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/cfde_txtedtengine.h"
#include "xfa/fde/tto/fde_textout.h"
#include "xfa/fwl/core/cfwl_message.h"
@@ -32,13 +33,8 @@ IFWL_ComboBox::IFWL_ComboBox(const IFWL_App* app,
m_rtClient.Reset();
m_rtBtn.Reset();
m_rtHandler.Reset();
-}
-
-IFWL_ComboBox::~IFWL_ComboBox() {}
-void IFWL_ComboBox::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_ComboBoxImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_ComboBoxImpDelegate>(this));
if (m_pWidgetMgr->IsFormDisabled()) {
DisForm_InitComboList();
@@ -54,11 +50,9 @@ void IFWL_ComboBox::Initialize() {
prop.m_pDataProvider = m_pProperties->m_pDataProvider;
m_pListBox.reset(new IFWL_ComboList(m_pOwnerApp, prop, this));
- m_pListBox->Initialize();
if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown) && !m_pEdit) {
CFWL_WidgetImpProperties prop2;
m_pEdit.reset(new IFWL_ComboEdit(m_pOwnerApp, prop2, this));
- m_pEdit->Initialize();
m_pEdit->SetOuter(this);
}
if (m_pEdit)
@@ -67,15 +61,7 @@ void IFWL_ComboBox::Initialize() {
SetStates(m_pProperties->m_dwStates);
}
-void IFWL_ComboBox::Finalize() {
- if (m_pEdit)
- m_pEdit->Finalize();
-
- m_pListBox->Finalize();
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
+IFWL_ComboBox::~IFWL_ComboBox() {}
FWL_Type IFWL_ComboBox::GetClassID() const {
return FWL_Type::ComboBox;
@@ -116,7 +102,6 @@ FWL_Error IFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded,
if (bAddDropDown && !m_pEdit) {
CFWL_WidgetImpProperties prop;
m_pEdit.reset(new IFWL_ComboEdit(m_pOwnerApp, prop, nullptr));
- m_pEdit->Initialize();
m_pEdit->SetOuter(this);
m_pEdit->SetParent(this);
} else if (bRemoveDropDown && m_pEdit) {
@@ -715,7 +700,6 @@ void IFWL_ComboBox::InitProxyForm() {
propForm.m_dwStates = FWL_WGTSTATE_Invisible;
m_pForm = new IFWL_FormProxy(m_pOwnerApp, propForm, m_pListBox.get());
- m_pForm->Initialize();
m_pListBox->SetParent(m_pForm);
m_pListProxyDelegate = new CFWL_ComboProxyImpDelegate(m_pForm, this);
m_pForm->SetCurrentDelegate(m_pListProxyDelegate);
@@ -732,7 +716,6 @@ void IFWL_ComboBox::DisForm_InitComboList() {
prop.m_pDataProvider = m_pProperties->m_pDataProvider;
prop.m_pThemeProvider = m_pProperties->m_pThemeProvider;
m_pListBox.reset(new IFWL_ComboList(m_pOwnerApp, prop, this));
- m_pListBox->Initialize();
}
void IFWL_ComboBox::DisForm_InitComboEdit() {
@@ -743,7 +726,6 @@ void IFWL_ComboBox::DisForm_InitComboEdit() {
prop.m_pParent = this;
prop.m_pThemeProvider = m_pProperties->m_pThemeProvider;
m_pEdit.reset(new IFWL_ComboEdit(m_pOwnerApp, prop, this));
- m_pEdit->Initialize();
m_pEdit->SetOuter(this);
}
diff --git a/xfa/fwl/core/ifwl_combobox.h b/xfa/fwl/core/ifwl_combobox.h
index 268a4b516b..5fab49986c 100644
--- a/xfa/fwl/core/ifwl_combobox.h
+++ b/xfa/fwl/core/ifwl_combobox.h
@@ -89,8 +89,6 @@ class IFWL_ComboBox : public IFWL_Widget {
~IFWL_ComboBox() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error ModifyStylesEx(uint32_t dwStylesExAdded,
diff --git a/xfa/fwl/core/ifwl_combolist.cpp b/xfa/fwl/core/ifwl_combolist.cpp
index 23392a5c70..0fdc5ac6d9 100644
--- a/xfa/fwl/core/ifwl_combolist.cpp
+++ b/xfa/fwl/core/ifwl_combolist.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_combolist.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/ifwl_combobox.h"
#include "xfa/fwl/core/ifwl_comboedit.h"
@@ -14,20 +15,7 @@ IFWL_ComboList::IFWL_ComboList(const IFWL_App* app,
IFWL_Widget* pOuter)
: IFWL_ListBox(app, properties, pOuter), m_bNotifyOwner(TRUE) {
ASSERT(pOuter);
-}
-
-void IFWL_ComboList::Initialize() {
- IFWL_ListBox::Initialize();
-
- // Delete the delegate that was created by IFWL_ListBox::Initialize ...
- delete m_pDelegate;
- m_pDelegate = new CFWL_ComboListImpDelegate(this);
-}
-
-void IFWL_ComboList::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_ListBox::Finalize();
+ SetDelegate(pdfium::MakeUnique<CFWL_ComboListImpDelegate>(this));
}
int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) {
@@ -195,7 +183,7 @@ int32_t CFWL_ComboListImpDelegate::OnDropListMouseMove(CFWL_MsgMouse* pMsg) {
} else if (m_pOwner->m_bNotifyOwner) {
m_pOwner->ClientToOuter(pMsg->m_fx, pMsg->m_fy);
IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOwner->m_pOuter);
- pOuter->m_pDelegate->OnProcessMessage(pMsg);
+ pOuter->GetDelegate()->OnProcessMessage(pMsg);
}
return 1;
}
@@ -213,7 +201,7 @@ int32_t CFWL_ComboListImpDelegate::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) {
IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOwner->m_pOuter);
if (m_pOwner->m_bNotifyOwner) {
m_pOwner->ClientToOuter(pMsg->m_fx, pMsg->m_fy);
- pOuter->m_pDelegate->OnProcessMessage(pMsg);
+ pOuter->GetDelegate()->OnProcessMessage(pMsg);
} else {
if (m_pOwner->IsShowScrollBar(TRUE) && m_pOwner->m_pVertScrollBar) {
CFX_RectF rect;
@@ -255,7 +243,7 @@ int32_t CFWL_ComboListImpDelegate::OnDropListKey(CFWL_MsgKey* pKey) {
}
if (bPropagate) {
pKey->m_pDstTarget = m_pOwner->m_pOuter;
- pOuter->m_pDelegate->OnProcessMessage(pKey);
+ pOuter->GetDelegate()->OnProcessMessage(pKey);
return 1;
}
return 0;
diff --git a/xfa/fwl/core/ifwl_combolist.h b/xfa/fwl/core/ifwl_combolist.h
index eaa03e36d4..781fbadf73 100644
--- a/xfa/fwl/core/ifwl_combolist.h
+++ b/xfa/fwl/core/ifwl_combolist.h
@@ -17,10 +17,6 @@ class IFWL_ComboList : public IFWL_ListBox {
const CFWL_WidgetImpProperties& properties,
IFWL_Widget* pOuter);
- // IFWL_Widget
- void Initialize() override;
- void Finalize() override;
-
int32_t MatchItem(const CFX_WideString& wsMatch);
void ChangeSelected(int32_t iSel);
int32_t CountItems();
diff --git a/xfa/fwl/core/ifwl_datetimecalendar.cpp b/xfa/fwl/core/ifwl_datetimecalendar.cpp
index ee04bf4978..a44b558190 100644
--- a/xfa/fwl/core/ifwl_datetimecalendar.cpp
+++ b/xfa/fwl/core/ifwl_datetimecalendar.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_datetimecalendar.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/cfwl_widgetmgr.h"
#include "xfa/fwl/core/ifwl_datetimepicker.h"
#include "xfa/fwl/core/ifwl_formproxy.h"
@@ -14,20 +15,8 @@ IFWL_DateTimeCalendar::IFWL_DateTimeCalendar(
const IFWL_App* app,
const CFWL_WidgetImpProperties& properties,
IFWL_Widget* pOuter)
- : IFWL_MonthCalendar(app, properties, pOuter) {}
-
-void IFWL_DateTimeCalendar::Initialize() {
- IFWL_MonthCalendar::Initialize();
-
- // Delete delegated set by IFWL_MonthCalendar::Initialize.
- delete m_pDelegate;
- m_pDelegate = new CFWL_DateTimeCalendarImpDelegate(this);
-}
-
-void IFWL_DateTimeCalendar::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_MonthCalendar::Finalize();
+ : IFWL_MonthCalendar(app, properties, pOuter) {
+ SetDelegate(pdfium::MakeUnique<CFWL_DateTimeCalendarImpDelegate>(this));
}
CFWL_DateTimeCalendarImpDelegate::CFWL_DateTimeCalendarImpDelegate(
diff --git a/xfa/fwl/core/ifwl_datetimecalendar.h b/xfa/fwl/core/ifwl_datetimecalendar.h
index 3d856fd578..7a3b960fe6 100644
--- a/xfa/fwl/core/ifwl_datetimecalendar.h
+++ b/xfa/fwl/core/ifwl_datetimecalendar.h
@@ -15,10 +15,6 @@ class IFWL_DateTimeCalendar : public IFWL_MonthCalendar {
const CFWL_WidgetImpProperties& properties,
IFWL_Widget* pOuter);
- // IFWL_MonthCalendar
- void Initialize() override;
- void Finalize() override;
-
protected:
friend class CFWL_DateTimeCalendarImpDelegate;
};
diff --git a/xfa/fwl/core/ifwl_datetimeedit.cpp b/xfa/fwl/core/ifwl_datetimeedit.cpp
index 6a7fd26214..1c0baae32d 100644
--- a/xfa/fwl/core/ifwl_datetimeedit.cpp
+++ b/xfa/fwl/core/ifwl_datetimeedit.cpp
@@ -6,26 +6,15 @@
#include "xfa/fwl/core/ifwl_datetimeedit.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/cfwl_widgetmgr.h"
#include "xfa/fwl/core/ifwl_datetimepicker.h"
IFWL_DateTimeEdit::IFWL_DateTimeEdit(const IFWL_App* app,
const CFWL_WidgetImpProperties& properties,
IFWL_Widget* pOuter)
- : IFWL_Edit(app, properties, pOuter) {}
-
-void IFWL_DateTimeEdit::Initialize() {
- IFWL_Edit::Initialize();
-
- // Delete delegate set by IFWL_Edit::Initialize.
- delete m_pDelegate;
- m_pDelegate = new CFWL_DateTimeEditImpDelegate(this);
-}
-
-void IFWL_DateTimeEdit::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Edit::Finalize();
+ : IFWL_Edit(app, properties, pOuter) {
+ SetDelegate(pdfium::MakeUnique<CFWL_DateTimeEditImpDelegate>(this));
}
CFWL_DateTimeEditImpDelegate::CFWL_DateTimeEditImpDelegate(
diff --git a/xfa/fwl/core/ifwl_datetimeedit.h b/xfa/fwl/core/ifwl_datetimeedit.h
index cbb118329a..39dd3718ac 100644
--- a/xfa/fwl/core/ifwl_datetimeedit.h
+++ b/xfa/fwl/core/ifwl_datetimeedit.h
@@ -19,10 +19,6 @@ class IFWL_DateTimeEdit : public IFWL_Edit {
const CFWL_WidgetImpProperties& properties,
IFWL_Widget* pOuter);
- // IFWL_Edit
- void Initialize() override;
- void Finalize() override;
-
protected:
friend class CFWL_DateTimeEditImpDelegate;
};
diff --git a/xfa/fwl/core/ifwl_datetimepicker.cpp b/xfa/fwl/core/ifwl_datetimepicker.cpp
index 148a85cfe6..844eb9ebe6 100644
--- a/xfa/fwl/core/ifwl_datetimepicker.cpp
+++ b/xfa/fwl/core/ifwl_datetimepicker.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_datetimepicker.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/cfwl_message.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
#include "xfa/fwl/core/cfwl_widgetmgr.h"
@@ -33,14 +34,8 @@ IFWL_DateTimePicker::IFWL_DateTimePicker(
m_iDay(-1),
m_bLBtnDown(FALSE) {
m_rtBtn.Set(0, 0, 0, 0);
-}
-
-IFWL_DateTimePicker::~IFWL_DateTimePicker() {}
-
-void IFWL_DateTimePicker::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_DateTimePickerImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_DateTimePickerImpDelegate>(this));
m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat;
CFWL_WidgetImpProperties propMonth;
@@ -51,7 +46,6 @@ void IFWL_DateTimePicker::Initialize() {
propMonth.m_pThemeProvider = m_pProperties->m_pThemeProvider;
m_pMonthCal.reset(new IFWL_DateTimeCalendar(m_pOwnerApp, propMonth, this));
- m_pMonthCal->Initialize();
CFX_RectF rtMonthCal;
m_pMonthCal->GetWidgetRect(rtMonthCal, TRUE);
rtMonthCal.Set(0, 0, rtMonthCal.width, rtMonthCal.height);
@@ -61,23 +55,12 @@ void IFWL_DateTimePicker::Initialize() {
propEdit.m_pThemeProvider = m_pProperties->m_pThemeProvider;
m_pEdit.reset(new IFWL_DateTimeEdit(m_pOwnerApp, propEdit, this));
- m_pEdit->Initialize();
RegisterEventTarget(m_pMonthCal.get());
RegisterEventTarget(m_pEdit.get());
}
-void IFWL_DateTimePicker::Finalize() {
- if (m_pEdit)
- m_pEdit->Finalize();
- if (m_pMonthCal)
- m_pMonthCal->Finalize();
- if (m_pForm)
- m_pForm->Finalize();
-
+IFWL_DateTimePicker::~IFWL_DateTimePicker() {
UnregisterEventTarget();
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
}
FWL_Type IFWL_DateTimePicker::GetClassID() const {
@@ -324,24 +307,19 @@ void IFWL_DateTimePicker::DrawDropDownButton(CFX_Graphics* pGraphics,
const CFX_Matrix* pMatrix) {
if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_Spin) ==
FWL_STYLEEXT_DTP_Spin) {
- CFWL_WidgetImpProperties prop;
- prop.m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert;
- prop.m_pParent = this;
- prop.m_rtWidget = m_rtBtn;
- IFWL_SpinButton* pSpin = new IFWL_SpinButton(m_pOwnerApp, prop);
- pSpin->Initialize();
- } else {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::DropDownButton;
- param.m_dwStates = m_iBtnState;
- param.m_pGraphics = pGraphics;
- param.m_rtPart = m_rtBtn;
- if (pMatrix) {
- param.m_matrix.Concat(*pMatrix);
- }
- pTheme->DrawBackground(&param);
+ return;
}
+
+ CFWL_ThemeBackground param;
+ param.m_pWidget = this;
+ param.m_iPart = CFWL_Part::DropDownButton;
+ param.m_dwStates = m_iBtnState;
+ param.m_pGraphics = pGraphics;
+ param.m_rtPart = m_rtBtn;
+ if (pMatrix)
+ param.m_matrix.Concat(*pMatrix);
+
+ pTheme->DrawBackground(&param);
}
void IFWL_DateTimePicker::FormatDateString(int32_t iYear,
@@ -464,7 +442,6 @@ void IFWL_DateTimePicker::InitProxyForm() {
propForm.m_pOwner = this;
m_pForm.reset(new IFWL_FormProxy(m_pOwnerApp, propForm, m_pMonthCal.get()));
- m_pForm->Initialize();
m_pMonthCal->SetParent(m_pForm.get());
}
@@ -494,7 +471,6 @@ void IFWL_DateTimePicker::DisForm_InitDateTimeCalendar() {
propMonth.m_pThemeProvider = m_pProperties->m_pThemeProvider;
m_pMonthCal.reset(new IFWL_DateTimeCalendar(m_pOwnerApp, propMonth, this));
- m_pMonthCal->Initialize();
CFX_RectF rtMonthCal;
m_pMonthCal->GetWidgetRect(rtMonthCal, TRUE);
rtMonthCal.Set(0, 0, rtMonthCal.width, rtMonthCal.height);
@@ -510,7 +486,6 @@ void IFWL_DateTimePicker::DisForm_InitDateTimeEdit() {
propEdit.m_pThemeProvider = m_pProperties->m_pThemeProvider;
m_pEdit.reset(new IFWL_DateTimeEdit(m_pOwnerApp, propEdit, this));
- m_pEdit->Initialize();
}
FX_BOOL IFWL_DateTimePicker::DisForm_IsMonthCalendarShowed() {
diff --git a/xfa/fwl/core/ifwl_datetimepicker.h b/xfa/fwl/core/ifwl_datetimepicker.h
index 476eb09b3c..5b360d3603 100644
--- a/xfa/fwl/core/ifwl_datetimepicker.h
+++ b/xfa/fwl/core/ifwl_datetimepicker.h
@@ -67,8 +67,6 @@ class IFWL_DateTimePicker : public IFWL_Widget {
~IFWL_DateTimePicker() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error Update() override;
diff --git a/xfa/fwl/core/ifwl_edit.cpp b/xfa/fwl/core/ifwl_edit.cpp
index b826bd2f02..8edc69d578 100644
--- a/xfa/fwl/core/ifwl_edit.cpp
+++ b/xfa/fwl/core/ifwl_edit.cpp
@@ -10,6 +10,7 @@
#include <memory>
#include <vector>
+#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
#include "xfa/fde/cfde_txtedtengine.h"
#include "xfa/fde/fde_gedevice.h"
@@ -74,33 +75,18 @@ IFWL_Edit::IFWL_Edit(const IFWL_App* app,
m_rtClient.Reset();
m_rtEngine.Reset();
m_rtStatic.Reset();
-}
-
-IFWL_Edit::~IFWL_Edit() {
- ClearRecord();
-}
-
-void IFWL_Edit::Initialize() {
- IFWL_Widget::Initialize();
- if (!m_pDelegate)
- m_pDelegate = new CFWL_EditImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_EditImpDelegate>(this));
InitCaret();
if (!m_pEdtEngine)
InitEngine();
}
-void IFWL_Edit::Finalize() {
+IFWL_Edit::~IFWL_Edit() {
if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
ShowCaret(FALSE);
- if (m_pHorzScrollBar)
- m_pHorzScrollBar->Finalize();
- if (m_pVertScrollBar)
- m_pVertScrollBar->Finalize();
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
+ ClearRecord();
}
FWL_Type IFWL_Edit::GetClassID() const {
@@ -1472,9 +1458,12 @@ void IFWL_Edit::InitScrollBar(FX_BOOL bVert) {
prop.m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible;
prop.m_pParent = this;
prop.m_pThemeProvider = m_pProperties->m_pThemeProvider;
- IFWL_ScrollBar* pScrollBar = new IFWL_ScrollBar(m_pOwnerApp, prop, this);
- pScrollBar->Initialize();
- (bVert ? &m_pVertScrollBar : &m_pHorzScrollBar)->reset(pScrollBar);
+
+ IFWL_ScrollBar* sb = new IFWL_ScrollBar(m_pOwnerApp, prop, this);
+ if (bVert)
+ m_pVertScrollBar.reset(sb);
+ else
+ m_pHorzScrollBar.reset(sb);
}
void IFWL_Edit::InitEngine() {
@@ -1571,7 +1560,6 @@ void IFWL_Edit::InitCaret() {
if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) {
CFWL_WidgetImpProperties prop;
m_pCaret.reset(new IFWL_Caret(m_pOwnerApp, prop, this));
- m_pCaret->Initialize();
m_pCaret->SetParent(this);
m_pCaret->SetStates(m_pProperties->m_dwStates);
}
diff --git a/xfa/fwl/core/ifwl_edit.h b/xfa/fwl/core/ifwl_edit.h
index a03431b6ee..4c44913b7e 100644
--- a/xfa/fwl/core/ifwl_edit.h
+++ b/xfa/fwl/core/ifwl_edit.h
@@ -112,8 +112,6 @@ class IFWL_Edit : public IFWL_Widget {
~IFWL_Edit() override;
// IFWL_Widget:
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error SetWidgetRect(const CFX_RectF& rect) override;
diff --git a/xfa/fwl/core/ifwl_form.cpp b/xfa/fwl/core/ifwl_form.cpp
index 2ded30e6d6..125f7c4cab 100644
--- a/xfa/fwl/core/ifwl_form.cpp
+++ b/xfa/fwl/core/ifwl_form.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_form.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/tto/fde_textout.h"
#include "xfa/fwl/core/cfwl_message.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
@@ -64,26 +65,16 @@ IFWL_Form::IFWL_Form(const IFWL_App* app,
m_rtRestore.Reset();
m_rtCaptionText.Reset();
m_rtIcon.Reset();
-}
-
-IFWL_Form::~IFWL_Form() {
- RemoveSysButtons();
-}
-
-void IFWL_Form::Initialize() {
- IFWL_Widget::Initialize();
RegisterForm();
RegisterEventTarget();
- m_pDelegate = new CFWL_FormImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_FormImpDelegate>(this));
}
-void IFWL_Form::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
+IFWL_Form::~IFWL_Form() {
UnregisterEventTarget();
UnRegisterForm();
- IFWL_Widget::Finalize();
+ RemoveSysButtons();
}
FWL_Type IFWL_Form::GetClassID() const {
diff --git a/xfa/fwl/core/ifwl_form.h b/xfa/fwl/core/ifwl_form.h
index 4203177d11..c6158c60e1 100644
--- a/xfa/fwl/core/ifwl_form.h
+++ b/xfa/fwl/core/ifwl_form.h
@@ -91,8 +91,6 @@ class IFWL_Form : public IFWL_Widget {
~IFWL_Form() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FX_BOOL IsInstance(const CFX_WideStringC& wsClass) const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
diff --git a/xfa/fwl/core/ifwl_formproxy.cpp b/xfa/fwl/core/ifwl_formproxy.cpp
index f79e915378..dee8973bc7 100644
--- a/xfa/fwl/core/ifwl_formproxy.cpp
+++ b/xfa/fwl/core/ifwl_formproxy.cpp
@@ -6,25 +6,17 @@
#include "xfa/fwl/core/ifwl_formproxy.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/fwl_noteimp.h"
IFWL_FormProxy::IFWL_FormProxy(const IFWL_App* app,
const CFWL_WidgetImpProperties& properties,
IFWL_Widget* pOuter)
- : IFWL_Form(app, properties, pOuter) {}
-
-IFWL_FormProxy::~IFWL_FormProxy() {}
-
-void IFWL_FormProxy::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_FormProxyImpDelegate(this);
+ : IFWL_Form(app, properties, pOuter) {
+ SetDelegate(pdfium::MakeUnique<CFWL_FormProxyImpDelegate>(this));
}
-void IFWL_FormProxy::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
+IFWL_FormProxy::~IFWL_FormProxy() {}
FWL_Type IFWL_FormProxy::GetClassID() const {
return FWL_Type::FormProxy;
diff --git a/xfa/fwl/core/ifwl_formproxy.h b/xfa/fwl/core/ifwl_formproxy.h
index 15288ce62f..c323bdc7b3 100644
--- a/xfa/fwl/core/ifwl_formproxy.h
+++ b/xfa/fwl/core/ifwl_formproxy.h
@@ -20,8 +20,6 @@ class IFWL_FormProxy : public IFWL_Form {
~IFWL_FormProxy() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FX_BOOL IsInstance(const CFX_WideStringC& wsClass) const override;
FWL_Error Update() override;
diff --git a/xfa/fwl/core/ifwl_listbox.cpp b/xfa/fwl/core/ifwl_listbox.cpp
index 7cd4c53ff3..b4b6c25136 100644
--- a/xfa/fwl/core/ifwl_listbox.cpp
+++ b/xfa/fwl/core/ifwl_listbox.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_listbox.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/tto/fde_textout.h"
#include "xfa/fwl/core/cfwl_message.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
@@ -33,25 +34,11 @@ IFWL_ListBox::IFWL_ListBox(const IFWL_App* app,
m_rtClient.Reset();
m_rtConent.Reset();
m_rtStatic.Reset();
-}
-
-IFWL_ListBox::~IFWL_ListBox() {}
-void IFWL_ListBox::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_ListBoxImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_ListBoxImpDelegate>(this));
}
-void IFWL_ListBox::Finalize() {
- if (m_pVertScrollBar)
- m_pVertScrollBar->Finalize();
- if (m_pHorzScrollBar)
- m_pHorzScrollBar->Finalize();
-
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
+IFWL_ListBox::~IFWL_ListBox() {}
FWL_Type IFWL_ListBox::GetClassID() const {
return FWL_Type::ListBox;
@@ -896,9 +883,8 @@ void IFWL_ListBox::InitScrollBar(FX_BOOL bVert) {
prop.m_dwStates = FWL_WGTSTATE_Invisible;
prop.m_pParent = this;
prop.m_pThemeProvider = m_pScrollBarTP;
- IFWL_ScrollBar* pScrollBar = new IFWL_ScrollBar(m_pOwnerApp, prop, this);
- pScrollBar->Initialize();
- (bVert ? &m_pVertScrollBar : &m_pHorzScrollBar)->reset(pScrollBar);
+ (bVert ? &m_pVertScrollBar : &m_pHorzScrollBar)
+ ->reset(new IFWL_ScrollBar(m_pOwnerApp, prop, this));
}
FX_BOOL IFWL_ListBox::IsShowScrollBar(FX_BOOL bVert) {
diff --git a/xfa/fwl/core/ifwl_listbox.h b/xfa/fwl/core/ifwl_listbox.h
index a5efceb5b0..25e28cc3a6 100644
--- a/xfa/fwl/core/ifwl_listbox.h
+++ b/xfa/fwl/core/ifwl_listbox.h
@@ -108,8 +108,6 @@ class IFWL_ListBox : public IFWL_Widget {
~IFWL_ListBox() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error Update() override;
diff --git a/xfa/fwl/core/ifwl_monthcalendar.cpp b/xfa/fwl/core/ifwl_monthcalendar.cpp
index 43e90a23a5..8c5b3505b4 100644
--- a/xfa/fwl/core/ifwl_monthcalendar.cpp
+++ b/xfa/fwl/core/ifwl_monthcalendar.cpp
@@ -8,6 +8,7 @@
#include <algorithm>
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/tto/fde_textout.h"
#include "xfa/fwl/core/cfwl_message.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
@@ -145,6 +146,8 @@ IFWL_MonthCalendar::IFWL_MonthCalendar(
m_rtClient.Reset();
m_rtWeekNum.Reset();
m_rtWeekNumSep.Reset();
+
+ SetDelegate(pdfium::MakeUnique<CFWL_MonthCalendarImpDelegate>(this));
}
IFWL_MonthCalendar::~IFWL_MonthCalendar() {
@@ -152,17 +155,6 @@ IFWL_MonthCalendar::~IFWL_MonthCalendar() {
m_arrSelDays.RemoveAll();
}
-void IFWL_MonthCalendar::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_MonthCalendarImpDelegate(this);
-}
-
-void IFWL_MonthCalendar::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
-
FWL_Type IFWL_MonthCalendar::GetClassID() const {
return FWL_Type::MonthCalendar;
}
diff --git a/xfa/fwl/core/ifwl_monthcalendar.h b/xfa/fwl/core/ifwl_monthcalendar.h
index 793eaa8eea..6bf8ad4898 100644
--- a/xfa/fwl/core/ifwl_monthcalendar.h
+++ b/xfa/fwl/core/ifwl_monthcalendar.h
@@ -58,8 +58,6 @@ class IFWL_MonthCalendar : public IFWL_Widget {
~IFWL_MonthCalendar() override;
// FWL_WidgetImp
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error Update() override;
diff --git a/xfa/fwl/core/ifwl_picturebox.cpp b/xfa/fwl/core/ifwl_picturebox.cpp
index 20ab54a37c..50bf2a40ea 100644
--- a/xfa/fwl/core/ifwl_picturebox.cpp
+++ b/xfa/fwl/core/ifwl_picturebox.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_picturebox.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/cfwl_picturebox.h"
#include "xfa/fwl/core/fwl_noteimp.h"
@@ -18,20 +19,11 @@ IFWL_PictureBox::IFWL_PictureBox(const IFWL_App* app,
m_rtClient.Reset();
m_rtImage.Reset();
m_matrix.SetIdentity();
-}
-
-IFWL_PictureBox::~IFWL_PictureBox() {}
-void IFWL_PictureBox::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_PictureBoxImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_PictureBoxImpDelegate>(this));
}
-void IFWL_PictureBox::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
+IFWL_PictureBox::~IFWL_PictureBox() {}
FWL_Type IFWL_PictureBox::GetClassID() const {
return FWL_Type::PictureBox;
diff --git a/xfa/fwl/core/ifwl_picturebox.h b/xfa/fwl/core/ifwl_picturebox.h
index 24c6e7edfd..ecbbc449cb 100644
--- a/xfa/fwl/core/ifwl_picturebox.h
+++ b/xfa/fwl/core/ifwl_picturebox.h
@@ -49,8 +49,6 @@ class IFWL_PictureBox : public IFWL_Widget {
~IFWL_PictureBox() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error Update() override;
diff --git a/xfa/fwl/core/ifwl_pushbutton.cpp b/xfa/fwl/core/ifwl_pushbutton.cpp
index b9d11d9e5a..597cf65529 100644
--- a/xfa/fwl/core/ifwl_pushbutton.cpp
+++ b/xfa/fwl/core/ifwl_pushbutton.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_pushbutton.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/tto/fde_textout.h"
#include "xfa/fwl/core/cfwl_message.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
@@ -22,20 +23,11 @@ IFWL_PushButton::IFWL_PushButton(const IFWL_App* app,
m_iTTOAlign(FDE_TTOALIGNMENT_Center) {
m_rtClient.Set(0, 0, 0, 0);
m_rtCaption.Set(0, 0, 0, 0);
-}
-
-IFWL_PushButton::~IFWL_PushButton() {}
-void IFWL_PushButton::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_PushButtonImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_PushButtonImpDelegate>(this));
}
-void IFWL_PushButton::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
+IFWL_PushButton::~IFWL_PushButton() {}
FWL_Type IFWL_PushButton::GetClassID() const {
return FWL_Type::PushButton;
diff --git a/xfa/fwl/core/ifwl_pushbutton.h b/xfa/fwl/core/ifwl_pushbutton.h
index 6a4d28ddba..c009c47dca 100644
--- a/xfa/fwl/core/ifwl_pushbutton.h
+++ b/xfa/fwl/core/ifwl_pushbutton.h
@@ -45,8 +45,6 @@ class IFWL_PushButton : public IFWL_Widget {
~IFWL_PushButton() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
void SetStates(uint32_t dwStates, FX_BOOL bSet = TRUE) override;
diff --git a/xfa/fwl/core/ifwl_scrollbar.cpp b/xfa/fwl/core/ifwl_scrollbar.cpp
index 27a131f45d..a66baddc74 100644
--- a/xfa/fwl/core/ifwl_scrollbar.cpp
+++ b/xfa/fwl/core/ifwl_scrollbar.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_scrollbar.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/cfwl_message.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
#include "xfa/fwl/core/cfwl_themepart.h"
@@ -51,20 +52,11 @@ IFWL_ScrollBar::IFWL_ScrollBar(const IFWL_App* app,
m_rtMaxBtn.Reset();
m_rtMinTrack.Reset();
m_rtMaxTrack.Reset();
-}
-
-IFWL_ScrollBar::~IFWL_ScrollBar() {}
-void IFWL_ScrollBar::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_ScrollBarImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_ScrollBarImpDelegate>(this));
}
-void IFWL_ScrollBar::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
+IFWL_ScrollBar::~IFWL_ScrollBar() {}
FWL_Type IFWL_ScrollBar::GetClassID() const {
return FWL_Type::ScrollBar;
diff --git a/xfa/fwl/core/ifwl_scrollbar.h b/xfa/fwl/core/ifwl_scrollbar.h
index 346649c11d..5d7fc97920 100644
--- a/xfa/fwl/core/ifwl_scrollbar.h
+++ b/xfa/fwl/core/ifwl_scrollbar.h
@@ -44,8 +44,6 @@ class IFWL_ScrollBar : public IFWL_Widget {
~IFWL_ScrollBar() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error Update() override;
diff --git a/xfa/fwl/core/ifwl_spinbutton.cpp b/xfa/fwl/core/ifwl_spinbutton.cpp
index 992ea7358c..81cff6722b 100644
--- a/xfa/fwl/core/ifwl_spinbutton.cpp
+++ b/xfa/fwl/core/ifwl_spinbutton.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_spinbutton.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fwl/core/cfwl_message.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
#include "xfa/fwl/core/cfwl_widgetimpproperties.h"
@@ -36,20 +37,11 @@ IFWL_SpinButton::IFWL_SpinButton(const IFWL_App* app,
m_rtUpButton.Reset();
m_rtDnButton.Reset();
m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert;
-}
-
-IFWL_SpinButton::~IFWL_SpinButton() {}
-void IFWL_SpinButton::Initialize() {
- IFWL_Widget::Initialize();
- m_pDelegate = new CFWL_SpinButtonImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_SpinButtonImpDelegate>(this));
}
-void IFWL_SpinButton::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
+IFWL_SpinButton::~IFWL_SpinButton() {}
FWL_Type IFWL_SpinButton::GetClassID() const {
return FWL_Type::SpinButton;
diff --git a/xfa/fwl/core/ifwl_spinbutton.h b/xfa/fwl/core/ifwl_spinbutton.h
index ad03098dc6..5bbd7fb23e 100644
--- a/xfa/fwl/core/ifwl_spinbutton.h
+++ b/xfa/fwl/core/ifwl_spinbutton.h
@@ -27,8 +27,6 @@ class IFWL_SpinButton : public IFWL_Widget {
~IFWL_SpinButton() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error Update() override;
diff --git a/xfa/fwl/core/ifwl_tooltip.cpp b/xfa/fwl/core/ifwl_tooltip.cpp
index 815670ed75..371709772e 100644
--- a/xfa/fwl/core/ifwl_tooltip.cpp
+++ b/xfa/fwl/core/ifwl_tooltip.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/core/ifwl_tooltip.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/tto/fde_textout.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
#include "xfa/fwl/core/cfwl_themepart.h"
@@ -29,24 +30,13 @@ IFWL_ToolTip::IFWL_ToolTip(const IFWL_App* app,
m_rtClient.Set(0, 0, 0, 0);
m_rtCaption.Set(0, 0, 0, 0);
m_rtAnchor.Set(0, 0, 0, 0);
-}
-
-IFWL_ToolTip::~IFWL_ToolTip() {}
-
-void IFWL_ToolTip::Initialize() {
- IFWL_Widget::Initialize();
-
- m_pProperties->m_dwStyles |= FWL_WGTSTYLE_Popup;
m_pProperties->m_dwStyles &= ~FWL_WGTSTYLE_Child;
+ m_pProperties->m_dwStyles |= FWL_WGTSTYLE_Popup;
- m_pDelegate = new CFWL_ToolTipImpDelegate(this);
+ SetDelegate(pdfium::MakeUnique<CFWL_ToolTipImpDelegate>(this));
}
-void IFWL_ToolTip::Finalize() {
- delete m_pDelegate;
- m_pDelegate = nullptr;
- IFWL_Widget::Finalize();
-}
+IFWL_ToolTip::~IFWL_ToolTip() {}
FWL_Type IFWL_ToolTip::GetClassID() const {
return FWL_Type::ToolTip;
diff --git a/xfa/fwl/core/ifwl_tooltip.h b/xfa/fwl/core/ifwl_tooltip.h
index fcf1637714..63708a7f5a 100644
--- a/xfa/fwl/core/ifwl_tooltip.h
+++ b/xfa/fwl/core/ifwl_tooltip.h
@@ -40,8 +40,6 @@ class IFWL_ToolTip : public IFWL_Form {
~IFWL_ToolTip() override;
// IFWL_Widget
- void Initialize() override;
- void Finalize() override;
FWL_Type GetClassID() const override;
FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
FWL_Error Update() override;
diff --git a/xfa/fwl/core/ifwl_widget.cpp b/xfa/fwl/core/ifwl_widget.cpp
index da90c4892d..961c02497b 100644
--- a/xfa/fwl/core/ifwl_widget.cpp
+++ b/xfa/fwl/core/ifwl_widget.cpp
@@ -30,7 +30,6 @@ IFWL_Widget::IFWL_Widget(const IFWL_App* app,
: m_pOwnerApp(app),
m_pWidgetMgr(app->GetWidgetMgr()),
m_pProperties(new CFWL_WidgetImpProperties(properties)),
- m_pDelegate(nullptr),
m_pCurDelegate(nullptr),
m_pOuter(pOuter),
m_pLayoutItem(nullptr),
@@ -38,21 +37,18 @@ IFWL_Widget::IFWL_Widget(const IFWL_App* app,
m_iLock(0),
m_nEventKey(0) {
ASSERT(m_pWidgetMgr);
-}
-
-IFWL_Widget::~IFWL_Widget() {}
-void IFWL_Widget::Initialize() {
IFWL_Widget* pParent = m_pProperties->m_pParent;
m_pWidgetMgr->InsertWidget(pParent, this);
- if (!IsChild()) {
- IFWL_Widget* pOwner = m_pProperties->m_pOwner;
- if (pOwner)
- m_pWidgetMgr->SetOwner(pOwner, this);
- }
+ if (IsChild())
+ return;
+
+ IFWL_Widget* pOwner = m_pProperties->m_pOwner;
+ if (pOwner)
+ m_pWidgetMgr->SetOwner(pOwner, this);
}
-void IFWL_Widget::Finalize() {
+IFWL_Widget::~IFWL_Widget() {
NotifyDriver();
m_pWidgetMgr->RemoveWidget(this);
}
@@ -354,7 +350,7 @@ FWL_Error IFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
IFWL_WidgetDelegate* IFWL_Widget::GetCurrentDelegate() {
if (!m_pCurDelegate)
- m_pCurDelegate = m_pDelegate;
+ m_pCurDelegate = m_pDelegate.get();
return m_pCurDelegate;
}
diff --git a/xfa/fwl/core/ifwl_widget.h b/xfa/fwl/core/ifwl_widget.h
index 2b385abc0e..264ff67513 100644
--- a/xfa/fwl/core/ifwl_widget.h
+++ b/xfa/fwl/core/ifwl_widget.h
@@ -66,8 +66,6 @@ class IFWL_Widget {
public:
virtual ~IFWL_Widget();
- virtual void Initialize();
- virtual void Finalize();
virtual FWL_Type GetClassID() const = 0;
virtual FX_BOOL IsInstance(const CFX_WideStringC& wsClass) const;
@@ -203,16 +201,23 @@ class IFWL_Widget {
FX_BOOL IsParent(IFWL_Widget* pParent);
+ void SetDelegate(std::unique_ptr<IFWL_WidgetDelegate> delegate) {
+ m_pDelegate = std::move(delegate);
+ }
+ IFWL_WidgetDelegate* GetDelegate() const { return m_pDelegate.get(); }
+
const IFWL_App* const m_pOwnerApp;
CFWL_WidgetMgr* const m_pWidgetMgr;
std::unique_ptr<CFWL_WidgetImpProperties> m_pProperties;
- IFWL_WidgetDelegate* m_pDelegate;
- IFWL_WidgetDelegate* m_pCurDelegate;
+ IFWL_WidgetDelegate* m_pCurDelegate; // Not owned.
IFWL_Widget* m_pOuter;
void* m_pLayoutItem;
CFWL_Widget* m_pAssociate;
int32_t m_iLock;
uint32_t m_nEventKey;
+
+ private:
+ std::unique_ptr<IFWL_WidgetDelegate> m_pDelegate;
};
class CFWL_WidgetImpDelegate : public IFWL_WidgetDelegate {