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