Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlTextBox.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19 * @file         FUiCtrlTextBox.cpp
20 * @brief        This is the implementation file for TextBox class.
21 */
22
23 #include <FUiCtrlTextBox.h>
24 #include <FBaseSysLog.h>
25 #include "FUiCtrl_TextBoxImpl.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Ui;
30
31 namespace Tizen { namespace Ui { namespace Controls
32 {
33
34 TextBox::TextBox(void)
35 {
36 }
37
38 TextBox::~TextBox(void)
39 {
40 }
41
42 result
43 TextBox::Construct(const Rectangle& rect, TextBoxBorder border)
44 {
45         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
46         SysAssertf(pTextBoxImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
47
48         pTextBoxImpl = _TextBoxImpl::CreateTextBoxImplN(this);
49         result r = GetLastResult();
50         SysTryReturn(NID_UI_CTRL, pTextBoxImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
51
52         _pControlImpl = pTextBoxImpl;
53
54         r = SetBounds(rect.x, rect.y, rect.width, rect.height);
55         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
56
57         r = pTextBoxImpl->Initialize(border);
58         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
59
60         return r;
61
62 }
63
64 result
65 TextBox::SetAutoLinkMask(unsigned long autoLinks)
66 {
67         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
68         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
69
70         return pTextBoxImpl->SetAutoLinkMask(autoLinks);
71 }
72
73 unsigned long
74 TextBox::GetAutoLinkMask(void) const
75 {
76         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
77         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
78
79         return pTextBoxImpl->GetAutoLinkMask();
80 }
81
82 void
83 TextBox::AddUiLinkEventListener(IUiLinkEventListener& listener)
84 {
85         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
86         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
87
88         result r = pTextBoxImpl->AddUiLinkEventListener(listener);
89         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
90 }
91
92 void
93 TextBox::RemoveUiLinkEventListener(IUiLinkEventListener& listener)
94 {
95         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
96         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
97
98         result r = pTextBoxImpl->RemoveUiLinkEventListener(listener);
99         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
100 }
101
102 result
103 TextBox::AppendCharacter(const Character& character)
104 {
105         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
106         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
107
108         return pTextBoxImpl->AppendCharacter(character);
109 }
110
111 result
112 TextBox::AppendText(const String& text)
113 {
114         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
115         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
116
117         return pTextBoxImpl->AppendText(text);
118 }
119
120 result
121 TextBox::Clear(void)
122 {
123         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
124         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
125
126         return pTextBoxImpl->Clear();
127 }
128
129 int
130 TextBox::GetLineCount(void) const
131 {
132         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
133         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
134
135         return pTextBoxImpl->GetLineCount();
136 }
137
138 String
139 TextBox::GetText(void) const
140 {
141         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
142         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
143
144         return pTextBoxImpl->GetText();
145 }
146
147 String
148 TextBox::GetText(int start, int end) const
149 {
150         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
151         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
152
153         return pTextBoxImpl->GetText(start, end);
154 }
155
156 int
157 TextBox::GetTextLength(void) const
158 {
159         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
160         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
161
162         return pTextBoxImpl->GetTextLength();
163 }
164
165 result
166 TextBox::InsertCharacterAt(int index, const Character& character)
167 {
168         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
169         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
170
171         return pTextBoxImpl->InsertCharacterAt(index, character);
172 }
173
174 result
175 TextBox::InsertTextAt(int index, const String& text)
176 {
177         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
178         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
179
180         return pTextBoxImpl->InsertTextAt(index, text);
181 }
182
183 result
184 TextBox::SetText(const String& text)
185 {
186         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
187         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
188
189         return pTextBoxImpl->SetText(text);
190 }
191
192 int
193 TextBox::GetLineSpacing(void) const
194 {
195         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
196         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
197
198         return pTextBoxImpl->GetLineSpacing();
199 }
200
201 result
202 TextBox::SetLineSpacing(int multiplier, int extra)
203 {
204         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
205         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
206
207         return pTextBoxImpl->SetLineSpacing(multiplier, extra);
208 }
209
210 HorizontalAlignment
211 TextBox::GetTextAlignment(void) const
212 {
213         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
214         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
215
216         return pTextBoxImpl->GetTextAlignment();
217 }
218
219 result
220 TextBox::SetTextAlignment(HorizontalAlignment alignment)
221 {
222         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
223         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
224
225         return pTextBoxImpl->SetTextAlignment(alignment);
226 }
227
228 int
229 TextBox::GetTextSize(void) const
230 {
231         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
232         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
233
234         return pTextBoxImpl->GetTextSize();
235 }
236
237 result
238 TextBox::SetTextSize(int size)
239 {
240         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
241         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
242
243         return pTextBoxImpl->SetTextSize(size);
244 }
245
246 result
247 TextBox::GetFontType(String& typefaceName, unsigned long& styleMask) const
248 {
249         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
250         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
251
252         return pTextBoxImpl->GetFontType(typefaceName, styleMask);
253 }
254
255 result
256 TextBox::SetFontType(const String& typefaceName, unsigned long styleMask)
257 {
258         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
259         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
260
261         return pTextBoxImpl->SetFontType(typefaceName, styleMask);
262 }
263
264 unsigned long
265 TextBox::GetTextStyle(void) const
266 {
267         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
268         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
269
270         return pTextBoxImpl->GetTextStyle();
271 }
272
273 result
274 TextBox::SetTextStyle(unsigned long style)
275 {
276         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
277         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
278
279         return pTextBoxImpl->SetTextStyle(style);
280 }
281
282 result
283 TextBox::SetFont(const Font& font)
284 {
285         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
286         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
287
288         return pTextBoxImpl->SetFont(font);
289 }
290
291 result
292 TextBox::ReleaseBlock(void)
293 {
294         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
295         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
296
297
298         return pTextBoxImpl->ReleaseBlock();
299 }
300
301 result
302 TextBox::GetBlockRange(int& start, int& end) const
303 {
304         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
305         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
306
307         return pTextBoxImpl->GetBlockRange(start, end);
308 }
309
310 result
311 TextBox::SetBlockRange(int start, int end)
312 {
313         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
314         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
315
316         return pTextBoxImpl->SetBlockRange(start, end);
317 }
318
319 void
320 TextBox::AddTextBlockEventListener(ITextBlockEventListener& listener)
321 {
322         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
323         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
324
325         result r = pTextBoxImpl->AddTextBlockEventListener(listener);
326         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
327 }
328
329 void
330 TextBox::RemoveTextBlockEventListener(ITextBlockEventListener& listener)
331 {
332         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
333         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
334
335         result r = pTextBoxImpl->RemoveTextBlockEventListener(listener);
336         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
337 }
338
339 Color
340 TextBox::GetColor(TextBoxStatus status) const
341 {
342         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
343         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
344
345         return pTextBoxImpl->GetColor(status);
346 }
347
348 Color
349 TextBox::GetTextColor(TextBoxTextColor type) const
350 {
351         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
352         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
353
354         return pTextBoxImpl->GetTextColor(type);
355 }
356
357 result
358 TextBox::SetColor(TextBoxStatus status, const Color& color)
359 {
360         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
361         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
362
363         return pTextBoxImpl->SetColor(status, color);
364 }
365
366 result
367 TextBox::SetTextColor(TextBoxTextColor type, const Color& color)
368 {
369         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
370         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
371
372         return pTextBoxImpl->SetTextColor(type, color);
373 }
374
375 result
376 TextBox::SetBackgroundBitmap(TextBoxStatus status, const Bitmap& bitmap)
377 {
378         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
379         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
380
381         return pTextBoxImpl->SetBackgroundBitmap(status, bitmap);
382 }
383
384 }}} // Tizen::Ui::Controls