[ACR-564] deprecate unused API
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Widget.cs
1 /*
2  * Copyright (c) 2018 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 using System.Collections.Generic;
19 using ElmSharp.Accessible;
20
21 namespace ElmSharp
22 {
23     /// <summary>
24     /// Enumeration for the focus direction.
25     /// </summary>
26     /// <since_tizen> preview </since_tizen>
27     [Obsolete("This has been deprecated in API12")]
28     public enum FocusDirection
29     {
30         /// <summary>
31         /// Previous direction.
32         /// </summary>
33         Previous,
34
35         /// <summary>
36         /// Next direction.
37         /// </summary>
38         Next,
39
40         /// <summary>
41         /// Up direction.
42         /// </summary>
43         Up,
44
45         /// <summary>
46         /// Down direction.
47         /// </summary>
48         Down,
49
50         /// <summary>
51         /// Right direction.
52         /// </summary>
53         Right,
54
55         /// <summary>
56         /// Left direction.
57         /// </summary>
58         Left
59     }
60
61     /// <summary>
62     /// The Widget is an abstract class and the parent of other widgets.
63     /// Inherits from <see cref="EvasObject"/>.
64     /// </summary>
65     /// <since_tizen> preview </since_tizen>
66     [Obsolete("This has been deprecated in API12")]
67     public abstract class Widget : AccessibleObject
68     {
69         Dictionary<string, EvasObject> _partContents = new Dictionary<string, EvasObject>();
70
71         SmartEvent _focused;
72         SmartEvent _unfocused;
73
74         internal Color _backgroundColor = Color.Default;
75         internal int _opacity = Color.Default.A;
76
77         /// <summary>
78         /// Creates and initializes a new instance of the Widget class.
79         /// </summary>
80         /// <since_tizen> preview </since_tizen>
81         [Obsolete("This has been deprecated in API12")]
82         protected Widget()
83         {
84         }
85
86         /// <summary>
87         /// Creates and initializes a new instance of the Widget class.
88         /// </summary>
89         /// <param name="parent">The parent of the new Widget instance.</param>
90         /// <since_tizen> preview </since_tizen>
91         [Obsolete("This has been deprecated in API12")]
92         protected Widget(EvasObject parent) : base(parent)
93         {
94         }
95
96         /// <summary>
97         /// Updates the part contents.
98         /// </summary>
99         /// <param name="content">The content which is put into the part.</param>
100         /// <param name="part">The updated part.</param>
101         /// <since_tizen> preview </since_tizen>
102         [Obsolete("This has been deprecated in API12")]
103         protected void UpdatePartContents(EvasObject content, string part = "__default__")
104         {
105             _partContents[part] = content;
106         }
107
108         /// <summary>
109         /// Focused will be triggered when the widget is focused.
110         /// </summary>
111         /// <since_tizen> preview </since_tizen>
112         [Obsolete("This has been deprecated in API12")]
113         public event EventHandler Focused;
114
115         /// <summary>
116         /// Unfocused will be triggered when the widget is unfocused.
117         /// </summary>
118         /// <since_tizen> preview </since_tizen>
119         [Obsolete("This has been deprecated in API12")]
120         public event EventHandler Unfocused;
121
122         /// <summary>
123         /// Sets or gets the state of the widget, which might be enabled or disabled.
124         /// </summary>
125         /// <since_tizen> preview </since_tizen>
126         [Obsolete("This has been deprecated in API12")]
127         public virtual bool IsEnabled
128         {
129             get
130             {
131                 return !Interop.Elementary.elm_object_disabled_get(RealHandle);
132             }
133             set
134             {
135                 Interop.Elementary.elm_object_disabled_set(RealHandle, !value);
136             }
137         }
138
139         /// <summary>
140         /// Sets or gets the style of the widget.
141         /// </summary>
142         /// <since_tizen> preview </since_tizen>
143         [Obsolete("This has been deprecated in API12")]
144         public string Style
145         {
146             get
147             {
148                 return Interop.Elementary.elm_object_style_get(RealHandle);
149             }
150             set
151             {
152                 Interop.Elementary.elm_object_style_set(RealHandle, value);
153             }
154         }
155
156         /// <summary>
157         /// Gets whether this widget is focused.
158         /// </summary>
159         /// <since_tizen> preview </since_tizen>
160         [Obsolete("This has been deprecated in API12")]
161         public bool IsFocused
162         {
163             get
164             {
165                 return Interop.Elementary.elm_object_focus_get(RealHandle);
166             }
167         }
168
169         /// <summary>
170         /// Gets whether a widget is focusable or not.
171         /// </summary>
172         /// <remarks>Widgets which are meant to be interacted with by input events, are created able to be focused by default.</remarks>
173         /// <since_tizen> preview </since_tizen>
174         [Obsolete("This has been deprecated in API12")]
175         public bool IsFocusAllowed
176         {
177             get
178             {
179                 return Interop.Elementary.elm_object_focus_allow_get(RealHandle);
180             }
181         }
182
183         /// <summary>
184         /// Sets or gets the text of the widget.
185         /// </summary>
186         /// <remarks>It could be overridden by special child class.</remarks>
187         /// <since_tizen> preview </since_tizen>
188         [Obsolete("This has been deprecated in API12")]
189         public virtual string Text
190         {
191             get
192             {
193                 return Interop.Elementary.elm_object_part_text_get(RealHandle);
194             }
195             set
196             {
197                 Interop.Elementary.elm_object_part_text_set(RealHandle, IntPtr.Zero, value);
198             }
199         }
200
201         /// <summary>
202         /// Sets or gets the background color of the widget.
203         /// </summary>
204         /// <remarks>It could be overridden by special child class.</remarks>
205         /// <since_tizen> preview </since_tizen>
206         [Obsolete("This has been deprecated in API12")]
207         public virtual Color BackgroundColor
208         {
209             get
210             {
211                 if (!_backgroundColor.IsDefault)
212                 {
213                     _backgroundColor = GetPartColor("bg");
214                 }
215                 return _backgroundColor;
216             }
217             set
218             {
219                 if (value.IsDefault)
220                 {
221                     Console.WriteLine("Widget instance doesn't support to set BackgroundColor to Color.Default.");
222                 }
223                 else
224                 {
225                     SetPartColor("bg", value);
226                     _backgroundColor = value;
227                 }
228             }
229         }
230
231         /// <summary>
232         /// Sets or gets the opacity of the widget.
233         /// </summary>
234         /// <remarks>It could be overridden by special child class.</remarks>
235         /// <since_tizen> preview </since_tizen>
236         [Obsolete("This has been deprecated in API12")]
237         public virtual int Opacity
238         {
239             get
240             {
241                 if (_opacity != Color.Default.A)
242                 {
243                     _opacity = GetPartOpacity("opacity");
244                 }
245                 return _opacity;
246             }
247             set
248             {
249                 SetPartOpacity("opacity", value);
250                 _opacity = value;
251             }
252         }
253
254         /// <summary>
255         /// Sets or gets whether a widget and its children are focusable or not.
256         /// </summary>
257         /// <since_tizen> preview </since_tizen>
258         [Obsolete("This has been deprecated in API12")]
259         public bool AllowTreeFocus
260         {
261             get
262             {
263                 return Interop.Elementary.elm_object_tree_focus_allow_get(RealHandle);
264             }
265             set
266             {
267                 Interop.Elementary.elm_object_tree_focus_allow_set(RealHandle, value);
268             }
269         }
270
271         /// <summary>
272         /// Sets or gets the widget's mirrored mode.
273         /// </summary>
274         /// <since_tizen> preview </since_tizen>
275         [Obsolete("This has been deprecated in API12")]
276         public bool IsMirroredMode
277         {
278             get
279             {
280                 return Interop.Elementary.elm_object_mirrored_get(RealHandle);
281             }
282             set
283             {
284                 Interop.Elementary.elm_object_mirrored_set(RealHandle, value);
285             }
286         }
287
288         /// <summary>
289         /// Sets or gets the widget's mirrored mode setting.
290         /// When widget is set to automatic mode(true), it follows the system mirrored mode.
291         /// </summary>
292         /// <since_tizen> preview </since_tizen>
293         [Obsolete("This has been deprecated in API12")]
294         public bool IsAutoMirroredMode
295         {
296             get
297             {
298                 return Interop.Elementary.elm_object_mirrored_automatic_get(RealHandle);
299             }
300             set
301             {
302                 Interop.Elementary.elm_object_mirrored_automatic_set(RealHandle, value);
303             }
304         }
305
306         /// <summary>
307         /// Sets the widget to be focused or not.
308         /// </summary>
309         /// <param name="isFocus">Whether be focused.</param>
310         /// <since_tizen> preview </since_tizen>
311         [Obsolete("This has been deprecated in API12")]
312         public void SetFocus(bool isFocus)
313         {
314             if (isFocus)
315             {
316                 Interop.Elementary.elm_object_focus_set(RealHandle, isFocus);
317             }
318             else
319             {
320                 Interop.Elementary.elm_object_focused_clear(RealHandle);
321             }
322         }
323
324         /// <summary>
325         /// Sets the ability for a widget to be focused.
326         /// </summary>
327         /// <param name="isAllowFocus">true if the object can be focused, false if not(and on errors).</param>
328         /// <since_tizen> preview </since_tizen>
329         [Obsolete("This has been deprecated in API12")]
330         public void AllowFocus(bool isAllowFocus)
331         {
332             Interop.Elementary.elm_object_focus_allow_set(RealHandle, isAllowFocus);
333         }
334
335         /// <summary>
336         /// Gives focus to the next widget in the widget tree.
337         /// </summary>
338         /// <param name="direction">Direction to move the focus.</param>
339         /// <since_tizen> preview </since_tizen>
340         [Obsolete("This has been deprecated in API12")]
341         public void FocusNext(FocusDirection direction)
342         {
343             Interop.Elementary.elm_object_focus_next(RealHandle, (int)direction);
344         }
345
346         /// <summary>
347         /// Sets the next widget with specific focus direction.
348         /// </summary>
349         /// <param name="next">Focus next widget.</param>
350         /// <param name="direction">Focus direction.</param>
351         /// <since_tizen> preview </since_tizen>
352         [Obsolete("This has been deprecated in API12")]
353         public void SetNextFocusObject(EvasObject next, FocusDirection direction)
354         {
355             Interop.Elementary.elm_object_focus_next_object_set(RealHandle, next?.RealHandle ?? IntPtr.Zero, (int)direction);
356         }
357
358         /// <summary>
359         /// Sets content to the particular part of the widget, and the preserve old content will be deleted.
360         /// </summary>
361         /// <param name="part">The name of the particular part.</param>
362         /// <param name="content">The content.</param>
363         /// <seealso cref="SetPartContent(string, EvasObject, bool)"/>
364         /// <since_tizen> preview </since_tizen>
365         [Obsolete("This has been deprecated in API12")]
366         public virtual bool SetPartContent(string part, EvasObject content)
367         {
368             return SetPartContent(part, content, false);
369         }
370
371         /// <summary>
372         /// Sets content to the particular part of the widget.
373         /// </summary>
374         /// <param name="part">The name of the particular part.</param>
375         /// <param name="content">The content.</param>
376         /// <param name="preserveOldContent">true, preserve old content will be unset and not be deleted. false, preserve old content will be deleted.</param>
377         /// <seealso cref="SetPartContent(string, EvasObject)"/>
378         /// <since_tizen> preview </since_tizen>
379         [Obsolete("This has been deprecated in API12")]
380         public virtual bool SetPartContent(string part, EvasObject content, bool preserveOldContent)
381         {
382             if (preserveOldContent)
383             {
384                 Interop.Elementary.elm_object_part_content_unset(RealHandle, part);
385             }
386             Interop.Elementary.elm_object_part_content_set(RealHandle, part, content);
387             UpdatePartContents(content, part);
388             return true;
389         }
390
391         /// <summary>
392         /// Sets content to the widget, and the preserve old content will be deleted.
393         /// </summary>
394         /// <param name="content">The content.</param>
395         /// <seealso cref="SetContent(EvasObject, bool)"/>
396         /// <since_tizen> preview </since_tizen>
397         [Obsolete("This has been deprecated in API12")]
398         public void SetContent(EvasObject content)
399         {
400             SetContent(content, false);
401         }
402
403         /// <summary>
404         /// Sets content to the widget.
405         /// </summary>
406         /// <param name="content">The content.</param>
407         /// <param name="preserveOldContent">true, preserve old content will be unset and not be deleted. false, preserve old content will be deleted.</param>
408         /// <seealso cref="SetContent(EvasObject)"/>
409         /// <since_tizen> preview </since_tizen>
410         [Obsolete("This has been deprecated in API12")]
411         public void SetContent(EvasObject content, bool preserveOldContent)
412         {
413             if (preserveOldContent)
414             {
415                 Interop.Elementary.elm_object_content_unset(RealHandle);
416             }
417
418             Interop.Elementary.elm_object_content_set(RealHandle, content);
419             UpdatePartContents(content);
420         }
421
422         /// <summary>
423         /// Sets text to the particular part of the widget.
424         /// </summary>
425         /// <param name="part">The name of the particular part.</param>
426         /// <param name="text">The text.</param>
427         /// <since_tizen> preview </since_tizen>
428         [Obsolete("This has been deprecated in API12")]
429         public virtual bool SetPartText(string part, string text)
430         {
431             Interop.Elementary.elm_object_part_text_set(RealHandle, part, text);
432             return true;
433         }
434
435         /// <summary>
436         /// Gets text of a particular part of the widget.
437         /// </summary>
438         /// <param name="part">The name of the particular part.</param>
439         /// <returns>Text of the particular part of the widget.</returns>
440         /// <since_tizen> preview </since_tizen>
441         [Obsolete("This has been deprecated in API12")]
442         public virtual string GetPartText(string part)
443         {
444             return Interop.Elementary.elm_object_part_text_get(RealHandle, part);
445         }
446
447         /// <summary>
448         /// Sets color of a particular part of the widget.
449         /// </summary>
450         /// <param name="part">The name of the particular part.</param>
451         /// <param name="color">The color to be set to the widget.</param>
452         /// <remarks>This method is a virtual method, it could be overridden by special child class.</remarks>
453         /// <since_tizen> preview </since_tizen>
454         [Obsolete("This has been deprecated in API12")]
455         public virtual void SetPartColor(string part, Color color)
456         {
457             Interop.Elementary.elm_object_color_class_color_set(RealHandle, part, color.R * color.A / 255,
458                                                                               color.G * color.A / 255,
459                                                                               color.B * color.A / 255,
460                                                                               color.A);
461         }
462
463         /// <summary>
464         /// Gets color of the particular part of the widget.
465         /// </summary>
466         /// <param name="part">The name of the particular part.</param>
467         /// <returns>The color of the particular part.</returns>
468         /// <remarks>This method is a virtual method, it could be overridden by special child class.</remarks>
469         /// <since_tizen> preview </since_tizen>
470         [Obsolete("This has been deprecated in API12")]
471         public virtual Color GetPartColor(string part)
472         {
473             int r, g, b, a;
474             Interop.Elementary.elm_object_color_class_color_get(RealHandle, part, out r, out g, out b, out a);
475             return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
476         }
477
478         /// <summary>
479         /// Sets opacity of the particular part of the widget.
480         /// </summary>
481         /// <param name="part">The name of the particular part.</param>
482         /// <param name="opacity">The opacity of the particular part.</param>
483         /// <since_tizen> preview </since_tizen>
484         [Obsolete("This has been deprecated in API12")]
485         public void SetPartOpacity(string part, int opacity)
486         {
487             Interop.Elementary.elm_object_color_class_color_set(Handle, part, 255, 255, 255, opacity);
488         }
489
490         /// <summary>
491         /// Gets opacity of the particular part of the widget.
492         /// </summary>
493         /// <param name="part">The name of the particular part.</param>
494         /// <returns>Opacity value of the particular part.</returns>
495         /// <since_tizen> preview </since_tizen>
496         [Obsolete("This has been deprecated in API12")]
497         public int GetPartOpacity(string part)
498         {
499             int r, g, b, a;
500             Interop.Elementary.elm_object_color_class_color_get(Handle, part, out r, out g, out b, out a);
501             return a;
502         }
503
504         /// <summary>
505         /// Sends a signal to the edje object of the widget.
506         /// </summary>
507         /// <param name="emission">The signal's name.</param>
508         /// <param name="source">The signal's source.</param>
509         /// <since_tizen> preview </since_tizen>
510         [Obsolete("This has been deprecated in API12")]
511         public void SignalEmit(string emission, string source)
512         {
513             Interop.Elementary.elm_object_signal_emit(Handle, emission, source);
514         }
515
516         /// <summary>
517         /// The callback of the Realized event.
518         /// </summary>
519         /// <since_tizen> preview </since_tizen>
520         [Obsolete("This has been deprecated in API12")]
521         protected override void OnRealized()
522         {
523             base.OnRealized();
524             _focused = new SmartEvent(this, "focused");
525             _focused.On += (s, e) => Focused?.Invoke(this, EventArgs.Empty);
526
527             _unfocused = new SmartEvent(this, "unfocused");
528             _unfocused.On += (s, e) => Unfocused?.Invoke(this, EventArgs.Empty);
529         }
530
531         internal IntPtr GetPartContent(string part)
532         {
533             return Interop.Elementary.elm_object_part_content_get(RealHandle, part);
534         }
535     }
536 }