Remove alignment from text controller.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / cursor-helper-functions.h
1 #ifndef __DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H__
2 #define __DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H__
3
4 /*
5  * Copyright (c) 2016 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/text/logical-model-impl.h>
23 #include <dali-toolkit/internal/text/metrics.h>
24 #include <dali-toolkit/internal/text/visual-model-impl.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Text
33 {
34
35 struct CursorInfo
36 {
37   CursorInfo()
38   : primaryPosition(),
39     secondaryPosition(),
40     lineOffset( 0.f ),
41     lineHeight( 0.f ),
42     primaryCursorHeight( 0.f ),
43     secondaryCursorHeight( 0.f ),
44     isSecondaryCursor( false )
45   {}
46
47   ~CursorInfo()
48   {}
49
50   Vector2 primaryPosition;       ///< The primary cursor's position (in text's coords).
51   Vector2 secondaryPosition;     ///< The secondary cursor's position (in text's coords).
52   float   lineOffset;            ///< The vertical offset where the line containing the cursor starts.
53   float   lineHeight;            ///< The height of the line where the cursor is placed.
54   float   primaryCursorHeight;   ///< The primary cursor's height.
55   float   secondaryCursorHeight; ///< The secondary cursor's height.
56   bool    isSecondaryCursor;     ///< Whether the secondary cursor is valid.
57 };
58
59 /**
60  * @brief Retrieves the closest line for a given touch point.
61  *
62  * It returns the first line if the touch point is above the text and the last line if the touch point is below.
63  *
64  * @param[in] visualModel The visual model.
65  * @param[in] visualY The touch point 'y' in text's coords.
66  *
67  * @return A line index.
68  */
69 LineIndex GetClosestLine( VisualModelPtr visualModel,
70                           float visualY );
71
72 /**
73  * @brief Retrieves the cursor's logical position for a given touch point x,y
74  *
75  * @param[in] visualModel The visual model.
76  * @param[in] logicalModel The logical model.
77  * @param[in] metrics A wrapper around FontClient used to get metrics.
78  * @param[in] visualX The touch point 'x' in text's coords.
79  * @param[in] visualY The touch point 'y' in text's coords.
80  *
81  * @return The logical cursor position (in characters). 0 is just before the first character, a value equal to the number of characters is just after the last character.
82  */
83 CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel,
84                                       LogicalModelPtr logicalModel,
85                                       MetricsPtr metrics,
86                                       float visualX,
87                                       float visualY );
88
89
90 /**
91  * @brief Calculates the cursor's position for a given character index in the logical order.
92  *
93  * It retrieves as well the line's height and the cursor's height and
94  * if there is a valid alternative cursor, its position and height.
95  *
96  * @param[in] visualModel The visual model.
97  * @param[in] logicalModel The logical model.
98  * @param[in] metrics A wrapper around FontClient used to get metrics.
99  * @param[in] logical The logical cursor position (in characters). 0 is just before the first character, a value equal to the number of characters is just after the last character.
100  * @param[out] cursorInfo The line's height, the cursor's height, the cursor's position and whether there is an alternative cursor.
101  */
102 void GetCursorPosition( VisualModelPtr visualModel,
103                         LogicalModelPtr logicalModel,
104                         MetricsPtr metrics,
105                         CharacterIndex logical,
106                         CursorInfo& cursorInfo );
107
108 /**
109  * @brief Find the indices to the first and last characters of a word for the given touch point.
110  *
111  * @param[in] visualModel The visual model.
112  * @param[in] logicalModel The logical model.
113  * @param[in] metrics A wrapper around FontClient used to get metrics.
114  * @param[in] visualX The touch point 'x' in text's coords.
115  * @param[in] visualY The touch point 'y' in text's coords.
116  * @param[out] startIndex Index to the first character of the selected word.
117  * @param[out] endIndex Index to the last character of the selected word.
118  */
119 void FindSelectionIndices( VisualModelPtr visualModel,
120                            LogicalModelPtr logicalModel,
121                            MetricsPtr metrics,
122                            float visualX,
123                            float visualY,
124                            CharacterIndex& startIndex,
125                            CharacterIndex& endIndex );
126
127 } // namespace Text
128
129 } // namespace Toolkit
130
131 } // namespace Dali
132
133 #endif // __DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H__