X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-controls%2Ftext-field-impl.cpp;h=f17ea34f6c1ed61ce79276eecb1b64da0ddb40f0;hp=fabfc7d9b8f186a41180cd335267112e53bea60c;hb=ded71874c72f72de672b8df770b4983a5d846944;hpb=6f62c2545af5b288bf447c380ccfb562cc7a4370 diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index fabfc7d..f17ea34 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -53,6 +54,22 @@ namespace 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() { @@ -69,15 +86,15 @@ DALI_PROPERTY_REGISTRATION( TextField, "font-family", STRING, FON 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( TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX ) +DALI_PROPERTY_REGISTRATION( TextField, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT ) +DALI_PROPERTY_REGISTRATION( TextField, "vertical-alignment", STRING, VERTICAL_ALIGNMENT ) DALI_TYPE_REGISTRATION_END() } // namespace @@ -181,16 +198,6 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr impl.mExceedPolicy = value.Get< int >(); break; } - case Toolkit::TextField::Property::CURSOR_IMAGE: - { - ResourceImage image = ResourceImage::New( value.Get< std::string >() ); - - if( impl.mDecorator ) - { - impl.mDecorator->SetCursorImage( image ); - } - break; - } case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR: { if( impl.mDecorator ) @@ -249,8 +256,36 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } - } - } + case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT: + { + 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( 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; + } + } // switch + } // textfield } Property::Value TextField::GetProperty( BaseObject* object, Property::Index index ) @@ -295,18 +330,6 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde value = impl.mExceedPolicy; break; } - case Toolkit::TextField::Property::CURSOR_IMAGE: - { - if( impl.mDecorator ) - { - ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetCursorImage() ); - if( image ) - { - value = image.GetUrl(); - } - } - break; - } case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR: { if( impl.mDecorator ) @@ -344,27 +367,35 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde } break; } - case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE: + case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX: { if( impl.mDecorator ) { - ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetCursorImage() ); - if( image ) - { - value = image.GetUrl(); - } + value = impl.mDecorator->GetBoundingBox(); } break; } - case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX: + case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT: { - if( impl.mDecorator ) + if( impl.mController ) { - value = impl.mDecorator->GetBoundingBox(); + 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; + } + } //switch } return value; @@ -372,6 +403,8 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde void TextField::OnInitialize() { + Actor self = Self(); + mController = Text::Controller::New( *this ); mDecorator = Text::Decorator::New( *this, *mController ); @@ -383,6 +416,7 @@ void TextField::OnInitialize() // 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() ) @@ -390,6 +424,10 @@ void TextField::OnInitialize() Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); mDecorator->SetBoundingBox( Rect( 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 ) @@ -407,14 +445,19 @@ float TextField::GetHeightForWidth( float width ) 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 ) { + const Vector2& scrollPosition = mController->GetScrollPosition(); + const Vector2& alignmentOffset = mController->GetAlignmentOffset(); + + Vector2 offset = scrollPosition + alignmentOffset; + if( mDecorator ) { - mDecorator->Relayout( size ); + mDecorator->Relayout( size, offset ); } if( !mRenderer ) @@ -438,6 +481,8 @@ void TextField::OnRelayout( const Vector2& size, ActorSizeContainer& container ) if( mRenderableActor ) { + mRenderableActor.SetPosition( offset.x, offset.y ); + // Make sure the actor is parented correctly with/without clipping if( mClipper ) { @@ -455,6 +500,19 @@ void TextField::OnKeyInputFocusGained() { VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged ); + ImfManager imfManager = ImfManager::Get(); + + if ( imfManager ) + { + imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent ); + + // Notify that the text editing start. + imfManager.Activate(); + + // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated. + imfManager.SetRestoreAfterFocusLost( true ); + } + mController->KeyboardFocusGainEvent(); } @@ -462,6 +520,18 @@ void TextField::OnKeyInputFocusLost() { VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged ); + ImfManager imfManager = ImfManager::Get(); + if ( imfManager ) + { + // The text editing is finished. Therefore the imf manager don't have restore activation. + imfManager.SetRestoreAfterFocusLost( false ); + + // Notify that the text editing finish. + imfManager.Deactivate(); + + imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent ); + } + mController->KeyboardFocusLostEvent(); } @@ -478,6 +548,11 @@ 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 ) @@ -488,6 +563,28 @@ bool TextField::OnKeyEvent( const KeyEvent& event ) return mController->KeyEvent( event ); } +ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent ) +{ + switch ( imfEvent.eventName ) + { + case ImfManager::COMMIT: + { + KeyEvent event( "", imfEvent.predictiveString, 0, 0, 0, KeyEvent::Down ); + mController->KeyEvent( event ); + break; + } + case ImfManager::PREEDIT: // fall through + case ImfManager::DELETESURROUNDING: + case ImfManager::GETSURROUNDING: + case ImfManager::VOID: + { + // do nothing + } + } // end switch + + return ImfManager::ImfCallbackData(); +} + void TextField::RequestTextRelayout() { RelayoutRequest();