Release 4.0.0-preview1-00258
[platform/core/csapi/tizenfx.git] / src / Tizen.Uix.InputMethodManager / Tizen.Uix.InputMethodManager / InputMethodManager.cs
1 /*
2 * Copyright (c) 2016 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
18 using static Interop.InputMethodManager;
19
20 namespace Tizen.Uix.InputMethodManager
21 {
22     /// <summary>
23     /// This class provides the function for launching the input method editor (IME) list and selector settings. A user can manage the installed IMEs in the system.
24     /// The input method editor (IME) is an input panel that lets users provide an input and the platform to receive the text data entered.
25     /// The manager is a module for managing the installed IMEs.
26     /// IME developers can use this module to open the installed IME list or the selector menu after their IME installation, and then guide to select the installed IME.
27     /// </summary>
28     public static class Manager
29     {
30         /// <summary>
31         /// Requests to open the installed IME list menu.
32         /// This API provides the installed IME list menu for IME developers who might want to open it to enable their IME.
33         /// </summary>
34         /// <privilege>
35         /// http://tizen.org/privilege/imemanager
36         /// </privilege>
37         /// <exception cref="T:System.InvalidOperationException">
38         /// This exception can occur if:
39         /// 1) The application does not have the privilege to call this function.
40         /// 2) Operation failed.
41         /// </exception>
42         public static void ShowIMEList()
43         {
44             ErrorCode error = ImeManagerShowImeList();
45             if (error != ErrorCode.None)
46             {
47                 Log.Error(LogTag, "ShowIMEList Failed with error " + error);
48                 throw InputMethodManagerExceptionFactory.CreateException(error);
49             }
50         }
51
52         /// <summary>
53         /// Requests to open the IME selector menu.
54         /// This API provides the IME selector menu for the IME or other application developers who might want to change the default IME.
55         /// </summary>
56         /// <privilege>
57         /// http://tizen.org/privilege/imemanager
58         /// </privilege>
59         /// <exception cref="T:System.InvalidOperationException">
60         /// This exception can occur if:
61         /// 1) The application does not have the privilege to call this function.
62         /// 2) Operation failed.
63         /// </exception>
64         public static void ShowIMESelector()
65         {
66             ErrorCode error = ImeManagerShowImeSelector();
67             if (error != ErrorCode.None)
68             {
69                 Log.Error(LogTag, "ShowIMESelector Failed with error " + error);
70                 throw InputMethodManagerExceptionFactory.CreateException(error);
71             }
72         }
73
74         /// <summary>
75         /// Checks if the specific IME is enabled or disabled in the system keyboard setting.
76         /// The IME developers can use this property to check if their IME is enabled or not.
77         /// </summary>
78         /// <privilege>
79         /// http://tizen.org/privilege/imemanager
80         /// </privilege>
81         /// <param name="appId">The application ID of the IME.</param>
82         /// <returns>The On (enabled) and Off (disabled) state of the IME.</returns>
83         /// <exception cref="T:System.ArgumentException">
84         /// This exception can occur if an invalid parameter is provided.
85         /// </exception>
86         /// <exception cref="T:System.InvalidOperationException">
87         /// This exception can occur if:
88         /// 1) The application does not have the privilege to call this function.
89         /// 2) Operation failed.
90         /// </exception>
91         public static bool IsIMEEnabled(string appId)
92         {
93             bool isIMEEnabled;
94             ErrorCode error = ImeManagerIsImeEnabled(appId, out isIMEEnabled);
95             if (error != ErrorCode.None)
96             {
97                 Log.Error(LogTag, "IsIMEEnabled Failed with error " + error);
98                 throw InputMethodManagerExceptionFactory.CreateException(error);
99             }
100
101             return isIMEEnabled;
102         }
103
104         /// <summary>
105         /// Checks which IME is the current activated (selected) IME.
106         /// </summary>
107         /// <privilege>
108         /// http://tizen.org/privilege/imemanager
109         /// </privilege>
110         /// <returns>
111         /// The current activated (selected) IME.
112         /// </returns>
113         /// <exception cref="T:System.InvalidOperationException">
114         /// This exception can occur if:
115         /// 1) The application does not have the privilege to call this function.
116         /// 2) Operation failed.
117         /// </exception>
118         public static string GetActiveIME()
119         {
120             string activeIME;
121             ErrorCode error = ImeManagerGetActiveIme(out activeIME);
122             if (error != ErrorCode.None)
123             {
124                 Log.Error(LogTag, "GetActiveIME Failed with error " + error);
125                 throw InputMethodManagerExceptionFactory.CreateException(error);
126             }
127
128             return activeIME;
129         }
130
131         /// <summary>
132         /// Gets the number of IMEs that are enabled (usable).
133         /// </summary>
134         /// <privilege>
135         /// http://tizen.org/privilege/imemanager
136         /// </privilege>
137         /// <returns>
138         /// The number of enabled IMEs.
139         /// </returns>
140         /// <exception cref="T:System.InvalidOperationException">
141         /// This exception can occur if:
142         /// 1) The application does not have the privilege to call this function.
143         /// 2) Operation failed.
144         /// </exception>
145         public static int GetEnabledIMECount()
146         {
147             int activeIME = ImeManagerGetEnabledImeCount();
148             ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
149             if (error != ErrorCode.None)
150             {
151                 Log.Error(LogTag, "GetEnabledIMECount Failed with error " + error);
152                 throw InputMethodManagerExceptionFactory.CreateException(error);
153             }
154
155             return activeIME;
156         }
157     }
158 }