#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/scripting/scripting.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/adaptor-framework/virtual-keyboard.h>
namespace
{
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::HorizontalAlignment > HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
+{
+ { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
+ { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
+ { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
+};
+const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
+
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::VerticalAlignment > VERTICAL_ALIGNMENT_STRING_TABLE[] =
+{
+ { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
+ { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
+ { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
+};
+const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
+
// Type registration
BaseHandle Create()
{
// Setup properties, signals and actions using the type-registry.
DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
-DALI_PROPERTY_REGISTRATION( TextField, "rendering-backend", INTEGER, RENDERING_BACKEND )
-DALI_PROPERTY_REGISTRATION( TextField, "placeholder-text", STRING, PLACEHOLDER_TEXT )
-DALI_PROPERTY_REGISTRATION( TextField, "text", STRING, TEXT )
-DALI_PROPERTY_REGISTRATION( TextField, "font-family", STRING, FONT_FAMILY )
-DALI_PROPERTY_REGISTRATION( TextField, "font-style", STRING, FONT_STYLE )
-DALI_PROPERTY_REGISTRATION( TextField, "point-size", FLOAT, POINT_SIZE )
-DALI_PROPERTY_REGISTRATION( TextField, "exceed-policy", INTEGER, EXCEED_POLICY )
-DALI_PROPERTY_REGISTRATION( TextField, "cursor-image", STRING, CURSOR_IMAGE )
-DALI_PROPERTY_REGISTRATION( TextField, "primary-cursor-color", VECTOR4, PRIMARY_CURSOR_COLOR )
-DALI_PROPERTY_REGISTRATION( TextField, "secondary-cursor-color", VECTOR4, SECONDARY_CURSOR_COLOR )
-DALI_PROPERTY_REGISTRATION( TextField, "enable-cursor-blink", BOOLEAN, ENABLE_CURSOR_BLINK )
-DALI_PROPERTY_REGISTRATION( TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL )
-DALI_PROPERTY_REGISTRATION( TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION )
-DALI_PROPERTY_REGISTRATION( TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE )
-DALI_PROPERTY_REGISTRATION( TextField, "decoration bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend", INTEGER, RENDERING_BACKEND )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text", STRING, PLACEHOLDER_TEXT )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family", STRING, FONT_FAMILY )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style", STRING, FONT_STYLE )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size", FLOAT, POINT_SIZE )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy", INTEGER, EXCEED_POLICY )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color", VECTOR4, TEXT_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset", VECTOR2, SHADOW_OFFSET )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color", VECTOR4, SHADOW_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color", VECTOR4, PRIMARY_CURSOR_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color", VECTOR4, SECONDARY_CURSOR_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink", BOOLEAN, ENABLE_CURSOR_BLINK )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image", VECTOR4, GRAB_HANDLE_PRESSED_IMAGE )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold", FLOAT, SCROLL_THRESHOLD )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed", FLOAT, SCROLL_SPEED )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left", STRING, SELECTION_HANDLE_IMAGE_LEFT )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right", STRING, SELECTION_HANDLE_IMAGE_RIGHT )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left", STRING, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", STRING, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color", STRING, SELECTION_HIGHLIGHT_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
DALI_TYPE_REGISTRATION_END()
{
float pointSize = value.Get< float >();
- if( impl.mController->GetDefaultPointSize() != pointSize /*TODO - epsilon*/ )
+ if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
{
impl.mController->SetDefaultPointSize( pointSize );
impl.RequestTextRelayout();
impl.mExceedPolicy = value.Get< int >();
break;
}
- case Toolkit::TextField::Property::CURSOR_IMAGE:
+ case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
{
- ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+ LayoutEngine& engine = impl.mController->GetLayoutEngine();
+ const LayoutEngine::HorizontalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::HorizontalAlignment >( value.Get< std::string >().c_str(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
- if( impl.mDecorator )
+ if( engine.GetHorizontalAlignment() != alignment )
+ {
+ engine.SetHorizontalAlignment( alignment );
+ impl.RequestTextRelayout();
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
+ {
+ LayoutEngine& engine = impl.mController->GetLayoutEngine();
+ const LayoutEngine::VerticalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::VerticalAlignment >( value.Get< std::string >().c_str(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
+
+ if( engine.GetVerticalAlignment() != alignment )
+ {
+ engine.SetVerticalAlignment( alignment );
+ impl.RequestTextRelayout();
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::TEXT_COLOR:
+ {
+ if ( impl.mController )
+ {
+ Vector4 textColor = value.Get< Vector4 >();
+ if ( impl.mController->GetTextColor() != textColor )
+ {
+ impl.mController->SetTextColor( textColor );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SHADOW_OFFSET:
+ {
+ if( impl.mController )
+ {
+ Vector2 shadowOffset = value.Get< Vector2 >();
+ if ( impl.mController->GetShadowOffset() != shadowOffset )
+ {
+ impl.mController->SetShadowOffset( shadowOffset );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SHADOW_COLOR:
+ {
+ if( impl.mController )
{
- impl.mDecorator->SetCursorImage( image );
+ Vector4 shadowColor = value.Get< Vector4 >();
+ if ( impl.mController->GetShadowColor() != shadowColor )
+ {
+ impl.mController->SetShadowColor( shadowColor );
+ impl.RequestTextRelayout();
+ }
}
break;
}
if( impl.mDecorator )
{
- impl.mDecorator->SetGrabHandleImage( image );
+ impl.mDecorator->SetGrabHandleImage( GRAB_HANDLE_IMAGE_RELEASED, image );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+
+ if( impl.mDecorator )
+ {
+ impl.mDecorator->SetGrabHandleImage( GRAB_HANDLE_IMAGE_PRESSED, image );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SCROLL_THRESHOLD:
+ {
+ float threshold = value.Get< float >();
+
+ if( impl.mDecorator )
+ {
+ impl.mDecorator->SetScrollThreshold( threshold );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SCROLL_SPEED:
+ {
+ float speed = value.Get< float >();
+
+ if( impl.mDecorator )
+ {
+ impl.mDecorator->SetScrollSpeed( speed );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+
+ if( impl.mDecorator )
+ {
+ impl.mDecorator->SetLeftSelectionImage( SELECTION_HANDLE_RELEASED, image );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+
+ if( impl.mDecorator )
+ {
+ impl.mDecorator->SetRightSelectionImage( SELECTION_HANDLE_RELEASED, image );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+
+ if( impl.mDecorator )
+ {
+ impl.mDecorator->SetLeftSelectionImage( SELECTION_HANDLE_PRESSED, image );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
+ {
+ ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+
+ if( impl.mDecorator )
+ {
+ impl.mDecorator->SetLeftSelectionImage( SELECTION_HANDLE_PRESSED, image );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
+ {
+ Vector4 color = value.Get< Vector4 >();
+
+ if( impl.mDecorator )
+ {
+ impl.mDecorator->SetHighlightColor( color );
}
break;
}
}
break;
}
- }
- }
+ } // switch
+ } // textfield
}
Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
value = impl.mExceedPolicy;
break;
}
- case Toolkit::TextField::Property::CURSOR_IMAGE:
+ case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
{
- if( impl.mDecorator )
+ if( impl.mController )
{
- ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetCursorImage() );
- if( image )
- {
- value = image.GetUrl();
- }
+ value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
+ {
+ if( impl.mController )
+ {
+ value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) );
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::TEXT_COLOR:
+ {
+ if ( impl.mController )
+ {
+ value = impl.mController->GetTextColor();
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SHADOW_OFFSET:
+ {
+ if ( impl.mController )
+ {
+ value = impl.mController->GetShadowOffset();
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SHADOW_COLOR:
+ {
+ if ( impl.mController )
+ {
+ value = impl.mController->GetShadowColor();
}
break;
}
{
if( impl.mDecorator )
{
- ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetCursorImage() );
+ ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetGrabHandleImage( GRAB_HANDLE_IMAGE_RELEASED ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
+ {
+ if( impl.mDecorator )
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetGrabHandleImage( GRAB_HANDLE_IMAGE_PRESSED ) );
if( image )
{
value = image.GetUrl();
}
break;
}
+ case Toolkit::TextField::Property::SCROLL_THRESHOLD:
+ {
+ if( impl.mDecorator )
+ {
+ value = impl.mDecorator->GetScrollThreshold();
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SCROLL_SPEED:
+ {
+ if( impl.mDecorator )
+ {
+ value = impl.mDecorator->GetScrollSpeed();
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
+ {
+ if( impl.mDecorator )
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetLeftSelectionImage( SELECTION_HANDLE_RELEASED ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
+ {
+ if( impl.mDecorator )
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetRightSelectionImage( SELECTION_HANDLE_RELEASED ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
+ {
+ if( impl.mDecorator )
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetLeftSelectionImage( SELECTION_HANDLE_PRESSED ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
+ {
+ if( impl.mDecorator )
+ {
+ ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetRightSelectionImage( SELECTION_HANDLE_PRESSED ) );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
+ {
+ if( impl.mDecorator )
+ {
+ value = impl.mDecorator->GetHighlightColor();
+ }
+ break;
+ }
case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
{
if( impl.mDecorator )
}
break;
}
- }
+ } //switch
}
return value;
void TextField::OnInitialize()
{
+ Actor self = Self();
+
mController = Text::Controller::New( *this );
mDecorator = Text::Decorator::New( *this, *mController );
// Forward input events to controller
EnableGestureDetection(Gesture::Tap);
GetTapGestureDetector().SetMaximumTapsRequired( 2 );
+ EnableGestureDetection(Gesture::Pan);
// Set BoundingBox to stage size if not already set.
if ( mDecorator->GetBoundingBox().IsEmpty() )
Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
}
+
+ // Fill-parent area by default
+ self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+ self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
}
void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
return mController->GetHeightForWidth( width );
}
-void TextField::OnRelayout( const Vector2& size, ActorSizeContainer& container )
+void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
{
if( mController->Relayout( size ) ||
!mRenderer )
if( mRenderableActor )
{
+ const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
+
+ mRenderableActor.SetPosition( offset.x, offset.y );
+
// Make sure the actor is parented correctly with/without clipping
if( mClipper )
{
}
mController->KeyboardFocusGainEvent();
+
+ EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
}
void TextField::OnKeyInputFocusLost()
}
mController->KeyboardFocusLostEvent();
+
+ EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
}
void TextField::OnTap( const TapGesture& gesture )
mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
}
+void TextField::OnPan( const PanGesture& gesture )
+{
+ mController->PanEvent( gesture.state, gesture.displacement );
+}
+
bool TextField::OnKeyEvent( const KeyEvent& event )
{
if( Dali::DALI_KEY_ESCAPE == event.keyCode )
return mController->KeyEvent( event );
}
-ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
+ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
{
switch ( imfEvent.eventName )
{
- case ImfManager::PREEDIT:
- {
- // TODO
- break;
- }
case ImfManager::COMMIT:
{
- // TODO
+ KeyEvent event( "", imfEvent.predictiveString, 0, 0, 0, KeyEvent::Down );
+ mController->KeyEvent( event );
break;
}
+ case ImfManager::PREEDIT: // fall through
case ImfManager::DELETESURROUNDING:
- {
- // TODO
- break;
- }
case ImfManager::GETSURROUNDING:
- {
- // TODO
- break;
- }
case ImfManager::VOID:
{
// do nothing