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