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