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 public event EventHandlerWithReturnType<object, EventArgs, bool> Clicked
136 if (_clickedEventHandler == null)
138 _clickedCallback = OnClicked;
139 ClickedSignal().Connect(_clickedCallback);
142 _clickedEventHandler += value;
147 _clickedEventHandler -= value;
149 if (_clickedEventHandler == null && ClickedSignal().Empty() == false)
151 ClickedSignal().Disconnect(_clickedCallback);
157 private bool OnClicked(IntPtr data)
159 if (_clickedEventHandler != null)
161 return _clickedEventHandler(this, null);
168 private EventHandlerWithReturnType<object, EventArgs, bool> _pressedEventHandler;
169 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
170 private delegate bool PressedCallbackType(global::System.IntPtr data);
171 private PressedCallbackType _pressedCallback;
174 /// The Pressed event will be triggered when the button is touched.
176 public event EventHandlerWithReturnType<object, EventArgs, bool> Pressed
180 if (_pressedEventHandler == null)
182 _pressedCallback = OnPressed;
183 PressedSignal().Connect(_pressedCallback);
186 _pressedEventHandler += value;
191 _pressedEventHandler -= value;
193 if (_pressedEventHandler == null && PressedSignal().Empty() == false)
195 this.PressedSignal().Disconnect(_pressedCallback);
200 private bool OnPressed(IntPtr data)
202 if (_pressedEventHandler != null)
204 return _pressedEventHandler(this, null);
211 private EventHandlerWithReturnType<object, EventArgs, bool> _releasedEventHandler;
212 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
213 private delegate bool ReleasedCallbackType(global::System.IntPtr data);
214 private ReleasedCallbackType _releasedCallback;
217 /// The Released event will be triggered when the button is touched and the touch point leaves the boundary of the button.
219 public event EventHandlerWithReturnType<object, EventArgs, bool> Released
223 if (_releasedEventHandler == null)
225 _releasedCallback = OnReleased;
226 ReleasedSignal().Connect(_releasedCallback);
228 _releasedEventHandler += value;
233 _releasedEventHandler -= value;
235 if (_releasedEventHandler == null && ReleasedSignal().Empty() == false)
237 ReleasedSignal().Disconnect(_releasedCallback);
243 private bool OnReleased(IntPtr data)
245 if (_releasedEventHandler != null)
247 return _releasedEventHandler(this, null);
253 private EventHandlerWithReturnType<object, EventArgs, bool> _stateChangedEventHandler;
254 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
255 private delegate bool StateChangedCallback(global::System.IntPtr data);
256 private StateChangedCallback _stateChangedCallback;
259 /// The StateChanged event will be triggered when the button's state is changed.
261 public event EventHandlerWithReturnType<object, EventArgs, bool> StateChanged
265 if (_stateChangedEventHandler == null)
267 _stateChangedCallback = OnStateChanged;
268 StateChangedSignal().Connect(_stateChangedCallback);
271 _stateChangedEventHandler += value;
276 _stateChangedEventHandler -= value;
278 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false)
280 StateChangedSignal().Disconnect(_stateChangedCallback);
285 private bool OnStateChanged(IntPtr data)
287 if (_stateChangedEventHandler != null)
289 return _stateChangedEventHandler(this, null);
296 /// Gets or sets the unselected button foreground or icon visual.
298 public Tizen.NUI.PropertyMap UnselectedVisual
302 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
303 GetProperty(Button.Property.UNSELECTED_VISUAL).Get(temp);
308 SetProperty(Button.Property.UNSELECTED_VISUAL, new Tizen.NUI.PropertyValue(value));
313 /// Gets or sets the selected button foreground or icon visual.
315 public Tizen.NUI.PropertyMap SelectedVisual
319 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
320 GetProperty(Button.Property.SELECTED_VISUAL).Get(temp);
325 SetProperty(Button.Property.SELECTED_VISUAL, new Tizen.NUI.PropertyValue(value));
330 /// Gets or sets the disabled selected state foreground or icon button visual.
332 public Tizen.NUI.PropertyMap DisabledSelectedVisual
336 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
337 GetProperty(Button.Property.DISABLED_SELECTED_VISUAL).Get(temp);
342 SetProperty(Button.Property.DISABLED_SELECTED_VISUAL, new Tizen.NUI.PropertyValue(value));
347 /// Gets or sets the disabled unselected state foreground or icon visual.
349 public Tizen.NUI.PropertyMap DisabledUnselectedVisual
353 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
354 GetProperty(Button.Property.DISABLED_UNSELECTED_VISUAL).Get(temp);
359 SetProperty(Button.Property.DISABLED_UNSELECTED_VISUAL, new Tizen.NUI.PropertyValue(value));
364 /// Gets or sets the disabled unselected state background button visual.
366 public Tizen.NUI.PropertyMap UnselectedBackgroundVisual
370 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
371 GetProperty(Button.Property.UNSELECTED_BACKGROUND_VISUAL).Get(temp);
376 SetProperty(Button.Property.UNSELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(value));
381 /// Gets or sets the selected background button visual.
383 public Tizen.NUI.PropertyMap SelectedBackgroundVisual
387 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
388 GetProperty(Button.Property.SELECTED_BACKGROUND_VISUAL).Get(temp);
393 SetProperty(Button.Property.SELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(value));
398 /// Gets or sets the disabled while unselected background button visual.
400 public Tizen.NUI.PropertyMap DisabledUnselectedBackgroundVisual
404 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
405 GetProperty(Button.Property.DISABLED_UNSELECTED_BACKGROUND_VISUAL).Get(temp);
410 SetProperty(Button.Property.DISABLED_UNSELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(value));
415 /// Gets or sets the disabled while selected background button visual.
417 public Tizen.NUI.PropertyMap DisabledSelectedBackgroundVisual
421 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
422 GetProperty(Button.Property.DISABLED_SELECTED_BACKGROUND_VISUAL).Get(temp);
427 SetProperty(Button.Property.DISABLED_SELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(value));
432 /// Gets or sets the position of the the label in relation to the foreground or icon, if both present.
434 public Align LabelRelativeAlignment
439 if (GetProperty(Button.Property.LABEL_RELATIVE_ALIGNMENT).Get(out temp) == false)
441 NUILog.Error("LabelRelativeAlignment get error!");
459 string valueToString = "";
464 valueToString = "BEGIN";
469 valueToString = "END";
474 valueToString = "TOP";
479 valueToString = "BOTTOM";
484 valueToString = "END";
488 SetProperty(Button.Property.LABEL_RELATIVE_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
493 /// Gets or sets the padding around the text.
495 public Vector4 LabelPadding
499 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
500 GetProperty(Button.Property.LABEL_PADDING).Get(temp);
505 SetProperty(Button.Property.LABEL_PADDING, new Tizen.NUI.PropertyValue(value));
510 /// Gets or sets the padding around the foreground visual.
512 public Vector4 ForegroundVisualPadding
516 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
517 GetProperty(Button.Property.FOREGROUND_VISUAL_PADDING).Get(temp);
522 SetProperty(Button.Property.FOREGROUND_VISUAL_PADDING, new Tizen.NUI.PropertyValue(value));
526 internal new class Property
528 internal static readonly int UNSELECTED_VISUAL = NDalicManualPINVOKE.Button_Property_UNSELECTED_VISUAL_get();
529 internal static readonly int SELECTED_VISUAL = NDalicManualPINVOKE.Button_Property_SELECTED_VISUAL_get();
530 internal static readonly int DISABLED_SELECTED_VISUAL = NDalicManualPINVOKE.Button_Property_DISABLED_SELECTED_VISUAL_get();
531 internal static readonly int DISABLED_UNSELECTED_VISUAL = NDalicManualPINVOKE.Button_Property_DISABLED_UNSELECTED_VISUAL_get();
532 internal static readonly int UNSELECTED_BACKGROUND_VISUAL = NDalicManualPINVOKE.Button_Property_UNSELECTED_BACKGROUND_VISUAL_get();
533 internal static readonly int SELECTED_BACKGROUND_VISUAL = NDalicManualPINVOKE.Button_Property_SELECTED_BACKGROUND_VISUAL_get();
534 internal static readonly int DISABLED_UNSELECTED_BACKGROUND_VISUAL = NDalicManualPINVOKE.Button_Property_DISABLED_UNSELECTED_BACKGROUND_VISUAL_get();
535 internal static readonly int DISABLED_SELECTED_BACKGROUND_VISUAL = NDalicManualPINVOKE.Button_Property_DISABLED_SELECTED_BACKGROUND_VISUAL_get();
536 internal static readonly int LABEL_RELATIVE_ALIGNMENT = NDalicManualPINVOKE.Button_Property_LABEL_RELATIVE_ALIGNMENT_get();
537 internal static readonly int LABEL_PADDING = NDalicManualPINVOKE.Button_Property_LABEL_PADDING_get();
538 internal static readonly int FOREGROUND_VISUAL_PADDING = NDalicManualPINVOKE.Button_Property_VISUAL_PADDING_get();
539 internal static readonly int AUTO_REPEATING = NDalicPINVOKE.Button_Property_AUTO_REPEATING_get();
540 internal static readonly int INITIAL_AUTO_REPEATING_DELAY = NDalicPINVOKE.Button_Property_INITIAL_AUTO_REPEATING_DELAY_get();
541 internal static readonly int NEXT_AUTO_REPEATING_DELAY = NDalicPINVOKE.Button_Property_NEXT_AUTO_REPEATING_DELAY_get();
542 internal static readonly int TOGGLABLE = NDalicPINVOKE.Button_Property_TOGGLABLE_get();
543 internal static readonly int SELECTED = NDalicPINVOKE.Button_Property_SELECTED_get();
544 internal static readonly int UNSELECTED_COLOR = NDalicPINVOKE.Button_Property_UNSELECTED_COLOR_get();
545 internal static readonly int SELECTED_COLOR = NDalicPINVOKE.Button_Property_SELECTED_COLOR_get();
546 internal static readonly int LABEL = NDalicPINVOKE.Button_Property_LABEL_get();
550 /// Creates an uninitialized button.<br>
551 /// Only the derived versions can be instantiated.<br>
553 public Button() : this(NDalicPINVOKE.new_Button__SWIG_0(), true)
555 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
558 internal ButtonSignal PressedSignal()
560 ButtonSignal ret = new ButtonSignal(NDalicPINVOKE.Button_PressedSignal(swigCPtr), false);
561 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
565 internal ButtonSignal ReleasedSignal()
567 ButtonSignal ret = new ButtonSignal(NDalicPINVOKE.Button_ReleasedSignal(swigCPtr), false);
568 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
572 internal ButtonSignal ClickedSignal()
574 ButtonSignal ret = new ButtonSignal(NDalicPINVOKE.Button_ClickedSignal(swigCPtr), false);
575 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
579 internal ButtonSignal StateChangedSignal()
581 ButtonSignal ret = new ButtonSignal(NDalicPINVOKE.Button_StateChangedSignal(swigCPtr), false);
582 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
587 /// If the autorepeating property is set to true, then the togglable property is set to false.
589 public bool AutoRepeating
594 GetProperty(Button.Property.AUTO_REPEATING).Get(out temp);
599 SetProperty(Button.Property.AUTO_REPEATING, new Tizen.NUI.PropertyValue(value));
604 /// By default, this value is set to 0.15 seconds.
606 public float InitialAutoRepeatingDelay
611 GetProperty(Button.Property.INITIAL_AUTO_REPEATING_DELAY).Get(out temp);
616 SetProperty(Button.Property.INITIAL_AUTO_REPEATING_DELAY, new Tizen.NUI.PropertyValue(value));
621 /// By default, this value is set to 0.05 seconds.
623 public float NextAutoRepeatingDelay
628 GetProperty(Button.Property.NEXT_AUTO_REPEATING_DELAY).Get(out temp);
633 SetProperty(Button.Property.NEXT_AUTO_REPEATING_DELAY, new Tizen.NUI.PropertyValue(value));
638 /// If the togglable property is set to true, then the autorepeating property is set to false.
640 public bool Togglable
645 GetProperty(Button.Property.TOGGLABLE).Get(out temp);
650 SetProperty(Button.Property.TOGGLABLE, new Tizen.NUI.PropertyValue(value));
655 /// Gets or sets the togglable button as either selected or unselected, togglable property must be set to true.
662 GetProperty(Button.Property.SELECTED).Get(out temp);
667 SetProperty(Button.Property.SELECTED, new Tizen.NUI.PropertyValue(value));
672 /// Gets or sets the unselected color.
674 public Color UnselectedColor
678 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
679 GetProperty(Button.Property.UNSELECTED_COLOR).Get(temp);
684 SetProperty(Button.Property.UNSELECTED_COLOR, new Tizen.NUI.PropertyValue(value));
689 /// Gets or sets the selected color.
691 public Color SelectedColor
695 Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
696 GetProperty(Button.Property.SELECTED_COLOR).Get(temp);
701 SetProperty(Button.Property.SELECTED_COLOR, new Tizen.NUI.PropertyValue(value));
706 /// Gets or sets the label.
708 public Tizen.NUI.PropertyMap Label
712 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
713 GetProperty(Button.Property.LABEL).Get(temp);
718 SetProperty(Button.Property.LABEL, new Tizen.NUI.PropertyValue(value));
723 /// Gets or sets the text of the label.
725 public string LabelText
729 Tizen.NUI.PropertyMap map = new Tizen.NUI.PropertyMap();
730 GetProperty( Button.Property.LABEL).Get(map);
731 Tizen.NUI.PropertyValue value = map.Find( TextVisualProperty.Text, "Text");
738 SetProperty( Button.Property.LABEL, new Tizen.NUI.PropertyValue( value ) );
743 /// Enumeration for describing the position, the text label can be, in relation to the control (and foreground/icon).
748 /// At the start of the control before the foreground or icon.
752 /// At the end of the control after the foreground or icon.
756 /// At the top of the control above the foreground or icon.
760 /// At the bottom of the control below the foreground or icon.