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

Side by Side Diff: xfa/fwl/lightwidget/cfwl_edit.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_edit.h ('k') | xfa/fwl/lightwidget/cfwl_listbox.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_edit.h" 7 #include "xfa/fwl/lightwidget/cfwl_edit.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "xfa/fwl/basewidget/ifwl_edit.h" 12 IFWL_Edit* CFWL_Edit::GetWidget() {
13 return static_cast<IFWL_Edit*>(m_pIface.get());
14 }
15
16 const IFWL_Edit* CFWL_Edit::GetWidget() const {
17 return static_cast<IFWL_Edit*>(m_pIface.get());
18 }
13 19
14 CFWL_Edit* CFWL_Edit::Create() { 20 CFWL_Edit* CFWL_Edit::Create() {
15 return new CFWL_Edit; 21 return new CFWL_Edit;
16 } 22 }
17 23
18 FWL_Error CFWL_Edit::Initialize(const CFWL_WidgetProperties* pProperties) { 24 FWL_Error CFWL_Edit::Initialize(const CFWL_WidgetProperties* pProperties) {
19 if (m_pIface) 25 if (m_pIface)
20 return FWL_Error::Indefinite; 26 return FWL_Error::Indefinite;
21 if (pProperties) { 27 if (pProperties) {
22 *m_pProperties = *pProperties; 28 *m_pProperties = *pProperties;
23 } 29 }
24 std::unique_ptr<IFWL_Edit> pEdit(IFWL_Edit::Create( 30 std::unique_ptr<IFWL_Edit> pEdit(IFWL_Edit::Create(
25 m_pProperties->MakeWidgetImpProperties(nullptr), nullptr)); 31 m_pProperties->MakeWidgetImpProperties(nullptr), nullptr));
26 FWL_Error ret = pEdit->Initialize(); 32 FWL_Error ret = pEdit->Initialize();
27 if (ret != FWL_Error::Succeeded) { 33 if (ret != FWL_Error::Succeeded) {
28 return ret; 34 return ret;
29 } 35 }
30 m_pIface = pEdit.release(); 36 m_pIface = std::move(pEdit);
31 CFWL_Widget::Initialize(); 37 CFWL_Widget::Initialize();
32 return FWL_Error::Succeeded; 38 return FWL_Error::Succeeded;
33 } 39 }
34 40
35 FWL_Error CFWL_Edit::SetText(const CFX_WideString& wsText) { 41 FWL_Error CFWL_Edit::SetText(const CFX_WideString& wsText) {
36 if (!m_pIface) 42 if (!GetWidget())
37 return FWL_Error::Indefinite; 43 return FWL_Error::Indefinite;
38 return static_cast<IFWL_Edit*>(m_pIface)->SetText(wsText); 44 return GetWidget()->SetText(wsText);
39 } 45 }
40 46
41 int32_t CFWL_Edit::GetTextLength() const { 47 int32_t CFWL_Edit::GetTextLength() const {
42 if (!m_pIface) 48 if (!GetWidget())
43 return 0; 49 return 0;
44 return static_cast<IFWL_Edit*>(m_pIface)->GetTextLength(); 50 return GetWidget()->GetTextLength();
45 } 51 }
46 52
47 FWL_Error CFWL_Edit::GetText(CFX_WideString& wsText, 53 FWL_Error CFWL_Edit::GetText(CFX_WideString& wsText,
48 int32_t nStart, 54 int32_t nStart,
49 int32_t nCount) const { 55 int32_t nCount) const {
50 if (!m_pIface) 56 if (!GetWidget())
51 return FWL_Error::Indefinite; 57 return FWL_Error::Indefinite;
52 return static_cast<IFWL_Edit*>(m_pIface)->GetText(wsText, nStart, nCount); 58 return GetWidget()->GetText(wsText, nStart, nCount);
53 } 59 }
54 60
55 FWL_Error CFWL_Edit::ClearText() { 61 FWL_Error CFWL_Edit::ClearText() {
56 if (!m_pIface) 62 if (!GetWidget())
57 return FWL_Error::Indefinite; 63 return FWL_Error::Indefinite;
58 return static_cast<IFWL_Edit*>(m_pIface)->ClearText(); 64 return GetWidget()->ClearText();
59 } 65 }
60 66
61 int32_t CFWL_Edit::GetCaretPos() const { 67 int32_t CFWL_Edit::GetCaretPos() const {
62 if (!m_pIface) 68 if (!GetWidget())
63 return -1; 69 return -1;
64 return static_cast<IFWL_Edit*>(m_pIface)->GetCaretPos(); 70 return GetWidget()->GetCaretPos();
65 } 71 }
66 72
67 int32_t CFWL_Edit::SetCaretPos(int32_t nIndex, FX_BOOL bBefore) { 73 int32_t CFWL_Edit::SetCaretPos(int32_t nIndex, FX_BOOL bBefore) {
68 if (!m_pIface) 74 if (!GetWidget())
69 return -1; 75 return -1;
70 return static_cast<IFWL_Edit*>(m_pIface)->SetCaretPos(nIndex, bBefore); 76 return GetWidget()->SetCaretPos(nIndex, bBefore);
71 } 77 }
72 78
73 int32_t CFWL_Edit::AddSelRange(int32_t nStart, int32_t nCount) { 79 int32_t CFWL_Edit::AddSelRange(int32_t nStart, int32_t nCount) {
74 if (!m_pIface) 80 if (!GetWidget())
75 return -1; 81 return -1;
76 static_cast<IFWL_Edit*>(m_pIface)->AddSelRange(nStart, nCount); 82 GetWidget()->AddSelRange(nStart, nCount);
77 int32_t pos = 0; 83 int32_t pos = 0;
78 int32_t sum = static_cast<IFWL_Edit*>(m_pIface)->GetTextLength(); 84 int32_t sum = GetWidget()->GetTextLength();
79 if (nCount == -1) { 85 if (nCount == -1) {
80 pos = sum; 86 pos = sum;
81 } else { 87 } else {
82 pos = nStart + nCount; 88 pos = nStart + nCount;
83 } 89 }
84 return static_cast<IFWL_Edit*>(m_pIface)->SetCaretPos(pos); 90 return GetWidget()->SetCaretPos(pos);
85 } 91 }
86 92
87 int32_t CFWL_Edit::CountSelRanges() { 93 int32_t CFWL_Edit::CountSelRanges() {
88 if (!m_pIface) 94 if (!GetWidget())
89 return 0; 95 return 0;
90 return static_cast<IFWL_Edit*>(m_pIface)->CountSelRanges(); 96 return GetWidget()->CountSelRanges();
91 } 97 }
92 98
93 int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t& nStart) { 99 int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t& nStart) {
94 if (!m_pIface) 100 if (!GetWidget())
95 return 0; 101 return 0;
96 return static_cast<IFWL_Edit*>(m_pIface)->GetSelRange(nIndex, nStart); 102 return GetWidget()->GetSelRange(nIndex, nStart);
97 } 103 }
98 104
99 FWL_Error CFWL_Edit::ClearSelections() { 105 FWL_Error CFWL_Edit::ClearSelections() {
100 if (!m_pIface) 106 if (!GetWidget())
101 return FWL_Error::Indefinite; 107 return FWL_Error::Indefinite;
102 return static_cast<IFWL_Edit*>(m_pIface)->ClearSelections(); 108 return GetWidget()->ClearSelections();
103 } 109 }
104 110
105 int32_t CFWL_Edit::GetLimit() { 111 int32_t CFWL_Edit::GetLimit() {
106 if (!m_pIface) 112 if (!GetWidget())
107 return -1; 113 return -1;
108 return static_cast<IFWL_Edit*>(m_pIface)->GetLimit(); 114 return GetWidget()->GetLimit();
109 } 115 }
110 116
111 FWL_Error CFWL_Edit::SetLimit(int32_t nLimit) { 117 FWL_Error CFWL_Edit::SetLimit(int32_t nLimit) {
112 if (!m_pIface) 118 if (!GetWidget())
113 return FWL_Error::Indefinite; 119 return FWL_Error::Indefinite;
114 return static_cast<IFWL_Edit*>(m_pIface)->SetLimit(nLimit); 120 return GetWidget()->SetLimit(nLimit);
115 } 121 }
116 122
117 FWL_Error CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) { 123 FWL_Error CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) {
118 if (!m_pIface) 124 if (!GetWidget())
119 return FWL_Error::Indefinite; 125 return FWL_Error::Indefinite;
120 return static_cast<IFWL_Edit*>(m_pIface)->SetAliasChar(wAlias); 126 return GetWidget()->SetAliasChar(wAlias);
121 } 127 }
122 128
123 FWL_Error CFWL_Edit::Insert(int32_t nStart, 129 FWL_Error CFWL_Edit::Insert(int32_t nStart,
124 const FX_WCHAR* lpText, 130 const FX_WCHAR* lpText,
125 int32_t nLen) { 131 int32_t nLen) {
126 if (!m_pIface) 132 if (!GetWidget())
127 return FWL_Error::Indefinite; 133 return FWL_Error::Indefinite;
128 return static_cast<IFWL_Edit*>(m_pIface)->Insert(nStart, lpText, nLen); 134 return GetWidget()->Insert(nStart, lpText, nLen);
129 } 135 }
130 136
131 FWL_Error CFWL_Edit::DeleteSelections() { 137 FWL_Error CFWL_Edit::DeleteSelections() {
132 if (!m_pIface) 138 if (!GetWidget())
133 return FWL_Error::Indefinite; 139 return FWL_Error::Indefinite;
134 return static_cast<IFWL_Edit*>(m_pIface)->DeleteSelections(); 140 return GetWidget()->DeleteSelections();
135 } 141 }
136 142
137 FWL_Error CFWL_Edit::DeleteRange(int32_t nStart, int32_t nCount) { 143 FWL_Error CFWL_Edit::DeleteRange(int32_t nStart, int32_t nCount) {
138 if (!m_pIface) 144 if (!GetWidget())
139 return FWL_Error::Indefinite; 145 return FWL_Error::Indefinite;
140 return static_cast<IFWL_Edit*>(m_pIface)->DeleteRange(nStart, nCount); 146 return GetWidget()->DeleteRange(nStart, nCount);
141 } 147 }
142 148
143 FWL_Error CFWL_Edit::Replace(int32_t nStart, 149 FWL_Error CFWL_Edit::Replace(int32_t nStart,
144 int32_t nLen, 150 int32_t nLen,
145 const CFX_WideStringC& wsReplace) { 151 const CFX_WideStringC& wsReplace) {
146 if (!m_pIface) 152 if (!GetWidget())
147 return FWL_Error::Indefinite; 153 return FWL_Error::Indefinite;
148 return static_cast<IFWL_Edit*>(m_pIface)->Replace(nStart, nLen, wsReplace); 154 return GetWidget()->Replace(nStart, nLen, wsReplace);
149 } 155 }
150 156
151 FWL_Error CFWL_Edit::DoClipboard(int32_t iCmd) { 157 FWL_Error CFWL_Edit::DoClipboard(int32_t iCmd) {
152 if (!m_pIface) 158 if (!GetWidget())
153 return FWL_Error::Indefinite; 159 return FWL_Error::Indefinite;
154 return static_cast<IFWL_Edit*>(m_pIface)->DoClipboard(iCmd); 160 return GetWidget()->DoClipboard(iCmd);
155 } 161 }
156 162
157 FX_BOOL CFWL_Edit::Redo(const IFDE_TxtEdtDoRecord* pRecord) { 163 FX_BOOL CFWL_Edit::Redo(const IFDE_TxtEdtDoRecord* pRecord) {
158 return m_pIface && static_cast<IFWL_Edit*>(m_pIface)->Redo(pRecord); 164 return GetWidget() && GetWidget()->Redo(pRecord);
159 } 165 }
160 166
161 FX_BOOL CFWL_Edit::Undo(const IFDE_TxtEdtDoRecord* pRecord) { 167 FX_BOOL CFWL_Edit::Undo(const IFDE_TxtEdtDoRecord* pRecord) {
162 return m_pIface && static_cast<IFWL_Edit*>(m_pIface)->Undo(pRecord); 168 return GetWidget() && GetWidget()->Undo(pRecord);
163 } 169 }
164 170
165 FWL_Error CFWL_Edit::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) { 171 FWL_Error CFWL_Edit::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) {
166 if (!m_pIface) 172 if (!GetWidget())
167 return FWL_Error::Indefinite; 173 return FWL_Error::Indefinite;
168 return static_cast<IFWL_Edit*>(m_pIface) 174 return GetWidget()->SetTabWidth(fTabWidth, bEquidistant);
169 ->SetTabWidth(fTabWidth, bEquidistant);
170 } 175 }
171 176
172 FWL_Error CFWL_Edit::SetNumberRange(int32_t iMin, int32_t iMax) { 177 FWL_Error CFWL_Edit::SetNumberRange(int32_t iMin, int32_t iMax) {
173 if (iMin > iMax) { 178 if (iMin > iMax) {
174 return FWL_Error::ParameterInvalid; 179 return FWL_Error::ParameterInvalid;
175 } 180 }
176 return static_cast<IFWL_Edit*>(m_pIface)->SetNumberRange(iMin, iMax); 181 return GetWidget()->SetNumberRange(iMin, iMax);
177 } 182 }
178 183
179 FWL_Error CFWL_Edit::SetBackColor(uint32_t dwColor) { 184 FWL_Error CFWL_Edit::SetBackColor(uint32_t dwColor) {
180 if (!m_pIface) 185 if (!GetWidget())
181 return FWL_Error::Indefinite; 186 return FWL_Error::Indefinite;
182 return static_cast<IFWL_Edit*>(m_pIface)->SetBackColor(dwColor); 187 return GetWidget()->SetBackColor(dwColor);
183 } 188 }
184 189
185 FWL_Error CFWL_Edit::SetFont(const CFX_WideString& wsFont, FX_FLOAT fSize) { 190 FWL_Error CFWL_Edit::SetFont(const CFX_WideString& wsFont, FX_FLOAT fSize) {
186 if (!m_pIface) 191 if (!GetWidget())
187 return FWL_Error::Indefinite; 192 return FWL_Error::Indefinite;
188 return static_cast<IFWL_Edit*>(m_pIface)->SetFont(wsFont, fSize); 193 return GetWidget()->SetFont(wsFont, fSize);
189 } 194 }
190 195
191 FX_BOOL CFWL_Edit::CanUndo() { 196 FX_BOOL CFWL_Edit::CanUndo() {
192 return static_cast<IFWL_Edit*>(m_pIface)->CanUndo(); 197 return GetWidget()->CanUndo();
193 } 198 }
194 199
195 FX_BOOL CFWL_Edit::CanRedo() { 200 FX_BOOL CFWL_Edit::CanRedo() {
196 return static_cast<IFWL_Edit*>(m_pIface)->CanRedo(); 201 return GetWidget()->CanRedo();
197 } 202 }
198 203
199 FX_BOOL CFWL_Edit::Undo() { 204 FX_BOOL CFWL_Edit::Undo() {
200 return static_cast<IFWL_Edit*>(m_pIface)->Undo(); 205 return GetWidget()->Undo();
201 } 206 }
202 207
203 FX_BOOL CFWL_Edit::Redo() { 208 FX_BOOL CFWL_Edit::Redo() {
204 return static_cast<IFWL_Edit*>(m_pIface)->Undo(); 209 return GetWidget()->Undo();
205 } 210 }
206 211
207 FX_BOOL CFWL_Edit::Copy(CFX_WideString& wsCopy) { 212 FX_BOOL CFWL_Edit::Copy(CFX_WideString& wsCopy) {
208 return static_cast<IFWL_Edit*>(m_pIface)->Copy(wsCopy); 213 return GetWidget()->Copy(wsCopy);
209 } 214 }
210 215
211 FX_BOOL CFWL_Edit::Cut(CFX_WideString& wsCut) { 216 FX_BOOL CFWL_Edit::Cut(CFX_WideString& wsCut) {
212 return static_cast<IFWL_Edit*>(m_pIface)->Cut(wsCut); 217 return GetWidget()->Cut(wsCut);
213 } 218 }
214 219
215 FX_BOOL CFWL_Edit::Paste(const CFX_WideString& wsPaste) { 220 FX_BOOL CFWL_Edit::Paste(const CFX_WideString& wsPaste) {
216 return static_cast<IFWL_Edit*>(m_pIface)->Paste(wsPaste); 221 return GetWidget()->Paste(wsPaste);
217 } 222 }
218 223
219 FX_BOOL CFWL_Edit::Delete() { 224 FX_BOOL CFWL_Edit::Delete() {
220 return static_cast<IFWL_Edit*>(m_pIface)->Delete(); 225 return GetWidget()->Delete();
221 } 226 }
222 227
223 void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { 228 void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) {
224 return static_cast<IFWL_Edit*>(m_pIface)->SetScrollOffset(fScrollOffset); 229 return GetWidget()->SetScrollOffset(fScrollOffset);
225 } 230 }
226 231
227 FX_BOOL CFWL_Edit::GetSuggestWords(CFX_PointF pointf, 232 FX_BOOL CFWL_Edit::GetSuggestWords(CFX_PointF pointf,
228 std::vector<CFX_ByteString>& sSuggest) { 233 std::vector<CFX_ByteString>& sSuggest) {
229 return static_cast<IFWL_Edit*>(m_pIface)->GetSuggestWords(pointf, sSuggest); 234 return GetWidget()->GetSuggestWords(pointf, sSuggest);
230 } 235 }
231 236
232 FX_BOOL CFWL_Edit::ReplaceSpellCheckWord(CFX_PointF pointf, 237 FX_BOOL CFWL_Edit::ReplaceSpellCheckWord(CFX_PointF pointf,
233 const CFX_ByteStringC& bsReplace) { 238 const CFX_ByteStringC& bsReplace) {
234 return static_cast<IFWL_Edit*>(m_pIface) 239 return GetWidget()->ReplaceSpellCheckWord(pointf, bsReplace);
235 ->ReplaceSpellCheckWord(pointf, bsReplace);
236 } 240 }
237 241
238 CFWL_Edit::CFWL_Edit() {} 242 CFWL_Edit::CFWL_Edit() {}
239 243
240 CFWL_Edit::~CFWL_Edit() {} 244 CFWL_Edit::~CFWL_Edit() {}
OLDNEW
« no previous file with comments | « xfa/fwl/lightwidget/cfwl_edit.h ('k') | xfa/fwl/lightwidget/cfwl_listbox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698