From 6fe32f898af3eea875fd01a6d18f719d17dd72f3 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 25 Oct 2018 23:25:58 +0000 Subject: Make CPWL_Wnd own its pAttachedData. This requires moving it out of CreateParams, since that must be a copyable struct, and implies that currently there is some questionable sharing going on. To resolve this, introduce a Clone() method so that each window gets its own copy. Make GetAttachedData() return a const pointer, so that callers can't free it behind our back. Tidy initializations along the way. Change-Id: Iadc97688b4692bf4fafefe8cff88af88672f7110 Reviewed-on: https://pdfium-review.googlesource.com/c/44590 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fpdfsdk/pwl/cpwl_combo_box.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'fpdfsdk/pwl/cpwl_combo_box.cpp') diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp index 341bd93e41..bb5890b519 100644 --- a/fpdfsdk/pwl/cpwl_combo_box.cpp +++ b/fpdfsdk/pwl/cpwl_combo_box.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" @@ -26,6 +27,11 @@ constexpr int kDefaultButtonWidth = 13; } // namespace +CPWL_CBListBox::CPWL_CBListBox(std::unique_ptr pAttachedData) + : CPWL_ListBox(std::move(pAttachedData)) {} + +CPWL_CBListBox::~CPWL_CBListBox() = default; + bool CPWL_CBListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { CPWL_Wnd::OnLButtonUp(point, nFlag); @@ -94,6 +100,11 @@ bool CPWL_CBListBox::OnCharNotify(uint16_t nChar, uint32_t nFlag) { return OnNotifySelectionChanged(true, nFlag); } +CPWL_CBButton::CPWL_CBButton(std::unique_ptr pAttachedData) + : CPWL_Wnd(std::move(pAttachedData)) {} + +CPWL_CBButton::~CPWL_CBButton() = default; + void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, const CFX_Matrix& mtUser2Device) { CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device); @@ -132,7 +143,6 @@ bool CPWL_CBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { CPWL_Wnd::OnLButtonDown(point, nFlag); SetCapture(); - if (CPWL_Wnd* pParent = GetParentWindow()) pParent->NotifyLButtonDown(this, point); @@ -143,13 +153,13 @@ bool CPWL_CBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { CPWL_Wnd::OnLButtonUp(point, nFlag); ReleaseCapture(); - return true; } -CPWL_ComboBox::CPWL_ComboBox() {} +CPWL_ComboBox::CPWL_ComboBox(std::unique_ptr pAttachedData) + : CPWL_Wnd(std::move(pAttachedData)) {} -CPWL_ComboBox::~CPWL_ComboBox() {} +CPWL_ComboBox::~CPWL_ComboBox() = default; void CPWL_ComboBox::OnCreate(CreateParams* pParamsToAdjust) { pParamsToAdjust->dwFlags &= ~PWS_HSCROLL; @@ -262,7 +272,7 @@ void CPWL_ComboBox::CreateEdit(const CreateParams& cp) { if (m_pEdit) return; - m_pEdit = new CPWL_Edit(); + m_pEdit = new CPWL_Edit(CloneAttachedData()); m_pEdit->AttachFFLData(m_pFormFiller.Get()); CreateParams ecp = cp; @@ -286,7 +296,7 @@ void CPWL_ComboBox::CreateButton(const CreateParams& cp) { if (m_pButton) return; - m_pButton = new CPWL_CBButton; + m_pButton = new CPWL_CBButton(CloneAttachedData()); CreateParams bcp = cp; bcp.pParentWnd = this; @@ -304,7 +314,7 @@ void CPWL_ComboBox::CreateListBox(const CreateParams& cp) { if (m_pList) return; - m_pList = new CPWL_CBListBox(); + m_pList = new CPWL_CBListBox(CloneAttachedData()); m_pList->AttachFFLData(m_pFormFiller.Get()); CreateParams lcp = cp; -- cgit v1.2.3