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