(toolkit) fix klocwork issues
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-input / text-input-text-highlight-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_HIGHLIGHT_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_HIGHLIGHT_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/geometry/mesh.h>
23 #include <dali/public-api/modeling/material.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/controls/text-input/textview-character-positions-impl.h>
27 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * @brief TextHighlight is a decoration which highlights selected text.
40  *
41  * The class creates a highlight mesh used to show selected text between handles.
42  * Not responsible for positioning.
43  */
44 class TextHighlight
45 {
46   /**
47    * structure to hold coordinates of each quad, which will make up the mesh.
48    */
49   struct QuadCoordinates
50   {
51     /**
52      * Default constructor
53      */
54     QuadCoordinates()
55     {
56     }
57
58     /**
59      * Constructor
60      * @param[in] x1 left co-ordinate
61      * @param[in] y1 top co-ordinate
62      * @param[in] x2 right co-ordinate
63      * @param[in] y2 bottom co-ordinate
64      */
65     QuadCoordinates(float x1, float y1, float x2, float y2)
66     : min(x1, y1),
67       max(x2, y2)
68     {
69     }
70
71     Vector2 min;                          ///< top-left (minimum) position of quad
72     Vector2 max;                          ///< bottom-right (maximum) position of quad
73   };
74
75   typedef std::vector<QuadCoordinates> QuadContainer;
76
77 public:
78
79   /**
80    * structure for information required to build the highlight mesh
81    */
82   struct HighlightInfo
83   {
84     /**
85      * Adds a Quad (2D rectangular sub-selection)
86      * @param[in] x1 left co-ordinate
87      * @param[in] y1 top co-ordinate
88      * @param[in] x2 right co-ordinate
89      * @param[in] y2 bottom co-ordinate
90      */
91     void AddQuad( float x1, float y1, float x2, float y2 );
92
93     /**
94      * Clamps all quads to fit within a min -> max 2D boundary.
95      */
96     void Clamp2D(const Vector2& min, const Vector2& max);
97
98     QuadContainer mQuadList;                                 ///< List of quads (sub-selections that form to create complete selection)
99   };
100
101   /**
102    * Constructor
103    * @param[in] textViewCharacterPositioning TextViewCharacterPositioning to be used for positioning information.
104    */
105   TextHighlight( TextViewCharacterPositioning& textViewCharacterPositioning );
106
107   /**
108    * Destructor
109    */
110   ~TextHighlight();
111
112   /**
113    * Gets the table of the visual text positions which has a flag
114    * for each Character. The flag is either true (character selected)
115    * or false (character de-selected)
116    * @note startSelection can be greater or less than endSelection
117    *
118    * @param[in,out] selectedVisualText The vector to be resized and populated with the selected flags
119    * @param[in] startSelection The start selection point for the text
120    * @param[in] endSelection The end selection point for the text
121    * @param[in] endSelection The end selection point for the text
122    * @param[in] textLayoutInfo TextView character layout information
123    */
124   void GetVisualTextSelection(std::vector<bool>& selectedVisualText, std::size_t startSelection, std::size_t endSelection,
125                               Toolkit::TextView::TextLayoutInfo& textLayoutInfo);
126
127   /**
128    * Iterates between selection handles and computes the info required to build the highlight mesh
129    * @param[in] handlePositionStart starting handle position
130    * @param[in] handlePositionEnd ending handle position
131    * @return textHighlight target TextHighlight
132    */
133   TextHighlight::HighlightInfo CalculateHighlightInfo( std::size_t handlePositionStart, std::size_t handlePositionEnd, Toolkit::TextView::TextLayoutInfo& textLayoutInfo );
134
135   /**
136    * Calculates new Mesh data so highlight moves with selection handles.
137    * @param[in] newHighlightInfo HighlightInfo calculated by CalculateHighlightInfo
138    */
139   void UpdateHighlight( TextHighlight::HighlightInfo& newHighlightInfo );
140
141   /**
142    * Creates the Mesh data needed by the Mesh Actor
143    */
144   Mesh CreateHighLightMesh();
145
146 private:
147
148   /**
149    * @brief Copy Constructor
150    * @param[in] textHight
151    * Undefined/Hidden.
152    */
153   TextHighlight(const TextHighlight& textHight );
154
155   /**
156    * @Assignment Constructor
157    * @param[in] rhs
158    * Undefined/Hidden.
159    */
160   TextHighlight& operator=(const TextHighlight& rhs);
161
162 private:
163
164   TextViewCharacterPositioning& mTextViewCharacterPositioning;
165
166   Mesh              mHighlightMesh;             ///< Mesh Data for highlight
167   MeshData          mMeshData;                  ///< Container to hold meshData for highlight
168   Material          mCustomMaterial;            ///< Custom material used for highlight
169   HighlightInfo     mNewHighlightInfo;          ///< Geometry info to create highlight.
170
171 };
172
173
174 } // namespace Internal
175
176
177 } // namespace Toolkit
178
179 } // namespace Dali
180
181 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_HIGHLIGHT_H__