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