[NUI] Sync dalihub and Samsung TizenFX (#338)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / UIComponents / PushButton.cs
1 /*
2  * Copyright(c) 2018 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 using System;
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
22 using System.Windows.Input;
23 using System.Collections.Generic;
24
25 namespace Tizen.NUI.UIComponents
26 {
27     /// <summary>
28     /// The PushButton changes its appearance when it is pressed, and returns to its original when it is released.
29     /// </summary>
30     /// <since_tizen> 3 </since_tizen>
31     public class PushButton : Button
32     {
33         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34         [EditorBrowsable(EditorBrowsableState.Never)]
35         public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(PushButton), null,
36                 BindingMode.OneWay, null, null, null, null, null as BindableProperty.CreateDefaultValueDelegate);
37         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
38         [EditorBrowsable(EditorBrowsableState.Never)]
39         public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(PushButton), null,
40                 BindingMode.OneWay, null, null, null, null, null as BindableProperty.CreateDefaultValueDelegate);
41
42         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
43
44         internal PushButton(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PushButton_SWIGUpcast(cPtr), cMemoryOwn)
45         {
46             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
47         }
48
49         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PushButton obj)
50         {
51             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
52         }
53
54         /// <summary>
55         /// To dispose the PushButton instance.
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         protected override void Dispose(DisposeTypes type)
59         {
60             if (disposed)
61             {
62                 return;
63             }
64
65             if(type == DisposeTypes.Explicit)
66             {
67                 //Called by User
68                 //Release your own managed resources here.
69                 //You should release all of your own disposable objects here.
70             }
71
72             //Release your own unmanaged resources here.
73             //You should not access any managed member here except static instance.
74             //because the execution order of Finalizes is non-deterministic.
75
76             if (swigCPtr.Handle != global::System.IntPtr.Zero)
77             {
78                 if (swigCMemOwn)
79                 {
80                     swigCMemOwn = false;
81                     NDalicPINVOKE.delete_PushButton(swigCPtr);
82                 }
83                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
84             }
85
86             base.Dispose(type);
87         }
88
89
90         internal new class Property
91         {
92             internal static readonly int UNSELECTED_ICON = NDalicPINVOKE.PushButton_Property_UNSELECTED_ICON_get();
93             internal static readonly int SELECTED_ICON = NDalicPINVOKE.PushButton_Property_SELECTED_ICON_get();
94             internal static readonly int ICON_ALIGNMENT = NDalicPINVOKE.PushButton_Property_ICON_ALIGNMENT_get();
95             internal static readonly int LABEL_PADDING = NDalicPINVOKE.PushButton_Property_LABEL_PADDING_get();
96             internal static readonly int ICON_PADDING = NDalicPINVOKE.PushButton_Property_ICON_PADDING_get();
97         }
98
99         /// <summary>
100         /// Creates the PushButton.
101         /// </summary>
102         /// <since_tizen> 3 </since_tizen>
103         public PushButton() : this(NDalicPINVOKE.PushButton_New(), true)
104         {
105             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
106             this.Clicked += (sender, e) =>
107             {
108                 ICommand command = this.Command;
109                 if (command != null)
110                 {
111                     command.Execute(this.CommandParameter);
112                 }
113                 return true;
114             };
115         }
116
117         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
118         [EditorBrowsable(EditorBrowsableState.Never)]
119         public ICommand Command
120         {
121             get
122             {
123                 return (ICommand)base.GetValue(PushButton.CommandProperty);
124             }
125             set
126             {
127                 base.SetValue(PushButton.CommandProperty, value);
128             }
129         }
130
131         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
132         [EditorBrowsable(EditorBrowsableState.Never)]
133         public object CommandParameter
134         {
135             get
136             {
137                 return base.GetValue(PushButton.CommandParameterProperty);
138             }
139             set
140             {
141                 base.SetValue(PushButton.CommandParameterProperty, value);
142             }
143         }
144     }
145 }