2 * Copyright(c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.ComponentModel;
21 namespace Tizen.NUI.WindowSystem.Shell
24 /// Class for the Tizen softkey client.
26 /// This class is need to be hidden as inhouse API.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class SoftkeyClient : IDisposable
30 private TizenShell _tzsh;
31 private IntPtr _softkeyClient;
33 private bool disposed = false;
34 private bool isDisposeQueued = false;
37 /// Creates a new Softkey Client handle.
39 /// <param name="tzShell">The TizenShell instance.</param>
40 /// <param name="win">The window to provide service of the quickpanel.</param>
41 /// <privilege>http://tizen.org/privilege/windowsystem.admin</privilege>
42 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
43 /// <exception cref="ArgumentNullException">Thrown when a argument is null.</exception>
44 /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation or no service.</exception>
45 /// <exception cref="UnauthorizedAccessException">Thrown when the caller does not have privilege to use this method.</exception>
46 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
47 public SoftkeyClient(TizenShell tzShell, Window win)
51 throw new ArgumentNullException(nameof(tzShell));
53 if (tzShell.GetNativeHandle() == IntPtr.Zero)
55 throw new ArgumentException("tzShell is not initialized.");
59 throw new ArgumentNullException(nameof(win));
63 _tzshWin = win.GetNativeId();
64 _softkeyClient = Interop.SoftkeyClient.Create(_tzsh.GetNativeHandle(), (IntPtr)_tzshWin);
65 if (_softkeyClient == IntPtr.Zero)
67 int err = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
68 _tzsh.ErrorCodeThrow(err);
79 isDisposeQueued = true;
80 DisposeQueue.Instance.Add(this);
91 Dispose(DisposeTypes.Implicit);
95 Dispose(DisposeTypes.Explicit);
96 GC.SuppressFinalize(this);
101 protected virtual void Dispose(DisposeTypes type)
105 if (_softkeyClient != IntPtr.Zero)
107 int res = Interop.SoftkeyClient.Destroy(_softkeyClient);
108 _softkeyClient = IntPtr.Zero;
115 /// Gets the visible state of a softkey service window.
117 /// <returns>The visible state of the softkey service window.</returns>
118 /// <exception cref="ArgumentException" > Thrown when failed of invalid argument.</exception>
119 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
120 /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation or no service.</exception>
121 public SoftkeyVisibleState Visible
130 /// Gets the expand state of a softkey service window.
132 /// <returns>The expand state of the softkey service window.</returns>
133 /// <exception cref="ArgumentException" > Thrown when failed of invalid argument.</exception>
134 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
135 /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation or no service.</exception>
136 public SoftkeyExpandState Expand
149 /// Gets the opacity state of a softkey service window.
151 /// <returns>The opacity state of the softkey service window.</returns>
152 /// <exception cref="ArgumentException" > Thrown when failed of invalid argument.</exception>
153 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
154 /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation or no service.</exception>
155 public SoftkeyOpacityState Opacity
168 /// Requests to show the softkey service window.
170 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
171 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
172 /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation or no service.</exception>
175 int res = Interop.SoftkeyClient.Show(_softkeyClient);
176 _tzsh.ErrorCodeThrow(res);
180 /// Requests to hide the softkey service window.
182 /// <exception cref="ArgumentException" > Thrown when failed of invalid argument.</exception>
183 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
184 /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation or no service.</exception>
187 int res = Interop.SoftkeyClient.Hide(_softkeyClient);
188 _tzsh.ErrorCodeThrow(res);
191 private SoftkeyVisibleState GetVisible()
193 int res = Interop.SoftkeyClient.GetVisibleState(_softkeyClient, out int vis);
195 _tzsh.ErrorCodeThrow(res);
197 return ChangeVisibleStateToPublic((Interop.SoftkeyClient.VisibleState)vis);
200 private SoftkeyExpandState GetExpand()
202 int res = Interop.SoftkeyClient.GetExpandState(_softkeyClient, out int expand);
204 _tzsh.ErrorCodeThrow(res);
206 return ChangeExpandStateToPublic((Interop.SoftkeyClient.ExpandState)expand);
209 private void SetExpand(SoftkeyExpandState expand)
211 int res = Interop.SoftkeyClient.SetExpandState(_softkeyClient, (int)(ChangeExpandStateToInternal(expand)));
213 _tzsh.ErrorCodeThrow(res);
216 private SoftkeyOpacityState GetOpacity()
218 int res = Interop.SoftkeyClient.GetOpacityState(_softkeyClient, out int opacity);
220 _tzsh.ErrorCodeThrow(res);
222 return ChangeOpacityStateToPublic((Interop.SoftkeyClient.OpacityState)opacity);
225 private void SetOpacity(SoftkeyOpacityState opacity)
227 int res = Interop.SoftkeyClient.SetOpacityState(_softkeyClient, (int)(ChangeOpacityStateToInternal(opacity)));
229 _tzsh.ErrorCodeThrow(res);
232 private SoftkeyVisibleState ChangeVisibleStateToPublic(Interop.SoftkeyClient.VisibleState state)
234 if (state == Interop.SoftkeyClient.VisibleState.Shown)
235 return SoftkeyVisibleState.Shown;
236 else if (state == Interop.SoftkeyClient.VisibleState.Hidden)
237 return SoftkeyVisibleState.Hidden;
239 return SoftkeyVisibleState.Unknown;
242 private Interop.SoftkeyClient.VisibleState ChangeVisibleStateToInternal(SoftkeyVisibleState state)
244 if (state == SoftkeyVisibleState.Shown)
245 return Interop.SoftkeyClient.VisibleState.Shown;
246 else if (state == SoftkeyVisibleState.Hidden)
247 return Interop.SoftkeyClient.VisibleState.Hidden;
249 return Interop.SoftkeyClient.VisibleState.Unknown;
252 private SoftkeyExpandState ChangeExpandStateToPublic(Interop.SoftkeyClient.ExpandState state)
254 if (state == Interop.SoftkeyClient.ExpandState.On)
255 return SoftkeyExpandState.On;
256 else if (state == Interop.SoftkeyClient.ExpandState.Off)
257 return SoftkeyExpandState.Off;
259 return SoftkeyExpandState.Unknown;
262 private Interop.SoftkeyClient.ExpandState ChangeExpandStateToInternal(SoftkeyExpandState state)
264 if (state == SoftkeyExpandState.On)
265 return Interop.SoftkeyClient.ExpandState.On;
266 else if (state == SoftkeyExpandState.Off)
267 return Interop.SoftkeyClient.ExpandState.Off;
269 return Interop.SoftkeyClient.ExpandState.Unknown;
272 private SoftkeyOpacityState ChangeOpacityStateToPublic(Interop.SoftkeyClient.OpacityState state)
274 if (state == Interop.SoftkeyClient.OpacityState.Opaque)
275 return SoftkeyOpacityState.Opaque;
276 else if (state == Interop.SoftkeyClient.OpacityState.Transparent)
277 return SoftkeyOpacityState.Transparent;
279 return SoftkeyOpacityState.Unknown;
282 private Interop.SoftkeyClient.OpacityState ChangeOpacityStateToInternal(SoftkeyOpacityState state)
284 if (state == SoftkeyOpacityState.Opaque)
285 return Interop.SoftkeyClient.OpacityState.Opaque;
286 else if (state == SoftkeyOpacityState.Transparent)
287 return Interop.SoftkeyClient.OpacityState.Transparent;
289 return Interop.SoftkeyClient.OpacityState.Unknown;