2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrlTextBox.cpp
20 * @brief This is the implementation file for TextBox class.
23 #include <FUiCtrlTextBox.h>
24 #include <FBaseSysLog.h>
25 #include "FUiCtrl_TextBoxImpl.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Ui;
31 namespace Tizen { namespace Ui { namespace Controls
34 TextBox::TextBox(void)
38 TextBox::~TextBox(void)
43 TextBox::Construct(const Rectangle& rect, TextBoxBorder border)
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.");
48 pTextBoxImpl = _TextBoxImpl::CreateTextBoxImplN(this);
49 result r = GetLastResult();
50 SysTryReturn(NID_UI_CTRL, pTextBoxImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
52 _pControlImpl = pTextBoxImpl;
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));
57 r = pTextBoxImpl->Initialize(border);
58 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
65 TextBox::Construct(const FloatRectangle& rect, TextBoxBorder border)
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.");
70 pTextBoxImpl = _TextBoxImpl::CreateTextBoxImplN(this);
71 result r = GetLastResult();
72 SysTryReturn(NID_UI_CTRL, pTextBoxImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
74 _pControlImpl = pTextBoxImpl;
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));
79 r = pTextBoxImpl->Initialize(border);
80 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
86 TextBox::SetAutoLinkMask(unsigned long autoLinks)
88 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
89 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
91 return pTextBoxImpl->SetAutoLinkMask(autoLinks);
95 TextBox::GetAutoLinkMask(void) const
97 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
98 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
100 return pTextBoxImpl->GetAutoLinkMask();
104 TextBox::AddUiLinkEventListener(IUiLinkEventListener& listener)
106 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
107 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
109 result r = pTextBoxImpl->AddUiLinkEventListener(listener);
110 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
114 TextBox::RemoveUiLinkEventListener(IUiLinkEventListener& listener)
116 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
117 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
119 result r = pTextBoxImpl->RemoveUiLinkEventListener(listener);
120 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
124 TextBox::AppendCharacter(const Character& character)
126 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
127 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
129 return pTextBoxImpl->AppendCharacter(character);
133 TextBox::AppendText(const String& text)
135 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
136 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
138 return pTextBoxImpl->AppendText(text);
144 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
145 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
147 return pTextBoxImpl->Clear();
151 TextBox::GetLineCount(void) const
153 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
154 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
156 return pTextBoxImpl->GetLineCount();
160 TextBox::GetText(void) const
162 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
163 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
165 return pTextBoxImpl->GetText();
169 TextBox::GetText(int start, int end) const
171 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
172 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
174 return pTextBoxImpl->GetText(start, end);
178 TextBox::GetTextLength(void) const
180 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
181 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
183 return pTextBoxImpl->GetTextLength();
187 TextBox::InsertCharacterAt(int index, const Character& character)
189 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
190 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
192 return pTextBoxImpl->InsertCharacterAt(index, character);
196 TextBox::InsertTextAt(int index, const String& text)
198 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
199 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
201 return pTextBoxImpl->InsertTextAt(index, text);
205 TextBox::SetText(const String& text)
207 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
208 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
210 return pTextBoxImpl->SetText(text);
214 TextBox::GetLineSpacing(void) const
216 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
217 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
219 return pTextBoxImpl->GetLineSpacing();
223 TextBox::GetLineSpacingF(void) const
225 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
226 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
228 return pTextBoxImpl->GetLineSpacingF();
232 TextBox::SetLineSpacing(int multiplier, int extra)
234 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
235 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
237 return pTextBoxImpl->SetLineSpacing(multiplier, extra);
241 TextBox::SetLineSpacing(int multiplier, float extra)
243 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
244 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
246 return pTextBoxImpl->SetLineSpacing(multiplier, extra);
250 TextBox::GetTextAlignment(void) const
252 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
253 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
255 return pTextBoxImpl->GetTextAlignment();
259 TextBox::SetTextAlignment(HorizontalAlignment alignment)
261 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
262 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
264 return pTextBoxImpl->SetTextAlignment(alignment);
268 TextBox::GetTextSize(void) const
270 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
271 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
273 return pTextBoxImpl->GetTextSize();
277 TextBox::GetTextSizeF(void) const
279 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
280 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
282 return pTextBoxImpl->GetTextSizeF();
286 TextBox::SetTextSize(int size)
288 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
289 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
291 return pTextBoxImpl->SetTextSize(size);
295 TextBox::SetTextSize(float size)
297 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
298 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
300 return pTextBoxImpl->SetTextSize(size);
304 TextBox::GetFontType(String& typefaceName, unsigned long& styleMask) const
306 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
307 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
309 return pTextBoxImpl->GetFontType(typefaceName, styleMask);
313 TextBox::SetFontType(const String& typefaceName, unsigned long styleMask)
315 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
316 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
318 return pTextBoxImpl->SetFontType(typefaceName, styleMask);
322 TextBox::GetTextStyle(void) const
324 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
325 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
327 return pTextBoxImpl->GetTextStyle();
331 TextBox::SetTextStyle(unsigned long style)
333 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
334 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
336 return pTextBoxImpl->SetTextStyle(style);
340 TextBox::SetFont(const Font& font)
342 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
343 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
345 return pTextBoxImpl->SetFont(font);
349 TextBox::ReleaseBlock(void)
351 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
352 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
355 return pTextBoxImpl->ReleaseBlock();
359 TextBox::GetBlockRange(int& start, int& end) const
361 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
362 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
364 return pTextBoxImpl->GetBlockRange(start, end);
368 TextBox::SetBlockRange(int start, int end)
370 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
371 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
373 return pTextBoxImpl->SetBlockRange(start, end);
377 TextBox::AddTextBlockEventListener(ITextBlockEventListener& listener)
379 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
380 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
382 result r = pTextBoxImpl->AddTextBlockEventListener(listener);
383 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
387 TextBox::RemoveTextBlockEventListener(ITextBlockEventListener& listener)
389 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
390 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
392 result r = pTextBoxImpl->RemoveTextBlockEventListener(listener);
393 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
397 TextBox::GetColor(TextBoxStatus status) const
399 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
400 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
402 return pTextBoxImpl->GetColor(status);
406 TextBox::GetTextColor(TextBoxTextColor type) const
408 const _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
409 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
411 return pTextBoxImpl->GetTextColor(type);
415 TextBox::SetColor(TextBoxStatus status, const Color& color)
417 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
418 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
420 return pTextBoxImpl->SetColor(status, color);
424 TextBox::SetTextColor(TextBoxTextColor type, const Color& color)
426 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
427 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
429 return pTextBoxImpl->SetTextColor(type, color);
433 TextBox::SetBackgroundBitmap(TextBoxStatus status, const Bitmap& bitmap)
435 _TextBoxImpl* pTextBoxImpl = _TextBoxImpl::GetInstance(*this);
436 SysAssertf(pTextBoxImpl != null, "Not yet constructed. Construct() should be called before use.");
438 return pTextBoxImpl->SetBackgroundBitmap(status, bitmap);
441 }}} // Tizen::Ui::Controls