From 067990ccf96ae962392a2dbacbfd8348dc4c7676 Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 13 Sep 2016 06:46:40 -0700 Subject: Stop converting widestring -> c_str -> widestring in several places. Avoids a needless alloc and copy. Review-Url: https://codereview.chromium.org/2338553002 --- fpdfsdk/pdfwindow/PWL_ComboBox.cpp | 20 +++++++------------- fpdfsdk/pdfwindow/PWL_ComboBox.h | 5 ++--- fpdfsdk/pdfwindow/PWL_Edit.cpp | 10 ++++------ fpdfsdk/pdfwindow/PWL_Edit.h | 4 ++-- fpdfsdk/pdfwindow/PWL_EditCtrl.cpp | 8 ++++---- fpdfsdk/pdfwindow/PWL_EditCtrl.h | 4 ++-- fpdfsdk/pdfwindow/PWL_ListBox.cpp | 2 +- fpdfsdk/pdfwindow/PWL_ListBox.h | 2 +- fpdfsdk/pdfwindow/PWL_Utils.cpp | 4 ++-- 9 files changed, 25 insertions(+), 34 deletions(-) (limited to 'fpdfsdk/pdfwindow') diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp b/fpdfsdk/pdfwindow/PWL_ComboBox.cpp index ebeb6751a0..c02b268d14 100644 --- a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp +++ b/fpdfsdk/pdfwindow/PWL_ComboBox.cpp @@ -221,12 +221,12 @@ CFX_WideString CPWL_ComboBox::GetText() const { return CFX_WideString(); } -void CPWL_ComboBox::SetText(const FX_WCHAR* text) { +void CPWL_ComboBox::SetText(const CFX_WideString& text) { if (m_pEdit) m_pEdit->SetText(text); } -void CPWL_ComboBox::AddString(const FX_WCHAR* str) { +void CPWL_ComboBox::AddString(const CFX_WideString& str) { if (m_pList) m_pList->AddString(str); } @@ -239,30 +239,26 @@ void CPWL_ComboBox::SetSelect(int32_t nItemIndex) { if (m_pList) m_pList->Select(nItemIndex); - m_pEdit->SetText(m_pList->GetText().c_str()); - + m_pEdit->SetText(m_pList->GetText()); m_nSelectItem = nItemIndex; } void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) { - if (m_pEdit) { + if (m_pEdit) m_pEdit->SetSel(nStartChar, nEndChar); - } } void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const { nStartChar = -1; nEndChar = -1; - if (m_pEdit) { + if (m_pEdit) m_pEdit->GetSel(nStartChar, nEndChar); - } } void CPWL_ComboBox::Clear() { - if (m_pEdit) { + if (m_pEdit) m_pEdit->Clear(); - } } void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) { @@ -619,11 +615,9 @@ FX_BOOL CPWL_ComboBox::IsPopup() const { } void CPWL_ComboBox::SetSelectText() { - CFX_WideString swText = m_pList->GetText(); m_pEdit->SelectAll(); - m_pEdit->ReplaceSel(m_pList->GetText().c_str()); + m_pEdit->ReplaceSel(m_pList->GetText()); m_pEdit->SelectAll(); - m_nSelectItem = m_pList->GetCurSel(); } diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.h b/fpdfsdk/pdfwindow/PWL_ComboBox.h index 02f9d1380a..df9eb5546e 100644 --- a/fpdfsdk/pdfwindow/PWL_ComboBox.h +++ b/fpdfsdk/pdfwindow/PWL_ComboBox.h @@ -69,9 +69,8 @@ class CPWL_ComboBox : public CPWL_Wnd { void SetFillerNotify(IPWL_Filler_Notify* pNotify); CFX_WideString GetText() const; - void SetText(const FX_WCHAR* text); - - void AddString(const FX_WCHAR* str); + void SetText(const CFX_WideString& text); + void AddString(const CFX_WideString& str); int32_t GetSelect() const; void SetSelect(int32_t nItemIndex); diff --git a/fpdfsdk/pdfwindow/PWL_Edit.cpp b/fpdfsdk/pdfwindow/PWL_Edit.cpp index 1aa7b5eb5a..c85993b9cb 100644 --- a/fpdfsdk/pdfwindow/PWL_Edit.cpp +++ b/fpdfsdk/pdfwindow/PWL_Edit.cpp @@ -38,12 +38,10 @@ CFX_ByteString CPWL_Edit::GetClassName() const { void CPWL_Edit::OnDestroy() {} -void CPWL_Edit::SetText(const FX_WCHAR* csText) { +void CPWL_Edit::SetText(const CFX_WideString& csText) { CFX_WideString swText = csText; - if (HasFlag(PES_RICH)) { CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); - if (CXML_Element* pXML = CXML_Element::Parse(sValue.c_str(), sValue.GetLength())) { int32_t nCount = pXML->CountChildren(); @@ -74,7 +72,7 @@ void CPWL_Edit::SetText(const FX_WCHAR* csText) { } } - m_pEdit->SetText(swText.c_str()); + m_pEdit->SetText(swText); } void CPWL_Edit::RePosChildWnd() { @@ -571,9 +569,9 @@ void CPWL_Edit::SetLimitChar(int32_t nLimitChar) { m_pEdit->SetLimitChar(nLimitChar); } -void CPWL_Edit::ReplaceSel(const FX_WCHAR* csText) { +void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) { m_pEdit->Clear(); - m_pEdit->InsertText(csText, DEFAULT_CHARSET); + m_pEdit->InsertText(wsText, DEFAULT_CHARSET); } CFX_FloatRect CPWL_Edit::GetFocusRect() const { diff --git a/fpdfsdk/pdfwindow/PWL_Edit.h b/fpdfsdk/pdfwindow/PWL_Edit.h index df69ebf5d7..568f4805a9 100644 --- a/fpdfsdk/pdfwindow/PWL_Edit.h +++ b/fpdfsdk/pdfwindow/PWL_Edit.h @@ -85,8 +85,8 @@ class CPWL_Edit : public CPWL_EditCtrl { void CutText(); - void SetText(const FX_WCHAR* csText); - void ReplaceSel(const FX_WCHAR* csText); + void SetText(const CFX_WideString& csText); + void ReplaceSel(const CFX_WideString& csText); CFX_ByteString GetTextAppearanceStream(const CFX_FloatPoint& ptOffset) const; CFX_ByteString GetCaretAppearanceStream(const CFX_FloatPoint& ptOffset) const; diff --git a/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp b/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp index febf69e7d0..575fd39089 100644 --- a/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp +++ b/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp @@ -464,8 +464,8 @@ FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const { return fFontSize; } -void CPWL_EditCtrl::SetText(const FX_WCHAR* csText) { - m_pEdit->SetText(csText); +void CPWL_EditCtrl::SetText(const CFX_WideString& wsText) { + m_pEdit->SetText(wsText); } void CPWL_EditCtrl::CopyText() {} @@ -476,9 +476,9 @@ void CPWL_EditCtrl::CutText() {} void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {} -void CPWL_EditCtrl::InsertText(const FX_WCHAR* csText) { +void CPWL_EditCtrl::InsertText(const CFX_WideString& wsText) { if (!IsReadOnly()) - m_pEdit->InsertText(csText, DEFAULT_CHARSET); + m_pEdit->InsertText(wsText, DEFAULT_CHARSET); } void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) { diff --git a/fpdfsdk/pdfwindow/PWL_EditCtrl.h b/fpdfsdk/pdfwindow/PWL_EditCtrl.h index f767d1ba72..8be2b00821 100644 --- a/fpdfsdk/pdfwindow/PWL_EditCtrl.h +++ b/fpdfsdk/pdfwindow/PWL_EditCtrl.h @@ -105,8 +105,8 @@ class CPWL_EditCtrl : public CPWL_Wnd { void IOnInvalidateRect(CFX_FloatRect* pRect); protected: - void InsertText(const FX_WCHAR* csText); - void SetText(const FX_WCHAR* csText); + void InsertText(const CFX_WideString& wsText); + void SetText(const CFX_WideString& wsText); void CopyText(); void PasteText(); void CutText(); diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.cpp b/fpdfsdk/pdfwindow/PWL_ListBox.cpp index 1265a8d446..2b44e29319 100644 --- a/fpdfsdk/pdfwindow/PWL_ListBox.cpp +++ b/fpdfsdk/pdfwindow/PWL_ListBox.cpp @@ -366,7 +366,7 @@ CFX_FloatRect CPWL_ListBox::GetFocusRect() const { return CPWL_Wnd::GetFocusRect(); } -void CPWL_ListBox::AddString(const FX_WCHAR* str) { +void CPWL_ListBox::AddString(const CFX_WideString& str) { m_pList->AddString(str); } diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.h b/fpdfsdk/pdfwindow/PWL_ListBox.h index 91ab7f768f..e42ca24ab4 100644 --- a/fpdfsdk/pdfwindow/PWL_ListBox.h +++ b/fpdfsdk/pdfwindow/PWL_ListBox.h @@ -75,7 +75,7 @@ class CPWL_ListBox : public CPWL_Wnd { void OnNotifySelChanged(FX_BOOL bKeyDown, FX_BOOL& bExit, uint32_t nFlag); - void AddString(const FX_WCHAR* str); + void AddString(const CFX_WideString& str); void SetTopVisibleIndex(int32_t nItemIndex); void ScrollToListItem(int32_t nItemIndex); void ResetContent(); diff --git a/fpdfsdk/pdfwindow/PWL_Utils.cpp b/fpdfsdk/pdfwindow/PWL_Utils.cpp index 0574454c4f..7c7e05af00 100644 --- a/fpdfsdk/pdfwindow/PWL_Utils.cpp +++ b/fpdfsdk/pdfwindow/PWL_Utils.cpp @@ -448,7 +448,7 @@ CFX_ByteString CPWL_Utils::GetTextAppStream(const CFX_FloatRect& rcBBox, pEdit->SetFontSize(fFontSize); pEdit->Initialize(); - pEdit->SetText(sText.c_str()); + pEdit->SetText(sText); CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint(0.0f, 0.0f)); @@ -480,7 +480,7 @@ CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox, pEdit->SetFontSize(fFontSize); pEdit->Initialize(); - pEdit->SetText(sLabel.c_str()); + pEdit->SetText(sLabel); CFX_FloatRect rcLabelContent = pEdit->GetContentRect(); CPWL_Icon Icon; -- cgit v1.2.3