TextInput Decorator class and stubbed decoration classes
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-input / textview-character-positions-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_TEXTVIEW_CHARACTER_POSITIONS_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_TEXTVIEW_CHARACTER_POSITIONS_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 ///
19
20 // INTERNAL INCLUDES
21 #include <dali-toolkit/internal/controls/text-input/text-input-text-style-impl.h>
22
23 // EXTERNAL INCLUDES
24 #include <dali/dali.h>
25 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 class TextInputTextStyle;
37
38 /**
39  * Class which contains functions related to the TextView.
40  * Functions which are needed by various parts of the TextInput to determine the position of characters.
41  * Functions to Set the TextView so text justification, alignment and wrapping behaviour in the desired manner for text input.
42  * The functionality of this class may be divided in future.
43  */
44 class TextViewCharacterPositioning
45 {
46
47 public:
48
49   /**
50    * @brief Constructor
51    *
52    * @param[in] displayedTextView TextView to be used with this class.
53    * @param[in] textStyle TextInputTextStyle to be used
54    */
55   TextViewCharacterPositioning( Toolkit::TextView displayedTextView, TextInputTextStyle& textStyle ):mTextStyle( textStyle ){};
56
57   /**
58    * Destructor
59    */
60   ~TextViewCharacterPositioning(){};
61
62   /**
63    * @brief Creates the TextView to be used within this class.
64    */
65   void CreateTextView(){};
66
67   /*
68    * @brief Get a handle to the current text view object
69    * If one does not exist then it's create.
70    * @return TextView
71    */
72   Toolkit::TextView GetTextView() const{return Toolkit::TextView();};
73
74   /**
75    * @brief Get the TextLayoutInfo from the TextView so know the updated positions of characters.
76    */
77   void UpdateTextLayoutInfo(){};
78
79
80   /**
81    *  @brief Get the TextLayoutInfo structure for the TextView
82    *  @return the TextLayoutInfo structure
83    */
84   const Toolkit::TextView::TextLayoutInfo& GetLayoutInfo() const{return mTextLayoutInfo;};
85
86
87   /**
88    * @brief Get the number of characters visually represented in the text
89    * @return the number of characters
90    */
91   std::size_t GetNumberOfCharactersInText() const{return 0;};
92
93   /**
94    * @brief Check if any text exists in TextView's character layout table
95    * @return bool true if empty
96    */
97   bool IsTextEmpty() const{return false;};
98
99   /**
100    * @brief Get the height of the line at the given cursor position
101    * @param[in] position
102    * @return float the height of the line
103    */
104   float GetLineHeight( std::size_t position ) const{return 0.0f;};
105
106   /**
107    * @brief Sets if the inputed text can exceed the text-input boundary.
108    * By default is enabled.
109    * @param[in] enable Whether the inputed text can exceed its boundary.
110    */
111   void SetTextExceedEnabled( bool enable ) {};
112
113   /**
114    * @brief Retrieves whether inputed text can exceed the text-input boundary.
115    * @return \e true if text inputed can exceed the boundary, otherwise \e false.
116    */
117   bool IsTextExceedEnabled() const{ return false;};
118
119   /**
120    * @brief From the given x and y vector the closest character position is returned
121    * @param[in] source the x and y position
122    * @return the position in the string of the character closest to the source.
123    */
124   std::size_t ReturnClosestIndex( const Vector2& source ){return 0;};
125
126   /**
127    * @brief If no text exists then this function uses the text alignment to position cursor.
128    * @param[in] cursorPosition
129    */
130   void GetActualPositionFromCharacterPositionWhenNoText( Vector3& cursorPosition ) const{};
131
132   /**
133    * @brief Function to position cursor when a word is wrapped to another line
134    * @param[in] characterPosition that actual position is required for
135    * @return the actual position of the cursor.
136    */
137   Vector3 PositionCursorAfterWordWrap( std::size_t characterPosition ) const{return Vector3::ZERO;};
138
139   /**
140    * @brief Returns the x-position of the current line justification
141    * (relative to left of text-view container)
142    * @return x position for line justification
143    */
144   float GetLineJustificationPosition() const{return 0.0f;};
145
146   /**
147    * @brief Retrieve the dimensions (and min-max) of this row of text that the character resides on.
148    * @param[in] characterPosition the position in the 'string' of characters.
149    * @param[out] min the top-left position of the rectangle representing this row
150    * @param[out] max the bottom-right position of the rectangle representing this row
151    * @return The size of the rectangle representing this row (max - min)
152    */
153   Size GetRowRectFromCharacterPosition(std::size_t characterPosition, Vector2& min, Vector2& max) const{return Vector2::ZERO;};
154
155   /**
156    * @brief Retrieve the character position of the first character on the row of text
157    * that this character resides on.
158    * @param[in] logicalPosition the position in the 'string' of characters.
159    * @return logical character position of start of row.
160    */
161   std::size_t GetRowStartFromCharacterPosition(std::size_t logicalPosition) const{return 0;};
162
163   /**
164    * @brief Gets the visual position of a logical position.
165    * @note This is preferred over directly accessing the Map, as it resolves visual
166    * positions outside of the character map range.
167    * @param[in] logicalPosition The logical position
168    * @return Visual position is returned.
169    */
170   std::size_t GetVisualPosition(std::size_t logicalPosition) const{return 0;};
171
172   /**
173    * @brief Return a vector which is the actual position for the given character position
174    * The character position is where a cursor would be position for that character.
175    * @param[in] characterPosition the logical (input) position in the 'string' of characters.
176    *
177    * @return Vector3 the actual x,y,z position
178    */
179   Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition ) const{return Vector3::ZERO;};
180
181   /**
182    * @brief Return a vector which is the actual position for the given character position
183    * The character position is where a cursor would be positioned for that character to be inserted.
184    * An additional alternatePosition is also set in circumstances where the possible writing
185    * of characters would be in the opposite direction.
186    * e.g. "HelloشقشلاهؤEnglish"
187    *            |     |
188    *            *     +
189    * [*] - Primary actual position for cursor i.e. continuing writing LTR (English)
190    * [+] - Alternate actual position for cursor i.e. writing RTL (Arabic)
191    *
192    * @param[in] characterPosition the logical (input) position in the 'string' of characters.
193    * @param[out] directionRTL Whether the actual x,y,z position is after LTR (false) or RTL (true) text.
194    * @param[out] alternatePosition the actual x,y,z position of the cursor if user types
195    * in alternate direction to current flow of text.
196    * @param[out] alternatePositionValid whether this alternate position is valid.
197    * @return Vector3 the actual x,y,z position
198    */
199   Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition, bool& directionRTL, Vector3& alternatePosition, bool& alternatePositionValid ) const{return Vector3::ZERO;};
200
201   /**
202    * @brief Get the currently displayed text.
203    * @return The currently displayed text.
204    */
205   std::string GetText() const{return std::string();};
206
207   /**
208    * @brief Get the text currently being displayed together with mark-up tags.
209    * @return string, the currently displayed string with mark-up.
210    */
211   std::string GetMarkupText() const{return std::string();};
212
213   /**
214    * @brief Sets whether markup processing should be carried out.
215    *
216    * @param[in] enable whether markup processing is carried out or not.
217    */
218   void SetMarkupProcessingEnabled( bool enable ){};
219
220   /**
221    * @brief Returns whether markup processing is enabled or not
222    *
223    * @return true is markup processing is enabled
224    */
225   bool IsMarkupProcessingEnabled() const{ return false;};
226
227   // Styled Text
228
229   /**
230    * @brief Check if styled text is empty
231    * @return bool returns true if styled text is empty
232    */
233   bool IsStyledTextEmpty() const{ return false;};
234
235   /**
236    * @brief The size of the style text
237    * @return std::size_t returns number of characters in styled text
238    */
239   std::size_t StyledTextSize() const{return 0;};
240
241   /**
242    * @brief Get the styled text array
243    * @return reference to MarkupProcessor::StyledTextArray
244    */
245   MarkupProcessor::StyledTextArray& GetStyledTextArray(){return mStyledText;};
246
247   /**
248    * @brief Get the style for the character at the given position
249    * @param[in] position of character style is required for
250    * @return a copy of the style structure for the character at the given position
251    */
252   TextStyle GetStyleAt( std::size_t position ) const{return TextStyle();};
253
254 /**
255    * @briefApplies the given style to all text, selected or not selected.
256    * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
257    * @param[in] style style to apply
258    * @param[in] mask mask style should be applied to
259    * @param[in] begin start position of range to apply style
260    * @param[in] end end position of range to apply style
261    */
262   void ApplyStyleToRange( const TextStyle& style, const TextStyle::Mask mask, const std::size_t begin, const std::size_t end ){};
263
264   // Snapshot
265   /**
266    * @copydoc TextView::SetSnapshotModeEnabled()
267    */
268   void SetSnapshotModeEnabled( bool enable ){};
269
270   /**
271    * @copydoc TextView::IsSnapshotModeEnabled()
272    */
273   bool IsSnapshotModeEnabled() const{ return false;};
274
275   // Scrolling
276   /**
277    * @copydoc TextView::SetScrollEnabled()
278    */
279   void SetScrollEnabled( bool enable ){};
280
281   /**
282    * @copydoc TextView::SetScrollPosition()
283    */
284   void SetScrollPosition( const Vector2& position ){};
285
286   /**
287    * @copydoc TextView::IsScrollEnabled()
288    */
289   bool IsScrollEnabled() const{ return false;};
290
291   /**
292    * @copydoc TextView::GetScrollPosition()
293    */
294   Vector2 GetScrollPosition() const{return Vector2::ZERO;};
295
296   /**
297    * @copydoc TextView::GetScrollPosition()
298    */
299   bool IsScrollPositionTrimmed() const{ return false;};
300
301 private:
302
303   /**
304    * @brief Copy Constructor
305    * @param[in] characterPositioning
306    * Undefined.
307    */
308   TextViewCharacterPositioning(const TextViewCharacterPositioning& characterPositioning );
309
310   /**
311    * @Assignment Constructor
312    * @param[in] rhs
313    * Undefined.
314    */
315   TextViewCharacterPositioning& operator=(const TextViewCharacterPositioning& rhs);
316
317 private:
318
319   Toolkit::TextView mDisplayedTextView;         // A text view object used to display the text.
320   TextInputTextStyle& mTextStyle;               // Holds the style object related to input style
321
322   MarkupProcessor::StyledTextArray mStyledText; // String currently displayed by TextView with style info.
323
324   Toolkit::TextView::TextLayoutInfo      mTextLayoutInfo; // It contains a table layout info per character sorted by the character's visual index (retrieved from TextView),
325                                                           // a reorder map that stores each character's visual (output) index according to its logical (input) index,
326                                                           // a reorder map that stores each character's logical (input) index according to its visual (output) index
327
328   bool mExceedEnabled:1; // flag set by user to determine if text can exceed the control's size
329   bool mMarkUpEnabled:1; // If Markup is being passed with the text
330 };
331
332
333 } // namespace Internal
334
335
336 } // namespace Toolkit
337
338 } // namespace Dali
339
340 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_TEXTVIEW_CHARACTER_POSITIONS_H__