Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / inc / FUiCtrl_TextBoxImpl.h
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                FUiCtrl_TextBoxImpl.h
20  * @brief               This is the header file for the _TextBoxImpl class.
21  *
22  * This header file contains the declarations of the %_EditPresenter class.
23  */
24
25 #ifndef _FUI_CTRL_INTERNAL_TEXT_BOX_IMPL_H_
26 #define _FUI_CTRL_INTERNAL_TEXT_BOX_IMPL_H_
27
28 #include <FOspConfig.h>
29 #include <FUiCtrlTextBox.h>
30 #include <FUiCtrlEditTypes.h>
31 #include <FUiITouchEventListener.h>
32 #include "FUi_ControlImpl.h"
33 #include "FUiCtrl_Edit.h"
34 #include "FUiCtrl_ITextBlockEventListener.h"
35 #include "FUiCtrl_IUiLinkEventListener.h"
36
37 namespace Tizen { namespace Ui { namespace Controls
38 {
39
40 // forward declarations
41 class _PublicTextBlockEvent;
42 class _PublicLinkEvent;
43
44 class _TextBoxImpl
45         : public _ControlImpl
46         , public _IUiLinkEventListener
47         , public _ITextBlockEventListener
48         , virtual public Tizen::Base::Runtime::IEventListener
49 {
50 public:
51         /**
52          * This is the default constructor for this class.
53          *
54          * @since       2.0
55          *
56          */
57         _TextBoxImpl(TextBox* pPublic, _Edit* pCore);
58
59         /**
60          * This is destructor for this class.
61          *
62          * @since       2.0
63          */
64         virtual ~_TextBoxImpl(void);
65
66         /**
67          * Creates this instance of the _TextBoxImpl with the specified parameters.
68          *
69          * @since               2.0
70          * @return              An error code
71          * @param[in]   pPublic             The pointer of the TextBox control.
72          */
73         static _TextBoxImpl* CreateTextBoxImplN(TextBox* pPublic);
74
75         virtual const char* GetPublicClassName(void) const;
76         virtual const TextBox& GetPublic(void) const;
77         virtual TextBox& GetPublic(void);
78         virtual const _Edit& GetCore(void) const;
79         virtual _Edit& GetCore(void);
80
81         /**
82          * Initializes this instance of the TextBox control with the specified parameters.
83          *
84          * @since               2.0
85          * @return              An error code
86          * @param[in]   border              The border style
87          * @exception   E_SUCCESS           The method was successful.
88          * @exception   E_OUT_OF_MEMORY         Insufficient memory.
89          * @exception   E_SYSTEM            A system error occurred.
90          */
91         result Initialize(TextBoxBorder border = TEXT_BOX_BORDER_ROUNDED);
92
93         /**
94          * Sets the auto-link mask.
95          *
96          * @since               2.0
97          * @return              An error code
98          * @param[in]   autoLinks               The auto-link mask @n
99          *                                                              Multiple link types can be combined using the bitwise OR operator (see Tizen::Base::Utility::LinkType).
100          *                                                              For more information, refer to @ref linkAutoLinkDetection "here".
101          * @exception   E_SUCCESS               The method was successful.
102          * @exception   E_SYSTEM                A system error occurred.
103          * @remarks             When @c autoLinks is set to zero, the auto-link detection is disabled.
104          * @see                 Tizen::Base::Utility::LinkType
105          * @see                 GetAutoLinkMask()
106          */
107         result SetAutoLinkMask(unsigned long autoLinks);
108
109         /**
110          * Gets the auto-link mask.
111          *
112          * @since               2.0
113          * @return              The auto-link mask
114          * @exception   E_SUCCESS                               The method was successful.
115          * @exception   E_SYSTEM                                A system error occurred.
116          * @remarks             The specific error code can be accessed using the GetLastResult() method.
117          * @see                 SetAutoLinkMask()
118          */
119         unsigned long GetAutoLinkMask(void) const;
120
121         /**
122          * Adds a link event listener.
123          *
124          * @since               2.0
125          * @param[in]   listener    The event listener to add
126          * @see                 RemoveUiLinkEventListener()
127          */
128         result AddUiLinkEventListener(Tizen::Ui::IUiLinkEventListener& listener);
129
130         /**
131          * Removes the specified link event listener. @n
132          * The removed listener cannot listen to events when they are fired.
133          *
134          * @since               2.0
135          * @param[in]   listener    The event listener to remove
136          * @see                 AddUiLinkEventListener()
137          */
138         result RemoveUiLinkEventListener(Tizen::Ui::IUiLinkEventListener& listener);
139
140 // Text
141         /**
142          * Appends the specified character at the end of the text.
143          *
144          * @since               2.0
145          * @return              An error code
146          * @param[in]   character           The character to add
147          * @exception   E_SUCCESS       The method was successful.
148          * @exception   E_SYSTEM            A system error occurred.
149          * @remarks             The method modifies the text buffer that is managed by the TextBox control.
150          *              To display the changes, the control must be drawn again.
151          */
152         result AppendCharacter(const Tizen::Base::Character& character);
153
154         /**
155          * Appends the specified text at the end of the text.
156          *
157          * @since               1.0
158          * @return              An error code
159          * @param[in]   text        The text to append
160          * @exception   E_SUCCESS   The method was successful.
161          * @exception   E_SYSTEM    A system error occurred.
162          * @remarks     To denote the end of a line use '\\n'. @n
163          *              The method modifies the text buffer that is managed by the TextBox control.
164          *              To display the changes, the control must be drawn again.
165          */
166         result AppendText(const Tizen::Base::String& text);
167
168         /**
169          * Clears text that is displayed by the TextBox control.
170          *
171          * @since               2.0
172          * @return              An error code
173          * @exception   E_SUCCESS       The method was successful.
174          * @exception   E_SYSTEM                A system error occurred.
175          * @remarks             The method modifies the text buffer that is managed by the TextBox control.
176          *              To display the changes, the control must be drawn again.
177          */
178         result Clear(void);
179
180         /**
181          * Gets the number of the lines contained in the TextBox control.
182          *
183          * @since               2.0
184          * @return              The line count of the text, @n
185          *                          else @c -1 if an error occurs
186          * @exception   E_SUCCESS               The method was successful.
187          * @remarks         The specific error code can be accessed using the GetLastResult() method.
188          */
189         int GetLineCount(void) const;
190
191         /**
192          * Gets the text that is displayed by the TextBox control.
193          *
194          * @since               2.0
195          * @return              The text of the TextBox control, @n
196          *                          else an empty string if an error occurs
197          * @exception   E_SUCCESS               The method was successful.
198          * @exception   E_OUT_OF_MEMORY Insufficient memory.
199          * @exception   E_SYSTEM        A system error occurred.
200          * @remarks         The specific error code can be accessed using the GetLastResult() method.
201          * @see                 SetText()
202          */
203         Tizen::Base::String GetText(void) const;
204
205         /**
206          * Gets a portion of the text that is displayed by the TextBox control.
207          *
208          * @since               2.0
209          * @return              The specified portion of the text, @n
210          *              else an empty string if an error occurs
211          * @param[in]   start           The starting index of range
212          * @param[in]   end                 The last index of range
213          * @exception   E_SUCCESS       The method was successful.
214          * @exception   E_OUT_OF_RANGE  The specified index is outside the bounds of the data structure, or the index is greater
215          *                              than the number of elements or less than zero.
216          * @exception   E_SYSTEM            A system error occurred.
217          * @remarks             The specific error code can be accessed using the GetLastResult() method.
218          * @see                 SetText()
219          */
220         Tizen::Base::String GetText(int start, int end) const;
221
222         /**
223          * Gets the length of the text that is displayed by the TextBox control.
224          *
225          * @since               2.0
226          * @return              The length of the text, @n
227          *              else @c -1 if an error occurs
228          * @exception   E_SUCCESS               The method was successful.
229          * @exception   E_SYSTEM                A system error occurred.
230          * @remarks             The specific error code can be accessed using the GetLastResult() method.
231          */
232         int GetTextLength(void) const;
233
234         /**
235          * Inserts the character at the specified index.
236          *
237          * @since               2.0
238          * @return              An error code
239          * @param[in]   index               The position at which to insert the character
240          * @param[in]   character           The character to insert
241          * @exception   E_SUCCESS       The method was successful.
242          * @exception   E_OUT_OF_RANGE  The specified @c index is outside the bounds of the data structure, or @c index is greater than the number of elements or less than zero.
243          * @exception   E_SYSTEM        A system error occurred.
244          */
245         result InsertCharacterAt(int index, const Tizen::Base::Character& character);
246
247         /**
248          * Inserts the text at the specified index.
249          *
250          * @since               2.0
251          * @return              An error code
252          * @param[in]   index               The position at which to insert the text
253          * @param[in]   text                The text to insert
254          * @exception   E_SUCCESS       The method was successful.
255          * @exception   E_OUT_OF_RANGE  The specified @c index is outside the bounds of the data structure, or @c index is greater than the number of elements or less than zero.
256          * @exception   E_SYSTEM        A system error occurred.
257          */
258         result InsertTextAt(int index, const Tizen::Base::String& text);
259
260         /**
261          * Sets the text to display.
262          *
263          * @since               2.0
264          * @return              An error code
265          * @param[in]   text            The text to display
266          * @exception   E_SUCCESS       The method was successful.
267          * @exception   E_SYSTEM        A system error occurred.
268          * @remarks     To denote the end of a line use '\\n'. @n
269          *              The method modifies the text buffer that is managed by the TextBox control.
270          *              To display the changes, the control must be drawn again.
271          */
272         result SetText(const Tizen::Base::String& text);
273
274 // Line Spacing
275         /**
276          * Gets the line spacing.
277          *
278          * @since               2.0
279          * @return      The line spacing,  @n
280          *              else @c -1 if an error occurs
281          * @exception   E_SUCCESS               The method was successful.
282          * @remarks             The specific error code can be accessed using the GetLastResult() method.
283          * @see                 SetLineSpacing()
284          */
285         int GetLineSpacing(void) const;
286
287         /**
288          * Sets the line spacing. @n
289          * The line spacing is determined by multiplying @c multiplier to the default line spacing and adding @c extra.
290          * @code
291          * The line spacing = (default line spacing) * multiplier + extra
292          * @endcode
293          * @since          2.0
294          * @return         An error code
295          * @param[in]      multiplier                    The line spacing multiplier
296          * @param[in]      extra                         The extra line spacing
297          * @exception      E_SUCCESS                     The method was successful.
298          * @exception      E_INVALID_ARG                 A specified parameter is invalid. @n
299          *                                               -- The specified line spacing value cannot be supported.
300          * @exception      E_SYSTEM                      A system error occurred.
301          * @see            GetLineSpacing()
302          */
303         result SetLineSpacing(int multiplier, int extra);
304
305         // Text Alignment
306         /**
307          * Gets the horizontal text alignment.
308          *
309          * @since               2.0
310          * @return              The horizontal text alignment
311          * @exception   E_SUCCESS               The method was successful.
312          * @exception   E_SYSTEM                A system error occurred.
313          * @remarks             The specific error code can be accessed using the GetLastResult() method.
314          * @see                 SetTextAlignment()
315          */
316         HorizontalAlignment GetTextAlignment(void) const;
317
318         /**
319          * Sets the horizontal text alignment.
320          *
321          * @since               2.0
322          * @return              An error code
323          * @param[in]   alignment               The horizontal text alignment
324          * @exception   E_SUCCESS               The method was successful.
325          * @exception   E_SYSTEM                A system error occurred.
326          * @see                 GetTextAlignment()
327          */
328         result SetTextAlignment(HorizontalAlignment alignment);
329
330 // Text Size
331         /**
332          * Gets the text size of the TextBox control.
333          *
334          * @since               2.0
335          * @return      The size of the text, @n
336          *              else @c -1 if an error occurs
337          * @exception   E_SUCCESS          The method was successful.
338          * @exception   E_SYSTEM           A system error occurred.
339          * @remarks             The specific error code can be accessed using the GetLastResult() method.
340          * @see                 SetTextSize()
341          */
342         int GetTextSize(void) const;
343
344         /**
345          * Gets the text total height of the TextBox control.
346          *
347          * @since               2.0
348          * @return      The total height of the text, @n
349          *              else @c -1 if an error occurs
350          * @exception   E_SUCCESS          The method was successful.
351          * @exception   E_SYSTEM           A system error occurred.
352          * @remarks             The specific error code can be accessed using the GetLastResult() method.
353          */
354         int GetTextTotalHeight(void) const;
355
356         /**
357          * Sets the text size.
358          *
359          * @since               2.0
360          * @return              An error code
361          * @param[in]   size                The text size
362          * @exception   E_SUCCESS           The method was successful.
363          * @exception   E_INVALID_ARG       A specified input parameter is invalid.@n
364          *                                                                      -- The specified @c size cannot be negative integer.
365          * @exception   E_SYSTEM            A system error occurred.
366          * @see                 GetTextSize()
367          */
368         result SetTextSize(int size);
369
370 // Text Font
371         /**
372          * Gets the font typeface name and the style mask of the TextBox control.
373          *
374          * @since               2.0
375          * @return              An error code
376          * @param[out]  typefaceName     The name of the font typeface
377          * @param[out]  style            The text style (see TextBoxTextStyle)
378          * @exception   E_SUCCESS        The method was successful.
379          * @exception   E_SYSTEM         A system error occurred.
380          * @remarks     Multiple styles can be combined using the bitwise OR operator.
381          * @see                 SetFontType()
382          * @see                 Tizen::Graphics::Font::GetSystemFontListN()
383          * @see                 TextBoxTextStyle
384          */
385         result GetFontType(Tizen::Base::String& typefaceName, unsigned long& style) const;
386
387         unsigned long GetTextStyle(void) const;
388
389         /**
390          * Sets the font and the style mask of the TextBox control.
391          *
392          * @since               2.0
393          * @return              An error code
394          * @param[in]   typefaceName     The name of the font typeface
395          * @param[in]   style            The text style @n
396          *                                                               Multiple styles can be combined using the bitwise OR operator(see TextBoxTextStyle).
397          * @exception   E_SUCCESS        The method was successful.
398          * @exception   E_INVALID_ARG    A specified input parameter is invalid, or the specified font typeface is not supported.
399          * @exception   E_SYSTEM         A system error occurred.
400          * @remarks         The specified font typeface must be one of the system fonts. @n
401          *              @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 be applied.
402          * @see                 GetFontType()
403          * @see                 Tizen::Graphics::Font::GetSystemFontListN()
404          * @see                 TextBoxTextStyle
405          */
406         result SetFontType(const Tizen::Base::String& typefaceName, unsigned long style);
407
408         result SetTextStyle(unsigned long style);
409
410         /**
411          * Sets the font to render the text.
412          *
413          * @since               2.0
414          * @return              An error code
415          * @param[in]   font             The text font
416          * @exception   E_SUCCESS        The method was successful.
417          * @exception   E_SYSTEM         A system error occurred.
418          * @remarks             All previously set text attributes (style, weight, decoration, and size) will be discarded.
419          */
420         result SetFont(const Tizen::Graphics::Font& font);
421
422 // Text Block
423         /**
424          * Releases the selection of the current text block.
425          *
426          * @since               2.0
427          * @return              An error code
428          * @exception   E_SUCCESS          The method was successful.
429          * @exception   E_SYSTEM           A system error occurred.
430          * @see                 GetBlockRange()
431          * @see                 SetBlockRange()
432          */
433         result ReleaseBlock(void);
434
435         /**
436          * Gets the start and the end index of the currently selected text block.
437          *
438          * @since               2.0
439          * @return              An error code
440          * @param[out]  start              The start index of the text block
441          * @param[out]  end                The end index of the text block
442          * @exception   E_SUCCESS          The method was successful.
443          * @exception   E_SYSTEM           A system error occurred.
444          * @remarks             The method returns @c start = 0 and @c end = 0 if there is no selected text block.
445          * @see                 ReleaseBlock()
446          * @see                 SetBlockRange()
447          */
448         result GetBlockRange(int& start, int& end) const;
449
450         /**
451          * Sets the specified block of the text.
452          *
453          * @since               2.0
454          * @return              An error code
455          * @param[in]   start           The start index of the text block
456          * @param[in]   end             The end index of the text block
457          * @exception   E_SUCCESS       The method was successful.
458          * @exception   E_OUT_OF_RANGE  The specified index is outside the bounds of the data structure, or either the @c start or @c end parameters are greater than the number of elements or less than zero.
459          * @exception   E_SYSTEM        A system error occurred.
460          * @see                 ReleaseBlock()
461          * @see                 GetBlockRange()
462          */
463         result SetBlockRange(int start, int end);
464
465 // Appearances
466         /**
467          * Gets the color of the TextBox control for the specified status.
468          *
469          * @since               2.0
470          * @return              The color of the TextBox control, @n
471          *                              else RGBA (0,0,0,0) if an error occurs
472          * @exception   E_SUCCESS           The method was successful.
473          * @remarks             The specific error code can be accessed using the GetLastResult() method.
474          * @see                 SetColor()
475          */
476         Tizen::Graphics::Color GetColor(TextBoxStatus status) const;
477
478         /**
479          * Gets the text color of the specified text color type.
480          *
481          * @since               2.0
482          * @return              The color, @n
483          *                              else RGBA (0,0,0,0) if an error occurs
484          * @param[in]   type                    The text color type
485          * @exception   E_SUCCESS               The method was successful.
486          * @exception   E_SYSTEM                A system error occurred.
487          * @remarks             The specific error code can be accessed using the GetLastResult() method.
488          * @see                 SetTextColor()
489          */
490         Tizen::Graphics::Color GetTextColor(TextBoxTextColor type) const;
491
492         /**
493          * Sets the background bitmap of the TextBox control.
494          *
495          * @since               2.0
496          * @return              An error code
497          * @param[in]   status          The state of the TextBox control
498          * @param[in]   bitmap          The background bitmap
499          * @exception   E_SUCCESS   The method was successful.
500          * @exception   E_SYSTEM    A system error occurred.
501          * @see                 SetBackgroundColor()
502          */
503         result SetBackgroundBitmap(TextBoxStatus status, const Tizen::Graphics::Bitmap& bitmap);
504
505         /**
506          * Sets the color of the TextBox control for the specified status.
507          *
508          * @since               2.0
509          * @return              An error code
510          * @param[in]   status          The state of the TextBox control
511          * @param[in]   color           The color to set
512          * @exception   E_SUCCESS       The method was successful.
513          * @exception   E_SYSTEM        A system error occurred.
514          * @see                 GetColor()
515          */
516         result SetColor(TextBoxStatus status, const Tizen::Graphics::Color& color);
517
518         /**
519          * Sets the text color of the TextBox control for the specified text type.
520          *
521          * @since               2.0
522          * @return              An error code
523          * @param[in]   type             The text color type
524          * @param[in]   color            The text color to set
525          * @exception   E_SUCCESS        The method was successful.
526          * @exception   E_SYSTEM         A system error occurred.
527          * @see                 GetTextColor()
528          */
529         result SetTextColor(TextBoxTextColor type, const Tizen::Graphics::Color& color);
530
531         /**
532          * Adds a text block event listener.
533          *
534          * @since               2.0
535          * @param[in]   listener        The event listener to add
536          * @remarks             Programmatically modifying the text selection does not cause the text block selection event to fire.
537          * @see                 RemoveTextBlockEventListener()
538          */
539         result AddTextBlockEventListener(Tizen::Ui::ITextBlockEventListener& listener);
540
541         /**
542          * Removes the specified text block event listener. @n
543          * The removed listener cannot listen to events when they are fired.
544          *
545          * @since               2.0
546          * @param[in]   listener        The event listener to remove
547          * @see                 AddTextBlockEventListener()
548          */
549         result RemoveTextBlockEventListener(Tizen::Ui::ITextBlockEventListener& listener);
550
551         virtual Tizen::Graphics::Dimension GetContentSize(void) const;
552
553 // Operation
554 public:
555         // callback
556         virtual result OnBoundsChanged(const Tizen::Graphics::Rectangle& oldRect, const Tizen::Graphics::Rectangle& newRect);
557         virtual void OnLinkClicked(Tizen::Ui::_Control& source, const Tizen::Base::String& text, Tizen::Base::Utility::LinkType linkType, const Tizen::Base::String& link);
558         virtual void OnTextBlockSelected(Tizen::Ui::_Control& source, int start, int end);
559
560 public:
561         static _TextBoxImpl* GetInstance(TextBox& textBox);
562         static const _TextBoxImpl* GetInstance(const TextBox& textBox);
563
564 protected:
565
566         //
567         // This is internal. If used in an application, the application can get rejected during the certification process.
568         // Frees the resources allocated by this control and destroys its native window if it is present).
569         //
570         virtual result Dispose(void);
571
572         //
573         // This is internal. Converts text color type between the Edit control and the TextBox control.
574         //
575         EditTextColor ConvertTextColorType(TextBoxTextColor color) const;
576
577         //
578         // This is internal. Converts text color type between the Edit control and the TextBox control.
579         //
580         EditStatus ConvertStatus(TextBoxStatus status) const;
581
582 private:
583         _TextBoxImpl(const _TextBoxImpl&);
584         _TextBoxImpl& operator =(const _TextBoxImpl&);
585
586 private:
587         _Edit* __pEdit;
588         _PublicTextBlockEvent* __pPublicTextBlockEvent;
589         _PublicLinkEvent* __pPublicLinkEvent;
590         unsigned long __autoLinkMask;
591
592 }; // _TextBoxImpl
593
594 }}} // Tizen::Ui::Controls
595
596 #endif  // _FUI_CTRL_INTERNAL_TEXT_BOX_IMPL_H_