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