Add PIXEL_SIZE and ELLIPSIS property in text-controls
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.cpp
1 /*
2  * Copyright (c) 2017 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/object/property-helper-devel.h>
27 #include <dali/public-api/object/type-registry-helper.h>
28 #include <dali/integration-api/adaptors/adaptor.h>
29 #include <dali/integration-api/debug.h>
30
31 // INTERNAL INCLUDES
32 #include <dali-toolkit/public-api/text/rendering-backend.h>
33 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
34 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
35 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
36 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
37 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
38 #include <dali-toolkit/internal/text/rendering/text-backend.h>
39 #include <dali-toolkit/internal/text/text-effects-style.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
41 #include <dali-toolkit/internal/text/text-view.h>
42 #include <dali-toolkit/internal/styling/style-manager-impl.h>
43
44 using namespace Dali::Toolkit::Text;
45
46 namespace Dali
47 {
48
49 namespace Toolkit
50 {
51
52 namespace Internal
53 {
54
55 namespace // unnamed namespace
56 {
57
58 #if defined(DEBUG_ENABLED)
59   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
60 #endif
61
62   const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
63 } // unnamed namespace
64
65 namespace
66 {
67
68 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
69 {
70   { "BEGIN",  Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN  },
71   { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
72   { "END",    Toolkit::Text::Layout::HORIZONTAL_ALIGN_END    },
73 };
74 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
75
76 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
77 {
78   { "TOP",    Toolkit::Text::Layout::VERTICAL_ALIGN_TOP    },
79   { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
80   { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
81 };
82 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
83
84 // Type registration
85 BaseHandle Create()
86 {
87   return Toolkit::TextField::New();
88 }
89
90 // Setup properties, signals and actions using the type-registry.
91 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
92
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend",                     INTEGER,   RENDERING_BACKEND                    )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text",                                 STRING,    TEXT                                 )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText",                      STRING,    PLACEHOLDER_TEXT                     )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused",               STRING,    PLACEHOLDER_TEXT_FOCUSED             )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily",                           STRING,    FONT_FAMILY                          )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle",                            MAP,       FONT_STYLE                           )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize",                            FLOAT,     POINT_SIZE                           )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength",                            INTEGER,   MAX_LENGTH                           )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy",                         INTEGER,   EXCEED_POLICY                        )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment",                  STRING,    HORIZONTAL_ALIGNMENT                 )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment",                    STRING,    VERTICAL_ALIGNMENT                   )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor",                            VECTOR4,   TEXT_COLOR                           )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor",                 VECTOR4,   PLACEHOLDER_TEXT_COLOR               )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset",                         VECTOR2,   SHADOW_OFFSET                        )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor",                          VECTOR4,   SHADOW_COLOR                         )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor",                   VECTOR4,   PRIMARY_CURSOR_COLOR                 )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor",                 VECTOR4,   SECONDARY_CURSOR_COLOR               )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink",                    BOOLEAN,   ENABLE_CURSOR_BLINK                  )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval",                  FLOAT,     CURSOR_BLINK_INTERVAL                )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration",                  FLOAT,     CURSOR_BLINK_DURATION                )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth",                          INTEGER,   CURSOR_WIDTH                         )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage",                      STRING,    GRAB_HANDLE_IMAGE                    )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage",               STRING,    GRAB_HANDLE_PRESSED_IMAGE            )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold",                      FLOAT,     SCROLL_THRESHOLD                     )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed",                          FLOAT,     SCROLL_SPEED                         )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft",             MAP,       SELECTION_HANDLE_IMAGE_LEFT          )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight",            MAP,       SELECTION_HANDLE_IMAGE_RIGHT         )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft",      MAP,       SELECTION_HANDLE_PRESSED_IMAGE_LEFT  )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight",     MAP,       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft",       MAP,       SELECTION_HANDLE_MARKER_IMAGE_LEFT   )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight",      MAP,       SELECTION_HANDLE_MARKER_IMAGE_RIGHT  )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor",              VECTOR4,   SELECTION_HIGHLIGHT_COLOR            )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox",                RECTANGLE, DECORATION_BOUNDING_BOX              )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings",                  MAP,       INPUT_METHOD_SETTINGS                )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor",                           VECTOR4,   INPUT_COLOR                          )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup",                         BOOLEAN,   ENABLE_MARKUP                        )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily",                      STRING,    INPUT_FONT_FAMILY                    )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle",                       MAP,       INPUT_FONT_STYLE                     )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize",                       FLOAT,     INPUT_POINT_SIZE                     )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline",                            MAP,       UNDERLINE                            )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline",                       MAP,       INPUT_UNDERLINE                      )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow",                               MAP,       SHADOW                               )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow",                          MAP,       INPUT_SHADOW                         )
136 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss",                               MAP,       EMBOSS                               )
137 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss",                          MAP,       INPUT_EMBOSS                         )
138 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline",                              MAP,       OUTLINE                              )
139 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline",                         MAP,       INPUT_OUTLINE                        )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings",            MAP,       HIDDEN_INPUT_SETTINGS                )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize",                      FLOAT,     PIXEL_SIZE                           )
142
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged",        SIGNAL_TEXT_CHANGED )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached",   SIGNAL_MAX_LENGTH_REACHED )
145 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged",  SIGNAL_INPUT_STYLE_CHANGED )
146
147 DALI_TYPE_REGISTRATION_END()
148
149 } // namespace
150
151 Toolkit::TextField TextField::New()
152 {
153   // Create the implementation, temporarily owned by this handle on stack
154   IntrusivePtr< TextField > impl = new TextField();
155
156   // Pass ownership to CustomActor handle
157   Toolkit::TextField handle( *impl );
158
159   // Second-phase init of the implementation
160   // This can only be done after the CustomActor connection has been made...
161   impl->Initialize();
162
163   return handle;
164 }
165
166 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
167 {
168   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
169
170   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
171
172
173   if( textField )
174   {
175     TextField& impl( GetImpl( textField ) );
176
177     switch( index )
178     {
179       case Toolkit::TextField::Property::RENDERING_BACKEND:
180       {
181         int backend = value.Get< int >();
182         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
183
184 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
185         if( Text::RENDERING_VECTOR_BASED == backend )
186         {
187           backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
188         }
189 #endif
190         if( impl.mRenderingBackend != backend )
191         {
192           impl.mRenderingBackend = backend;
193           impl.mRenderer.Reset();
194
195           if( impl.mController )
196           {
197             // When using the vector-based rendering, the size of the GLyphs are different
198             TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
199             impl.mController->SetGlyphType( glyphType );
200           }
201         }
202         break;
203       }
204       case Toolkit::TextField::Property::TEXT:
205       {
206         if( impl.mController )
207         {
208           const std::string& text = value.Get< std::string >();
209           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
210
211           impl.mController->SetText( text );
212         }
213         break;
214       }
215       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
216       {
217         if( impl.mController )
218         {
219           const std::string& text = value.Get< std::string >();
220           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
221
222           impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
223         }
224         break;
225       }
226       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
227       {
228         if( impl.mController )
229         {
230           const std::string& text = value.Get< std::string >();
231           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
232
233           impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
234         }
235         break;
236       }
237       case Toolkit::TextField::Property::FONT_FAMILY:
238       {
239         if( impl.mController )
240         {
241           const std::string& fontFamily = value.Get< std::string >();
242           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
243           impl.mController->SetDefaultFontFamily( fontFamily );
244         }
245         break;
246       }
247       case Toolkit::TextField::Property::FONT_STYLE:
248       {
249         SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
250         break;
251       }
252       case Toolkit::TextField::Property::POINT_SIZE:
253       {
254         if( impl.mController )
255         {
256           const float pointSize = value.Get< float >();
257           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
258
259           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
260           {
261             impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
262           }
263         }
264         break;
265       }
266       case Toolkit::TextField::Property::MAX_LENGTH:
267       {
268         if( impl.mController )
269         {
270           const int max = value.Get< int >();
271           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
272
273           impl.mController->SetMaximumNumberOfCharacters( max );
274         }
275         break;
276       }
277       case Toolkit::TextField::Property::EXCEED_POLICY:
278       {
279         impl.mExceedPolicy = value.Get<int>();
280
281         if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
282         {
283           impl.EnableClipping();
284         }
285         else
286         {
287           UnparentAndReset( impl.mStencil );
288         }
289         impl.RequestTextRelayout();
290         break;
291       }
292       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
293       {
294         if( impl.mController )
295         {
296           const std::string& alignStr = value.Get< std::string >();
297           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
298
299           Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
300           if( Scripting::GetEnumeration< Layout::HorizontalAlignment >( alignStr.c_str(),
301                                                                         HORIZONTAL_ALIGNMENT_STRING_TABLE,
302                                                                         HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
303                                                                         alignment ) )
304           {
305             impl.mController->SetHorizontalAlignment( alignment );
306           }
307         }
308         break;
309       }
310       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
311       {
312         if( impl.mController )
313         {
314           const std::string& alignStr = value.Get< std::string >();
315           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
316
317           Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
318           if( Scripting::GetEnumeration< Layout::VerticalAlignment >( alignStr.c_str(),
319                                                                       VERTICAL_ALIGNMENT_STRING_TABLE,
320                                                                       VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
321                                                                       alignment ) )
322           {
323             impl.mController->SetVerticalAlignment( alignment );
324           }
325         }
326         break;
327       }
328       case Toolkit::TextField::Property::TEXT_COLOR:
329       {
330         if( impl.mController )
331         {
332           const Vector4& textColor = value.Get< Vector4 >();
333           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 );
334
335           if( impl.mController->GetDefaultColor() != textColor )
336           {
337             impl.mController->SetDefaultColor( textColor );
338             impl.mController->SetInputColor( textColor );
339             impl.mRenderer.Reset();
340           }
341         }
342         break;
343       }
344       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
345       {
346         if( impl.mController )
347         {
348           const Vector4& textColor = value.Get< Vector4 >();
349           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 );
350
351           if( impl.mController->GetPlaceholderTextColor() != textColor )
352           {
353             impl.mController->SetPlaceholderTextColor( textColor );
354             impl.mRenderer.Reset();
355           }
356         }
357         break;
358       }
359       case Toolkit::TextField::Property::SHADOW_OFFSET:
360       {
361         if( impl.mController )
362         {
363           const Vector2& shadowOffset = value.Get< Vector2 >();
364           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
365
366           if ( impl.mController->GetShadowOffset() != shadowOffset )
367           {
368             impl.mController->SetShadowOffset( shadowOffset );
369             impl.mRenderer.Reset();
370           }
371         }
372         break;
373       }
374       case Toolkit::TextField::Property::SHADOW_COLOR:
375       {
376         if( impl.mController )
377         {
378           const Vector4& shadowColor = value.Get< Vector4 >();
379           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 );
380
381           if ( impl.mController->GetShadowColor() != shadowColor )
382           {
383             impl.mController->SetShadowColor( shadowColor );
384             impl.mRenderer.Reset();
385           }
386         }
387         break;
388       }
389       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
390       {
391         if( impl.mDecorator )
392         {
393           const Vector4& color = value.Get< Vector4 >();
394           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 );
395
396           impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
397           impl.RequestTextRelayout();
398         }
399         break;
400       }
401       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
402       {
403         if( impl.mDecorator )
404         {
405           const Vector4& color = value.Get< Vector4 >();
406           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 );
407
408           impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
409           impl.RequestTextRelayout();
410         }
411         break;
412       }
413       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
414       {
415         if( impl.mController )
416         {
417           const bool enable = value.Get< bool >();
418           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
419
420           impl.mController->SetEnableCursorBlink( enable );
421           impl.RequestTextRelayout();
422         }
423         break;
424       }
425       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
426       {
427         if( impl.mDecorator )
428         {
429           const float interval = value.Get< float >();
430           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
431
432           impl.mDecorator->SetCursorBlinkInterval( interval );
433         }
434         break;
435       }
436       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
437       {
438         if( impl.mDecorator )
439         {
440           const float duration = value.Get< float >();
441           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
442
443           impl.mDecorator->SetCursorBlinkDuration( duration );
444         }
445         break;
446       }
447       case Toolkit::TextField::Property::CURSOR_WIDTH:
448       {
449         if( impl.mDecorator )
450         {
451           const int width = value.Get< int >();
452           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
453
454           impl.mDecorator->SetCursorWidth( width );
455           impl.mController->GetLayoutEngine().SetCursorWidth( width );
456         }
457         break;
458       }
459       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
460       {
461         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
462         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
463
464         if( impl.mDecorator )
465         {
466           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
467           impl.RequestTextRelayout();
468         }
469         break;
470       }
471       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
472       {
473         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
474         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
475
476         if( impl.mDecorator )
477         {
478           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
479           impl.RequestTextRelayout();
480         }
481         break;
482       }
483       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
484       {
485         const float threshold = value.Get< float >();
486         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
487
488         if( impl.mDecorator )
489         {
490           impl.mDecorator->SetScrollThreshold( threshold );
491         }
492         break;
493       }
494       case Toolkit::TextField::Property::SCROLL_SPEED:
495       {
496         const float speed = value.Get< float >();
497         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
498
499         if( impl.mDecorator )
500         {
501           impl.mDecorator->SetScrollSpeed( speed );
502         }
503         break;
504       }
505       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
506       {
507         const Image image = Scripting::NewImage( value );
508
509         if( impl.mDecorator && image )
510         {
511           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
512           impl.RequestTextRelayout();
513         }
514         break;
515       }
516       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
517       {
518         const Image image = Scripting::NewImage( value );
519
520         if( impl.mDecorator && image )
521         {
522           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
523           impl.RequestTextRelayout();
524         }
525         break;
526       }
527       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
528       {
529         const Image image = Scripting::NewImage( value );
530
531         if( impl.mDecorator && image )
532         {
533           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
534           impl.RequestTextRelayout();
535         }
536         break;
537       }
538       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
539       {
540         const Image image = Scripting::NewImage( value );
541
542         if( impl.mDecorator && image )
543         {
544           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
545           impl.RequestTextRelayout();
546         }
547         break;
548       }
549       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
550       {
551         const Image image = Scripting::NewImage( value );
552
553         if( impl.mDecorator && image )
554         {
555           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
556           impl.RequestTextRelayout();
557         }
558         break;
559       }
560       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
561       {
562         const Image image = Scripting::NewImage( value );
563
564         if( impl.mDecorator && image )
565         {
566           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
567           impl.RequestTextRelayout();
568         }
569         break;
570       }
571       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
572       {
573         const Vector4 color = value.Get< Vector4 >();
574         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 );
575
576         if( impl.mDecorator )
577         {
578           impl.mDecorator->SetHighlightColor( color );
579           impl.RequestTextRelayout();
580         }
581         break;
582       }
583       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
584       {
585         if( impl.mDecorator )
586         {
587           const Rect<int> box = value.Get< Rect<int> >();
588           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 );
589
590           impl.mDecorator->SetBoundingBox( box );
591           impl.RequestTextRelayout();
592         }
593         break;
594       }
595       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
596       {
597         const Property::Map* map = value.GetMap();
598         if (map)
599         {
600           impl.mInputMethodOptions.ApplyProperty( *map );
601         }
602         impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
603
604         Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
605         if (control == textField)
606         {
607           impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
608         }
609         break;
610       }
611       case Toolkit::TextField::Property::INPUT_COLOR:
612       {
613         if( impl.mController )
614         {
615           const Vector4 inputColor = value.Get< Vector4 >();
616           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), inputColor.r, inputColor.g, inputColor.b, inputColor.a );
617
618           impl.mController->SetInputColor( inputColor );
619         }
620         break;
621       }
622       case Toolkit::TextField::Property::ENABLE_MARKUP:
623       {
624         if( impl.mController )
625         {
626           const bool enableMarkup = value.Get<bool>();
627           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
628
629           impl.mController->SetMarkupProcessorEnabled( enableMarkup );
630         }
631         break;
632       }
633       case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
634       {
635         if( impl.mController )
636         {
637           const std::string& fontFamily = value.Get< std::string >();
638           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
639           impl.mController->SetInputFontFamily( fontFamily );
640         }
641         break;
642       }
643       case Toolkit::TextField::Property::INPUT_FONT_STYLE:
644       {
645         SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
646         break;
647       }
648       case Toolkit::TextField::Property::INPUT_POINT_SIZE:
649       {
650         if( impl.mController )
651         {
652           const float pointSize = value.Get< float >();
653           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
654           impl.mController->SetInputFontPointSize( pointSize );
655         }
656         break;
657       }
658       case Toolkit::TextField::Property::UNDERLINE:
659       {
660         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
661         if( update )
662         {
663           impl.mRenderer.Reset();
664         }
665         break;
666       }
667       case Toolkit::TextField::Property::INPUT_UNDERLINE:
668       {
669         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
670         if( update )
671         {
672           impl.mRenderer.Reset();
673         }
674         break;
675       }
676       case Toolkit::TextField::Property::SHADOW:
677       {
678         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
679         if( update )
680         {
681           impl.mRenderer.Reset();
682         }
683         break;
684       }
685       case Toolkit::TextField::Property::INPUT_SHADOW:
686       {
687         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
688         if( update )
689         {
690           impl.mRenderer.Reset();
691         }
692         break;
693       }
694       case Toolkit::TextField::Property::EMBOSS:
695       {
696         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
697         if( update )
698         {
699           impl.mRenderer.Reset();
700         }
701         break;
702       }
703       case Toolkit::TextField::Property::INPUT_EMBOSS:
704       {
705         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
706         if( update )
707         {
708           impl.mRenderer.Reset();
709         }
710         break;
711       }
712       case Toolkit::TextField::Property::OUTLINE:
713       {
714         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
715         if( update )
716         {
717           impl.mRenderer.Reset();
718         }
719         break;
720       }
721       case Toolkit::TextField::Property::INPUT_OUTLINE:
722       {
723         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
724         if( update )
725         {
726           impl.mRenderer.Reset();
727         }
728         break;
729       }
730       case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
731       {
732         const Property::Map* map = value.GetMap();
733         if (map)
734         {
735           impl.mController->SetHiddenInputOption(*map);
736         }
737         break;
738       }
739       case Toolkit::DevelTextField::Property::PIXEL_SIZE:
740       {
741         if( impl.mController )
742         {
743           const float pixelSize = value.Get< float >();
744           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
745
746           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
747           {
748             impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
749           }
750         }
751         break;
752       }
753     } // switch
754   } // textfield
755 }
756
757 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
758 {
759   Property::Value value;
760
761   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
762
763   if( textField )
764   {
765     TextField& impl( GetImpl( textField ) );
766
767     switch( index )
768     {
769       case Toolkit::TextField::Property::RENDERING_BACKEND:
770       {
771         value = impl.mRenderingBackend;
772         break;
773       }
774       case Toolkit::TextField::Property::TEXT:
775       {
776         if( impl.mController )
777         {
778           std::string text;
779           impl.mController->GetText( text );
780           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
781           value = text;
782         }
783         break;
784       }
785       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
786       {
787         if( impl.mController )
788         {
789           std::string text;
790           impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
791           value = text;
792         }
793         break;
794       }
795       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
796       {
797         if( impl.mController )
798         {
799           std::string text;
800           impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
801           value = text;
802         }
803         break;
804       }
805       case Toolkit::TextField::Property::FONT_FAMILY:
806       {
807         if( impl.mController )
808         {
809           value = impl.mController->GetDefaultFontFamily();
810         }
811         break;
812       }
813       case Toolkit::TextField::Property::FONT_STYLE:
814       {
815         GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
816         break;
817       }
818       case Toolkit::TextField::Property::POINT_SIZE:
819       {
820         if( impl.mController )
821         {
822           value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
823         }
824         break;
825       }
826       case Toolkit::TextField::Property::MAX_LENGTH:
827       {
828         if( impl.mController )
829         {
830           value = impl.mController->GetMaximumNumberOfCharacters();
831         }
832         break;
833       }
834       case Toolkit::TextField::Property::EXCEED_POLICY:
835       {
836         value = impl.mExceedPolicy;
837         break;
838       }
839       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
840       {
841         if( impl.mController )
842         {
843           const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
844                                                                                                           HORIZONTAL_ALIGNMENT_STRING_TABLE,
845                                                                                                           HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
846           if( name )
847           {
848             value = std::string( name );
849           }
850         }
851         break;
852       }
853       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
854       {
855         if( impl.mController )
856         {
857           const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
858                                                                                                         VERTICAL_ALIGNMENT_STRING_TABLE,
859                                                                                                         VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
860           if( name )
861           {
862             value = std::string( name );
863           }
864         }
865         break;
866       }
867       case Toolkit::TextField::Property::TEXT_COLOR:
868       {
869         if ( impl.mController )
870         {
871           value = impl.mController->GetDefaultColor();
872         }
873         break;
874       }
875       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
876       {
877         if ( impl.mController )
878         {
879           value = impl.mController->GetPlaceholderTextColor();
880         }
881         break;
882       }
883       case Toolkit::TextField::Property::SHADOW_OFFSET:
884       {
885         if ( impl.mController )
886         {
887           value = impl.mController->GetShadowOffset();
888         }
889         break;
890       }
891       case Toolkit::TextField::Property::SHADOW_COLOR:
892       {
893         if ( impl.mController )
894         {
895           value = impl.mController->GetShadowColor();
896         }
897         break;
898       }
899       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
900       {
901         if( impl.mDecorator )
902         {
903           value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
904         }
905         break;
906       }
907       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
908       {
909         if( impl.mDecorator )
910         {
911           value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
912         }
913         break;
914       }
915       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
916       {
917         value = impl.mController->GetEnableCursorBlink();
918         break;
919       }
920       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
921       {
922         if( impl.mDecorator )
923         {
924           value = impl.mDecorator->GetCursorBlinkInterval();
925         }
926         break;
927       }
928       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
929       {
930         if( impl.mDecorator )
931         {
932           value = impl.mDecorator->GetCursorBlinkDuration();
933         }
934         break;
935       }
936       case Toolkit::TextField::Property::CURSOR_WIDTH:
937       {
938         if( impl.mDecorator )
939         {
940           value = impl.mDecorator->GetCursorWidth();
941         }
942         break;
943       }
944       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
945       {
946         if( impl.mDecorator )
947         {
948           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
949           if( image )
950           {
951             value = image.GetUrl();
952           }
953         }
954         break;
955       }
956       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
957       {
958         if( impl.mDecorator )
959         {
960           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
961           if( image )
962           {
963             value = image.GetUrl();
964           }
965         }
966         break;
967       }
968       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
969       {
970         if( impl.mDecorator )
971         {
972           value = impl.mDecorator->GetScrollThreshold();
973         }
974         break;
975       }
976       case Toolkit::TextField::Property::SCROLL_SPEED:
977       {
978         if( impl.mDecorator )
979         {
980           value = impl.mDecorator->GetScrollSpeed();
981         }
982         break;
983       }
984       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
985       {
986         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
987         break;
988       }
989       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
990       {
991         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
992         break;
993       }
994       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
995       {
996         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
997         break;
998       }
999       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1000       {
1001         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1002         break;
1003       }
1004       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1005       {
1006         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1007         break;
1008       }
1009       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1010       {
1011         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1012         break;
1013       }
1014       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1015       {
1016         if( impl.mDecorator )
1017         {
1018           value = impl.mDecorator->GetHighlightColor();
1019         }
1020         break;
1021       }
1022       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1023       {
1024         if( impl.mDecorator )
1025         {
1026           Rect<int> boundingBox;
1027           impl.mDecorator->GetBoundingBox( boundingBox );
1028           value = boundingBox;
1029         }
1030         break;
1031       }
1032       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1033       {
1034         Property::Map map;
1035         impl.mInputMethodOptions.RetrieveProperty( map );
1036         value = map;
1037         break;
1038       }
1039       case Toolkit::TextField::Property::INPUT_COLOR:
1040       {
1041         if( impl.mController )
1042         {
1043           value = impl.mController->GetInputColor();
1044         }
1045         break;
1046       }
1047       case Toolkit::TextField::Property::ENABLE_MARKUP:
1048       {
1049         if( impl.mController )
1050         {
1051           value = impl.mController->IsMarkupProcessorEnabled();
1052         }
1053         break;
1054       }
1055       case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1056       {
1057         if( impl.mController )
1058         {
1059           value = impl.mController->GetInputFontFamily();
1060         }
1061         break;
1062       }
1063       case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1064       {
1065         GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1066         break;
1067       }
1068       case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1069       {
1070         if( impl.mController )
1071         {
1072           value = impl.mController->GetInputFontPointSize();
1073         }
1074         break;
1075       }
1076       case Toolkit::TextField::Property::UNDERLINE:
1077       {
1078         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1079         break;
1080       }
1081       case Toolkit::TextField::Property::INPUT_UNDERLINE:
1082       {
1083         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1084         break;
1085       }
1086       case Toolkit::TextField::Property::SHADOW:
1087       {
1088         GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1089         break;
1090       }
1091       case Toolkit::TextField::Property::INPUT_SHADOW:
1092       {
1093         GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1094         break;
1095       }
1096       case Toolkit::TextField::Property::EMBOSS:
1097       {
1098         GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1099         break;
1100       }
1101       case Toolkit::TextField::Property::INPUT_EMBOSS:
1102       {
1103         GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1104         break;
1105       }
1106       case Toolkit::TextField::Property::OUTLINE:
1107       {
1108         GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1109         break;
1110       }
1111       case Toolkit::TextField::Property::INPUT_OUTLINE:
1112       {
1113         GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1114         break;
1115       }
1116       case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
1117       {
1118         Property::Map map;
1119         impl.mController->GetHiddenInputOption(map);
1120         value = map;
1121         break;
1122       }
1123       case Toolkit::DevelTextField::Property::PIXEL_SIZE:
1124       {
1125         if( impl.mController )
1126         {
1127           value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1128         }
1129         break;
1130       }
1131     } //switch
1132   }
1133
1134   return value;
1135 }
1136
1137 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1138 {
1139   Dali::BaseHandle handle( object );
1140
1141   bool connected( true );
1142   Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1143
1144   if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1145   {
1146     field.TextChangedSignal().Connect( tracker, functor );
1147   }
1148   else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1149   {
1150     field.MaxLengthReachedSignal().Connect( tracker, functor );
1151   }
1152   else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1153   {
1154     field.InputStyleChangedSignal().Connect( tracker, functor );
1155   }
1156   else
1157   {
1158     // signalName does not match any signal
1159     connected = false;
1160   }
1161
1162   return connected;
1163 }
1164
1165 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1166 {
1167   return mTextChangedSignal;
1168 }
1169
1170 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1171 {
1172   return mMaxLengthReachedSignal;
1173 }
1174
1175 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1176 {
1177   return mInputStyleChangedSignal;
1178 }
1179
1180 void TextField::OnInitialize()
1181 {
1182   Actor self = Self();
1183
1184   mController = Text::Controller::New( this, this );
1185
1186   // When using the vector-based rendering, the size of the GLyphs are different
1187   TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1188   mController->SetGlyphType( glyphType );
1189
1190   mDecorator = Text::Decorator::New( *mController,
1191                                      *mController );
1192
1193   mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1194
1195   // Enables the text input.
1196   mController->EnableTextInput( mDecorator );
1197
1198   // Enables the horizontal scrolling after the text input has been enabled.
1199   mController->SetHorizontalScrollEnabled( true );
1200
1201   // Disables the vertical scrolling.
1202   mController->SetVerticalScrollEnabled( false );
1203
1204   // Disable the smooth handle panning.
1205   mController->SetSmoothHandlePanEnabled( false );
1206
1207   mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1208   mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1209
1210   // Forward input events to controller
1211   EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1212   GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1213
1214   mImfManager = ImfManager::Get();
1215
1216   self.TouchSignal().Connect( this, &TextField::OnTouched );
1217
1218   // Set BoundingBox to stage size if not already set.
1219   Rect<int> boundingBox;
1220   mDecorator->GetBoundingBox( boundingBox );
1221
1222   if( boundingBox.IsEmpty() )
1223   {
1224     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1225     mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1226   }
1227
1228   // Flip vertically the 'left' selection handle
1229   mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1230
1231   // Fill-parent area by default
1232   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1233   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1234   self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1235
1236   if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1237   {
1238     EnableClipping();
1239   }
1240 }
1241
1242 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1243 {
1244   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1245
1246   switch ( change )
1247   {
1248     case StyleChange::DEFAULT_FONT_CHANGE:
1249     {
1250       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1251       const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1252       // Property system did not set the font so should update it.
1253       mController->UpdateAfterFontChange( newFont );
1254       RelayoutRequest();
1255       break;
1256     }
1257
1258     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1259     {
1260       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1261       RelayoutRequest();
1262       break;
1263     }
1264     case StyleChange::THEME_CHANGE:
1265     {
1266       // Nothing to do, let control base class handle this
1267       break;
1268     }
1269   }
1270
1271   // Up call to Control
1272   Control::OnStyleChange( styleManager, change );
1273 }
1274
1275 Vector3 TextField::GetNaturalSize()
1276 {
1277   return mController->GetNaturalSize();
1278 }
1279
1280 float TextField::GetHeightForWidth( float width )
1281 {
1282   return mController->GetHeightForWidth( width );
1283 }
1284
1285 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1286 {
1287   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1288
1289   const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1290
1291   if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1292       !mRenderer )
1293   {
1294     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1295
1296     if( mDecorator &&
1297         ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1298     {
1299       mDecorator->Relayout( size );
1300     }
1301
1302     if( !mRenderer )
1303     {
1304       mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1305     }
1306
1307     RenderText( updateTextType );
1308   }
1309
1310   // The text-field emits signals when the input style changes. These changes of style are
1311   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1312   // can't be emitted during the size negotiation as the callbacks may update the UI.
1313   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1314   if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1315   {
1316     if( Adaptor::IsAvailable() )
1317     {
1318       Adaptor& adaptor = Adaptor::Get();
1319
1320       if( NULL == mIdleCallback )
1321       {
1322         // @note: The callback manager takes the ownership of the callback object.
1323         mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1324         adaptor.AddIdle( mIdleCallback );
1325       }
1326     }
1327   }
1328 }
1329
1330 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1331 {
1332   Actor renderableActor;
1333
1334   if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1335   {
1336     if( mRenderer )
1337     {
1338       renderableActor = mRenderer->Render( mController->GetView(),
1339                                            mAlignmentOffset,
1340                                            DepthIndex::CONTENT );
1341     }
1342
1343     if( renderableActor != mRenderableActor )
1344     {
1345       UnparentAndReset( mRenderableActor );
1346       mRenderableActor = renderableActor;
1347     }
1348   }
1349
1350   if( mRenderableActor )
1351   {
1352     const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1353
1354     mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1355
1356     // Make sure the actors are parented correctly with/without clipping
1357     Actor self = mStencil ? mStencil : Self();
1358
1359     for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1360            endIt = mClippingDecorationActors.end();
1361          it != endIt;
1362          ++it )
1363     {
1364       self.Add( *it );
1365     }
1366     mClippingDecorationActors.clear();
1367
1368     self.Add( mRenderableActor );
1369   }
1370 }
1371
1372 void TextField::OnKeyInputFocusGained()
1373 {
1374   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1375
1376   mImfManager.ApplyOptions( mInputMethodOptions );
1377
1378   mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1379
1380   mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1381
1382   // Notify that the text editing start.
1383   mImfManager.Activate();
1384
1385   // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1386   mImfManager.SetRestoreAfterFocusLost( true );
1387
1388    ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1389
1390    if ( notifier )
1391    {
1392       notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1393    }
1394
1395   mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1396
1397   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1398 }
1399
1400 void TextField::OnKeyInputFocusLost()
1401 {
1402   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1403
1404   mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1405   // The text editing is finished. Therefore the imf manager don't have restore activation.
1406   mImfManager.SetRestoreAfterFocusLost( false );
1407
1408   // Notify that the text editing finish.
1409   mImfManager.Deactivate();
1410
1411   mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1412
1413   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1414
1415   if ( notifier )
1416   {
1417     notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1418   }
1419
1420   mController->KeyboardFocusLostEvent();
1421
1422   EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1423 }
1424
1425 void TextField::OnTap( const TapGesture& gesture )
1426 {
1427   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1428
1429   mImfManager.Activate();
1430
1431   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1432   mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1433
1434   SetKeyInputFocus();
1435 }
1436
1437 void TextField::OnPan( const PanGesture& gesture )
1438 {
1439   mController->PanEvent( gesture.state, gesture.displacement );
1440 }
1441
1442 void TextField::OnLongPress( const LongPressGesture& gesture )
1443 {
1444   mImfManager.Activate();
1445
1446   mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1447
1448   SetKeyInputFocus();
1449 }
1450
1451 bool TextField::OnKeyEvent( const KeyEvent& event )
1452 {
1453   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1454
1455   if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1456   {
1457     // Make sure ClearKeyInputFocus when only key is up
1458     if( event.state == KeyEvent::Up )
1459     {
1460       ClearKeyInputFocus();
1461     }
1462
1463     return true;
1464   }
1465
1466   return mController->KeyEvent( event );
1467 }
1468
1469 void TextField::RequestTextRelayout()
1470 {
1471   RelayoutRequest();
1472 }
1473
1474 void TextField::TextChanged()
1475 {
1476   Dali::Toolkit::TextField handle( GetOwner() );
1477   mTextChangedSignal.Emit( handle );
1478 }
1479
1480 void TextField::MaxLengthReached()
1481 {
1482   Dali::Toolkit::TextField handle( GetOwner() );
1483   mMaxLengthReachedSignal.Emit( handle );
1484 }
1485
1486 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1487 {
1488   Dali::Toolkit::TextField handle( GetOwner() );
1489
1490   Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1491
1492   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1493   {
1494     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1495   }
1496   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1497   {
1498     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1499   }
1500   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1501   {
1502     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1503   }
1504   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1505   {
1506     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1507   }
1508   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1509   {
1510     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1511   }
1512   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1513   {
1514     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1515   }
1516   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1517   {
1518     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1519   }
1520   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1521   {
1522     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1523   }
1524   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1525   {
1526     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1527   }
1528   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1529   {
1530     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1531   }
1532
1533   mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1534 }
1535
1536 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1537 {
1538   if( actor )
1539   {
1540     if( needsClipping )
1541     {
1542       mClippingDecorationActors.push_back( actor );
1543     }
1544     else
1545     {
1546       Self().Add( actor );
1547     }
1548   }
1549 }
1550
1551 void TextField::OnStageConnect( Dali::Actor actor )
1552 {
1553   if ( mHasBeenStaged )
1554   {
1555     RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1556   }
1557   else
1558   {
1559     mHasBeenStaged = true;
1560   }
1561 }
1562
1563 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1564 {
1565   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1566   return mController->OnImfEvent( imfManager, imfEvent );
1567 }
1568
1569 void TextField::GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1570 {
1571   if( mDecorator )
1572   {
1573     ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1574
1575     if ( image )
1576     {
1577       Property::Map map;
1578       Scripting::CreatePropertyMap( image, map );
1579       value = map;
1580     }
1581   }
1582 }
1583
1584 void TextField::EnableClipping()
1585 {
1586   if( !mStencil )
1587   {
1588     // Creates an extra control to be used as stencil buffer.
1589     mStencil = Control::New();
1590     mStencil.SetAnchorPoint( AnchorPoint::CENTER );
1591     mStencil.SetParentOrigin( ParentOrigin::CENTER );
1592
1593     // Creates a background visual. Even if the color is transparent it updates the stencil.
1594     mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1595                           Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ).
1596                           Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1597
1598     // Enable the clipping property.
1599     mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1600     mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1601
1602     Self().Add( mStencil );
1603   }
1604 }
1605
1606 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1607 {
1608   mController->PasteClipboardItemEvent();
1609 }
1610
1611 void TextField::KeyboardStatusChanged(bool keyboardShown)
1612 {
1613   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1614
1615   // Just hide the grab handle when keyboard is hidden.
1616   if (!keyboardShown )
1617   {
1618     mController->KeyboardFocusLostEvent();
1619   }
1620   else
1621   {
1622     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1623   }
1624 }
1625
1626 void TextField::OnStageConnection( int depth )
1627 {
1628   // Sets the depth to the visuals inside the text's decorator.
1629   mDecorator->SetTextDepth( depth );
1630
1631   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1632
1633   // Call the Control::OnStageConnection() to set the depth of the background.
1634   Control::OnStageConnection( depth );
1635 }
1636
1637 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1638 {
1639   return true;
1640 }
1641
1642 void TextField::OnIdleSignal()
1643 {
1644   // Emits the change of input style signals.
1645   mController->ProcessInputStyleChangedSignals();
1646
1647   // Set the pointer to null as the callback manager deletes the callback after execute it.
1648   mIdleCallback = NULL;
1649 }
1650
1651 TextField::TextField()
1652 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1653   mIdleCallback( NULL ),
1654   mAlignmentOffset( 0.f ),
1655   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1656   mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1657   mHasBeenStaged( false )
1658 {
1659 }
1660
1661 TextField::~TextField()
1662 {
1663   UnparentAndReset( mStencil );
1664
1665   if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1666   {
1667     Adaptor::Get().RemoveIdle( mIdleCallback );
1668   }
1669 }
1670
1671 } // namespace Internal
1672
1673 } // namespace Toolkit
1674
1675 } // namespace Dali