Merge to XFA: Use stdint.h types throughout PDFium.
[pdfium.git] / xfa / src / fwl / src / lightwidget / edit.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 CFWL_Edit* CFWL_Edit::Create()\r
9 {\r
10     return FX_NEW CFWL_Edit;\r
11 }\r
12 FWL_ERR CFWL_Edit::Initialize(const CFWL_WidgetProperties *pProperties )\r
13 {\r
14     _FWL_RETURN_VALUE_IF_FAIL(!m_pImp, FWL_ERR_Indefinite);\r
15     if (pProperties) {\r
16         *m_pProperties = *pProperties;\r
17     }\r
18     CFWL_WidgetImpProperties prop;\r
19     prop.m_dwStyles = m_pProperties->m_dwStyles;\r
20     prop.m_dwStyleExes = m_pProperties->m_dwStyleExes;\r
21     prop.m_dwStates = m_pProperties->m_dwStates;\r
22     prop.m_ctmOnParent = m_pProperties->m_ctmOnParent;\r
23     if (m_pProperties->m_pParent) {\r
24         prop.m_pParent = m_pProperties->m_pParent->GetWidget();\r
25     }\r
26     if (m_pProperties->m_pOwner) {\r
27         prop.m_pOwner = m_pProperties->m_pOwner->GetWidget();\r
28     }\r
29     prop.m_rtWidget = m_pProperties->m_rtWidget;\r
30     m_pImp = IFWL_Edit::Create();\r
31     FWL_ERR ret = ((IFWL_Edit*)m_pImp)->Initialize(prop);\r
32     if (ret == FWL_ERR_Succeeded) {\r
33         CFWL_Widget::Initialize();\r
34     }\r
35     return ret;\r
36 }\r
37 FWL_ERR CFWL_Edit::SetText(const CFX_WideString &wsText)\r
38 {\r
39     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
40     return ((IFWL_Edit*)m_pImp)->SetText(wsText);\r
41 }\r
42 int32_t CFWL_Edit::GetTextLength() const\r
43 {\r
44     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, 0);\r
45     return ((IFWL_Edit*)m_pImp)->GetTextLength();\r
46 }\r
47 FWL_ERR CFWL_Edit::GetText(CFX_WideString &wsText, int32_t nStart, int32_t nCount) const\r
48 {\r
49     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
50     return ((IFWL_Edit*)m_pImp)->GetText(wsText, nStart, nCount);\r
51 }\r
52 FWL_ERR CFWL_Edit::ClearText()\r
53 {\r
54     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
55     return ((IFWL_Edit*)m_pImp)->ClearText();\r
56 }\r
57 int32_t CFWL_Edit::GetCaretPos() const\r
58 {\r
59     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, -1);\r
60     return ((IFWL_Edit*)m_pImp)->GetCaretPos();\r
61 }\r
62 int32_t CFWL_Edit::SetCaretPos(int32_t nIndex, FX_BOOL bBefore)\r
63 {\r
64     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, -1);\r
65     return ((IFWL_Edit*)m_pImp)->SetCaretPos(nIndex, bBefore);\r
66 }\r
67 FWL_ERR CFWL_Edit::AddSelRange(int32_t nStart, int32_t nCount)\r
68 {\r
69     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
70     ((IFWL_Edit*)m_pImp)->AddSelRange(nStart, nCount);\r
71     int32_t pos = 0;\r
72     int32_t sum = ((IFWL_Edit*)m_pImp)->GetTextLength();\r
73     if (nCount == -1) {\r
74         pos = sum;\r
75     } else {\r
76         pos = nStart + nCount;\r
77     }\r
78     return ((IFWL_Edit*)m_pImp)->SetCaretPos(pos);\r
79 }\r
80 int32_t CFWL_Edit::CountSelRanges()\r
81 {\r
82     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, 0);\r
83     return ((IFWL_Edit*)m_pImp)->CountSelRanges();\r
84 }\r
85 int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t &nStart)\r
86 {\r
87     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, 0);\r
88     return ((IFWL_Edit*)m_pImp)->GetSelRange(nIndex, nStart);\r
89 }\r
90 FWL_ERR CFWL_Edit::ClearSelections()\r
91 {\r
92     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
93     return ((IFWL_Edit*)m_pImp)->ClearSelections();\r
94 }\r
95 int32_t CFWL_Edit::GetLimit()\r
96 {\r
97     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, -1);\r
98     return ((IFWL_Edit*)m_pImp)->GetLimit();\r
99 }\r
100 FWL_ERR CFWL_Edit::SetLimit(int32_t nLimit)\r
101 {\r
102     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
103     return ((IFWL_Edit*)m_pImp)->SetLimit(nLimit);\r
104 }\r
105 FWL_ERR CFWL_Edit::SetAliasChar(FX_WCHAR wAlias)\r
106 {\r
107     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
108     return ((IFWL_Edit*)m_pImp)->SetAliasChar(wAlias);\r
109 }\r
110 FWL_ERR CFWL_Edit::SetFormatString(const CFX_WideString &wsFormat)\r
111 {\r
112     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
113     return ((IFWL_Edit*)m_pImp)->SetFormatString(wsFormat);\r
114 }\r
115 FWL_ERR CFWL_Edit::Insert(int32_t nStart, FX_LPCWSTR lpText, int32_t nLen)\r
116 {\r
117     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
118     return ((IFWL_Edit*)m_pImp)->Insert(nStart, lpText, nLen);\r
119 }\r
120 FWL_ERR CFWL_Edit::DeleteSelections()\r
121 {\r
122     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
123     return ((IFWL_Edit*)m_pImp)->DeleteSelections();\r
124 }\r
125 FWL_ERR CFWL_Edit::DeleteRange(int32_t nStart, int32_t nCount)\r
126 {\r
127     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
128     return ((IFWL_Edit*)m_pImp)->DeleteRange(nStart, nCount);\r
129 }\r
130 FWL_ERR CFWL_Edit::ReplaceSelections(const CFX_WideStringC &wsReplace)\r
131 {\r
132     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
133     return ((IFWL_Edit*)m_pImp)->ReplaceSelections(wsReplace);\r
134 }\r
135 FWL_ERR CFWL_Edit::Replace(int32_t nStart, int32_t nLen, const CFX_WideStringC &wsReplace)\r
136 {\r
137     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
138     return ((IFWL_Edit*)m_pImp)->Replace(nStart, nLen, wsReplace);\r
139 }\r
140 FWL_ERR CFWL_Edit::DoClipboard(int32_t iCmd)\r
141 {\r
142     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
143     return ((IFWL_Edit*)m_pImp)->DoClipboard(iCmd);\r
144 }\r
145 FX_BOOL CFWL_Edit::Redo(FX_BSTR bsRecord)\r
146 {\r
147     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
148     return ((IFWL_Edit*)m_pImp)->Redo(bsRecord);\r
149 }\r
150 FX_BOOL CFWL_Edit::Undo(FX_BSTR bsRecord)\r
151 {\r
152     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
153     return ((IFWL_Edit*)m_pImp)->Undo(bsRecord);\r
154 }\r
155 FWL_ERR CFWL_Edit::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant)\r
156 {\r
157     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
158     return ((IFWL_Edit*)m_pImp)->SetTabWidth(fTabWidth, bEquidistant);\r
159 }\r
160 FWL_ERR CFWL_Edit::SetNumberRange(int32_t iMin, int32_t iMax)\r
161 {\r
162     if (iMin > iMax) {\r
163         return FWL_ERR_Parameter_Invalid;\r
164     }\r
165     return ((IFWL_Edit*)m_pImp)->SetNumberRange(iMin, iMax);\r
166 }\r
167 FWL_ERR CFWL_Edit::SetBackColor(FX_DWORD dwColor)\r
168 {\r
169     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
170     return ((IFWL_Edit*)m_pImp)->SetBackColor(dwColor);\r
171 }\r
172 FWL_ERR CFWL_Edit::SetFont(const CFX_WideString &wsFont, FX_FLOAT fSize)\r
173 {\r
174     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
175     return ((IFWL_Edit*)m_pImp)->SetFont(wsFont, fSize);\r
176 }\r
177 FX_BOOL CFWL_Edit::CanUndo()\r
178 {\r
179     return ((IFWL_Edit*)m_pImp)->CanUndo();\r
180 }\r
181 FX_BOOL CFWL_Edit::CanRedo()\r
182 {\r
183     return ((IFWL_Edit*)m_pImp)->CanRedo();\r
184 }\r
185 FX_BOOL CFWL_Edit::Undo()\r
186 {\r
187     return ((IFWL_Edit*)m_pImp)->Undo();\r
188 }\r
189 FX_BOOL CFWL_Edit::Redo()\r
190 {\r
191     return ((IFWL_Edit*)m_pImp)->Undo();\r
192 }\r
193 FX_BOOL CFWL_Edit::Copy(CFX_WideString &wsCopy)\r
194 {\r
195     return ((IFWL_Edit*)m_pImp)->Copy(wsCopy);\r
196 }\r
197 FX_BOOL CFWL_Edit::Cut(CFX_WideString &wsCut)\r
198 {\r
199     return ((IFWL_Edit*)m_pImp)->Cut(wsCut);\r
200 }\r
201 FX_BOOL CFWL_Edit::Paste(const CFX_WideString &wsPaste)\r
202 {\r
203     return ((IFWL_Edit*)m_pImp)->Paste(wsPaste);\r
204 }\r
205 FX_BOOL CFWL_Edit::Delete()\r
206 {\r
207     return ((IFWL_Edit*)m_pImp)->Delete();\r
208 }\r
209 void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset)\r
210 {\r
211     return ((IFWL_Edit*)m_pImp)->SetScrollOffset(fScrollOffset);\r
212 }\r
213 FX_BOOL CFWL_Edit::GetSuggestWords(CFX_PointF pointf, CFX_ByteStringArray &sSuggest)\r
214 {\r
215     return ((IFWL_Edit*)m_pImp)->GetSuggestWords(pointf, sSuggest);\r
216 }\r
217 FX_BOOL CFWL_Edit::ReplaceSpellCheckWord(CFX_PointF pointf, FX_BSTR bsReplace)\r
218 {\r
219     return ((IFWL_Edit*)m_pImp)->ReplaceSpellCheckWord(pointf, bsReplace);\r
220 }\r
221 CFWL_Edit::CFWL_Edit()\r
222 {\r
223 }\r
224 CFWL_Edit::~CFWL_Edit()\r
225 {\r
226 }\r