[NUI] Adjust directory (#903)
[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
43         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
44
45         /// <summary>
46         /// Creates the PushButton.
47         /// </summary>
48         /// <since_tizen> 3 </since_tizen>
49         public PushButton() : this(Interop.PushButton.PushButton_New(), true)
50         {
51             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52         }
53
54         internal PushButton(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PushButton.PushButton_SWIGUpcast(cPtr), cMemoryOwn)
55         {
56             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
57         }
58
59         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
60         [EditorBrowsable(EditorBrowsableState.Never)]
61         public ICommand Command
62         {
63             get
64             {
65                 return (ICommand)base.GetValue(PushButton.CommandProperty);
66             }
67             set
68             {
69                 base.SetValue(PushButton.CommandProperty, value);
70             }
71         }
72
73         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
74         [EditorBrowsable(EditorBrowsableState.Never)]
75         public object CommandParameter
76         {
77             get
78             {
79                 return base.GetValue(PushButton.CommandParameterProperty);
80             }
81             set
82             {
83                 base.SetValue(PushButton.CommandParameterProperty, value);
84             }
85         }
86
87         /// Only used by the IL of xaml, will never changed to not hidden.
88         [EditorBrowsable(EditorBrowsableState.Never)]
89         public override bool IsCreateByXaml
90         {
91             get
92             {
93                 return base.IsCreateByXaml;
94             }
95             set
96             {
97                 base.IsCreateByXaml = value;
98
99                 if (value == true)
100                 {
101                     this.Clicked += (sender, e) =>
102                     {
103                         ICommand command = this.Command;
104                         if (command != null)
105                         {
106                             command.Execute(this.CommandParameter);
107                         }
108                         return true;
109                     };
110                 }
111             }
112         }
113
114         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PushButton obj)
115         {
116             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
117         }
118
119         /// <summary>
120         /// To dispose the PushButton instance.
121         /// </summary>
122         /// <since_tizen> 3 </since_tizen>
123         protected override void Dispose(DisposeTypes type)
124         {
125             if (disposed)
126             {
127                 return;
128             }
129
130             if (type == DisposeTypes.Explicit)
131             {
132                 //Called by User
133                 //Release your own managed resources here.
134                 //You should release all of your own disposable objects here.
135             }
136
137             //Release your own unmanaged resources here.
138             //You should not access any managed member here except static instance.
139             //because the execution order of Finalizes is non-deterministic.
140
141             if (swigCPtr.Handle != global::System.IntPtr.Zero)
142             {
143                 if (swigCMemOwn)
144                 {
145                     swigCMemOwn = false;
146                     Interop.PushButton.delete_PushButton(swigCPtr);
147                 }
148                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
149             }
150
151             base.Dispose(type);
152         }
153
154         internal new class Property
155         {
156             internal static readonly int UNSELECTED_ICON = Interop.PushButton.PushButton_Property_UNSELECTED_ICON_get();
157             internal static readonly int SELECTED_ICON = Interop.PushButton.PushButton_Property_SELECTED_ICON_get();
158             internal static readonly int ICON_ALIGNMENT = Interop.PushButton.PushButton_Property_ICON_ALIGNMENT_get();
159             internal static readonly int LABEL_PADDING = Interop.PushButton.PushButton_Property_LABEL_PADDING_get();
160             internal static readonly int ICON_PADDING = Interop.PushButton.PushButton_Property_ICON_PADDING_get();
161         }
162     }
163 }