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 <memory>
8
9 #include "xfa/src/foxitlib.h"
10
Create()11 CFWL_Edit* CFWL_Edit::Create() {
12 return new CFWL_Edit;
13 }
Initialize(const CFWL_WidgetProperties * pProperties)14 FWL_ERR CFWL_Edit::Initialize(const CFWL_WidgetProperties* pProperties) {
15 if (m_pIface)
16 return FWL_ERR_Indefinite;
17 if (pProperties) {
18 *m_pProperties = *pProperties;
19 }
20 std::unique_ptr<IFWL_Edit> pEdit(IFWL_Edit::Create(
21 m_pProperties->MakeWidgetImpProperties(nullptr), nullptr));
22 FWL_ERR ret = pEdit->Initialize();
23 if (ret != FWL_ERR_Succeeded) {
24 return ret;
25 }
26 m_pIface = pEdit.release();
27 CFWL_Widget::Initialize();
28 return FWL_ERR_Succeeded;
29 }
SetText(const CFX_WideString & wsText)30 FWL_ERR CFWL_Edit::SetText(const CFX_WideString& wsText) {
31 if (!m_pIface)
32 return FWL_ERR_Indefinite;
33 return static_cast<IFWL_Edit*>(m_pIface)->SetText(wsText);
34 }
GetTextLength() const35 int32_t CFWL_Edit::GetTextLength() const {
36 if (!m_pIface)
37 return 0;
38 return static_cast<IFWL_Edit*>(m_pIface)->GetTextLength();
39 }
GetText(CFX_WideString & wsText,int32_t nStart,int32_t nCount) const40 FWL_ERR CFWL_Edit::GetText(CFX_WideString& wsText,
41 int32_t nStart,
42 int32_t nCount) const {
43 if (!m_pIface)
44 return FWL_ERR_Indefinite;
45 return static_cast<IFWL_Edit*>(m_pIface)->GetText(wsText, nStart, nCount);
46 }
ClearText()47 FWL_ERR CFWL_Edit::ClearText() {
48 if (!m_pIface)
49 return FWL_ERR_Indefinite;
50 return static_cast<IFWL_Edit*>(m_pIface)->ClearText();
51 }
GetCaretPos() const52 int32_t CFWL_Edit::GetCaretPos() const {
53 if (!m_pIface)
54 return -1;
55 return static_cast<IFWL_Edit*>(m_pIface)->GetCaretPos();
56 }
SetCaretPos(int32_t nIndex,FX_BOOL bBefore)57 int32_t CFWL_Edit::SetCaretPos(int32_t nIndex, FX_BOOL bBefore) {
58 if (!m_pIface)
59 return -1;
60 return static_cast<IFWL_Edit*>(m_pIface)->SetCaretPos(nIndex, bBefore);
61 }
AddSelRange(int32_t nStart,int32_t nCount)62 FWL_ERR CFWL_Edit::AddSelRange(int32_t nStart, int32_t nCount) {
63 if (!m_pIface)
64 return FWL_ERR_Indefinite;
65 static_cast<IFWL_Edit*>(m_pIface)->AddSelRange(nStart, nCount);
66 int32_t pos = 0;
67 int32_t sum = static_cast<IFWL_Edit*>(m_pIface)->GetTextLength();
68 if (nCount == -1) {
69 pos = sum;
70 } else {
71 pos = nStart + nCount;
72 }
73 return static_cast<IFWL_Edit*>(m_pIface)->SetCaretPos(pos);
74 }
CountSelRanges()75 int32_t CFWL_Edit::CountSelRanges() {
76 if (!m_pIface)
77 return 0;
78 return static_cast<IFWL_Edit*>(m_pIface)->CountSelRanges();
79 }
GetSelRange(int32_t nIndex,int32_t & nStart)80 int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t& nStart) {
81 if (!m_pIface)
82 return 0;
83 return static_cast<IFWL_Edit*>(m_pIface)->GetSelRange(nIndex, nStart);
84 }
ClearSelections()85 FWL_ERR CFWL_Edit::ClearSelections() {
86 if (!m_pIface)
87 return FWL_ERR_Indefinite;
88 return static_cast<IFWL_Edit*>(m_pIface)->ClearSelections();
89 }
GetLimit()90 int32_t CFWL_Edit::GetLimit() {
91 if (!m_pIface)
92 return -1;
93 return static_cast<IFWL_Edit*>(m_pIface)->GetLimit();
94 }
SetLimit(int32_t nLimit)95 FWL_ERR CFWL_Edit::SetLimit(int32_t nLimit) {
96 if (!m_pIface)
97 return FWL_ERR_Indefinite;
98 return static_cast<IFWL_Edit*>(m_pIface)->SetLimit(nLimit);
99 }
SetAliasChar(FX_WCHAR wAlias)100 FWL_ERR CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) {
101 if (!m_pIface)
102 return FWL_ERR_Indefinite;
103 return static_cast<IFWL_Edit*>(m_pIface)->SetAliasChar(wAlias);
104 }
SetFormatString(const CFX_WideString & wsFormat)105 FWL_ERR CFWL_Edit::SetFormatString(const CFX_WideString& wsFormat) {
106 if (!m_pIface)
107 return FWL_ERR_Indefinite;
108 return static_cast<IFWL_Edit*>(m_pIface)->SetFormatString(wsFormat);
109 }
Insert(int32_t nStart,const FX_WCHAR * lpText,int32_t nLen)110 FWL_ERR CFWL_Edit::Insert(int32_t nStart,
111 const FX_WCHAR* lpText,
112 int32_t nLen) {
113 if (!m_pIface)
114 return FWL_ERR_Indefinite;
115 return static_cast<IFWL_Edit*>(m_pIface)->Insert(nStart, lpText, nLen);
116 }
DeleteSelections()117 FWL_ERR CFWL_Edit::DeleteSelections() {
118 if (!m_pIface)
119 return FWL_ERR_Indefinite;
120 return static_cast<IFWL_Edit*>(m_pIface)->DeleteSelections();
121 }
DeleteRange(int32_t nStart,int32_t nCount)122 FWL_ERR CFWL_Edit::DeleteRange(int32_t nStart, int32_t nCount) {
123 if (!m_pIface)
124 return FWL_ERR_Indefinite;
125 return static_cast<IFWL_Edit*>(m_pIface)->DeleteRange(nStart, nCount);
126 }
ReplaceSelections(const CFX_WideStringC & wsReplace)127 FWL_ERR CFWL_Edit::ReplaceSelections(const CFX_WideStringC& wsReplace) {
128 if (!m_pIface)
129 return FWL_ERR_Indefinite;
130 return static_cast<IFWL_Edit*>(m_pIface)->ReplaceSelections(wsReplace);
131 }
Replace(int32_t nStart,int32_t nLen,const CFX_WideStringC & wsReplace)132 FWL_ERR CFWL_Edit::Replace(int32_t nStart,
133 int32_t nLen,
134 const CFX_WideStringC& wsReplace) {
135 if (!m_pIface)
136 return FWL_ERR_Indefinite;
137 return static_cast<IFWL_Edit*>(m_pIface)->Replace(nStart, nLen, wsReplace);
138 }
DoClipboard(int32_t iCmd)139 FWL_ERR CFWL_Edit::DoClipboard(int32_t iCmd) {
140 if (!m_pIface)
141 return FWL_ERR_Indefinite;
142 return static_cast<IFWL_Edit*>(m_pIface)->DoClipboard(iCmd);
143 }
Redo(const CFX_ByteStringC & bsRecord)144 FX_BOOL CFWL_Edit::Redo(const CFX_ByteStringC& bsRecord) {
145 if (!m_pIface)
146 return FALSE;
147 return static_cast<IFWL_Edit*>(m_pIface)->Redo(bsRecord);
148 }
Undo(const CFX_ByteStringC & bsRecord)149 FX_BOOL CFWL_Edit::Undo(const CFX_ByteStringC& bsRecord) {
150 if (!m_pIface)
151 return FALSE;
152 return static_cast<IFWL_Edit*>(m_pIface)->Undo(bsRecord);
153 }
SetTabWidth(FX_FLOAT fTabWidth,FX_BOOL bEquidistant)154 FWL_ERR CFWL_Edit::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) {
155 if (!m_pIface)
156 return FWL_ERR_Indefinite;
157 return static_cast<IFWL_Edit*>(m_pIface)
158 ->SetTabWidth(fTabWidth, bEquidistant);
159 }
SetNumberRange(int32_t iMin,int32_t iMax)160 FWL_ERR CFWL_Edit::SetNumberRange(int32_t iMin, int32_t iMax) {
161 if (iMin > iMax) {
162 return FWL_ERR_Parameter_Invalid;
163 }
164 return static_cast<IFWL_Edit*>(m_pIface)->SetNumberRange(iMin, iMax);
165 }
SetBackColor(FX_DWORD dwColor)166 FWL_ERR CFWL_Edit::SetBackColor(FX_DWORD dwColor) {
167 if (!m_pIface)
168 return FWL_ERR_Indefinite;
169 return static_cast<IFWL_Edit*>(m_pIface)->SetBackColor(dwColor);
170 }
SetFont(const CFX_WideString & wsFont,FX_FLOAT fSize)171 FWL_ERR CFWL_Edit::SetFont(const CFX_WideString& wsFont, FX_FLOAT fSize) {
172 if (!m_pIface)
173 return FWL_ERR_Indefinite;
174 return static_cast<IFWL_Edit*>(m_pIface)->SetFont(wsFont, fSize);
175 }
CanUndo()176 FX_BOOL CFWL_Edit::CanUndo() {
177 return static_cast<IFWL_Edit*>(m_pIface)->CanUndo();
178 }
CanRedo()179 FX_BOOL CFWL_Edit::CanRedo() {
180 return static_cast<IFWL_Edit*>(m_pIface)->CanRedo();
181 }
Undo()182 FX_BOOL CFWL_Edit::Undo() {
183 return static_cast<IFWL_Edit*>(m_pIface)->Undo();
184 }
Redo()185 FX_BOOL CFWL_Edit::Redo() {
186 return static_cast<IFWL_Edit*>(m_pIface)->Undo();
187 }
Copy(CFX_WideString & wsCopy)188 FX_BOOL CFWL_Edit::Copy(CFX_WideString& wsCopy) {
189 return static_cast<IFWL_Edit*>(m_pIface)->Copy(wsCopy);
190 }
Cut(CFX_WideString & wsCut)191 FX_BOOL CFWL_Edit::Cut(CFX_WideString& wsCut) {
192 return static_cast<IFWL_Edit*>(m_pIface)->Cut(wsCut);
193 }
Paste(const CFX_WideString & wsPaste)194 FX_BOOL CFWL_Edit::Paste(const CFX_WideString& wsPaste) {
195 return static_cast<IFWL_Edit*>(m_pIface)->Paste(wsPaste);
196 }
Delete()197 FX_BOOL CFWL_Edit::Delete() {
198 return static_cast<IFWL_Edit*>(m_pIface)->Delete();
199 }
SetScrollOffset(FX_FLOAT fScrollOffset)200 void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) {
201 return static_cast<IFWL_Edit*>(m_pIface)->SetScrollOffset(fScrollOffset);
202 }
GetSuggestWords(CFX_PointF pointf,CFX_ByteStringArray & sSuggest)203 FX_BOOL CFWL_Edit::GetSuggestWords(CFX_PointF pointf,
204 CFX_ByteStringArray& sSuggest) {
205 return static_cast<IFWL_Edit*>(m_pIface)->GetSuggestWords(pointf, sSuggest);
206 }
ReplaceSpellCheckWord(CFX_PointF pointf,const CFX_ByteStringC & bsReplace)207 FX_BOOL CFWL_Edit::ReplaceSpellCheckWord(CFX_PointF pointf,
208 const CFX_ByteStringC& bsReplace) {
209 return static_cast<IFWL_Edit*>(m_pIface)
210 ->ReplaceSpellCheckWord(pointf, bsReplace);
211 }
CFWL_Edit()212 CFWL_Edit::CFWL_Edit() {}
~CFWL_Edit()213 CFWL_Edit::~CFWL_Edit() {}
214