[NUI] Fix Accessibility warning messages (#2705)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ViewAccessibilityEvent.cs
1 /*
2  * Copyright(c) 2021 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 System.Runtime.InteropServices;
21 using Tizen.NUI.Components;
22 using Tizen.NUI;
23
24 namespace Tizen.NUI.BaseComponents
25 {
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     [StructLayout(LayoutKind.Sequential)]
28     public struct GestureInfoType : IEquatable<GestureInfoType>
29     {
30         [EditorBrowsable(EditorBrowsableState.Never)]
31         public AccessibilityGesture type { get; set; }
32
33         [EditorBrowsable(EditorBrowsableState.Never)]
34         public int xBeg { get; set; }
35
36         [EditorBrowsable(EditorBrowsableState.Never)]
37         public int xEnd { get; set; }
38
39         [EditorBrowsable(EditorBrowsableState.Never)]
40         public int yBeg { get; set; }
41
42         [EditorBrowsable(EditorBrowsableState.Never)]
43         public int yEnd { get; set; }
44
45         [EditorBrowsable(EditorBrowsableState.Never)]
46         public AccessibilityGestureState state { get; set; }
47
48         [EditorBrowsable(EditorBrowsableState.Never)]
49         public uint eventTime { get; set; }
50
51         [EditorBrowsable(EditorBrowsableState.Never)]
52         public override bool Equals(System.Object obj)
53         {
54             if(obj is GestureInfoType)
55             {
56                 return this.Equals((GestureInfoType)obj);
57             }
58             return false;
59         }
60
61         public bool Equals(GestureInfoType other)
62         {
63             if ((other == null) || !this.GetType().Equals(other.GetType()))
64                 return false;
65
66             GestureInfoType sec = (GestureInfoType)other;
67             return
68               type == sec.type &&
69               xBeg == sec.xBeg &&
70               xEnd == sec.xEnd &&
71               yBeg == sec.yBeg &&
72               yEnd == sec.yEnd &&
73               state == sec.state &&
74               eventTime == sec.eventTime;
75         }
76
77         [EditorBrowsable(EditorBrowsableState.Never)]
78         public static bool operator ==(GestureInfoType arg1, GestureInfoType arg2)
79         {
80             return arg1.Equals(arg2);
81         }
82
83         /// <summary>
84         /// The != operator.
85         /// </summary>
86         [EditorBrowsable(EditorBrowsableState.Never)]
87         public static bool operator !=(GestureInfoType arg1, GestureInfoType arg2)
88         {
89             return !arg1.Equals(arg2);
90         }
91
92         [EditorBrowsable(EditorBrowsableState.Never)]
93         public override int GetHashCode()
94         {
95             return Tuple.Create((int)type, xBeg, xEnd, yBeg, yEnd, (int)state, eventTime).GetHashCode();
96         }
97     }
98
99     [EditorBrowsable(EditorBrowsableState.Never)]
100     public class GestureInfoEventArgs : EventArgs
101     {
102         public GestureInfoType GestureInfo { get; internal set; }
103         public int Consumed { get; set; }
104     }
105
106     [EditorBrowsable(EditorBrowsableState.Never)]
107     public class GetDescriptionEventArgs : EventArgs
108     {
109         public string Description { get; internal set; }
110     }
111
112     [EditorBrowsable(EditorBrowsableState.Never)]
113     public class GetNameEventArgs : EventArgs
114     {
115         public string Description { get; internal set; }
116     }
117
118     /// <summary>
119     /// View is the base class for all views.
120     /// </summary>
121     /// <since_tizen> 3 </since_tizen>
122     public partial class View
123     {
124         internal class ControlHandle : SafeHandle {
125             public ControlHandle() : base (IntPtr.Zero, true) {}
126
127             public ControlHandle(IntPtr ptr) : base(ptr, true) {}
128
129             public override bool IsInvalid {
130                 get {
131                     return this.handle == IntPtr.Zero;
132                 }
133             }
134
135             protected override bool ReleaseHandle() {
136                 Interop.View.DeleteControlHandleView(handle);
137                 this.SetHandle(IntPtr.Zero);
138                 return true;
139             }
140         }
141
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         ControlHandle GetControl() {
144             var ret = new ControlHandle(Interop.View.DownCast(SwigCPtr));
145             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146             return ret;
147         }
148
149         ///////////////////////////////////////////////////////////////////
150         // ***************** AccessiblityDoGestureSignal ****************//
151         ///////////////////////////////////////////////////////////////////
152
153         private delegate void GestureInfoHandlerType(IntPtr data);
154         private GestureInfoHandlerType gestureInfoCallback;
155         private EventHandler<GestureInfoEventArgs> gestureInfoHandler;
156
157         private void OnGestureInfoEvent(IntPtr data) {
158             if (data == IntPtr.Zero)
159                 return;
160
161             if (Marshal.SizeOf<GestureInfoType>() != AccessibilityDoGestureSignal.GetSizeOfGestureInfo()) {
162                 throw new global::System.ApplicationException("ABI mismatch SizeOf(C# GestureInfo) != SizeOf(c++ GestureInfo)");
163             }
164
165             var arg = new GestureInfoEventArgs();
166
167             arg.Consumed = AccessibilityDoGestureSignal.GetResult(data);
168             arg.GestureInfo = (GestureInfoType)Marshal.PtrToStructure(data, typeof(GestureInfoType));
169
170             gestureInfoHandler?.Invoke(this, arg);
171
172             AccessibilityDoGestureSignal.SetResult(data, Convert.ToInt32(arg.Consumed));
173         }
174
175         // This uses DoGestureInfo signal from C++ API.
176         [EditorBrowsable(EditorBrowsableState.Never)]
177         public event EventHandler<GestureInfoEventArgs> GestureInfoReceived {
178             add {
179                 if (gestureInfoHandler == null) {
180                     gestureInfoCallback = OnGestureInfoEvent;
181                     GestureInfoSignal().Connect(gestureInfoCallback);
182                 }
183                 gestureInfoHandler += value;
184             }
185             remove {
186                 gestureInfoHandler -= value;
187                 if (gestureInfoHandler == null && GestureInfoSignal().Empty() == false)
188                     GestureInfoSignal().Disconnect(gestureInfoCallback);
189             }
190         }
191
192         internal AccessibilityDoGestureSignal GestureInfoSignal() {
193             var handle = GetControl();
194             AccessibilityDoGestureSignal ret = new AccessibilityDoGestureSignal(Interop.ControlDevel.DaliToolkitDevelControlAccessibilityDoGestureSignal(handle), false);
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196             return ret;
197         }
198
199         ///////////////////////////////////////////////////////////////////
200         // ************** AccessiblityGetDescriptionSignal ************* //
201         ///////////////////////////////////////////////////////////////////
202
203         private delegate void GetDescriptionHandlerType(IntPtr data);
204         private GetDescriptionHandlerType getDescriptionCallback;
205         private EventHandler<GetDescriptionEventArgs> getDescriptionHandler;
206
207         private void OnGetDescriptionEvent(IntPtr data) {
208             if (data == IntPtr.Zero)
209                 return;
210
211             var arg = new GetDescriptionEventArgs();
212             arg.Description = StringToVoidSignal.ConvertParam1(data);
213
214             getDescriptionHandler?.Invoke(this, arg);
215         }
216
217         // This uses GetDescription signal from C++ API.
218         [EditorBrowsable(EditorBrowsableState.Never)]
219         public event EventHandler<GetDescriptionEventArgs> DescriptionRequested {
220             add {
221                 if (getDescriptionHandler == null) {
222                     getDescriptionCallback = OnGetDescriptionEvent;
223                     GetDescriptionSignal().Connect(getDescriptionCallback);
224                 }
225                 getDescriptionHandler += value;
226             }
227             remove {
228                 getDescriptionHandler -= value;
229                 if (getDescriptionHandler == null && GetDescriptionSignal().Empty() == false)
230                     GetDescriptionSignal().Disconnect(getDescriptionCallback);
231             }
232         }
233
234         internal StringToVoidSignal GetDescriptionSignal() {
235             var handle = GetControl();
236             StringToVoidSignal ret = new StringToVoidSignal(Interop.ControlDevel.DaliToolkitDevelControlAccessibilityGetDescriptionSignal(handle), false);
237             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238             return ret;
239         }
240
241         ///////////////////////////////////////////////////////////////////
242         // ***************** AccessiblityGetNameSignal ***************** //
243         ///////////////////////////////////////////////////////////////////
244
245         private delegate void GetNameHandlerType(IntPtr data);
246         private GetNameHandlerType getNameCallback;
247         private EventHandler<GetNameEventArgs> getNameHandler;
248
249         private void OnGetNameEvent(IntPtr data) {
250             if (data == IntPtr.Zero)
251                 return;
252
253             var arg = new GetNameEventArgs();
254             arg.Description = StringToVoidSignal.ConvertParam1(data);
255
256             getNameHandler?.Invoke(this, arg);
257         }
258
259         // This uses GetName signal from C++ API.
260         [EditorBrowsable(EditorBrowsableState.Never)]
261         public event EventHandler<GetNameEventArgs> NameRequested {
262             add {
263                 if (getNameHandler == null) {
264                     getNameCallback = OnGetNameEvent;
265                     GetNameSignal().Connect(getNameCallback);
266                 }
267                 getNameHandler += value;
268             }
269             remove {
270                 getNameHandler -= value;
271                 if (getNameHandler == null && GetNameSignal().Empty() == false)
272                     GetNameSignal().Disconnect(getNameCallback);
273             }
274         }
275
276         internal StringToVoidSignal GetNameSignal() {
277             var handle = GetControl();
278             StringToVoidSignal ret = new StringToVoidSignal(Interop.ControlDevel.DaliToolkitDevelControlAccessibilityGetNameSignal(handle), false);
279             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280             return ret;
281         }
282
283         ///////////////////////////////////////////////////////////////////
284         // **************** AccessibilityActivateSignal **************** //
285         ///////////////////////////////////////////////////////////////////
286
287         private delegate void VoidHandlerType();
288         private VoidHandlerType activateCallback;
289         private EventHandler activateHandler;
290
291         private void OnActivateEvent() {
292             activateHandler?.Invoke(this, null);
293         }
294
295         [EditorBrowsable(EditorBrowsableState.Never)]
296         public event EventHandler Activate {
297             add {
298                 if (activateHandler == null) {
299                     activateCallback = OnActivateEvent;
300                     ActivateSignal().Connect(activateCallback);
301                 }
302                 activateHandler += value;
303             }
304             remove {
305                 activateHandler -= value;
306                 if (activateHandler == null && ActivateSignal().Empty() == false)
307                     ActivateSignal().Disconnect(activateCallback);
308             }
309         }
310
311         internal VoidSignal ActivateSignal() {
312             var handle = GetControl();
313             VoidSignal ret = new VoidSignal(Interop.ControlDevel.DaliToolkitDevelControlAccessibilityActivateSignal(handle), false);
314             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315             return ret;
316         }
317
318         ///////////////////////////////////////////////////////////////////
319         // ************ AccessibilityReadingSkippedSignal ************** //
320         ///////////////////////////////////////////////////////////////////
321
322         private VoidHandlerType readingSkippedCallback;
323         private EventHandler readingSkippedHandler;
324
325         private void OnReadingSkippedEvent() {
326             readingSkippedHandler?.Invoke(this, null);
327         }
328
329         [EditorBrowsable(EditorBrowsableState.Never)]
330         public event EventHandler ReadingSkipped {
331             add {
332                 if (readingSkippedHandler == null) {
333                     readingSkippedCallback = OnReadingSkippedEvent;
334                     ReadingSkippedSignal().Connect(readingSkippedCallback);
335                 }
336                 readingSkippedHandler += value;
337             }
338             remove {
339                 readingSkippedHandler -= value;
340                 if (readingSkippedHandler == null && ReadingSkippedSignal().Empty() == false)
341                     ReadingSkippedSignal().Disconnect(readingSkippedCallback);
342             }
343         }
344
345         internal VoidSignal ReadingSkippedSignal() {
346             var handle = GetControl();
347             VoidSignal ret = new VoidSignal(Interop.ControlDevel.DaliToolkitDevelControlAccessibilityReadingSkippedSignal(handle), false);
348             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349             return ret;
350         }
351
352         ///////////////////////////////////////////////////////////////////
353         // ************* AccessibilityReadingPausedSignal ************** //
354         ///////////////////////////////////////////////////////////////////
355
356         private VoidHandlerType readingPausedCallback;
357         private EventHandler readingPausedHandler;
358
359         private void OnReadingPausedEvent() {
360             readingPausedHandler?.Invoke(this, null);
361         }
362
363         [EditorBrowsable(EditorBrowsableState.Never)]
364         public event EventHandler ReadingPaused {
365             add {
366                 if (readingPausedHandler == null) {
367                     readingPausedCallback = OnReadingPausedEvent;
368                     ReadingPausedSignal().Connect(readingPausedCallback);
369                 }
370                 readingPausedHandler += value;
371             }
372             remove {
373                 readingPausedHandler -= value;
374                 if (readingPausedHandler == null && ReadingPausedSignal().Empty() == false)
375                     ReadingPausedSignal().Disconnect(readingPausedCallback);
376             }
377         }
378
379         internal VoidSignal ReadingPausedSignal() {
380             var handle = GetControl();
381             VoidSignal ret = new VoidSignal(Interop.ControlDevel.DaliToolkitDevelControlAccessibilityReadingPausedSignal(handle), false);
382             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383             return ret;
384         }
385
386         ///////////////////////////////////////////////////////////////////
387         // ************* AccessibilityReadingResumedSignal ************* //
388         ///////////////////////////////////////////////////////////////////
389
390         private VoidHandlerType readingResumedCallback;
391         private EventHandler readingResumedHandler;
392
393         private void OnReadingResumedEvent() {
394             readingResumedHandler?.Invoke(this, null);
395         }
396
397         [EditorBrowsable(EditorBrowsableState.Never)]
398         public event EventHandler ReadingResumed  {
399             add {
400                 if (readingResumedHandler == null) {
401                     readingResumedCallback = OnReadingResumedEvent;
402                     ReadingResumedSignal().Connect(readingResumedCallback);
403                 }
404                 readingResumedHandler += value;
405             }
406             remove {
407                 readingResumedHandler -= value;
408                 if (readingResumedHandler == null && ReadingResumedSignal().Empty() == false)
409                     ReadingResumedSignal().Disconnect(readingResumedCallback);
410             }
411         }
412
413         internal VoidSignal ReadingResumedSignal() {
414             var handle = GetControl();
415             VoidSignal ret = new VoidSignal(Interop.ControlDevel.DaliToolkitDevelControlAccessibilityReadingResumedSignal(handle), false);
416             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417             return ret;
418         }
419
420         ///////////////////////////////////////////////////////////////////
421         // ************ AccessibilityReadingCancelledSignal ************ //
422         ///////////////////////////////////////////////////////////////////
423
424         private VoidHandlerType readingCancelledCallback;
425         private EventHandler readingCancelledHandler;
426
427         private void OnReadingCancelledEvent() {
428             readingCancelledHandler?.Invoke(this, null);
429         }
430
431         [EditorBrowsable(EditorBrowsableState.Never)]
432         public event EventHandler ReadingCancelled  {
433             add {
434                 if (readingCancelledHandler == null) {
435                     readingCancelledCallback = OnReadingCancelledEvent;
436                     ReadingCancelledSignal().Connect(readingCancelledCallback);
437                 }
438                 readingCancelledHandler += value;
439             }
440             remove {
441                 readingCancelledHandler -= value;
442                 if (readingCancelledHandler == null && ReadingCancelledSignal().Empty() == false)
443                     ReadingCancelledSignal().Disconnect(readingCancelledCallback);
444             }
445         }
446
447         internal VoidSignal ReadingCancelledSignal() {
448             var handle = GetControl();
449             VoidSignal ret = new VoidSignal(Interop.ControlDevel.DaliToolkitDevelControlAccessibilityReadingCancelledSignal(handle), false);
450             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
451             return ret;
452         }
453
454         ///////////////////////////////////////////////////////////////////
455         // ************* AccessibilityReadingStoppedSignal ************* //
456         ///////////////////////////////////////////////////////////////////
457
458         private VoidHandlerType readingStoppedCallback;
459         private EventHandler readingStoppedHandler;
460
461         private void OnReadingStoppedEvent() {
462             readingStoppedHandler?.Invoke(this, null);
463         }
464
465         [EditorBrowsable(EditorBrowsableState.Never)]
466         public event EventHandler ReadingStopped  {
467             add {
468                 if (readingStoppedHandler == null) {
469                     readingStoppedCallback = OnReadingStoppedEvent;
470                     ReadingStoppedSignal().Connect(readingStoppedCallback);
471                 }
472                 readingStoppedHandler += value;
473             }
474             remove {
475                 readingStoppedHandler -= value;
476                 if (readingStoppedHandler == null && ReadingStoppedSignal().Empty() == false)
477                     ReadingStoppedSignal().Disconnect(readingStoppedCallback);
478             }
479         }
480
481         internal VoidSignal ReadingStoppedSignal() {
482             var handle = GetControl();
483             VoidSignal ret = new VoidSignal(Interop.ControlDevel.DaliToolkitDevelControlAccessibilityReadingStoppedSignal(handle), false);
484             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
485             return ret;
486         }
487     }
488 }