[NUI] Refactor dispose pattern to reduce duplication (#1112)
[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     /// This will be deprecated
32     [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
33     [EditorBrowsable(EditorBrowsableState.Never)]
34     public class PushButton : Button
35     {
36         /// This will be deprecated
37         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
38         [EditorBrowsable(EditorBrowsableState.Never)]
39         public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(PushButton), null,
40                 BindingMode.OneWay, null, null, null, null, null as BindableProperty.CreateDefaultValueDelegate);
41         /// This will be deprecated
42         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(PushButton), null,
45                 BindingMode.OneWay, null, null, null, null, null as BindableProperty.CreateDefaultValueDelegate);
46
47
48
49         /// <summary>
50         /// Creates the PushButton.
51         /// </summary>
52         /// <since_tizen> 3 </since_tizen>
53         /// This will be deprecated
54         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         public PushButton() : this(Interop.PushButton.PushButton_New(), true)
57         {
58             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59         }
60
61         internal PushButton(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PushButton.PushButton_SWIGUpcast(cPtr), cMemoryOwn)
62         {
63         }
64
65         /// This will be deprecated
66         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public ICommand Command
69         {
70             get
71             {
72                 return (ICommand)base.GetValue(PushButton.CommandProperty);
73             }
74             set
75             {
76                 base.SetValue(PushButton.CommandProperty, value);
77             }
78         }
79
80         /// This will be deprecated
81         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
82         [EditorBrowsable(EditorBrowsableState.Never)]
83         public object CommandParameter
84         {
85             get
86             {
87                 return base.GetValue(PushButton.CommandParameterProperty);
88             }
89             set
90             {
91                 base.SetValue(PushButton.CommandParameterProperty, value);
92             }
93         }
94
95         /// Only used by the IL of xaml, will never changed to not hidden.
96         [EditorBrowsable(EditorBrowsableState.Never)]
97         public override bool IsCreateByXaml
98         {
99             get
100             {
101                 return base.IsCreateByXaml;
102             }
103             set
104             {
105                 base.IsCreateByXaml = value;
106
107                 if (value == true)
108                 {
109                     this.Clicked += (sender, e) =>
110                     {
111                         ICommand command = this.Command;
112                         if (command != null)
113                         {
114                             command.Execute(this.CommandParameter);
115                         }
116                         return true;
117                     };
118                 }
119             }
120         }
121
122         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PushButton obj)
123         {
124             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
125         }
126
127         /// This will not be public opened.
128         [EditorBrowsable(EditorBrowsableState.Never)]
129         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
130         {
131             Interop.PushButton.delete_PushButton(swigCPtr);
132         }
133
134         internal new class Property
135         {
136             internal static readonly int UNSELECTED_ICON = Interop.PushButton.PushButton_Property_UNSELECTED_ICON_get();
137             internal static readonly int SELECTED_ICON = Interop.PushButton.PushButton_Property_SELECTED_ICON_get();
138             internal static readonly int ICON_ALIGNMENT = Interop.PushButton.PushButton_Property_ICON_ALIGNMENT_get();
139             internal static readonly int LABEL_PADDING = Interop.PushButton.PushButton_Property_LABEL_PADDING_get();
140             internal static readonly int ICON_PADDING = Interop.PushButton.PushButton_Property_ICON_PADDING_get();
141         }
142     }
143 }