783e1e68352e3340467547446ad117972af5c559
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / buttons / button.cpp
1 /*
2  * Copyright (c) 2015 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 <dali-toolkit/public-api/controls/buttons/button.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/controls/buttons/button-impl.h>
26 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 Button::Button()
35 {}
36
37 Button::Button( const Button& button )
38 : Control( button )
39 {
40 }
41
42 Button& Button::operator=( const Button& button )
43 {
44   if( &button != this )
45   {
46     Control::operator=( button );
47   }
48   return *this;
49 }
50
51 Button::~Button()
52 {
53 }
54
55 Button Button::DownCast( BaseHandle handle )
56 {
57   return Control::DownCast<Button, Internal::Button>(handle);
58 }
59
60 void Button::SetDisabled( bool disabled )
61 {
62   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabled() is deprecated and will be removed from next release. Use SetProperty DISABLED or Styling file instead.\n" );
63
64   Dali::Toolkit::GetImplementation( *this ).SetDisabled( disabled );
65 }
66
67 bool Button::IsDisabled() const
68 {
69   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: IsDisabled() is deprecated and will be removed from next release. Use GetProperty DISABLED instead.\n" );
70
71   return Dali::Toolkit::GetImplementation( *this ).IsDisabled();
72 }
73
74 void Button::SetAutoRepeating( bool autoRepeating )
75 {
76   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetAutoRepeating() is deprecated and will be removed from next release. Use SetProperty AUTO_REPEATING or Styling file instead.\n" );
77
78   Dali::Toolkit::GetImplementation( *this ).SetAutoRepeating( autoRepeating );
79 }
80
81 bool Button::IsAutoRepeating() const
82 {
83   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: IsAutoRepeating() is deprecated and will be removed from next release. Use GetProperty AUTO_REPEATING instead.\n" );
84
85   return Dali::Toolkit::GetImplementation( *this ).IsAutoRepeating();
86 }
87
88 void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
89 {
90   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetInitialAutoRepeatingDelay() is deprecated and will be removed from next release. Use SetProperty INITIAL_AUTO_REPEATING_DELAY or Styling file instead.\n" );
91
92   Dali::Toolkit::GetImplementation( *this ).SetInitialAutoRepeatingDelay( initialAutoRepeatingDelay );
93 }
94
95 float Button::GetInitialAutoRepeatingDelay() const
96 {
97   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetPositionInheritanceMode() is deprecated and will be removed from next release. Use GetProperty INITIAL_AUTO_REPEATING_DELAY or Styling file instead.\n" );
98
99   return Dali::Toolkit::GetImplementation( *this ).GetInitialAutoRepeatingDelay();
100 }
101
102 void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
103 {
104   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetNextAutoRepeatingDelay() is deprecated and will be removed from next release. Use SetProperty NEXT_AUTO_REPEATING_DELAY or Styling file instead.\n" );
105
106   Dali::Toolkit::GetImplementation( *this ).SetNextAutoRepeatingDelay( nextAutoRepeatingDelay );
107 }
108
109 float Button::GetNextAutoRepeatingDelay() const
110 {
111   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: GetNextAutoRepeatingDelay() is deprecated and will be removed from next release. Use GetProperty NEXT_AUTO_REPEATING_DELAY instead.\n" );
112
113   return Dali::Toolkit::GetImplementation( *this ).GetNextAutoRepeatingDelay();
114 }
115
116 void Button::SetTogglableButton( bool togglable )
117 {
118   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetTogglableButton() is deprecated and will be removed from next release. Use SetProperty TOGGLABLE or Styling file instead.\n" );
119
120   Dali::Toolkit::GetImplementation( *this ).SetTogglableButton( togglable );
121 }
122
123 bool Button::IsTogglableButton() const
124 {
125   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: IsTogglableButton() is deprecated and will be removed from next release. Use GetProperty TOGGLABLE instead.\n" );
126
127   return Dali::Toolkit::GetImplementation( *this ).IsTogglableButton();
128 }
129
130 void Button::SetSelected( bool selected )
131 {
132   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetSelected() is deprecated and will be removed from next release. Use SetProperty SELECTED instead.\n" );
133
134   Dali::Toolkit::GetImplementation( *this ).SetSelected( selected );
135 }
136
137 bool Button::IsSelected() const
138 {
139   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: IsSelected() is deprecated and will be removed from next release. Use GetProperty SELECTED instead.\n" );
140
141   return Dali::Toolkit::GetImplementation( *this ).IsSelected();
142 }
143
144 void Button::SetAnimationTime( float animationTime )
145 {
146   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetAnimationTime() is deprecated and will be removed from next release. Use Styling file to set animation instead.\n" );
147
148   Dali::Toolkit::GetImplementation( *this ).SetAnimationTime( animationTime );
149 }
150
151 float Button::GetAnimationTime() const
152 {
153   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: GetAnimationTime() is deprecated and will be removed from next release.\n" );
154
155   return Dali::Toolkit::GetImplementation( *this ).GetAnimationTime();
156 }
157
158 void Button::SetLabelText( const std::string& label )
159 {
160   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetLabelText() is deprecated and will be removed from next release. Use SetProperty LABEL or Styling file instead.\n" );
161
162   Dali::Toolkit::GetImplementation( *this ).SetLabelText( label );
163 }
164
165 std::string Button::GetLabelText() const
166 {
167   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: GetLabelText() is deprecated and will be removed from next release. Use GetProperty LABEL instead.\n" );
168
169   return Dali::Toolkit::GetImplementation( *this ).GetLabelText();
170 }
171
172 void Button::SetUnselectedImage( const std::string& filename )
173 {
174   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetUnselectedImage() is deprecated and will be removed from next release. Use SetProperty UNSELECTED_STATE_IMAGE or Styling file instead.\n" );
175
176   Dali::Toolkit::GetImplementation( *this ).SetUnselectedImage( filename );
177 }
178
179 void Button::SetBackgroundImage( const std::string& filename )
180 {
181   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetBackgroundImage() is deprecated and will be removed from next release. Use Styling file instead.\n" );
182
183   Dali::Toolkit::GetImplementation( *this ).SetBackgroundImage( filename );
184 }
185
186 void Button::SetSelectedImage( const std::string& filename )
187 {
188   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetSelectedImage() is deprecated and will be removed from next release. Use SetProperty SELECTED_STATE_IMAGE or Styling file instead.\n" );
189
190   Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( filename );
191 }
192
193 void Button::SetSelectedBackgroundImage( const std::string& filename )
194 {
195   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetSelectedBackgroundImage() is deprecated and will be removed from next release. Use Styling file instead.\n" );
196
197   Dali::Toolkit::GetImplementation( *this ).SetSelectedBackgroundImage( filename );
198 }
199
200 void Button::SetDisabledBackgroundImage( const std::string& filename )
201 {
202   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabledBackgroundImage() is deprecated and will be removed from next release. Use SetProperty DISABLED_STATE_IMAGE or Styling file instead.\n" );
203
204   Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( filename );
205 }
206
207 void Button::SetDisabledImage( const std::string& filename )
208 {
209   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabledImage() is deprecated and will be removed from next release. Use Styling file instead.\n" );
210
211   Dali::Toolkit::GetImplementation( *this ).SetDisabledImage( filename );
212 }
213
214 void Button::SetDisabledSelectedImage( const std::string& filename )
215 {
216   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabledSelectedImage() is deprecated and will be removed from next release. Use Styling file instead.\n" );
217
218   Dali::Toolkit::GetImplementation( *this ).SetDisabledSelectedImage( filename );
219 }
220
221 Button::ButtonSignalType& Button::PressedSignal()
222 {
223   return Dali::Toolkit::GetImplementation( *this ).PressedSignal();
224 }
225
226 Button::ButtonSignalType& Button::ReleasedSignal()
227 {
228   return Dali::Toolkit::GetImplementation( *this ).ReleasedSignal();
229 }
230
231 Button::ButtonSignalType& Button::ClickedSignal()
232 {
233   return Dali::Toolkit::GetImplementation( *this ).ClickedSignal();
234 }
235
236 Button::ButtonSignalType& Button::StateChangedSignal()
237 {
238   return Dali::Toolkit::GetImplementation( *this ).StateChangedSignal();
239 }
240
241 // Deprecated API
242
243 void Button::SetLabel( Actor label )
244 {
245   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetLabel() is deprecated and will be removed from next release. Use SetProperty LABEL instead.\n" );
246
247   Dali::Toolkit::GetImplementation( *this ).SetLabel( label );
248 }
249
250 void Button::SetButtonImage( Image image )
251 {
252   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetButtonImage() is deprecated and will be removed from next release. Use Styling file instead.\n" );
253
254   Actor imageView = Toolkit::ImageView::New( image );
255   imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
256   Dali::Toolkit::GetImplementation( *this ).SetButtonImage( imageView );
257 }
258
259 void Button::SetSelectedImage( Image image )
260 {
261   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetSelectedImage() is deprecated and will be removed from next release. Use Styling file instead.\n" );
262
263   Actor imageView = Toolkit::ImageView::New( image );
264   imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
265   Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( imageView );
266 }
267
268 Actor Button::GetButtonImage() const
269 {
270   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: GetButtonImage() is deprecated and will be removed from next release.\n" );
271
272   return Dali::Toolkit::GetImplementation( *this ).GetButtonImage();
273 }
274
275 Actor Button::GetSelectedImage() const
276 {
277   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: GetSelectedImage() is deprecated and will be removed from next release.\n" );
278
279   return Dali::Toolkit::GetImplementation( *this ).GetSelectedImage();
280 }
281
282
283 Button::Button( Internal::Button& implementation )
284 : Control( implementation )
285 {
286 }
287
288 Button::Button( Dali::Internal::CustomActor* internal )
289 : Control( internal )
290 {
291   VerifyCustomActorPointer<Internal::Button>(internal);
292 }
293
294 } // namespace Toolkit
295
296 } // namespace Dali