[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / toggle-button-impl.cpp
index 1b6ef02..1479e35 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -144,11 +144,22 @@ void ToggleButton::SetProperty(BaseObject* object, Property::Index propertyIndex
           std::vector<std::string> tips;
           size_t                   tipsCount = tipArray->Count();
           tips.resize(tipsCount);
+
+          bool valid = true;
           for(size_t i = 0; i != tipsCount; ++i)
           {
-            tipArray->GetElementAt(i).Get(tips[i]);
+            if(DALI_UNLIKELY(!tipArray->GetElementAt(i).Get(tips[i])))
+            {
+              // Given array is invalid. Fast out.
+              valid = false;
+              break;
+            }
+          }
+
+          if(DALI_LIKELY(valid))
+          {
+            toggleButtonImpl.SetToggleTooltips(tips);
           }
-          toggleButtonImpl.SetToggleTooltips(tips);
         }
         break;
       }
@@ -176,8 +187,7 @@ Property::Value ToggleButton::GetProperty(BaseObject* object, Property::Index pr
     {
       case Toolkit::ToggleButton::Property::STATE_VISUALS:
       {
-        Property::Array array = toggleButtonImpl.GetToggleStates();
-        value                 = Property::Value(array);
+        value = toggleButtonImpl.GetToggleStates();
         break;
       }
       case Toolkit::ToggleButton::Property::TOOLTIPS:
@@ -357,7 +367,7 @@ void ToggleButton::OnPressed()
 {
   DALI_LOG_INFO(gLogButtonFilter, Debug::General, "ToggleButton::OnPressed\n");
   // State index will add 1 only when button is pressed.
-  mCurrentToggleIndex = (mCurrentToggleIndex + 1) % mToggleVisuals.size();
+  mCurrentToggleIndex = (mCurrentToggleIndex + 1) % static_cast<uint32_t>(mToggleVisuals.size());
 
   // Both create SelectedVisual and UnselectedVisual
   PrepareVisual(Toolkit::Button::Property::UNSELECTED_VISUAL, mToggleVisuals[mCurrentToggleIndex]);
@@ -402,12 +412,14 @@ Property::Index ToggleButton::ToggleButtonAccessible::GetDescriptionPropertyInde
 void ToggleButton::OnStateChange(State newState)
 {
   // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used
-  if((Self() == Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor()) && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
+  if(newState == SELECTED_STATE || newState == UNSELECTED_STATE)
   {
     auto* accessible = GetAccessibleObject();
-
-    accessible->EmitStateChanged(Dali::Accessibility::State::CHECKED, mCurrentToggleIndex ? 1 : 0, 0);
-    accessible->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
+    if(DALI_LIKELY(accessible) && accessible->IsHighlighted())
+    {
+      accessible->EmitStateChanged(Dali::Accessibility::State::CHECKED, mCurrentToggleIndex ? 1 : 0, 0);
+      accessible->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
+    }
   }
 }