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