eef0cd8970d93e1b7fb71b53017ac67316b3b69c
[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 <dali/public-api/events/touch-event.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/public-api/actors/image-actor.h>
25 #include <dali/public-api/scripting/scripting.h>
26 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 const Property::Index Button::PROPERTY_DISABLED                     = Internal::Button::BUTTON_PROPERTY_START_INDEX;
35 const Property::Index Button::PROPERTY_AUTO_REPEATING               = Internal::Button::BUTTON_PROPERTY_START_INDEX + 1;
36 const Property::Index Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_START_INDEX + 2;
37 const Property::Index Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY    = Internal::Button::BUTTON_PROPERTY_START_INDEX + 3;
38 const Property::Index Button::PROPERTY_TOGGLABLE                    = Internal::Button::BUTTON_PROPERTY_START_INDEX + 4;
39 const Property::Index Button::PROPERTY_SELECTED                     = Internal::Button::BUTTON_PROPERTY_START_INDEX + 5;
40 const Property::Index Button::PROPERTY_NORMAL_STATE_ACTOR           = Internal::Button::BUTTON_PROPERTY_START_INDEX + 6;
41 const Property::Index Button::PROPERTY_SELECTED_STATE_ACTOR         = Internal::Button::BUTTON_PROPERTY_START_INDEX + 7;
42 const Property::Index Button::PROPERTY_DISABLED_STATE_ACTOR         = Internal::Button::BUTTON_PROPERTY_START_INDEX + 8;
43 const Property::Index Button::PROPERTY_LABEL_ACTOR                  = Internal::Button::BUTTON_PROPERTY_START_INDEX + 9;
44
45 namespace Internal
46 {
47
48 namespace
49 {
50
51 const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
52 const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
53
54 BaseHandle Create()
55 {
56   // empty handle as we cannot create button (but type registered for clicked signal)
57   return BaseHandle();
58 }
59
60 TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Control), Create );
61
62 SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_PRESSED , &Button::DoConnectSignal );
63 SignalConnectorType signalConnector2( typeRegistration, Toolkit::Button::SIGNAL_RELEASED, &Button::DoConnectSignal );
64 SignalConnectorType signalConnector3( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal );
65 SignalConnectorType signalConnector4( typeRegistration, Toolkit::Button::SIGNAL_STATE_CHANGED, &Button::DoConnectSignal );
66
67 TypeAction action1( typeRegistration, Toolkit::Button::ACTION_BUTTON_CLICK, &Button::DoAction );
68
69 PropertyRegistration property1( typeRegistration, "disabled",                     Toolkit::Button::PROPERTY_DISABLED,                     Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
70 PropertyRegistration property2( typeRegistration, "auto-repeating",               Toolkit::Button::PROPERTY_AUTO_REPEATING,               Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
71 PropertyRegistration property3( typeRegistration, "initial-auto-repeating-delay", Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, Property::FLOAT,   &Button::SetProperty, &Button::GetProperty );
72 PropertyRegistration property4( typeRegistration, "next-auto-repeating-delay",    Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY,    Property::FLOAT,   &Button::SetProperty, &Button::GetProperty );
73 PropertyRegistration property5( typeRegistration, "togglable",                    Toolkit::Button::PROPERTY_TOGGLABLE,                    Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
74 PropertyRegistration property6( typeRegistration, "selected",                     Toolkit::Button::PROPERTY_SELECTED,                     Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
75 PropertyRegistration property7( typeRegistration, "normal-state-actor",           Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR,           Property::MAP,     &Button::SetProperty, &Button::GetProperty );
76 PropertyRegistration property8( typeRegistration, "selected-state-actor",         Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR,         Property::MAP,     &Button::SetProperty, &Button::GetProperty );
77 PropertyRegistration property9( typeRegistration, "disabled-state-actor",         Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR,         Property::MAP,     &Button::SetProperty, &Button::GetProperty );
78 PropertyRegistration property10( typeRegistration, "label-actor",                 Toolkit::Button::PROPERTY_LABEL_ACTOR,                  Property::MAP,     &Button::SetProperty, &Button::GetProperty );
79
80 } // unnamed namespace
81
82 Button::Button()
83 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
84   mTogglableButton( false ),
85   mSelected( false ),
86   mPainter( NULL ),
87   mAutoRepeatingTimer(),
88   mDisabled( false ),
89   mAutoRepeating( false ),
90 //  mTogglableButton( false ),
91 //  mSelected( false ),
92   mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ),
93   mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
94   mClickActionPerforming( false ),
95   mState( ButtonUp )
96 {
97 }
98
99 Button::~Button()
100 {
101   if( mAutoRepeatingTimer )
102   {
103     mAutoRepeatingTimer.Reset();
104   }
105 }
106
107 void Button::SetDisabled( bool disabled )
108 {
109   mDisabled = disabled;
110
111   // Notifies the painter.
112   Toolkit::Button handle( GetOwner() );
113   if( mPainter )
114   {
115     mPainter->SetDisabled( handle, mDisabled );
116   }
117 }
118
119 bool Button::IsDisabled() const
120 {
121   return mDisabled;
122 }
123
124 void Button::SetAutoRepeating( bool autoRepeating )
125 {
126   mAutoRepeating = autoRepeating;
127
128   // An autorepeating button can't be a togglable button.
129   if( autoRepeating )
130   {
131     mTogglableButton = false;
132     if( mSelected )
133     {
134       // Emit a signal is not wanted, only change the appearance.
135       Toolkit::Button handle( GetOwner() );
136       mPainter->Selected( handle );
137       mSelected = false;
138     }
139   }
140
141   // Notifies the painter.
142   mPainter->SetAutoRepeating( mAutoRepeating );
143 }
144
145 bool Button::IsAutoRepeating() const
146 {
147   return mAutoRepeating;
148 }
149
150 void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
151 {
152   DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f );
153   mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
154 }
155
156 float Button::GetInitialAutoRepeatingDelay() const
157 {
158   return mInitialAutoRepeatingDelay;
159 }
160
161 void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
162 {
163   DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
164   mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
165 }
166
167 float Button::GetNextAutoRepeatingDelay() const
168 {
169   return mNextAutoRepeatingDelay;
170 }
171
172 void Button::SetTogglableButton( bool togglable )
173 {
174   mTogglableButton = togglable;
175
176   // A togglable button can't be an autorepeating button.
177   if( togglable )
178   {
179     mAutoRepeating = false;
180
181     // Notifies the painter.
182     mPainter->SetAutoRepeating( mAutoRepeating );
183   }
184 }
185
186 bool Button::IsTogglableButton() const
187 {
188   return mTogglableButton;
189 }
190
191 void Button::SetSelected( bool selected )
192 {
193   if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
194   {
195     mSelected = selected;
196
197     Toolkit::Button handle( GetOwner() );
198
199     // Notifies the painter the button has been selected.
200     mPainter->Selected( handle );
201
202     // Emit signal.
203     mStateChangedSignal.Emit( handle );
204   }
205 }
206
207 bool Button::IsSelected() const
208 {
209   return mTogglableButton && mSelected;
210 }
211
212 void Button::SetAnimationTime( float animationTime )
213 {
214   OnAnimationTimeSet( animationTime );
215 }
216
217 float Button::GetAnimationTime() const
218 {
219   return OnAnimationTimeRequested();
220 }
221
222 void Button::SetLabel( const std::string& label )
223 {
224   Toolkit::TextView textView = Toolkit::TextView::New( label );
225   textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button
226   SetLabel( textView );
227
228   RelayoutRequest();
229 }
230
231 void Button::SetLabel( Actor label )
232 {
233   Toolkit::Button handle( GetOwner() );
234
235   mPainter->SetLabel( handle, label );
236 }
237
238 Actor Button::GetLabel() const
239 {
240   return mLabel;
241 }
242
243 Actor& Button::GetLabel()
244 {
245   return mLabel;
246 }
247
248 void Button::SetButtonImage( Image image )
249 {
250   SetButtonImage( ImageActor::New( image ) );
251 }
252
253 void Button::SetButtonImage( Actor image )
254 {
255   Toolkit::Button handle( GetOwner() );
256   mPainter->SetButtonImage( handle, image );
257 }
258
259 Actor Button::GetButtonImage() const
260 {
261   return mButtonImage;
262 }
263
264 Actor& Button::GetButtonImage()
265 {
266   return mButtonImage;
267 }
268
269 void Button::SetSelectedImage( Image image )
270 {
271   SetSelectedImage( ImageActor::New( image ) );
272 }
273
274 void Button::SetSelectedImage( Actor image )
275 {
276   Toolkit::Button handle( GetOwner() );
277   mPainter->SetSelectedImage( handle, image );
278 }
279
280 Actor Button::GetSelectedImage() const
281 {
282   return mSelectedImage;
283 }
284
285 Actor& Button::GetSelectedImage()
286 {
287   return mSelectedImage;
288 }
289
290 void Button::SetBackgroundImage( Image image )
291 {
292   SetBackgroundImage( ImageActor::New( image ) );
293 }
294
295 void Button::SetBackgroundImage( Actor image )
296 {
297   Toolkit::Button handle( GetOwner() );
298   mPainter->SetBackgroundImage( handle, image );
299 }
300
301 Actor Button::GetBackgroundImage() const
302 {
303   return mBackgroundImage;
304 }
305
306 Actor& Button::GetBackgroundImage()
307 {
308   return mBackgroundImage;
309 }
310
311 void Button::SetDisabledImage( Image image )
312 {
313   SetDisabledImage( ImageActor::New( image ) );
314 }
315
316 void Button::SetDisabledImage( Actor image )
317 {
318   Toolkit::Button handle( GetOwner() );
319   mPainter->SetDisabledImage( handle, image );
320 }
321
322 Actor Button::GetDisabledImage() const
323 {
324   return mDisabledImage;
325 }
326
327 Actor& Button::GetDisabledImage()
328 {
329   return mDisabledImage;
330 }
331
332 void Button::SetDisabledSelectedImage( Image image )
333 {
334   SetDisabledSelectedImage( ImageActor::New( image ) );
335 }
336
337 void Button::SetDisabledSelectedImage( Actor image )
338 {
339   Toolkit::Button handle( GetOwner() );
340   mPainter->SetDisabledSelectedImage( handle, image );
341 }
342
343 Actor Button::GetDisabledSelectedImage() const
344 {
345   return mDisabledSelectedImage;
346 }
347
348 Actor& Button::GetDisabledSelectedImage()
349 {
350   return mDisabledSelectedImage;
351 }
352
353 void Button::SetDisabledBackgroundImage( Image image )
354 {
355   SetDisabledBackgroundImage( ImageActor::New( image ) );
356 }
357
358 void Button::SetDisabledBackgroundImage( Actor image )
359 {
360   Toolkit::Button handle( GetOwner() );
361   mPainter->SetDisabledBackgroundImage( handle, image );
362 }
363
364 Actor Button::GetDisabledBackgroundImage() const
365 {
366   return mDisabledBackgroundImage;
367 }
368
369 Actor& Button::GetDisabledBackgroundImage()
370 {
371   return mDisabledBackgroundImage;
372 }
373
374 Actor& Button::GetFadeOutButtonImage()
375 {
376   return mFadeOutButtonImage;
377 }
378
379 Actor& Button::GetFadeOutSelectedImage()
380 {
381   return mFadeOutSelectedImage;
382 }
383
384 Actor& Button::GetFadeOutBackgroundImage()
385 {
386   return mFadeOutBackgroundImage;
387 }
388
389 bool Button::DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes )
390 {
391   bool ret = false;
392
393   Dali::BaseHandle handle( object );
394
395   Toolkit::Button button = Toolkit::Button::DownCast( handle );
396
397   DALI_ASSERT_ALWAYS( button );
398
399   if( Toolkit::Button::ACTION_BUTTON_CLICK == actionName )
400   {
401     GetImplementation( button ).DoClickAction( attributes );
402     ret = true;
403   }
404
405   return ret;
406 }
407
408 void Button::DoClickAction( const PropertyValueContainer& attributes )
409 {
410   // Prevents the button signals from doing a recursive loop by sending an action
411   // and re-emitting the signals.
412   if( !mClickActionPerforming )
413   {
414     mClickActionPerforming = true;
415     OnButtonDown();
416     mState = ButtonDown;
417     OnButtonUp();
418     mClickActionPerforming = false;
419   }
420 }
421
422 void Button::OnAnimationTimeSet( float animationTime )
423 {
424   mPainter->SetAnimationTime( animationTime );
425 }
426
427 float Button::OnAnimationTimeRequested() const
428 {
429   return mPainter->GetAnimationTime();
430 }
431
432 void Button::OnButtonStageDisconnection()
433 {
434   if( ButtonDown == mState )
435   {
436     if( !mTogglableButton )
437     {
438       Toolkit::Button handle( GetOwner() );
439
440       // Notifies the painter the button has been released.
441       mPainter->Released( handle );
442
443       if( mAutoRepeating )
444       {
445         mAutoRepeatingTimer.Reset();
446       }
447     }
448   }
449 }
450
451 void Button::OnButtonDown()
452 {
453   if( !mTogglableButton )
454   {
455     Toolkit::Button handle( GetOwner() );
456
457     // Notifies the painter the button has been pressed.
458     mPainter->Pressed( handle );
459
460     if( mAutoRepeating )
461     {
462       SetUpTimer( mInitialAutoRepeatingDelay );
463     }
464
465     //Emit signal.
466     mPressedSignal.Emit( handle );
467   }
468 }
469
470 void Button::OnButtonUp()
471 {
472   if( ButtonDown == mState )
473   {
474     if( mTogglableButton )
475     {
476       SetSelected( !mSelected );
477     }
478     else
479     {
480       Toolkit::Button handle( GetOwner() );
481
482       // Notifies the painter the button has been clicked.
483       mPainter->Released( handle );
484       mPainter->Clicked( handle );
485
486       if( mAutoRepeating )
487       {
488         mAutoRepeatingTimer.Reset();
489       }
490
491       //Emit signal.
492       mReleasedSignal.Emit( handle );
493       mClickedSignal.Emit( handle );
494     }
495   }
496 }
497
498 void Button::OnTouchPointLeave()
499 {
500   if( ButtonDown == mState )
501   {
502     if( !mTogglableButton )
503     {
504       Toolkit::Button handle( GetOwner() );
505
506       // Notifies the painter the button has been released.
507       mPainter->Released( handle );
508
509       if( mAutoRepeating )
510       {
511         mAutoRepeatingTimer.Reset();
512       }
513
514       //Emit signal.
515       mReleasedSignal.Emit( handle );
516     }
517   }
518 }
519
520 void Button::OnTouchPointInterrupted()
521 {
522   OnTouchPointLeave();
523 }
524
525 Toolkit::Button::ButtonSignalType& Button::PressedSignal()
526 {
527   return mPressedSignal;
528 }
529
530 Toolkit::Button::ButtonSignalType& Button::ReleasedSignal()
531 {
532   return mReleasedSignal;
533 }
534
535 Toolkit::Button::ButtonSignalType& Button::ClickedSignal()
536 {
537   return mClickedSignal;
538 }
539
540 Toolkit::Button::ButtonSignalType& Button::StateChangedSignal()
541 {
542   return mStateChangedSignal;
543 }
544
545 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
546 {
547   Dali::BaseHandle handle( object );
548
549   bool connected( true );
550   Toolkit::Button button = Toolkit::Button::DownCast(handle);
551
552   if( Toolkit::Button::SIGNAL_PRESSED == signalName )
553   {
554     button.PressedSignal().Connect( tracker, functor );
555   }
556   else if( Toolkit::Button::SIGNAL_RELEASED == signalName )
557   {
558     button.ReleasedSignal().Connect( tracker, functor );
559   }
560   else if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName )
561   {
562     button.ClickedSignal().Connect( tracker, functor );
563   }
564   else if( Dali::Toolkit::Button::SIGNAL_STATE_CHANGED == signalName )
565   {
566     button.StateChangedSignal().Connect( tracker, functor );
567   }
568   else
569   {
570     // signalName does not match any signal
571     connected = false;
572   }
573
574   return connected;
575 }
576
577 bool Button::OnTouchEvent(const TouchEvent& event)
578 {
579   // Only events are processed when the button is not disabled and the touch event has only
580   // one touch point.
581   if( ( !mDisabled ) && ( 1 == event.GetPointCount() ) )
582   {
583     switch( event.GetPoint(0).state )
584     {
585       case TouchPoint::Down:
586       {
587         OnButtonDown(); // Notification for derived classes.
588
589         // Sets the button state to ButtonDown.
590         mState = ButtonDown;
591         break;
592       }
593       case TouchPoint::Up:
594       {
595         OnButtonUp(); // Notification for derived classes.
596
597         // Sets the button state to ButtonUp.
598         mState = ButtonUp;
599         break;
600       }
601       case TouchPoint::Interrupted:
602       {
603         OnTouchPointInterrupted(); // Notification for derived classes.
604
605         // Sets the button state to the default (ButtonUp).
606         mState = ButtonUp;
607         break;
608       }
609       case TouchPoint::Leave:
610       {
611         OnTouchPointLeave(); // Notification for derived classes.
612
613         // Sets the button state to the default (ButtonUp).
614         mState = ButtonUp;
615         break;
616       }
617       case TouchPoint::Motion:
618       case TouchPoint::Stationary: // FALLTHROUGH
619       {
620         // Nothing to do
621         break;
622       }
623       default:
624       {
625         DALI_ASSERT_ALWAYS( !"Point status unhandled." );
626         break;
627       }
628     }
629   }
630   else if( 1 < event.GetPointCount() )
631   {
632     OnTouchPointLeave(); // Notification for derived classes.
633
634     // Sets the button state to the default (ButtonUp).
635     mState = ButtonUp;
636   }
637
638   return false;
639 }
640
641 void Button::OnInitialize()
642 {
643   // Initialize the painter and notifies subclasses.
644   Toolkit::Button handle( GetOwner() );
645   if( mPainter )
646   {
647     mPainter->Initialize( handle );
648   }
649
650   Actor self = Self();
651
652   mTapDetector = TapGestureDetector::New();
653   mTapDetector.Attach( self );
654   mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
655
656   OnButtonInitialize();
657
658   self.SetKeyboardFocusable( true );
659 }
660
661 void Button::OnActivated()
662 {
663   // When the button is activated, it performs the click action
664   PropertyValueContainer attributes;
665   DoClickAction( attributes );
666 }
667
668 void Button::OnControlSizeSet(const Vector3& targetSize)
669 {
670   Toolkit::Button handle( GetOwner() );
671   if( mPainter )
672   {
673     mPainter->SetSize( handle, targetSize );
674   }
675 }
676
677 void Button::OnTap(Actor actor, const TapGesture& tap)
678 {
679   // Do nothing.
680 }
681
682 void Button::SetUpTimer( float delay )
683 {
684   mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
685   mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
686   mAutoRepeatingTimer.Start();
687 }
688
689 bool Button::AutoRepeatingSlot()
690 {
691   bool consumed = false;
692   if( !mDisabled )
693   {
694     // Restart the autorepeat timer.
695     SetUpTimer( mNextAutoRepeatingDelay );
696
697     Toolkit::Button handle( GetOwner() );
698
699     // Notifies the painter the button has been pressed.
700     mPainter->Pressed( handle );
701
702     //Emit signal.
703     consumed = mReleasedSignal.Emit( handle );
704     consumed |= mClickedSignal.Emit( handle );
705     consumed |= mPressedSignal.Emit( handle );
706  }
707
708   return consumed;
709 }
710
711 void Button::OnControlStageDisconnection()
712 {
713   OnButtonStageDisconnection(); // Notification for derived classes.
714   mState = ButtonUp;
715 }
716
717 void Button::SetPainter(ButtonPainterPtr painter)
718 {
719   mPainter = painter;
720 }
721
722 Button::ButtonState Button::GetState()
723 {
724   return mState;
725 }
726
727 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
728 {
729   Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
730
731   if ( button )
732   {
733     switch ( index )
734     {
735       case Toolkit::Button::PROPERTY_DISABLED:
736       {
737         GetImplementation( button ).SetDisabled( value.Get<bool>() );
738         break;
739       }
740
741       case Toolkit::Button::PROPERTY_AUTO_REPEATING:
742       {
743         GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
744         break;
745       }
746
747       case Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY:
748       {
749         GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
750         break;
751       }
752
753       case Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY:
754       {
755         GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
756         break;
757       }
758
759       case Toolkit::Button::PROPERTY_TOGGLABLE:
760       {
761         GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
762         break;
763       }
764
765       case Toolkit::Button::PROPERTY_SELECTED:
766       {
767         GetImplementation( button ).SetSelected( value.Get< bool >() );
768         break;
769       }
770
771       case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR:
772       {
773         GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) );
774         break;
775       }
776
777       case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR:
778       {
779         GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) );
780         break;
781       }
782
783       case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR:
784       {
785         GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
786         break;
787       }
788
789       case Toolkit::Button::PROPERTY_LABEL_ACTOR:
790       {
791         GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
792         break;
793       }
794     }
795   }
796 }
797
798 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
799 {
800   Property::Value value;
801
802   Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
803
804   if ( button )
805   {
806     switch ( propertyIndex )
807     {
808       case Toolkit::Button::PROPERTY_DISABLED:
809       {
810         value = GetImplementation( button ).mDisabled;
811         break;
812       }
813
814       case Toolkit::Button::PROPERTY_AUTO_REPEATING:
815       {
816         value = GetImplementation( button ).mAutoRepeating;
817         break;
818       }
819
820       case Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY:
821       {
822         value = GetImplementation( button ).mInitialAutoRepeatingDelay;
823         break;
824       }
825
826       case Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY:
827       {
828         value = GetImplementation( button ).mNextAutoRepeatingDelay;
829         break;
830       }
831
832       case Toolkit::Button::PROPERTY_TOGGLABLE:
833       {
834         value = GetImplementation( button ).mTogglableButton;
835         break;
836       }
837
838       case Toolkit::Button::PROPERTY_SELECTED:
839       {
840         value = GetImplementation( button ).mSelected;
841         break;
842       }
843
844       case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR:
845       {
846         Property::Map map;
847         Scripting::CreatePropertyMap( GetImplementation( button ).mButtonImage, map );
848         value = map;
849         break;
850       }
851
852       case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR:
853       {
854         Property::Map map;
855         Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedImage, map );
856         value = map;
857         break;
858       }
859
860       case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR:
861       {
862         Property::Map map;
863         Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledImage, map );
864         value = map;
865         break;
866       }
867
868       case Toolkit::Button::PROPERTY_LABEL_ACTOR:
869       {
870         Property::Map map;
871         Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map );
872         value = map;
873         break;
874       }
875     }
876   }
877
878   return value;
879 }
880
881 } // namespace Internal
882
883 } // namespace Toolkit
884
885 } // namespace Dali