Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: xfa/fwl/lightwidget/cfwl_listbox.cpp

Issue 2209153002: Use virtual function to retrieve interface pointer (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/lightwidget/cfwl_listbox.h ('k') | xfa/fwl/lightwidget/cfwl_picturebox.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fwl/lightwidget/cfwl_listbox.h" 7 #include "xfa/fwl/lightwidget/cfwl_listbox.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "third_party/base/stl_util.h" 11 #include "third_party/base/stl_util.h"
12 12
13 IFWL_ListBox* CFWL_ListBox::GetWidget() {
14 return static_cast<IFWL_ListBox*>(m_pIface.get());
15 }
16
17 const IFWL_ListBox* CFWL_ListBox::GetWidget() const {
18 return static_cast<IFWL_ListBox*>(m_pIface.get());
19 }
20
13 CFWL_ListBox* CFWL_ListBox::Create() { 21 CFWL_ListBox* CFWL_ListBox::Create() {
14 return new CFWL_ListBox; 22 return new CFWL_ListBox;
15 } 23 }
16 24
17 FWL_Error CFWL_ListBox::Initialize(const CFWL_WidgetProperties* pProperties) { 25 FWL_Error CFWL_ListBox::Initialize(const CFWL_WidgetProperties* pProperties) {
18 if (m_pIface) 26 if (m_pIface)
19 return FWL_Error::Indefinite; 27 return FWL_Error::Indefinite;
20 if (pProperties) { 28 if (pProperties) {
21 *m_pProperties = *pProperties; 29 *m_pProperties = *pProperties;
22 } 30 }
23 std::unique_ptr<IFWL_ListBox> pListBox(IFWL_ListBox::Create( 31 std::unique_ptr<IFWL_ListBox> pListBox(IFWL_ListBox::Create(
24 m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr)); 32 m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr));
25 FWL_Error ret = pListBox->Initialize(); 33 FWL_Error ret = pListBox->Initialize();
26 if (ret != FWL_Error::Succeeded) { 34 if (ret != FWL_Error::Succeeded) {
27 return ret; 35 return ret;
28 } 36 }
29 m_pIface = pListBox.release(); 37 m_pIface = std::move(pListBox);
30 CFWL_Widget::Initialize(); 38 CFWL_Widget::Initialize();
31 return FWL_Error::Succeeded; 39 return FWL_Error::Succeeded;
32 } 40 }
33 41
34 FWL_Error CFWL_ListBox::AddDIBitmap(CFX_DIBitmap* pDIB, IFWL_ListItem* pItem) { 42 FWL_Error CFWL_ListBox::AddDIBitmap(CFX_DIBitmap* pDIB, IFWL_ListItem* pItem) {
35 static_cast<CFWL_ListItem*>(pItem)->m_pDIB = pDIB; 43 static_cast<CFWL_ListItem*>(pItem)->m_pDIB = pDIB;
36 return FWL_Error::Succeeded; 44 return FWL_Error::Succeeded;
37 } 45 }
38 46
39 IFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd, 47 IFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd,
40 FX_BOOL bSelect) { 48 FX_BOOL bSelect) {
41 std::unique_ptr<CFWL_ListItem> pItem(new CFWL_ListItem); 49 std::unique_ptr<CFWL_ListItem> pItem(new CFWL_ListItem);
42 pItem->m_dwStates = 0; 50 pItem->m_dwStates = 0;
43 pItem->m_wsText = wsAdd; 51 pItem->m_wsText = wsAdd;
44 pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0; 52 pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0;
45 m_ListBoxDP.m_ItemArray.push_back(std::move(pItem)); 53 m_ListBoxDP.m_ItemArray.push_back(std::move(pItem));
46 return m_ListBoxDP.m_ItemArray.back().get(); 54 return m_ListBoxDP.m_ItemArray.back().get();
47 } 55 }
48 56
49 FX_BOOL CFWL_ListBox::DeleteString(IFWL_ListItem* pItem) { 57 FX_BOOL CFWL_ListBox::DeleteString(IFWL_ListItem* pItem) {
50 int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), pItem); 58 int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), pItem);
51 if (nIndex < 0 || 59 if (nIndex < 0 ||
52 static_cast<size_t>(nIndex) >= m_ListBoxDP.m_ItemArray.size()) { 60 static_cast<size_t>(nIndex) >= m_ListBoxDP.m_ItemArray.size()) {
53 return FALSE; 61 return FALSE;
54 } 62 }
55 int32_t iCount = m_ListBoxDP.CountItems(m_pIface); 63 int32_t iCount = m_ListBoxDP.CountItems(m_pIface.get());
56 int32_t iSel = nIndex + 1; 64 int32_t iSel = nIndex + 1;
57 if (iSel >= iCount) { 65 if (iSel >= iCount) {
58 iSel = nIndex - 1; 66 iSel = nIndex - 1;
59 if (iSel < 0) { 67 if (iSel < 0) {
60 iSel = -1; 68 iSel = -1;
61 } 69 }
62 } 70 }
63 if (iSel >= 0) { 71 if (iSel >= 0) {
64 CFWL_ListItem* pSel = 72 CFWL_ListItem* pSel =
65 static_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, iSel)); 73 static_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface.get(), iSel));
66 pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected; 74 pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected;
67 } 75 }
68 m_ListBoxDP.m_ItemArray.erase(m_ListBoxDP.m_ItemArray.begin() + nIndex); 76 m_ListBoxDP.m_ItemArray.erase(m_ListBoxDP.m_ItemArray.begin() + nIndex);
69 return TRUE; 77 return TRUE;
70 } 78 }
71 79
72 void CFWL_ListBox::DeleteAll() { 80 void CFWL_ListBox::DeleteAll() {
73 m_ListBoxDP.m_ItemArray.clear(); 81 m_ListBoxDP.m_ItemArray.clear();
74 } 82 }
75 83
76 int32_t CFWL_ListBox::CountSelItems() { 84 int32_t CFWL_ListBox::CountSelItems() {
77 if (!m_pIface) 85 if (!GetWidget())
78 return 0; 86 return 0;
79 return static_cast<IFWL_ListBox*>(m_pIface)->CountSelItems(); 87 return GetWidget()->CountSelItems();
80 } 88 }
81 89
82 IFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) { 90 IFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) {
83 if (!m_pIface) 91 if (!GetWidget())
84 return nullptr; 92 return nullptr;
85 return static_cast<IFWL_ListBox*>(m_pIface)->GetSelItem(nIndexSel); 93 return GetWidget()->GetSelItem(nIndexSel);
86 } 94 }
87 95
88 int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { 96 int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) {
89 if (!m_pIface) 97 if (!GetWidget())
90 return 0; 98 return 0;
91 return static_cast<IFWL_ListBox*>(m_pIface)->GetSelIndex(nIndex); 99 return GetWidget()->GetSelIndex(nIndex);
92 } 100 }
93 101
94 FWL_Error CFWL_ListBox::SetSelItem(IFWL_ListItem* pItem, FX_BOOL bSelect) { 102 FWL_Error CFWL_ListBox::SetSelItem(IFWL_ListItem* pItem, FX_BOOL bSelect) {
95 if (!m_pIface) 103 if (!GetWidget())
96 return FWL_Error::Indefinite; 104 return FWL_Error::Indefinite;
97 return static_cast<IFWL_ListBox*>(m_pIface)->SetSelItem(pItem, bSelect); 105 return GetWidget()->SetSelItem(pItem, bSelect);
98 } 106 }
99 107
100 FWL_Error CFWL_ListBox::GetItemText(IFWL_ListItem* pItem, 108 FWL_Error CFWL_ListBox::GetItemText(IFWL_ListItem* pItem,
101 CFX_WideString& wsText) { 109 CFX_WideString& wsText) {
102 if (!m_pIface) 110 if (!GetWidget())
103 return FWL_Error::Indefinite; 111 return FWL_Error::Indefinite;
104 return static_cast<IFWL_ListBox*>(m_pIface)->GetItemText(pItem, wsText); 112 return GetWidget()->GetItemText(pItem, wsText);
105 } 113 }
106 114
107 FWL_Error CFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) { 115 FWL_Error CFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) {
108 if (!m_pIface) 116 if (!GetWidget())
109 return FWL_Error::Indefinite; 117 return FWL_Error::Indefinite;
110 return static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fPos, bVert); 118 return GetWidget()->GetScrollPos(fPos, bVert);
111 } 119 }
112 120
113 FWL_Error CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) { 121 FWL_Error CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) {
114 m_ListBoxDP.m_fItemHeight = fItemHeight; 122 m_ListBoxDP.m_fItemHeight = fItemHeight;
115 return FWL_Error::Succeeded; 123 return FWL_Error::Succeeded;
116 } 124 }
117 125
118 IFWL_ListItem* CFWL_ListBox::GetFocusItem() { 126 IFWL_ListItem* CFWL_ListBox::GetFocusItem() {
119 for (const auto& pItem : m_ListBoxDP.m_ItemArray) { 127 for (const auto& pItem : m_ListBoxDP.m_ItemArray) {
120 if (pItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused) 128 if (pItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 static_cast<CFWL_ListItem*>(pItem)->m_pData = pData; 170 static_cast<CFWL_ListItem*>(pItem)->m_pData = pData;
163 return FWL_Error::Succeeded; 171 return FWL_Error::Succeeded;
164 } 172 }
165 173
166 void* CFWL_ListBox::GetItemData(IFWL_ListItem* pItem) { 174 void* CFWL_ListBox::GetItemData(IFWL_ListItem* pItem) {
167 return pItem ? static_cast<CFWL_ListItem*>(pItem)->m_pData : nullptr; 175 return pItem ? static_cast<CFWL_ListItem*>(pItem)->m_pData : nullptr;
168 } 176 }
169 177
170 IFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { 178 IFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) {
171 CFX_RectF rtClient; 179 CFX_RectF rtClient;
172 m_pIface->GetClientRect(rtClient); 180 GetWidget()->GetClientRect(rtClient);
173 fx -= rtClient.left; 181 fx -= rtClient.left;
174 fy -= rtClient.top; 182 fy -= rtClient.top;
175 FX_FLOAT fPosX = 0; 183 FX_FLOAT fPosX = 0;
176 FX_FLOAT fPosY = 0; 184 FX_FLOAT fPosY = 0;
177 static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fx); 185 GetWidget()->GetScrollPos(fx);
178 static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fy, FALSE); 186 GetWidget()->GetScrollPos(fy, FALSE);
179 int32_t nCount = m_ListBoxDP.CountItems(nullptr); 187 int32_t nCount = m_ListBoxDP.CountItems(nullptr);
180 for (int32_t i = 0; i < nCount; i++) { 188 for (int32_t i = 0; i < nCount; i++) {
181 IFWL_ListItem* pItem = m_ListBoxDP.GetItem(nullptr, i); 189 IFWL_ListItem* pItem = m_ListBoxDP.GetItem(nullptr, i);
182 if (!pItem) { 190 if (!pItem) {
183 continue; 191 continue;
184 } 192 }
185 CFX_RectF rtItem; 193 CFX_RectF rtItem;
186 m_ListBoxDP.GetItemRect(nullptr, pItem, rtItem); 194 m_ListBoxDP.GetItemRect(nullptr, pItem, rtItem);
187 rtItem.Offset(-fPosX, -fPosY); 195 rtItem.Offset(-fPosX, -fPosY);
188 if (rtItem.Contains(fx, fy)) { 196 if (rtItem.Contains(fx, fy)) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 m_rtItem.Reset(); 350 m_rtItem.Reset();
343 m_dwStates = 0; 351 m_dwStates = 0;
344 m_wsText = L""; 352 m_wsText = L"";
345 m_pDIB = nullptr; 353 m_pDIB = nullptr;
346 m_pData = nullptr; 354 m_pData = nullptr;
347 m_dwCheckState = 0; 355 m_dwCheckState = 0;
348 m_rtCheckBox.Reset(); 356 m_rtCheckBox.Reset();
349 } 357 }
350 358
351 CFWL_ListItem::~CFWL_ListItem() {} 359 CFWL_ListItem::~CFWL_ListItem() {}
OLDNEW
« no previous file with comments | « xfa/fwl/lightwidget/cfwl_listbox.h ('k') | xfa/fwl/lightwidget/cfwl_picturebox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698