2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/text-controls/text-editor-impl.h>
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/devel-api/object/type-registry-helper.h>
29 #include <dali/integration-api/debug.h>
32 #include <dali-toolkit/public-api/text/rendering-backend.h>
33 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
34 #include <dali-toolkit/internal/text/rendering/text-backend.h>
35 #include <dali-toolkit/internal/text/text-font-style.h>
36 #include <dali-toolkit/internal/text/text-view.h>
37 #include <dali-toolkit/internal/styling/style-manager-impl.h>
39 using namespace Dali::Toolkit::Text;
50 namespace // unnamed namespace
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
57 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
58 } // unnamed namespace
63 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
65 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
66 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
67 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
69 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
74 return Toolkit::TextEditor::New();
77 // Setup properties, signals and actions using the type-registry.
78 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextEditor, Toolkit::Control, Create );
80 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "text", STRING, TEXT )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontStyle", STRING, FONT_STYLE )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontStyle", STRING, INPUT_FONT_STYLE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
111 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
113 DALI_TYPE_REGISTRATION_END()
117 Toolkit::TextEditor TextEditor::New()
119 // Create the implementation, temporarily owned by this handle on stack
120 IntrusivePtr< TextEditor > impl = new TextEditor();
122 // Pass ownership to CustomActor handle
123 Toolkit::TextEditor handle( *impl );
125 // Second-phase init of the implementation
126 // This can only be done after the CustomActor connection has been made...
132 void TextEditor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
134 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
136 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
141 TextEditor& impl( GetImpl( textEditor ) );
145 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
147 int backend = value.Get< int >();
148 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
150 if( impl.mRenderingBackend != backend )
152 impl.mRenderingBackend = backend;
153 impl.mRenderer.Reset();
154 impl.RequestTextRelayout();
158 case Toolkit::TextEditor::Property::TEXT:
160 if( impl.mController )
162 const std::string text = value.Get< std::string >();
163 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT %s\n", impl.mController.Get(), text.c_str() );
165 impl.mController->SetText( text );
169 case Toolkit::TextEditor::Property::TEXT_COLOR:
171 if( impl.mController )
173 const Vector4 textColor = value.Get< Vector4 >();
174 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 );
176 if( impl.mController->GetTextColor() != textColor )
178 impl.mController->SetTextColor( textColor );
179 impl.mController->SetInputColor( textColor );
180 impl.mRenderer.Reset();
185 case Toolkit::TextEditor::Property::FONT_FAMILY:
187 if( impl.mController )
189 const std::string fontFamily = value.Get< std::string >();
190 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
191 impl.mController->SetDefaultFontFamily( fontFamily );
195 case Toolkit::TextEditor::Property::FONT_STYLE:
197 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
200 case Toolkit::TextEditor::Property::POINT_SIZE:
202 if( impl.mController )
204 const float pointSize = value.Get< float >();
205 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
207 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
209 impl.mController->SetDefaultPointSize( pointSize );
214 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
216 if( impl.mController )
218 const std::string alignStr = value.Get< std::string >();
219 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
221 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
222 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
223 HORIZONTAL_ALIGNMENT_STRING_TABLE,
224 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
227 impl.mController->SetHorizontalAlignment( alignment );
232 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
234 const float threshold = value.Get< float >();
235 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
237 if( impl.mDecorator )
239 impl.mDecorator->SetScrollThreshold( threshold );
243 case Toolkit::TextEditor::Property::SCROLL_SPEED:
245 const float speed = value.Get< float >();
246 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
248 if( impl.mDecorator )
250 impl.mDecorator->SetScrollSpeed( speed );
254 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
256 if( impl.mDecorator )
258 const Vector4 color = value.Get< Vector4 >();
259 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 );
261 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
262 impl.RequestTextRelayout();
266 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
268 if( impl.mDecorator )
270 const Vector4 color = value.Get< Vector4 >();
271 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 );
273 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
274 impl.RequestTextRelayout();
278 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
280 if( impl.mController )
282 const bool enable = value.Get< bool >();
283 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
285 impl.mController->SetEnableCursorBlink( enable );
286 impl.RequestTextRelayout();
290 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
292 if( impl.mDecorator )
294 const float interval = value.Get< float >();
295 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
297 impl.mDecorator->SetCursorBlinkInterval( interval );
301 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
303 if( impl.mDecorator )
305 const float duration = value.Get< float >();
306 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
308 impl.mDecorator->SetCursorBlinkDuration( duration );
312 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
314 if( impl.mDecorator )
316 const int width = value.Get< int >();
317 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
319 impl.mDecorator->SetCursorWidth( width );
320 impl.mController->GetLayoutEngine().SetCursorWidth( width );
324 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
326 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
327 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
329 if( impl.mDecorator )
331 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
332 impl.RequestTextRelayout();
336 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
338 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
339 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
341 if( impl.mDecorator )
343 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
344 impl.RequestTextRelayout();
348 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
350 const Image image = Scripting::NewImage( value );
352 if( impl.mDecorator && image )
354 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
355 impl.RequestTextRelayout();
359 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
361 const Image image = Scripting::NewImage( value );
363 if( impl.mDecorator && image )
365 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
366 impl.RequestTextRelayout();
370 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
372 const Image image = Scripting::NewImage( value );
374 if( impl.mDecorator && image )
376 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
377 impl.RequestTextRelayout();
381 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
383 const Image image = Scripting::NewImage( value );
385 if( impl.mDecorator && image )
387 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
388 impl.RequestTextRelayout();
392 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
394 const Image image = Scripting::NewImage( value );
396 if( impl.mDecorator && image )
398 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
399 impl.RequestTextRelayout();
403 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
405 const Image image = Scripting::NewImage( value );
407 if( impl.mDecorator && image )
409 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
410 impl.RequestTextRelayout();
414 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
416 const Vector4 color = value.Get< Vector4 >();
417 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 );
419 if( impl.mDecorator )
421 impl.mDecorator->SetHighlightColor( color );
422 impl.RequestTextRelayout();
426 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
428 if( impl.mDecorator )
430 const Rect<int> box = value.Get< Rect<int> >();
431 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 );
433 impl.mDecorator->SetBoundingBox( box );
434 impl.RequestTextRelayout();
438 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
440 if( impl.mController )
442 const bool enableMarkup = value.Get<bool>();
443 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
445 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
449 case Toolkit::TextEditor::Property::INPUT_COLOR:
451 if( impl.mController )
453 const Vector4 inputColor = value.Get< Vector4 >();
454 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 );
456 impl.mController->SetInputColor( inputColor );
460 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
462 if( impl.mController )
464 const std::string fontFamily = value.Get< std::string >();
465 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
466 impl.mController->SetInputFontFamily( fontFamily );
470 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
472 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
475 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
477 if( impl.mController )
479 const float pointSize = value.Get< float >();
480 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
481 impl.mController->SetInputFontPointSize( pointSize );
489 Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index index )
491 Property::Value value;
493 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
497 TextEditor& impl( GetImpl( textEditor ) );
501 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
503 value = impl.mRenderingBackend;
506 case Toolkit::TextEditor::Property::TEXT:
508 if( impl.mController )
511 impl.mController->GetText( text );
512 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p returning text: %s\n", impl.mController.Get(), text.c_str() );
517 case Toolkit::TextEditor::Property::TEXT_COLOR:
519 if ( impl.mController )
521 value = impl.mController->GetTextColor();
525 case Toolkit::TextEditor::Property::FONT_FAMILY:
527 if( impl.mController )
529 value = impl.mController->GetDefaultFontFamily();
533 case Toolkit::TextEditor::Property::FONT_STYLE:
535 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
538 case Toolkit::TextEditor::Property::POINT_SIZE:
540 if( impl.mController )
542 value = impl.mController->GetDefaultPointSize();
546 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
548 if( impl.mController )
550 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
551 HORIZONTAL_ALIGNMENT_STRING_TABLE,
552 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
555 value = std::string( name );
560 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
562 if( impl.mDecorator )
564 value = impl.mDecorator->GetScrollThreshold();
568 case Toolkit::TextEditor::Property::SCROLL_SPEED:
570 if( impl.mDecorator )
572 value = impl.mDecorator->GetScrollSpeed();
576 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
578 if( impl.mDecorator )
580 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
584 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
586 if( impl.mDecorator )
588 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
592 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
594 value = impl.mController->GetEnableCursorBlink();
597 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
599 if( impl.mDecorator )
601 value = impl.mDecorator->GetCursorBlinkInterval();
605 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
607 if( impl.mDecorator )
609 value = impl.mDecorator->GetCursorBlinkDuration();
613 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
615 if( impl.mDecorator )
617 value = impl.mDecorator->GetCursorWidth();
621 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
623 if( impl.mDecorator )
625 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
628 value = image.GetUrl();
633 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
635 if( impl.mDecorator )
637 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
640 value = image.GetUrl();
645 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
647 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
650 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
652 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
655 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
657 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
660 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
662 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
665 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
667 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
670 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
672 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
675 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
677 if( impl.mDecorator )
679 value = impl.mDecorator->GetHighlightColor();
683 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
685 if( impl.mDecorator )
687 Rect<int> boundingBox;
688 impl.mDecorator->GetBoundingBox( boundingBox );
693 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
695 if( impl.mController )
697 value = impl.mController->IsMarkupProcessorEnabled();
701 case Toolkit::TextEditor::Property::INPUT_COLOR:
703 if( impl.mController )
705 value = impl.mController->GetInputColor();
709 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
711 if( impl.mController )
713 value = impl.mController->GetInputFontFamily();
717 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
719 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
722 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
724 if( impl.mController )
726 value = impl.mController->GetInputFontPointSize();
736 bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
738 Dali::BaseHandle handle( object );
740 bool connected( true );
741 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast( handle );
743 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
745 editor.TextChangedSignal().Connect( tracker, functor );
749 // signalName does not match any signal
756 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
758 return mTextChangedSignal;
761 void TextEditor::OnInitialize()
765 mController = Text::Controller::New( *this );
767 mDecorator = Text::Decorator::New( *mController,
770 mController->GetLayoutEngine().SetLayout( LayoutEngine::MULTI_LINE_BOX );
772 mController->EnableTextInput( mDecorator );
774 mController->SetMaximumNumberOfCharacters( std::numeric_limits<Length>::max() );
776 // Forward input events to controller
777 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
778 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
780 self.TouchedSignal().Connect( this, &TextEditor::OnTouched );
782 // Set BoundingBox to stage size if not already set.
783 Rect<int> boundingBox;
784 mDecorator->GetBoundingBox( boundingBox );
786 if( boundingBox.IsEmpty() )
788 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
789 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
792 // Flip vertically the 'left' selection handle
793 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
795 // Fill-parent area by default
796 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
797 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
798 self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
801 void TextEditor::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
803 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
807 case StyleChange::DEFAULT_FONT_CHANGE:
809 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
810 std::string newFont = styleManager.GetDefaultFontFamily();
811 // Property system did not set the font so should update it.
812 mController->UpdateAfterFontChange( newFont );
816 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
818 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
820 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
822 // Property system did not set the PointSize so should update it.
823 // todo instruct text-controller to update model
827 case StyleChange::THEME_CHANGE:
829 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
835 Vector3 TextEditor::GetNaturalSize()
837 return mController->GetNaturalSize();
840 float TextEditor::GetHeightForWidth( float width )
842 return mController->GetHeightForWidth( width );
845 void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container )
847 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
849 if( mController->Relayout( size ) ||
852 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get() );
856 mDecorator->Relayout( size );
861 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
864 EnableClipping( true, size );
869 void TextEditor::RenderText()
872 Actor renderableActor;
875 renderableActor = mRenderer->Render( mController->GetView(), DepthIndex::TEXT );
878 if( renderableActor != mRenderableActor )
880 UnparentAndReset( mRenderableActor );
881 mRenderableActor = renderableActor;
884 if( mRenderableActor )
886 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
888 mRenderableActor.SetPosition( offset.x, offset.y );
893 clipRootActor = mClipper->GetRootActor();
896 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
897 endIt = mClippingDecorationActors.end();
905 clipRootActor.Add( actor );
912 mClippingDecorationActors.clear();
914 // Make sure the actor is parented correctly with/without clipping
917 clipRootActor.Add( mRenderableActor );
921 self.Add( mRenderableActor );
926 void TextEditor::OnKeyInputFocusGained()
928 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() );
930 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
932 ImfManager imfManager = ImfManager::Get();
936 imfManager.EventReceivedSignal().Connect( this, &TextEditor::OnImfEvent );
938 // Notify that the text editing start.
939 imfManager.Activate();
941 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
942 imfManager.SetRestoreAfterFocusLost( true );
945 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
949 notifier.ContentSelectedSignal().Connect( this, &TextEditor::OnClipboardTextSelected );
952 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
954 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
957 void TextEditor::OnKeyInputFocusLost()
959 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get() );
961 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextEditor::KeyboardStatusChanged );
963 ImfManager imfManager = ImfManager::Get();
966 // The text editing is finished. Therefore the imf manager don't have restore activation.
967 imfManager.SetRestoreAfterFocusLost( false );
969 // Notify that the text editing finish.
970 imfManager.Deactivate();
972 imfManager.EventReceivedSignal().Disconnect( this, &TextEditor::OnImfEvent );
975 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
979 notifier.ContentSelectedSignal().Disconnect( this, &TextEditor::OnClipboardTextSelected );
982 mController->KeyboardFocusLostEvent();
984 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
987 void TextEditor::OnTap( const TapGesture& gesture )
989 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() );
991 // Show the keyboard if it was hidden.
992 if (!VirtualKeyboard::IsVisible())
994 VirtualKeyboard::Show();
997 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
998 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1003 void TextEditor::OnPan( const PanGesture& gesture )
1005 mController->PanEvent( gesture.state, gesture.displacement );
1008 void TextEditor::OnLongPress( const LongPressGesture& gesture )
1010 // Show the keyboard if it was hidden.
1011 if (!VirtualKeyboard::IsVisible())
1013 VirtualKeyboard::Show();
1016 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1021 bool TextEditor::OnKeyEvent( const KeyEvent& event )
1023 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1025 if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1027 ClearKeyInputFocus();
1031 return mController->KeyEvent( event );
1034 void TextEditor::AddDecoration( Actor& actor, bool needsClipping )
1040 mClippingDecorationActors.push_back( actor );
1044 Self().Add( actor );
1049 void TextEditor::RequestTextRelayout()
1054 void TextEditor::TextChanged()
1056 Dali::Toolkit::TextEditor handle( GetOwner() );
1057 mTextChangedSignal.Emit( handle );
1060 void TextEditor::MaxLengthReached()
1062 // Nothing to do as TextEditor doesn't emit a max length reached signal.
1065 void TextEditor::OnStageConnect( Dali::Actor actor )
1067 if ( mHasBeenStaged )
1073 mHasBeenStaged = true;
1077 ImfManager::ImfCallbackData TextEditor::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1079 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1080 return mController->OnImfEvent( imfManager, imfEvent );
1083 void TextEditor::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1087 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1092 Scripting::CreatePropertyMap( image, map );
1098 void TextEditor::EnableClipping( bool clipping, const Vector2& size )
1102 // Not worth to created clip actor if width or height is equal to zero.
1103 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1107 Actor self = Self();
1109 mClipper = Clipper::New( size );
1110 self.Add( mClipper->GetRootActor() );
1111 self.Add( mClipper->GetImageActor() );
1113 else if ( mClipper )
1115 mClipper->Refresh( size );
1121 // Note - this will automatically remove the root & image actors
1126 void TextEditor::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1128 mController->PasteClipboardItemEvent();
1131 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1133 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1135 // Just hide the grab handle when keyboard is hidden.
1136 if (!keyboardShown )
1138 mController->KeyboardFocusLostEvent();
1142 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1146 void TextEditor::OnStageConnection( int depth )
1148 // Call the Control::OnStageConnection() to set the depth of the background.
1149 Control::OnStageConnection( depth );
1151 // Sets the depth to the renderers inside the text's decorator.
1152 mDecorator->SetTextDepth( depth );
1154 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1157 bool TextEditor::OnTouched( Actor actor, const TouchEvent& event )
1162 TextEditor::TextEditor()
1163 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1164 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1165 mHasBeenStaged( false )
1169 TextEditor::~TextEditor()
1174 } // namespace Internal
1176 } // namespace Toolkit