(TextInput) Cursor is not moved to start of word when selecting text.
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-input / text-input-handles-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_HANDLES_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_HANDLES_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/dali.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal
31 {
32 /**
33  * Class to create handles and alter their visualisation.
34  * Not responsible for positioning.
35  */
36
37 class TextInputHandles : public ConnectionTracker
38 {
39
40 public:
41
42   /**
43    * Default constructor
44    */
45   TextInputHandles();
46
47   /**
48    * Destructor
49    */
50   ~TextInputHandles();
51
52   /**
53    * Create the selection handles
54    */
55   void CreateSelectionHandles();
56
57   /**
58    * Un-parents the Selection Handles and resets their Image Actors
59    */
60   void DestorySelectionHandles();
61
62   /**
63    * Set the Actor visibility on Selection Handle One
64    * @param[in] visibility visibility flag
65    */
66   void SetSelectionHandleOneVisibility( bool visibility );
67
68   /**
69    * Set the Actor visibility on Selection Handle Two
70    * @param[in] visibility visibility flag
71    */
72   void SetSelectionHandleTwoVisibility( bool visibility );
73
74   /**
75    * Attach the two selection handles to the pan gesture detector
76    * @param[in] panGestureDetector the PanGestureDetector to attach to
77    */
78   void AttachSelectionHandlesToGivenPanGesture(PanGestureDetector& panGestureDetector );
79
80   /**
81    * Attach the two selection handles to the tap gesture detector
82    * @param[in] tapGestureDetector the TapGestureDetector to attach to
83    */
84   void AttachSelectionHandlesToGivenTapDetector(TapGestureDetector& tapGestureDetector );
85
86   /**
87    * Attach the grab handle to the pan gesture detector
88    * @param[in] panGestureDetector the PanGestureDetector to attach to
89    */
90   void AttachGrabHandleToGivenPanGesture( PanGestureDetector& panGestureDetector );
91
92   /**
93    * Get Selection handle one
94    * @return selection handle actor
95    */
96   Actor GetSelectionHandleOne();
97
98   /**
99    * Get Selection handle two
100    * @return selection handle actor
101    */
102   Actor GetSelectionHandleTwo();
103
104   /**
105    * Get the grab handle
106    * @return grab handle Actor
107    */
108   Actor GetGrabHandle();
109
110   /**
111    * Create the grab handle that positions the cursor
112    * @param[in] image the image to be used.
113    */
114   void CreateGrabHandle();
115
116   /**
117    * Removes and Resets GrabHandle
118    */
119   void DestoryGrabHandle();
120
121   /**
122    * Set the image to be used as the cursor grab hander
123    * @pre The text input actor has been initialised.
124    * @param[in] image The image to be used.
125    */
126   void SetGrabHandleImage( Dali::Image image );
127
128   /**
129    * Set the Actor visibility on the GrabHandle
130    * @param[in] visibility visibility flag
131    */
132   void SetGrabHandleVisibility( bool visibility );
133
134   /* Touch Event Callbacks */
135
136   /**
137    * Callback on selection handle touched.
138    * Sets the image depending if handle in pressed or normal state
139    * @param[in] actor touched
140    * @param[in] touch touch event, used to determine if down or up event
141    */
142   bool OnSelectionHandleTouched(Dali::Actor actor, const TouchEvent& touch);
143
144 private:
145
146   /**
147    * @brief Copy Constructor
148    * @param[in] handles
149    * Undefined/Hidden.
150    */
151   TextInputHandles(const TextInputHandles& handles);
152
153   /**
154    * @Assignment Constructor
155    * @param[in] rhs
156    * Undefined/Hidden.
157    */
158   TextInputHandles& operator=(const TextInputHandles& rhs);
159
160 private:
161
162   ImageActor mSelectionHandleOne;                 // First selection handle used for selecting text to cut&paste
163   ImageActor mSelectionHandleTwo;                 // Second selection handle used for selecting text to cut&paste
164   Actor mHandleOneGrabArea;                       // Invisible actor that receives pans events for the selection handle.
165   Actor mHandleTwoGrabArea;                       // Invisible actor that receives pans events for the selection handle.
166
167   Image mSelectionHandleOneImage;                 // image used for selection handle one
168   Image mSelectionHandleOneImagePressed;          // image used for selection handle one pressed state
169   Image mSelectionHandleTwoImage;                 // image used for selection handle two
170   Image mSelectionHandleTwoImagePressed;          // image used for selection handle two pressed state
171
172   Vector3 mSelectionHandleOneOffset;              // Handle One's Offset
173   Vector3 mSelectionHandleTwoOffset;              // Handle Two's Offset
174   Vector3 mSelectionHandleOneCoordinatePosition;  // Actual x y z position of handle
175   Vector3 mSelectionHandleTwoCoordinatePosition;  // Actual x y z position of handle
176   std::size_t mSelectionHandleOneStringPosition;  // Position of handle along the string of text
177   std::size_t mSelectionHandleTwoStringPosition;  // Position of handle along the string of text
178
179   Image mGrabHandleImage;                         // Image to be used for grab handle
180   ImageActor mGrabHandle;                         // Handle used to move cursor for editing
181   Actor mGrabHandleGrabArea;                      // invisible actor that receives pans events for the grab handle.
182
183   bool mIsSelectionHandleOneFlipped:1;            // Flag to know whether the handle one is flipped or not.
184   bool mIsSelectionHandleTwoFlipped:1;            // Flag to know whether the handle two is flipped or not.
185 };
186
187
188 } // namespace Internal
189
190
191 } // namespace Toolkit
192
193 } // namespace Dali
194
195 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_HANDLES_H__