From: Paul Wisbey Date: Fri, 6 Mar 2015 16:12:34 +0000 (+0000) Subject: Merge remote-tracking branch 'origin/tizen' into new_text X-Git-Tag: new_text_0.1~12 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=eea53605c5acb244aebb72d75bdd9b3a68a9678a Merge remote-tracking branch 'origin/tizen' into new_text Conflicts: dali-toolkit/internal/controls/text-input/text-input-decorator-impl.cpp dali-toolkit/internal/controls/text-input/text-input-impl.cpp dali-toolkit/internal/controls/text-input/text-input-impl.h dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp dali-toolkit/internal/controls/text-view/text-view-impl.cpp dali-toolkit/internal/controls/text-view/text-view-impl.h dali-toolkit/internal/controls/text-view/text-view-word-processor.cpp dali-toolkit/public-api/controls/text-input/text-input.h dali-toolkit/public-api/controls/text-view/text-view.h Change-Id: I02bcdd172b1be75e3f6aa38c4dc8c55cdc076399 --- eea53605c5acb244aebb72d75bdd9b3a68a9678a diff --cc dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 224530b,0000000..2c87bbc mode 100644,000000..100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@@ -1,393 -1,0 +1,392 @@@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include +#include ++#include +#include +#include + +// INTERNAL INCLUDES +#include +#include + +using namespace Dali::Toolkit::Text; + +namespace +{ + +const unsigned int DEFAULT_RENDERING_BACKEND = 0; + +} // namespace + + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +namespace +{ + +// Type registration +BaseHandle Create() +{ + return Toolkit::TextField::New(); +} + - TypeRegistration mType( typeid(Toolkit::TextField), typeid(Toolkit::Control), 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", INT, RENDERING_BACKEND ) ++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, "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_TYPE_REGISTRATION_END() + +} // namespace + +Toolkit::TextField TextField::New() +{ + // Create the implementation, temporarily owned by this handle on stack + IntrusivePtr< TextField > impl = new TextField(); + + // Pass ownership to CustomActor handle + Toolkit::TextField handle( *impl ); + + // Second-phase init of the implementation + // This can only be done after the CustomActor connection has been made... + impl->Initialize(); + + return handle; +} + +void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) ); + + if( textField ) + { + TextField& impl( GetImpl( textField ) ); + + switch( index ) + { - case Toolkit::TextField::PROPERTY_RENDERING_BACKEND: ++ case Toolkit::TextField::Property::RENDERING_BACKEND: + { + unsigned int backend = value.Get< unsigned int >(); + + if( impl.mRenderingBackend != backend ) + { + impl.mRenderingBackend = backend; + impl.mRenderer.Reset(); + } + break; + } - case Toolkit::TextField::PROPERTY_PLACEHOLDER_TEXT: ++ case Toolkit::TextField::Property::PLACEHOLDER_TEXT: + { + if( impl.mController ) + { + //impl.mController->SetPlaceholderText( value.Get< std::string >() ); TODO + } + break; + } - case Toolkit::TextField::PROPERTY_TEXT: ++ case Toolkit::TextField::Property::TEXT: + { + if( impl.mController ) + { + impl.mController->SetText( value.Get< std::string >() ); + } + break; + } - case Toolkit::TextField::PROPERTY_CURSOR_IMAGE: ++ 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: ++ case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR: + { + if( impl.mDecorator ) + { + impl.mDecorator->SetColor( PRIMARY_CURSOR, value.Get< Vector4 >() ); + } + break; + } - case Toolkit::TextField::PROPERTY_SECONDARY_CURSOR_COLOR: ++ case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR: + { + if( impl.mDecorator ) + { + impl.mDecorator->SetColor( SECONDARY_CURSOR, value.Get< Vector4 >() ); + } + break; + } - case Toolkit::TextField::PROPERTY_ENABLE_CURSOR_BLINK: ++ case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK: + { + if( impl.mController ) + { + //impl.mController->SetEnableCursorBlink( value.Get< bool >() ); TODO + } + break; + } - case Toolkit::TextField::PROPERTY_CURSOR_BLINK_INTERVAL: ++ case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL: + { + if( impl.mDecorator ) + { + impl.mDecorator->SetCursorBlinkInterval( value.Get< float >() ); + } + break; + } - case Toolkit::TextField::PROPERTY_CURSOR_BLINK_DURATION: ++ case Toolkit::TextField::Property::CURSOR_BLINK_DURATION: + { + if( impl.mDecorator ) + { + impl.mDecorator->SetCursorBlinkDuration( value.Get< float >() ); + } + break; + } - case Toolkit::TextField::PROPERTY_GRAB_HANDLE_IMAGE: ++ case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE: + { + ResourceImage image = ResourceImage::New( value.Get< std::string >() ); + + if( impl.mDecorator ) + { + impl.mDecorator->SetGrabHandleImage( image ); + } + break; + } - case Toolkit::TextField::PROPERTY_DECORATION_BOUNDING_BOX: ++ case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX: + { + if( impl.mDecorator ) + { + impl.mDecorator->SetBoundingBox( value.Get< Rect >() ); + } + break; + } + } + } +} + +Property::Value TextField::GetProperty( BaseObject* object, Property::Index index ) +{ + Property::Value value; + + Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) ); + + if( textField ) + { + TextField& impl( GetImpl( textField ) ); + + switch( index ) + { - case Toolkit::TextField::PROPERTY_RENDERING_BACKEND: ++ case Toolkit::TextField::Property::RENDERING_BACKEND: + { + value = impl.mRenderingBackend; + break; + } - case Toolkit::TextField::PROPERTY_PLACEHOLDER_TEXT: ++ case Toolkit::TextField::Property::PLACEHOLDER_TEXT: + { + DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" ); + break; + } - case Toolkit::TextField::PROPERTY_TEXT: ++ case Toolkit::TextField::Property::TEXT: + { + DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" ); + break; + } - case Toolkit::TextField::PROPERTY_CURSOR_IMAGE: ++ 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: ++ case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR: + { + if( impl.mDecorator ) + { + value = impl.mDecorator->GetColor( PRIMARY_CURSOR ); + } + break; + } - case Toolkit::TextField::PROPERTY_SECONDARY_CURSOR_COLOR: ++ case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR: + { + if( impl.mDecorator ) + { + value = impl.mDecorator->GetColor( SECONDARY_CURSOR ); + } + break; + } - case Toolkit::TextField::PROPERTY_ENABLE_CURSOR_BLINK: ++ case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK: + { + //value = impl.mController->GetEnableCursorBlink(); TODO + break; + } - case Toolkit::TextField::PROPERTY_CURSOR_BLINK_INTERVAL: ++ case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL: + { + if( impl.mDecorator ) + { + value = impl.mDecorator->GetCursorBlinkInterval(); + } + break; + } - case Toolkit::TextField::PROPERTY_CURSOR_BLINK_DURATION: ++ case Toolkit::TextField::Property::CURSOR_BLINK_DURATION: + { + if( impl.mDecorator ) + { + value = impl.mDecorator->GetCursorBlinkDuration(); + } + break; + } - case Toolkit::TextField::PROPERTY_GRAB_HANDLE_IMAGE: ++ case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE: + { + if( impl.mDecorator ) + { + ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetCursorImage() ); + if( image ) + { + value = image.GetUrl(); + } + } + break; + } - case Toolkit::TextField::PROPERTY_DECORATION_BOUNDING_BOX: ++ case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX: + { + if( impl.mDecorator ) + { + value = impl.mDecorator->GetBoundingBox(); + } + break; + } + } + } + + return value; +} + +void TextField::OnInitialize() +{ + mController = Text::Controller::New( *this ); + + mDecorator = Text::Decorator::New( *this, *mController ); + + mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX ); + + mController->EnableTextInput( mDecorator ); + + // Forward input events to controller + mDoubleTapDetector = TapGestureDetector::New(); + mDoubleTapDetector.SetMaximumTapsRequired( 2 ); + mDoubleTapDetector.DetectedSignal().Connect( this, &TextField::OnTap ); + mDoubleTapDetector.Attach(Self()); + + // Set BoundingBox to stage size if not already set. + if ( mDecorator->GetBoundingBox().IsEmpty() ) + { + Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); + mDecorator->SetBoundingBox( Rect( 0.0f, 0.0f, stageSize.width, stageSize.height ) ); + } +} + +Vector3 TextField::GetNaturalSize() +{ + return mController->GetNaturalSize(); +} + +float TextField::GetHeightForWidth( float width ) +{ + return mController->GetHeightForWidth( width ); +} + +void TextField::OnRelayout( const Vector2& size, ActorSizeContainer& container ) +{ + if( mController->Relayout( size ) ) + { + if( mDecorator ) + { + mDecorator->Relayout( size ); + } + + if( !mRenderer ) + { + mRenderer = Backend::Get().NewRenderer( mRenderingBackend ); + } + + if( mRenderer ) + { + Actor renderableActor = mRenderer->Render( mController->GetView() ); + + if( renderableActor ) + { + Self().Add( renderableActor ); + } + } + } +} + +void TextField::OnTap( Actor actor, const TapGesture& gesture ) +{ + mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y ); +} + +void TextField::RequestTextRelayout() +{ + RelayoutRequest(); +} + +TextField::TextField() +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ), + mRenderingBackend( DEFAULT_RENDERING_BACKEND ) +{ +} + +TextField::~TextField() +{ +} + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali diff --cc dali-toolkit/internal/controls/text-controls/text-field-impl.h index 3f98cbd,0000000..32a7db2 mode 100644,000000..100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@@ -1,162 -1,0 +1,155 @@@ +#ifndef __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__ +#define __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include +#include +#include +#include +#include +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +/** + * @brief A control which renders a short text string. + */ +class TextField : public Control, public Text::ControlInterface +{ +public: + - // Properties - enum - { - TEXTFIELD_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, - TEXTFIELD_PROPERTY_END_INDEX = TEXTFIELD_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices - }; - + /** + * @copydoc Dali::Toollkit::TextField::New() + */ + static Toolkit::TextField New(); + + // Properties + + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] index The property index. + * @param[in] value The new property value. + */ + static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ); + + /** + * Called to retrieve a property of an object of this type. + * @param[in] object The object whose property is to be retrieved. + * @param[in] index The property index. + * @return The current value of the property. + */ + static Property::Value GetProperty( BaseObject* object, Property::Index index ); + +private: // From Control + + /** + * @copydoc Control::OnInitialize() + */ + virtual void OnInitialize(); + + /** + * @copydoc Control::GetNaturalSize() + */ + virtual Vector3 GetNaturalSize(); + + /** + * @copydoc Control::GetHeightForWidth() + */ + virtual float GetHeightForWidth( float width ); + + /** + * @copydoc Control::OnInitialize() + */ + virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); + + /** + * Received for single & double taps + */ + void OnTap( Actor actor, const TapGesture& tap ); + + /** + * @copydoc Text::ControlInterface::RequestTextRelayout() + */ + virtual void RequestTextRelayout(); + +private: // Implementation + + /** + * Construct a new TextField. + */ + TextField(); + + /** + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~TextField(); + +private: + + // Undefined copy constructor and assignment operators + TextField(const TextField&); + TextField& operator=(const TextField& rhs); + +private: // Data + + Text::ControllerPtr mController; + Text::RendererPtr mRenderer; + Text::DecoratorPtr mDecorator; + + TapGestureDetector mDoubleTapDetector; + + unsigned int mRenderingBackend; +}; + +} // namespace Internal + +// Helpers for public-api forwarding methods + +inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField ) +{ + DALI_ASSERT_ALWAYS(textField); + + Dali::RefObject& handle = textField.GetImplementation(); + + return static_cast(handle); +} + +inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField ) +{ + DALI_ASSERT_ALWAYS(textField); + + const Dali::RefObject& handle = textField.GetImplementation(); + + return static_cast(handle); +} + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__ diff --cc dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index 8b1cb70,0000000..bb0607d mode 100644,000000..100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@@ -1,283 -1,0 +1,284 @@@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include ++#include +#include + +// INTERNAL INCLUDES +#include +#include + +using Dali::Toolkit::Text::LayoutEngine; +using Dali::Toolkit::Text::Backend; + +namespace +{ + +const unsigned int DEFAULT_RENDERING_BACKEND = 0; + +} // namespace + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +namespace +{ + +// Type registration +BaseHandle Create() +{ + return Toolkit::TextLabel::New(); +} + +// Setup properties, signals and actions using the type-registry. +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create ); + - DALI_PROPERTY_REGISTRATION( TextLabel, "rendering-backend", INT, RENDERING_BACKEND ) ++DALI_PROPERTY_REGISTRATION( TextLabel, "rendering-backend", INTEGER, RENDERING_BACKEND ) +DALI_PROPERTY_REGISTRATION( TextLabel, "text", STRING, TEXT ) +DALI_PROPERTY_REGISTRATION( TextLabel, "font-family", STRING, FONT_FAMILY ) +DALI_PROPERTY_REGISTRATION( TextLabel, "font-style", STRING, FONT_STYLE ) +DALI_PROPERTY_REGISTRATION( TextLabel, "point-size", FLOAT, POINT_SIZE ) +DALI_PROPERTY_REGISTRATION( TextLabel, "multi-line", BOOLEAN, MULTI_LINE ) + +DALI_TYPE_REGISTRATION_END() + +} // namespace + +Toolkit::TextLabel TextLabel::New() +{ + // Create the implementation, temporarily owned by this handle on stack + IntrusivePtr< TextLabel > impl = new TextLabel(); + + // Pass ownership to CustomActor handle + Toolkit::TextLabel handle( *impl ); + + // Second-phase init of the implementation + // This can only be done after the CustomActor connection has been made... + impl->Initialize(); + + return handle; +} + +void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) ); + + if( label ) + { + TextLabel& impl( GetImpl( label ) ); + switch( index ) + { - case Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND: ++ case Toolkit::TextLabel::Property::RENDERING_BACKEND: + { + unsigned int backend = value.Get< int >(); + + if( impl.mRenderingBackend != backend ) + { + impl.mRenderingBackend = static_cast< unsigned int >( backend ); + impl.mRenderer.Reset(); + impl.RequestTextRelayout(); + } + break; + } - case Toolkit::TextLabel::PROPERTY_TEXT: ++ case Toolkit::TextLabel::Property::TEXT: + { + if( impl.mController ) + { + impl.mController->SetText( value.Get< std::string >() ); + impl.RequestTextRelayout(); + } + break; + } - case Toolkit::TextLabel::PROPERTY_FONT_FAMILY: ++ case Toolkit::TextLabel::Property::FONT_FAMILY: + { + if( impl.mController ) + { + std::string fontFamily = value.Get< std::string >(); + + if( impl.mController->GetDefaultFontFamily() != fontFamily ) + { + impl.mController->SetDefaultFontFamily( fontFamily ); + impl.RequestTextRelayout(); + } + } + break; + } - case Toolkit::TextLabel::PROPERTY_FONT_STYLE: ++ case Toolkit::TextLabel::Property::FONT_STYLE: + { + if( impl.mController ) + { + std::string fontStyle = value.Get< std::string >(); + + if( impl.mController->GetDefaultFontStyle() != fontStyle ) + { + impl.mController->SetDefaultFontStyle( fontStyle ); + impl.RequestTextRelayout(); + } + } + break; + } - case Toolkit::TextLabel::PROPERTY_POINT_SIZE: ++ case Toolkit::TextLabel::Property::POINT_SIZE: + { + if( impl.mController ) + { + float pointSize = value.Get< float >(); + + if( impl.mController->GetDefaultPointSize() != pointSize /*TODO - epsilon*/ ) + { + impl.mController->SetDefaultPointSize( pointSize ); + impl.RequestTextRelayout(); + } + } + break; + } - case Toolkit::TextLabel::PROPERTY_MULTI_LINE: ++ case Toolkit::TextLabel::Property::MULTI_LINE: + { + if( impl.mController ) + { + LayoutEngine& engine = impl.mController->GetLayoutEngine(); + LayoutEngine::Layout layout = value.Get< bool >() ? LayoutEngine::MULTI_LINE_BOX : LayoutEngine::SINGLE_LINE_BOX; + + if( engine.GetLayout() != layout ) + { + impl.mController->GetLayoutEngine().SetLayout( layout ); + impl.RequestTextRelayout(); + } + } + break; + } + } + } +} + +Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index ) +{ + Property::Value value; + + Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) ); + + if( label ) + { + TextLabel& impl( GetImpl( label ) ); + switch( index ) + { - case Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND: ++ case Toolkit::TextLabel::Property::RENDERING_BACKEND: + { + value = impl.mRenderingBackend; + break; + } - case Toolkit::TextLabel::PROPERTY_TEXT: ++ case Toolkit::TextLabel::Property::TEXT: + { + if( impl.mController ) + { + std::string text; + impl.mController->GetText( text ); + value = text; + } + + DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" ); + break; + } - case Toolkit::TextLabel::PROPERTY_MULTI_LINE: ++ case Toolkit::TextLabel::Property::MULTI_LINE: + { + if( impl.mController ) + { + value = static_cast( LayoutEngine::MULTI_LINE_BOX == impl.mController->GetLayoutEngine().GetLayout() ); + } + break; + } + } + } + + return value; +} + +void TextLabel::OnInitialize() +{ + mController = Text::Controller::New( *this ); +} + +Vector3 TextLabel::GetNaturalSize() +{ + return mController->GetNaturalSize(); +} + +float TextLabel::GetHeightForWidth( float width ) +{ + return mController->GetHeightForWidth( width ); +} + +void TextLabel::OnRelayout( const Vector2& size, ActorSizeContainer& container ) +{ + if( mController->Relayout( size ) || + !mRenderer ) + { + if( !mRenderer ) + { + mRenderer = Backend::Get().NewRenderer( mRenderingBackend ); + } + + RenderableActor renderableActor; + if( mRenderer ) + { + renderableActor = mRenderer->Render( mController->GetView() ); + } + + if( renderableActor != mRenderableActor ) + { + UnparentAndReset( mRenderableActor ); + + if( renderableActor ) + { + Self().Add( renderableActor ); + } + + mRenderableActor = renderableActor; + } + } +} + +void TextLabel::RequestTextRelayout() +{ + RelayoutRequest(); +} + +TextLabel::TextLabel() +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ), + mRenderingBackend( DEFAULT_RENDERING_BACKEND ) +{ +} + +TextLabel::~TextLabel() +{ +} + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali diff --cc dali-toolkit/internal/controls/text-controls/text-label-impl.h index 5c62137,0000000..de54bf0 mode 100644,000000..100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@@ -1,153 -1,0 +1,146 @@@ +#ifndef __DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H__ +#define __DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include +#include +#include +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +/** + * @brief A control which renders a short text string. + */ +class TextLabel : public Control, public Text::ControlInterface +{ +public: + - // Properties - enum - { - TEXTLABEL_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, - TEXTLABEL_PROPERTY_END_INDEX = TEXTLABEL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices - }; - + /** + * @copydoc Dali::Toollkit::TextLabel::New() + */ + static Toolkit::TextLabel New(); + + // Properties + + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] index The property index. + * @param[in] value The new property value. + */ + static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ); + + /** + * Called to retrieve a property of an object of this type. + * @param[in] object The object whose property is to be retrieved. + * @param[in] index The property index. + * @return The current value of the property. + */ + static Property::Value GetProperty( BaseObject* object, Property::Index index ); + +private: // From Control + + /** + * @copydoc Control::OnInitialize() + */ + virtual void OnInitialize(); + + /** + * @copydoc Control::OnInitialize() + */ + virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); + + /** + * @copydoc Control::GetNaturalSize() + */ + virtual Vector3 GetNaturalSize(); + + /** + * @copydoc Control::GetHeightForWidth() + */ + virtual float GetHeightForWidth( float width ); + + /** + * @copydoc Text::ControlInterface::RequestTextRelayout() + */ + virtual void RequestTextRelayout(); + +private: // Implementation + + /** + * Construct a new TextLabel. + */ + TextLabel(); + + /** + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~TextLabel(); + +private: + + // Undefined copy constructor and assignment operators + TextLabel(const TextLabel&); + TextLabel& operator=(const TextLabel& rhs); + +private: // Data + + Text::ControllerPtr mController; + Text::RendererPtr mRenderer; + RenderableActor mRenderableActor; + + unsigned int mRenderingBackend; +}; + +} // namespace Internal + +// Helpers for public-api forwarding methods + +inline Toolkit::Internal::TextLabel& GetImpl( Toolkit::TextLabel& textLabel ) +{ + DALI_ASSERT_ALWAYS(textLabel); + + Dali::RefObject& handle = textLabel.GetImplementation(); + + return static_cast(handle); +} + +inline const Toolkit::Internal::TextLabel& GetImpl( const Toolkit::TextLabel& textLabel ) +{ + DALI_ASSERT_ALWAYS(textLabel); + + const Dali::RefObject& handle = textLabel.GetImplementation(); + + return static_cast(handle); +} + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H__ diff --cc dali-toolkit/public-api/controls/text-controls/text-field.h index be8779b,0000000..821b35c mode 100644,000000..100644 --- a/dali-toolkit/public-api/controls/text-controls/text-field.h +++ b/dali-toolkit/public-api/controls/text-controls/text-field.h @@@ -1,140 -1,0 +1,140 @@@ +#ifndef __DALI_TOOLKIT_TEXT_FIELD_H__ +#define __DALI_TOOLKIT_TEXT_FIELD_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal DALI_INTERNAL +{ +class TextField; +} + +/** + * @brief A control which provides a single-line editable text field. + */ +class DALI_IMPORT_API TextField : public Control +{ +public: + + /** + * @brief The start and end property ranges for this control. + */ + enum PropertyRange + { + PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices + }; + + /** + * @brief An enumeration of properties belonging to the TextLabel class. + */ + struct Property + { + enum + { - PROPERTY_RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "rendering-backend", The type or rendering e.g. bitmap-based, type INT - PROPERTY_PLACEHOLDER_TEXT, ///< name "placeholder-text", The text to display when the TextField is empty, type STRING - PROPERTY_TEXT, ///< name "text", The text to display in UTF-8 format, type STRING - PROPERTY_FONT_FAMILY, ///< name "font-family", The requested font family, type STRING - PROPERTY_FONT_STYLE, ///< name "font-style", The requested font style e.g. Regular/Italic, type STRING - PROPERTY_POINT_SIZE, ///< name "point-size", The size of font in points, type FLOAT - PROPERTY_CURSOR_IMAGE, ///< name "cursor-image", The image to display for cursors, type STRING - PROPERTY_PRIMARY_CURSOR_COLOR, ///< name "primary-cursor-color", The color to apply to the primary cursor, type VECTOR4 - PROPERTY_SECONDARY_CURSOR_COLOR, ///< name "secondary-cursor-color", The color to apply to the secondary cursor, type VECTOR4 - PROPERTY_ENABLE_CURSOR_BLINK, ///< name "enable-cursor-blink", Whether the cursor should blink or not, type BOOLEAN - PROPERTY_CURSOR_BLINK_INTERVAL, ///< name "cursor-blink-interval", The time interval between cursor on/off states, type FLOAT - PROPERTY_CURSOR_BLINK_DURATION, ///< name "cursor-blink-duration", The cursor will stop blinking after this duration (if non-zero), type FLOAT - PROPERTY_GRAB_HANDLE_IMAGE, ///< name "grab-handle-image", The image to display for grab handle, type STRING - PROPERTY_DECORATION_BOUNDING_BOX ///< name "decoration-bounding-box", The decorations (handles etc) will positioned within this area on-screen, type RECTANGLE ++ RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "rendering-backend", The type or rendering e.g. bitmap-based, type INT ++ PLACEHOLDER_TEXT, ///< name "placeholder-text", The text to display when the TextField is empty, type STRING ++ TEXT, ///< name "text", The text to display in UTF-8 format, type STRING ++ FONT_FAMILY, ///< name "font-family", The requested font family, type STRING ++ FONT_STYLE, ///< name "font-style", The requested font style e.g. Regular/Italic, type STRING ++ POINT_SIZE, ///< name "point-size", The size of font in points, type FLOAT ++ CURSOR_IMAGE, ///< name "cursor-image", The image to display for cursors, type STRING ++ PRIMARY_CURSOR_COLOR, ///< name "primary-cursor-color", The color to apply to the primary cursor, type VECTOR4 ++ SECONDARY_CURSOR_COLOR, ///< name "secondary-cursor-color", The color to apply to the secondary cursor, type VECTOR4 ++ ENABLE_CURSOR_BLINK, ///< name "enable-cursor-blink", Whether the cursor should blink or not, type BOOLEAN ++ CURSOR_BLINK_INTERVAL, ///< name "cursor-blink-interval", The time interval between cursor on/off states, type FLOAT ++ CURSOR_BLINK_DURATION, ///< name "cursor-blink-duration", The cursor will stop blinking after this duration (if non-zero), type FLOAT ++ GRAB_HANDLE_IMAGE, ///< name "grab-handle-image", The image to display for grab handle, type STRING ++ DECORATION_BOUNDING_BOX ///< name "decoration-bounding-box", The decorations (handles etc) will positioned within this area on-screen, type RECTANGLE + }; + }; + + /** + * Create the TextField control. + * @return A handle to the TextField control. + */ + static TextField New(); + + /** + * @brief Creates an empty handle. + */ + TextField(); + + /** + * @brief Copy constructor. + * + * @param[in] handle The handle to copy from. + */ + TextField( const TextField& handle ); + + /** + * @brief Assignment operator. + * + * @param[in] handle The handle to copy from. + * @return A reference to this. + */ + TextField& operator=( const TextField& handle ); + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~TextField(); + + /** + * @brief Downcast a handle to TextField. + * + * If the BaseHandle points is a TextField the downcast returns a valid handle. + * If not the returned handle is left empty. + * + * @param[in] handle Handle to an object + * @return handle to a TextField or an empty handle + */ + static TextField DownCast( BaseHandle handle ); + +public: // Not intended for application developers + + /** + * @brief Creates a handle using the Toolkit::Internal implementation. + * + * @param[in] implementation The Control implementation. + */ + DALI_INTERNAL TextField( Internal::TextField& implementation ); + + /** + * @brief Allows the creation of this Control from an Internal::CustomActor pointer. + * + * @param[in] internal A pointer to the internal CustomActor. + */ + explicit DALI_INTERNAL TextField( Dali::Internal::CustomActor* internal ); +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_TEXT_FIELD_H__ diff --cc dali-toolkit/public-api/controls/text-controls/text-label.h index cc3cf24,0000000..e36b44a mode 100644,000000..100644 --- a/dali-toolkit/public-api/controls/text-controls/text-label.h +++ b/dali-toolkit/public-api/controls/text-controls/text-label.h @@@ -1,134 -1,0 +1,134 @@@ +#ifndef __DALI_TOOLKIT_TEXT_LABEL_H__ +#define __DALI_TOOLKIT_TEXT_LABEL_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal DALI_INTERNAL +{ +class TextLabel; +} + +/** + * @brief A control which renders a short text string. + * + * Text labels are lightweight, non-editable and do not respond to user input. + */ +class DALI_IMPORT_API TextLabel : public Control +{ +public: + + /** + * @brief The start and end property ranges for this control. + */ + enum PropertyRange + { + PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices + }; + + /** + * @brief An enumeration of properties belonging to the TextLabel class. + */ + struct Property + { + enum + { - PROPERTY_RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "rendering-backend", The type or rendering e.g. bitmap-based, type INT - PROPERTY_TEXT, ///< name "text", The text to display in UTF-8 format, type STRING - PROPERTY_FONT_FAMILY, ///< name "font-family", The requested font family, type STRING - PROPERTY_FONT_STYLE, ///< name "font-style", The requested font style e.g. Regular/Italic, type STRING - PROPERTY_POINT_SIZE, ///< name "point-size", The size of font in points, type FLOAT - PROPERTY_MULTI_LINE, ///< name "multi-line", The single-line or multi-line layout option, type BOOLEAN ++ RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "rendering-backend", The type or rendering e.g. bitmap-based, type INT ++ TEXT, ///< name "text", The text to display in UTF-8 format, type STRING ++ FONT_FAMILY, ///< name "font-family", The requested font family, type STRING ++ FONT_STYLE, ///< name "font-style", The requested font style e.g. Regular/Italic, type STRING ++ POINT_SIZE, ///< name "point-size", The size of font in points, type FLOAT ++ MULTI_LINE, ///< name "multi-line", The single-line or multi-line layout option, type BOOLEAN + }; + }; + + /** + * Create the TextLabel control. + * @return A handle to the TextLabel control. + */ + static TextLabel New(); + + /** + * @brief Creates an empty handle. + */ + TextLabel(); + + /** + * @brief Copy constructor. + * + * @param[in] handle The handle to copy from. + */ + TextLabel( const TextLabel& handle ); + + /** + * @brief Assignment operator. + * + * @param[in] handle The handle to copy from. + * @return A reference to this. + */ + TextLabel& operator=( const TextLabel& handle ); + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~TextLabel(); + + /** + * @brief Downcast a handle to TextLabel. + * + * If the BaseHandle points is a TextLabel the downcast returns a valid handle. + * If not the returned handle is left empty. + * + * @param[in] handle Handle to an object + * @return handle to a TextLabel or an empty handle + */ + static TextLabel DownCast( BaseHandle handle ); + +public: // Not intended for application developers + + /** + * @brief Creates a handle using the Toolkit::Internal implementation. + * + * @param[in] implementation The Control implementation. + */ + DALI_INTERNAL TextLabel( Internal::TextLabel& implementation ); + + /** + * @brief Allows the creation of this Control from an Internal::CustomActor pointer. + * + * @param[in] internal A pointer to the internal CustomActor. + */ + explicit DALI_INTERNAL TextLabel( Dali::Internal::CustomActor* internal ); +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_TEXT_LABEL_H__