Changed indicator bg color.
[platform/framework/native/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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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::Construct(const FloatRectangle& rect, TextBoxBorder border)
66 {
67         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
68         SysAssertf(pTextBoxImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
69
70         pTextBoxImpl = _TextBoxImpl::CreateTextBoxImplN(this);
71         result r = GetLastResult();
72         SysTryReturn(NID_UI_CTRL, pTextBoxImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
73
74         _pControlImpl = pTextBoxImpl;
75
76         r = SetBounds(rect.x, rect.y, rect.width, rect.height);
77         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
78
79         r = pTextBoxImpl->Initialize(border);
80         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
81
82         return r;
83 }
84
85 result
86 TextBox::SetAutoLinkMask(unsigned long autoLinks)
87 {
88         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
89         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
90
91         return pTextBoxImpl->SetAutoLinkMask(autoLinks);
92 }
93
94 unsigned long
95 TextBox::GetAutoLinkMask(void) const
96 {
97         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
98         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
99
100         return pTextBoxImpl->GetAutoLinkMask();
101 }
102
103 void
104 TextBox::AddUiLinkEventListener(IUiLinkEventListener& listener)
105 {
106         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
107         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
108
109         result r = pTextBoxImpl->AddUiLinkEventListener(listener);
110         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
111 }
112
113 void
114 TextBox::RemoveUiLinkEventListener(IUiLinkEventListener& listener)
115 {
116         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
117         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
118
119         result r = pTextBoxImpl->RemoveUiLinkEventListener(listener);
120         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
121 }
122
123 result
124 TextBox::AppendCharacter(const Character& character)
125 {
126         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
127         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
128
129         return pTextBoxImpl->AppendCharacter(character);
130 }
131
132 result
133 TextBox::AppendText(const String& text)
134 {
135         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
136         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
137
138         return pTextBoxImpl->AppendText(text);
139 }
140
141 result
142 TextBox::Clear(void)
143 {
144         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
145         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
146
147         return pTextBoxImpl->Clear();
148 }
149
150 int
151 TextBox::GetLineCount(void) const
152 {
153         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
154         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
155
156         return pTextBoxImpl->GetLineCount();
157 }
158
159 String
160 TextBox::GetText(void) const
161 {
162         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
163         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
164
165         return pTextBoxImpl->GetText();
166 }
167
168 String
169 TextBox::GetText(int start, int end) const
170 {
171         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
172         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
173
174         return pTextBoxImpl->GetText(start, end);
175 }
176
177 int
178 TextBox::GetTextLength(void) const
179 {
180         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
181         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
182
183         return pTextBoxImpl->GetTextLength();
184 }
185
186 result
187 TextBox::InsertCharacterAt(int index, const Character& character)
188 {
189         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
190         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
191
192         return pTextBoxImpl->InsertCharacterAt(index, character);
193 }
194
195 result
196 TextBox::InsertTextAt(int index, const String& text)
197 {
198         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
199         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
200
201         return pTextBoxImpl->InsertTextAt(index, text);
202 }
203
204 result
205 TextBox::SetText(const String& text)
206 {
207         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
208         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
209
210         return pTextBoxImpl->SetText(text);
211 }
212
213 int
214 TextBox::GetLineSpacing(void) const
215 {
216         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
217         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
218
219         return pTextBoxImpl->GetLineSpacing();
220 }
221
222 float
223 TextBox::GetLineSpacingF(void) const
224 {
225         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
226         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
227
228         return pTextBoxImpl->GetLineSpacingF();
229 }
230
231 result
232 TextBox::SetLineSpacing(int multiplier, int extra)
233 {
234         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
235         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
236
237         return pTextBoxImpl->SetLineSpacing(multiplier, extra);
238 }
239
240 result
241 TextBox::SetLineSpacing(int multiplier, float extra)
242 {
243         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
244         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
245
246         return pTextBoxImpl->SetLineSpacing(multiplier, extra);
247 }
248
249 HorizontalAlignment
250 TextBox::GetTextAlignment(void) const
251 {
252         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
253         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
254
255         return pTextBoxImpl->GetTextAlignment();
256 }
257
258 result
259 TextBox::SetTextAlignment(HorizontalAlignment alignment)
260 {
261         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
262         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
263
264         return pTextBoxImpl->SetTextAlignment(alignment);
265 }
266
267 int
268 TextBox::GetTextSize(void) const
269 {
270         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
271         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
272
273         return pTextBoxImpl->GetTextSize();
274 }
275
276 float
277 TextBox::GetTextSizeF(void) const
278 {
279         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
280         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
281
282         return pTextBoxImpl->GetTextSizeF();
283 }
284
285 result
286 TextBox::SetTextSize(int size)
287 {
288         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
289         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
290
291         return pTextBoxImpl->SetTextSize(size);
292 }
293
294 result
295 TextBox::SetTextSize(float size)
296 {
297         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
298         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
299
300         return pTextBoxImpl->SetTextSize(size);
301 }
302
303 result
304 TextBox::GetFontType(String& typefaceName, unsigned long& styleMask) const
305 {
306         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
307         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
308
309         return pTextBoxImpl->GetFontType(typefaceName, styleMask);
310 }
311
312 result
313 TextBox::SetFontType(const String& typefaceName, unsigned long styleMask)
314 {
315         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
316         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
317
318         return pTextBoxImpl->SetFontType(typefaceName, styleMask);
319 }
320
321 unsigned long
322 TextBox::GetTextStyle(void) const
323 {
324         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
325         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
326
327         return pTextBoxImpl->GetTextStyle();
328 }
329
330 result
331 TextBox::SetTextStyle(unsigned long style)
332 {
333         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
334         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
335
336         return pTextBoxImpl->SetTextStyle(style);
337 }
338
339 result
340 TextBox::SetFont(const Font& font)
341 {
342         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
343         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
344
345         return pTextBoxImpl->SetFont(font);
346 }
347
348 result
349 TextBox::ReleaseBlock(void)
350 {
351         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
352         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
353
354
355         return pTextBoxImpl->ReleaseBlock();
356 }
357
358 result
359 TextBox::GetBlockRange(int& start, int& end) const
360 {
361         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
362         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
363
364         return pTextBoxImpl->GetBlockRange(start, end);
365 }
366
367 result
368 TextBox::SetBlockRange(int start, int end)
369 {
370         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
371         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
372
373         return pTextBoxImpl->SetBlockRange(start, end);
374 }
375
376 void
377 TextBox::AddTextBlockEventListener(ITextBlockEventListener& listener)
378 {
379         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
380         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
381
382         result r = pTextBoxImpl->AddTextBlockEventListener(listener);
383         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
384 }
385
386 void
387 TextBox::RemoveTextBlockEventListener(ITextBlockEventListener& listener)
388 {
389         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
390         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
391
392         result r = pTextBoxImpl->RemoveTextBlockEventListener(listener);
393         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
394 }
395
396 Color
397 TextBox::GetColor(TextBoxStatus status) const
398 {
399         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
400         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
401
402         return pTextBoxImpl->GetColor(status);
403 }
404
405 Color
406 TextBox::GetTextColor(TextBoxTextColor type) const
407 {
408         const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
409         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
410
411         return pTextBoxImpl->GetTextColor(type);
412 }
413
414 result
415 TextBox::SetColor(TextBoxStatus status, const Color& color)
416 {
417         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
418         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
419
420         return pTextBoxImpl->SetColor(status, color);
421 }
422
423 result
424 TextBox::SetTextColor(TextBoxTextColor type, const Color& color)
425 {
426         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
427         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
428
429         return pTextBoxImpl->SetTextColor(type, color);
430 }
431
432 result
433 TextBox::SetBackgroundBitmap(TextBoxStatus status, const Bitmap& bitmap)
434 {
435         _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
436         SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
437
438         return pTextBoxImpl->SetBackgroundBitmap(status, bitmap);
439 }
440
441 }}} // Tizen::Ui::Controls