summaryrefslogtreecommitdiff
path: root/fpdfsdk/fxedit
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fxedit')
-rw-r--r--fpdfsdk/fxedit/fxet_list.cpp132
-rw-r--r--fpdfsdk/fxedit/fxet_list.h139
2 files changed, 96 insertions, 175 deletions
diff --git a/fpdfsdk/fxedit/fxet_list.cpp b/fpdfsdk/fxedit/fxet_list.cpp
index 6778122b7e..949d99217d 100644
--- a/fpdfsdk/fxedit/fxet_list.cpp
+++ b/fpdfsdk/fxedit/fxet_list.cpp
@@ -15,7 +15,7 @@
#include "fpdfsdk/pdfwindow/cpwl_list_box.h"
#include "third_party/base/stl_util.h"
-CFX_ListItem::CFX_ListItem()
+CFX_ListCtrl::Item::Item()
: m_pEdit(new CFX_Edit),
m_bSelected(false),
m_rcListItem(0.0f, 0.0f, 0.0f, 0.0f) {
@@ -23,50 +23,29 @@ CFX_ListItem::CFX_ListItem()
m_pEdit->Initialize();
}
-CFX_ListItem::~CFX_ListItem() {
-}
+CFX_ListCtrl::Item::~Item() {}
-void CFX_ListItem::SetFontMap(IPVT_FontMap* pFontMap) {
+void CFX_ListCtrl::Item::SetFontMap(IPVT_FontMap* pFontMap) {
m_pEdit->SetFontMap(pFontMap);
}
-CFX_Edit* CFX_ListItem::GetEdit() const {
- return m_pEdit.get();
-}
-
-CFX_Edit_Iterator* CFX_ListItem::GetIterator() const {
+CFX_Edit_Iterator* CFX_ListCtrl::Item::GetIterator() const {
return m_pEdit->GetIterator();
}
-void CFX_ListItem::SetRect(const CFX_FloatRect& rect) {
- m_rcListItem = rect;
-}
-
-CFX_FloatRect CFX_ListItem::GetRect() const {
- return m_rcListItem;
-}
-
-bool CFX_ListItem::IsSelected() const {
- return m_bSelected;
-}
-
-void CFX_ListItem::SetSelect(bool bSelected) {
- m_bSelected = bSelected;
-}
-
-void CFX_ListItem::SetText(const CFX_WideString& text) {
+void CFX_ListCtrl::Item::SetText(const CFX_WideString& text) {
m_pEdit->SetText(text);
}
-void CFX_ListItem::SetFontSize(float fFontSize) {
+void CFX_ListCtrl::Item::SetFontSize(float fFontSize) {
m_pEdit->SetFontSize(fFontSize);
}
-float CFX_ListItem::GetItemHeight() const {
+float CFX_ListCtrl::Item::GetItemHeight() const {
return m_pEdit->GetContentRect().Height();
}
-uint16_t CFX_ListItem::GetFirstChar() const {
+uint16_t CFX_ListCtrl::Item::GetFirstChar() const {
CPVT_Word word;
CFX_Edit_Iterator* pIterator = GetIterator();
pIterator->SetAt(1);
@@ -74,18 +53,10 @@ uint16_t CFX_ListItem::GetFirstChar() const {
return word.Word;
}
-CFX_WideString CFX_ListItem::GetText() const {
+CFX_WideString CFX_ListCtrl::Item::GetText() const {
return m_pEdit->GetText();
}
-CFX_ListContainer::CFX_ListContainer() {}
-
-CFX_ListContainer::~CFX_ListContainer() {}
-
-void CFX_ListContainer::SetPlateRect(const CFX_FloatRect& rect) {
- m_rcPlate = rect;
-}
-
CPLST_Select::CPLST_Select() {}
CPLST_Select::~CPLST_Select() {}
@@ -146,18 +117,14 @@ CFX_ListCtrl::~CFX_ListCtrl() {
Empty();
}
-void CFX_ListCtrl::SetNotify(CPWL_List_Notify* pNotify) {
- m_pNotify = pNotify;
-}
-
CFX_PointF CFX_ListCtrl::InToOut(const CFX_PointF& point) const {
- CFX_FloatRect rcPlate = GetPlateRect();
+ CFX_FloatRect rcPlate = m_rcPlate;
return CFX_PointF(point.x - (m_ptScrollPos.x - rcPlate.left),
point.y - (m_ptScrollPos.y - rcPlate.top));
}
CFX_PointF CFX_ListCtrl::OutToIn(const CFX_PointF& point) const {
- CFX_FloatRect rcPlate = GetPlateRect();
+ CFX_FloatRect rcPlate = m_rcPlate;
return CFX_PointF(point.x + (m_ptScrollPos.x - rcPlate.left),
point.y + (m_ptScrollPos.y - rcPlate.top));
}
@@ -176,6 +143,28 @@ CFX_FloatRect CFX_ListCtrl::OutToIn(const CFX_FloatRect& rect) const {
ptRightTop.y);
}
+CFX_PointF CFX_ListCtrl::InnerToOuter(const CFX_PointF& point) const {
+ return CFX_PointF(point.x + GetBTPoint().x, GetBTPoint().y - point.y);
+}
+
+CFX_PointF CFX_ListCtrl::OuterToInner(const CFX_PointF& point) const {
+ return CFX_PointF(point.x - GetBTPoint().x, GetBTPoint().y - point.y);
+}
+
+CFX_FloatRect CFX_ListCtrl::InnerToOuter(const CFX_FloatRect& rect) const {
+ CFX_PointF ptLeftTop = InnerToOuter(CFX_PointF(rect.left, rect.top));
+ CFX_PointF ptRightBottom = InnerToOuter(CFX_PointF(rect.right, rect.bottom));
+ return CFX_FloatRect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x,
+ ptLeftTop.y);
+}
+
+CFX_FloatRect CFX_ListCtrl::OuterToInner(const CFX_FloatRect& rect) const {
+ CFX_PointF ptLeftTop = OuterToInner(CFX_PointF(rect.left, rect.top));
+ CFX_PointF ptRightBottom = OuterToInner(CFX_PointF(rect.right, rect.bottom));
+ return CFX_FloatRect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x,
+ ptLeftTop.y);
+}
+
void CFX_ListCtrl::OnMouseDown(const CFX_PointF& point,
bool bShift,
bool bCtrl) {
@@ -304,7 +293,7 @@ bool CFX_ListCtrl::OnChar(uint16_t nChar, bool bShift, bool bCtrl) {
}
void CFX_ListCtrl::SetPlateRect(const CFX_FloatRect& rect) {
- CFX_ListContainer::SetPlateRect(rect);
+ m_rcPlate = rect;
m_ptScrollPos.x = rect.left;
SetScrollPos(CFX_PointF(rect.left, rect.top));
ReArrange(0);
@@ -321,18 +310,10 @@ CFX_FloatRect CFX_ListCtrl::GetItemRectInternal(int32_t nIndex) const {
CFX_FloatRect rcItem = m_ListItems[nIndex]->GetRect();
rcItem.left = 0.0f;
- rcItem.right = GetPlateRect().Width();
+ rcItem.right = m_rcPlate.Width();
return InnerToOuter(rcItem);
}
-int32_t CFX_ListCtrl::GetCaret() const {
- return m_nCaretIndex;
-}
-
-int32_t CFX_ListCtrl::GetSelect() const {
- return m_nSelItem;
-}
-
void CFX_ListCtrl::AddString(const CFX_WideString& str) {
AddItem(str);
ReArrange(GetCount() - 1);
@@ -389,7 +370,7 @@ void CFX_ListCtrl::InvalidateItem(int32_t nItemIndex) {
if (nItemIndex == -1) {
if (!m_bNotifyFlag) {
m_bNotifyFlag = true;
- CFX_FloatRect rcRefresh = GetPlateRect();
+ CFX_FloatRect rcRefresh = m_rcPlate;
m_pNotify->IOnInvalidateRect(&rcRefresh);
m_bNotifyFlag = false;
}
@@ -430,7 +411,7 @@ void CFX_ListCtrl::Select(int32_t nItemIndex) {
}
bool CFX_ListCtrl::IsItemVisible(int32_t nItemIndex) const {
- CFX_FloatRect rcPlate = GetPlateRect();
+ CFX_FloatRect rcPlate = m_rcPlate;
CFX_FloatRect rcItem = GetItemRect(nItemIndex);
return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top;
@@ -440,7 +421,7 @@ void CFX_ListCtrl::ScrollToListItem(int32_t nItemIndex) {
if (!IsValid(nItemIndex))
return;
- CFX_FloatRect rcPlate = GetPlateRect();
+ CFX_FloatRect rcPlate = m_rcPlate;
CFX_FloatRect rcItem = GetItemRectInternal(nItemIndex);
CFX_FloatRect rcItemCtrl = GetItemRect(nItemIndex);
@@ -457,7 +438,7 @@ void CFX_ListCtrl::ScrollToListItem(int32_t nItemIndex) {
void CFX_ListCtrl::SetScrollInfo() {
if (m_pNotify) {
- CFX_FloatRect rcPlate = GetPlateRect();
+ CFX_FloatRect rcPlate = m_rcPlate;
CFX_FloatRect rcContent = GetContentRectInternal();
if (!m_bNotifyFlag) {
@@ -476,7 +457,7 @@ void CFX_ListCtrl::SetScrollPos(const CFX_PointF& point) {
void CFX_ListCtrl::SetScrollPosY(float fy) {
if (!IsFloatEqual(m_ptScrollPos.y, fy)) {
- CFX_FloatRect rcPlate = GetPlateRect();
+ CFX_FloatRect rcPlate = m_rcPlate;
CFX_FloatRect rcContent = GetContentRectInternal();
if (rcPlate.Height() > rcContent.Height()) {
@@ -503,7 +484,7 @@ void CFX_ListCtrl::SetScrollPosY(float fy) {
}
CFX_FloatRect CFX_ListCtrl::GetContentRectInternal() const {
- return InnerToOuter(CFX_ListContainer::GetContentRect());
+ return InnerToOuter(m_rcContent);
}
CFX_FloatRect CFX_ListCtrl::GetContentRect() const {
@@ -530,7 +511,6 @@ void CFX_ListCtrl::ReArrange(int32_t nItemIndex) {
void CFX_ListCtrl::SetTopItem(int32_t nIndex) {
if (IsValid(nIndex)) {
- GetPlateRect();
CFX_FloatRect rcItem = GetItemRectInternal(nIndex);
SetScrollPosY(rcItem.top);
}
@@ -581,16 +561,8 @@ CFX_WideString CFX_ListCtrl::GetText() const {
return GetItemText(m_nSelItem);
}
-void CFX_ListCtrl::SetFontMap(IPVT_FontMap* pFontMap) {
- m_pFontMap = pFontMap;
-}
-
-void CFX_ListCtrl::SetFontSize(float fFontSize) {
- m_fFontSize = fFontSize;
-}
-
void CFX_ListCtrl::AddItem(const CFX_WideString& str) {
- auto pListItem = pdfium::MakeUnique<CFX_ListItem>();
+ auto pListItem = pdfium::MakeUnique<Item>();
pListItem->SetFontMap(m_pFontMap.Get());
pListItem->SetFontSize(m_fFontSize);
pListItem->SetText(str);
@@ -607,18 +579,9 @@ int32_t CFX_ListCtrl::GetCount() const {
return pdfium::CollectionSize<int32_t>(m_ListItems);
}
-CFX_FloatRect CFX_ListCtrl::GetPlateRect() const {
- return CFX_ListContainer::GetPlateRect();
-}
-
-float CFX_ListCtrl::GetFontSize() const {
- return m_fFontSize;
-}
-
float CFX_ListCtrl::GetFirstHeight() const {
if (m_ListItems.empty() || !m_ListItems.front())
return 1.0f;
-
return m_ListItems.front()->GetItemHeight();
}
@@ -648,7 +611,7 @@ int32_t CFX_ListCtrl::FindNext(int32_t nIndex, wchar_t nChar) const {
if (nCircleIndex >= sz)
nCircleIndex = 0;
- if (CFX_ListItem* pListItem = m_ListItems[nCircleIndex].get()) {
+ if (Item* pListItem = m_ListItems[nCircleIndex].get()) {
if (FXSYS_toupper(pListItem->GetFirstChar()) == FXSYS_toupper(nChar))
return nCircleIndex;
}
@@ -667,14 +630,6 @@ void CFX_ListCtrl::SetItemSelect(int32_t nIndex, bool bSelected) {
m_ListItems[nIndex]->SetSelect(bSelected);
}
-void CFX_ListCtrl::SetMultipleSel(bool bMultiple) {
- m_bMultiple = bMultiple;
-}
-
-bool CFX_ListCtrl::IsMultipleSel() const {
- return m_bMultiple;
-}
-
bool CFX_ListCtrl::IsValid(int32_t nItemIndex) const {
return pdfium::IndexInBounds(m_ListItems, nItemIndex);
}
@@ -682,6 +637,5 @@ bool CFX_ListCtrl::IsValid(int32_t nItemIndex) const {
CFX_WideString CFX_ListCtrl::GetItemText(int32_t nIndex) const {
if (pdfium::IndexInBounds(m_ListItems, nIndex) && m_ListItems[nIndex])
return m_ListItems[nIndex]->GetText();
-
return L"";
}
diff --git a/fpdfsdk/fxedit/fxet_list.h b/fpdfsdk/fxedit/fxet_list.h
index 6884c69391..2b353a8a46 100644
--- a/fpdfsdk/fxedit/fxet_list.h
+++ b/fpdfsdk/fxedit/fxet_list.h
@@ -19,77 +19,6 @@ class CFX_Edit;
class CFX_Edit_Iterator;
class CPWL_List_Notify;
-class CFX_ListItem final {
- public:
- CFX_ListItem();
- ~CFX_ListItem();
-
- void SetFontMap(IPVT_FontMap* pFontMap);
- CFX_Edit* GetEdit() const;
-
- void SetRect(const CFX_FloatRect& rect);
- void SetSelect(bool bSelected);
- void SetText(const CFX_WideString& text);
- void SetFontSize(float fFontSize);
- CFX_WideString GetText() const;
-
- CFX_FloatRect GetRect() const;
- bool IsSelected() const;
- float GetItemHeight() const;
- uint16_t GetFirstChar() const;
-
- private:
- CFX_Edit_Iterator* GetIterator() const;
-
- std::unique_ptr<CFX_Edit> m_pEdit;
- bool m_bSelected;
- CFX_FloatRect m_rcListItem;
-};
-
-class CFX_ListContainer {
- public:
- CFX_ListContainer();
- virtual ~CFX_ListContainer();
-
- virtual void SetPlateRect(const CFX_FloatRect& rect);
-
- CFX_FloatRect GetPlateRect() const { return m_rcPlate; }
- void SetContentRect(const CFX_FloatRect& rect) { m_rcContent = rect; }
- CFX_FloatRect GetContentRect() const { return m_rcContent; }
- CFX_PointF GetBTPoint() const {
- return CFX_PointF(m_rcPlate.left, m_rcPlate.top);
- }
- CFX_PointF GetETPoint() const {
- return CFX_PointF(m_rcPlate.right, m_rcPlate.bottom);
- }
-
- public:
- CFX_PointF InnerToOuter(const CFX_PointF& point) const {
- return CFX_PointF(point.x + GetBTPoint().x, GetBTPoint().y - point.y);
- }
- CFX_PointF OuterToInner(const CFX_PointF& point) const {
- return CFX_PointF(point.x - GetBTPoint().x, GetBTPoint().y - point.y);
- }
- CFX_FloatRect InnerToOuter(const CFX_FloatRect& rect) const {
- CFX_PointF ptLeftTop = InnerToOuter(CFX_PointF(rect.left, rect.top));
- CFX_PointF ptRightBottom =
- InnerToOuter(CFX_PointF(rect.right, rect.bottom));
- return CFX_FloatRect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x,
- ptLeftTop.y);
- }
- CFX_FloatRect OuterToInner(const CFX_FloatRect& rect) const {
- CFX_PointF ptLeftTop = OuterToInner(CFX_PointF(rect.left, rect.top));
- CFX_PointF ptRightBottom =
- OuterToInner(CFX_PointF(rect.right, rect.bottom));
- return CFX_FloatRect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x,
- ptLeftTop.y);
- }
-
- private:
- CFX_FloatRect m_rcPlate;
- CFX_FloatRect m_rcContent;
-};
-
class CPLST_Select {
public:
enum State { DESELECTING = -1, NORMAL = 0, SELECTING = 1 };
@@ -112,15 +41,12 @@ class CPLST_Select {
std::map<int32_t, State> m_Items;
};
-class CFX_ListCtrl : protected CFX_ListContainer {
+class CFX_ListCtrl {
public:
CFX_ListCtrl();
- ~CFX_ListCtrl() override;
-
- // CFX_ListContainer
- void SetPlateRect(const CFX_FloatRect& rect) override;
+ ~CFX_ListCtrl();
- void SetNotify(CPWL_List_Notify* pNotify);
+ void SetNotify(CPWL_List_Notify* pNotify) { m_pNotify = pNotify; }
void OnMouseDown(const CFX_PointF& point, bool bShift, bool bCtrl);
void OnMouseMove(const CFX_PointF& point, bool bShift, bool bCtrl);
void OnVK_UP(bool bShift, bool bCtrl);
@@ -135,10 +61,15 @@ class CFX_ListCtrl : protected CFX_ListContainer {
void SetScrollPos(const CFX_PointF& point);
void ScrollToListItem(int32_t nItemIndex);
CFX_FloatRect GetItemRect(int32_t nIndex) const;
- int32_t GetCaret() const;
- int32_t GetSelect() const;
+ int32_t GetCaret() const { return m_nCaretIndex; }
+ int32_t GetSelect() const { return m_nSelItem; }
int32_t GetTopItem() const;
+ void SetContentRect(const CFX_FloatRect& rect) { m_rcContent = rect; }
CFX_FloatRect GetContentRect() const;
+ CFX_PointF GetBTPoint() const {
+ return CFX_PointF(m_rcPlate.left, m_rcPlate.top);
+ }
+
int32_t GetItemIndex(const CFX_PointF& point) const;
void AddString(const CFX_WideString& str);
void SetTopItem(int32_t nIndex);
@@ -148,16 +79,18 @@ class CFX_ListCtrl : protected CFX_ListContainer {
void Cancel();
CFX_WideString GetText() const;
- void SetFontMap(IPVT_FontMap* pFontMap);
- void SetFontSize(float fFontSize);
- CFX_FloatRect GetPlateRect() const;
- float GetFontSize() const;
+ void SetFontMap(IPVT_FontMap* pFontMap) { m_pFontMap = pFontMap; }
+ void SetFontSize(float fFontSize) { m_fFontSize = fFontSize; }
+ CFX_FloatRect GetPlateRect() const { return m_rcPlate; }
+ void SetPlateRect(const CFX_FloatRect& rect);
+
+ float GetFontSize() const { return m_fFontSize; }
CFX_Edit* GetItemEdit(int32_t nIndex) const;
int32_t GetCount() const;
bool IsItemSelected(int32_t nIndex) const;
float GetFirstHeight() const;
- void SetMultipleSel(bool bMultiple);
- bool IsMultipleSel() const;
+ void SetMultipleSel(bool bMultiple) { m_bMultiple = bMultiple; }
+ bool IsMultipleSel() const { return m_bMultiple; }
bool IsValid(int32_t nItemIndex) const;
int32_t FindNext(int32_t nIndex, wchar_t nChar) const;
int32_t GetFirstSelected() const;
@@ -167,7 +100,39 @@ class CFX_ListCtrl : protected CFX_ListContainer {
CFX_FloatRect InToOut(const CFX_FloatRect& rect) const;
CFX_FloatRect OutToIn(const CFX_FloatRect& rect) const;
+ CFX_PointF InnerToOuter(const CFX_PointF& point) const;
+ CFX_PointF OuterToInner(const CFX_PointF& point) const;
+ CFX_FloatRect InnerToOuter(const CFX_FloatRect& rect) const;
+ CFX_FloatRect OuterToInner(const CFX_FloatRect& rect) const;
+
private:
+ class Item {
+ public:
+ Item();
+ ~Item();
+
+ void SetFontMap(IPVT_FontMap* pFontMap);
+ CFX_Edit* GetEdit() const { return m_pEdit.get(); }
+
+ void SetRect(const CFX_FloatRect& rect) { m_rcListItem = rect; }
+ void SetSelect(bool bSelected) { m_bSelected = bSelected; }
+ void SetText(const CFX_WideString& text);
+ void SetFontSize(float fFontSize);
+ CFX_WideString GetText() const;
+
+ CFX_FloatRect GetRect() const { return m_rcListItem; }
+ bool IsSelected() const { return m_bSelected; }
+ float GetItemHeight() const;
+ uint16_t GetFirstChar() const;
+
+ private:
+ CFX_Edit_Iterator* GetIterator() const;
+
+ std::unique_ptr<CFX_Edit> m_pEdit;
+ bool m_bSelected;
+ CFX_FloatRect m_rcListItem;
+ };
+
void ReArrange(int32_t nItemIndex);
CFX_FloatRect GetItemRectInternal(int32_t nIndex) const;
CFX_FloatRect GetContentRectInternal() const;
@@ -183,6 +148,8 @@ class CFX_ListCtrl : protected CFX_ListContainer {
void SetItemSelect(int32_t nItemIndex, bool bSelected);
int32_t GetLastSelected() const;
+ CFX_FloatRect m_rcPlate;
+ CFX_FloatRect m_rcContent;
CFX_UnownedPtr<CPWL_List_Notify> m_pNotify;
bool m_bNotifyFlag;
CFX_PointF m_ptScrollPos;
@@ -191,7 +158,7 @@ class CFX_ListCtrl : protected CFX_ListContainer {
int32_t m_nFootIndex; // for multiple
bool m_bCtrlSel; // for multiple
int32_t m_nCaretIndex; // for multiple
- std::vector<std::unique_ptr<CFX_ListItem>> m_ListItems;
+ std::vector<std::unique_ptr<Item>> m_ListItems;
float m_fFontSize;
CFX_UnownedPtr<IPVT_FontMap> m_pFontMap;
bool m_bMultiple;