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