Merge "(Automated Tests) Increase line coverage of Builder" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / button-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "button-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23 #include <dali/public-api/events/touch-data.h>
24 #include <dali/public-api/images/resource-image.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/public-api/object/type-registry-helper.h>
27 #include <dali/devel-api/scripting/scripting.h>
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
31 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
32
33 /**
34  * Button states and contents
35  *                                         (3) mSelectedContent
36  *  (2) mUnselectedContent                 (2) mSelectedBackgroundContent
37  *  (1) mBackgroundContent                 (1) mBackgroundContent
38  * < unselected > ----------------------- < selected >
39  *       |                OnSelect()            |
40  *       | OnDisabled()                         | OnDisabled()
41  *       |                                      |
42  * < disabled >                           < disabled-selected >
43  *  (2) mDisabledContent                   (2) mDisabledSelectedContent
44  *  (1) mDisabledBackgroundContent         (1) mDisabledBackgroundContent
45  *
46  * The drawing order of child actors is as follows.
47  *
48  *  Top      mLabel
49  *   |       mUnselectedContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent
50  *   |       mSelectedBackgroundContent
51  * Bottom    mBackgroundContent / mDisabledBackgroundContent
52  *
53  * Some of contents may be missed.
54  * And 2 images - fade-in image and fade-out image - in the same layer can be shown during the transition animation. Fade-in image should be above fade-out image.
55  */
56
57 namespace Dali
58 {
59
60 namespace Toolkit
61 {
62
63 namespace Internal
64 {
65
66 namespace
67 {
68
69 BaseHandle Create()
70 {
71   // empty handle as we cannot create button (but type registered for clicked signal)
72   return BaseHandle();
73 }
74
75 // Setup properties, signals and actions using the type-registry.
76 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create );
77
78 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled",                     BOOLEAN, DISABLED                     )
79 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "autoRepeating",                BOOLEAN, AUTO_REPEATING               )
80 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initialAutoRepeatingDelay",    FLOAT,   INITIAL_AUTO_REPEATING_DELAY )
81 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "nextAutoRepeatingDelay",       FLOAT,   NEXT_AUTO_REPEATING_DELAY    )
82 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable",                    BOOLEAN, TOGGLABLE                    )
83 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected",                     BOOLEAN, SELECTED                     )
84 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedStateImage",         STRING,  UNSELECTED_STATE_IMAGE       )
85 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedStateImage",           STRING,  SELECTED_STATE_IMAGE         )
86 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledStateImage",           STRING,  DISABLED_STATE_IMAGE         )
87 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedColor",              VECTOR4, UNSELECTED_COLOR             )
88 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedColor",                VECTOR4, SELECTED_COLOR               )
89 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label",                        MAP,     LABEL                        )
90
91 // Deprecated properties:
92 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelText",                    STRING,  LABEL_TEXT                   )
93
94 // Signals:
95 DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "pressed",                               SIGNAL_PRESSED               )
96 DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "released",                              SIGNAL_RELEASED              )
97 DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "clicked",                               SIGNAL_CLICKED               )
98 DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "stateChanged",                          SIGNAL_STATE_CHANGED         )
99
100 // Actions:
101 DALI_ACTION_REGISTRATION(   Toolkit, Button, "buttonClick",                           ACTION_BUTTON_CLICK          )
102
103 DALI_TYPE_REGISTRATION_END()
104
105 const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
106 const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
107
108 } // unnamed namespace
109
110 Button::Button()
111 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
112   mAutoRepeatingTimer(),
113   mUnselectedColor( Color::WHITE ), // The natural colors of the specified images will be used by default.
114   mSelectedColor( Color::WHITE ),
115   mDisabled( false ),
116   mAutoRepeating( false ),
117   mTogglableButton( false ),
118   mSelected( false ),
119   mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ),
120   mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
121   mAnimationTime( 0.0f ),
122   mClickActionPerforming( false ),
123   mState( ButtonUp ),
124   mPaintState( UnselectedState )
125 {
126 }
127
128 Button::~Button()
129 {
130 }
131
132 void Button::SetDisabled( bool disabled )
133 {
134   if( disabled == mDisabled )
135   {
136     return;
137   }
138
139   StopTransitionAnimation();
140
141   mDisabled = disabled;
142
143   // Notifies the derived class the button has been disabled.
144   OnDisabled();
145
146   switch( mPaintState )
147   {
148     case UnselectedState:
149     {
150       //Layer Order
151       //(3) mDisabledContent (Inserted)
152       //(4) mUnselectedContent
153       //(2) mDisabledBackgroundContent (Inserted)
154       //(1) mBackgroundContent
155
156       AddButtonImage( mBackgroundContent );
157       TransitionButtonImage( mDisabledBackgroundContent );
158       AddButtonImage( mUnselectedContent );
159       TransitionButtonImage( mDisabledContent );
160
161       AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
162       ReAddLabel();
163
164       TransitionOut( mDecoration[ SELECTED_DECORATION ] );
165       TransitionOut( mUnselectedContent );
166       TransitionOut( mSelectedContent );
167       TransitionOut( mBackgroundContent );
168       TransitionOut( mSelectedBackgroundContent );
169       TransitionOut( mDisabledSelectedContent );
170
171       mPaintState = DisabledUnselectedState;
172       break;
173     }
174     case SelectedState:
175     {
176       //Layer Order
177       //(5) mDisabledSelectedContent (Inserted)
178       //(4) mSelectedContent
179       //(3) mDisabledBackgroundContent (Inserted)
180       //(2) mSelectedBackgroundContent
181       //(1) mBackgroundContent
182
183       AddButtonImage( mBackgroundContent );
184       AddButtonImage( mSelectedBackgroundContent );
185       TransitionButtonImage( mDisabledBackgroundContent );
186       AddButtonImage( mSelectedContent );
187       TransitionButtonImage( mDisabledSelectedContent );
188
189       AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
190       ReAddLabel();
191
192       TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
193       TransitionOut( mUnselectedContent );
194       TransitionOut( mSelectedContent );
195       TransitionOut( mBackgroundContent );
196       TransitionOut( mSelectedBackgroundContent );
197       TransitionOut( mDisabledContent );
198
199       mPaintState = DisabledSelectedState;
200       break;
201     }
202     case DisabledUnselectedState:
203     {
204       //Layer Order
205       //(3) mUnselectedContent (Inserted)
206       //(4) mDisabledContent
207       //(2) mBackgroundContent (Inserted)
208       //(1) mDisabledBackgroundContent
209
210       AddButtonImage( mDisabledBackgroundContent );
211       TransitionButtonImage( mBackgroundContent );
212       AddButtonImage( mDisabledContent );
213       TransitionButtonImage( mUnselectedContent );
214
215       AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
216       ReAddLabel();
217
218       TransitionOut( mDecoration[ SELECTED_DECORATION ] );
219       TransitionOut( mSelectedContent );
220       TransitionOut( mSelectedBackgroundContent );
221       TransitionOut( mDisabledContent );
222       TransitionOut( mDisabledSelectedContent );
223       TransitionOut( mDisabledBackgroundContent );
224
225       mPaintState = UnselectedState;
226       break;
227     }
228     case DisabledSelectedState:
229     {
230       //Layer Order
231       //(4) mSelectedContent (Inserted)
232       //(5) mDisabledSelectedContent
233       //(3) mSelectedBackgroundContent (Inserted)
234       //(2) mBackgroundContent (Inserted)
235       //(1) mDisabledBackgroundContent
236
237       AddButtonImage( mDisabledBackgroundContent );
238       TransitionButtonImage( mBackgroundContent );
239       TransitionButtonImage( mSelectedBackgroundContent );
240       AddButtonImage( mDisabledSelectedContent );
241       TransitionButtonImage( mSelectedContent );
242
243       AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
244       ReAddLabel();
245
246       TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
247       TransitionOut( mUnselectedContent );
248       TransitionOut( mDisabledContent );
249       TransitionOut( mDisabledSelectedContent );
250       TransitionOut( mDisabledBackgroundContent );
251
252       mPaintState = SelectedState;
253       break;
254     }
255   }
256
257   StartTransitionAnimation();
258 }
259
260 bool Button::IsDisabled() const
261 {
262   return mDisabled;
263 }
264
265 void Button::SetAutoRepeating( bool autoRepeating )
266 {
267   mAutoRepeating = autoRepeating;
268
269   // An autorepeating button can't be a togglable button.
270   if( autoRepeating )
271   {
272     mTogglableButton = false;
273
274     if( mSelected )
275     {
276       // Emit a signal is not wanted, only change the appearance.
277       SetSelected( false, false );
278     }
279   }
280 }
281
282 bool Button::IsAutoRepeating() const
283 {
284   return mAutoRepeating;
285 }
286
287 void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
288 {
289   DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f );
290   mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
291 }
292
293 float Button::GetInitialAutoRepeatingDelay() const
294 {
295   return mInitialAutoRepeatingDelay;
296 }
297
298 void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
299 {
300   DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
301   mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
302 }
303
304 float Button::GetNextAutoRepeatingDelay() const
305 {
306   return mNextAutoRepeatingDelay;
307 }
308
309 void Button::SetTogglableButton( bool togglable )
310 {
311   mTogglableButton = togglable;
312
313   // A togglable button can't be an autorepeating button.
314   if( togglable )
315   {
316     mAutoRepeating = false;
317   }
318 }
319
320 bool Button::IsTogglableButton() const
321 {
322   return mTogglableButton;
323 }
324
325 void Button::SetSelected( bool selected )
326 {
327   if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
328   {
329     SetSelected( selected, true );
330   }
331 }
332
333 void Button::SetSelected( bool selected, bool emitSignal )
334 {
335   StopTransitionAnimation();
336
337   mSelected = selected;
338
339   // Notifies the derived class the button has been selected.
340   OnSelected();
341
342   switch( mPaintState )
343   {
344     case UnselectedState:
345     {
346       //Layer Order
347       //(3) mSelectedContent (Inserted)
348       //(4) mUnselectedContent
349       //(2) mSelectedBackgroundContent (Inserted)
350       //(1) mBackgroundContent
351
352       AddButtonImage( mBackgroundContent );
353       TransitionButtonImage( mSelectedBackgroundContent );
354       AddButtonImage( mUnselectedContent );
355       TransitionButtonImage( mSelectedContent );
356
357       AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
358       TransitionButtonImage( mDecoration[ SELECTED_DECORATION ] );
359       ReAddLabel();
360
361       TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
362       TransitionOut( mUnselectedContent );
363       TransitionOut( mDisabledContent );
364       TransitionOut( mDisabledSelectedContent );
365       TransitionOut( mDisabledBackgroundContent );
366
367       mPaintState = SelectedState;
368       break;
369     }
370     case SelectedState:
371     {
372       //Layer Order
373       //(3) mUnselectedContent (Inserted)
374       //(2) mSelectedContent
375       //(1) mBackgroundContent
376
377       AddButtonImage( mBackgroundContent );
378       AddButtonImage( mSelectedContent );
379       TransitionButtonImage( mUnselectedContent );
380
381       AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
382       TransitionButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
383       ReAddLabel();
384
385       TransitionOut( mDecoration[ SELECTED_DECORATION ] );
386       TransitionOut( mSelectedContent );
387       TransitionOut( mSelectedBackgroundContent );
388       TransitionOut( mDisabledContent );
389       TransitionOut( mDisabledSelectedContent );
390       TransitionOut( mDisabledBackgroundContent );
391
392       mPaintState = UnselectedState;
393       break;
394     }
395     case DisabledUnselectedState:
396     case DisabledSelectedState:
397     {
398       DALI_ASSERT_DEBUG( 0 && "Shouldn't be able to change paint state if the button is disabled." );
399       break;
400     }
401   }
402
403   StartTransitionAnimation();
404
405   if( emitSignal )
406   {
407     Toolkit::Button handle( GetOwner() );
408
409     // Emit signal.
410     mStateChangedSignal.Emit( handle );
411   }
412
413   RelayoutRequest();
414 }
415
416 bool Button::IsSelected() const
417 {
418   return mTogglableButton && mSelected;
419 }
420
421 void Button::SetAnimationTime( float animationTime )
422 {
423   mAnimationTime = animationTime;
424 }
425
426 float Button::GetAnimationTime() const
427 {
428   return mAnimationTime;
429 }
430
431 void Button::SetLabelText( const std::string& label )
432 {
433   Property::Map labelProperty;
434   labelProperty.Insert( "text", label );
435   ModifyLabel( labelProperty );
436 }
437
438 std::string Button::GetLabelText() const
439 {
440   Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel );
441   if( label )
442   {
443     return label.GetProperty<std::string>( Dali::Toolkit::TextLabel::Property::TEXT );
444   }
445   return std::string();
446 }
447
448 void Button::ModifyLabel( const Property::Map& properties )
449 {
450   // If we don't have a label yet, create one.
451   if( !mLabel )
452   {
453     // If we don't have a label, create one and set it up.
454     // Note: The label text is set from the passed in property map after creation.
455     mLabel = Toolkit::TextLabel::New();
456     mLabel.SetPosition( 0.0f, 0.0f );
457     // label should be the top of the button
458     Self().Add( mLabel );
459   }
460
461   // Set any properties specified for the label by iterating through all property key-value pairs.
462   for( unsigned int i = 0, mapCount = properties.Count(); i < mapCount; ++i )
463   {
464     const StringValuePair& propertyPair( properties.GetPair( i ) );
465
466     // Convert the property string to a property index.
467     Property::Index setPropertyIndex = mLabel.GetPropertyIndex( propertyPair.first );
468     if( setPropertyIndex != Property::INVALID_INDEX )
469     {
470       // If the conversion worked, we have a valid property index,
471       // Set the property to the new value.
472       mLabel.SetProperty( setPropertyIndex, propertyPair.second );
473     }
474   }
475
476   // Notify derived button classes of the change.
477   OnLabelSet( false );
478
479   RelayoutRequest();
480 }
481
482 Actor& Button::GetLabelActor()
483 {
484   return mLabel;
485 }
486
487 void Button::SetDecoration( DecorationState state, Actor actor )
488 {
489   if( mDecoration[ state ] && mDecoration[ state ].GetParent() )
490   {
491     mDecoration[ state ].Unparent();
492   }
493
494   mDecoration[ state ] = actor;
495   mDecoration[ state ].SetColorMode( USE_OWN_COLOR );
496
497   ResetImageLayers();
498   RelayoutRequest();
499 }
500
501 Actor& Button::GetDecoration( DecorationState state )
502 {
503   return mDecoration[ state ];
504 }
505
506 void Button::SetupContent( Actor& actorToModify, Actor newActor )
507 {
508   if( newActor )
509   {
510     StopTransitionAnimation();
511
512     if( actorToModify && actorToModify.GetParent() )
513     {
514       actorToModify.Unparent();
515     }
516
517     actorToModify = newActor;
518
519     if( actorToModify )
520     {
521       actorToModify.SetAnchorPoint( AnchorPoint::TOP_LEFT );
522       actorToModify.SetParentOrigin( ParentOrigin::TOP_LEFT );
523       actorToModify.SetPosition( 0.f, 0.f );
524     }
525
526     ResetImageLayers();
527   }
528 }
529
530 void Button::SetUnselectedColor( const Vector4& color )
531 {
532   mUnselectedColor = color;
533
534   if( mUnselectedContent && !GetUnselectedImageFilename().empty() )
535   {
536     // If there is existing unselected content, change the color on it directly.
537     mUnselectedContent.SetColor( mUnselectedColor );
538   }
539   else
540   {
541     // If there is no existing content, create a new actor to use for flat color.
542     Toolkit::Control unselectedContentActor = Toolkit::Control::New();
543     unselectedContentActor.SetBackgroundColor( mUnselectedColor );
544     SetupContent( mUnselectedContent, unselectedContentActor );
545     mUnselectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
546   }
547 }
548
549 const Vector4 Button::GetUnselectedColor() const
550 {
551   return mUnselectedColor;
552 }
553
554 void Button::SetSelectedColor( const Vector4& color )
555 {
556   mSelectedColor = color;
557
558   if( mSelectedContent && !GetSelectedImageFilename().empty() )
559   {
560     // If there is existing unselected content, change the color on it directly.
561     mSelectedContent.SetColor( mSelectedColor );
562   }
563   else
564   {
565     // If there is no existing content, create a new actor to use for flat color.
566     Toolkit::Control selectedContentActor = Toolkit::Control::New();
567     selectedContentActor.SetBackgroundColor( mSelectedColor );
568     SetupContent( mSelectedContent, selectedContentActor );
569     mSelectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
570   }
571 }
572
573 const Vector4 Button::GetSelectedColor() const
574 {
575   return mSelectedColor;
576 }
577
578 void Button::SetUnselectedImage( const std::string& filename )
579 {
580   Toolkit::ImageView newContent;
581   if( !filename.empty() )
582   {
583     newContent = Toolkit::ImageView::New( filename );
584   }
585   else
586   {
587     newContent = Toolkit::ImageView::New();
588   }
589
590   if( newContent )
591   {
592     SetupContent( mUnselectedContent, newContent );
593
594     mUnselectedContent.SetColor( mUnselectedColor );
595
596     OnUnselectedImageSet();
597     RelayoutRequest();
598   }
599 }
600
601 Actor& Button::GetUnselectedImage()
602 {
603   return mUnselectedContent;
604 }
605
606 void Button::SetSelectedImage( const std::string& filename )
607 {
608   Toolkit::ImageView newContent;
609   if( !filename.empty() )
610   {
611    newContent = Toolkit::ImageView::New( filename );
612   }
613   else
614   {
615     newContent = Toolkit::ImageView::New();
616   }
617
618   if( newContent )
619   {
620     SetupContent( mSelectedContent, newContent );
621
622     mSelectedContent.SetColor( mSelectedColor );
623
624     OnSelectedImageSet();
625     RelayoutRequest();
626   }
627 }
628
629 Actor& Button::GetSelectedImage()
630 {
631   return mSelectedContent;
632 }
633
634 void Button::SetBackgroundImage( const std::string& filename )
635 {
636   SetupContent( mBackgroundContent, Toolkit::ImageView::New( filename ) );
637
638   OnBackgroundImageSet();
639   RelayoutRequest();
640 }
641
642 Actor& Button::GetBackgroundImage()
643 {
644   return mBackgroundContent;
645 }
646
647 void Button::SetSelectedBackgroundImage( const std::string& filename )
648 {
649   SetupContent( mSelectedBackgroundContent, Toolkit::ImageView::New( filename ) );
650
651   OnSelectedBackgroundImageSet();
652   RelayoutRequest();
653 }
654
655 Actor& Button::GetSelectedBackgroundImage()
656 {
657   return mSelectedBackgroundContent;
658 }
659
660 void Button::SetDisabledImage( const std::string& filename )
661 {
662   SetupContent( mDisabledContent, Toolkit::ImageView::New( filename ) );
663
664   OnDisabledImageSet();
665   RelayoutRequest();
666 }
667
668 Actor& Button::GetDisabledImage()
669 {
670   return mDisabledContent;
671 }
672
673 void Button::SetDisabledSelectedImage( const std::string& filename )
674 {
675   SetupContent( mDisabledSelectedContent, Toolkit::ImageView::New( filename ) );
676
677   OnDisabledSelectedImageSet();
678   RelayoutRequest();
679 }
680
681 Actor& Button::GetDisabledSelectedImage()
682 {
683   return mDisabledSelectedContent;
684 }
685
686 void Button::SetDisabledBackgroundImage( const std::string& filename )
687 {
688   SetupContent( mDisabledBackgroundContent, Toolkit::ImageView::New( filename ) );
689
690   OnDisabledBackgroundImageSet();
691   RelayoutRequest();
692 }
693
694 Actor& Button::GetDisabledBackgroundImage()
695 {
696   return mDisabledBackgroundContent;
697 }
698
699 std::string Button::GetUnselectedImageFilename() const
700 {
701   if( mUnselectedContent )
702   {
703     ResourceImage image = ResourceImage::DownCast( mUnselectedContent );
704     if( image )
705     {
706       return image.GetUrl();
707     }
708   }
709   return std::string();
710 }
711
712 std::string Button::GetSelectedImageFilename() const
713 {
714   if( mSelectedContent )
715   {
716     ResourceImage image = ResourceImage::DownCast( mSelectedContent );
717     if( image )
718     {
719       return image.GetUrl();
720     }
721   }
722   return std::string();
723 }
724
725 std::string Button::GetDisabledImageFilename() const
726 {
727   if( mDisabledContent )
728   {
729     ResourceImage image = ResourceImage::DownCast( mDisabledContent );
730     if( image )
731     {
732       return image.GetUrl();
733     }
734   }
735   return std::string();
736 }
737
738 bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
739 {
740   bool ret = false;
741
742   Dali::BaseHandle handle( object );
743
744   Toolkit::Button button = Toolkit::Button::DownCast( handle );
745
746   DALI_ASSERT_ALWAYS( button );
747
748   if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
749   {
750     ret = GetImplementation( button ).DoClickAction( attributes );
751   }
752
753   return ret;
754 }
755
756 bool Button::DoClickAction( const Property::Map& attributes )
757 {
758   // Prevents the button signals from doing a recursive loop by sending an action
759   // and re-emitting the signals.
760   if( !mClickActionPerforming )
761   {
762     mClickActionPerforming = true;
763     OnButtonDown();
764     mState = ButtonDown;
765     OnButtonUp();
766     mClickActionPerforming = false;
767
768     return true;
769   }
770
771   return false;
772 }
773
774 void Button::OnButtonDown()
775 {
776   if( !mTogglableButton )
777   {
778     Pressed();
779
780     if( mAutoRepeating )
781     {
782       SetUpTimer( mInitialAutoRepeatingDelay );
783     }
784   }
785
786   // The pressed signal should be emitted regardless of toggle mode.
787   Toolkit::Button handle( GetOwner() );
788   mPressedSignal.Emit( handle );
789 }
790
791 void Button::OnButtonUp()
792 {
793   if( ButtonDown == mState )
794   {
795     if( mTogglableButton )
796     {
797       SetSelected( !mSelected );
798     }
799     else
800     {
801       Released();
802
803       if( mAutoRepeating )
804       {
805         mAutoRepeatingTimer.Reset();
806       }
807     }
808
809     // The clicked and released signals should be emitted regardless of toggle mode.
810     Toolkit::Button handle( GetOwner() );
811     mReleasedSignal.Emit( handle );
812     mClickedSignal.Emit( handle );
813   }
814 }
815
816 void Button::OnTouchPointLeave()
817 {
818   if( ButtonDown == mState )
819   {
820     if( !mTogglableButton )
821     {
822       Released();
823
824       if( mAutoRepeating )
825       {
826         mAutoRepeatingTimer.Reset();
827       }
828     }
829
830     // The released signal should be emitted regardless of toggle mode.
831     Toolkit::Button handle( GetOwner() );
832     mReleasedSignal.Emit( handle );
833   }
834 }
835
836 void Button::OnTouchPointInterrupted()
837 {
838   OnTouchPointLeave();
839 }
840
841 Toolkit::Button::ButtonSignalType& Button::PressedSignal()
842 {
843   return mPressedSignal;
844 }
845
846 Toolkit::Button::ButtonSignalType& Button::ReleasedSignal()
847 {
848   return mReleasedSignal;
849 }
850
851 Toolkit::Button::ButtonSignalType& Button::ClickedSignal()
852 {
853   return mClickedSignal;
854 }
855
856 Toolkit::Button::ButtonSignalType& Button::StateChangedSignal()
857 {
858   return mStateChangedSignal;
859 }
860
861 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
862 {
863   Dali::BaseHandle handle( object );
864
865   bool connected( true );
866   Toolkit::Button button = Toolkit::Button::DownCast( handle );
867
868   if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) )
869   {
870     button.PressedSignal().Connect( tracker, functor );
871   }
872   else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) )
873   {
874     button.ReleasedSignal().Connect( tracker, functor );
875   }
876   else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) )
877   {
878     button.ClickedSignal().Connect( tracker, functor );
879   }
880   else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) )
881   {
882     button.StateChangedSignal().Connect( tracker, functor );
883   }
884   else
885   {
886     // signalName does not match any signal
887     connected = false;
888   }
889
890   return connected;
891 }
892
893 void Button::OnInitialize()
894 {
895   Actor self = Self();
896
897   mTapDetector = TapGestureDetector::New();
898   mTapDetector.Attach( self );
899   mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
900
901   self.SetKeyboardFocusable( true );
902
903   self.TouchSignal().Connect( this, &Button::OnTouch );
904 }
905
906 bool Button::OnAccessibilityActivated()
907 {
908   return OnKeyboardEnter();
909 }
910
911 bool Button::OnKeyboardEnter()
912 {
913   // When the enter key is pressed, or button is activated, the click action is performed.
914   Property::Map attributes;
915   bool ret = DoClickAction( attributes );
916
917   return ret;
918 }
919
920 void Button::OnStageDisconnection()
921 {
922   if( ButtonDown == mState )
923   {
924     if( !mTogglableButton )
925     {
926       Released();
927
928       if( mAutoRepeating )
929       {
930         mAutoRepeatingTimer.Reset();
931       }
932     }
933   }
934
935   mState = ButtonUp;
936
937   Control::OnStageDisconnection();
938 }
939
940 bool Button::OnTouch( Actor actor, const TouchData& touch )
941 {
942   // Only events are processed when the button is not disabled and the touch event has only
943   // one touch point.
944   if( ( !mDisabled ) && ( 1 == touch.GetPointCount() ) )
945   {
946     switch( touch.GetState( 0 ) )
947     {
948       case PointState::DOWN:
949       {
950         OnButtonDown(); // Notification for derived classes.
951
952         // Sets the button state to ButtonDown.
953         mState = ButtonDown;
954         break;
955       }
956       case PointState::UP:
957       {
958         OnButtonUp(); // Notification for derived classes.
959
960         // Sets the button state to ButtonUp.
961         mState = ButtonUp;
962         break;
963       }
964       case PointState::INTERRUPTED:
965       {
966         OnTouchPointInterrupted(); // Notification for derived classes.
967
968         // Sets the button state to the default (ButtonUp).
969         mState = ButtonUp;
970         break;
971       }
972       case PointState::LEAVE:
973       {
974         OnTouchPointLeave(); // Notification for derived classes.
975
976         // Sets the button state to the default (ButtonUp).
977         mState = ButtonUp;
978         break;
979       }
980       case PointState::MOTION:
981       case PointState::STATIONARY: // FALLTHROUGH
982       {
983         // Nothing to do
984         break;
985       }
986     }
987   }
988   else if( 1 < touch.GetPointCount() )
989   {
990     OnTouchPointLeave(); // Notification for derived classes.
991
992     // Sets the button state to the default (ButtonUp).
993     mState = ButtonUp;
994   }
995
996   return false;
997 }
998
999 void Button::OnTap(Actor actor, const TapGesture& tap)
1000 {
1001   // Do nothing.
1002 }
1003
1004 void Button::SetUpTimer( float delay )
1005 {
1006   mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
1007   mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
1008   mAutoRepeatingTimer.Start();
1009 }
1010
1011 bool Button::AutoRepeatingSlot()
1012 {
1013   bool consumed = false;
1014   if( !mDisabled )
1015   {
1016     // Restart the autorepeat timer.
1017     SetUpTimer( mNextAutoRepeatingDelay );
1018
1019     Pressed();
1020
1021     Toolkit::Button handle( GetOwner() );
1022
1023     //Emit signal.
1024     consumed = mReleasedSignal.Emit( handle );
1025     consumed |= mClickedSignal.Emit( handle );
1026     consumed |= mPressedSignal.Emit( handle );
1027  }
1028
1029   return consumed;
1030 }
1031
1032 void Button::Pressed()
1033 {
1034   if( mPaintState == UnselectedState )
1035   {
1036     StopTransitionAnimation();
1037
1038     // Notifies the derived class the button has been pressed.
1039     OnPressed();
1040
1041     //Layer Order
1042     //(4) mSelectedContent (Inserted)
1043     //(3) mUnselectedContent
1044     //(2) mSelectedBackgroundContent (Inserted)
1045     //(1) mBackgroundContent
1046
1047     AddButtonImage( mBackgroundContent );
1048     TransitionButtonImage( mSelectedBackgroundContent );
1049     AddButtonImage( mUnselectedContent );
1050     TransitionButtonImage( mSelectedContent );
1051
1052     AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
1053     TransitionButtonImage( mDecoration[ SELECTED_DECORATION ] );
1054     ReAddLabel();
1055
1056     TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
1057     TransitionOut( mUnselectedContent );
1058     TransitionOut( mDisabledContent );
1059     TransitionOut( mDisabledSelectedContent );
1060     TransitionOut( mDisabledBackgroundContent );
1061
1062     mPaintState = SelectedState;
1063
1064     StartTransitionAnimation();
1065   }
1066 }
1067
1068 void Button::Released()
1069 {
1070   if( mPaintState == SelectedState )
1071   {
1072     StopTransitionAnimation();
1073
1074     // Notifies the derived class the button has been released.
1075     OnReleased();
1076
1077     //Layer Order
1078     //(3) mUnselectedContent (Inserted)
1079     //(2) mSelectedContent
1080     //(1) mBackgroundContent
1081
1082     AddButtonImage( mBackgroundContent );
1083     AddButtonImage( mSelectedContent );
1084     TransitionButtonImage( mUnselectedContent );
1085
1086     AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
1087     TransitionButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
1088     ReAddLabel();
1089
1090     TransitionOut( mDecoration[ SELECTED_DECORATION ] );
1091     TransitionOut( mSelectedContent );
1092     TransitionOut( mSelectedBackgroundContent );
1093     TransitionOut( mDisabledContent );
1094     TransitionOut( mDisabledSelectedContent );
1095     TransitionOut( mDisabledBackgroundContent );
1096
1097     mPaintState = UnselectedState;
1098
1099     StartTransitionAnimation();
1100   }
1101 }
1102
1103 Button::ButtonState Button::GetState()
1104 {
1105   return mState;
1106 }
1107
1108 Button::PaintState Button::GetPaintState()
1109 {
1110   return mPaintState;
1111 }
1112
1113 void Button::PrepareAddButtonImage( Actor& actor )
1114 {
1115   if( actor )
1116   {
1117     Self().Add( actor );
1118     PrepareForTranstionOut( actor );
1119   }
1120 }
1121
1122 void Button::TransitionButtonImage( Actor& actor )
1123 {
1124   if( actor )
1125   {
1126     if( !actor.GetParent() )
1127     {
1128       Self().Add( actor );
1129     }
1130
1131     OnTransitionIn( actor );
1132   }
1133 }
1134
1135 void Button::AddButtonImage( Actor& actor )
1136 {
1137   if( actor )
1138   {
1139     Self().Add( actor );
1140   }
1141 }
1142
1143 void Button::ReAddLabel()
1144 {
1145   if( mLabel )
1146   {
1147     mLabel.Unparent();
1148     Self().Add( mLabel );
1149   }
1150 }
1151
1152 void Button::RemoveButtonImage( Actor& actor )
1153 {
1154   if( actor )
1155   {
1156     if( actor.GetParent() )
1157     {
1158       Self().Remove( actor );
1159     }
1160     PrepareForTranstionIn( actor );
1161   }
1162 }
1163
1164 unsigned int Button::FindChildIndex( Actor& actor )
1165 {
1166   Actor self = Self();
1167   unsigned int childrenNum = self.GetChildCount();
1168
1169   for( unsigned int i = 0; i < childrenNum; i++ )
1170   {
1171     Actor child = self.GetChildAt( i );
1172     if( child == actor )
1173     {
1174       return i;
1175     }
1176   }
1177
1178   return childrenNum;
1179 }
1180
1181 void Button::TransitionOut( Actor actor )
1182 {
1183   OnTransitionOut( actor );
1184 }
1185
1186 void Button::ResetImageLayers()
1187 {
1188   // Ensure that all layers are in the correct order and state according to the paint state
1189
1190   switch( mPaintState )
1191   {
1192     case UnselectedState:
1193     {
1194       //Layer Order
1195       //(2) mUnselectedContent
1196       //(1) mBackgroundContent
1197
1198       RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
1199       RemoveButtonImage( mSelectedContent );
1200       RemoveButtonImage( mSelectedBackgroundContent );
1201       RemoveButtonImage( mDisabledContent );
1202       RemoveButtonImage( mDisabledSelectedContent );
1203       RemoveButtonImage( mDisabledBackgroundContent );
1204
1205       PrepareAddButtonImage( mBackgroundContent );
1206       PrepareAddButtonImage( mUnselectedContent );
1207
1208       PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
1209       ReAddLabel();
1210       break;
1211     }
1212     case SelectedState:
1213     {
1214       //Layer Order
1215       //(3) mSelectedContent
1216       //(2) mSelectedBackgroundContent
1217       //(1) mBackgroundContent
1218
1219       RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
1220       RemoveButtonImage( mUnselectedContent );
1221       RemoveButtonImage( mDisabledContent );
1222       RemoveButtonImage( mDisabledSelectedContent );
1223       RemoveButtonImage( mDisabledBackgroundContent );
1224
1225       PrepareAddButtonImage( mBackgroundContent );
1226       PrepareAddButtonImage( mSelectedBackgroundContent );
1227       PrepareAddButtonImage( mSelectedContent );
1228
1229       PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
1230       ReAddLabel();
1231       break;
1232     }
1233     case DisabledUnselectedState:
1234     {
1235       //Layer Order
1236       //(2) mDisabledContent
1237       //(1) mDisabledBackgroundContent
1238
1239       RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
1240       RemoveButtonImage( mUnselectedContent );
1241       RemoveButtonImage( mBackgroundContent );
1242       RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
1243       RemoveButtonImage( mSelectedContent );
1244       RemoveButtonImage( mDisabledSelectedContent );
1245       RemoveButtonImage( mSelectedBackgroundContent );
1246
1247       PrepareAddButtonImage( mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent );
1248       PrepareAddButtonImage( mDisabledContent ? mDisabledContent : mUnselectedContent );
1249
1250       PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
1251       ReAddLabel();
1252       break;
1253     }
1254     case DisabledSelectedState:
1255     {
1256       //Layer Order
1257       // (2) mDisabledSelectedContent
1258       // (1) mDisabledBackgroundContent
1259
1260       RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
1261       RemoveButtonImage( mUnselectedContent );
1262       RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
1263       RemoveButtonImage( mSelectedContent );
1264       RemoveButtonImage( mBackgroundContent );
1265       RemoveButtonImage( mSelectedBackgroundContent );
1266       RemoveButtonImage( mDisabledContent );
1267
1268       if( mDisabledBackgroundContent )
1269       {
1270         PrepareAddButtonImage( mDisabledBackgroundContent );
1271       }
1272       else
1273       {
1274         PrepareAddButtonImage( mBackgroundContent );
1275         PrepareAddButtonImage( mSelectedBackgroundContent );
1276       }
1277
1278       PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent );
1279
1280       PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
1281       ReAddLabel();
1282       break;
1283     }
1284   }
1285 }
1286
1287 void Button::StartTransitionAnimation()
1288 {
1289   if( mTransitionAnimation )
1290   {
1291     mTransitionAnimation.Play();
1292   }
1293   else
1294   {
1295     ResetImageLayers();
1296   }
1297 }
1298
1299 void Button::StopTransitionAnimation()
1300 {
1301   if( mTransitionAnimation )
1302   {
1303     mTransitionAnimation.Clear();
1304     mTransitionAnimation.Reset();
1305   }
1306 }
1307
1308 Dali::Animation Button::GetTransitionAnimation()
1309 {
1310   if( !mTransitionAnimation )
1311   {
1312     mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
1313     mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished );
1314   }
1315
1316   return mTransitionAnimation;
1317 }
1318
1319 void Button::TransitionAnimationFinished( Dali::Animation& source )
1320 {
1321   StopTransitionAnimation();
1322   ResetImageLayers();
1323 }
1324
1325 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
1326 {
1327   Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1328
1329   if ( button )
1330   {
1331     switch ( index )
1332     {
1333       case Toolkit::Button::Property::DISABLED:
1334       {
1335         GetImplementation( button ).SetDisabled( value.Get< bool >() );
1336         break;
1337       }
1338
1339       case Toolkit::Button::Property::AUTO_REPEATING:
1340       {
1341         GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
1342         break;
1343       }
1344
1345       case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1346       {
1347         GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
1348         break;
1349       }
1350
1351       case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1352       {
1353         GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
1354         break;
1355       }
1356
1357       case Toolkit::Button::Property::TOGGLABLE:
1358       {
1359         GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
1360         break;
1361       }
1362
1363       case Toolkit::Button::Property::SELECTED:
1364       {
1365         GetImplementation( button ).SetSelected( value.Get< bool >() );
1366         break;
1367       }
1368
1369       case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
1370       {
1371         GetImplementation( button ).SetUnselectedImage( value.Get< std::string >() );
1372         break;
1373       }
1374
1375       case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
1376       {
1377         GetImplementation( button ).SetSelectedImage( value.Get< std::string >() );
1378         break;
1379       }
1380
1381       case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
1382       {
1383         GetImplementation( button ).SetDisabledImage( value.Get< std::string >() );
1384         break;
1385       }
1386
1387       case Toolkit::Button::Property::UNSELECTED_COLOR:
1388       {
1389         GetImplementation( button ).SetUnselectedColor( value.Get< Vector4 >() );
1390         break;
1391       }
1392
1393       case Toolkit::Button::Property::SELECTED_COLOR:
1394       {
1395         GetImplementation( button ).SetSelectedColor( value.Get< Vector4 >() );
1396         break;
1397       }
1398
1399       case Toolkit::Button::Property::LABEL_TEXT:
1400       {
1401         GetImplementation( button ).SetLabelText( value.Get< std::string >() );
1402         break;
1403       }
1404
1405       case Toolkit::Button::Property::LABEL:
1406       {
1407         // Get a Property::Map from the property if possible.
1408         Property::Map setPropertyMap;
1409         if( value.Get( setPropertyMap ) )
1410         {
1411           GetImplementation( button ).ModifyLabel( setPropertyMap );
1412         }
1413       }
1414       break;
1415     }
1416   }
1417 }
1418
1419 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
1420 {
1421   Property::Value value;
1422
1423   Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1424
1425   if ( button )
1426   {
1427     switch ( propertyIndex )
1428     {
1429       case Toolkit::Button::Property::DISABLED:
1430       {
1431         value = GetImplementation( button ).mDisabled;
1432         break;
1433       }
1434
1435       case Toolkit::Button::Property::AUTO_REPEATING:
1436       {
1437         value = GetImplementation( button ).mAutoRepeating;
1438         break;
1439       }
1440
1441       case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1442       {
1443         value = GetImplementation( button ).mInitialAutoRepeatingDelay;
1444         break;
1445       }
1446
1447       case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1448       {
1449         value = GetImplementation( button ).mNextAutoRepeatingDelay;
1450         break;
1451       }
1452
1453       case Toolkit::Button::Property::TOGGLABLE:
1454       {
1455         value = GetImplementation( button ).mTogglableButton;
1456         break;
1457       }
1458
1459       case Toolkit::Button::Property::SELECTED:
1460       {
1461         value = GetImplementation( button ).mSelected;
1462         break;
1463       }
1464
1465       case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
1466       {
1467         value = GetImplementation( button ).GetUnselectedImageFilename();
1468         break;
1469       }
1470
1471       case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
1472       {
1473         value = GetImplementation( button ).GetSelectedImageFilename();
1474         break;
1475       }
1476
1477       case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
1478       {
1479         value = GetImplementation( button ).GetDisabledImageFilename();
1480         break;
1481       }
1482
1483       case Toolkit::Button::Property::UNSELECTED_COLOR:
1484       {
1485         value = GetImplementation( button ).GetUnselectedColor();
1486         break;
1487       }
1488
1489       case Toolkit::Button::Property::SELECTED_COLOR:
1490       {
1491         value = GetImplementation( button ).GetSelectedColor();
1492         break;
1493       }
1494
1495       case Toolkit::Button::Property::LABEL_TEXT:
1496       {
1497         value = GetImplementation( button ).GetLabelText();
1498         break;
1499       }
1500
1501       case Toolkit::Button::Property::LABEL:
1502       {
1503         Property::Map emptyMap;
1504         value = emptyMap;
1505         break;
1506       }
1507     }
1508   }
1509
1510   return value;
1511 }
1512
1513 // Deprecated API
1514
1515 void Button::SetLabel( Actor label )
1516 {
1517   if( mLabel != label )
1518   {
1519     if( mLabel && mLabel.GetParent() )
1520     {
1521       mLabel.GetParent().Remove( mLabel );
1522     }
1523
1524     mLabel = label;
1525     mLabel.SetPosition( 0.0f, 0.0f );
1526
1527     // label should be the top of the button
1528     Self().Add( mLabel );
1529
1530     ResetImageLayers();
1531     OnLabelSet( true );
1532
1533     RelayoutRequest();
1534   }
1535 }
1536
1537 void Button::SetButtonImage( Actor image )
1538 {
1539   if( image )
1540   {
1541     StopTransitionAnimation();
1542
1543     SetupContent( mUnselectedContent, image );
1544
1545     OnUnselectedImageSet();
1546     RelayoutRequest();
1547   }
1548 }
1549
1550 void Button::SetSelectedImage( Actor image )
1551 {
1552   if( image )
1553   {
1554     StopTransitionAnimation();
1555
1556     SetupContent( mSelectedContent, image );
1557
1558     OnSelectedImageSet();
1559     RelayoutRequest();
1560   }
1561 }
1562
1563 void Button::SetBackgroundImage( Actor image )
1564 {
1565   if( image )
1566   {
1567     StopTransitionAnimation();
1568
1569     SetupContent( mBackgroundContent, image );
1570
1571     OnBackgroundImageSet();
1572     RelayoutRequest();
1573   }
1574 }
1575
1576 void Button::SetSelectedBackgroundImage( Actor image )
1577 {
1578   if( image )
1579   {
1580     StopTransitionAnimation();
1581
1582     SetupContent( mSelectedBackgroundContent, image );
1583
1584     OnSelectedBackgroundImageSet();
1585     RelayoutRequest();
1586   }
1587 }
1588
1589 void Button::SetDisabledImage( Actor image )
1590 {
1591   if( image )
1592   {
1593     StopTransitionAnimation();
1594
1595     SetupContent( mDisabledContent, image );
1596
1597     OnDisabledImageSet();
1598     RelayoutRequest();
1599   }
1600 }
1601
1602 void Button::SetDisabledSelectedImage( Actor image )
1603 {
1604   if( image )
1605   {
1606     StopTransitionAnimation();
1607
1608     SetupContent( mDisabledSelectedContent, image );
1609
1610     OnDisabledSelectedImageSet();
1611     RelayoutRequest();
1612   }
1613 }
1614
1615 void Button::SetDisabledBackgroundImage( Actor image )
1616 {
1617   if( image )
1618   {
1619     StopTransitionAnimation();
1620
1621     SetupContent( mDisabledBackgroundContent, image );
1622
1623     OnDisabledBackgroundImageSet();
1624     RelayoutRequest();
1625   }
1626 }
1627
1628 Actor Button::GetButtonImage() const
1629 {
1630   return mUnselectedContent;
1631 }
1632
1633 Actor Button::GetSelectedImage() const
1634 {
1635   return mSelectedContent;
1636 }
1637
1638
1639 } // namespace Internal
1640
1641 } // namespace Toolkit
1642
1643 } // namespace Dali