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);
208 * Initializes this instance of %TextBox with the specified parameters.
212 * @return An error code
213 * @param[in] rect An instance of the Graphics::FloatRectangle class @n
214 * This instance represents the x and y coordinates of the top-left corner of the created window along with
215 * the width and height of the control.
216 * @param[in] border The border style
217 * @exception E_SUCCESS The method is successful.
218 * @exception E_SYSTEM A system error has occurred.
220 result Construct(const Tizen::Graphics::FloatRectangle& rect, TextBoxBorder border = TEXT_BOX_BORDER_ROUNDED);
225 * Sets the auto-link mask.
229 * @return An error code
230 * @param[in] autoLinks The auto-link mask @n
231 * Multiple link types can be combined using the bitwise OR operator (see Tizen::Base::Utility::LinkType). @n
232 * For more information, see <a href="../org.tizen.native.appprogramming/html/guide/ui/auto_link_detection.htm">AutoLink Detection</a>.
233 * @exception E_SUCCESS The method is successful.
234 * @exception E_SYSTEM A system error has occurred.
235 * @remarks When @c autoLinks is set to @c 0, the auto-link detection is disabled.
236 * @see Tizen::Base::Utility::LinkType
237 * @see GetAutoLinkMask()
239 result SetAutoLinkMask(unsigned long autoLinks);
242 * Gets the auto-link mask.
246 * @return The auto-link mask
247 * @exception E_SUCCESS The method is successful.
248 * @exception E_SYSTEM A system error has occurred.
249 * @remarks The specific error code can be accessed using the GetLastResult() method.
250 * @see SetAutoLinkMask()
252 unsigned long GetAutoLinkMask(void) const;
255 * Adds a link event listener.
259 * @param[in] listener The event listener to add
260 * @see RemoveUiLinkEventListener()
262 void AddUiLinkEventListener(Tizen::Ui::IUiLinkEventListener& listener);
265 * Removes the specified link event listener. @n
266 * The removed listener cannot listen to events when they are fired.
270 * @param[in] listener The event listener to remove
271 * @see AddUiLinkEventListener()
273 void RemoveUiLinkEventListener(Tizen::Ui::IUiLinkEventListener& listener);
277 * Appends the specified character at the end of the text.
281 * @return An error code
282 * @param[in] character The character to add
283 * @exception E_SUCCESS The method is successful.
284 * @exception E_SYSTEM A system error has occurred.
285 * @remarks 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 AppendCharacter(const Tizen::Base::Character& character);
291 * Appends the specified text at the end of the text.
295 * @return An error code
296 * @param[in] text The text to append
297 * @exception E_SUCCESS The method is successful.
298 * @exception E_SYSTEM A system error has occurred.
299 * @remarks To denote the end of a line use '\\n'. @n
300 * The method modifies the text buffer that is managed by the %TextBox control. @n
301 * To display the changes, the control must be drawn again.
303 result AppendText(const Tizen::Base::String& text);
306 * Clears the text that is displayed by the %TextBox control.
310 * @return An error code
311 * @exception E_SUCCESS The method is successful.
312 * @exception E_SYSTEM A system error has occurred.
313 * @remarks The method modifies the text buffer that is managed by the %TextBox control. @n
314 * To display the changes, the control must be drawn again.
319 * Gets the number of the lines contained in the %TextBox control.
323 * @return The line count of the text, @n
324 * else @c -1 if an error occurs
325 * @exception E_SUCCESS The method is successful.
326 * @remarks The specific error code can be accessed using the GetLastResult() method.
328 int GetLineCount(void) const;
331 * Gets the text that is displayed by the %TextBox control.
335 * @return The text of the %TextBox control, @n
336 * else an empty string if an error occurs
337 * @exception E_SUCCESS The method is successful.
338 * @exception E_SYSTEM A system error has occurred.
339 * @remarks The specific error code can be accessed using the GetLastResult() method.
342 Tizen::Base::String GetText(void) const;
345 * Gets a portion of the text that is displayed by the %TextBox control.
349 * @return The specified portion of the text, @n
350 * else an empty string if an error occurs
351 * @param[in] start The starting index of the range
352 * @param[in] end The last index of the range
353 * @exception E_SUCCESS The method is successful.
354 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure. @n
355 * The index is greater than the number of elements or less than @c 0.
356 * @exception E_SYSTEM A system error has occurred.
357 * @remarks The specific error code can be accessed using the GetLastResult() method.
360 Tizen::Base::String GetText(int start, int end) const;
363 * Gets the length of the text that is displayed by the %TextBox control.
367 * @return The length of the text, @n
368 * else @c -1 if an error occurs
369 * @exception E_SUCCESS The method is successful.
370 * @exception E_SYSTEM A system error has occurred.
371 * @remarks The specific error code can be accessed using the GetLastResult() method.
373 int GetTextLength(void) const;
376 * Inserts the character at the specified index.
380 * @return An error code
381 * @param[in] index The position at which to insert the character
382 * @param[in] character The character to insert
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 InsertCharacterAt(int index, const Tizen::Base::Character& character);
391 * Inserts the text at the specified index.
395 * @return An error code
396 * @param[in] index The position at which to insert the text
397 * @param[in] text The text to insert
398 * @exception E_SUCCESS The method is successful.
399 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure. @n
400 * The specified @c index is greater than the number of elements or less than @c 0.
401 * @exception E_SYSTEM A system error has occurred.
403 result InsertTextAt(int index, const Tizen::Base::String& text);
406 * Sets the text to be displayed.
410 * @return An error code
411 * @param[in] text The text to display
412 * @exception E_SUCCESS The method is successful.
413 * @exception E_SYSTEM A system error has occurred.
414 * @remarks To denote the end of a line use '\\n'. @n
415 * The method modifies the text buffer that is managed by the %TextBox control. @n
416 * To display the changes, the control must be drawn again.
418 result SetText(const Tizen::Base::String& text);
422 * Gets the line spacing.
426 * @return The line spacing, @n
427 * else @c -1 if an error occurs
428 * @exception E_SUCCESS The method is successful.
429 * @remarks The specific error code can be accessed using the GetLastResult() method.
430 * @see SetLineSpacing()
432 int GetLineSpacing(void) const;
435 * Gets the line spacing.
439 * @return The line spacing, @n
440 * else @c -1 if an error occurs
441 * @exception E_SUCCESS The method is successful.
442 * @remarks The specific error code can be accessed using the GetLastResult() method.
443 * @see SetLineSpacing()
445 float GetLineSpacingF(void) const;
448 * Sets the line spacing. @n
449 * The line spacing is determined by multiplying @c multiplier to the default line spacing and adding @c extra. @n
452 * The line spacing = (default line spacing) * multiplier + extra
457 * @return An error code
458 * @param[in] multiplier The line spacing multiplier
459 * @param[in] extra The extra line spacing
460 * @exception E_SUCCESS The method is successful.
461 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
462 * The specified line spacing value cannot be supported.
463 * @exception E_SYSTEM A system error has occurred.
464 * @see GetLineSpacing()
466 result SetLineSpacing(int multiplier, int extra);
469 * Sets the line spacing. @n
470 * The line spacing is determined by multiplying @c multiplier to the default line spacing and adding @c extra. @n
473 * The line spacing = (default line spacing) * multiplier + extra
478 * @return An error code
479 * @param[in] multiplier The line spacing multiplier
480 * @param[in] extra The extra line spacing
481 * @exception E_SUCCESS The method is successful.
482 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
483 * The specified line spacing value cannot be supported.
484 * @exception E_SYSTEM A system error has occurred.
485 * @see GetLineSpacingF()
487 result SetLineSpacing(int multiplier, float extra);
491 * Gets the horizontal text alignment.
495 * @return The horizontal text alignment
496 * @exception E_SUCCESS The method is successful.
497 * @exception E_SYSTEM A system error has occurred.
498 * @remarks The specific error code can be accessed using the GetLastResult() method.
499 * @see SetTextAlignment()
501 HorizontalAlignment GetTextAlignment(void) const;
504 * Sets the horizontal text alignment.
508 * @return An error code
509 * @param[in] alignment The horizontal text alignment
510 * @exception E_SUCCESS The method is successful.
511 * @exception E_SYSTEM A system error has occurred.
512 * @see GetTextAlignment()
514 result SetTextAlignment(HorizontalAlignment alignment);
518 * Gets the text size of the %TextBox control.
522 * @return The size of the text, @n
523 * else @c -1 if an error occurs
524 * @exception E_SUCCESS The method is successful.
525 * @exception E_SYSTEM A system error has occurred.
526 * @remarks The specific error code can be accessed using the GetLastResult() method.
529 int GetTextSize(void) const;
532 * Gets the text size of the %TextBox control.
536 * @return The size of the text, @n
537 * else @c -1 if an error occurs
538 * @exception E_SUCCESS The method is successful.
539 * @exception E_SYSTEM A system error has occurred.
540 * @remarks The specific error code can be accessed using the GetLastResult() method.
543 float GetTextSizeF(void) const;
546 * Sets the text size.
550 * @return An error code
551 * @param[in] size The text size
552 * @exception E_SUCCESS The method is successful.
553 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
554 * The specified @c size cannot be a negative integer.
555 * @exception E_SYSTEM A system error has occurred.
558 result SetTextSize(int size);
561 * Sets the text size.
565 * @return An error code
566 * @param[in] size The text size
567 * @exception E_SUCCESS The method is successful.
568 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
569 * The specified @c size cannot be a negative integer.
570 * @exception E_SYSTEM A system error has occurred.
571 * @see GetTextSizeF()
573 result SetTextSize(float size);
578 * Gets the font typeface name and the style mask of the %TextBox control.
580 * @brief <i> [Deprecated] </i>
581 * @deprecated This method is deprecated. Instead of using this method, use the GetTextStyle() method.
584 * @return An error code
585 * @param[out] typefaceName The name of the font typeface
586 * @param[out] style The text style (see TextBoxTextStyle)
587 * @exception E_SUCCESS The method is successful.
588 * @exception E_SYSTEM A system error has occurred.
589 * @remarks Multiple styles can be combined using the bitwise OR operator.
591 * @see Tizen::Graphics::Font::GetSystemFontListN()
592 * @see TextBoxTextStyle
595 result GetFontType(Tizen::Base::String& typefaceName, unsigned long& style) const;
598 * Gets the text style mask of the %TextBox control.
602 * @return A bitwise combination of Tizen::Ui::Controls::TextBoxTextStyle
603 * @see SetTextStyle()
604 * @see TextBoxTextStyle
606 unsigned long GetTextStyle(void) const;
610 * Sets the font and the style mask of the %TextBox control.
612 * @brief <i> [Deprecated] </i>
613 * @deprecated This method is deprecated. Instead of using this method, use the SetTextStyle() method.
616 * @return An error code
617 * @param[in] typefaceName The name of the font typeface
618 * @param[in] style The text style @n
619 * Multiple styles can be combined using the bitwise OR operator(see TextBoxTextStyle).
620 * @exception E_SUCCESS The method is successful.
621 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified font typeface is not supported.
622 * @exception E_SYSTEM A system error has occurred.
623 * @remarks The specified font typeface must be one of the system fonts. @n
624 * @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
627 * @see Tizen::Graphics::Font::GetSystemFontListN()
628 * @see TextBoxTextStyle
631 result SetFontType(const Tizen::Base::String& typefaceName, unsigned long style);
634 * Sets the text style mask of the %TextBox control.
638 * @return An error code
639 * @param[in] style The text style @n
640 * Multiple styles can be combined using the bitwise OR operator (see Tizen::Ui::Controls::TextBoxTextStyle).
641 * @exception E_SUCCESS The method is successful.
642 * @exception E_OUT_OF_MEMORY The memory is insufficient.
643 * @see GetTextStyle()
644 * @see TextBoxTextStyle
646 result SetTextStyle(unsigned long style);
648 using Control::SetFont;
651 * Sets the font to render the text.
653 * @brief <i> [Deprecated] </i>
654 * @deprecated This method is deprecated. Instead of using this method, use the SetFont(const String& fontName) method of superclass.
657 * @return An error code
658 * @param[in] font The text font
659 * @exception E_SUCCESS The method is successful.
660 * @exception E_SYSTEM A system error has occurred.
661 * @remarks All previously set text attributes (style, weight, decoration, and size) will be discarded.
664 result SetFont(const Tizen::Graphics::Font& font);
668 * Releases the selection of the current text block.
672 * @return An error code
673 * @exception E_SUCCESS The method is successful.
674 * @exception E_SYSTEM A system error has occurred.
675 * @see GetBlockRange()
676 * @see SetBlockRange()
678 result ReleaseBlock(void);
681 * Gets the start and the end index of the currently selected text block.
685 * @return An error code
686 * @param[out] start The start index of the text block
687 * @param[out] end The end index of the text block
688 * @exception E_SUCCESS The method is successful.
689 * @exception E_SYSTEM A system error has occurred.
690 * @remarks The method returns @c start = 0 and @c end = 0 if there is no selected text block.
691 * @see ReleaseBlock()
692 * @see SetBlockRange()
694 result GetBlockRange(int& start, int& end) const;
697 * Sets the specified block of the text.
701 * @return An error code
702 * @param[in] start The start index of the text block
703 * @param[in] end The end index of the text block
704 * @exception E_SUCCESS The method is successful.
705 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure. @n
706 * Either the @c start or @c end parameters are greater than the number of elements or less than @c 0.
707 * @exception E_SYSTEM A system error has occurred.
708 * @see ReleaseBlock()
709 * @see GetBlockRange()
711 result SetBlockRange(int start, int end);
715 * Gets the color of the %TextBox control for the specified status.
719 * @return The color of the %TextBox control, @n
720 * else RGBA (0,0,0,0) if an error occurs
721 * @param[in] status The state of the %TextBox control
722 * @exception E_SUCCESS The method is successful.
723 * @remarks The specific error code can be accessed using the GetLastResult() method.
726 Tizen::Graphics::Color GetColor(TextBoxStatus status) const;
729 * Gets the text color of the specified text color type.
733 * @return The color, @n
734 * else RGBA (0,0,0,0) if an error occurs
735 * @param[in] type The text color type
736 * @exception E_SUCCESS The method is successful.
737 * @exception E_SYSTEM A system error has occurred.
738 * @remarks The specific error code can be accessed using the GetLastResult() method.
739 * @see SetTextColor()
741 Tizen::Graphics::Color GetTextColor(TextBoxTextColor type) const;
744 * Sets the background bitmap of the %TextBox control.
748 * @return An error code
749 * @param[in] status The state of the %TextBox control
750 * @param[in] bitmap The background bitmap
751 * @exception E_SUCCESS The method is successful.
752 * @exception E_SYSTEM A system error has occurred.
753 * @see SetBackgroundColor()
755 result SetBackgroundBitmap(TextBoxStatus status, const Tizen::Graphics::Bitmap& bitmap);
758 * Sets the color of the %TextBox control for the specified status.
762 * @return An error code
763 * @param[in] status The state of the %TextBox control
764 * @param[in] color The color to set
765 * @exception E_SUCCESS The method is successful.
766 * @exception E_SYSTEM A system error has occurred.
769 result SetColor(TextBoxStatus status, const Tizen::Graphics::Color& color);
772 * Sets the text color of the %TextBox control for the specified text type.
776 * @return An error code
777 * @param[in] type The text color type
778 * @param[in] color The text color to set
779 * @exception E_SUCCESS The method is successful.
780 * @exception E_SYSTEM A system error has occurred.
781 * @see GetTextColor()
783 result SetTextColor(TextBoxTextColor type, const Tizen::Graphics::Color& color);
786 * Adds a text block event listener.
790 * @param[in] listener The event listener to add
791 * @remarks Programmatically modifying the text selection does not cause the text block selection event to fire.
792 * @see RemoveTextBlockEventListener()
794 void AddTextBlockEventListener(Tizen::Ui::ITextBlockEventListener& listener);
797 * Removes the specified text block event listener. @n
798 * The removed listener cannot listen to events when they are fired.
802 * @param[in] listener The event listener to remove
803 * @see AddTextBlockEventListener()
805 void RemoveTextBlockEventListener(Tizen::Ui::ITextBlockEventListener& listener);
808 friend class _TextBoxImpl;
811 TextBox(const TextBox& value);
812 TextBox& operator =(const TextBox& value);
814 }}} //Tizen::Ui::Controls
816 #endif // _FUI_CTRL_TEXT_BOX_H_