1 // Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
16 // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
17 // Some have been manually changed
19 namespace Tizen.NUI.UIComponents
23 using System.Runtime.InteropServices;
24 using Tizen.NUI.BaseComponents;
27 /// The Button class is a base class for different kinds of buttons.<br>
28 /// This class provides the disabled property and the clicked signal.<br>
29 /// The clicked event handler is emitted when the button is touched, and the touch point doesn't leave the boundary of the button.<br>
30 /// When the disabled property is set to true, no signal is emitted.<br>
31 /// The 'Visual' describes not just traditional images like PNG and BMP, but also refers to whatever is used to show the button. It could be a color, gradient, or some other kind of renderer.<br>
32 /// The button's appearance can be modified by setting properties for the various visuals or images.<br>
33 /// It is not mandatory to set all the visuals. A button could be defined only by setting its background visual, or by setting its background and selected visuals.<br>
34 /// The button visual is shown over the background visual.<br>
35 /// When pressed, the unselected visuals are replaced by the selected visuals.<br>
36 /// The text label is always placed on the top of all images.<br>
37 /// When the button is disabled, the background button and the selected visuals are replaced by their disabled visuals.<br>
39 public class Button : View
41 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
43 internal Button(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Button_SWIGUpcast(cPtr), cMemoryOwn)
45 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
48 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Button obj)
50 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
54 /// To dispose the button instance.
56 protected override void Dispose(DisposeTypes type)
63 if (type == DisposeTypes.Explicit)
66 //Release your own managed resources here.
67 //You should release all of your own disposable objects here.
71 //Release your own unmanaged resources here.
72 //You should not access any managed member here except static instance.
73 //because the execution order of Finalizes is non-deterministic.
75 DisConnectFromSignals();
77 if (swigCPtr.Handle != global::System.IntPtr.Zero)
82 NDalicPINVOKE.delete_Button(swigCPtr);
84 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
90 private void DisConnectFromSignals()
93 global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
95 // Use BaseHandle CPtr as current might have been deleted already in derived classes.
96 swigCPtr = GetBaseHandleCPtrHandleRef;
98 if (_stateChangedCallback != null)
100 StateChangedSignal().Disconnect(_stateChangedCallback);
103 if (_releasedCallback != null)
105 ReleasedSignal().Disconnect(_releasedCallback);
108 if (_pressedCallback != null)
110 this.PressedSignal().Disconnect(_pressedCallback);
113 if (_clickedCallback != null)
115 ClickedSignal().Disconnect(_clickedCallback);
118 // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
119 // Restore current CPtr.
120 swigCPtr = currentCPtr;
124 private EventHandlerWithReturnType<object, EventArgs, bool> _clickedEventHandler;
125 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
126 private delegate bool ClickedCallbackType(global::System.IntPtr data);
127 private ClickedCallbackType _clickedCallback;
130 /// The Clicked event will be triggered when the button is touched and the touch point doesn't leave the boundary of the button.
132 /// <since_tizen> 3 </since_tizen>
133 public event EventHandlerWithReturnType<object, EventArgs, bool> Clicked
137 if (_clickedEventHandler == null)
139 _clickedCallback = OnClicked;
140 ClickedSignal().Connect(_clickedCallback);
143 _clickedEventHandler += value;
148 _clickedEventHandler -= value;
150 if (_clickedEventHandler == null && ClickedSignal().Empty() == false)
152 ClickedSignal().Disconnect(_clickedCallback);
158 private bool OnClicked(IntPtr data)
160 if (_clickedEventHandler != null)
162 return _clickedEventHandler(this, null);
169 private EventHandlerWithReturnType<object, EventArgs, bool> _pressedEventHandler;
170 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
171 private delegate bool PressedCallbackType(global::System.IntPtr data);
172 private PressedCallbackType _pressedCallback;
175 /// The Pressed event will be triggered when the button is touched.
177 /// <since_tizen> 3 </since_tizen>
178 public event EventHandlerWithReturnType<object, EventArgs, bool> Pressed
182 if (_pressedEventHandler == null)
184 _pressedCallback = OnPressed;
185 PressedSignal().Connect(_pressedCallback);
188 _pressedEventHandler += value;
193 _pressedEventHandler -= value;
195 if (_pressedEventHandler == null && PressedSignal().Empty() == false)
197 this.PressedSignal().Disconnect(_pressedCallback);
202 private bool OnPressed(IntPtr data)
204 if (_pressedEventHandler != null)
206 return _pressedEventHandler(this, null);
213 private EventHandlerWithReturnType<object, EventArgs, bool> _releasedEventHandler;
214 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
215 private delegate bool ReleasedCallbackType(global::System.IntPtr data);
216 private ReleasedCallbackType _releasedCallback;
219 /// The Released event will be triggered when the button is touched and the touch point leaves the boundary of the button.
221 /// <since_tizen> 3 </since_tizen>
222 public event EventHandlerWithReturnType<object, EventArgs, bool> Released
226 if (_releasedEventHandler == null)
228 _releasedCallback = OnReleased;
229 ReleasedSignal().Connect(_releasedCallback);
231 _releasedEventHandler += value;
236 _releasedEventHandler -= value;
238 if (_releasedEventHandler == null && ReleasedSignal().Empty() == false)
240 ReleasedSignal().Disconnect(_releasedCallback);
246 private bool OnReleased(IntPtr data)
248 if (_releasedEventHandler != null)
250 return _releasedEventHandler(this, null);
256 private EventHandlerWithReturnType<object, EventArgs, bool> _stateChangedEventHandler;
257 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
258 private delegate bool StateChangedCallback(global::System.IntPtr data);
259 private StateChangedCallback _stateChangedCallback;
262 /// The StateChanged event will be triggered when the button's state is changed.
264 /// <since_tizen> 3 </since_tizen>
265 public event EventHandlerWithReturnType<object, EventArgs, bool> StateChanged
269 if (_stateChangedEventHandler == null)
271 _stateChangedCallback = OnStateChanged;
272 StateChangedSignal().Connect(_stateChangedCallback);
275 _stateChangedEventHandler += value;
280 _stateChangedEventHandler -= value;
282 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false)
284 StateChangedSignal().Disconnect(_stateChangedCallback);
289 private bool OnStateChanged(IntPtr data)
291 if (_stateChangedEventHandler != null)
293 return _stateChangedEventHandler(this, null);
300 /// Gets or sets the unselected button foreground or icon visual.
302 /// <since_tizen> 3 </since_tizen>
303 public Tizen.NUI.PropertyMap UnselectedVisual
307 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
308 GetProperty(Button.Property.UNSELECTED_VISUAL).Get(temp);
313 SetProperty(Button.Property.UNSELECTED_VISUAL, new Tizen.NUI.PropertyValue(value));
318 /// Gets or sets the selected button foreground or icon visual.
320 /// <since_tizen> 3 </since_tizen>
321 public Tizen.NUI.PropertyMap SelectedVisual
325 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
326 GetProperty(Button.Property.SELECTED_VISUAL).Get(temp);
331 SetProperty(Button.Property.SELECTED_VISUAL, new Tizen.NUI.PropertyValue(value));
336 /// Gets or sets the disabled selected state foreground or icon button visual.
338 /// <since_tizen> 3 </since_tizen>
339 public Tizen.NUI.PropertyMap DisabledSelectedVisual
343 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
344 GetProperty(Button.Property.DISABLED_SELECTED_VISUAL).Get(temp);
349 SetProperty(Button.Property.DISABLED_SELECTED_VISUAL, new Tizen.NUI.PropertyValue(value));
354 /// Gets or sets the disabled unselected state foreground or icon visual.
356 /// <since_tizen> 3 </since_tizen>
357 public Tizen.NUI.PropertyMap DisabledUnselectedVisual
361 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
362 GetProperty(Button.Property.DISABLED_UNSELECTED_VISUAL).Get(temp);
367 SetProperty(Button.Property.DISABLED_UNSELECTED_VISUAL, new Tizen.NUI.PropertyValue(value));
372 /// Gets or sets the disabled unselected state background button visual.
374 /// <since_tizen> 3 </since_tizen>
375 public Tizen.NUI.PropertyMap UnselectedBackgroundVisual
379 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
380 GetProperty(Button.Property.UNSELECTED_BACKGROUND_VISUAL).Get(temp);
385 SetProperty(Button.Property.UNSELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(value));
390 /// Gets or sets the selected background button visual.
392 /// <since_tizen> 3 </since_tizen>
393 public Tizen.NUI.PropertyMap SelectedBackgroundVisual
397 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
398 GetProperty(Button.Property.SELECTED_BACKGROUND_VISUAL).Get(temp);
403 SetProperty(Button.Property.SELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(value));
408 /// Gets or sets the disabled while unselected background button visual.
410 /// <since_tizen> 3 </since_tizen>
411 public Tizen.NUI.PropertyMap DisabledUnselectedBackgroundVisual
415 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
416 GetProperty(Button.Property.DISABLED_UNSELECTED_BACKGROUND_VISUAL).Get(temp);
421 SetProperty(Button.Property.DISABLED_UNSELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(value));
426 /// Gets or sets the disabled while selected background button visual.
428 /// <since_tizen> 3 </since_tizen>
429 public Tizen.NUI.PropertyMap DisabledSelectedBackgroundVisual
433 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
434 GetProperty(Button.Property.DISABLED_SELECTED_BACKGROUND_VISUAL).Get(temp);
439 SetProperty(Button.Property.DISABLED_SELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(value));
444 /// Gets or sets the position of the the label in relation to the foreground or icon, if both present.
446 /// <since_tizen> 3 </since_tizen>
447 public Align LabelRelativeAlignment
452 if (GetProperty(Button.Property.LABEL_RELATIVE_ALIGNMENT).Get(out temp) == false)
454 NUILog.Error("LabelRelativeAlignment get error!");
472 string valueToString = "";
477 valueToString = "BEGIN";
482 valueToString = "END";
487 valueToString = "TOP";
492 valueToString = "BOTTOM";
497 valueToString = "END";
501 SetProperty(Button.Property.LABEL_RELATIVE_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
506 /// Gets or sets the padding around the text.
508 /// <since_tizen> 3 </since_tizen>
509 public Vector4 LabelPadding
513 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
514 GetProperty(Button.Property.LABEL_PADDING).Get(temp);
519 SetProperty(Button.Property.LABEL_PADDING, new Tizen.NUI.PropertyValue(value));
524 /// Gets or sets the padding around the foreground visual.
526 /// <since_tizen> 3 </since_tizen>
527 public Vector4 ForegroundVisualPadding
531 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
532 GetProperty(Button.Property.FOREGROUND_VISUAL_PADDING).Get(temp);
537 SetProperty(Button.Property.FOREGROUND_VISUAL_PADDING, new Tizen.NUI.PropertyValue(value));
541 internal new class Property
543 internal static readonly int UNSELECTED_VISUAL = NDalicManualPINVOKE.Button_Property_UNSELECTED_VISUAL_get();
544 internal static readonly int SELECTED_VISUAL = NDalicManualPINVOKE.Button_Property_SELECTED_VISUAL_get();
545 internal static readonly int DISABLED_SELECTED_VISUAL = NDalicManualPINVOKE.Button_Property_DISABLED_SELECTED_VISUAL_get();
546 internal static readonly int DISABLED_UNSELECTED_VISUAL = NDalicManualPINVOKE.Button_Property_DISABLED_UNSELECTED_VISUAL_get();
547 internal static readonly int UNSELECTED_BACKGROUND_VISUAL = NDalicManualPINVOKE.Button_Property_UNSELECTED_BACKGROUND_VISUAL_get();
548 internal static readonly int SELECTED_BACKGROUND_VISUAL = NDalicManualPINVOKE.Button_Property_SELECTED_BACKGROUND_VISUAL_get();
549 internal static readonly int DISABLED_UNSELECTED_BACKGROUND_VISUAL = NDalicManualPINVOKE.Button_Property_DISABLED_UNSELECTED_BACKGROUND_VISUAL_get();
550 internal static readonly int DISABLED_SELECTED_BACKGROUND_VISUAL = NDalicManualPINVOKE.Button_Property_DISABLED_SELECTED_BACKGROUND_VISUAL_get();
551 internal static readonly int LABEL_RELATIVE_ALIGNMENT = NDalicManualPINVOKE.Button_Property_LABEL_RELATIVE_ALIGNMENT_get();
552 internal static readonly int LABEL_PADDING = NDalicManualPINVOKE.Button_Property_LABEL_PADDING_get();
553 internal static readonly int FOREGROUND_VISUAL_PADDING = NDalicManualPINVOKE.Button_Property_VISUAL_PADDING_get();
554 internal static readonly int AUTO_REPEATING = NDalicPINVOKE.Button_Property_AUTO_REPEATING_get();
555 internal static readonly int INITIAL_AUTO_REPEATING_DELAY = NDalicPINVOKE.Button_Property_INITIAL_AUTO_REPEATING_DELAY_get();
556 internal static readonly int NEXT_AUTO_REPEATING_DELAY = NDalicPINVOKE.Button_Property_NEXT_AUTO_REPEATING_DELAY_get();
557 internal static readonly int TOGGLABLE = NDalicPINVOKE.Button_Property_TOGGLABLE_get();
558 internal static readonly int SELECTED = NDalicPINVOKE.Button_Property_SELECTED_get();
559 internal static readonly int UNSELECTED_COLOR = NDalicPINVOKE.Button_Property_UNSELECTED_COLOR_get();
560 internal static readonly int SELECTED_COLOR = NDalicPINVOKE.Button_Property_SELECTED_COLOR_get();
561 internal static readonly int LABEL = NDalicPINVOKE.Button_Property_LABEL_get();
565 /// Creates an uninitialized button.<br>
566 /// Only the derived versions can be instantiated.<br>
568 /// <since_tizen> 3 </since_tizen>
569 public Button() : this(NDalicPINVOKE.new_Button__SWIG_0(), true)
571 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
574 internal ButtonSignal PressedSignal()
576 ButtonSignal ret = new ButtonSignal(NDalicPINVOKE.Button_PressedSignal(swigCPtr), false);
577 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
581 internal ButtonSignal ReleasedSignal()
583 ButtonSignal ret = new ButtonSignal(NDalicPINVOKE.Button_ReleasedSignal(swigCPtr), false);
584 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
588 internal ButtonSignal ClickedSignal()
590 ButtonSignal ret = new ButtonSignal(NDalicPINVOKE.Button_ClickedSignal(swigCPtr), false);
591 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
595 internal ButtonSignal StateChangedSignal()
597 ButtonSignal ret = new ButtonSignal(NDalicPINVOKE.Button_StateChangedSignal(swigCPtr), false);
598 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
603 /// If the autorepeating property is set to true, then the togglable property is set to false.
605 /// <since_tizen> 3 </since_tizen>
606 public bool AutoRepeating
611 GetProperty(Button.Property.AUTO_REPEATING).Get(out temp);
616 SetProperty(Button.Property.AUTO_REPEATING, new Tizen.NUI.PropertyValue(value));
621 /// By default, this value is set to 0.15 seconds.
623 /// <since_tizen> 3 </since_tizen>
624 public float InitialAutoRepeatingDelay
629 GetProperty(Button.Property.INITIAL_AUTO_REPEATING_DELAY).Get(out temp);
634 SetProperty(Button.Property.INITIAL_AUTO_REPEATING_DELAY, new Tizen.NUI.PropertyValue(value));
639 /// By default, this value is set to 0.05 seconds.
641 /// <since_tizen> 3 </since_tizen>
642 public float NextAutoRepeatingDelay
647 GetProperty(Button.Property.NEXT_AUTO_REPEATING_DELAY).Get(out temp);
652 SetProperty(Button.Property.NEXT_AUTO_REPEATING_DELAY, new Tizen.NUI.PropertyValue(value));
657 /// If the togglable property is set to true, then the autorepeating property is set to false.
659 /// <since_tizen> 3 </since_tizen>
660 public bool Togglable
665 GetProperty(Button.Property.TOGGLABLE).Get(out temp);
670 SetProperty(Button.Property.TOGGLABLE, new Tizen.NUI.PropertyValue(value));
675 /// Gets or sets the togglable button as either selected or unselected, togglable property must be set to true.
677 /// <since_tizen> 3 </since_tizen>
683 GetProperty(Button.Property.SELECTED).Get(out temp);
688 SetProperty(Button.Property.SELECTED, new Tizen.NUI.PropertyValue(value));
693 /// Gets or sets the unselected color.
695 /// <since_tizen> 3 </since_tizen>
696 public Color UnselectedColor
700 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
701 GetProperty(Button.Property.UNSELECTED_COLOR).Get(temp);
706 SetProperty(Button.Property.UNSELECTED_COLOR, new Tizen.NUI.PropertyValue(value));
711 /// Gets or sets the selected color.
713 /// <since_tizen> 3 </since_tizen>
714 public Color SelectedColor
718 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
719 GetProperty(Button.Property.SELECTED_COLOR).Get(temp);
724 SetProperty(Button.Property.SELECTED_COLOR, new Tizen.NUI.PropertyValue(value));
729 /// Gets or sets the label.
731 /// <since_tizen> 3 </since_tizen>
732 public Tizen.NUI.PropertyMap Label
736 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
737 GetProperty(Button.Property.LABEL).Get(temp);
742 SetProperty(Button.Property.LABEL, new Tizen.NUI.PropertyValue(value));
747 /// Gets or sets the text of the label.
749 /// <since_tizen> 3 </since_tizen>
750 public string LabelText
754 Tizen.NUI.PropertyMap map = new Tizen.NUI.PropertyMap();
755 GetProperty( Button.Property.LABEL).Get(map);
756 Tizen.NUI.PropertyValue value = map.Find( TextVisualProperty.Text, "Text");
763 SetProperty( Button.Property.LABEL, new Tizen.NUI.PropertyValue( value ) );
768 /// Enumeration for describing the position, the text label can be, in relation to the control (and foreground/icon).
770 /// <since_tizen> 3 </since_tizen>
774 /// At the start of the control before the foreground or icon.
778 /// At the end of the control after the foreground or icon.
782 /// At the top of the control above the foreground or icon.
786 /// At the bottom of the control below the foreground or icon.