2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
18 * @file FUiCtrlTextBox.h
19 * @brief This is the header file for the %TextBox class.
21 * This header file contains the declarations of the %TextBox class and its helper classes.
24 #ifndef _FUI_CTRL_TEXT_BOX_H_
25 #define _FUI_CTRL_TEXT_BOX_H_
27 #include <FGrpRectangle.h>
28 #include <FUiCtrlControlsTypes.h>
29 #include <FUiControl.h>
30 #include <FUiITextBlockEventListener.h>
31 #include <FUiIUiLinkEventListener.h>
33 namespace Tizen { namespace Ui { namespace Controls
40 namespace Tizen { namespace Ui { namespace Controls
45 * Defines the possible types of text box borders.
51 TEXT_BOX_BORDER_NONE, /**< No border */
52 TEXT_BOX_BORDER_ROUNDED /**< The rounded border */
59 * Defines the possible states of the text box.
65 TEXT_BOX_STATUS_NORMAL, /**< The normal state */
66 TEXT_BOX_STATUS_HIGHLIGHTED, /**< The focus-highlighted state */
67 TEXT_BOX_STATUS_DISABLED /**< The disabled state */
72 * @enum TextBoxTextColor
74 * Defines the possible text colors.
80 TEXT_BOX_TEXT_COLOR_NORMAL, /**< The default text color */
81 TEXT_BOX_TEXT_COLOR_HIGHLIGHTED, /**< The highlighted text color */
82 TEXT_BOX_TEXT_COLOR_DISABLED, /**< The disabled text color */
83 TEXT_BOX_TEXT_COLOR_BLOCKED, /**< The text block color */
84 TEXT_BOX_TEXT_COLOR_LINK /**< The link text color */
89 * @enum TextBoxTextStyle
91 * Defines the possible text styles.
97 TEXT_BOX_TEXT_STYLE_NORMAL = 0x0000, /**< The normal text style */
98 TEXT_BOX_TEXT_STYLE_BOLD = 0x0001, /**< The bold text style */
99 TEXT_BOX_TEXT_STYLE_ITALIC = 0x0002, /**< The italic text style */
100 TEXT_BOX_TEXT_STYLE_UNDERLINE = 0x0004, /**< The underline text style */
101 TEXT_BOX_TEXT_STYLE_STRIKEOUT = 0x0008, /**< The strikeout text style */
102 TEXT_BOX_TEXT_STYLE_MAX = 0x7FFF /**< The placeholder */
107 * @brief This class is an implementation of a %TextBox control.
111 * The %TextBox class displays a non-editable text field.
113 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/implementing_textbox.htm">TextBox</a>.
116 // Sample code for TextBoxSample.h
120 : public Tizen::Ui::Controls::Form
126 bool Initialize(void);
127 virtual result OnInitializing(void);
130 Tizen::Ui::Controls::TextBox* __pTextBox;
135 // Sample code for TextBoxSample.cpp
136 #include <FGraphics.h>
138 #include "TextBoxSample.h"
140 using namespace Tizen::Graphics;
141 using namespace Tizen::Ui::Controls;
144 TextBoxSample::Initialize(void)
146 Construct(FORM_STYLE_NORMAL);
151 TextBoxSample::OnInitializing(void)
153 result r = E_SUCCESS;
155 // Creates an instance of TextBox
156 __pTextBox = new TextBox();
157 __pTextBox->Construct(Rectangle(50, 50, GetClientAreaBounds().width-80, 300), TEXT_BOX_BORDER_ROUNDED);
159 // Sets properties on the text box
160 __pTextBox->SetTextSize(50);
161 __pTextBox->SetText(L"Tizen Developer");
162 __pTextBox->SetTextColor(TEXT_BOX_TEXT_COLOR_HIGHLIGHTED, Color::GetColor(COLOR_ID_RED));
163 __pTextBox->AppendText(L"\nTizen SDK");
165 // Adds the text box to the form
166 AddControl(*__pTextBox);
172 class _OSP_EXPORT_ TextBox
173 : public Tizen::Ui::Control
178 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
186 * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes are called when the destructor of this interface is called.
190 virtual ~TextBox(void);
193 * Initializes this instance of %TextBox with the specified parameters.
197 * @return An error code
198 * @param[in] rect An instance of the Graphics::Rectangle class @n
199 * This instance represents the x and y coordinates of the top-left corner of the created window along with
200 * the width and height of the control.
201 * @param[in] border The border style
202 * @exception E_SUCCESS The method is successful.
203 * @exception E_SYSTEM A system error has occurred.
205 result Construct(const Tizen::Graphics::Rectangle& rect, TextBoxBorder border = TEXT_BOX_BORDER_ROUNDED);
210 * Sets the auto-link mask.
214 * @return An error code
215 * @param[in] autoLinks The auto-link mask @n
216 * Multiple link types can be combined using the bitwise OR operator (see Tizen::Base::Utility::LinkType). @n
217 * For more information, see <a href="../org.tizen.native.appprogramming/html/guide/ui/auto_link_detection.htm">AutoLink Detection</a>.
218 * @exception E_SUCCESS The method is successful.
219 * @exception E_SYSTEM A system error has occurred.
220 * @remarks When @c autoLinks is set to @c 0, the auto-link detection is disabled.
221 * @see Tizen::Base::Utility::LinkType
222 * @see GetAutoLinkMask()
224 result SetAutoLinkMask(unsigned long autoLinks);
227 * Gets the auto-link mask.
231 * @return The auto-link mask
232 * @exception E_SUCCESS The method is successful.
233 * @exception E_SYSTEM A system error has occurred.
234 * @remarks The specific error code can be accessed using the GetLastResult() method.
235 * @see SetAutoLinkMask()
237 unsigned long GetAutoLinkMask(void) const;
240 * Adds a link event listener.
244 * @param[in] listener The event listener to be added
245 * @see RemoveUiLinkEventListener()
247 void AddUiLinkEventListener(Tizen::Ui::IUiLinkEventListener& listener);
250 * Removes the specified link event listener. @n
251 * The removed listener cannot listen to events when they are fired.
255 * @param[in] listener The event listener to be removed
256 * @see AddUiLinkEventListener()
258 void RemoveUiLinkEventListener(Tizen::Ui::IUiLinkEventListener& listener);
262 * Appends the specified character at the end of the text.
266 * @return An error code
267 * @param[in] character The character to be added
268 * @exception E_SUCCESS The method is successful.
269 * @exception E_SYSTEM A system error has occurred.
270 * @remarks The method modifies the text buffer that is managed by the %TextBox control. @n
271 * To display the changes, the control must be drawn again.
273 result AppendCharacter(const Tizen::Base::Character& character);
276 * Appends the specified text at the end of the text.
280 * @return An error code
281 * @param[in] text The text to be appended
282 * @exception E_SUCCESS The method is successful.
283 * @exception E_SYSTEM A system error has occurred.
284 * @remarks To denote the end of a line use '\\n'. @n
285 * The method modifies the text buffer that is managed by the %TextBox control. @n
286 * To display the changes, the control must be drawn again.
288 result AppendText(const Tizen::Base::String& text);
291 * Clears the text that is displayed by the %TextBox control.
295 * @return An error code
296 * @exception E_SUCCESS The method is successful.
297 * @exception E_SYSTEM A system error has occurred.
298 * @remarks The method modifies the text buffer that is managed by the %TextBox control. @n
299 * To display the changes, the control must be drawn again.
304 * Gets the number of the lines contained in the %TextBox control.
308 * @return The line count of the text, @n
309 * else @c -1 if an error occurs
310 * @exception E_SUCCESS The method is successful.
311 * @remarks The specific error code can be accessed using the GetLastResult() method.
313 int GetLineCount(void) const;
316 * Gets the text that is displayed by the %TextBox control.
320 * @return The text of the %TextBox control, @n
321 * else an empty string if an error occurs
322 * @exception E_SUCCESS The method is successful.
323 * @exception E_SYSTEM A system error has occurred.
324 * @remarks The specific error code can be accessed using the GetLastResult() method.
327 Tizen::Base::String GetText(void) const;
330 * Gets a portion of the text that is displayed by the %TextBox control.
334 * @return The specified portion of the text, @n
335 * else an empty string if an error occurs
336 * @param[in] start The starting index of the range
337 * @param[in] end The last index of the range
338 * @exception E_SUCCESS The method is successful.
339 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure. @n
340 * The index is greater than the number of elements or less than @c 0.
341 * @exception E_SYSTEM A system error has occurred.
342 * @remarks The specific error code can be accessed using the GetLastResult() method.
345 Tizen::Base::String GetText(int start, int end) const;
348 * Gets the length of the text that is displayed by the %TextBox control.
352 * @return The length of the text, @n
353 * else @c -1 if an error occurs
354 * @exception E_SUCCESS The method is successful.
355 * @exception E_SYSTEM A system error has occurred.
356 * @remarks The specific error code can be accessed using the GetLastResult() method.
358 int GetTextLength(void) const;
361 * Inserts the character at the specified index.
365 * @return An error code
366 * @param[in] index The position at which to insert the character
367 * @param[in] character The character to be inserted
368 * @exception E_SUCCESS The method is successful.
369 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure. @n
370 * The specified @c index is greater than the number of elements or less than @c 0.
371 * @exception E_SYSTEM A system error has occurred.
373 result InsertCharacterAt(int index, const Tizen::Base::Character& character);
376 * Inserts the text at the specified index.
380 * @return An error code
381 * @param[in] index The position at which to insert the text
382 * @param[in] text The text to be inserted
383 * @exception E_SUCCESS The method is successful.
384 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure. @n
385 * The specified @c index is greater than the number of elements or less than @c 0.
386 * @exception E_SYSTEM A system error has occurred.
388 result InsertTextAt(int index, const Tizen::Base::String& text);
391 * Sets the text to be displayed.
395 * @return An error code
396 * @param[in] text The text to be displayed
397 * @exception E_SUCCESS The method is successful.
398 * @exception E_SYSTEM A system error has occurred.
399 * @remarks To denote the end of a line use '\\n'. @n
400 * The method modifies the text buffer that is managed by the %TextBox control. @n
401 * To display the changes, the control must be drawn again.
403 result SetText(const Tizen::Base::String& text);
407 * Gets the line spacing.
411 * @return The line spacing, @n
412 * else @c -1 if an error occurs
413 * @exception E_SUCCESS The method is successful.
414 * @remarks The specific error code can be accessed using the GetLastResult() method.
415 * @see SetLineSpacing()
417 int GetLineSpacing(void) const;
420 * Sets the line spacing. @n
421 * The line spacing is determined by multiplying @c multiplier to the default line spacing and adding @c extra. @n
424 * The line spacing = (default line spacing) * multiplier + extra
429 * @return An error code
430 * @param[in] multiplier The line spacing multiplier
431 * @param[in] extra The extra line spacing
432 * @exception E_SUCCESS The method is successful.
433 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
434 * The specified line spacing value cannot be supported.
435 * @exception E_SYSTEM A system error has occurred.
436 * @see GetLineSpacing()
438 result SetLineSpacing(int multiplier, int extra);
442 * Gets the horizontal text alignment.
446 * @return The horizontal text alignment
447 * @exception E_SUCCESS The method is successful.
448 * @exception E_SYSTEM A system error has occurred.
449 * @remarks The specific error code can be accessed using the GetLastResult() method.
450 * @see SetTextAlignment()
452 HorizontalAlignment GetTextAlignment(void) const;
455 * Sets the horizontal text alignment.
459 * @return An error code
460 * @param[in] alignment The horizontal text alignment
461 * @exception E_SUCCESS The method is successful.
462 * @exception E_SYSTEM A system error has occurred.
463 * @see GetTextAlignment()
465 result SetTextAlignment(HorizontalAlignment alignment);
469 * Gets the text size of the %TextBox control.
473 * @return The size of the text, @n
474 * else @c -1 if an error occurs
475 * @exception E_SUCCESS The method is successful.
476 * @exception E_SYSTEM A system error has occurred.
477 * @remarks The specific error code can be accessed using the GetLastResult() method.
480 int GetTextSize(void) const;
483 * Sets the text size.
487 * @return An error code
488 * @param[in] size The text size
489 * @exception E_SUCCESS The method is successful.
490 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
491 * The specified @c size cannot be a negative integer.
492 * @exception E_SYSTEM A system error has occurred.
495 result SetTextSize(int size);
500 * Gets the font typeface name and the style mask of the %TextBox control.
502 * @brief <i> [Deprecated] </i>
503 * @deprecated This method is deprecated. Instead of using this method, use the GetTextStyle() method.
506 * @return An error code
507 * @param[out] typefaceName The name of the font typeface
508 * @param[out] style The text style (see TextBoxTextStyle)
509 * @exception E_SUCCESS The method is successful.
510 * @exception E_SYSTEM A system error has occurred.
511 * @remarks Multiple styles can be combined using the bitwise OR operator.
513 * @see Tizen::Graphics::Font::GetSystemFontListN()
514 * @see TextBoxTextStyle
517 result GetFontType(Tizen::Base::String& typefaceName, unsigned long& style) const;
520 * Gets the text style mask of the %TextBox control.
524 * @return A bitwise combination of Tizen::Ui::Controls::TextBoxTextStyle
525 * @see SetTextStyle()
526 * @see TextBoxTextStyle
528 unsigned long GetTextStyle(void) const;
532 * Sets the font and the style mask of the %TextBox control.
534 * @brief <i> [Deprecated] </i>
535 * @deprecated This method is deprecated. Instead of using this method, use the SetTextStyle() method.
538 * @return An error code
539 * @param[in] typefaceName The name of the font typeface
540 * @param[in] style The text style @n
541 * Multiple styles can be combined using the bitwise OR operator(see TextBoxTextStyle).
542 * @exception E_SUCCESS The method is successful.
543 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified font typeface is not supported.
544 * @exception E_SYSTEM A system error has occurred.
545 * @remarks The specified font typeface must be one of the system fonts. @n
546 * @c italic and @c bold cannot be applied at the same time. If the specified style mask contains both @c italic and @c bold, @c italic will
549 * @see Tizen::Graphics::Font::GetSystemFontListN()
550 * @see TextBoxTextStyle
553 result SetFontType(const Tizen::Base::String& typefaceName, unsigned long style);
556 * Sets the text style mask of the %TextBox control.
560 * @return An error code
561 * @param[in] style The text style @n
562 * Multiple styles can be combined using the bitwise OR operator (see Tizen::Ui::Controls::TextBoxTextStyle).
563 * @exception E_SUCCESS The method is successful.
564 * @exception E_OUT_OF_MEMORY The memory is insufficient.
565 * @see GetTextStyle()
566 * @see TextBoxTextStyle
568 result SetTextStyle(unsigned long style);
570 using Control::SetFont;
573 * Sets the font to render the text.
575 * @brief <i> [Deprecated] </i>
576 * @deprecated This method is deprecated. Instead of using this method, use the SetFont(const String& fontName) method of superclass.
579 * @return An error code
580 * @param[in] font The text font
581 * @exception E_SUCCESS The method is successful.
582 * @exception E_SYSTEM A system error has occurred.
583 * @remarks All previously set text attributes (style, weight, decoration, and size) will be discarded.
586 result SetFont(const Tizen::Graphics::Font& font);
590 * Releases the selection of the current text block.
594 * @return An error code
595 * @exception E_SUCCESS The method is successful.
596 * @exception E_SYSTEM A system error has occurred.
597 * @see GetBlockRange()
598 * @see SetBlockRange()
600 result ReleaseBlock(void);
603 * Gets the start and the end index of the currently selected text block.
607 * @return An error code
608 * @param[out] start The start index of the text block
609 * @param[out] end The end index of the text block
610 * @exception E_SUCCESS The method is successful.
611 * @exception E_SYSTEM A system error has occurred.
612 * @remarks The method returns @c start = 0 and @c end = 0 if there is no selected text block.
613 * @see ReleaseBlock()
614 * @see SetBlockRange()
616 result GetBlockRange(int& start, int& end) const;
619 * Sets the specified block of the text.
623 * @return An error code
624 * @param[in] start The start index of the text block
625 * @param[in] end The end index of the text block
626 * @exception E_SUCCESS The method is successful.
627 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure. @n
628 * Either the @c start or @c end parameters are greater than the number of elements or less than @c 0.
629 * @exception E_SYSTEM A system error has occurred.
630 * @see ReleaseBlock()
631 * @see GetBlockRange()
633 result SetBlockRange(int start, int end);
637 * Gets the color of the %TextBox control for the specified status.
641 * @return The color of the %TextBox control, @n
642 * else RGBA (0,0,0,0) if an error occurs
643 * @param[in] status The state of the %TextBox control
644 * @exception E_SUCCESS The method is successful.
645 * @remarks The specific error code can be accessed using the GetLastResult() method.
648 Tizen::Graphics::Color GetColor(TextBoxStatus status) const;
651 * Gets the text color of the specified text color type.
655 * @return The color, @n
656 * else RGBA (0,0,0,0) if an error occurs
657 * @param[in] type The text color type
658 * @exception E_SUCCESS The method is successful.
659 * @exception E_SYSTEM A system error has occurred.
660 * @remarks The specific error code can be accessed using the GetLastResult() method.
661 * @see SetTextColor()
663 Tizen::Graphics::Color GetTextColor(TextBoxTextColor type) const;
666 * Sets the background bitmap of the %TextBox control.
670 * @return An error code
671 * @param[in] status The state of the %TextBox control
672 * @param[in] bitmap The background bitmap
673 * @exception E_SUCCESS The method is successful.
674 * @exception E_SYSTEM A system error has occurred.
675 * @see SetBackgroundColor()
677 result SetBackgroundBitmap(TextBoxStatus status, const Tizen::Graphics::Bitmap& bitmap);
680 * Sets the color of the %TextBox control for the specified status.
684 * @return An error code
685 * @param[in] status The state of the %TextBox control
686 * @param[in] color The color to be set
687 * @exception E_SUCCESS The method is successful.
688 * @exception E_SYSTEM A system error has occurred.
691 result SetColor(TextBoxStatus status, const Tizen::Graphics::Color& color);
694 * Sets the text color of the %TextBox control for the specified text type.
698 * @return An error code
699 * @param[in] type The text color type
700 * @param[in] color The text color to be set
701 * @exception E_SUCCESS The method is successful.
702 * @exception E_SYSTEM A system error has occurred.
703 * @see GetTextColor()
705 result SetTextColor(TextBoxTextColor type, const Tizen::Graphics::Color& color);
708 * Adds a text block event listener.
712 * @param[in] listener The event listener to be added
713 * @remarks Programmatically modifying the text selection does not cause the text block selection event to fire.
714 * @see RemoveTextBlockEventListener()
716 void AddTextBlockEventListener(Tizen::Ui::ITextBlockEventListener& listener);
719 * Removes the specified text block event listener. @n
720 * The removed listener cannot listen to events when they are fired.
724 * @param[in] listener The event listener to be removed
725 * @see AddTextBlockEventListener()
727 void RemoveTextBlockEventListener(Tizen::Ui::ITextBlockEventListener& listener);
730 friend class _TextBoxImpl;
733 TextBox(const TextBox& value);
734 TextBox& operator =(const TextBox& value);
736 }}} //Tizen::Ui::Controls
738 #endif // _FUI_CTRL_TEXT_BOX_H_