7eac68c4f314605d1af55ede026b3c3215dd4204
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.WindowSystem / src / public / QuickPanelService.cs
1 /*
2  * Copyright(c) 2020 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.Collections.Generic;
20 using System.ComponentModel;
21 using System.Text;
22
23 namespace Tizen.NUI.WindowSystem.Shell
24 {
25     /// <summary>
26     /// Class for the Tizen quickpanel service.
27     /// </summary>
28     /// This class is need to be hidden as inhouse API.
29     [EditorBrowsable(EditorBrowsableState.Never)]
30     public class QuickPanelService : IDisposable
31     {
32         private TizenShell _tzsh;
33         private IntPtr _tzshQpService;
34         private int _tzshWin;
35         private bool disposed = false;
36         private bool isDisposeQueued = false;
37
38         /// <summary>
39         /// QuickPanel Type.
40         /// </summary>
41         public enum Types
42         {
43             /// <summary>
44             /// Unknown type. There is no quickpanel service.
45             /// </summary>
46             Unknown = 0x0,
47             /// <summary>
48             /// System default type.
49             /// </summary>
50             SystemDefault = 0x1,
51             /// <summary>
52             /// Context menu type.
53             /// </summary>
54             ContextMenu = 0x2,
55             /// <summary>
56             /// Apps menu type.
57             /// </summary>
58             AppsMenu = 0x3,
59         }
60
61         /// <summary>
62         /// Effect type.
63         /// </summary>
64         public enum EffectType
65         {
66             /// <summary>
67             /// Swipe effect
68             /// </summary>
69             Swipe = 0,
70             /// <summary>
71             /// Move effect
72             /// </summary>
73             Move = 1,
74             /// <summary>
75             /// App control effect
76             /// </summary>
77             Custom = 2,
78         }
79
80         /// <summary>
81         /// Creates a new Quickpanel Service handle.
82         /// </summary>
83         /// <param name="tzShell">The TzShell instance.</param>
84         /// <param name="win">The window to provide service of the quickpanel.</param>
85         /// <param name="type">The type of quickpanel service.</param>
86         /// <exception cref="Tizen.Applications.Exceptions.OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
87         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
88         /// <exception cref="ArgumentNullException">Thrown when a argument is null.</exception>
89         public QuickPanelService(TizenShell tzShell, Window win, Types type)
90         {
91             if (tzShell == null)
92             {
93                 throw new ArgumentNullException(nameof(tzShell));
94             }
95             if (tzShell.GetNativeHandle() == IntPtr.Zero)
96             {
97                 throw new ArgumentException("tzShell is not initialized.");
98             }
99             if (win == null)
100             {
101                 throw new ArgumentNullException(nameof(win));
102             }
103
104             _tzsh = tzShell;
105             _tzshWin = win.GetNativeId();
106             _tzshQpService = Interop.QuickPanelService.CreateWithType(_tzsh.GetNativeHandle(), (IntPtr)_tzshWin, (int)type);
107             if (_tzshQpService == IntPtr.Zero)
108             {
109                 int err = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
110                 _tzsh.ErrorCodeThrow(err);
111             }
112         }
113
114         /// <summary>
115         /// Destructor.
116         /// </summary>
117         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
118         ~QuickPanelService()
119         {
120             if (!isDisposeQueued)
121             {
122                 isDisposeQueued = true;
123                 DisposeQueue.Instance.Add(this);
124             }
125         }
126
127         /// <summary>
128         /// Dispose.
129         /// </summary>
130         /// <exception cref="MemberAccessException">Thrown when private memeber is a corrupted.</exception>
131         public void Dispose()
132         {
133             if (isDisposeQueued)
134             {
135                 Dispose(DisposeTypes.Implicit);
136             }
137             else
138             {
139                 Dispose(DisposeTypes.Explicit);
140                 GC.SuppressFinalize(this);
141             }
142         }
143
144         /// <inheritdoc/>
145         protected virtual void Dispose(DisposeTypes disposing)
146         {
147             int res;
148             if (!disposed)
149             {
150                 if (_tzshQpService != IntPtr.Zero)
151                 {
152                     res = Interop.QuickPanelService.Destroy(_tzshQpService);
153                     try
154                     {
155                         _tzsh.ErrorCodeThrow(res);
156                     }
157                     catch (ArgumentException e)
158                     {
159                         throw new MemberAccessException("QuickPanelService is a corrupted");
160                     }
161                     _tzshQpService = IntPtr.Zero;
162                 }
163                 disposed = true;
164             }
165         }
166
167         /// <summary>
168         /// Gets the type of the quickpanel service handle.
169         /// </summary>
170         /// <returns>The type of the quickpanel service handle</returns>
171         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
172         public Types ServiceType
173         {
174             get
175             {
176                 return GetType();
177             }
178         }
179
180         private new Types GetType()
181         {
182             int res;
183             int type;
184
185             res = Interop.QuickPanelService.GetType(_tzshQpService, out type);
186
187             _tzsh.ErrorCodeThrow(res);
188
189             return (Types)type;
190         }
191
192         /// <summary>
193         /// Requests to show the quickpanel service window.
194         /// </summary>
195         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
196         public void Show()
197         {
198             int res;
199
200             res = Interop.QuickPanelService.Show(_tzshQpService);
201             _tzsh.ErrorCodeThrow(res);
202         }
203
204         /// <summary>
205         /// Requests to hide the quickpanel service window.
206         /// </summary>
207         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
208         public void Hide()
209         {
210             int res;
211
212             res = Interop.QuickPanelService.Hide(_tzshQpService);
213             _tzsh.ErrorCodeThrow(res);
214         }
215
216         /// <summary>
217         /// Sets the content region of the quickpanel service handle.
218         /// </summary>
219         /// <param name="angle">The angle setting the region</param>
220         /// <param name="region">The region of the content</param>
221         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
222         /// <exception cref="ArgumentNullException">Thrown when a argument is null.</exception>
223         public void SetContentRegion(uint angle, TizenRegion region)
224         {
225             int res;
226
227             if (region == null)
228             {
229                 throw new ArgumentNullException(nameof(region));
230             }
231             res = Interop.QuickPanelService.SetContentRegion(_tzshQpService, angle, region.GetNativeHandle());
232             _tzsh.ErrorCodeThrow(res);
233         }
234
235         /// <summary>
236         /// Sets the handler region of the quickpanel service handle.
237         /// </summary>
238         /// <param name="angle">The angle setting the region</param>
239         /// <param name="region">The region of the content</param>
240         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
241         /// <exception cref="ArgumentNullException">Thrown when a argument is null.</exception>
242         public void SetHandlerRegion(uint angle, TizenRegion region)
243         {
244             int res;
245
246             if (region == null)
247             {
248                 throw new ArgumentNullException(nameof(region));
249             }
250             res = Interop.QuickPanelService.SetHandlerRegion(_tzshQpService, angle, region.GetNativeHandle());
251             _tzsh.ErrorCodeThrow(res);
252         }
253
254         /// <summary>
255         /// Requests to change the effect of animation.
256         /// </summary>
257         /// <param name="type">The type of effect, enumeration for effect type.</param>
258         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
259         public void SetEffectType(EffectType type)
260         {
261             int res;
262
263             res = Interop.QuickPanelService.SetEffectType(_tzshQpService, (int)type);
264             _tzsh.ErrorCodeThrow(res);
265         }
266
267         /// <summary>
268         /// Requests to lock/unlock scrolling the quickpanel service window.
269         /// </summary>
270         /// <param name="locked">The scroll lock state</param>
271         /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
272         public void LockScroll(bool locked)
273         {
274             int res;
275
276             res = Interop.QuickPanelService.LockScroll(_tzshQpService, locked);
277             _tzsh.ErrorCodeThrow(res);
278         }
279     }
280 }