Scaling feature for fixed-size fonts
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.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/internal/controls/text-controls/text-field-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <string>
23 #include <iostream>
24 #include <cstring>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/public-api/common/stage.h>
27 #include <dali/public-api/images/resource-image.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/devel-api/object/type-registry-helper.h>
30 #include <dali/devel-api/scripting/scripting.h>
31 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
32 #include <dali/integration-api/debug.h>
33
34 // INTERNAL INCLUDES
35 #include <dali-toolkit/public-api/text/rendering-backend.h>
36 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
37 #include <dali-toolkit/internal/text/rendering/text-backend.h>
38 #include <dali-toolkit/internal/text/text-view.h>
39 #include <dali-toolkit/internal/styling/style-manager-impl.h>
40
41 using namespace Dali::Toolkit::Text;
42
43 namespace Dali
44 {
45
46 namespace Toolkit
47 {
48
49 namespace Internal
50 {
51
52 namespace // unnamed namespace
53 {
54
55 #if defined(DEBUG_ENABLED)
56   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
57 #endif
58
59   const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
60
61 } // unnamed namespace
62
63 namespace
64 {
65
66 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
67 {
68   { "BEGIN",  Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN  },
69   { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
70   { "END",    Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END    },
71 };
72 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
73
74 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
75 {
76   { "TOP",    Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP    },
77   { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
78   { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
79 };
80 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
81
82 // Type registration
83 BaseHandle Create()
84 {
85   return Toolkit::TextField::New();
86 }
87
88 // Setup properties, signals and actions using the type-registry.
89 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
90
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend",                    INTEGER,   RENDERING_BACKEND                    )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text",                                 STRING,    TEXT                                 )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text",                     STRING,    PLACEHOLDER_TEXT                     )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-focused",             STRING,    PLACEHOLDER_TEXT_FOCUSED             )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family",                          STRING,    FONT_FAMILY                          )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style",                           STRING,    FONT_STYLE                           )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size",                           FLOAT,     POINT_SIZE                           )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "max-length",                           INTEGER,   MAX_LENGTH                           )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy",                        INTEGER,   EXCEED_POLICY                        )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment",                 STRING,    HORIZONTAL_ALIGNMENT                 )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment",                   STRING,    VERTICAL_ALIGNMENT                   )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color",                           VECTOR4,   TEXT_COLOR                           )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-color",               VECTOR4,   PLACEHOLDER_TEXT_COLOR               )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset",                        VECTOR2,   SHADOW_OFFSET                        )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color",                         VECTOR4,   SHADOW_COLOR                         )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color",                 VECTOR4,   PRIMARY_CURSOR_COLOR                 )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color",               VECTOR4,   SECONDARY_CURSOR_COLOR               )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink",                  BOOLEAN,   ENABLE_CURSOR_BLINK                  )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval",                FLOAT,     CURSOR_BLINK_INTERVAL                )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration",                FLOAT,     CURSOR_BLINK_DURATION                )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-width",                         INTEGER,   CURSOR_WIDTH                         )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image",                    STRING,    GRAB_HANDLE_IMAGE                    )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image",            STRING,    GRAB_HANDLE_PRESSED_IMAGE            )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold",                     FLOAT,     SCROLL_THRESHOLD                     )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed",                         FLOAT,     SCROLL_SPEED                         )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left",          MAP,       SELECTION_HANDLE_IMAGE_LEFT          )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right",         MAP,       SELECTION_HANDLE_IMAGE_RIGHT         )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left",  MAP,       SELECTION_HANDLE_PRESSED_IMAGE_LEFT  )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", MAP,       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-left",   MAP,       SELECTION_HANDLE_MARKER_IMAGE_LEFT   )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-right",  MAP,       SELECTION_HANDLE_MARKER_IMAGE_RIGHT  )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color",            VECTOR4,   SELECTION_HIGHLIGHT_COLOR            )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box",              RECTANGLE, DECORATION_BOUNDING_BOX              )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings",                MAP,       INPUT_METHOD_SETTINGS                )
125
126 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "text-changed",       SIGNAL_TEXT_CHANGED )
127 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
128
129 DALI_TYPE_REGISTRATION_END()
130
131 } // namespace
132
133 Toolkit::TextField TextField::New()
134 {
135   // Create the implementation, temporarily owned by this handle on stack
136   IntrusivePtr< TextField > impl = new TextField();
137
138   // Pass ownership to CustomActor handle
139   Toolkit::TextField handle( *impl );
140
141   // Second-phase init of the implementation
142   // This can only be done after the CustomActor connection has been made...
143   impl->Initialize();
144
145   return handle;
146 }
147
148 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
149 {
150   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
151
152   if( textField )
153   {
154     TextField& impl( GetImpl( textField ) );
155
156     switch( index )
157     {
158       case Toolkit::TextField::Property::RENDERING_BACKEND:
159       {
160         int backend = value.Get< int >();
161         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
162
163         if( impl.mRenderingBackend != backend )
164         {
165           impl.mRenderingBackend = backend;
166           impl.mRenderer.Reset();
167           impl.RequestTextRelayout();
168         }
169         break;
170       }
171       case Toolkit::TextField::Property::TEXT:
172       {
173         if( impl.mController )
174         {
175           const std::string text = value.Get< std::string >();
176           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
177
178           impl.mController->SetText( text );
179         }
180         break;
181       }
182       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
183       {
184         if( impl.mController )
185         {
186           const std::string text = value.Get< std::string >();
187           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
188
189           impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
190         }
191         break;
192       }
193       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
194       {
195         if( impl.mController )
196         {
197           const std::string text = value.Get< std::string >();
198           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
199
200           impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
201         }
202         break;
203       }
204       case Toolkit::TextField::Property::FONT_FAMILY:
205       {
206         if( impl.mController )
207         {
208           const std::string fontFamily = value.Get< std::string >();
209           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
210
211           if( impl.mController->GetDefaultFontFamily() != fontFamily )
212           {
213             impl.mController->SetDefaultFontFamily( fontFamily );
214           }
215         }
216         break;
217       }
218       case Toolkit::TextField::Property::FONT_STYLE:
219       {
220         if( impl.mController )
221         {
222           const std::string fontStyle = value.Get< std::string >();
223           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %s\n", impl.mController.Get(), fontStyle.c_str() );
224
225           if( impl.mController->GetDefaultFontStyle() != fontStyle )
226           {
227             impl.mController->SetDefaultFontStyle( fontStyle );
228           }
229         }
230         break;
231       }
232       case Toolkit::TextField::Property::POINT_SIZE:
233       {
234         if( impl.mController )
235         {
236           const float pointSize = value.Get< float >();
237           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
238
239           if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
240           {
241             impl.mController->SetDefaultPointSize( pointSize );
242           }
243         }
244         break;
245       }
246       case Toolkit::TextField::Property::MAX_LENGTH:
247       {
248         if( impl.mController )
249         {
250           const int max = value.Get< int >();
251           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
252
253           impl.mController->SetMaximumNumberOfCharacters( max );
254         }
255         break;
256       }
257       case Toolkit::TextField::Property::EXCEED_POLICY:
258       {
259         // TODO
260         break;
261       }
262       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
263       {
264         if( impl.mController )
265         {
266           const std::string alignStr = value.Get< std::string >();
267           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
268
269           LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
270           if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
271                                                                               HORIZONTAL_ALIGNMENT_STRING_TABLE,
272                                                                               HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
273                                                                               alignment ) )
274           {
275             impl.mController->SetHorizontalAlignment( alignment );
276           }
277         }
278         break;
279       }
280       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
281       {
282         if( impl.mController )
283         {
284           const std::string alignStr = value.Get< std::string >();
285           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
286
287           LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
288           if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
289                                                                             VERTICAL_ALIGNMENT_STRING_TABLE,
290                                                                             VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
291                                                                             alignment ) )
292           {
293             impl.mController->SetVerticalAlignment( alignment );
294           }
295         }
296         break;
297       }
298       case Toolkit::TextField::Property::TEXT_COLOR:
299       {
300         if( impl.mController )
301         {
302           const Vector4 textColor = value.Get< Vector4 >();
303           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
304
305           if( impl.mController->GetTextColor() != textColor )
306           {
307             impl.mController->SetTextColor( textColor );
308             impl.mRenderer.Reset();
309           }
310         }
311         break;
312       }
313       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
314       {
315         if( impl.mController )
316         {
317           const Vector4 textColor = value.Get< Vector4 >();
318           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
319
320           if( impl.mController->GetPlaceholderTextColor() != textColor )
321           {
322             impl.mController->SetPlaceholderTextColor( textColor );
323             impl.mRenderer.Reset();
324           }
325         }
326         break;
327       }
328       case Toolkit::TextField::Property::SHADOW_OFFSET:
329       {
330         if( impl.mController )
331         {
332           const Vector2 shadowOffset = value.Get< Vector2 >();
333           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
334
335           if ( impl.mController->GetShadowOffset() != shadowOffset )
336           {
337             impl.mController->SetShadowOffset( shadowOffset );
338             impl.mRenderer.Reset();
339           }
340         }
341         break;
342       }
343       case Toolkit::TextField::Property::SHADOW_COLOR:
344       {
345         if( impl.mController )
346         {
347           const Vector4 shadowColor = value.Get< Vector4 >();
348           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_COLOR %f,%f,%f,%f\n", impl.mController.Get(), shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a );
349
350           if ( impl.mController->GetShadowColor() != shadowColor )
351           {
352             impl.mController->SetShadowColor( shadowColor );
353             impl.mRenderer.Reset();
354           }
355         }
356         break;
357       }
358       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
359       {
360         if( impl.mDecorator )
361         {
362           const Vector4 color = value.Get< Vector4 >();
363           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
364
365           impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
366           impl.RequestTextRelayout();
367         }
368         break;
369       }
370       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
371       {
372         if( impl.mDecorator )
373         {
374           const Vector4 color = value.Get< Vector4 >();
375           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
376
377           impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
378           impl.RequestTextRelayout();
379         }
380         break;
381       }
382       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
383       {
384         if( impl.mController )
385         {
386           const bool enable = value.Get< bool >();
387           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
388
389           impl.mController->SetEnableCursorBlink( enable );
390           impl.RequestTextRelayout();
391         }
392         break;
393       }
394       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
395       {
396         if( impl.mDecorator )
397         {
398           const float interval = value.Get< float >();
399           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
400
401           impl.mDecorator->SetCursorBlinkInterval( interval );
402         }
403         break;
404       }
405       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
406       {
407         if( impl.mDecorator )
408         {
409           const float duration = value.Get< float >();
410           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
411
412           impl.mDecorator->SetCursorBlinkDuration( duration );
413         }
414         break;
415       }
416       case Toolkit::TextField::Property::CURSOR_WIDTH:
417       {
418         if( impl.mDecorator )
419         {
420           const int width = value.Get< int >();
421           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
422
423           impl.mDecorator->SetCursorWidth( width );
424           impl.mController->GetLayoutEngine().SetCursorWidth( width );
425         }
426         break;
427       }
428       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
429       {
430         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
431         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
432
433         if( impl.mDecorator )
434         {
435           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
436           impl.RequestTextRelayout();
437         }
438         break;
439       }
440       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
441       {
442         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
443         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
444
445         if( impl.mDecorator )
446         {
447           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
448           impl.RequestTextRelayout();
449         }
450         break;
451       }
452       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
453       {
454         const float threshold = value.Get< float >();
455         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
456
457         if( impl.mDecorator )
458         {
459           impl.mDecorator->SetScrollThreshold( threshold );
460         }
461         break;
462       }
463       case Toolkit::TextField::Property::SCROLL_SPEED:
464       {
465         const float speed = value.Get< float >();
466         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
467
468         if( impl.mDecorator )
469         {
470           impl.mDecorator->SetScrollSpeed( speed );
471         }
472         break;
473       }
474       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
475       {
476         const Image image = Scripting::NewImage( value );
477
478         if( impl.mDecorator )
479         {
480           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
481           impl.RequestTextRelayout();
482         }
483         break;
484       }
485       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
486       {
487         const Image image = Scripting::NewImage( value );
488
489         if( impl.mDecorator )
490         {
491           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
492           impl.RequestTextRelayout();
493         }
494         break;
495       }
496       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
497       {
498         const Image image = Scripting::NewImage( value );
499
500         if( impl.mDecorator )
501         {
502           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
503           impl.RequestTextRelayout();
504         }
505         break;
506       }
507       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
508       {
509         const Image image = Scripting::NewImage( value );
510
511         if( impl.mDecorator )
512         {
513           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
514           impl.RequestTextRelayout();
515         }
516         break;
517       }
518       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
519       {
520         const Image image = Scripting::NewImage( value );
521         if( impl.mDecorator )
522         {
523           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
524           impl.RequestTextRelayout();
525         }
526         break;
527       }
528       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
529       {
530         const Image image = Scripting::NewImage( value );
531         if( impl.mDecorator )
532         {
533           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
534           impl.RequestTextRelayout();
535         }
536         break;
537       }
538       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
539       {
540         const Vector4 color = value.Get< Vector4 >();
541         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTION_HIGHLIGHT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
542
543         if( impl.mDecorator )
544         {
545           impl.mDecorator->SetHighlightColor( color );
546           impl.RequestTextRelayout();
547         }
548         break;
549       }
550       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
551       {
552         if( impl.mDecorator )
553         {
554           const Rect<int> box = value.Get< Rect<int> >();
555           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p DECORATION_BOUNDING_BOX %d,%d %dx%d\n", impl.mController.Get(), box.x, box.y, box.width, box.height );
556
557           impl.mDecorator->SetBoundingBox( box );
558           impl.RequestTextRelayout();
559         }
560         break;
561       }
562       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
563       {
564         const Property::Map map = value.Get<Property::Map>();
565         VirtualKeyboard::ApplySettings( map );
566         break;
567       }
568     } // switch
569   } // textfield
570 }
571
572 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
573 {
574   Property::Value value;
575
576   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
577
578   if( textField )
579   {
580     TextField& impl( GetImpl( textField ) );
581
582     switch( index )
583     {
584       case Toolkit::TextField::Property::RENDERING_BACKEND:
585       {
586         value = impl.mRenderingBackend;
587         break;
588       }
589       case Toolkit::TextField::Property::TEXT:
590       {
591         if( impl.mController )
592         {
593           std::string text;
594           impl.mController->GetText( text );
595           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
596           value = text;
597         }
598         break;
599       }
600       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
601       {
602         if( impl.mController )
603         {
604           std::string text;
605           impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
606           value = text;
607         }
608         break;
609       }
610       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
611       {
612         if( impl.mController )
613         {
614           std::string text;
615           impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
616           value = text;
617         }
618         break;
619       }
620       case Toolkit::TextField::Property::FONT_FAMILY:
621       {
622         if( impl.mController )
623         {
624           value = impl.mController->GetDefaultFontFamily();
625         }
626         break;
627       }
628       case Toolkit::TextField::Property::FONT_STYLE:
629       {
630         if( impl.mController )
631         {
632           value = impl.mController->GetDefaultFontStyle();
633         }
634         break;
635       }
636       case Toolkit::TextField::Property::POINT_SIZE:
637       {
638         if( impl.mController )
639         {
640           value = impl.mController->GetDefaultPointSize();
641         }
642         break;
643       }
644       case Toolkit::TextField::Property::MAX_LENGTH:
645       {
646         if( impl.mController )
647         {
648           value = impl.mController->GetMaximumNumberOfCharacters();
649         }
650         break;
651       }
652       case Toolkit::TextField::Property::EXCEED_POLICY:
653       {
654         value = impl.mExceedPolicy;
655         break;
656       }
657       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
658       {
659         if( impl.mController )
660         {
661           const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
662                                                                                                                 HORIZONTAL_ALIGNMENT_STRING_TABLE,
663                                                                                                                 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
664           if( name )
665           {
666             value = std::string( name );
667           }
668         }
669         break;
670       }
671       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
672       {
673         if( impl.mController )
674         {
675           const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
676                                                                                                               VERTICAL_ALIGNMENT_STRING_TABLE,
677                                                                                                               VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
678           if( name )
679           {
680             value = std::string( name );
681           }
682         }
683         break;
684       }
685       case Toolkit::TextField::Property::TEXT_COLOR:
686       {
687         if ( impl.mController )
688         {
689           value = impl.mController->GetTextColor();
690         }
691         break;
692       }
693       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
694       {
695         if ( impl.mController )
696         {
697           value = impl.mController->GetPlaceholderTextColor();
698         }
699         break;
700       }
701       case Toolkit::TextField::Property::SHADOW_OFFSET:
702       {
703         if ( impl.mController )
704         {
705           value = impl.mController->GetShadowOffset();
706         }
707         break;
708       }
709       case Toolkit::TextField::Property::SHADOW_COLOR:
710       {
711         if ( impl.mController )
712         {
713           value = impl.mController->GetShadowColor();
714         }
715         break;
716       }
717       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
718       {
719         if( impl.mDecorator )
720         {
721           value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
722         }
723         break;
724       }
725       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
726       {
727         if( impl.mDecorator )
728         {
729           value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
730         }
731         break;
732       }
733       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
734       {
735         value = impl.mController->GetEnableCursorBlink();
736         break;
737       }
738       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
739       {
740         if( impl.mDecorator )
741         {
742           value = impl.mDecorator->GetCursorBlinkInterval();
743         }
744         break;
745       }
746       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
747       {
748         if( impl.mDecorator )
749         {
750           value = impl.mDecorator->GetCursorBlinkDuration();
751         }
752         break;
753       }
754       case Toolkit::TextField::Property::CURSOR_WIDTH:
755       {
756         if( impl.mDecorator )
757         {
758           value = impl.mDecorator->GetCursorWidth();
759         }
760         break;
761       }
762       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
763       {
764         if( impl.mDecorator )
765         {
766           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
767           if( image )
768           {
769             value = image.GetUrl();
770           }
771         }
772         break;
773       }
774       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
775       {
776         if( impl.mDecorator )
777         {
778           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
779           if( image )
780           {
781             value = image.GetUrl();
782           }
783         }
784         break;
785       }
786       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
787       {
788         if( impl.mDecorator )
789         {
790           value = impl.mDecorator->GetScrollThreshold();
791         }
792         break;
793       }
794       case Toolkit::TextField::Property::SCROLL_SPEED:
795       {
796         if( impl.mDecorator )
797         {
798           value = impl.mDecorator->GetScrollSpeed();
799         }
800         break;
801       }
802       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
803       {
804         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
805         break;
806       }
807       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
808       {
809         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
810         break;
811       }
812       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
813       {
814         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
815         break;
816       }
817       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
818       {
819         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
820         break;
821       }
822       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
823       {
824         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
825         break;
826       }
827       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
828       {
829         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
830         break;
831       }
832       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
833       {
834         if( impl.mDecorator )
835         {
836           value = impl.mDecorator->GetHighlightColor();
837         }
838         break;
839       }
840       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
841       {
842         if( impl.mDecorator )
843         {
844           value = impl.mDecorator->GetBoundingBox();
845         }
846         break;
847       }
848       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
849       {
850         break;
851       }
852     } //switch
853   }
854
855   return value;
856 }
857
858 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
859 {
860   Dali::BaseHandle handle( object );
861
862   bool connected( true );
863   Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
864
865   if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
866   {
867     field.TextChangedSignal().Connect( tracker, functor );
868   }
869   else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
870   {
871     field.MaxLengthReachedSignal().Connect( tracker, functor );
872   }
873   else
874   {
875     // signalName does not match any signal
876     connected = false;
877   }
878
879   return connected;
880 }
881
882 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
883 {
884   return mTextChangedSignal;
885 }
886
887 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
888 {
889   return mMaxLengthReachedSignal;
890 }
891
892 void TextField::OnInitialize()
893 {
894   Actor self = Self();
895
896   mController = Text::Controller::New( *this );
897
898   mDecorator = Text::Decorator::New( *mController,
899                                      *mController );
900
901   mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
902
903   mController->EnableTextInput( mDecorator );
904
905   // Forward input events to controller
906   EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan |Gesture::LongPress ) );
907   GetTapGestureDetector().SetMaximumTapsRequired( 2 );
908
909   self.TouchedSignal().Connect( this, &TextField::OnTouched );
910
911   // Set BoundingBox to stage size if not already set.
912   if ( mDecorator->GetBoundingBox().IsEmpty() )
913   {
914     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
915     mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
916   }
917
918   // Fill-parent area by default
919   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
920   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
921   self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
922 }
923
924 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
925 {
926   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
927
928    switch ( change )
929    {
930      case StyleChange::DEFAULT_FONT_CHANGE:
931      {
932        DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE\n");
933        if ( mController->GetDefaultFontFamily() == "" )
934        {
935          // Property system did not set the font so should update it.
936          // todo instruct text-controller to update model
937        }
938        break;
939      }
940
941      case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
942      {
943        DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
944
945        if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
946        {
947          // Property system did not set the PointSize so should update it.
948          // todo instruct text-controller to update model
949        }
950        break;
951      }
952      case StyleChange::THEME_CHANGE:
953      {
954        GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
955        break;
956      }
957    }
958 }
959
960 Vector3 TextField::GetNaturalSize()
961 {
962   return mController->GetNaturalSize();
963 }
964
965 float TextField::GetHeightForWidth( float width )
966 {
967   return mController->GetHeightForWidth( width );
968 }
969
970 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
971 {
972   if( mController->Relayout( size ) ||
973       !mRenderer )
974   {
975     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
976
977     if( mDecorator )
978     {
979       mDecorator->Relayout( size );
980     }
981
982     if( !mRenderer )
983     {
984       mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
985     }
986
987     EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
988     RenderText();
989   }
990 }
991
992 void TextField::RenderText()
993 {
994   Actor self = Self();
995   Actor renderableActor;
996   if( mRenderer )
997   {
998     renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() );
999   }
1000
1001   if( renderableActor != mRenderableActor )
1002   {
1003     UnparentAndReset( mRenderableActor );
1004     mRenderableActor = renderableActor;
1005   }
1006
1007   if( mRenderableActor )
1008   {
1009     const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
1010
1011     mRenderableActor.SetPosition( offset.x, offset.y );
1012
1013     Actor clipRootActor;
1014     if( mClipper )
1015     {
1016       clipRootActor = mClipper->GetRootActor();
1017     }
1018
1019     for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1020            endIt = mClippingDecorationActors.end();
1021          it != endIt;
1022          ++it )
1023     {
1024       Actor actor = *it;
1025
1026       if( clipRootActor )
1027       {
1028         clipRootActor.Add( actor );
1029       }
1030       else
1031       {
1032         self.Add( actor );
1033       }
1034     }
1035     mClippingDecorationActors.clear();
1036
1037     // Make sure the actor is parented correctly with/without clipping
1038     if( clipRootActor )
1039     {
1040       clipRootActor.Add( mRenderableActor );
1041     }
1042     else
1043     {
1044       self.Add( mRenderableActor );
1045     }
1046   }
1047 }
1048
1049 void TextField::OnKeyInputFocusGained()
1050 {
1051   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1052
1053   VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1054
1055   ImfManager imfManager = ImfManager::Get();
1056
1057   if ( imfManager )
1058   {
1059     imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1060
1061     // Notify that the text editing start.
1062     imfManager.Activate();
1063
1064     // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1065     imfManager.SetRestoreAfterFocusLost( true );
1066   }
1067
1068    ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1069
1070    if ( notifier )
1071    {
1072       notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1073    }
1074
1075   mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1076
1077   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1078 }
1079
1080 void TextField::OnKeyInputFocusLost()
1081 {
1082   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1083
1084   VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1085
1086   ImfManager imfManager = ImfManager::Get();
1087   if ( imfManager )
1088   {
1089     // The text editing is finished. Therefore the imf manager don't have restore activation.
1090     imfManager.SetRestoreAfterFocusLost( false );
1091
1092     // Notify that the text editing finish.
1093     imfManager.Deactivate();
1094
1095     imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1096   }
1097
1098   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1099
1100   if ( notifier )
1101   {
1102     notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1103   }
1104
1105   mController->KeyboardFocusLostEvent();
1106
1107   EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1108 }
1109
1110 void TextField::OnTap( const TapGesture& gesture )
1111 {
1112   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1113
1114   // Show the keyboard if it was hidden.
1115   if (!VirtualKeyboard::IsVisible())
1116   {
1117     VirtualKeyboard::Show();
1118   }
1119
1120   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1121   mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1122
1123   SetKeyInputFocus();
1124 }
1125
1126 void TextField::OnPan( const PanGesture& gesture )
1127 {
1128   mController->PanEvent( gesture.state, gesture.displacement );
1129 }
1130
1131 void TextField::OnLongPress( const LongPressGesture& gesture )
1132 {
1133   mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1134 }
1135
1136 bool TextField::OnKeyEvent( const KeyEvent& event )
1137 {
1138   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1139
1140   if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1141       "Return" == event.keyPressedName ) // Make a Dali key code for this
1142   {
1143     ClearKeyInputFocus();
1144     return true;
1145   }
1146
1147   return mController->KeyEvent( event );
1148 }
1149
1150 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1151 {
1152   if( actor )
1153   {
1154     if( needsClipping )
1155     {
1156       mClippingDecorationActors.push_back( actor );
1157     }
1158     else
1159     {
1160       Self().Add( actor );
1161     }
1162   }
1163 }
1164
1165 void TextField::RequestTextRelayout()
1166 {
1167   RelayoutRequest();
1168 }
1169
1170 void TextField::TextChanged()
1171 {
1172   Dali::Toolkit::TextField handle( GetOwner() );
1173   mTextChangedSignal.Emit( handle );
1174 }
1175
1176 void TextField::OnStageConnect( Dali::Actor actor )
1177 {
1178   if ( mHasBeenStaged )
1179   {
1180     RenderText();
1181   }
1182   else
1183   {
1184     mHasBeenStaged = true;
1185   }
1186 }
1187
1188 void TextField::MaxLengthReached()
1189 {
1190   Dali::Toolkit::TextField handle( GetOwner() );
1191   mMaxLengthReachedSignal.Emit( handle );
1192 }
1193
1194 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1195 {
1196   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1197   return mController->OnImfEvent( imfManager, imfEvent );
1198 }
1199
1200 void TextField::GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1201 {
1202   if( mDecorator )
1203   {
1204     ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1205
1206     if ( image )
1207     {
1208       Property::Map map;
1209       Scripting::CreatePropertyMap( image, map );
1210       value = map;
1211     }
1212   }
1213 }
1214
1215 void TextField::EnableClipping( bool clipping, const Vector2& size )
1216 {
1217   if( clipping )
1218   {
1219     // Not worth to created clip actor if width or height is equal to zero.
1220     if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1221     {
1222       if( !mClipper )
1223       {
1224         Actor self = Self();
1225
1226         mClipper = Clipper::New( size );
1227         self.Add( mClipper->GetRootActor() );
1228         self.Add( mClipper->GetImageActor() );
1229       }
1230       else if ( mClipper )
1231       {
1232         mClipper->Refresh( size );
1233       }
1234     }
1235   }
1236   else
1237   {
1238     // Note - this will automatically remove the root & image actors
1239     mClipper.Reset();
1240   }
1241 }
1242
1243 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1244 {
1245   mController->PasteClipboardItemEvent();
1246 }
1247
1248 void TextField::KeyboardStatusChanged(bool keyboardShown)
1249 {
1250   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1251
1252   // Just hide the grab handle when keyboard is hidden.
1253   if (!keyboardShown )
1254   {
1255     mController->KeyboardFocusLostEvent();
1256   }
1257   else
1258   {
1259     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1260   }
1261 }
1262
1263 void TextField::OnStageConnection( int depth )
1264 {
1265   // Call the Control::OnStageConnection() to set the depth of the background.
1266   Control::OnStageConnection( depth );
1267
1268   // Sets the depth to the renderers inside the text's decorator.
1269   mDecorator->SetTextDepth( depth );
1270
1271   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1272 }
1273
1274 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1275 {
1276   return true;
1277 }
1278
1279 TextField::TextField()
1280 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1281   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1282   mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1283   mHasBeenStaged( false )
1284 {
1285 }
1286
1287 TextField::~TextField()
1288 {
1289   mClipper.Reset();
1290 }
1291
1292 } // namespace Internal
1293
1294 } // namespace Toolkit
1295
1296 } // namespace Dali