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