diff options
author | weili <weili@chromium.org> | 2016-08-08 17:30:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-08 17:30:37 -0700 |
commit | 5d8e5aa882fe8d37d32b71137f039165581ddb82 (patch) | |
tree | a0a2b0efa1ee6f8fd06c964f4b9cda5f551c74ae | |
parent | b6befb2ed2485a3805cddea86dc7574510178ea9 (diff) | |
download | pdfium-5d8e5aa882fe8d37d32b71137f039165581ddb82.tar.xz |
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
22 files changed, 292 insertions, 257 deletions
diff --git a/xfa/fwl/lightwidget/cfwl_barcode.cpp b/xfa/fwl/lightwidget/cfwl_barcode.cpp index 2e29d63f34..24dce17fee 100644 --- a/xfa/fwl/lightwidget/cfwl_barcode.cpp +++ b/xfa/fwl/lightwidget/cfwl_barcode.cpp @@ -8,6 +8,14 @@ #include <memory> +IFWL_Barcode* CFWL_Barcode::GetWidget() { + return static_cast<IFWL_Barcode*>(m_pIface.get()); +} + +const IFWL_Barcode* CFWL_Barcode::GetWidget() const { + return static_cast<IFWL_Barcode*>(m_pIface.get()); +} + CFWL_Barcode* CFWL_Barcode::Create() { return new CFWL_Barcode; } @@ -24,7 +32,7 @@ FWL_Error CFWL_Barcode::Initialize(const CFWL_WidgetProperties* pProperties) { if (ret != FWL_Error::Succeeded) { return ret; } - m_pIface = pBarcode.release(); + m_pIface = std::move(pBarcode); CFWL_Widget::Initialize(); return FWL_Error::Succeeded; } @@ -34,15 +42,12 @@ CFWL_Barcode::CFWL_Barcode() {} CFWL_Barcode::~CFWL_Barcode() {} void CFWL_Barcode::SetType(BC_TYPE type) { - if (!m_pIface) - return; - static_cast<IFWL_Barcode*>(m_pIface)->SetType(type); + if (GetWidget()) + GetWidget()->SetType(type); } FX_BOOL CFWL_Barcode::IsProtectedType() { - if (!m_pIface) - return 0; - return static_cast<IFWL_Barcode*>(m_pIface)->IsProtectedType(); + return GetWidget() ? GetWidget()->IsProtectedType() : FALSE; } CFWL_Barcode::CFWL_BarcodeDP::CFWL_BarcodeDP() diff --git a/xfa/fwl/lightwidget/cfwl_barcode.h b/xfa/fwl/lightwidget/cfwl_barcode.h index 466ff6ed09..cf394f6167 100644 --- a/xfa/fwl/lightwidget/cfwl_barcode.h +++ b/xfa/fwl/lightwidget/cfwl_barcode.h @@ -17,6 +17,10 @@ class CFWL_WidgetProperties; class CFWL_Barcode : public CFWL_Edit { public: static CFWL_Barcode* Create(); + + IFWL_Barcode* GetWidget() override; + const IFWL_Barcode* GetWidget() const override; + FWL_Error Initialize(const CFWL_WidgetProperties* pProperties = nullptr); void SetType(BC_TYPE type); FX_BOOL IsProtectedType(); @@ -36,7 +40,7 @@ class CFWL_Barcode : public CFWL_Edit { void SetDataLength(int32_t dataLength) { m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_DATALENGTH; m_barcodeData.m_nDataLength = dataLength; - static_cast<IFWL_Barcode*>(m_pIface)->SetLimit(dataLength); + GetWidget()->SetLimit(dataLength); } void SetCalChecksum(int32_t calChecksum) { m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_CALCHECKSUM; 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<IFWL_CheckBox*>(m_pIface.get()); +} + +const IFWL_CheckBox* CFWL_CheckBox::GetWidget() const { + return static_cast<IFWL_CheckBox*>(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<IFWL_CheckBox*>(m_pIface)->GetCheckState(); + return GetWidget()->GetCheckState(); } FWL_Error CFWL_CheckBox::SetCheckState(int32_t iCheck) { - return static_cast<IFWL_CheckBox*>(m_pIface)->SetCheckState(iCheck); + return GetWidget()->SetCheckState(iCheck); } CFWL_CheckBox::CFWL_CheckBox() {} diff --git a/xfa/fwl/lightwidget/cfwl_checkbox.h b/xfa/fwl/lightwidget/cfwl_checkbox.h index eb23536e25..51e62943dc 100644 --- a/xfa/fwl/lightwidget/cfwl_checkbox.h +++ b/xfa/fwl/lightwidget/cfwl_checkbox.h @@ -15,6 +15,9 @@ class CFWL_CheckBox : public CFWL_Widget { CFWL_CheckBox(); ~CFWL_CheckBox() override; + IFWL_CheckBox* GetWidget() override; + const IFWL_CheckBox* GetWidget() const override; + static CFWL_CheckBox* Create(); FWL_Error Initialize(const CFWL_WidgetProperties* pProperties = nullptr); diff --git a/xfa/fwl/lightwidget/cfwl_combobox.cpp b/xfa/fwl/lightwidget/cfwl_combobox.cpp index 01b64dcd07..678edc40c8 100644 --- a/xfa/fwl/lightwidget/cfwl_combobox.cpp +++ b/xfa/fwl/lightwidget/cfwl_combobox.cpp @@ -11,6 +11,14 @@ #include "xfa/fwl/core/fwl_error.h" #include "xfa/fwl/core/ifwl_widget.h" +IFWL_ComboBox* CFWL_ComboBox::GetWidget() { + return static_cast<IFWL_ComboBox*>(m_pIface.get()); +} + +const IFWL_ComboBox* CFWL_ComboBox::GetWidget() const { + return static_cast<IFWL_ComboBox*>(m_pIface.get()); +} + CFWL_ComboBox* CFWL_ComboBox::Create() { return new CFWL_ComboBox; } @@ -27,7 +35,7 @@ FWL_Error CFWL_ComboBox::Initialize(const CFWL_WidgetProperties* pProperties) { if (ret != FWL_Error::Succeeded) { return ret; } - m_pIface = pComboBox.release(); + m_pIface = std::move(pComboBox); CFWL_Widget::Initialize(); return FWL_Error::Succeeded; } @@ -69,8 +77,8 @@ int32_t CFWL_ComboBox::CountItems() { FWL_Error CFWL_ComboBox::GetTextByIndex(int32_t iIndex, CFX_WideString& wsText) { - CFWL_ComboBoxItem* pItem = - static_cast<CFWL_ComboBoxItem*>(m_comboBoxData.GetItem(m_pIface, iIndex)); + CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( + m_comboBoxData.GetItem(m_pIface.get(), iIndex)); if (!pItem) return FWL_Error::Indefinite; wsText = pItem->m_wsText; @@ -78,78 +86,57 @@ FWL_Error CFWL_ComboBox::GetTextByIndex(int32_t iIndex, } int32_t CFWL_ComboBox::GetCurSel() { - if (!m_pIface) - return -1; - return static_cast<IFWL_ComboBox*>(m_pIface)->GetCurSel(); + return GetWidget() ? GetWidget()->GetCurSel() : -1; } FWL_Error CFWL_ComboBox::SetCurSel(int32_t iSel) { - if (!m_pIface) - return FWL_Error::Indefinite; - return static_cast<IFWL_ComboBox*>(m_pIface)->SetCurSel(iSel); + return GetWidget() ? GetWidget()->SetCurSel(iSel) : FWL_Error::Indefinite; } FWL_Error CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { - if (!m_pIface) - return FWL_Error::Indefinite; - return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditText(wsText); + return GetWidget() ? GetWidget()->SetEditText(wsText) : FWL_Error::Indefinite; } int32_t CFWL_ComboBox::GetEditTextLength() const { - if (!m_pIface) - return 0; - return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditTextLength(); + return GetWidget() ? GetWidget()->GetEditTextLength() : 0; } FWL_Error CFWL_ComboBox::GetEditText(CFX_WideString& wsText, int32_t nStart, int32_t nCount) const { - if (!m_pIface) - return FWL_Error::Indefinite; - return static_cast<IFWL_ComboBox*>(m_pIface) - ->GetEditText(wsText, nStart, nCount); + return GetWidget() ? GetWidget()->GetEditText(wsText, nStart, nCount) + : FWL_Error::Indefinite; } FWL_Error CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { - if (!m_pIface) - return FWL_Error::Indefinite; - return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditSelRange(nStart, nCount); + return GetWidget() ? GetWidget()->SetEditSelRange(nStart, nCount) + : FWL_Error::Indefinite; } int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) { - if (!m_pIface) - return 0; - return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditSelRange(nIndex, nStart); + return GetWidget() ? GetWidget()->GetEditSelRange(nIndex, nStart) : 0; } int32_t CFWL_ComboBox::GetEditLimit() { - if (!m_pIface) - return 0; - return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditLimit(); + return GetWidget() ? GetWidget()->GetEditLimit() : 0; } FWL_Error CFWL_ComboBox::SetEditLimit(int32_t nLimit) { - if (!m_pIface) - return FWL_Error::Indefinite; - return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditLimit(nLimit); + return GetWidget() ? GetWidget()->SetEditLimit(nLimit) + : FWL_Error::Indefinite; } FWL_Error CFWL_ComboBox::EditDoClipboard(int32_t iCmd) { - if (!m_pIface) - return FWL_Error::Indefinite; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditDoClipboard(iCmd); + return GetWidget() ? GetWidget()->EditDoClipboard(iCmd) + : FWL_Error::Indefinite; } FX_BOOL CFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditRedo(pRecord); + return GetWidget() ? GetWidget()->EditRedo(pRecord) : FALSE; } FX_BOOL CFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditUndo(pRecord); + return GetWidget() ? GetWidget()->EditUndo(pRecord) : FALSE; } FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { @@ -158,8 +145,8 @@ FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { } FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { - CFWL_ComboBoxItem* pItem = - static_cast<CFWL_ComboBoxItem*>(m_comboBoxData.GetItem(m_pIface, iIndex)); + CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( + m_comboBoxData.GetItem(m_pIface.get(), iIndex)); if (!pItem) return FWL_Error::Indefinite; pItem->m_pData = pData; @@ -167,114 +154,85 @@ FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { } void* CFWL_ComboBox::GetItemData(int32_t iIndex) { - CFWL_ComboBoxItem* pItem = - static_cast<CFWL_ComboBoxItem*>(m_comboBoxData.GetItem(m_pIface, iIndex)); + CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( + m_comboBoxData.GetItem(m_pIface.get(), iIndex)); return pItem ? pItem->m_pData : nullptr; } FWL_Error CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) { - return static_cast<IFWL_ComboBox*>(m_pIface)->GetListBoxt()->SetThemeProvider( - pTheme); + return GetWidget()->GetListBoxt()->SetThemeProvider(pTheme); } FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() { - return static_cast<IFWL_ComboBox*>(m_pIface)->AfterFocusShowDropList(); + return GetWidget()->AfterFocusShowDropList(); } FWL_Error CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) { - return static_cast<IFWL_ComboBox*>(m_pIface)->OpenDropDownList(bActivate); + return GetWidget()->OpenDropDownList(bActivate); } FX_BOOL CFWL_ComboBox::EditCanUndo() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanUndo(); + return GetWidget() ? GetWidget()->EditCanUndo() : FALSE; } FX_BOOL CFWL_ComboBox::EditCanRedo() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanRedo(); + return GetWidget() ? GetWidget()->EditCanRedo() : FALSE; } FX_BOOL CFWL_ComboBox::EditUndo() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditUndo(); + return GetWidget() ? GetWidget()->EditUndo() : FALSE; } FX_BOOL CFWL_ComboBox::EditRedo() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditRedo(); + return GetWidget() ? GetWidget()->EditRedo() : FALSE; } FX_BOOL CFWL_ComboBox::EditCanCopy() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanCopy(); + return GetWidget() ? GetWidget()->EditCanCopy() : FALSE; } FX_BOOL CFWL_ComboBox::EditCanCut() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanCut(); + return GetWidget() ? GetWidget()->EditCanCut() : FALSE; } FX_BOOL CFWL_ComboBox::EditCanSelectAll() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanSelectAll(); + return GetWidget() ? GetWidget()->EditCanSelectAll() : FALSE; } FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditCopy(wsCopy); + return GetWidget() ? GetWidget()->EditCopy(wsCopy) : FALSE; } FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditCut(wsCut); + return GetWidget() ? GetWidget()->EditCut(wsCut) : FALSE; } FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditPaste(wsPaste); + return GetWidget() ? GetWidget()->EditPaste(wsPaste) : FALSE; } FX_BOOL CFWL_ComboBox::EditSelectAll() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditSelectAll(); + return GetWidget() ? GetWidget()->EditSelectAll() : FALSE; } FX_BOOL CFWL_ComboBox::EditDelete() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditDelete(); + return GetWidget() ? GetWidget()->EditDelete() : FALSE; } FX_BOOL CFWL_ComboBox::EditDeSelect() { - if (!m_pIface) - return FALSE; - return static_cast<IFWL_ComboBox*>(m_pIface)->EditDeSelect(); + return GetWidget() ? GetWidget()->EditDeSelect() : FALSE; } FWL_Error CFWL_ComboBox::GetBBox(CFX_RectF& rect) { - if (!m_pIface) - return FWL_Error::Indefinite; - return static_cast<IFWL_ComboBox*>(m_pIface)->GetBBox(rect); + return GetWidget() ? GetWidget()->GetBBox(rect) : FWL_Error::Indefinite; } FWL_Error CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved) { - if (!m_pIface) - return FWL_Error::Indefinite; - return static_cast<IFWL_ComboBox*>(m_pIface) - ->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); + return GetWidget() + ? GetWidget()->EditModifyStylesEx(dwStylesExAdded, + dwStylesExRemoved) + : FWL_Error::Indefinite; } CFWL_ComboBox::CFWL_ComboBox() {} diff --git a/xfa/fwl/lightwidget/cfwl_combobox.h b/xfa/fwl/lightwidget/cfwl_combobox.h index ab703fe372..186d4b7874 100644 --- a/xfa/fwl/lightwidget/cfwl_combobox.h +++ b/xfa/fwl/lightwidget/cfwl_combobox.h @@ -23,6 +23,9 @@ class CFWL_ComboBox : public CFWL_Widget { CFWL_ComboBox(); ~CFWL_ComboBox() override; + IFWL_ComboBox* GetWidget() override; + const IFWL_ComboBox* GetWidget() const override; + static CFWL_ComboBox* Create(); FWL_Error Initialize(const CFWL_WidgetProperties* pProperties = nullptr); int32_t AddString(const CFX_WideStringC& wsText); diff --git a/xfa/fwl/lightwidget/cfwl_datetimepicker.cpp b/xfa/fwl/lightwidget/cfwl_datetimepicker.cpp index dba1a527b4..1256e1a35d 100644 --- a/xfa/fwl/lightwidget/cfwl_datetimepicker.cpp +++ b/xfa/fwl/lightwidget/cfwl_datetimepicker.cpp @@ -12,6 +12,14 @@ #include "xfa/fwl/core/fwl_error.h" #include "xfa/fwl/core/ifwl_widget.h" +IFWL_DateTimePicker* CFWL_DateTimePicker::GetWidget() { + return static_cast<IFWL_DateTimePicker*>(m_pIface.get()); +} + +const IFWL_DateTimePicker* CFWL_DateTimePicker::GetWidget() const { + return static_cast<IFWL_DateTimePicker*>(m_pIface.get()); +} + CFWL_DateTimePicker* CFWL_DateTimePicker::Create() { return new CFWL_DateTimePicker; } @@ -31,7 +39,7 @@ FWL_Error CFWL_DateTimePicker::Initialize( if (ret != FWL_Error::Succeeded) { return ret; } - m_pIface = pDateTimePicker.release(); + m_pIface = std::move(pDateTimePicker); CFWL_Widget::Initialize(); return FWL_Error::Succeeded; } @@ -46,34 +54,31 @@ FWL_Error CFWL_DateTimePicker::SetToday(int32_t iYear, } int32_t CFWL_DateTimePicker::CountSelRanges() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->CountSelRanges(); + return GetWidget()->CountSelRanges(); } int32_t CFWL_DateTimePicker::GetSelRange(int32_t nIndex, int32_t& nStart) { - return static_cast<IFWL_DateTimePicker*>(m_pIface) - ->GetSelRange(nIndex, nStart); + return GetWidget()->GetSelRange(nIndex, nStart); } FWL_Error CFWL_DateTimePicker::GetEditText(CFX_WideString& wsText) { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->GetEditText(wsText); + return GetWidget()->GetEditText(wsText); } FWL_Error CFWL_DateTimePicker::SetEditText(const CFX_WideString& wsText) { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->SetEditText(wsText); + return GetWidget()->SetEditText(wsText); } FWL_Error CFWL_DateTimePicker::GetCurSel(int32_t& iYear, int32_t& iMonth, int32_t& iDay) { - return static_cast<IFWL_DateTimePicker*>(m_pIface) - ->GetCurSel(iYear, iMonth, iDay); + return GetWidget()->GetCurSel(iYear, iMonth, iDay); } FWL_Error CFWL_DateTimePicker::SetCurSel(int32_t iYear, int32_t iMonth, int32_t iDay) { - return static_cast<IFWL_DateTimePicker*>(m_pIface) - ->SetCurSel(iYear, iMonth, iDay); + return GetWidget()->SetCurSel(iYear, iMonth, iDay); } CFWL_DateTimePicker::CFWL_DateTimePicker() {} @@ -105,67 +110,66 @@ FWL_Error CFWL_DateTimePicker::CFWL_DateTimePickerDP::GetToday( } FX_BOOL CFWL_DateTimePicker::CanUndo() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanUndo(); + return GetWidget()->CanUndo(); } FX_BOOL CFWL_DateTimePicker::CanRedo() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanRedo(); + return GetWidget()->CanRedo(); } FX_BOOL CFWL_DateTimePicker::Undo() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->Undo(); + return GetWidget()->Undo(); } FX_BOOL CFWL_DateTimePicker::Redo() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->Redo(); + return GetWidget()->Redo(); } FX_BOOL CFWL_DateTimePicker::CanCopy() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanCopy(); + return GetWidget()->CanCopy(); } FX_BOOL CFWL_DateTimePicker::CanCut() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanCut(); + return GetWidget()->CanCut(); } FX_BOOL CFWL_DateTimePicker::CanSelectAll() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanSelectAll(); + return GetWidget()->CanSelectAll(); } FX_BOOL CFWL_DateTimePicker::Copy(CFX_WideString& wsCopy) { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->Copy(wsCopy); + return GetWidget()->Copy(wsCopy); } FX_BOOL CFWL_DateTimePicker::Cut(CFX_WideString& wsCut) { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->Copy(wsCut); + return GetWidget()->Copy(wsCut); } FX_BOOL CFWL_DateTimePicker::Paste(const CFX_WideString& wsPaste) { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->Paste(wsPaste); + return GetWidget()->Paste(wsPaste); } FX_BOOL CFWL_DateTimePicker::SelectAll() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->SelectAll(); + return GetWidget()->SelectAll(); } FX_BOOL CFWL_DateTimePicker::Delete() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->Delete(); + return GetWidget()->Delete(); } FX_BOOL CFWL_DateTimePicker::DeSelect() { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->DeSelect(); + return GetWidget()->DeSelect(); } FWL_Error CFWL_DateTimePicker::GetBBox(CFX_RectF& rect) { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->GetBBox(rect); + return GetWidget()->GetBBox(rect); } FWL_Error CFWL_DateTimePicker::SetEditLimit(int32_t nLimit) { - return static_cast<IFWL_DateTimePicker*>(m_pIface)->SetEditLimit(nLimit); + return GetWidget()->SetEditLimit(nLimit); } FWL_Error CFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved) { - return static_cast<IFWL_DateTimePicker*>(m_pIface) - ->ModifyEditStylesEx(dwStylesExAdded, dwStylesExRemoved); + return GetWidget()->ModifyEditStylesEx(dwStylesExAdded, dwStylesExRemoved); } diff --git a/xfa/fwl/lightwidget/cfwl_datetimepicker.h b/xfa/fwl/lightwidget/cfwl_datetimepicker.h index 4348b6cd38..d727729e9d 100644 --- a/xfa/fwl/lightwidget/cfwl_datetimepicker.h +++ b/xfa/fwl/lightwidget/cfwl_datetimepicker.h @@ -14,6 +14,9 @@ class CFWL_DateTimePicker : public CFWL_Widget { public: static CFWL_DateTimePicker* Create(); + IFWL_DateTimePicker* GetWidget() override; + const IFWL_DateTimePicker* GetWidget() const override; + FWL_Error Initialize(const CFWL_WidgetProperties* pProperties = nullptr); FWL_Error SetToday(int32_t iYear, int32_t iMonth, int32_t iDay); FWL_Error GetEditText(CFX_WideString& wsText); diff --git a/xfa/fwl/lightwidget/cfwl_edit.cpp b/xfa/fwl/lightwidget/cfwl_edit.cpp index f1471ea13b..b74cd050a4 100644 --- a/xfa/fwl/lightwidget/cfwl_edit.cpp +++ b/xfa/fwl/lightwidget/cfwl_edit.cpp @@ -9,7 +9,13 @@ #include <memory> #include <vector> -#include "xfa/fwl/basewidget/ifwl_edit.h" +IFWL_Edit* CFWL_Edit::GetWidget() { + return static_cast<IFWL_Edit*>(m_pIface.get()); +} + +const IFWL_Edit* CFWL_Edit::GetWidget() const { + return static_cast<IFWL_Edit*>(m_pIface.get()); +} CFWL_Edit* CFWL_Edit::Create() { return new CFWL_Edit; @@ -27,212 +33,210 @@ FWL_Error CFWL_Edit::Initialize(const CFWL_WidgetProperties* pProperties) { if (ret != FWL_Error::Succeeded) { return ret; } - m_pIface = pEdit.release(); + m_pIface = std::move(pEdit); CFWL_Widget::Initialize(); return FWL_Error::Succeeded; } FWL_Error CFWL_Edit::SetText(const CFX_WideString& wsText) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->SetText(wsText); + return GetWidget()->SetText(wsText); } int32_t CFWL_Edit::GetTextLength() const { - if (!m_pIface) + if (!GetWidget()) return 0; - return static_cast<IFWL_Edit*>(m_pIface)->GetTextLength(); + return GetWidget()->GetTextLength(); } FWL_Error CFWL_Edit::GetText(CFX_WideString& wsText, int32_t nStart, int32_t nCount) const { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->GetText(wsText, nStart, nCount); + return GetWidget()->GetText(wsText, nStart, nCount); } FWL_Error CFWL_Edit::ClearText() { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->ClearText(); + return GetWidget()->ClearText(); } int32_t CFWL_Edit::GetCaretPos() const { - if (!m_pIface) + if (!GetWidget()) return -1; - return static_cast<IFWL_Edit*>(m_pIface)->GetCaretPos(); + return GetWidget()->GetCaretPos(); } int32_t CFWL_Edit::SetCaretPos(int32_t nIndex, FX_BOOL bBefore) { - if (!m_pIface) + if (!GetWidget()) return -1; - return static_cast<IFWL_Edit*>(m_pIface)->SetCaretPos(nIndex, bBefore); + return GetWidget()->SetCaretPos(nIndex, bBefore); } int32_t CFWL_Edit::AddSelRange(int32_t nStart, int32_t nCount) { - if (!m_pIface) + if (!GetWidget()) return -1; - static_cast<IFWL_Edit*>(m_pIface)->AddSelRange(nStart, nCount); + GetWidget()->AddSelRange(nStart, nCount); int32_t pos = 0; - int32_t sum = static_cast<IFWL_Edit*>(m_pIface)->GetTextLength(); + int32_t sum = GetWidget()->GetTextLength(); if (nCount == -1) { pos = sum; } else { pos = nStart + nCount; } - return static_cast<IFWL_Edit*>(m_pIface)->SetCaretPos(pos); + return GetWidget()->SetCaretPos(pos); } int32_t CFWL_Edit::CountSelRanges() { - if (!m_pIface) + if (!GetWidget()) return 0; - return static_cast<IFWL_Edit*>(m_pIface)->CountSelRanges(); + return GetWidget()->CountSelRanges(); } int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t& nStart) { - if (!m_pIface) + if (!GetWidget()) return 0; - return static_cast<IFWL_Edit*>(m_pIface)->GetSelRange(nIndex, nStart); + return GetWidget()->GetSelRange(nIndex, nStart); } FWL_Error CFWL_Edit::ClearSelections() { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->ClearSelections(); + return GetWidget()->ClearSelections(); } int32_t CFWL_Edit::GetLimit() { - if (!m_pIface) + if (!GetWidget()) return -1; - return static_cast<IFWL_Edit*>(m_pIface)->GetLimit(); + return GetWidget()->GetLimit(); } FWL_Error CFWL_Edit::SetLimit(int32_t nLimit) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->SetLimit(nLimit); + return GetWidget()->SetLimit(nLimit); } FWL_Error CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->SetAliasChar(wAlias); + return GetWidget()->SetAliasChar(wAlias); } FWL_Error CFWL_Edit::Insert(int32_t nStart, const FX_WCHAR* lpText, int32_t nLen) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->Insert(nStart, lpText, nLen); + return GetWidget()->Insert(nStart, lpText, nLen); } FWL_Error CFWL_Edit::DeleteSelections() { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->DeleteSelections(); + return GetWidget()->DeleteSelections(); } FWL_Error CFWL_Edit::DeleteRange(int32_t nStart, int32_t nCount) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->DeleteRange(nStart, nCount); + return GetWidget()->DeleteRange(nStart, nCount); } FWL_Error CFWL_Edit::Replace(int32_t nStart, int32_t nLen, const CFX_WideStringC& wsReplace) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->Replace(nStart, nLen, wsReplace); + return GetWidget()->Replace(nStart, nLen, wsReplace); } FWL_Error CFWL_Edit::DoClipboard(int32_t iCmd) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->DoClipboard(iCmd); + return GetWidget()->DoClipboard(iCmd); } FX_BOOL CFWL_Edit::Redo(const IFDE_TxtEdtDoRecord* pRecord) { - return m_pIface && static_cast<IFWL_Edit*>(m_pIface)->Redo(pRecord); + return GetWidget() && GetWidget()->Redo(pRecord); } FX_BOOL CFWL_Edit::Undo(const IFDE_TxtEdtDoRecord* pRecord) { - return m_pIface && static_cast<IFWL_Edit*>(m_pIface)->Undo(pRecord); + return GetWidget() && GetWidget()->Undo(pRecord); } FWL_Error CFWL_Edit::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface) - ->SetTabWidth(fTabWidth, bEquidistant); + return GetWidget()->SetTabWidth(fTabWidth, bEquidistant); } FWL_Error CFWL_Edit::SetNumberRange(int32_t iMin, int32_t iMax) { if (iMin > iMax) { return FWL_Error::ParameterInvalid; } - return static_cast<IFWL_Edit*>(m_pIface)->SetNumberRange(iMin, iMax); + return GetWidget()->SetNumberRange(iMin, iMax); } FWL_Error CFWL_Edit::SetBackColor(uint32_t dwColor) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->SetBackColor(dwColor); + return GetWidget()->SetBackColor(dwColor); } FWL_Error CFWL_Edit::SetFont(const CFX_WideString& wsFont, FX_FLOAT fSize) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_Edit*>(m_pIface)->SetFont(wsFont, fSize); + return GetWidget()->SetFont(wsFont, fSize); } FX_BOOL CFWL_Edit::CanUndo() { - return static_cast<IFWL_Edit*>(m_pIface)->CanUndo(); + return GetWidget()->CanUndo(); } FX_BOOL CFWL_Edit::CanRedo() { - return static_cast<IFWL_Edit*>(m_pIface)->CanRedo(); + return GetWidget()->CanRedo(); } FX_BOOL CFWL_Edit::Undo() { - return static_cast<IFWL_Edit*>(m_pIface)->Undo(); + return GetWidget()->Undo(); } FX_BOOL CFWL_Edit::Redo() { - return static_cast<IFWL_Edit*>(m_pIface)->Undo(); + return GetWidget()->Undo(); } FX_BOOL CFWL_Edit::Copy(CFX_WideString& wsCopy) { - return static_cast<IFWL_Edit*>(m_pIface)->Copy(wsCopy); + return GetWidget()->Copy(wsCopy); } FX_BOOL CFWL_Edit::Cut(CFX_WideString& wsCut) { - return static_cast<IFWL_Edit*>(m_pIface)->Cut(wsCut); + return GetWidget()->Cut(wsCut); } FX_BOOL CFWL_Edit::Paste(const CFX_WideString& wsPaste) { - return static_cast<IFWL_Edit*>(m_pIface)->Paste(wsPaste); + return GetWidget()->Paste(wsPaste); } FX_BOOL CFWL_Edit::Delete() { - return static_cast<IFWL_Edit*>(m_pIface)->Delete(); + return GetWidget()->Delete(); } void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { - return static_cast<IFWL_Edit*>(m_pIface)->SetScrollOffset(fScrollOffset); + return GetWidget()->SetScrollOffset(fScrollOffset); } FX_BOOL CFWL_Edit::GetSuggestWords(CFX_PointF pointf, std::vector<CFX_ByteString>& sSuggest) { - return static_cast<IFWL_Edit*>(m_pIface)->GetSuggestWords(pointf, sSuggest); + return GetWidget()->GetSuggestWords(pointf, sSuggest); } FX_BOOL CFWL_Edit::ReplaceSpellCheckWord(CFX_PointF pointf, const CFX_ByteStringC& bsReplace) { - return static_cast<IFWL_Edit*>(m_pIface) - ->ReplaceSpellCheckWord(pointf, bsReplace); + return GetWidget()->ReplaceSpellCheckWord(pointf, bsReplace); } CFWL_Edit::CFWL_Edit() {} diff --git a/xfa/fwl/lightwidget/cfwl_edit.h b/xfa/fwl/lightwidget/cfwl_edit.h index a6db961a2b..a9a466a49a 100644 --- a/xfa/fwl/lightwidget/cfwl_edit.h +++ b/xfa/fwl/lightwidget/cfwl_edit.h @@ -9,6 +9,7 @@ #include <vector> +#include "xfa/fwl/basewidget/ifwl_edit.h" #include "xfa/fwl/lightwidget/cfwl_widget.h" class CFWL_WidgetProperties; @@ -19,6 +20,9 @@ class CFWL_Edit : public CFWL_Widget { CFWL_Edit(); ~CFWL_Edit() override; + IFWL_Edit* GetWidget() override; + const IFWL_Edit* GetWidget() const override; + static CFWL_Edit* Create(); FWL_Error Initialize(const CFWL_WidgetProperties* pProperties = nullptr); FWL_Error SetText(const CFX_WideString& wsText); diff --git a/xfa/fwl/lightwidget/cfwl_listbox.cpp b/xfa/fwl/lightwidget/cfwl_listbox.cpp index e85e773813..d5ea8797ba 100644 --- a/xfa/fwl/lightwidget/cfwl_listbox.cpp +++ b/xfa/fwl/lightwidget/cfwl_listbox.cpp @@ -10,6 +10,14 @@ #include "third_party/base/stl_util.h" +IFWL_ListBox* CFWL_ListBox::GetWidget() { + return static_cast<IFWL_ListBox*>(m_pIface.get()); +} + +const IFWL_ListBox* CFWL_ListBox::GetWidget() const { + return static_cast<IFWL_ListBox*>(m_pIface.get()); +} + CFWL_ListBox* CFWL_ListBox::Create() { return new CFWL_ListBox; } @@ -26,7 +34,7 @@ FWL_Error CFWL_ListBox::Initialize(const CFWL_WidgetProperties* pProperties) { if (ret != FWL_Error::Succeeded) { return ret; } - m_pIface = pListBox.release(); + m_pIface = std::move(pListBox); CFWL_Widget::Initialize(); return FWL_Error::Succeeded; } @@ -52,7 +60,7 @@ FX_BOOL CFWL_ListBox::DeleteString(IFWL_ListItem* pItem) { static_cast<size_t>(nIndex) >= m_ListBoxDP.m_ItemArray.size()) { return FALSE; } - int32_t iCount = m_ListBoxDP.CountItems(m_pIface); + int32_t iCount = m_ListBoxDP.CountItems(m_pIface.get()); int32_t iSel = nIndex + 1; if (iSel >= iCount) { iSel = nIndex - 1; @@ -62,7 +70,7 @@ FX_BOOL CFWL_ListBox::DeleteString(IFWL_ListItem* pItem) { } if (iSel >= 0) { CFWL_ListItem* pSel = - static_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, iSel)); + static_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface.get(), iSel)); pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected; } m_ListBoxDP.m_ItemArray.erase(m_ListBoxDP.m_ItemArray.begin() + nIndex); @@ -74,40 +82,40 @@ void CFWL_ListBox::DeleteAll() { } int32_t CFWL_ListBox::CountSelItems() { - if (!m_pIface) + if (!GetWidget()) return 0; - return static_cast<IFWL_ListBox*>(m_pIface)->CountSelItems(); + return GetWidget()->CountSelItems(); } IFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) { - if (!m_pIface) + if (!GetWidget()) return nullptr; - return static_cast<IFWL_ListBox*>(m_pIface)->GetSelItem(nIndexSel); + return GetWidget()->GetSelItem(nIndexSel); } int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { - if (!m_pIface) + if (!GetWidget()) return 0; - return static_cast<IFWL_ListBox*>(m_pIface)->GetSelIndex(nIndex); + return GetWidget()->GetSelIndex(nIndex); } FWL_Error CFWL_ListBox::SetSelItem(IFWL_ListItem* pItem, FX_BOOL bSelect) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_ListBox*>(m_pIface)->SetSelItem(pItem, bSelect); + return GetWidget()->SetSelItem(pItem, bSelect); } FWL_Error CFWL_ListBox::GetItemText(IFWL_ListItem* pItem, CFX_WideString& wsText) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_ListBox*>(m_pIface)->GetItemText(pItem, wsText); + return GetWidget()->GetItemText(pItem, wsText); } FWL_Error CFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) { - if (!m_pIface) + if (!GetWidget()) return FWL_Error::Indefinite; - return static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fPos, bVert); + return GetWidget()->GetScrollPos(fPos, bVert); } FWL_Error CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) { @@ -169,13 +177,13 @@ void* CFWL_ListBox::GetItemData(IFWL_ListItem* pItem) { IFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { CFX_RectF rtClient; - m_pIface->GetClientRect(rtClient); + GetWidget()->GetClientRect(rtClient); fx -= rtClient.left; fy -= rtClient.top; FX_FLOAT fPosX = 0; FX_FLOAT fPosY = 0; - static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fx); - static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fy, FALSE); + GetWidget()->GetScrollPos(fx); + GetWidget()->GetScrollPos(fy, FALSE); int32_t nCount = m_ListBoxDP.CountItems(nullptr); for (int32_t i = 0; i < nCount; i++) { IFWL_ListItem* pItem = m_ListBoxDP.GetItem(nullptr, i); diff --git a/xfa/fwl/lightwidget/cfwl_listbox.h b/xfa/fwl/lightwidget/cfwl_listbox.h index 725a7248a1..f647ae8d56 100644 --- a/xfa/fwl/lightwidget/cfwl_listbox.h +++ b/xfa/fwl/lightwidget/cfwl_listbox.h @@ -22,6 +22,9 @@ class CFWL_ListBox : public CFWL_Widget { CFWL_ListBox(); ~CFWL_ListBox() override; + IFWL_ListBox* GetWidget() override; + const IFWL_ListBox* GetWidget() const override; + static CFWL_ListBox* Create(); FWL_Error Initialize(const CFWL_WidgetProperties* pProperties = nullptr); FWL_Error AddDIBitmap(CFX_DIBitmap* pDIB, IFWL_ListItem* pItem); diff --git a/xfa/fwl/lightwidget/cfwl_picturebox.cpp b/xfa/fwl/lightwidget/cfwl_picturebox.cpp index 33b11cd8b5..8e0cc60b09 100644 --- a/xfa/fwl/lightwidget/cfwl_picturebox.cpp +++ b/xfa/fwl/lightwidget/cfwl_picturebox.cpp @@ -8,6 +8,14 @@ #include <memory> +IFWL_PictureBox* CFWL_PictureBox::GetWidget() { + return static_cast<IFWL_PictureBox*>(m_pIface.get()); +} + +const IFWL_PictureBox* CFWL_PictureBox::GetWidget() const { + return static_cast<IFWL_PictureBox*>(m_pIface.get()); +} + CFWL_PictureBox* CFWL_PictureBox::Create() { return new CFWL_PictureBox; } @@ -25,7 +33,7 @@ FWL_Error CFWL_PictureBox::Initialize( if (ret != FWL_Error::Succeeded) { return ret; } - m_pIface = pPictureBox.release(); + m_pIface = std::move(pPictureBox); CFWL_Widget::Initialize(); return FWL_Error::Succeeded; } @@ -49,7 +57,7 @@ FWL_Error CFWL_PictureBox::SetRotation(FX_FLOAT fRotation) { } int32_t CFWL_PictureBox::GetFlipMode() { - return m_PictureBoxDP.GetFlipMode(m_pIface); + return m_PictureBoxDP.GetFlipMode(m_pIface.get()); } FWL_Error CFWL_PictureBox::SetFlipMode(int32_t iFlipMode) { @@ -58,7 +66,7 @@ FWL_Error CFWL_PictureBox::SetFlipMode(int32_t iFlipMode) { } int32_t CFWL_PictureBox::GetOpacity() { - return m_PictureBoxDP.GetOpacity(m_pIface); + return m_PictureBoxDP.GetOpacity(m_pIface.get()); } FWL_Error CFWL_PictureBox::SetOpacity(int32_t iOpacity) { @@ -68,7 +76,7 @@ FWL_Error CFWL_PictureBox::SetOpacity(int32_t iOpacity) { FWL_Error CFWL_PictureBox::GetScale(FX_FLOAT& fScaleX, FX_FLOAT& fScaleY) { CFX_Matrix matrix; - m_PictureBoxDP.GetMatrix(m_pIface, matrix); + m_PictureBoxDP.GetMatrix(m_pIface.get(), matrix); matrix.Scale(fScaleX, fScaleY); return FWL_Error::Succeeded; } @@ -81,7 +89,7 @@ FWL_Error CFWL_PictureBox::SetScale(FX_FLOAT fScaleX, FX_FLOAT fScaleY) { FWL_Error CFWL_PictureBox::GetOffset(FX_FLOAT& fx, FX_FLOAT& fy) { CFX_Matrix matrix; - m_PictureBoxDP.GetMatrix(m_pIface, matrix); + m_PictureBoxDP.GetMatrix(m_pIface.get(), matrix); fx = matrix.e; fy = matrix.f; return FWL_Error::Succeeded; diff --git a/xfa/fwl/lightwidget/cfwl_picturebox.h b/xfa/fwl/lightwidget/cfwl_picturebox.h index ffc67f4446..612ff1d84d 100644 --- a/xfa/fwl/lightwidget/cfwl_picturebox.h +++ b/xfa/fwl/lightwidget/cfwl_picturebox.h @@ -16,6 +16,9 @@ class CFWL_PictureBox : public CFWL_Widget { CFWL_PictureBox(); ~CFWL_PictureBox() override; + IFWL_PictureBox* GetWidget() override; + const IFWL_PictureBox* GetWidget() const override; + static CFWL_PictureBox* Create(); FWL_Error Initialize(const CFWL_WidgetProperties* pProperties = nullptr); diff --git a/xfa/fwl/lightwidget/cfwl_pushbutton.cpp b/xfa/fwl/lightwidget/cfwl_pushbutton.cpp index 7c8a9fa64d..b1031692dd 100644 --- a/xfa/fwl/lightwidget/cfwl_pushbutton.cpp +++ b/xfa/fwl/lightwidget/cfwl_pushbutton.cpp @@ -8,6 +8,14 @@ #include <memory> +IFWL_PushButton* CFWL_PushButton::GetWidget() { + return static_cast<IFWL_PushButton*>(m_pIface.get()); +} + +const IFWL_PushButton* CFWL_PushButton::GetWidget() const { + return static_cast<IFWL_PushButton*>(m_pIface.get()); +} + CFWL_PushButton* CFWL_PushButton::Create() { return new CFWL_PushButton; } @@ -25,7 +33,7 @@ FWL_Error CFWL_PushButton::Initialize( if (ret != FWL_Error::Succeeded) { return ret; } - m_pIface = pPushButton.release(); + m_pIface = std::move(pPushButton); CFWL_Widget::Initialize(); return FWL_Error::Succeeded; } diff --git a/xfa/fwl/lightwidget/cfwl_pushbutton.h b/xfa/fwl/lightwidget/cfwl_pushbutton.h index c2b71681c2..ce26a54655 100644 --- a/xfa/fwl/lightwidget/cfwl_pushbutton.h +++ b/xfa/fwl/lightwidget/cfwl_pushbutton.h @@ -15,6 +15,9 @@ class CFWL_PushButton : public CFWL_Widget { CFWL_PushButton(); ~CFWL_PushButton() override; + IFWL_PushButton* GetWidget() override; + const IFWL_PushButton* GetWidget() const override; + static CFWL_PushButton* Create(); FWL_Error Initialize(const CFWL_WidgetProperties* pProperties = nullptr); diff --git a/xfa/fwl/lightwidget/cfwl_widget.cpp b/xfa/fwl/lightwidget/cfwl_widget.cpp index 8022f0afb0..3a5478a433 100644 --- a/xfa/fwl/lightwidget/cfwl_widget.cpp +++ b/xfa/fwl/lightwidget/cfwl_widget.cpp @@ -20,7 +20,11 @@ #define FWL_WGT_CalcMultiLineDefWidth 120.0f IFWL_Widget* CFWL_Widget::GetWidget() { - return m_pIface; + return m_pIface.get(); +} + +const IFWL_Widget* CFWL_Widget::GetWidget() const { + return m_pIface.get(); } FWL_Error CFWL_Widget::GetClassName(CFX_WideString& wsClass) const { @@ -208,18 +212,15 @@ IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { } CFWL_Widget::CFWL_Widget() - : m_pIface(nullptr), m_pDelegate(nullptr), m_pProperties(nullptr) { - m_pProperties = new CFWL_WidgetProperties; - m_pWidgetMgr = CFWL_WidgetMgr::GetInstance(); + : m_pDelegate(nullptr), + m_pWidgetMgr(CFWL_WidgetMgr::GetInstance()), + m_pProperties(new CFWL_WidgetProperties) { ASSERT(m_pWidgetMgr); } CFWL_Widget::~CFWL_Widget() { - delete m_pProperties; - if (m_pIface) { + if (m_pIface) m_pIface->Finalize(); - delete m_pIface; - } } FWL_Error CFWL_Widget::Repaint(const CFX_RectF* pRect) { @@ -233,7 +234,7 @@ FWL_Error CFWL_Widget::Repaint(const CFX_RectF* pRect) { m_pIface->GetWidgetRect(rect); rect.left = rect.top = 0; } - return m_pWidgetMgr->RepaintWidget(m_pIface, &rect); + return m_pWidgetMgr->RepaintWidget(m_pIface.get(), &rect); } FWL_Error CFWL_Widget::SetFocus(FX_BOOL bFocus) { @@ -249,9 +250,9 @@ FWL_Error CFWL_Widget::SetFocus(FX_BOOL bFocus) { return FWL_Error::Indefinite; if (bFocus) { - pDriver->SetFocus(m_pIface); + pDriver->SetFocus(m_pIface.get()); } else { - if (pDriver->GetFocus() == m_pIface) { + if (pDriver->GetFocus() == m_pIface.get()) { pDriver->SetFocus(nullptr); } } @@ -270,7 +271,7 @@ FWL_Error CFWL_Widget::SetGrab(FX_BOOL bSet) { if (!pDriver) return FWL_Error::Indefinite; - pDriver->SetGrab(m_pIface, bSet); + pDriver->SetGrab(m_pIface.get(), bSet); return FWL_Error::Succeeded; } @@ -320,7 +321,7 @@ CFX_SizeF CFWL_Widget::CalcTextSize(const CFX_WideString& wsText, return CFX_SizeF(); CFWL_ThemeText calPart; - calPart.m_pWidget = m_pIface; + calPart.m_pWidget = m_pIface.get(); calPart.m_wsText = wsText; calPart.m_dwTTOStyles = bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; diff --git a/xfa/fwl/lightwidget/cfwl_widget.h b/xfa/fwl/lightwidget/cfwl_widget.h index 2c180bad8f..80e278e161 100644 --- a/xfa/fwl/lightwidget/cfwl_widget.h +++ b/xfa/fwl/lightwidget/cfwl_widget.h @@ -7,6 +7,8 @@ #ifndef XFA_FWL_LIGHTWIDGET_CFWL_WIDGET_H_ #define XFA_FWL_LIGHTWIDGET_CFWL_WIDGET_H_ +#include <memory> + #include "xfa/fwl/core/cfwl_event.h" #include "xfa/fwl/lightwidget/cfwl_widgetproperties.h" #include "xfa/fwl/core/ifwl_widget.h" @@ -21,7 +23,9 @@ class CFWL_Widget { public: virtual ~CFWL_Widget(); - IFWL_Widget* GetWidget(); + virtual IFWL_Widget* GetWidget(); + virtual const IFWL_Widget* GetWidget() const; + FWL_Error GetClassName(CFX_WideString& wsClass) const; FWL_Type GetClassID() const; virtual FX_BOOL IsInstance(const CFX_WideStringC& wsClass) const; @@ -70,13 +74,14 @@ class CFWL_Widget { CFX_SizeF CalcTextSize(const CFX_WideString& wsText, FX_BOOL bMultiLine = FALSE, int32_t iLineWidth = -1); - IFWL_Widget* m_pIface; - IFWL_WidgetDelegate* m_pDelegate; - CFWL_WidgetMgr* m_pWidgetMgr; - CFWL_WidgetProperties* m_pProperties; protected: FWL_Error Initialize(const CFWL_WidgetProperties* pProperties = nullptr); + + std::unique_ptr<IFWL_Widget> m_pIface; + IFWL_WidgetDelegate* m_pDelegate; + CFWL_WidgetMgr* const m_pWidgetMgr; + std::unique_ptr<CFWL_WidgetProperties> m_pProperties; }; #endif // XFA_FWL_LIGHTWIDGET_CFWL_WIDGET_H_ diff --git a/xfa/fxfa/app/xfa_ffcheckbutton.cpp b/xfa/fxfa/app/xfa_ffcheckbutton.cpp index 253cbd0025..5b651b6561 100644 --- a/xfa/fxfa/app/xfa_ffcheckbutton.cpp +++ b/xfa/fxfa/app/xfa_ffcheckbutton.cpp @@ -248,7 +248,7 @@ FX_BOOL CXFA_FFCheckButton::OnLButtonUp(uint32_t dwFlags, ms.m_fx = fx; ms.m_fy = fy; FWLToClient(ms.m_fx, ms.m_fy); - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } diff --git a/xfa/fxfa/app/xfa_fffield.cpp b/xfa/fxfa/app/xfa_fffield.cpp index 66520b2738..3274477005 100644 --- a/xfa/fxfa/app/xfa_fffield.cpp +++ b/xfa/fxfa/app/xfa_fffield.cpp @@ -110,7 +110,7 @@ void CXFA_FFField::DrawFocus(CFX_Graphics* pGS, CFX_Matrix* pMatrix) { } void CXFA_FFField::SetFWLThemeProvider() { if (m_pNormalWidget) { - m_pNormalWidget->m_pIface->SetThemeProvider(GetApp()->GetFWLTheme()); + m_pNormalWidget->GetWidget()->SetThemeProvider(GetApp()->GetFWLTheme()); } } FX_BOOL CXFA_FFField::IsLoaded() { @@ -349,7 +349,7 @@ FX_BOOL CXFA_FFField::OnMouseEnter() { } CFWL_MsgMouse ms; ms.m_dwCmd = FWL_MouseCommand::Enter; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); ms.m_pSrcTarget = nullptr; TranslateFWLMessage(&ms); return TRUE; @@ -360,7 +360,7 @@ FX_BOOL CXFA_FFField::OnMouseExit() { } CFWL_MsgMouse ms; ms.m_dwCmd = FWL_MouseCommand::Leave; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } @@ -393,7 +393,7 @@ FX_BOOL CXFA_FFField::OnLButtonDown(uint32_t dwFlags, ms.m_fx = fx; ms.m_fy = fy; FWLToClient(ms.m_fx, ms.m_fy); - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } @@ -411,7 +411,7 @@ FX_BOOL CXFA_FFField::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { ms.m_fx = fx; ms.m_fy = fy; FWLToClient(ms.m_fx, ms.m_fy); - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } @@ -427,7 +427,7 @@ FX_BOOL CXFA_FFField::OnLButtonDblClk(uint32_t dwFlags, ms.m_fx = fx; ms.m_fy = fy; FWLToClient(ms.m_fx, ms.m_fy); - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } @@ -441,7 +441,7 @@ FX_BOOL CXFA_FFField::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { ms.m_fx = fx; ms.m_fy = fy; FWLToClient(ms.m_fx, ms.m_fy); - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } @@ -459,7 +459,7 @@ FX_BOOL CXFA_FFField::OnMouseWheel(uint32_t dwFlags, FWLToClient(ms.m_fx, ms.m_fy); ms.m_fDeltaX = zDelta; ms.m_fDeltaY = 0; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } @@ -483,7 +483,7 @@ FX_BOOL CXFA_FFField::OnRButtonDown(uint32_t dwFlags, ms.m_fx = fx; ms.m_fy = fy; FWLToClient(ms.m_fx, ms.m_fy); - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } @@ -501,7 +501,7 @@ FX_BOOL CXFA_FFField::OnRButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { ms.m_fx = fx; ms.m_fy = fy; FWLToClient(ms.m_fx, ms.m_fy); - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } @@ -517,7 +517,7 @@ FX_BOOL CXFA_FFField::OnRButtonDblClk(uint32_t dwFlags, ms.m_fx = fx; ms.m_fy = fy; FWLToClient(ms.m_fx, ms.m_fy); - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); TranslateFWLMessage(&ms); return TRUE; } @@ -528,7 +528,7 @@ FX_BOOL CXFA_FFField::OnSetFocus(CXFA_FFWidget* pOldWidget) { return FALSE; } CFWL_MsgSetFocus ms; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); ms.m_pSrcTarget = nullptr; TranslateFWLMessage(&ms); m_dwStatus |= XFA_WidgetStatus_Focused; @@ -540,7 +540,7 @@ FX_BOOL CXFA_FFField::OnKillFocus(CXFA_FFWidget* pNewWidget) { return CXFA_FFWidget::OnKillFocus(pNewWidget); } CFWL_MsgKillFocus ms; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); ms.m_pSrcTarget = nullptr; TranslateFWLMessage(&ms); m_dwStatus &= ~XFA_WidgetStatus_Focused; @@ -556,7 +556,7 @@ FX_BOOL CXFA_FFField::OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) { ms.m_dwCmd = FWL_KeyCommand::KeyDown; ms.m_dwFlags = dwFlags; ms.m_dwKeyCode = dwKeyCode; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); ms.m_pSrcTarget = nullptr; TranslateFWLMessage(&ms); return TRUE; @@ -569,7 +569,7 @@ FX_BOOL CXFA_FFField::OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) { ms.m_dwCmd = FWL_KeyCommand::KeyUp; ms.m_dwFlags = dwFlags; ms.m_dwKeyCode = dwKeyCode; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); ms.m_pSrcTarget = nullptr; TranslateFWLMessage(&ms); return TRUE; @@ -591,7 +591,7 @@ FX_BOOL CXFA_FFField::OnChar(uint32_t dwChar, uint32_t dwFlags) { ms.m_dwCmd = FWL_KeyCommand::Char; ms.m_dwFlags = dwFlags; ms.m_dwKeyCode = dwChar; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); ms.m_pSrcTarget = nullptr; TranslateFWLMessage(&ms); return TRUE; diff --git a/xfa/fxfa/app/xfa_ffimageedit.cpp b/xfa/fxfa/app/xfa_ffimageedit.cpp index 85e464d40a..77de97019b 100644 --- a/xfa/fxfa/app/xfa_ffimageedit.cpp +++ b/xfa/fxfa/app/xfa_ffimageedit.cpp @@ -97,7 +97,7 @@ FX_BOOL CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags, ms.m_dwFlags = dwFlags; ms.m_fx = fx; ms.m_fy = fy; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); FWLToClient(ms.m_fx, ms.m_fy); TranslateFWLMessage(&ms); return TRUE; diff --git a/xfa/fxfa/app/xfa_fftextedit.cpp b/xfa/fxfa/app/xfa_fftextedit.cpp index 398cf87cd8..6df4507e22 100644 --- a/xfa/fxfa/app/xfa_fftextedit.cpp +++ b/xfa/fxfa/app/xfa_fftextedit.cpp @@ -111,7 +111,7 @@ FX_BOOL CXFA_FFTextEdit::OnLButtonDown(uint32_t dwFlags, ms.m_dwFlags = dwFlags; ms.m_fx = fx; ms.m_fy = fy; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); FWLToClient(ms.m_fx, ms.m_fy); TranslateFWLMessage(&ms); return TRUE; @@ -158,14 +158,14 @@ FX_BOOL CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) { } CXFA_FFWidget::OnSetFocus(pOldWidget); CFWL_MsgSetFocus ms; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); ms.m_pSrcTarget = nullptr; TranslateFWLMessage(&ms); return TRUE; } FX_BOOL CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { CFWL_MsgKillFocus ms; - ms.m_pDstTarget = m_pNormalWidget->m_pIface; + ms.m_pDstTarget = m_pNormalWidget->GetWidget(); ms.m_pSrcTarget = nullptr; TranslateFWLMessage(&ms); m_dwStatus &= ~XFA_WidgetStatus_Focused; |