2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "check-box-button-impl.h"
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/type-registry.h>
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>
30 #if defined(DEBUG_ENABLED)
31 extern Debug::Filter* gLogButtonFilter;
44 return Toolkit::CheckBoxButton::New();
47 TypeRegistration mType(typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create);
51 Dali::Toolkit::CheckBoxButton CheckBoxButton::New()
53 // Create the implementation, temporarily owned on stack
54 IntrusivePtr<CheckBoxButton> internalCheckBoxButton = new CheckBoxButton();
56 // Pass ownership to CustomActor
57 Dali::Toolkit::CheckBoxButton checkBoxButton(*internalCheckBoxButton);
59 // Second-phase init of the implementation
60 // This can only be done after the CustomActor connection has been made...
61 internalCheckBoxButton->Initialize();
63 return checkBoxButton;
66 CheckBoxButton::CheckBoxButton()
69 SetTogglableButton(true);
72 CheckBoxButton::~CheckBoxButton()
76 void CheckBoxButton::OnInitialize()
78 Button::OnInitialize();
80 Self().SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::CHECK_BOX);
83 DevelControl::ControlAccessible* CheckBoxButton::CreateAccessibleObject()
85 return new CheckBoxButton::CheckBoxButtonAccessible(Self());
88 Dali::Accessibility::States CheckBoxButton::CheckBoxButtonAccessible::CalculateStates()
90 auto state = Button::ButtonAccessible::CalculateStates();
91 auto self = Toolkit::Button::DownCast(Self());
92 if(self.GetProperty<bool>(Toolkit::Button::Property::SELECTED))
94 state[Dali::Accessibility::State::CHECKED] = true;
99 void CheckBoxButton::OnStateChange(State newState)
101 // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used
102 if((Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor() == Self()) && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
104 GetAccessibleObject()->EmitStateChanged(Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0);
108 } // namespace Internal
110 } // namespace Toolkit