From 5d8e5aa882fe8d37d32b71137f039165581ddb82 Mon Sep 17 00:00:00 2001 From: weili Date: Mon, 8 Aug 2016 17:30:37 -0700 Subject: Use virtual function to retrieve interface pointer Use virtual function to return the actual interface type instead of the base interface type to avoid a lot of casts. Also tidy up CFWL_Widget by encapsulating variables, and use smart pointers for class owned member variables. Review-Url: https://codereview.chromium.org/2209153002 --- xfa/fwl/lightwidget/cfwl_checkbox.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'xfa/fwl/lightwidget/cfwl_checkbox.cpp') diff --git a/xfa/fwl/lightwidget/cfwl_checkbox.cpp b/xfa/fwl/lightwidget/cfwl_checkbox.cpp index a93bc4674a..1f59ee148a 100644 --- a/xfa/fwl/lightwidget/cfwl_checkbox.cpp +++ b/xfa/fwl/lightwidget/cfwl_checkbox.cpp @@ -10,6 +10,14 @@ #include "xfa/fwl/core/fwl_error.h" +IFWL_CheckBox* CFWL_CheckBox::GetWidget() { + return static_cast(m_pIface.get()); +} + +const IFWL_CheckBox* CFWL_CheckBox::GetWidget() const { + return static_cast(m_pIface.get()); +} + CFWL_CheckBox* CFWL_CheckBox::Create() { return new CFWL_CheckBox; } @@ -26,7 +34,7 @@ FWL_Error CFWL_CheckBox::Initialize(const CFWL_WidgetProperties* pProperties) { if (ret != FWL_Error::Succeeded) { return ret; } - m_pIface = pCheckBox.release(); + m_pIface = std::move(pCheckBox); CFWL_Widget::Initialize(); return FWL_Error::Succeeded; } @@ -42,11 +50,11 @@ FWL_Error CFWL_CheckBox::SetBoxSize(FX_FLOAT fHeight) { } int32_t CFWL_CheckBox::GetCheckState() { - return static_cast(m_pIface)->GetCheckState(); + return GetWidget()->GetCheckState(); } FWL_Error CFWL_CheckBox::SetCheckState(int32_t iCheck) { - return static_cast(m_pIface)->SetCheckState(iCheck); + return GetWidget()->SetCheckState(iCheck); } CFWL_CheckBox::CFWL_CheckBox() {} -- cgit v1.2.3