[NUI.WindowSystem] introduce the taskbar service feature
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.WindowSystem / src / public / TaskbarService.cs
1 /*
2  * Copyright(c) 2023 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
21 namespace Tizen.NUI.WindowSystem.Shell
22 {
23     /// <summary>
24     /// Class for the Tizen taskbar service.
25     /// </summary>
26     /// This class is need to be hidden as inhouse API.
27     [EditorBrowsable(EditorBrowsableState.Never)]
28     public class TaskbarService : IDisposable
29     {
30         private TizenShell _tzsh;
31         private IntPtr _taskbarService;
32         private int _tzshWin;
33         private bool disposed = false;
34         private bool isDisposeQueued = false;
35
36         /// <summary>
37         /// Enumeration for placed type of taskbar service window.
38         /// </summary>
39         public enum PlaceType
40         {
41             /// <summary>
42             /// Place to Bottom of Screen. Default type.
43             /// </summary>
44             Bottom = 0x0,
45             /// <summary>
46             /// Place to Top of Screen.
47             /// </summary>
48             Top = 0x1,
49             /// <summary>
50             /// Place to Left Side of Screen.
51             /// </summary>
52             Left = 0x2,
53             /// <summary>
54             /// Place to Right Side of Screen.
55             /// </summary>
56             Right = 0x3,
57         }
58
59         /// <summary>
60         /// Creates a new Taskbar Service handle.
61         /// </summary>
62         /// <param name="tzShell">The TizenShell instance.</param>
63         /// <param name="win">The window to provide service of the taskbar.</param>
64         /// <param name="type">The type to be placed on the screen.</param>
65         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
66         /// <exception cref="ArgumentNullException">Thrown when a argument is null.</exception>
67         public TaskbarService(TizenShell tzShell, Window win, PlaceType type = PlaceType.Bottom)
68         {
69             if (tzShell == null)
70             {
71                 throw new ArgumentNullException(nameof(tzShell));
72             }
73             if (tzShell.GetNativeHandle() == IntPtr.Zero)
74             {
75                 throw new ArgumentException("tzShell is not initialized.");
76             }
77             if (win == null)
78             {
79                 throw new ArgumentNullException(nameof(win));
80             }
81
82             _tzsh = tzShell;
83             _tzshWin = win.GetNativeId();
84             _taskbarService = Interop.TaskbarService.Create(_tzsh.GetNativeHandle(), (IntPtr)_tzshWin);
85             if (_taskbarService == IntPtr.Zero)
86             {
87                 int err = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
88                 _tzsh.ErrorCodeThrow(err);
89             }
90
91             Interop.TaskbarService.SetPlaceType(_taskbarService, (int)type);
92         }
93
94         /// <summary>
95         /// Destructor.
96         /// </summary>
97         ~TaskbarService()
98         {
99             if (!isDisposeQueued)
100             {
101                 isDisposeQueued = true;
102                 DisposeQueue.Instance.Add(this);
103             }
104         }
105
106         /// <summary>
107         /// Dispose.
108         /// </summary>
109         public void Dispose()
110         {
111             if (isDisposeQueued)
112             {
113                 Dispose(DisposeTypes.Implicit);
114             }
115             else
116             {
117                 Dispose(DisposeTypes.Explicit);
118                 GC.SuppressFinalize(this);
119             }
120         }
121
122         /// <inheritdoc/>
123         protected virtual void Dispose(DisposeTypes type)
124         {
125             if (!disposed)
126             {
127                 if (_taskbarService != IntPtr.Zero)
128                 {
129                     int res = Interop.TaskbarService.Destroy(_taskbarService);
130                     _taskbarService = IntPtr.Zero;
131                 }
132                 disposed = true;
133             }
134         }
135
136         /// <summary>
137         /// Set the current place type.
138         /// The window manager can use this to determine the geometry of another applications.
139         /// </summary>
140         /// <param name="type">The type of placement, enumeration for the place type.</param>
141         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
142         public void SetPlaceType(PlaceType type)
143         {
144             int res;
145
146             res = Interop.TaskbarService.SetPlaceType(_taskbarService, (int)type);
147             _tzsh.ErrorCodeThrow(res);
148         }
149
150         /// <summary>
151         /// Set the size of the taskbar.
152         /// This may be different from the actual size. The window manager can use this to  
153         /// determine the geometry of another applications.
154         /// </summary>
155         /// <param name="width">The width of the taskbar area.</param>
156         /// <param name="height">The height of the taskbar area.</param>
157         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>             
158         public void SetSize(uint width, uint height)
159         {
160             int res;
161
162             res = Interop.TaskbarService.SetSize(_taskbarService, width, height);
163             _tzsh.ErrorCodeThrow(res);
164         }
165     }
166 }