45c50579fb6a86344d7dc583ebe952573808bca8
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / check-box-button-impl.cpp
1 /*
2  * Copyright (c) 2020 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 "check-box-button-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/type-registry.h>
24
25 //INTERNAL INCLUDES
26 #include <dali-toolkit/internal/controls/image-view/image-view-impl.h>
27 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
28 #include <dali-toolkit/devel-api/shader-effects/image-region-effect.h>
29 #include <dali-toolkit/devel-api/shader-effects/image-region-effect.h>
30
31 #if defined(DEBUG_ENABLED)
32   extern Debug::Filter* gLogButtonFilter;
33 #endif
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 namespace
45 {
46
47 BaseHandle Create()
48 {
49   return Toolkit::CheckBoxButton::New();
50 }
51
52 TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create );
53
54
55
56 }
57
58 Dali::Toolkit::CheckBoxButton CheckBoxButton::New()
59 {
60   // Create the implementation, temporarily owned on stack
61   IntrusivePtr< CheckBoxButton > internalCheckBoxButton = new CheckBoxButton();
62
63   // Pass ownership to CustomActor
64   Dali::Toolkit::CheckBoxButton checkBoxButton( *internalCheckBoxButton );
65
66   // Second-phase init of the implementation
67   // This can only be done after the CustomActor connection has been made...
68   internalCheckBoxButton->Initialize();
69
70   return checkBoxButton;
71 }
72
73 CheckBoxButton::CheckBoxButton()
74 : Button()
75 {
76   SetTogglableButton( true );
77   DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) {
78     return std::unique_ptr< Dali::Accessibility::Accessible >(
79         new AccessibleImpl( actor, Dali::Accessibility::Role::CHECK_BOX ) );
80   } );
81 }
82
83 CheckBoxButton::~CheckBoxButton()
84 {
85 }
86
87 void CheckBoxButton::OnInitialize()
88 {
89   Button::OnInitialize();
90 }
91
92 Dali::Accessibility::States CheckBoxButton::AccessibleImpl::CalculateStates()
93 {
94   auto tmp = Button::AccessibleImpl::CalculateStates();
95   auto slf = Toolkit::Button::DownCast( self );
96   if( slf.GetProperty<bool>( Toolkit::Button::Property::SELECTED ) )
97     tmp[Dali::Accessibility::State::CHECKED] = true;
98   return tmp;
99 }
100
101 void CheckBoxButton::OnStateChange( State newState )
102 {
103   // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used
104   if (Dali::Accessibility::IsUp() && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
105   {
106     Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(
107       Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0
108     );
109   }
110 }
111
112 } // namespace Internal
113
114 } // namespace Toolkit
115
116 } // namespace Dali