X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=base%2Fdali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fpush-button-impl.cpp;h=ee89ab9691cb70aea9cf0f6eb4124c5bb445618d;hp=03752f125d38bd2df4db21d15142be3549020cca;hb=93fb6a1d3dc8872275bde30ef6a05407a67d694c;hpb=30f6ca1e541089b19f2b349a8a12d8a5bcaf2f9e diff --git a/base/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/base/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index 03752f1..ee89ab9 100644 --- a/base/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/base/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -1,32 +1,33 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.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://floralicense.org/license/ -// -// 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. -// +/* + * Copyright (c) 2014 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 "push-button-impl.h" // EXTERNAL INCLUDES - #include +#include +#include +#include // INTERNAL INCLUDES - #include "push-button-default-painter-impl.h" -#include +#include namespace Dali { @@ -57,9 +58,8 @@ BaseHandle Create() TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create ); -SignalConnectorType signalConnector1( typeRegistration, Toolkit::PushButton::SIGNAL_TOGGLED , &PushButton::DoConnectSignal ); -SignalConnectorType signalConnector2( typeRegistration, Toolkit::PushButton::SIGNAL_PRESSED , &PushButton::DoConnectSignal ); -SignalConnectorType signalConnector3( typeRegistration, Toolkit::PushButton::SIGNAL_RELEASED, &PushButton::DoConnectSignal ); +SignalConnectorType signalConnector1( typeRegistration, Toolkit::PushButton::SIGNAL_PRESSED , &PushButton::DoConnectSignal ); +SignalConnectorType signalConnector2( typeRegistration, Toolkit::PushButton::SIGNAL_RELEASED, &PushButton::DoConnectSignal ); TypeAction action1( typeRegistration, Toolkit::PushButton::ACTION_PUSH_BUTTON_CLICK, &PushButton::DoAction ); @@ -81,12 +81,36 @@ namespace const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f ); const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f ); +const float TEXT_PADDING = 12.0f; + // Helper function used to cast a ButtonPainter to PushButtonDefaultPainter PushButtonDefaultPainterPtr GetPushButtonPainter( Dali::Toolkit::Internal::ButtonPainterPtr painter ) { return static_cast( painter.Get() ); } +/** + * Find the first image actor in the actor hierarchy + */ +ImageActor FindImageActor( Actor root ) +{ + ImageActor imageActor = ImageActor::DownCast( root ); + if( !imageActor && root ) + { + for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i ) + { + ImageActor childImageActor = FindImageActor( root.GetChildAt( i ) ); + if( childImageActor ) + { + return childImageActor; + } + } + } + + return imageActor; +} + + } // unnamed namespace Dali::Toolkit::PushButton PushButton::New() @@ -299,9 +323,7 @@ Actor PushButton::GetDimmedImage() const void PushButton::SetLabelText( const std::string& text ) { - Toolkit::TextView textView ( Toolkit::TextView::New( text ) ); - textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button - SetLabelText( textView ); + // TODO } void PushButton::SetLabelText( Actor text ) @@ -330,11 +352,6 @@ Actor& PushButton::GetFadeOutButtonImage() return mFadeOutButtonImage; } -Toolkit::PushButton::ToggledSignalV2& PushButton::ToggledSignal() -{ - return mToggledSignalV2; -} - Toolkit::PushButton::PressedSignalV2& PushButton::PressedSignal() { return mPressedSignalV2; @@ -558,7 +575,7 @@ void PushButton::OnButtonUp() // Notifies the painter the button has been toggled. GetPushButtonPainter( mPainter )->Toggled( handle ); - //Emit signal. + // Emit signal. mToggledSignalV2.Emit( handle, mToggled ); } else @@ -618,6 +635,25 @@ float PushButton::OnAnimationTimeRequested() const return GetPushButtonPainter( mPainter )->GetAnimationTime(); } +void PushButton::OnButtonStageDisconnection() +{ + if( ButtonDown == mState ) + { + if( !mToggleButton ) + { + Toolkit::PushButton handle( GetOwner() ); + + // Notifies the painter the button has been released. + GetPushButtonPainter( mPainter )->Released( handle ); + + if( mAutoRepeating ) + { + mAutoRepeatingTimer.Reset(); + } + } + } +} + PushButton::PushButton() : Button(), mAutoRepeating( false ), @@ -674,10 +710,56 @@ bool PushButton::AutoRepeatingSlot() void PushButton::OnActivated() { // When the button is activated, it performs the click action - std::vector attributes; + PropertyValueContainer attributes; DoClickAction(attributes); } +Vector3 PushButton::GetNaturalSize() +{ + Vector3 size = Control::GetNaturalSize(); + + const bool widthIsZero = EqualsZero( size.width ); + const bool heightIsZero = EqualsZero( size.height ); + + if( widthIsZero || heightIsZero ) + { + // If background and background not scale9 try get size from that + ImageActor imageActor = FindImageActor( mButtonImage ); + if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) + { + Vector3 imageSize = RelayoutHelper::GetNaturalSize( imageActor ); + + if( widthIsZero ) + { + size.width = imageSize.width; + } + + if( heightIsZero ) + { + size.height = imageSize.height; + } + } + + ImageActor backgroundImageActor = FindImageActor( mBackgroundImage ); + if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) + { + Vector3 imageSize = RelayoutHelper::GetNaturalSize( backgroundImageActor ); + + if( widthIsZero ) + { + size.width = std::max( size.width, imageSize.width ); + } + + if( heightIsZero ) + { + size.height = std::max( size.height, imageSize.height ); + } + } + } + + return size; +} + void PushButton::DoClickAction(const PropertyValueContainer& attributes) { // Prevents the button signals from doing a recursive loop by sending an action @@ -692,7 +774,7 @@ void PushButton::DoClickAction(const PropertyValueContainer& attributes) } } -bool PushButton::DoAction(BaseObject* object, const std::string& actionName, const std::vector& attributes) +bool PushButton::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes) { bool ret = false;