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