Merge "(TextInput) Emits text modified signal when cut or paste performed" into tizen
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-view / text-view-word-group-processor.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_WORD_GROUP_PROCESSOR_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_WORD_GROUP_PROCESSOR_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-view/text-view-impl.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal
31 {
32
33 namespace TextViewProcessor
34 {
35
36 /**
37  * Updates the word group layout size info.
38  *
39  * @param[in,out] wordGroupLayoutInfo The word group layout info.
40  */
41 void UpdateGroupLayoutInfo( TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo );
42
43 /**
44  * Creates a data structure with info to layout the group of words, and data structures with useful info to modify the layout data structure if characters are added or removed.
45  *
46  * @param[in] wordGroup The styled group of words.
47  * @param[in,out] textLayoutInfo Layout info for the whole text. This function uses it to check if the words should be split into individual characters. It also modifies which is the maximum word width.
48  * @param[out] wordGroupLayoutInfo Layout info for the whole group of words.
49  */
50 void CreateWordGroupInfo( const MarkupProcessor::StyledTextArray& wordGroup,
51                           TextViewProcessor::TextLayoutInfo& textLayoutInfo,
52                           TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo );
53
54 /**
55  * Removes a given number of words from the given group of words.
56  *
57  * @pre \e wordIndex and \e wordIndex + \e numberOfWords can't exceed the bounds of the group.
58  *
59  * @param[in] wordIndex Index to the word within the group of words with the starting position to be deleted.
60  * @param[in] numberOfWords The number of words to be deleted.
61  * @param[in,out] wordGroupLayoutInfo The input is the layout info of the group of words. The output is the layout info of the group of words without the removed words.
62  */
63 void RemoveWordsFromWordGroup( std::size_t wordIndex,
64                                std::size_t numberOfWords,
65                                WordGroupLayoutInfo& wordGroupLayoutInfo );
66
67 /**
68  * @param[in,out] relayoutData Natural size (metrics), layout, text-actor info.
69  * @param[in] numberOfCharacters The number of characters to be deleted.
70  * @param[out] mergeWords Whether words need to be merged after removing characters.
71  * @param[out] mergeLines Whether current line need to be merged with the next one.
72  * @param[in,out] textInfoIndicesBegin Indices to the line, word and characters from where to delete characters. It returns from where words need to be removed.
73  * @param[out] textInfoIndicesEnd If lines or words need to be merged it returns info to delete them (If a word is merged, it has to be removed. Equal for lines).
74  * @param[out] textInfoMergeIndicesBegin The indices to the first part of the line, group and word to be merged.
75  * @param[out] textInfoMergeIndicesEnd The indices to the last part of the line, group and word to be merged.
76  * @param[in,out] groupLayout Layout info of the group of words where the word is located.
77  * @param[out] removedTextActorsFromFirstWord Stores removed text-actors of the word pointed by the 'begin' index.
78  * @param[out] removedTextActorsFromLastWord Stores removed text-actors of the word pointed by the 'end' index.
79  */
80 void RemoveCharactersFromWordGroupInfo( TextView::RelayoutData& relayoutData,
81                                         std::size_t numberOfCharacters,
82                                         bool& mergeWords,
83                                         bool& mergeLines,
84                                         TextViewProcessor::TextInfoIndices& textInfoIndicesBegin,
85                                         TextViewProcessor::TextInfoIndices& textInfoIndicesEnd,
86                                         TextViewProcessor::TextInfoIndices& textInfoMergeIndicesBegin,
87                                         TextViewProcessor::TextInfoIndices& textInfoMergeIndicesEnd,
88                                         TextViewProcessor::WordGroupLayoutInfo& groupLayout,
89                                         std::vector<TextActor>& removedTextActorsFromFirstWord,
90                                         std::vector<TextActor>& removedTextActorsFromLastWord );
91
92 /**
93  * Splits a group of words in two.
94  *
95  * @note It deletes whatever there is in the last part of the group of words.
96  *
97  * @param[in] indices Index to the word within the group of words and index to the character within the word where to split the word.
98  * @param[in,out] firstWordGroupLayoutInfo The input is the layout info of the given group of words. The output is the first part of the input group of words (from the word \e 0 to the word \e wordPosition).
99  * @param[in,out] lastWordGroupLayoutInfo Layout info of the last part of the given group of words ( from the word \e wordPosition + \e 1 to the end of the group of words).
100  */
101 void SplitWordGroup( const TextInfoIndices& indices,
102                      WordGroupLayoutInfo& firstWordGroupLayoutInfo,
103                      WordGroupLayoutInfo& lastWordGroupLayoutInfo );
104
105 /**
106  * Merges the two given groups of words by adding words of the last group of words to the firs one.
107  *
108  * @note Does nothing if last part of the group of words is empty.
109  * @note If the first part of the group of words is empty it just copy the last part to it.
110  * @note It assets if groups of words contain text with different direction. (Left to Right and Right to Left text)
111  * @note it asserts if the last word of the first group is a line separator (new line character)
112  *
113  * @param[in,out] firstWordGroupLayoutInfo The input is the layout info of the first group of words. The output is the layout info of the merged group of words.
114  * @param[in] lastWordGroupLayoutInfo Layout info of the last group of words.
115  *
116  */
117 void MergeWordGroup( WordGroupLayoutInfo& firstWordGroupLayoutInfo,
118                      const WordGroupLayoutInfo& lastWordGroupLayoutInfo );
119
120 /**
121  * Collects text-actors from the given line, within the given indices, and stores them into the text-actor vector.
122  *
123  * @param[out] textActors Stores the text-actors of the given line.
124  * @param[in] line The line with groups of words.
125  * @param[in] groupIndexBegin Index to the first group of words.
126  * @param[in] groupIndexEnd Index to the last group of words.
127  */
128 void CollectTextActorsFromGroups( std::vector<TextActor>& textActors, const LineLayoutInfo& line, std::size_t groupIndexBegin, std::size_t groupIndexEnd );
129
130 } //namespace TextViewProcessor
131
132 } //namespace Internal
133
134 } //namespace Toolkit
135
136 } //namespace Dali
137
138 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_WORD_GROUP_PROCESSOR_H__