Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / AccessibleObject.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.Accessible
20 {
21     /// <summary>
22     /// The delegate to define how to provide informations for <see cref="IAccessibleObject.Name"/> or <see cref="IAccessibleObject.Description"/>.
23     /// </summary>
24     /// <param name="obj">The sender obj.</param>
25     /// <returns>Return information for Name or Description.</returns>
26     public delegate string AccessibleInfoProvider (AccessibleObject obj);
27
28     /// <summary>
29     /// It's a base abstract class for <see cref="Widget"/>.
30     /// It provides available definitions for the screen reader, such as <see cref="IAccessibleObject.Name"/>, <see cref="IAccessibleObject.Description"/>, <see cref="IAccessibleObject.ReadingInfoType"/>, etc.
31     /// There's many the relationship between two accessible objects, like <see cref="ChildOf"/>, <see cref="ParentOf"/>, <see cref="FlowsTo"/>, <see cref="FlowsFrom"/>, etc.
32     /// </summary>
33     public abstract class AccessibleObject : EvasObject, IAccessibleObject
34     {
35
36         AccessibleInfoProvider _nameProvider;
37         AccessibleInfoProvider _descriptionProvider;
38
39         Interop.Elementary.Elm_Atspi_Reading_Info_Cb _nameProviderInternal;
40         Interop.Elementary.Elm_Atspi_Reading_Info_Cb _descriptionProviderInternal;
41
42         /// <summary>
43         /// Gets or sets the reading information types of an accessible object.
44         /// </summary>
45         ReadingInfoType IAccessibleObject.ReadingInfoType
46         {
47             get
48             {
49                 return (ReadingInfoType)Interop.Elementary.elm_atspi_accessible_reading_info_type_get(RealHandle);
50             }
51             set
52             {
53                 Interop.Elementary.elm_atspi_accessible_reading_info_type_set(RealHandle,
54                         (Interop.Elementary.Elm_Accessible_Reading_Info_Type)value);
55             }
56         }
57
58         /// <summary>
59         /// Gets or sets the role of the object in accessibility domain.
60         /// </summary>
61         AccessRole IAccessibleObject.Role
62         {
63             get
64             {
65                 return (AccessRole)Interop.Elementary.elm_atspi_accessible_role_get(RealHandle);
66             }
67             set
68             {
69                 Interop.Elementary.elm_atspi_accessible_role_set(RealHandle,
70                         (Interop.Elementary.Elm_Atspi_Role)value);
71             }
72         }
73
74         /// <summary>
75         /// Gets or sets highlightable of given widget.
76         /// </summary>
77         bool IAccessibleObject.CanHighlight
78         {
79             get
80             {
81                 return Interop.Elementary.elm_atspi_accessible_can_highlight_get(RealHandle);
82             }
83             set
84             {
85                 Interop.Elementary.elm_atspi_accessible_can_highlight_set(RealHandle, value);
86             }
87         }
88
89         /// <summary>
90         /// Gets or sets the translation domain of "name" and "description" properties.
91         /// Translation domain should be set if application wants to support i18n for accessibily "name" and "description" properties.
92         /// When translation domain is set values of "name" and "description" properties will be translated with dgettext function using current translation domain as "domainname" parameter.
93         /// It is application developer responsibility to ensure that translation files are loaded and binded to translation domain when accessibility is enabled.
94         /// </summary>
95         string IAccessibleObject.TranslationDomain
96         {
97             get
98             {
99                 return Interop.Elementary.elm_atspi_accessible_translation_domain_get(RealHandle);
100             }
101             set
102             {
103                 Interop.Elementary.elm_atspi_accessible_translation_domain_set(RealHandle, value);
104             }
105         }
106
107         /// <summary>
108         /// Gets or sets an accessible name of the object.
109         /// </summary>
110         string IAccessibleObject.Name
111         {
112             get
113             {
114                 return Interop.Elementary.elm_atspi_accessible_name_get(RealHandle);
115             }
116             set
117             {
118                 Interop.Elementary.elm_atspi_accessible_name_set(RealHandle, value);
119             }
120         }
121
122         /// <summary>
123         /// Gets or sets contextual information about object.
124         /// </summary>
125         string IAccessibleObject.Description
126         {
127             get
128             {
129                 return Interop.Elementary.elm_atspi_accessible_description_get(RealHandle);
130             }
131             set
132             {
133                 Interop.Elementary.elm_atspi_accessible_description_set(RealHandle, value);
134             }
135         }
136
137         /// <summary>
138         /// Gets or sets the delegate for <see cref="IAccessibleObject.Name"/>.
139         /// </summary>
140         AccessibleInfoProvider IAccessibleObject.NameProvider
141         {
142             get
143             {
144                 return _nameProvider;
145             }
146
147             set
148             {
149                 if (_nameProviderInternal == null)
150                 {
151                     _nameProviderInternal = (data, obj) => _nameProvider(this);
152                 }
153                 if (value == null)
154                 {
155                     _nameProvider = null;
156                     Interop.Elementary.elm_atspi_accessible_name_cb_set(RealHandle, null, IntPtr.Zero);
157                 }
158                 else
159                 {
160                     _nameProvider = new AccessibleInfoProvider(value);
161                     Interop.Elementary.elm_atspi_accessible_name_cb_set(RealHandle, _nameProviderInternal, IntPtr.Zero);
162                 }
163             }
164         }
165
166         /// <summary>
167         /// Gets or sets the delegate for <see cref = "IAccessibleObject.Description" />.
168         /// </summary>
169         AccessibleInfoProvider IAccessibleObject.DescriptionProvider
170         {
171             get
172             {
173                 return _descriptionProvider;
174             }
175
176             set
177             {
178                 if (_descriptionProviderInternal == null)
179                 {
180                     _descriptionProviderInternal = (data, obj) => _descriptionProvider(this);
181                 }
182                 if (value == null)
183                 {
184                     _descriptionProvider = null;
185                     Interop.Elementary.elm_atspi_accessible_description_cb_set(RealHandle, null, IntPtr.Zero);
186                 }
187                 else
188                 {
189                     _descriptionProvider = new AccessibleInfoProvider(value);
190                     Interop.Elementary.elm_atspi_accessible_description_cb_set(RealHandle, _descriptionProviderInternal, IntPtr.Zero);
191                 }
192             }
193         }
194
195         /// <summary>
196         /// Creates and initializes a new instance of the AccessibleObject class with parent EvasObject class parameter.
197         /// </summary>
198         /// <param name="parent">Parent EvasObject class </param>
199         public AccessibleObject(EvasObject parent) : base(parent)
200         {
201         }
202
203         /// <summary>
204         /// Creates and initializes a new instance of the AccessibleObject class.
205         /// </summary>
206         public AccessibleObject() : base()
207         {
208         }
209
210         /// <summary>
211         /// Defines the relationship between two accessible objects.
212         /// Relationships can be queried by Assistive Technology clients to provide customized feedback, improving overall user experience.
213         /// AppendRelation API is asymmetric, which means that appending, for example, relation <see cref="FlowsTo"/> from object A to B, do not append relation <see cref="FlowsFrom"/> from object B to object A.
214         /// </summary>
215         /// <param name="relation">The relationship between source object and target object of a given type.</param>
216         void IAccessibleObject.AppendRelation(IAccessibleRelation relation)
217         {
218             if (relation.Target == null) throw new ArgumentException("Target of Accessibility relation can not be null");
219             Interop.Elementary.elm_atspi_accessible_relationship_append(RealHandle, relation.Type, relation.Target.Handle);
220         }
221
222         /// <summary>
223         /// Removes the relationship between two accessible objects.
224         /// </summary>
225         /// <param name="relation">The relationship between source object and target object of a given type.</param>
226         void IAccessibleObject.RemoveRelation(IAccessibleRelation relation)
227         {
228             if (relation.Target == null) throw new ArgumentException("Target of Accessibility relation can not be null");
229             Interop.Elementary.elm_atspi_accessible_relationship_remove(RealHandle, relation.Type, relation.Target.Handle);
230         }
231
232         /// <summary>
233         /// Highlights accessible widget.
234         /// </summary>
235         public void Highlight()
236         {
237             Interop.Elementary.elm_atspi_component_highlight_grab(RealHandle);
238         }
239
240         /// <summary>
241         /// Clears highlight of accessible widget.
242         /// </summary>
243         public void Unhighlight()
244         {
245             Interop.Elementary.elm_atspi_component_highlight_clear(RealHandle);
246         }
247     }
248 }