[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Radio.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// The Radio is a widget that allows for 1 or more options to be displayed, and have the user choose only 1 of them.
23     /// </summary>
24     /// <since_tizen> preview </since_tizen>
25     public class Radio : Layout
26     {
27         SmartEvent _changed;
28
29         /// <summary>
30         /// Creates and initializes a new instance of the Radio class.
31         /// </summary>
32         /// <param name="parent">The EvasObject to which the new Radio will be attached as a child.</param>
33         /// <since_tizen> preview </since_tizen>
34         public Radio(EvasObject parent) : base(parent)
35         {
36             _changed = new SmartEvent(this, this.RealHandle, "changed");
37             _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
38         }
39
40         /// <summary>
41         /// ValueChanged will be triggered when value of the radio changes.
42         /// </summary>
43         /// <since_tizen> preview </since_tizen>
44         public event EventHandler ValueChanged;
45
46         /// <summary>
47         /// Sets or gets a unique value to each radio button.
48         /// </summary>
49         /// <since_tizen> preview </since_tizen>
50         public int StateValue
51         {
52             get
53             {
54                 return Interop.Elementary.elm_radio_state_value_get(RealHandle);
55             }
56             set
57             {
58                 Interop.Elementary.elm_radio_state_value_set(RealHandle, value);
59             }
60         }
61
62         /// <summary>
63         /// Sets or gets the value of the radio group.
64         /// </summary>
65         /// <since_tizen> preview </since_tizen>
66         public int GroupValue
67         {
68             get
69             {
70                 return Interop.Elementary.elm_radio_value_get(RealHandle);
71             }
72             set
73             {
74                 Interop.Elementary.elm_radio_value_set(RealHandle, value);
75             }
76         }
77
78         /// <summary>
79         /// Adds this radio to a group of other radio objects.
80         /// </summary>
81         /// <param name="group">Group which add radio in.</param>
82         /// <since_tizen> preview </since_tizen>
83         public void SetGroup(Radio group)
84         {
85             if (group == null)
86             {
87                 throw new ArgumentNullException("group");
88             }
89             Interop.Elementary.elm_radio_group_add(RealHandle, group.RealHandle);
90         }
91
92         /// <summary>
93         /// Creates a widget handle.
94         /// </summary>
95         /// <param name="parent">Parent EvasObject.</param>
96         /// <returns>Handle IntPtr.</returns>
97         /// <since_tizen> preview </since_tizen>
98         protected override IntPtr CreateHandle(EvasObject parent)
99         {
100             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
101             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
102
103             RealHandle = Interop.Elementary.elm_radio_add(handle);
104             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
105
106             return handle;
107         }
108     }
109 }