Added interface for queuing input events in TextController
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / decorator / text-decorator.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/public-api/text/decorator/text-decorator.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/constants.h>
23 #include <dali/public-api/images/image.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/math/vector4.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Text
34 {
35
36 struct Decorator::Impl
37 {
38   struct CursorImpl
39   {
40     CursorImpl()
41     : x(0.0f),
42       y(0.0f),
43       height(0.0f),
44       color(Dali::Color::WHITE)
45     {
46     }
47
48     float x;
49     float y;
50     float height;
51
52     Vector4 color;
53   };
54
55   Impl(Dali::Toolkit::Internal::Control& parent, Observer& observer)
56   : mParent(parent),
57     mObserver(observer),
58     mActiveCursor(ACTIVE_CURSOR_NONE),
59     mCursorBlinkInterval(0.5f),
60     mCursorBlinkDuration(0.0f)
61   {
62   }
63
64   void Relayout( const Vector2& size )
65   {
66     // TODO
67   }
68
69   Internal::Control& mParent;
70   Observer& mObserver;
71
72   unsigned int mActiveCursor;
73
74   CursorImpl mCursor[CURSOR_COUNT];
75
76   Image mCursorImage;
77   Image mGrabHandleImage;
78
79   float mCursorBlinkInterval;
80   float mCursorBlinkDuration;
81 };
82
83 DecoratorPtr Decorator::New( Internal::Control& parent, Observer& observer )
84 {
85   return DecoratorPtr( new Decorator(parent, observer) );
86 }
87
88 void Decorator::Relayout( const Vector2& size )
89 {
90   mImpl->Relayout( size );
91 }
92
93 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
94 {
95   mImpl->mActiveCursor = activeCursor;
96 }
97
98 unsigned int Decorator::GetActiveCursor() const
99 {
100   return mImpl->mActiveCursor;
101 }
102
103 void Decorator::SetPosition( Cursor cursor, float x, float y, float height )
104 {
105   mImpl->mCursor[cursor].x = x;
106   mImpl->mCursor[cursor].y = y;
107   mImpl->mCursor[cursor].height = height;
108 }
109
110 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& height ) const
111 {
112   x = mImpl->mCursor[cursor].x;
113   y = mImpl->mCursor[cursor].y;
114   height = mImpl->mCursor[cursor].height;
115 }
116
117 void Decorator::SetCursorImage( Dali::Image image )
118 {
119   mImpl->mCursorImage = image;
120 }
121
122 Dali::Image Decorator::GetCursorImage() const
123 {
124   return mImpl->mCursorImage;
125 }
126
127 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
128 {
129   mImpl->mCursor[cursor].color = color;
130 }
131
132 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
133 {
134   return mImpl->mCursor[cursor].color;
135 }
136
137 void Decorator::StartCursorBlink()
138 {
139   // TODO
140 }
141
142 void Decorator::StopCursorBlink()
143 {
144   // TODO
145 }
146
147 void Decorator::SetCursorBlinkInterval( float seconds )
148 {
149   mImpl->mCursorBlinkInterval = seconds;
150 }
151
152 float Decorator::GetCursorBlinkInterval() const
153 {
154   return mImpl->mCursorBlinkInterval;
155 }
156
157 void Decorator::SetCursorBlinkDuration( float seconds )
158 {
159   mImpl->mCursorBlinkDuration = seconds;
160 }
161
162 float Decorator::GetCursorBlinkDuration() const
163 {
164   return mImpl->mCursorBlinkDuration;
165 }
166
167 void Decorator::SetGrabHandleImage( Dali::Image image )
168 {
169   mImpl->mGrabHandleImage = image;
170 }
171
172 Dali::Image Decorator::GetGrabHandleImage() const
173 {
174   return mImpl->mGrabHandleImage;
175 }
176
177 Decorator::~Decorator()
178 {
179   delete mImpl;
180 }
181
182 Decorator::Decorator(Dali::Toolkit::Internal::Control& parent, Observer& observer)
183 : mImpl( NULL )
184 {
185   mImpl = new Decorator::Impl(parent, observer);
186 }
187
188 } // namespace Text
189
190 } // namespace Toolkit
191
192 } // namespace Dali