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

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: 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_combobox.h ('k') | xfa/fwl/lightwidget/cfwl_datetimepicker.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_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 return GetWidget() ? GetWidget()->GetCurSel() : -1;
82 return -1;
83 return static_cast<IFWL_ComboBox*>(m_pIface)->GetCurSel();
84 } 90 }
85 91
86 FWL_Error CFWL_ComboBox::SetCurSel(int32_t iSel) { 92 FWL_Error CFWL_ComboBox::SetCurSel(int32_t iSel) {
87 if (!m_pIface) 93 return GetWidget() ? GetWidget()->SetCurSel(iSel) : FWL_Error::Indefinite;
88 return FWL_Error::Indefinite;
89 return static_cast<IFWL_ComboBox*>(m_pIface)->SetCurSel(iSel);
90 } 94 }
91 95
92 FWL_Error CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { 96 FWL_Error CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) {
93 if (!m_pIface) 97 return GetWidget() ? GetWidget()->SetEditText(wsText) : FWL_Error::Indefinite;
94 return FWL_Error::Indefinite;
95 return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditText(wsText);
96 } 98 }
97 99
98 int32_t CFWL_ComboBox::GetEditTextLength() const { 100 int32_t CFWL_ComboBox::GetEditTextLength() const {
99 if (!m_pIface) 101 return GetWidget() ? GetWidget()->GetEditTextLength() : 0;
100 return 0;
101 return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditTextLength();
102 } 102 }
103 103
104 FWL_Error CFWL_ComboBox::GetEditText(CFX_WideString& wsText, 104 FWL_Error CFWL_ComboBox::GetEditText(CFX_WideString& wsText,
105 int32_t nStart, 105 int32_t nStart,
106 int32_t nCount) const { 106 int32_t nCount) const {
107 if (!m_pIface) 107 return GetWidget() ? GetWidget()->GetEditText(wsText, nStart, nCount)
108 return FWL_Error::Indefinite; 108 : FWL_Error::Indefinite;
109 return static_cast<IFWL_ComboBox*>(m_pIface)
110 ->GetEditText(wsText, nStart, nCount);
111 } 109 }
112 110
113 FWL_Error CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { 111 FWL_Error CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) {
114 if (!m_pIface) 112 return GetWidget() ? GetWidget()->SetEditSelRange(nStart, nCount)
115 return FWL_Error::Indefinite; 113 : FWL_Error::Indefinite;
116 return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditSelRange(nStart, nCount);
117 } 114 }
118 115
119 int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) { 116 int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) {
120 if (!m_pIface) 117 return GetWidget() ? GetWidget()->GetEditSelRange(nIndex, nStart) : 0;
121 return 0;
122 return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditSelRange(nIndex, nStart);
123 } 118 }
124 119
125 int32_t CFWL_ComboBox::GetEditLimit() { 120 int32_t CFWL_ComboBox::GetEditLimit() {
126 if (!m_pIface) 121 return GetWidget() ? GetWidget()->GetEditLimit() : 0;
127 return 0;
128 return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditLimit();
129 } 122 }
130 123
131 FWL_Error CFWL_ComboBox::SetEditLimit(int32_t nLimit) { 124 FWL_Error CFWL_ComboBox::SetEditLimit(int32_t nLimit) {
132 if (!m_pIface) 125 return GetWidget() ? GetWidget()->SetEditLimit(nLimit)
133 return FWL_Error::Indefinite; 126 : FWL_Error::Indefinite;
134 return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditLimit(nLimit);
135 } 127 }
136 128
137 FWL_Error CFWL_ComboBox::EditDoClipboard(int32_t iCmd) { 129 FWL_Error CFWL_ComboBox::EditDoClipboard(int32_t iCmd) {
138 if (!m_pIface) 130 return GetWidget() ? GetWidget()->EditDoClipboard(iCmd)
139 return FWL_Error::Indefinite; 131 : FWL_Error::Indefinite;
140 return static_cast<IFWL_ComboBox*>(m_pIface)->EditDoClipboard(iCmd);
141 } 132 }
142 133
143 FX_BOOL CFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { 134 FX_BOOL CFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) {
144 if (!m_pIface) 135 return GetWidget() ? GetWidget()->EditRedo(pRecord) : FALSE;
145 return FALSE;
146 return static_cast<IFWL_ComboBox*>(m_pIface)->EditRedo(pRecord);
147 } 136 }
148 137
149 FX_BOOL CFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { 138 FX_BOOL CFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) {
150 if (!m_pIface) 139 return GetWidget() ? GetWidget()->EditUndo(pRecord) : FALSE;
151 return FALSE;
152 return static_cast<IFWL_ComboBox*>(m_pIface)->EditUndo(pRecord);
153 } 140 }
154 141
155 FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { 142 FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) {
156 m_comboBoxData.m_fMaxListHeight = fMaxHeight; 143 m_comboBoxData.m_fMaxListHeight = fMaxHeight;
157 return FWL_Error::Succeeded; 144 return FWL_Error::Succeeded;
158 } 145 }
159 146
160 FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { 147 FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) {
161 CFWL_ComboBoxItem* pItem = 148 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>(
162 static_cast<CFWL_ComboBoxItem*>(m_comboBoxData.GetItem(m_pIface, iIndex)); 149 m_comboBoxData.GetItem(m_pIface.get(), iIndex));
163 if (!pItem) 150 if (!pItem)
164 return FWL_Error::Indefinite; 151 return FWL_Error::Indefinite;
165 pItem->m_pData = pData; 152 pItem->m_pData = pData;
166 return FWL_Error::Succeeded; 153 return FWL_Error::Succeeded;
167 } 154 }
168 155
169 void* CFWL_ComboBox::GetItemData(int32_t iIndex) { 156 void* CFWL_ComboBox::GetItemData(int32_t iIndex) {
170 CFWL_ComboBoxItem* pItem = 157 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>(
171 static_cast<CFWL_ComboBoxItem*>(m_comboBoxData.GetItem(m_pIface, iIndex)); 158 m_comboBoxData.GetItem(m_pIface.get(), iIndex));
172 return pItem ? pItem->m_pData : nullptr; 159 return pItem ? pItem->m_pData : nullptr;
173 } 160 }
174 161
175 FWL_Error CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) { 162 FWL_Error CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) {
176 return static_cast<IFWL_ComboBox*>(m_pIface)->GetListBoxt()->SetThemeProvider( 163 return GetWidget()->GetListBoxt()->SetThemeProvider(pTheme);
177 pTheme);
178 } 164 }
179 165
180 FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() { 166 FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() {
181 return static_cast<IFWL_ComboBox*>(m_pIface)->AfterFocusShowDropList(); 167 return GetWidget()->AfterFocusShowDropList();
182 } 168 }
183 169
184 FWL_Error CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) { 170 FWL_Error CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) {
185 return static_cast<IFWL_ComboBox*>(m_pIface)->OpenDropDownList(bActivate); 171 return GetWidget()->OpenDropDownList(bActivate);
186 } 172 }
187 173
188 FX_BOOL CFWL_ComboBox::EditCanUndo() { 174 FX_BOOL CFWL_ComboBox::EditCanUndo() {
189 if (!m_pIface) 175 return GetWidget() ? GetWidget()->EditCanUndo() : FALSE;
190 return FALSE;
191 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanUndo();
192 } 176 }
193 177
194 FX_BOOL CFWL_ComboBox::EditCanRedo() { 178 FX_BOOL CFWL_ComboBox::EditCanRedo() {
195 if (!m_pIface) 179 return GetWidget() ? GetWidget()->EditCanRedo() : FALSE;
196 return FALSE;
197 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanRedo();
198 } 180 }
199 181
200 FX_BOOL CFWL_ComboBox::EditUndo() { 182 FX_BOOL CFWL_ComboBox::EditUndo() {
201 if (!m_pIface) 183 return GetWidget() ? GetWidget()->EditUndo() : FALSE;
202 return FALSE;
203 return static_cast<IFWL_ComboBox*>(m_pIface)->EditUndo();
204 } 184 }
205 185
206 FX_BOOL CFWL_ComboBox::EditRedo() { 186 FX_BOOL CFWL_ComboBox::EditRedo() {
207 if (!m_pIface) 187 return GetWidget() ? GetWidget()->EditRedo() : FALSE;
208 return FALSE;
209 return static_cast<IFWL_ComboBox*>(m_pIface)->EditRedo();
210 } 188 }
211 189
212 FX_BOOL CFWL_ComboBox::EditCanCopy() { 190 FX_BOOL CFWL_ComboBox::EditCanCopy() {
213 if (!m_pIface) 191 return GetWidget() ? GetWidget()->EditCanCopy() : FALSE;
214 return FALSE;
215 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanCopy();
216 } 192 }
217 193
218 FX_BOOL CFWL_ComboBox::EditCanCut() { 194 FX_BOOL CFWL_ComboBox::EditCanCut() {
219 if (!m_pIface) 195 return GetWidget() ? GetWidget()->EditCanCut() : FALSE;
220 return FALSE;
221 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanCut();
222 } 196 }
223 197
224 FX_BOOL CFWL_ComboBox::EditCanSelectAll() { 198 FX_BOOL CFWL_ComboBox::EditCanSelectAll() {
225 if (!m_pIface) 199 return GetWidget() ? GetWidget()->EditCanSelectAll() : FALSE;
226 return FALSE;
227 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanSelectAll();
228 } 200 }
229 201
230 FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { 202 FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) {
231 if (!m_pIface) 203 return GetWidget() ? GetWidget()->EditCopy(wsCopy) : FALSE;
232 return FALSE;
233 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCopy(wsCopy);
234 } 204 }
235 205
236 FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) { 206 FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) {
237 if (!m_pIface) 207 return GetWidget() ? GetWidget()->EditCut(wsCut) : FALSE;
238 return FALSE;
239 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCut(wsCut);
240 } 208 }
241 209
242 FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { 210 FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) {
243 if (!m_pIface) 211 return GetWidget() ? GetWidget()->EditPaste(wsPaste) : FALSE;
244 return FALSE;
245 return static_cast<IFWL_ComboBox*>(m_pIface)->EditPaste(wsPaste);
246 } 212 }
247 213
248 FX_BOOL CFWL_ComboBox::EditSelectAll() { 214 FX_BOOL CFWL_ComboBox::EditSelectAll() {
249 if (!m_pIface) 215 return GetWidget() ? GetWidget()->EditSelectAll() : FALSE;
250 return FALSE;
251 return static_cast<IFWL_ComboBox*>(m_pIface)->EditSelectAll();
252 } 216 }
253 217
254 FX_BOOL CFWL_ComboBox::EditDelete() { 218 FX_BOOL CFWL_ComboBox::EditDelete() {
255 if (!m_pIface) 219 return GetWidget() ? GetWidget()->EditDelete() : FALSE;
256 return FALSE;
257 return static_cast<IFWL_ComboBox*>(m_pIface)->EditDelete();
258 } 220 }
259 221
260 FX_BOOL CFWL_ComboBox::EditDeSelect() { 222 FX_BOOL CFWL_ComboBox::EditDeSelect() {
261 if (!m_pIface) 223 return GetWidget() ? GetWidget()->EditDeSelect() : FALSE;
262 return FALSE;
263 return static_cast<IFWL_ComboBox*>(m_pIface)->EditDeSelect();
264 } 224 }
265 225
266 FWL_Error CFWL_ComboBox::GetBBox(CFX_RectF& rect) { 226 FWL_Error CFWL_ComboBox::GetBBox(CFX_RectF& rect) {
267 if (!m_pIface) 227 return GetWidget() ? GetWidget()->GetBBox(rect) : FWL_Error::Indefinite;
268 return FWL_Error::Indefinite;
269 return static_cast<IFWL_ComboBox*>(m_pIface)->GetBBox(rect);
270 } 228 }
271 229
272 FWL_Error CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, 230 FWL_Error CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded,
273 uint32_t dwStylesExRemoved) { 231 uint32_t dwStylesExRemoved) {
274 if (!m_pIface) 232 return GetWidget()
275 return FWL_Error::Indefinite; 233 ? GetWidget()->EditModifyStylesEx(dwStylesExAdded,
276 return static_cast<IFWL_ComboBox*>(m_pIface) 234 dwStylesExRemoved)
277 ->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); 235 : FWL_Error::Indefinite;
278 } 236 }
279 237
280 CFWL_ComboBox::CFWL_ComboBox() {} 238 CFWL_ComboBox::CFWL_ComboBox() {}
281 239
282 CFWL_ComboBox::~CFWL_ComboBox() {} 240 CFWL_ComboBox::~CFWL_ComboBox() {}
283 241
284 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() { 242 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() {
285 m_fItemHeight = 0; 243 m_fItemHeight = 0;
286 m_fMaxListHeight = 0; 244 m_fMaxListHeight = 0;
287 } 245 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return FWL_Error::Succeeded; 382 return FWL_Error::Succeeded;
425 } 383 }
426 384
427 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) { 385 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) {
428 return m_fMaxListHeight; 386 return m_fMaxListHeight;
429 } 387 }
430 388
431 CFWL_ComboBoxItem::CFWL_ComboBoxItem() : m_pDIB(nullptr), m_pData(nullptr) {} 389 CFWL_ComboBoxItem::CFWL_ComboBoxItem() : m_pDIB(nullptr), m_pData(nullptr) {}
432 390
433 CFWL_ComboBoxItem::~CFWL_ComboBoxItem() {} 391 CFWL_ComboBoxItem::~CFWL_ComboBoxItem() {}
OLDNEW
« no previous file with comments | « xfa/fwl/lightwidget/cfwl_combobox.h ('k') | xfa/fwl/lightwidget/cfwl_datetimepicker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698