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 /xfa/fwl/lightwidget/cfwl_edit.cpp | |
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
Diffstat (limited to 'xfa/fwl/lightwidget/cfwl_edit.cpp')
-rw-r--r-- | xfa/fwl/lightwidget/cfwl_edit.cpp | 128 |
1 files changed, 66 insertions, 62 deletions
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() {} |