6300fe27abc23520871585fa043df552693ae54b
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H
2 #define DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
26 #include "button-impl.h"
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal
33 {
34 /**
35  * PushButton implementation class.
36  *
37  * \sa Dali::Toolkit::PushButton
38  */
39 class PushButton : public Button
40 {
41 public:
42   /**
43    * Create a new PushButton.
44    * @return A smart-pointer to the newly allocated PushButton.
45    */
46   static Dali::Toolkit::PushButton New();
47
48 protected:
49   /**
50    * Construct a new PushButton.
51    */
52   PushButton();
53
54   /**
55    * A reference counted object may only be deleted by calling Unreference()
56    */
57   virtual ~PushButton();
58
59 public:
60   // Properties
61
62   /**
63    * Enum for the alignment modes of the icon.
64    */
65   enum IconAlignment
66   {
67     LEFT,
68     RIGHT,
69     TOP,
70     BOTTOM,
71     DEFAULT = RIGHT
72   };
73
74   /**
75    * Called when a property of an object of this type is set.
76    * @param[in] object The object whose property is set.
77    * @param[in] index The property index.
78    * @param[in] value The new property value.
79    */
80   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
81
82   /**
83    * Called to retrieve a property of an object of this type.
84    * @param[in] object The object whose property is to be retrieved.
85    * @param[in] index The property index.
86    * @return The current value of the property.
87    */
88   static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
89
90 private: // From Button
91   /**
92    * @copydoc Toolkit::Internal::Button::OnInitialize
93    */
94   void OnInitialize() override;
95
96 private:
97   /**
98    * @brief Sets the alignment mode to use to align the icon to the label.
99    *
100    * @param[in] iconAlignment The alignment mode to use
101    */
102   void SetIconAlignment(const PushButton::IconAlignment iconAlignment);
103
104   /**
105    * @brief Gets the alignment mode used to align the icon to the label.
106    *
107    * @return The alignment mode in use
108    */
109   const PushButton::IconAlignment GetIconAlignment() const;
110
111 private:
112   // Undefined
113   PushButton(const PushButton&);
114
115   // Undefined
116   PushButton& operator=(const PushButton&);
117
118 private:
119   IconAlignment mIconAlignment; ///< The alignment of the icon against the label.
120
121 protected:
122   struct AccessibleImpl : public Button::AccessibleImpl
123   {
124     using Button::AccessibleImpl::AccessibleImpl;
125
126     Dali::Accessibility::States CalculateStates() override;
127   };
128   void OnStateChange(State newState) override;
129 };
130
131 } // namespace Internal
132
133 // Helpers for public-api forwarding methods
134
135 inline Toolkit::Internal::PushButton& GetImplementation(Toolkit::PushButton& button)
136 {
137   DALI_ASSERT_ALWAYS(button);
138
139   Dali::RefObject& handle = button.GetImplementation();
140
141   return static_cast<Toolkit::Internal::PushButton&>(handle);
142 }
143
144 inline const Toolkit::Internal::PushButton& GetImplementation(const Toolkit::PushButton& button)
145 {
146   DALI_ASSERT_ALWAYS(button);
147
148   const Dali::RefObject& handle = button.GetImplementation();
149
150   return static_cast<const Toolkit::Internal::PushButton&>(handle);
151 }
152
153 } // namespace Toolkit
154
155 } // namespace Dali
156
157 #endif // DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H