summaryrefslogtreecommitdiff
path: root/fpdfsdk/fxedit/fxet_list.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-23 14:18:37 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-23 21:32:07 +0000
commit7388470573be4437b0062ec16ba2178bf380790d (patch)
tree2472d139e6e467385ba09d87caa68c896634d731 /fpdfsdk/fxedit/fxet_list.cpp
parent41fdbdf0bc46edd44377a72ff09f12dd68519112 (diff)
downloadpdfium-7388470573be4437b0062ec16ba2178bf380790d.tar.xz
Use std::map<> in CPLST_Select
Replace integer state value with an enum. Change-Id: I78eacf90465692946640ea5a031af03259fd417f Reviewed-on: https://pdfium-review.googlesource.com/3155 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fxedit/fxet_list.cpp')
-rw-r--r--fpdfsdk/fxedit/fxet_list.cpp117
1 files changed, 23 insertions, 94 deletions
diff --git a/fpdfsdk/fxedit/fxet_list.cpp b/fpdfsdk/fxedit/fxet_list.cpp
index b10bb6284b..c10b6a205e 100644
--- a/fpdfsdk/fxedit/fxet_list.cpp
+++ b/fpdfsdk/fxedit/fxet_list.cpp
@@ -6,6 +6,7 @@
#include "fpdfsdk/fxedit/fxet_list.h"
+#include <algorithm>
#include <utility>
#include "core/fpdfdoc/cpvt_word.h"
@@ -86,108 +87,46 @@ void CFX_ListContainer::SetPlateRect(const CFX_FloatRect& rect) {
CPLST_Select::CPLST_Select() {}
-CPLST_Select::~CPLST_Select() {
- for (int32_t i = 0, sz = m_aItems.GetSize(); i < sz; i++)
- delete m_aItems.GetAt(i);
-
- m_aItems.RemoveAll();
-}
+CPLST_Select::~CPLST_Select() {}
void CPLST_Select::Add(int32_t nItemIndex) {
- int32_t nIndex = Find(nItemIndex);
-
- if (nIndex < 0) {
- m_aItems.Add(new CPLST_Select_Item(nItemIndex, 1));
- } else {
- if (CPLST_Select_Item* pItem = m_aItems.GetAt(nIndex)) {
- pItem->nState = 1;
- }
- }
+ m_Items[nItemIndex] = SELECTING;
}
void CPLST_Select::Add(int32_t nBeginIndex, int32_t nEndIndex) {
- if (nBeginIndex > nEndIndex) {
- int32_t nTemp = nEndIndex;
- nEndIndex = nBeginIndex;
- nBeginIndex = nTemp;
- }
+ if (nBeginIndex > nEndIndex)
+ std::swap(nBeginIndex, nEndIndex);
- for (int32_t i = nBeginIndex; i <= nEndIndex; i++)
+ for (int32_t i = nBeginIndex; i <= nEndIndex; ++i)
Add(i);
}
void CPLST_Select::Sub(int32_t nItemIndex) {
- for (int32_t i = m_aItems.GetSize() - 1; i >= 0; i--) {
- if (CPLST_Select_Item* pItem = m_aItems.GetAt(i))
- if (pItem->nItemIndex == nItemIndex)
- pItem->nState = -1;
- }
+ auto it = m_Items.find(nItemIndex);
+ if (it != m_Items.end())
+ it->second = DESELECTING;
}
void CPLST_Select::Sub(int32_t nBeginIndex, int32_t nEndIndex) {
- if (nBeginIndex > nEndIndex) {
- int32_t nTemp = nEndIndex;
- nEndIndex = nBeginIndex;
- nBeginIndex = nTemp;
- }
+ if (nBeginIndex > nEndIndex)
+ std::swap(nBeginIndex, nEndIndex);
- for (int32_t i = nBeginIndex; i <= nEndIndex; i++)
+ for (int32_t i = nBeginIndex; i <= nEndIndex; ++i)
Sub(i);
}
-int32_t CPLST_Select::Find(int32_t nItemIndex) const {
- for (int32_t i = 0, sz = m_aItems.GetSize(); i < sz; i++) {
- if (CPLST_Select_Item* pItem = m_aItems.GetAt(i)) {
- if (pItem->nItemIndex == nItemIndex)
- return i;
- }
- }
-
- return -1;
-}
-
-bool CPLST_Select::IsExist(int32_t nItemIndex) const {
- return Find(nItemIndex) >= 0;
-}
-
-int32_t CPLST_Select::GetCount() const {
- return m_aItems.GetSize();
-}
-
-int32_t CPLST_Select::GetItemIndex(int32_t nIndex) const {
- if (nIndex >= 0 && nIndex < m_aItems.GetSize())
- if (CPLST_Select_Item* pItem = m_aItems.GetAt(nIndex))
- return pItem->nItemIndex;
-
- return -1;
-}
-
-int32_t CPLST_Select::GetState(int32_t nIndex) const {
- if (nIndex >= 0 && nIndex < m_aItems.GetSize())
- if (CPLST_Select_Item* pItem = m_aItems.GetAt(nIndex))
- return pItem->nState;
-
- return 0;
-}
-
void CPLST_Select::DeselectAll() {
- for (int32_t i = 0, sz = m_aItems.GetSize(); i < sz; i++) {
- if (CPLST_Select_Item* pItem = m_aItems.GetAt(i)) {
- pItem->nState = -1;
- }
- }
+ for (auto& item : m_Items)
+ item.second = DESELECTING;
}
void CPLST_Select::Done() {
- for (int32_t i = m_aItems.GetSize() - 1; i >= 0; i--) {
- if (CPLST_Select_Item* pItem = m_aItems.GetAt(i)) {
- if (pItem->nState == -1) {
- delete pItem;
- m_aItems.RemoveAt(i);
- } else {
- pItem->nState = 0;
- }
- }
+ auto it = m_Items.begin();
+ while (it != m_Items.end()) {
+ if (it->second == DESELECTING)
+ it = m_Items.erase(it);
+ else
+ (it++)->second = NORMAL;
}
}
@@ -470,20 +409,10 @@ void CFX_ListCtrl::InvalidateItem(int32_t nItemIndex) {
}
void CFX_ListCtrl::SelectItems() {
- for (int32_t i = 0, sz = m_aSelItems.GetCount(); i < sz; i++) {
- int32_t nItemIndex = m_aSelItems.GetItemIndex(i);
- int32_t nState = m_aSelItems.GetState(i);
-
- switch (nState) {
- case 1:
- SetMultipleSelect(nItemIndex, true);
- break;
- case -1:
- SetMultipleSelect(nItemIndex, false);
- break;
- }
+ for (const auto& item : m_aSelItems) {
+ if (item.second != CPLST_Select::NORMAL)
+ SetMultipleSelect(item.first, item.second == CPLST_Select::SELECTING);
}
-
m_aSelItems.Done();
}