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

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

Issue 2209153002: Use virtual function to retrieve interface pointer (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: complete changes 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
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_combobox.h" 7 #include "xfa/fwl/lightwidget/cfwl_combobox.h"
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "xfa/fwl/core/fwl_error.h" 11 #include "xfa/fwl/core/fwl_error.h"
12 #include "xfa/fwl/core/ifwl_widget.h" 12 #include "xfa/fwl/core/ifwl_widget.h"
13 13
14 IFWL_ComboBox* CFWL_ComboBox::GetWidget() {
15 return static_cast<IFWL_ComboBox*>(m_pIface.get());
16 }
17
18 const IFWL_ComboBox* CFWL_ComboBox::GetWidget() const {
19 return static_cast<IFWL_ComboBox*>(m_pIface.get());
20 }
21
14 CFWL_ComboBox* CFWL_ComboBox::Create() { 22 CFWL_ComboBox* CFWL_ComboBox::Create() {
15 return new CFWL_ComboBox; 23 return new CFWL_ComboBox;
16 } 24 }
17 25
18 FWL_Error CFWL_ComboBox::Initialize(const CFWL_WidgetProperties* pProperties) { 26 FWL_Error CFWL_ComboBox::Initialize(const CFWL_WidgetProperties* pProperties) {
19 if (m_pIface) 27 if (m_pIface)
20 return FWL_Error::Indefinite; 28 return FWL_Error::Indefinite;
21 if (pProperties) { 29 if (pProperties) {
22 *m_pProperties = *pProperties; 30 *m_pProperties = *pProperties;
23 } 31 }
24 std::unique_ptr<IFWL_ComboBox> pComboBox(IFWL_ComboBox::Create( 32 std::unique_ptr<IFWL_ComboBox> pComboBox(IFWL_ComboBox::Create(
25 m_pProperties->MakeWidgetImpProperties(&m_comboBoxData))); 33 m_pProperties->MakeWidgetImpProperties(&m_comboBoxData)));
26 FWL_Error ret = pComboBox->Initialize(); 34 FWL_Error ret = pComboBox->Initialize();
27 if (ret != FWL_Error::Succeeded) { 35 if (ret != FWL_Error::Succeeded) {
28 return ret; 36 return ret;
29 } 37 }
30 m_pIface = pComboBox.release(); 38 m_pIface = std::move(pComboBox);
31 CFWL_Widget::Initialize(); 39 CFWL_Widget::Initialize();
32 return FWL_Error::Succeeded; 40 return FWL_Error::Succeeded;
33 } 41 }
34 42
35 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { 43 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) {
36 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem); 44 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem);
37 pItem->m_wsText = wsText; 45 pItem->m_wsText = wsText;
38 pItem->m_dwStyles = 0; 46 pItem->m_dwStyles = 0;
39 m_comboBoxData.m_ItemArray.push_back(std::move(pItem)); 47 m_comboBoxData.m_ItemArray.push_back(std::move(pItem));
40 return m_comboBoxData.m_ItemArray.size() - 1; 48 return m_comboBoxData.m_ItemArray.size() - 1;
(...skipping 21 matching lines...) Expand all
62 void CFWL_ComboBox::RemoveAll() { 70 void CFWL_ComboBox::RemoveAll() {
63 m_comboBoxData.m_ItemArray.clear(); 71 m_comboBoxData.m_ItemArray.clear();
64 } 72 }
65 73
66 int32_t CFWL_ComboBox::CountItems() { 74 int32_t CFWL_ComboBox::CountItems() {
67 return m_comboBoxData.CountItems(GetWidget()); 75 return m_comboBoxData.CountItems(GetWidget());
68 } 76 }
69 77
70 FWL_Error CFWL_ComboBox::GetTextByIndex(int32_t iIndex, 78 FWL_Error CFWL_ComboBox::GetTextByIndex(int32_t iIndex,
71 CFX_WideString& wsText) { 79 CFX_WideString& wsText) {
72 CFWL_ComboBoxItem* pItem = 80 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>(
73 static_cast<CFWL_ComboBoxItem*>(m_comboBoxData.GetItem(m_pIface, iIndex)); 81 m_comboBoxData.GetItem(m_pIface.get(), iIndex));
74 if (!pItem) 82 if (!pItem)
75 return FWL_Error::Indefinite; 83 return FWL_Error::Indefinite;
76 wsText = pItem->m_wsText; 84 wsText = pItem->m_wsText;
77 return FWL_Error::Succeeded; 85 return FWL_Error::Succeeded;
78 } 86 }
79 87
80 int32_t CFWL_ComboBox::GetCurSel() { 88 int32_t CFWL_ComboBox::GetCurSel() {
81 if (!m_pIface) 89 if (!GetWidget())
82 return -1; 90 return -1;
83 return static_cast<IFWL_ComboBox*>(m_pIface)->GetCurSel(); 91 return GetWidget()->GetCurSel();
84 } 92 }
85 93
86 FWL_Error CFWL_ComboBox::SetCurSel(int32_t iSel) { 94 FWL_Error CFWL_ComboBox::SetCurSel(int32_t iSel) {
87 if (!m_pIface) 95 if (!GetWidget())
88 return FWL_Error::Indefinite; 96 return FWL_Error::Indefinite;
89 return static_cast<IFWL_ComboBox*>(m_pIface)->SetCurSel(iSel); 97 return GetWidget()->SetCurSel(iSel);
90 } 98 }
91 99
92 FWL_Error CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { 100 FWL_Error CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) {
93 if (!m_pIface) 101 if (!GetWidget())
94 return FWL_Error::Indefinite; 102 return FWL_Error::Indefinite;
95 return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditText(wsText); 103 return GetWidget()->SetEditText(wsText);
96 } 104 }
97 105
98 int32_t CFWL_ComboBox::GetEditTextLength() const { 106 int32_t CFWL_ComboBox::GetEditTextLength() const {
99 if (!m_pIface) 107 if (!GetWidget())
100 return 0; 108 return 0;
101 return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditTextLength(); 109 return GetWidget()->GetEditTextLength();
102 } 110 }
103 111
104 FWL_Error CFWL_ComboBox::GetEditText(CFX_WideString& wsText, 112 FWL_Error CFWL_ComboBox::GetEditText(CFX_WideString& wsText,
105 int32_t nStart, 113 int32_t nStart,
106 int32_t nCount) const { 114 int32_t nCount) const {
107 if (!m_pIface) 115 if (!GetWidget())
108 return FWL_Error::Indefinite; 116 return FWL_Error::Indefinite;
109 return static_cast<IFWL_ComboBox*>(m_pIface) 117 return GetWidget()->GetEditText(wsText, nStart, nCount);
110 ->GetEditText(wsText, nStart, nCount);
111 } 118 }
112 119
113 FWL_Error CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { 120 FWL_Error CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) {
114 if (!m_pIface) 121 if (!GetWidget())
115 return FWL_Error::Indefinite; 122 return FWL_Error::Indefinite;
116 return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditSelRange(nStart, nCount); 123 return GetWidget()->SetEditSelRange(nStart, nCount);
117 } 124 }
118 125
119 int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) { 126 int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) {
120 if (!m_pIface) 127 if (!GetWidget())
121 return 0; 128 return 0;
122 return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditSelRange(nIndex, nStart); 129 return GetWidget()->GetEditSelRange(nIndex, nStart);
123 } 130 }
124 131
125 int32_t CFWL_ComboBox::GetEditLimit() { 132 int32_t CFWL_ComboBox::GetEditLimit() {
126 if (!m_pIface) 133 if (!GetWidget())
127 return 0; 134 return 0;
128 return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditLimit(); 135 return GetWidget()->GetEditLimit();
129 } 136 }
130 137
131 FWL_Error CFWL_ComboBox::SetEditLimit(int32_t nLimit) { 138 FWL_Error CFWL_ComboBox::SetEditLimit(int32_t nLimit) {
132 if (!m_pIface) 139 if (!GetWidget())
133 return FWL_Error::Indefinite; 140 return FWL_Error::Indefinite;
134 return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditLimit(nLimit); 141 return GetWidget()->SetEditLimit(nLimit);
135 } 142 }
136 143
137 FWL_Error CFWL_ComboBox::EditDoClipboard(int32_t iCmd) { 144 FWL_Error CFWL_ComboBox::EditDoClipboard(int32_t iCmd) {
138 if (!m_pIface) 145 if (!GetWidget())
139 return FWL_Error::Indefinite; 146 return FWL_Error::Indefinite;
140 return static_cast<IFWL_ComboBox*>(m_pIface)->EditDoClipboard(iCmd); 147 return GetWidget()->EditDoClipboard(iCmd);
141 } 148 }
142 149
143 FX_BOOL CFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { 150 FX_BOOL CFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) {
144 if (!m_pIface) 151 if (!GetWidget())
145 return FALSE; 152 return FALSE;
146 return static_cast<IFWL_ComboBox*>(m_pIface)->EditRedo(pRecord); 153 return GetWidget()->EditRedo(pRecord);
147 } 154 }
148 155
149 FX_BOOL CFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { 156 FX_BOOL CFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) {
150 if (!m_pIface) 157 if (!GetWidget())
151 return FALSE; 158 return FALSE;
152 return static_cast<IFWL_ComboBox*>(m_pIface)->EditUndo(pRecord); 159 return GetWidget()->EditUndo(pRecord);
153 } 160 }
154 161
155 FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { 162 FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) {
156 m_comboBoxData.m_fMaxListHeight = fMaxHeight; 163 m_comboBoxData.m_fMaxListHeight = fMaxHeight;
157 return FWL_Error::Succeeded; 164 return FWL_Error::Succeeded;
158 } 165 }
159 166
160 FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { 167 FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) {
161 CFWL_ComboBoxItem* pItem = 168 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>(
162 static_cast<CFWL_ComboBoxItem*>(m_comboBoxData.GetItem(m_pIface, iIndex)); 169 m_comboBoxData.GetItem(m_pIface.get(), iIndex));
163 if (!pItem) 170 if (!pItem)
164 return FWL_Error::Indefinite; 171 return FWL_Error::Indefinite;
165 pItem->m_pData = pData; 172 pItem->m_pData = pData;
166 return FWL_Error::Succeeded; 173 return FWL_Error::Succeeded;
167 } 174 }
168 175
169 void* CFWL_ComboBox::GetItemData(int32_t iIndex) { 176 void* CFWL_ComboBox::GetItemData(int32_t iIndex) {
170 CFWL_ComboBoxItem* pItem = 177 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>(
171 static_cast<CFWL_ComboBoxItem*>(m_comboBoxData.GetItem(m_pIface, iIndex)); 178 m_comboBoxData.GetItem(m_pIface.get(), iIndex));
172 return pItem ? pItem->m_pData : nullptr; 179 return pItem ? pItem->m_pData : nullptr;
173 } 180 }
174 181
175 FWL_Error CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) { 182 FWL_Error CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) {
176 return static_cast<IFWL_ComboBox*>(m_pIface)->GetListBoxt()->SetThemeProvider( 183 return GetWidget()->GetListBoxt()->SetThemeProvider(pTheme);
177 pTheme);
178 } 184 }
179 185
180 FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() { 186 FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() {
181 return static_cast<IFWL_ComboBox*>(m_pIface)->AfterFocusShowDropList(); 187 return GetWidget()->AfterFocusShowDropList();
182 } 188 }
183 189
184 FWL_Error CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) { 190 FWL_Error CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) {
185 return static_cast<IFWL_ComboBox*>(m_pIface)->OpenDropDownList(bActivate); 191 return GetWidget()->OpenDropDownList(bActivate);
186 } 192 }
187 193
188 FX_BOOL CFWL_ComboBox::EditCanUndo() { 194 FX_BOOL CFWL_ComboBox::EditCanUndo() {
189 if (!m_pIface) 195 if (!GetWidget())
190 return FALSE; 196 return FALSE;
191 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanUndo(); 197 return GetWidget()->EditCanUndo();
192 } 198 }
193 199
194 FX_BOOL CFWL_ComboBox::EditCanRedo() { 200 FX_BOOL CFWL_ComboBox::EditCanRedo() {
195 if (!m_pIface) 201 if (!GetWidget())
196 return FALSE; 202 return FALSE;
197 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanRedo(); 203 return GetWidget()->EditCanRedo();
198 } 204 }
199 205
200 FX_BOOL CFWL_ComboBox::EditUndo() { 206 FX_BOOL CFWL_ComboBox::EditUndo() {
201 if (!m_pIface) 207 if (!GetWidget())
202 return FALSE; 208 return FALSE;
203 return static_cast<IFWL_ComboBox*>(m_pIface)->EditUndo(); 209 return GetWidget()->EditUndo();
204 } 210 }
205 211
206 FX_BOOL CFWL_ComboBox::EditRedo() { 212 FX_BOOL CFWL_ComboBox::EditRedo() {
207 if (!m_pIface) 213 if (!GetWidget())
208 return FALSE; 214 return FALSE;
209 return static_cast<IFWL_ComboBox*>(m_pIface)->EditRedo(); 215 return GetWidget()->EditRedo();
210 } 216 }
211 217
212 FX_BOOL CFWL_ComboBox::EditCanCopy() { 218 FX_BOOL CFWL_ComboBox::EditCanCopy() {
213 if (!m_pIface) 219 if (!GetWidget())
214 return FALSE; 220 return FALSE;
215 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanCopy(); 221 return GetWidget()->EditCanCopy();
216 } 222 }
217 223
218 FX_BOOL CFWL_ComboBox::EditCanCut() { 224 FX_BOOL CFWL_ComboBox::EditCanCut() {
219 if (!m_pIface) 225 if (!GetWidget())
220 return FALSE; 226 return FALSE;
221 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanCut(); 227 return GetWidget()->EditCanCut();
222 } 228 }
223 229
224 FX_BOOL CFWL_ComboBox::EditCanSelectAll() { 230 FX_BOOL CFWL_ComboBox::EditCanSelectAll() {
225 if (!m_pIface) 231 if (!GetWidget())
226 return FALSE; 232 return FALSE;
227 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanSelectAll(); 233 return GetWidget()->EditCanSelectAll();
228 } 234 }
229 235
230 FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { 236 FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) {
231 if (!m_pIface) 237 if (!GetWidget())
232 return FALSE; 238 return FALSE;
233 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCopy(wsCopy); 239 return GetWidget()->EditCopy(wsCopy);
234 } 240 }
235 241
236 FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) { 242 FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) {
237 if (!m_pIface) 243 if (!GetWidget())
238 return FALSE; 244 return FALSE;
239 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCut(wsCut); 245 return GetWidget()->EditCut(wsCut);
240 } 246 }
241 247
242 FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { 248 FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) {
243 if (!m_pIface) 249 if (!GetWidget())
244 return FALSE; 250 return FALSE;
245 return static_cast<IFWL_ComboBox*>(m_pIface)->EditPaste(wsPaste); 251 return GetWidget()->EditPaste(wsPaste);
246 } 252 }
247 253
248 FX_BOOL CFWL_ComboBox::EditSelectAll() { 254 FX_BOOL CFWL_ComboBox::EditSelectAll() {
249 if (!m_pIface) 255 if (!GetWidget())
250 return FALSE; 256 return FALSE;
251 return static_cast<IFWL_ComboBox*>(m_pIface)->EditSelectAll(); 257 return GetWidget()->EditSelectAll();
252 } 258 }
253 259
254 FX_BOOL CFWL_ComboBox::EditDelete() { 260 FX_BOOL CFWL_ComboBox::EditDelete() {
255 if (!m_pIface) 261 if (!GetWidget())
256 return FALSE; 262 return FALSE;
257 return static_cast<IFWL_ComboBox*>(m_pIface)->EditDelete(); 263 return GetWidget()->EditDelete();
258 } 264 }
259 265
260 FX_BOOL CFWL_ComboBox::EditDeSelect() { 266 FX_BOOL CFWL_ComboBox::EditDeSelect() {
261 if (!m_pIface) 267 if (!GetWidget())
262 return FALSE; 268 return FALSE;
263 return static_cast<IFWL_ComboBox*>(m_pIface)->EditDeSelect(); 269 return GetWidget()->EditDeSelect();
264 } 270 }
265 271
266 FWL_Error CFWL_ComboBox::GetBBox(CFX_RectF& rect) { 272 FWL_Error CFWL_ComboBox::GetBBox(CFX_RectF& rect) {
267 if (!m_pIface) 273 if (!GetWidget())
268 return FWL_Error::Indefinite; 274 return FWL_Error::Indefinite;
269 return static_cast<IFWL_ComboBox*>(m_pIface)->GetBBox(rect); 275 return GetWidget()->GetBBox(rect);
270 } 276 }
271 277
272 FWL_Error CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, 278 FWL_Error CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded,
273 uint32_t dwStylesExRemoved) { 279 uint32_t dwStylesExRemoved) {
274 if (!m_pIface) 280 if (!GetWidget())
275 return FWL_Error::Indefinite; 281 return FWL_Error::Indefinite;
276 return static_cast<IFWL_ComboBox*>(m_pIface) 282 return GetWidget()->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
277 ->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
278 } 283 }
279 284
280 CFWL_ComboBox::CFWL_ComboBox() {} 285 CFWL_ComboBox::CFWL_ComboBox() {}
281 286
282 CFWL_ComboBox::~CFWL_ComboBox() {} 287 CFWL_ComboBox::~CFWL_ComboBox() {}
283 288
284 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() { 289 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() {
285 m_fItemHeight = 0; 290 m_fItemHeight = 0;
286 m_fMaxListHeight = 0; 291 m_fMaxListHeight = 0;
287 } 292 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return FWL_Error::Succeeded; 429 return FWL_Error::Succeeded;
425 } 430 }
426 431
427 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) { 432 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) {
428 return m_fMaxListHeight; 433 return m_fMaxListHeight;
429 } 434 }
430 435
431 CFWL_ComboBoxItem::CFWL_ComboBoxItem() : m_pDIB(nullptr), m_pData(nullptr) {} 436 CFWL_ComboBoxItem::CFWL_ComboBoxItem() : m_pDIB(nullptr), m_pData(nullptr) {}
432 437
433 CFWL_ComboBoxItem::~CFWL_ComboBoxItem() {} 438 CFWL_ComboBoxItem::~CFWL_ComboBoxItem() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698