Return a std::pair in various PWL GetSelection() methods.
Replace two out-parameters with a single return value.
Change-Id: Id8bf173e4a5ae010565f53d6a6d2b514a04436bb
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/69130
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp
index 903a9a5..5d6dd61 100644
--- a/fpdfsdk/formfiller/cffl_combobox.cpp
+++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -127,11 +127,7 @@
if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false)) {
if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
fa.bFieldFull = pEdit->IsTextFull();
- int nSelStart = 0;
- int nSelEnd = 0;
- pEdit->GetSelection(nSelStart, nSelEnd);
- fa.nSelEnd = nSelEnd;
- fa.nSelStart = nSelStart;
+ std::tie(fa.nSelStart, fa.nSelEnd) = pEdit->GetSelection();
fa.sValue = pEdit->GetText();
fa.sChangeEx = GetSelectExportText();
@@ -186,7 +182,7 @@
if (!pEdit)
return;
- pEdit->GetSelection(m_State.nStart, m_State.nEnd);
+ std::tie(m_State.nStart, m_State.nEnd) = pEdit->GetSelection();
m_State.sValue = pEdit->GetText();
}
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp
index 9756575..a0d352b 100644
--- a/fpdfsdk/formfiller/cffl_textfield.cpp
+++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -220,7 +220,7 @@
if (!pWnd)
return;
- pWnd->GetSelection(m_State.nStart, m_State.nEnd);
+ std::tie(m_State.nStart, m_State.nEnd) = pWnd->GetSelection();
m_State.sValue = pWnd->GetText();
}
diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp
index a42792a..1f99143 100644
--- a/fpdfsdk/pwl/cpwl_combo_box.cpp
+++ b/fpdfsdk/pwl/cpwl_combo_box.cpp
@@ -253,13 +253,10 @@
m_pEdit->SetSelection(nStartChar, nEndChar);
}
-void CPWL_ComboBox::GetEditSelection(int32_t& nStartChar,
- int32_t& nEndChar) const {
- nStartChar = -1;
- nEndChar = -1;
-
- if (m_pEdit)
- m_pEdit->GetSelection(nStartChar, nEndChar);
+std::pair<int32_t, int32_t> CPWL_ComboBox::GetEditSelection() const {
+ if (!m_pEdit)
+ return std::make_pair(-1, -1);
+ return m_pEdit->GetSelection();
}
void CPWL_ComboBox::ClearSelection() {
diff --git a/fpdfsdk/pwl/cpwl_combo_box.h b/fpdfsdk/pwl/cpwl_combo_box.h
index 66565e2..6f71c71 100644
--- a/fpdfsdk/pwl/cpwl_combo_box.h
+++ b/fpdfsdk/pwl/cpwl_combo_box.h
@@ -8,6 +8,7 @@
#define FPDFSDK_PWL_CPWL_COMBO_BOX_H_
#include <memory>
+#include <utility>
#include "core/fxcrt/unowned_ptr.h"
#include "fpdfsdk/pwl/cpwl_edit.h"
@@ -80,7 +81,7 @@
void SetSelect(int32_t nItemIndex);
void SetEditSelection(int32_t nStartChar, int32_t nEndChar);
- void GetEditSelection(int32_t& nStartChar, int32_t& nEndChar) const;
+ std::pair<int32_t, int32_t> GetEditSelection() const;
void ClearSelection();
void SelectAll();
bool IsPopup() const;
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp
index 20ebb82..a1e4ba9 100644
--- a/fpdfsdk/pwl/cpwl_edit.cpp
+++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -331,14 +331,12 @@
if (!m_pEdit->IsSelected())
return CPVT_WordRange();
- int32_t nStart = -1;
- int32_t nEnd = -1;
-
- m_pEdit->GetSelection(nStart, nEnd);
+ int32_t nStart;
+ int32_t nEnd;
+ std::tie(nStart, nEnd) = m_pEdit->GetSelection();
CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
-
return CPVT_WordRange(wpStart, wpEnd);
}
@@ -419,9 +417,9 @@
WideString strChange;
WideString strChangeEx;
- int nSelStart = 0;
- int nSelEnd = 0;
- GetSelection(nSelStart, nSelEnd);
+ int nSelStart;
+ int nSelEnd;
+ std::tie(nSelStart, nSelEnd) = GetSelection();
if (nSelStart == nSelEnd)
nSelEnd = nSelStart + 1;
@@ -493,9 +491,9 @@
if (m_pFillerNotify) {
WideString swChange;
- int nSelStart = 0;
- int nSelEnd = 0;
- GetSelection(nSelStart, nSelEnd);
+ int nSelStart;
+ int nSelEnd;
+ std::tie(nSelStart, nSelEnd) = GetSelection();
switch (nChar) {
case FWL_VKEY_Back:
diff --git a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
index b5db1df..d62c7c6 100644
--- a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
@@ -340,8 +340,8 @@
m_pEdit->SetSelection(nStartChar, nEndChar);
}
-void CPWL_EditCtrl::GetSelection(int32_t& nStartChar, int32_t& nEndChar) const {
- m_pEdit->GetSelection(nStartChar, nEndChar);
+std::pair<int32_t, int32_t> CPWL_EditCtrl::GetSelection() const {
+ return m_pEdit->GetSelection();
}
void CPWL_EditCtrl::ClearSelection() {
diff --git a/fpdfsdk/pwl/cpwl_edit_ctrl.h b/fpdfsdk/pwl/cpwl_edit_ctrl.h
index dde8cbc..67bd247 100644
--- a/fpdfsdk/pwl/cpwl_edit_ctrl.h
+++ b/fpdfsdk/pwl/cpwl_edit_ctrl.h
@@ -8,6 +8,7 @@
#define FPDFSDK_PWL_CPWL_EDIT_CTRL_H_
#include <memory>
+#include <utility>
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_string.h"
@@ -29,7 +30,7 @@
~CPWL_EditCtrl() override;
void SetSelection(int32_t nStartChar, int32_t nEndChar);
- void GetSelection(int32_t& nStartChar, int32_t& nEndChar) const;
+ std::pair<int32_t, int32_t> GetSelection() const;
void ClearSelection();
void SelectAll();
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.cpp b/fpdfsdk/pwl/cpwl_edit_impl.cpp
index a9ee19e..8dbc9f1 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_impl.cpp
@@ -712,24 +712,20 @@
SetCaretInfo();
}
-void CPWL_EditImpl::GetSelection(int32_t& nStartChar, int32_t& nEndChar) const {
- nStartChar = -1;
- nEndChar = -1;
+std::pair<int32_t, int32_t> CPWL_EditImpl::GetSelection() const {
if (!m_pVT->IsValid())
- return;
+ return std::make_pair(-1, -1);
if (m_SelState.IsEmpty()) {
- nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
- nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
- return;
+ return std::make_pair(m_pVT->WordPlaceToWordIndex(m_wpCaret),
+ m_pVT->WordPlaceToWordIndex(m_wpCaret));
}
if (m_SelState.BeginPos < m_SelState.EndPos) {
- nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
- nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
- return;
+ return std::make_pair(m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos),
+ m_pVT->WordPlaceToWordIndex(m_SelState.EndPos));
}
- nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
- nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
+ return std::make_pair(m_pVT->WordPlaceToWordIndex(m_SelState.EndPos),
+ m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos));
}
int32_t CPWL_EditImpl::GetCaret() const {
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.h b/fpdfsdk/pwl/cpwl_edit_impl.h
index e9ac7de..f16be7e 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.h
+++ b/fpdfsdk/pwl/cpwl_edit_impl.h
@@ -9,6 +9,7 @@
#include <deque>
#include <memory>
+#include <utility>
#include <vector>
#include "core/fpdfdoc/cpdf_variabletext.h"
@@ -330,7 +331,7 @@
WideString GetRangeText(const CPVT_WordRange& range) const;
float GetCharSpace() const;
void SetSelection(int32_t nStartChar, int32_t nEndChar);
- void GetSelection(int32_t& nStartChar, int32_t& nEndChar) const;
+ std::pair<int32_t, int32_t> GetSelection() const;
void SelectAll();
void SelectNone();
bool IsSelected() const;