Tizen 2.1 base
[platform/framework/native/ime.git] / src / FUiIme_InputServiceSignalListener.cpp
1 //\r
2 // Open Service Platform\r
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.\r
4 //\r
5 // Licensed under the Apache License, Version 2.0 (the License);\r
6 // you may not use this file except in compliance with the License.\r
7 // You may obtain a copy of the License at\r
8 //\r
9 //     http://www.apache.org/licenses/LICENSE-2.0\r
10 //\r
11 // Unless required by applicable law or agreed to in writing, software\r
12 // distributed under the License is distributed on an "AS IS" BASIS,\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 // See the License for the specific language governing permissions and\r
15 // limitations under the License.\r
16 //\r
17 \r
18 /**\r
19  * @file        FUiIme_InputServiceSignalListener.cpp\r
20  * @brief       This is the implementation file for the %_InputServiceSignalListener class.\r
21  *\r
22  * This implementation file contains definition of the %_InputServiceSignalListener class.\r
23  */\r
24 \r
25 #include <Ecore_IMF.h>\r
26 \r
27 #include <FAppApp.h>\r
28 #include <FBaseString.h>\r
29 #include <FBaseSysLog.h>\r
30 #include <FGrpRectangle.h>\r
31 #include <FUiInputConnectionTypes.h>\r
32 \r
33 #include "FUiIme_InputMethodImpl.h"\r
34 #include "FUiIme_InputServiceSignalListener.h"\r
35 #include "FUiIme_ScimDataConverter.h"\r
36 \r
37 using namespace Tizen::Base;\r
38 using namespace Tizen::Graphics;\r
39 using namespace Tizen::Ui;\r
40 \r
41 namespace Tizen { namespace Ui { namespace Ime {\r
42 \r
43 IInputMethodProvider* _InputServiceSignalListener::__pIInputMethodProvider = null;\r
44 IInputMethodListener* _InputServiceSignalListener::__pIInputMethodListener = null;\r
45 \r
46 _InputServiceSignalListener::_InputServiceSignalListener()\r
47 {\r
48 }\r
49 \r
50 _InputServiceSignalListener::~_InputServiceSignalListener()\r
51 {\r
52         __pIInputMethodProvider = null;\r
53         __pIInputMethodListener = null;\r
54 }\r
55 \r
56 void\r
57 _InputServiceSignalListener::SetInputMethodProvider(IInputMethodProvider* pProvider)\r
58 {\r
59         __pIInputMethodProvider = pProvider;\r
60 \r
61         return;\r
62 }\r
63 \r
64 void\r
65 _InputServiceSignalListener::SetInputMethodListener(IInputMethodListener* pListener)\r
66 {\r
67         __pIInputMethodListener = pListener;\r
68 \r
69         return;\r
70 }\r
71 \r
72 void\r
73 _InputServiceSignalListener::GetEnterKeyAction(const scim::HelperAgent* pHelperAgent, scim::uint32& action)\r
74 {\r
75         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
76 \r
77         InputPanelAction inputPanelAction = __pIInputMethodProvider->GetEnterKeyAction();\r
78         SysTryReturnVoidResult(NID_UI_IME, (inputPanelAction >= INPUT_PANEL_ACTION_ENTER) && (inputPanelAction <= INPUT_PANEL_ACTION_DONE), E_INVALID_DATA, "[E_INVALID_DATA] A requested data is invalid.");\r
79 \r
80         switch (inputPanelAction)\r
81         {\r
82         case INPUT_PANEL_ACTION_ENTER:\r
83                 action = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;\r
84                 break;\r
85         case INPUT_PANEL_ACTION_DONE:\r
86                 action = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;\r
87                 break;\r
88         case INPUT_PANEL_ACTION_GO:\r
89                 action = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO;\r
90                 break;\r
91         case INPUT_PANEL_ACTION_JOIN:\r
92                 action = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN;\r
93                 break;\r
94         case INPUT_PANEL_ACTION_LOGIN:\r
95                 action = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN;\r
96                 break;\r
97         case INPUT_PANEL_ACTION_NEXT:\r
98                 action = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT;\r
99                 break;\r
100         case INPUT_PANEL_ACTION_SEARCH:\r
101                 action = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH;\r
102                 break;\r
103         case INPUT_PANEL_ACTION_SEND:\r
104                 action = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND;\r
105                 break;\r
106         default:\r
107                 action = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;\r
108                 break;\r
109         }\r
110 \r
111         return;\r
112 }\r
113 \r
114 void\r
115 _InputServiceSignalListener::GetInputPanelBounds(const scim::HelperAgent* pHelperAgent, struct scim::rectinfo& bounds)\r
116 {\r
117         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
118 \r
119         SysLog(NID_UI_IME, "The bounds of the input panel have been requested.");\r
120 \r
121         Rectangle inputPanelBounds = __pIInputMethodProvider->GetInputPanelBounds();\r
122 \r
123         _ScimDataConverter converter;\r
124         converter.ConvertRectangle(inputPanelBounds, bounds);\r
125 \r
126         return;\r
127 }\r
128 \r
129 void\r
130 _InputServiceSignalListener::GetInputPanelStyle(const scim::HelperAgent* pHelperAgent, scim::uint32& style)\r
131 {\r
132         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
133 \r
134         InputPanelStyle inputPanelStyle = __pIInputMethodProvider->GetInputPanelStyle();\r
135         SysTryReturnVoidResult(NID_UI_IME, (inputPanelStyle >= INPUT_PANEL_STYLE_NORMAL) && (inputPanelStyle <= INPUT_PANEL_STYLE_IP), E_INVALID_DATA, "[E_INVALID_DATA] A requested data is invalid.");\r
136 \r
137         switch (inputPanelStyle)\r
138         {\r
139         case INPUT_PANEL_STYLE_NORMAL:\r
140                 style = ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL;\r
141                 break;\r
142         case INPUT_PANEL_STYLE_EMAIL:\r
143                 style = ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL;\r
144                 break;\r
145         case INPUT_PANEL_STYLE_IP:\r
146                 style = ECORE_IMF_INPUT_PANEL_LAYOUT_IP;\r
147                 break;\r
148         case INPUT_PANEL_STYLE_NUMBER:\r
149                 style = ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBERONLY;\r
150                 break;\r
151         case INPUT_PANEL_STYLE_PHONE_NUMBER:\r
152                 style = ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER;\r
153                 break;\r
154         case INPUT_PANEL_STYLE_URL:\r
155                 style = ECORE_IMF_INPUT_PANEL_LAYOUT_URL;\r
156                 break;\r
157         default:\r
158                 style = ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL;\r
159                 break;\r
160         }       \r
161 \r
162         return;\r
163 }\r
164 \r
165 void\r
166 _InputServiceSignalListener::SetCapsModeEnabled(const scim::HelperAgent* pHelperAgent, scim::uint32& mode)\r
167 {\r
168         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
169 \r
170         bool enable = (mode != 0 ? true : false);\r
171 \r
172         __pIInputMethodProvider->SetCapsModeEnabled(enable);\r
173 \r
174         return;\r
175 }\r
176 \r
177 void\r
178 _InputServiceSignalListener::SetEnterKeyAction(const scim::HelperAgent* pHelperAgent, scim::uint32& action)\r
179 {\r
180         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
181         SysTryReturnVoidResult(NID_UI_IME, action <= ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND, E_INVALID_ARG,\r
182                                                 "[E_INVALID_ARG] Invalid argument(s) is used. The enter key action is beyond the scope.");\r
183 \r
184         InputPanelAction inputPanelAction;\r
185 \r
186         switch (action)\r
187         {\r
188         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT:\r
189                 inputPanelAction = INPUT_PANEL_ACTION_ENTER;\r
190                 break;\r
191         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE:\r
192                 inputPanelAction = INPUT_PANEL_ACTION_DONE;\r
193                 break;\r
194         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO:\r
195                 inputPanelAction = INPUT_PANEL_ACTION_GO;\r
196                 break;\r
197         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN:\r
198                 inputPanelAction = INPUT_PANEL_ACTION_JOIN;\r
199                 break;\r
200         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN:\r
201                 inputPanelAction = INPUT_PANEL_ACTION_LOGIN;\r
202                 break;\r
203         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT:\r
204                 inputPanelAction = INPUT_PANEL_ACTION_NEXT;\r
205                 break;\r
206         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH:\r
207                 inputPanelAction = INPUT_PANEL_ACTION_SEARCH;\r
208                 break;\r
209         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND:\r
210                 inputPanelAction = INPUT_PANEL_ACTION_SEND;\r
211                 break;\r
212         default:\r
213                 inputPanelAction = INPUT_PANEL_ACTION_ENTER;\r
214                 break;\r
215         }\r
216 \r
217         __pIInputMethodProvider->SetEnterKeyAction(inputPanelAction);\r
218 \r
219         return;\r
220 }\r
221 \r
222 void\r
223 _InputServiceSignalListener::SetEnterKeyActionEnabled(const scim::HelperAgent* pHelperAgent, scim::uint32& disable)\r
224 {\r
225         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
226 \r
227         bool enable = (disable != 0 ? false : true);\r
228 \r
229         __pIInputMethodProvider->SetEnterKeyActionEnabled(enable);\r
230 \r
231         return;\r
232 }\r
233 \r
234 void\r
235 _InputServiceSignalListener::SetInputPanelStyle(const scim::HelperAgent* pHelperAgent, scim::uint32& style)\r
236 {\r
237         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
238         SysTryReturnVoidResult(NID_UI_IME, style < ECORE_IMF_INPUT_PANEL_LAYOUT_INVALID, E_INVALID_ARG,\r
239                                                 "[E_INVALID_ARG] Invalid argument(s) is used. The input panel style is beyond the scope.");\r
240 \r
241         InputPanelStyle inputPanelStyle;\r
242 \r
243         switch (style)\r
244         {\r
245         case ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL:\r
246                 inputPanelStyle = INPUT_PANEL_STYLE_NORMAL;\r
247                 break;\r
248         case ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL:\r
249                 inputPanelStyle = INPUT_PANEL_STYLE_EMAIL;\r
250                 break;\r
251         case ECORE_IMF_INPUT_PANEL_LAYOUT_IP:\r
252                 inputPanelStyle = INPUT_PANEL_STYLE_IP;\r
253                 break;\r
254         case ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBERONLY:\r
255                 inputPanelStyle = INPUT_PANEL_STYLE_NUMBER;\r
256                 break;\r
257         case ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER:\r
258                 inputPanelStyle = INPUT_PANEL_STYLE_PHONE_NUMBER;\r
259                 break;\r
260         case ECORE_IMF_INPUT_PANEL_LAYOUT_URL:\r
261                 inputPanelStyle = INPUT_PANEL_STYLE_URL;\r
262                 break;\r
263         default:\r
264                 inputPanelStyle = INPUT_PANEL_STYLE_NORMAL;\r
265                 break;\r
266         }       \r
267 \r
268         __pIInputMethodProvider->SetInputPanelStyle(inputPanelStyle);\r
269 \r
270         return;\r
271 }\r
272 \r
273 void\r
274 _InputServiceSignalListener::SetLanguage(const scim::HelperAgent* pHelperAgent, scim::uint32& language)\r
275 {\r
276         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
277 \r
278         Tizen::Locales::LanguageCode languageCode = (language == ECORE_IMF_INPUT_PANEL_LANG_ALPHABET ? Tizen::Locales::LANGUAGE_ENG : Tizen::Locales::LANGUAGE_INVALID);\r
279 \r
280         if (languageCode == Tizen::Locales::LANGUAGE_INVALID)\r
281         {\r
282                 return;\r
283         }\r
284 \r
285         //__pIInputMethodProvider->SetLanguage(languageCode);\r
286 \r
287         return;\r
288 }\r
289 \r
290 void\r
291 _InputServiceSignalListener::HideInputPanel(const scim::HelperAgent* pHelperAgent, int inputContext, const scim::String& uuid)\r
292 {\r
293         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
294 \r
295         SysLog(NID_UI_IME, "Hiding the input panel has been requested.");\r
296 \r
297         __pIInputMethodProvider->HideInputPanel();\r
298 \r
299         return;\r
300 }\r
301 \r
302 void\r
303 _InputServiceSignalListener::IsEnterKeyActionEnabled(const scim::HelperAgent* pHelperAgent, scim::uint32& enable)\r
304 {\r
305         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
306 \r
307         enable = static_cast<scim::uint32>(__pIInputMethodProvider->IsEnterKeyActionEnabled());\r
308 \r
309         return;\r
310 }\r
311 \r
312 void\r
313 _InputServiceSignalListener::ShowInputPanel(const scim::HelperAgent* pHelperAgent, int inputContext, char* pBuffer, size_t& length)\r
314 {\r
315         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodProvider, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
316 \r
317         SysLog(NID_UI_IME, "Showing the input panel has been requested.");\r
318 \r
319         __pIInputMethodProvider->ShowInputPanel();\r
320 \r
321         return;\r
322 }\r
323 \r
324 void\r
325 _InputServiceSignalListener::OnCursorPositionChanged(const scim::HelperAgent* pHelperAgent, int inputContext, const scim::String& uuid, int position)\r
326 {\r
327         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodListener, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
328 \r
329         __pIInputMethodListener->OnCursorPositionChanged(position);\r
330 \r
331         return;\r
332 }\r
333 \r
334 void\r
335 _InputServiceSignalListener::OnSurroundingTextReceived(const scim::HelperAgent* pHelperAgent, int inputContext, const scim::String& text, int cursorPosition)\r
336 {\r
337         SysTryReturnVoidResult(NID_UI_IME, __pIInputMethodListener, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The required instance does not exist.");\r
338 \r
339         String ospText;\r
340 \r
341         _ScimDataConverter converter;\r
342         converter.ConvertString(text, ospText);\r
343 \r
344         __pIInputMethodListener->OnSurroundingTextReceived(ospText, cursorPosition);\r
345 \r
346         return;\r
347 }\r
348 \r
349 void\r
350 _InputServiceSignalListener::OnTerminate (const scim::HelperAgent* pHelperAgent, int inputContext, const scim::String& uuid)\r
351 {\r
352         Tizen::App::App::GetInstance()->Terminate();\r
353 \r
354         return;\r
355 }\r
356 \r
357 }}} // Tizen::Ui::Ime\r