fixed bug(P130730-6872)fixed bug(P130730-6872)
[platform/framework/native/uifw.git] / src / ui / FUi_InputConnectionImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUi_InputConnectionImpl.cpp
20  * @brief               This is the implementation file for the _InputConnectionImpl class.
21  */
22
23 #include <Elementary.h>
24 #include <FBaseDataType.h>
25 #include <FBaseSysLog.h>
26 #include <FUiInputConnection.h>
27 #include <new>
28 #include "FUi_BidiUtils.h"
29 #include "FUi_Control.h"
30 #include "FUi_ControlImpl.h"
31 #include "FUi_ControlManager.h"
32 #include "FUi_CoordinateSystemUtils.h"
33 #include "FUi_EcoreEvas.h"
34 #include "FUi_EcoreEvasMgr.h"
35 #include "FUi_InputConnectionImpl.h"
36 #include "FUi_InputConnectionUtils.h"
37 #include "FUi_UiEventManager.h"
38 #include "FUiAnim_EflNode.h"
39 #include "FUiAnim_VisualElement.h"
40 #include "FUi_Window.h"
41 #include "FUiAnim_EflLayer.h"
42 #include "FUiAnim_RootVisualElement.h"
43
44 using namespace Tizen::Base;
45 using namespace Tizen::Graphics;
46 using namespace Tizen::Locales;
47 using namespace Tizen::Ui;
48 using namespace Tizen::Ui::Animations;
49
50 namespace {
51
52 const int LANGUAGE_CODE_START = 0;
53 const int LANGUAGE_CODE_MAX = 2;
54 const int LANGUAGE_IM_DATA_LENGTH = 10;
55
56 void
57 OnInputPanelShowStateEvent(void* pData, Ecore_IMF_Context* pContext, int value)
58 {
59         SysTryReturnVoidResult(NID_UI, pData != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelShowStateEvent pData is null ");
60         SysTryReturnVoidResult(NID_UI, pContext != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelShowStateEvent pContext is null ");
61
62         SysLog(NID_UI_CTRL, "[InputConnection] OnInputPanelShowStateEvent is called.[ctx=0x%x, showState=%d]\n", pContext, value);
63
64         _InputConnectionImpl* pImpl = static_cast<_InputConnectionImpl*>(pData);
65         IInputConnectionEventListener* pListener = pImpl->GetInputConnectionListener();
66         IInputConnectionEventListenerF* pListenerF = pImpl->GetInputConnectionListenerF();
67         InputConnection* pInputConnection = pImpl->GetInputConnection();
68
69         result r = E_SUCCESS;
70
71         Ecore_IMF_Input_Panel_State ecoreInputPanelShowState = static_cast<Ecore_IMF_Input_Panel_State>(value);
72         InputPanelShowState inputPanelState = INPUT_PANEL_SHOW_STATE_HIDE;
73
74         switch (ecoreInputPanelShowState)
75         {
76         case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
77                 inputPanelState = INPUT_PANEL_SHOW_STATE_SHOW;
78                 break;
79         case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
80                 inputPanelState = INPUT_PANEL_SHOW_STATE_HIDE;
81                 break;
82         case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
83                 return;
84         default:
85                 break;
86         }
87
88         r = pImpl->SetInputPanelShowState(inputPanelState);
89         SysTryReturnVoidResult(NID_UI,  r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
90
91         if (pListener)
92         {
93                 pListener->OnInputConnectionPanelShowStateChanged(*pInputConnection, inputPanelState);
94         }
95         if (pListenerF)
96         {
97                 pListenerF->OnInputConnectionPanelShowStateChanged(*pInputConnection, inputPanelState);
98         }
99         SetLastResult(E_SUCCESS);
100
101         return;
102 }
103
104 void
105 OnInputPanelLanguageEvent(void* pData, Ecore_IMF_Context* pContext, int value)
106 {
107         SysTryReturnVoidResult(NID_UI, pData != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelLanguageEvent pData is null ");
108         SysTryReturnVoidResult(NID_UI, pContext != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelLanguageEvent pContext is null ");
109
110         _InputConnectionImpl* pImpl = static_cast<_InputConnectionImpl*>(pData);
111         IInputConnectionEventListener* pListener = pImpl->GetInputConnectionListener();
112         IInputConnectionEventListenerF* pListenerF = pImpl->GetInputConnectionListenerF();
113         InputConnection* pInputConnection = pImpl->GetInputConnection();
114
115         char* pLocale = null;
116         ecore_imf_context_input_panel_language_locale_get(pContext, &pLocale);
117         String tempBuffer(pLocale);
118         String language;
119         tempBuffer.SubString(LANGUAGE_CODE_START, LANGUAGE_CODE_MAX, language);
120         LanguageCode newLanguageCode = Locale::TwoLetterLanguageCodeStringToLanguageCode(language);
121
122         if (pListener)
123         {
124                 pListener->OnInputConnectionPanelLanguageChanged(*pInputConnection, newLanguageCode);
125         }
126         if (pListenerF)
127         {
128                 pListenerF->OnInputConnectionPanelLanguageChanged(*pInputConnection, newLanguageCode);
129         }
130         if (pLocale)
131         {
132                 free(pLocale);
133         }
134
135         SetLastResult(E_SUCCESS);
136
137         return;
138 }
139
140 void
141 OnInputPanelSizeChangedEvent(void* pData, Ecore_IMF_Context* pContext, int value)
142 {
143         SysTryReturnVoidResult(NID_UI, pData != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelSizeChangedEvent pData is null ");
144         SysTryReturnVoidResult(NID_UI, pContext != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelSizeChangedEvent pContext is null ");
145
146         _InputConnectionImpl* pImpl = static_cast<_InputConnectionImpl*>(pData);
147         IInputConnectionEventListener* pListener = pImpl->GetInputConnectionListener();
148         IInputConnectionEventListenerF* pListenerF = pImpl->GetInputConnectionListenerF();
149         InputConnection* pInputConnection = pImpl->GetInputConnection();
150
151         Rectangle bounds = pImpl->GetInputPanelBounds();
152
153         SysLog(NID_UI_CTRL, "[InputConnection] OnInputPanelSizeChangedEvent is called.[ctx=0x%x][x = %d, y = %d, width = %d, height = %d]\n", pContext, bounds.x, bounds.y, bounds.width, bounds.height);
154
155         if (pListener)
156         {
157                 pListener->OnInputConnectionPanelBoundsChanged(*pInputConnection, bounds);
158         }
159         if (pListenerF)
160         {
161                 pListenerF->OnInputConnectionPanelBoundsChanged(*pInputConnection, _CoordinateSystemUtils::ConvertToFloat(bounds));
162         }
163
164         SetLastResult(E_SUCCESS);
165
166         return;
167 }
168
169 void
170 OnInputPanelPredictionModeEvent(void* pData, Ecore_IMF_Context* pContext, int value)
171 {
172         SysTryReturnVoidResult(NID_UI, pData != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelPredictionModeEvent pData is null ");
173         SysTryReturnVoidResult(NID_UI, pContext != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelPredictionModeEvent pContext is null ");
174
175         _InputConnectionImpl* pImpl = static_cast<_InputConnectionImpl*>(pData);
176         IInputConnectionEventListener* pListener = pImpl->GetInputConnectionListener();
177         IInputConnectionEventListenerF* pListenerF = pImpl->GetInputConnectionListenerF();
178         InputConnection* pInputConnection = pImpl->GetInputConnection();
179
180         if (pListener)
181         {
182                 pListener->OnInputConnectionTextPredictionShowStateChanged(*pInputConnection, static_cast<bool>(value));
183         }
184         if (pListenerF)
185         {
186                 pListenerF->OnInputConnectionTextPredictionShowStateChanged(*pInputConnection, static_cast<bool>(value));
187         }
188         SetLastResult(E_SUCCESS);
189
190         return;
191 }
192
193 void
194 OnInputPanelPredictionSizeChangedEvent(void* pData, Ecore_IMF_Context* pContext, int value)
195 {
196         SysTryReturnVoidResult(NID_UI, pData != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelPredictionSizeChangedEvent pData is null ");
197         SysTryReturnVoidResult(NID_UI, pContext != null, E_INVALID_ARG, "[E_INVALID_ARG] OnInputPanelPredictionSizeChangedEvent pContext is null ");
198
199         _InputConnectionImpl* pImpl = static_cast<_InputConnectionImpl*>(pData);
200         IInputConnectionEventListener* pListener = pImpl->GetInputConnectionListener();
201         IInputConnectionEventListenerF* pListenerF = pImpl->GetInputConnectionListenerF();
202         InputConnection* pInputConnection = pImpl->GetInputConnection();
203
204         Rectangle bounds = pImpl->GetPredictionBounds();
205
206         if (pListener)
207         {
208                 pListener->OnInputConnectionTextPredictionBoundsChanged(*pInputConnection, bounds);
209         }
210         if (pListenerF)
211         {
212                 pListenerF->OnInputConnectionTextPredictionBoundsChanged(*pInputConnection, _CoordinateSystemUtils::ConvertToFloat(bounds));
213         }
214         SetLastResult(E_SUCCESS);
215
216         return;
217 }
218
219 Eina_Bool
220 OnRetrieveSurrounding(void* pData, Ecore_IMF_Context* pContext, char** pText, int* pCursorPostion)
221 {
222         SysTryReturn(NID_UI, pData != null, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] OnRetrieveSurrounding pData == null.");
223         SysTryReturn(NID_UI, pContext != null, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] OnRetrieveSurrounding pContext is null ");
224
225         _InputConnectionImpl* pImpl = static_cast<_InputConnectionImpl*>(pData);
226         IInputConnectionProvider* pProvider = pImpl->GetInputConnectionProvider();
227
228         InputConnection* pInputConnection = pImpl->GetInputConnection();
229
230         char* pSurroundingText = null;
231         String string;
232
233         pProvider->GetPreviousText(*pInputConnection, string, *pCursorPostion);
234
235         int len = wcstombs(0, static_cast<const wchar_t*>(string.GetPointer()), 0);
236         //SysTryReturn(NID_BASE, len != -1, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid string.");
237
238         if (pText == null)
239         {
240                 return ECORE_CALLBACK_PASS_ON;
241         }
242
243         if (len < 0)
244         {
245                 *pText = null;
246                 return ECORE_CALLBACK_DONE;
247         }
248         //This memory will be released by ECORE IMF
249         pSurroundingText = (char*)malloc(len+1);
250         SysTryReturn(NID_UI, pSurroundingText, EINA_FALSE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] OnRetrieveSurrounding pSurroundingText == null.");
251
252         len = wcstombs(pSurroundingText, static_cast<const wchar_t*>(string.GetPointer()), len);
253         pSurroundingText[len] = null;
254         *pText = pSurroundingText;
255
256         SetLastResult(E_SUCCESS);
257
258         return ECORE_CALLBACK_PASS_ON;
259 }
260
261 void
262 OnCommitTextEcoreEvent(void* pData, Ecore_IMF_Context* pContext, void* pEventInfo)
263 {
264         SysTryReturnVoidResult(NID_UI, pData != null, E_INVALID_ARG, "[E_INVALID_ARG] OnCommitTextEcoreEvent pData is null ");
265         SysTryReturnVoidResult(NID_UI, pEventInfo != null, E_INVALID_ARG, "[E_INVALID_ARG] OnCommitTextEcoreEvent pEventInfo is null ");
266
267         _InputConnectionImpl* pImpl = static_cast<_InputConnectionImpl*>(pData);
268         IInputConnectionEventListener* pListener = pImpl->GetInputConnectionListener();
269         IInputConnectionEventListenerF* pListenerF = pImpl->GetInputConnectionListenerF();
270
271         String commitText(static_cast<char*>(pEventInfo));
272         InputConnection* pInputConnection = pImpl->GetInputConnection();
273
274         if (pListener)
275         {
276                 pListener->OnInputConnectionTextCommitted(*pInputConnection, commitText);
277         }
278         if (pListenerF)
279         {
280                 pListenerF->OnInputConnectionTextCommitted(*pInputConnection, commitText);
281         }
282
283         SetLastResult(E_SUCCESS);
284
285         return;
286 }
287
288 void
289 OnComposeTextEcoreEvent(void* pData, Ecore_IMF_Context* pContext, void* pEventInfo)
290 {
291         SysTryReturnVoidResult(NID_UI, pData != null, E_INVALID_ARG, "[E_INVALID_ARG] OnComposeTextEcoreEvent pData is null ");
292         //SysTryReturnVoidResult(NID_UI, pEventInfo != null, E_INVALID_ARG, "[E_INVALID_ARG] OnComposeTextEcoreEvent pEventInfo is null ");
293
294         _InputConnectionImpl* pImpl = static_cast<_InputConnectionImpl*>(pData);
295         IInputConnectionEventListener* pListener = pImpl->GetInputConnectionListener();
296         IInputConnectionEventListenerF* pListenerF = pImpl->GetInputConnectionListenerF();
297
298         int cursorPosition = 0;
299         char* pText = null;
300         ecore_imf_context_preedit_string_get(pContext, &pText, &cursorPosition);
301         String composingText(pText);
302         if (pText)
303         {
304                 free(pText);
305         }
306
307         InputConnection* pInputConnection = pImpl->GetInputConnection();
308
309         if (pListener)
310         {
311                 pListener->OnInputConnectionComposingTextChanged(*pInputConnection, composingText, cursorPosition);
312         }
313         if (pListenerF)
314         {
315                 pListenerF->OnInputConnectionComposingTextChanged(*pInputConnection, composingText, cursorPosition);
316         }
317
318         SetLastResult(E_SUCCESS);
319
320         return;
321 }
322
323 void
324 OnDeleteSurroundingTextEcoreEvent(void* pData, Ecore_IMF_Context* pContext, void* pEventInfo)
325 {
326         SysTryReturnVoidResult(NID_UI, pData != null, E_INVALID_ARG, "[E_INVALID_ARG] OnDeleteSurroundingTextEcoreEvent pData is null ");
327         SysTryReturnVoidResult(NID_UI, pEventInfo != null, E_INVALID_ARG, "[E_INVALID_ARG] OnDeleteSurroundingTextEcoreEvent pEventInfo is null ");
328
329         _InputConnectionImpl* pImpl = static_cast<_InputConnectionImpl*>(pData);
330         IInputConnectionProvider* pProvider = pImpl->GetInputConnectionProvider();
331         Ecore_IMF_Event_Delete_Surrounding* pEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>(pEventInfo);
332
333         InputConnection* pInputConnection = pImpl->GetInputConnection();
334         pProvider->DeleteSurroundingText(*pInputConnection, pEvent->offset, pEvent->n_chars);
335
336         SetLastResult(E_SUCCESS);
337
338         return;
339 }
340
341 /*
342 Eina_Bool
343 OnUSBKeyboardEcoreEvent(void* pData, int eventType, void* pEventInfo)
344 {
345         return ECORE_CALLBACK_PASS_ON;
346 }
347 */
348
349 } // Anonymous
350
351 namespace Tizen { namespace Ui {
352
353 _InputConnectionImpl::_InputConnectionImpl(InputConnection* pInputConnection)
354         : __pContext(null)
355         , __controlHandle()
356         , __IsBounded(false)
357         , __pListener(null)
358         , __pListenerF(null)
359         , __pProvider(null)
360         , __pInputConnection(pInputConnection)
361         , __inputPanelAction(INPUT_PANEL_ACTION_ENTER)
362         , __inputPanelState(INPUT_PANEL_SHOW_STATE_HIDE)
363         , __inputPanelStyle(INPUT_PANEL_STYLE_NORMAL)
364         , __pUSBEventHandler(null)
365         , __IsKeyEventSkipped(false)
366         , __passwordMode(false)
367 {
368
369 }
370
371 _InputConnectionImpl::~_InputConnectionImpl(void)
372 {
373         __pInputConnection = null;
374         __pListener = null;
375         __pListenerF = null;
376         __pProvider = null;
377         if (__pContext)
378         {
379                 RemoveInputPanelCallback();
380                 RemoveEcoreEventCallback();
381                 RemoveEvasObjectEventCallback();
382                 ecore_imf_context_focus_out(__pContext);
383                 ecore_imf_context_del(__pContext);
384                 ecore_imf_shutdown();
385                 __pContext = null;
386         }
387 }
388
389 _InputConnectionImpl*
390 _InputConnectionImpl::CreateInputConnectionImplN(InputConnection* pInputConnection)
391 {
392         ClearLastResult();
393
394         _InputConnectionImpl* pImpl = new (std::nothrow) _InputConnectionImpl(pInputConnection);
395         SysTryReturn(NID_UI, pImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
396
397         return pImpl;
398
399 }
400
401 result
402 _InputConnectionImpl::Initialize(const _Control& control, const IInputConnectionEventListener& listener, const IInputConnectionProvider& provider)
403 {
404         result r = E_SUCCESS;
405
406         __controlHandle = control.GetHandle();
407
408         __pListener = const_cast<IInputConnectionEventListener*>(&listener);
409         __pListenerF = null;
410         __pProvider = const_cast<IInputConnectionProvider*>(&provider);
411
412         ecore_imf_init();
413         const char* pId = ecore_imf_context_default_id_get();
414         SysTryReturnResult(NID_UI, pId != null, E_SYSTEM, "A system error occurred.");
415
416
417         __pContext = (Ecore_IMF_Context*)ecore_imf_context_add(pId);
418         SysTryReturnResult(NID_UI, __pContext, E_SYSTEM, "A system error occurred.");
419
420         AddInputPanelCallback();
421         AddEcoreEventCallback();
422         AddEvasObjectEventCallback();
423
424         return r;
425
426 }
427
428 result
429 _InputConnectionImpl::Initialize(const _Control& control, const IInputConnectionEventListenerF& listener, const IInputConnectionProvider& provider)
430 {
431         result r = E_SUCCESS;
432
433         __controlHandle = control.GetHandle();
434
435         __pListener = null;
436         __pListenerF = const_cast<IInputConnectionEventListenerF*>(&listener);
437         __pProvider = const_cast<IInputConnectionProvider*>(&provider);
438
439         ecore_imf_init();
440         const char* pId = ecore_imf_context_default_id_get();
441         SysTryReturnResult(NID_UI, pId != null, E_SYSTEM, "A system error occurred.");
442
443
444         __pContext = (Ecore_IMF_Context*)ecore_imf_context_add(pId);
445         SysTryReturnResult(NID_UI, __pContext, E_SYSTEM, "A system error occurred.");
446
447         AddInputPanelCallback();
448         AddEcoreEventCallback();
449         AddEvasObjectEventCallback();
450
451         return r;
452
453 }
454
455 result
456 _InputConnectionImpl::BindInputMethod(void)
457 {
458         result r = E_SUCCESS;
459
460         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
461
462         _Control* pControl = _ControlManager::GetInstance()->GetObject(__controlHandle);
463
464         _Window* pWindow = pControl->GetRootWindow();
465         if (pWindow)
466         {
467                 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
468                 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
469
470                 if (pLayer)
471                 {
472                         ecore_imf_context_client_window_set(__pContext, (void*)ecore_evas_window_get(pLayer->GetEcoreEvas()));
473                         ecore_imf_context_client_canvas_set(__pContext, pLayer->GetEvas());
474                         ecore_imf_context_input_panel_enabled_set(__pContext, EINA_FALSE);
475                 }
476         }
477
478         ecore_imf_context_focus_in(__pContext);
479         __IsBounded = true;
480
481         SysLog(NID_UI_CTRL, "[InputConnection] BindInputMethod is called.[ctx=0x%x]\n", __pContext);
482
483         return r;
484 }
485
486 result
487 _InputConnectionImpl::UnbindInputMethod(void)
488 {
489         result r = E_SUCCESS;
490
491         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
492
493         ecore_imf_context_focus_out(__pContext);
494
495         SysLog(NID_UI_CTRL, "[InputConnection] UnbindInputMethod is called.[ctx=0x%x]\n", __pContext);
496
497         __IsBounded = false;
498
499         return r;
500 }
501
502 result
503 _InputConnectionImpl::ShowInputPanel(void)
504 {
505         result r = E_SUCCESS;
506
507         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
508         SysTryReturnResult(NID_UI, __IsBounded, E_INVALID_STATE, "This is not a bind state");
509
510         ecore_imf_context_input_panel_show(__pContext);
511         __inputPanelState = INPUT_PANEL_SHOW_STATE_SHOW;
512
513         SysLog(NID_UI_CTRL, "[InputConnection] ShowInputPanel is called.[ctx=0x%x]\n", __pContext);
514
515         return r;
516 }
517
518 result
519 _InputConnectionImpl::HideInputPanel(void)
520 {
521         result r = E_SUCCESS;
522
523         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
524         SysTryReturnResult(NID_UI, __IsBounded, E_INVALID_STATE, "This is not a bind state");
525
526         ecore_imf_context_input_panel_hide(__pContext);
527         __inputPanelState = INPUT_PANEL_SHOW_STATE_HIDE;
528
529         SysLog(NID_UI_CTRL, "[InputConnection] HideInputPanel is called.[ctx=0x%x]\n", __pContext);
530
531         return r;
532 }
533
534 result
535 _InputConnectionImpl::SetInputPanelStyle(InputPanelStyle style)
536 {
537         result r = E_SUCCESS;
538
539         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
540
541         __inputPanelStyle = style;
542
543         Ecore_IMF_Input_Panel_Layout ecorePanelLayout = ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL;
544
545         switch (style)
546         {
547         case INPUT_PANEL_STYLE_NORMAL:
548                 ecorePanelLayout = ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL;
549                 if (__passwordMode == true)
550                 {
551                         ecorePanelLayout = ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD;
552                 }
553                 break;
554         case INPUT_PANEL_STYLE_NUMBER:
555                 ecorePanelLayout = ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBER;
556                 break;
557         case INPUT_PANEL_STYLE_EMAIL:
558                 ecorePanelLayout = ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL;
559                 break;
560         case INPUT_PANEL_STYLE_URL:
561                 ecorePanelLayout = ECORE_IMF_INPUT_PANEL_LAYOUT_URL;
562                 break;
563         case INPUT_PANEL_STYLE_PHONE_NUMBER:
564                 ecorePanelLayout = ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER;
565                 break;
566         case INPUT_PANEL_STYLE_IP:
567                 ecorePanelLayout = ECORE_IMF_INPUT_PANEL_LAYOUT_IP;
568                 break;
569         case INPUT_PANEL_STYLE_NUMBER_ONLY:
570                 ecorePanelLayout = ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBERONLY;
571                 break;
572         default:
573                 break;
574         }
575
576         ecore_imf_context_input_panel_layout_set(__pContext, ecorePanelLayout);
577         return r;
578 }
579
580 InputPanelStyle
581 _InputConnectionImpl::GetInputPanelStyle(void) const
582 {
583         ClearLastResult();
584
585         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
586
587         Ecore_IMF_Input_Panel_Layout ecorePanelLayout = ecore_imf_context_input_panel_layout_get(__pContext);
588         InputPanelStyle inputPanelStyle = INPUT_PANEL_STYLE_NORMAL;
589
590         switch (ecorePanelLayout)
591         {
592         case ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL:
593                 inputPanelStyle = INPUT_PANEL_STYLE_NORMAL;
594                 break;
595         case ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBER:
596                 inputPanelStyle = INPUT_PANEL_STYLE_NUMBER;
597                 break;
598         case ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL:
599                 inputPanelStyle = INPUT_PANEL_STYLE_EMAIL;
600                 break;
601         case ECORE_IMF_INPUT_PANEL_LAYOUT_URL:
602                 inputPanelStyle = INPUT_PANEL_STYLE_URL;
603                 break;
604         case ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER:
605                 inputPanelStyle = INPUT_PANEL_STYLE_PHONE_NUMBER;
606                 break;
607         case ECORE_IMF_INPUT_PANEL_LAYOUT_IP:
608                 inputPanelStyle = INPUT_PANEL_STYLE_IP;
609                 break;
610         case ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBERONLY:
611                 inputPanelStyle = INPUT_PANEL_STYLE_NUMBER_ONLY;
612                 break;
613         default:
614                 break;
615         }
616
617         return inputPanelStyle;
618 }
619
620 result
621 _InputConnectionImpl::SetAutoCapitalizationMode(AutoCapitalizationMode autoCapitalizationMode)
622 {
623         result r = E_SUCCESS;
624
625         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
626
627          Ecore_IMF_Autocapital_Type ecoreAutoCapitalization = ECORE_IMF_AUTOCAPITAL_TYPE_SENTENCE;
628
629         switch (autoCapitalizationMode)
630         {
631         case AUTO_CAPITALIZATION_MODE_NONE:
632                 ecoreAutoCapitalization = ECORE_IMF_AUTOCAPITAL_TYPE_NONE;
633                 break;
634         case AUTO_CAPITALIZATION_MODE_WORD:
635                 ecoreAutoCapitalization = ECORE_IMF_AUTOCAPITAL_TYPE_WORD;
636                 break;
637         case AUTO_CAPITALIZATION_MODE_SENTENCE:
638                 ecoreAutoCapitalization = ECORE_IMF_AUTOCAPITAL_TYPE_SENTENCE;
639                 break;
640         case AUTO_CAPITALIZATION_MODE_ALL:
641                 ecoreAutoCapitalization =ECORE_IMF_AUTOCAPITAL_TYPE_ALLCHARACTER;
642                 break;
643         default:
644                 break;
645         }
646
647         ecore_imf_context_autocapital_type_set(__pContext, ecoreAutoCapitalization);
648         return r;
649 }
650
651 AutoCapitalizationMode
652 _InputConnectionImpl::GetAutoCapitalizationMode(void) const
653 {
654         ClearLastResult();
655
656         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
657
658         Ecore_IMF_Autocapital_Type ecoreAutoCapitalization = ecore_imf_context_autocapital_type_get(__pContext);
659         AutoCapitalizationMode autoCapitalizationMode = AUTO_CAPITALIZATION_MODE_SENTENCE;
660
661         switch (ecoreAutoCapitalization)
662         {
663         case ECORE_IMF_AUTOCAPITAL_TYPE_NONE:
664                 autoCapitalizationMode = AUTO_CAPITALIZATION_MODE_NONE;
665                 break;
666         case ECORE_IMF_AUTOCAPITAL_TYPE_WORD:
667                 autoCapitalizationMode = AUTO_CAPITALIZATION_MODE_WORD;
668                 break;
669         case ECORE_IMF_AUTOCAPITAL_TYPE_SENTENCE:
670                 autoCapitalizationMode = AUTO_CAPITALIZATION_MODE_SENTENCE;
671                 break;
672         case ECORE_IMF_AUTOCAPITAL_TYPE_ALLCHARACTER:
673                 autoCapitalizationMode = AUTO_CAPITALIZATION_MODE_ALL;
674                 break;
675         default:
676                 break;
677         }
678
679         return autoCapitalizationMode;
680 }
681
682 InputPanelShowState
683 _InputConnectionImpl::GetInputPanelShowState(void) const
684 {
685         ClearLastResult();
686
687         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
688
689         return __inputPanelState;
690 }
691
692 result
693 _InputConnectionImpl::SetInputPanelShowState(InputPanelShowState state)
694 {
695         result r = E_SUCCESS;
696
697         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
698
699         __inputPanelState = state;
700         return r;
701 }
702
703 result
704 _InputConnectionImpl::FinishTextComposition(void)
705 {
706         result r = E_SUCCESS;
707
708         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
709         SysTryReturnResult(NID_UI, __IsBounded, E_INVALID_STATE, "This is not a bind state");
710
711         ecore_imf_context_reset(__pContext);
712         return r;
713 }
714
715 result
716 _InputConnectionImpl::SetInputPanelAction(InputPanelAction inputPanelAction)
717 {
718         result r = E_SUCCESS;
719
720         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
721
722         __inputPanelAction = inputPanelAction;
723         Ecore_IMF_Input_Panel_Return_Key_Type ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
724
725         switch (inputPanelAction)
726         {
727         case INPUT_PANEL_ACTION_GO:
728                 ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO;
729                 break;
730         case INPUT_PANEL_ACTION_NEXT:
731                 ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT;
732                 break;
733         case INPUT_PANEL_ACTION_SEND:
734                 ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND;
735                 break;
736         case INPUT_PANEL_ACTION_SEARCH:
737                 ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH;
738                 break;
739         case INPUT_PANEL_ACTION_LOGIN:
740                 ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN;
741                 break;
742         case INPUT_PANEL_ACTION_SIGN_IN:
743                 ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SIGNIN;
744                 break;
745         case INPUT_PANEL_ACTION_JOIN:
746                 ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN;
747                 break;
748         case INPUT_PANEL_ACTION_DONE:
749                 ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
750                 break;
751         case INPUT_PANEL_ACTION_ENTER:
752                 ecorePanelAction = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
753                 break;
754         default:
755                 break;
756         }
757
758         ecore_imf_context_input_panel_return_key_type_set(__pContext, ecorePanelAction);
759
760         return r;
761 }
762
763 InputPanelAction
764 _InputConnectionImpl::GetInputPanelAction(void) const
765 {
766         ClearLastResult();
767
768         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
769
770         Ecore_IMF_Input_Panel_Return_Key_Type ecorePanelAction = ecore_imf_context_input_panel_return_key_type_get(__pContext);
771         InputPanelAction inputPanelAction = INPUT_PANEL_ACTION_ENTER;
772
773         switch (ecorePanelAction)
774         {
775         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO:
776                 inputPanelAction = INPUT_PANEL_ACTION_GO;
777                 break;
778         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT:
779                 inputPanelAction = INPUT_PANEL_ACTION_NEXT;
780                 break;
781         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND:
782                 inputPanelAction = INPUT_PANEL_ACTION_SEND;
783                 break;
784         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH:
785                 inputPanelAction = INPUT_PANEL_ACTION_SEARCH;
786                 break;
787         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN:
788                 inputPanelAction = INPUT_PANEL_ACTION_LOGIN;
789                 break;
790         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SIGNIN:
791                 inputPanelAction = INPUT_PANEL_ACTION_SIGN_IN;
792                 break;
793         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN:
794                 inputPanelAction = INPUT_PANEL_ACTION_JOIN;
795                 break;
796         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE:
797                 inputPanelAction = INPUT_PANEL_ACTION_DONE;
798                 break;
799         case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT:
800                 inputPanelAction = INPUT_PANEL_ACTION_ENTER;
801                 break;
802         default:
803                 break;
804         }
805
806         return inputPanelAction;
807 }
808
809 result
810 _InputConnectionImpl::SetInputPanelActionEnabled(bool enable)
811 {
812         result r = E_SUCCESS;
813
814         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
815
816         ecore_imf_context_input_panel_return_key_disabled_set(__pContext, (!enable ? EINA_TRUE : EINA_FALSE));
817         return r;
818 }
819
820 bool
821 _InputConnectionImpl::IsInputPanelActionEnabled(void) const
822 {
823         ClearLastResult();
824
825         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
826
827         Eina_Bool enabled = ecore_imf_context_input_panel_return_key_disabled_get(__pContext);
828
829         return static_cast<bool>(!enabled);
830 }
831
832 result
833 _InputConnectionImpl::SetCursorPosition(int position)
834 {
835         result r = E_SUCCESS;
836
837         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
838         SysTryReturnResult(NID_UI, position >= 0, E_INVALID_ARG, "The input parameter is invalid.");
839         SysTryReturnResult(NID_UI, __IsBounded, E_INVALID_STATE, "This is not a bind state");
840
841         ecore_imf_context_cursor_position_set(__pContext, position);
842         return r;
843 }
844
845 result
846 _InputConnectionImpl::SetCursorBounds(const Rectangle& rect)
847 {
848         result r = E_SUCCESS;
849
850         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
851
852         SysTryReturnResult(NID_UI, (rect.width > 0)&&(rect.height > 0), E_INVALID_ARG, "The input parameter is invalid.");
853         SysTryReturnResult(NID_UI, __IsBounded, E_INVALID_STATE, "This is not a bind state");
854
855
856         Rectangle cursorRectangle;
857         cursorRectangle = rect;
858
859         const _Control* pControl = _ControlManager::GetInstance()->GetObject(__controlHandle);
860
861         if (pControl)
862         {
863                 Rectangle absoluteControlRectangle;
864                 absoluteControlRectangle = pControl->GetAbsoluteBounds(true);
865                 cursorRectangle.x += absoluteControlRectangle.x;
866                 cursorRectangle.y += absoluteControlRectangle.y;
867         }
868
869         Rectangle physicalRect = _CoordinateSystemUtils::Transform(cursorRectangle);
870
871         ecore_imf_context_cursor_location_set(__pContext, physicalRect.x, physicalRect.y, physicalRect.width, physicalRect.height);
872         return r;
873 }
874
875 result
876 _InputConnectionImpl::SetCursorBounds(const FloatRectangle& rect)
877 {
878         result r = E_SUCCESS;
879
880         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
881
882         SysTryReturnResult(NID_UI, (rect.width > 0)&&(rect.height > 0), E_INVALID_ARG, "The input parameter is invalid.");
883         SysTryReturnResult(NID_UI, __IsBounded, E_INVALID_STATE, "This is not a bind state");
884
885
886         FloatRectangle cursorRectangle;
887         cursorRectangle = rect;
888
889         const _Control* pControl = _ControlManager::GetInstance()->GetObject(__controlHandle);
890
891         if (pControl)
892         {
893                 FloatRectangle absoluteControlRectangle;
894                 absoluteControlRectangle = pControl->GetAbsoluteBoundsF(true);
895                 cursorRectangle.x += absoluteControlRectangle.x;
896                 cursorRectangle.y += absoluteControlRectangle.y;
897         }
898
899         FloatRectangle physicalFloatRect = _CoordinateSystemUtils::Transform(cursorRectangle);
900         Rectangle physicalRect = _CoordinateSystemUtils::ConvertToInteger(physicalFloatRect);
901
902         ecore_imf_context_cursor_location_set(__pContext, physicalRect.x, physicalRect.y, physicalRect.width, physicalRect.height);
903         return r;
904 }
905
906 Rectangle
907 _InputConnectionImpl::GetInputPanelBounds(void) const
908 {
909         ClearLastResult();
910
911         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
912
913         int x = 0;
914         int y = 0;
915         int w = 0;
916         int h = 0;
917
918         ecore_imf_context_input_panel_geometry_get(__pContext, &x, &y, &w, &h);
919         return Rectangle(x, y, w, h);
920 }
921
922 FloatRectangle
923 _InputConnectionImpl::GetInputPanelBoundsF(void) const
924 {
925         ClearLastResult();
926
927         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
928
929         int x = 0;
930         int y = 0;
931         int w = 0;
932         int h = 0;
933
934         ecore_imf_context_input_panel_geometry_get(__pContext, &x, &y, &w, &h);
935         FloatRectangle inputPanelFloatRect;
936         inputPanelFloatRect.x = _CoordinateSystemUtils::ConvertToFloat(x);
937         inputPanelFloatRect.y = _CoordinateSystemUtils::ConvertToFloat(y);
938         inputPanelFloatRect.width = _CoordinateSystemUtils::ConvertToFloat(w);
939         inputPanelFloatRect.height = _CoordinateSystemUtils::ConvertToFloat(h);
940
941         return inputPanelFloatRect;
942 }
943
944 Rectangle
945 _InputConnectionImpl::GetPredictionBounds(void) const
946 {
947         ClearLastResult();
948
949         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
950
951         int x = 0;
952         int y = 0;
953         int w = 0;
954         int h = 0;
955
956         ecore_imf_context_candidate_panel_geometry_get(__pContext, &x, &y, &w, &h);
957         return Rectangle(x, y, w, h);
958 }
959
960 FloatRectangle
961 _InputConnectionImpl::GetPredictionBoundsF(void) const
962 {
963         ClearLastResult();
964
965         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
966
967         int x = 0;
968         int y = 0;
969         int w = 0;
970         int h = 0;
971
972         ecore_imf_context_candidate_panel_geometry_get(__pContext, &x, &y, &w, &h);
973         FloatRectangle inputPredictionFloatRect;
974         inputPredictionFloatRect.x = _CoordinateSystemUtils::ConvertToFloat(x);
975         inputPredictionFloatRect.y = _CoordinateSystemUtils::ConvertToFloat(y);
976         inputPredictionFloatRect.width = _CoordinateSystemUtils::ConvertToFloat(w);
977         inputPredictionFloatRect.height = _CoordinateSystemUtils::ConvertToFloat(h);
978
979         return inputPredictionFloatRect;
980 }
981
982 result
983 _InputConnectionImpl::SetTextPredictionEnabled(bool enable)
984 {
985         result r = E_SUCCESS;
986
987         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
988
989         ecore_imf_context_prediction_allow_set(__pContext, (enable ? EINA_TRUE : EINA_FALSE));
990
991         return r;
992 }
993
994 bool
995 _InputConnectionImpl::IsTextPredictionEnabled(void) const
996 {
997         ClearLastResult();
998
999         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
1000
1001         Eina_Bool enabled = ecore_imf_context_prediction_allow_get(__pContext);
1002
1003         return static_cast<bool>(enabled);
1004 }
1005
1006 result
1007 _InputConnectionImpl::SetCapsLockEnabled(bool enable)
1008 {
1009         result r = E_SUCCESS;
1010
1011         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
1012
1013         ecore_imf_context_input_panel_caps_lock_mode_set(__pContext, (enable ? EINA_TRUE : EINA_FALSE));
1014
1015         return r;
1016 }
1017
1018 bool
1019 _InputConnectionImpl::IsCapsLockEnabled(void) const
1020 {
1021         ClearLastResult();
1022
1023         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
1024
1025         Eina_Bool enabled = ecore_imf_context_input_panel_caps_lock_mode_get(__pContext);
1026
1027         return static_cast<bool>(enabled);
1028 }
1029
1030 result
1031 _InputConnectionImpl::SetPasswordMode(bool enable)
1032 {
1033         result r = E_SUCCESS;
1034
1035         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
1036
1037         __passwordMode = true;
1038         ecore_imf_context_input_panel_layout_set(__pContext, ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD);
1039
1040         return r;
1041 }
1042
1043 bool
1044 _InputConnectionImpl::IsPasswordMode(void) const
1045 {
1046         return __passwordMode;
1047 }
1048
1049 result
1050 _InputConnectionImpl::SetInputPanelLanguage(LanguageCode languageCode)
1051 {
1052         result r = E_SUCCESS;
1053
1054         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
1055
1056         String language(L"");
1057         language = _BidiUtils::ConvertLanguageCountryCodeString(languageCode);
1058         if (language == String(L""))
1059         {
1060                 const char* pLanguage = "lang=en_US";
1061                 ecore_imf_context_input_panel_imdata_set(__pContext, pLanguage, LANGUAGE_IM_DATA_LENGTH);
1062                 return r;
1063         }
1064         else
1065         {
1066                 char* pLanguage = null;
1067                 int len = wcstombs(0, static_cast<const wchar_t*>(language.GetPointer()), 0);
1068                 pLanguage = (char*)malloc(len+1);
1069                 SysTryReturn(NID_UI, pLanguage, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pLanguage is null.");
1070
1071                 len = wcstombs(pLanguage, static_cast<const wchar_t*>(language.GetPointer()), len);
1072                 pLanguage[len] = null;
1073
1074                 ecore_imf_context_input_panel_imdata_set(__pContext, pLanguage, LANGUAGE_IM_DATA_LENGTH);
1075
1076                 free(pLanguage);
1077         }
1078         return r;
1079 }
1080
1081 LanguageCode
1082 _InputConnectionImpl::GetInputPanelLanguage(void) const
1083 {
1084         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
1085
1086         ClearLastResult();
1087
1088         char* pLocale = null;
1089
1090         ecore_imf_context_input_panel_language_locale_get(__pContext, &pLocale);
1091
1092         String tempBuffer(pLocale);
1093         String language;
1094         tempBuffer.SubString(LANGUAGE_CODE_START, LANGUAGE_CODE_MAX, language);
1095
1096         if (pLocale)
1097         {
1098                 free(pLocale);
1099         }
1100
1101         return Locale::TwoLetterLanguageCodeStringToLanguageCode(language);
1102 }
1103
1104 void
1105 _InputConnectionImpl::SendOpaqueCommand(const String& command)
1106 {
1107         SysAssertf(__pContext != null, "Not yet constructed. Construct() should be called before use.");
1108
1109         char* pCommand = null;
1110         int length = 0;
1111
1112         length = wcstombs(0, static_cast<const wchar_t*>(command.GetPointer()), 0);
1113         SysTryReturnVoidResult(NID_UI, length != -1, E_OUT_OF_MEMORY, "A system error occurred.");
1114
1115         pCommand = (char*)malloc(length+1);
1116         SysTryReturnVoidResult(NID_UI, pCommand, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1117
1118         length = wcstombs(pCommand, static_cast<const wchar_t*>(command.GetPointer()), length);
1119         pCommand[length] = null;
1120
1121         ecore_imf_context_input_panel_imdata_set(__pContext, pCommand, length);
1122
1123         free(pCommand);
1124 }
1125
1126 InputConnection*
1127 _InputConnectionImpl::GetInputConnection(void) const
1128 {
1129         return __pInputConnection;
1130 }
1131
1132 IInputConnectionEventListener*
1133 _InputConnectionImpl::GetInputConnectionListener(void) const
1134 {
1135         return __pListener;
1136 }
1137
1138 IInputConnectionEventListenerF*
1139 _InputConnectionImpl::GetInputConnectionListenerF(void) const
1140 {
1141         return __pListenerF;
1142 }
1143
1144 IInputConnectionProvider*
1145 _InputConnectionImpl::GetInputConnectionProvider(void) const
1146 {
1147         return __pProvider;
1148 }
1149
1150 bool
1151 _InputConnectionImpl::CheckContextEvent(Ecore_IMF_Event_Type type, void* pEventInfo)
1152 {
1153         ClearLastResult();
1154
1155         if (type == ECORE_IMF_EVENT_KEY_DOWN)
1156         {
1157                 Evas_Event_Key_Down* pDownEvent = static_cast<Evas_Event_Key_Down*>(pEventInfo);
1158                 SysTryReturn(NID_UI, pDownEvent != null, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1159                 Ecore_IMF_Event_Key_Down ecoreEvent;
1160                 ecore_imf_evas_event_key_down_wrap(pDownEvent, &ecoreEvent);
1161                 if (ecore_imf_context_filter_event(__pContext, type, (Ecore_IMF_Event*)&ecoreEvent) == EINA_TRUE)
1162                 {
1163                         return true;
1164                 }
1165         }
1166         else if (type == ECORE_IMF_EVENT_KEY_UP)
1167         {
1168                 Evas_Event_Key_Up* pUpEvent = static_cast<Evas_Event_Key_Up*>(pEventInfo);
1169                 SysTryReturn(NID_UI, pUpEvent != null, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1170                 Ecore_IMF_Event_Key_Up ecoreEvent;
1171                 ecore_imf_evas_event_key_up_wrap(pUpEvent, &ecoreEvent);
1172                 if (ecore_imf_context_filter_event(__pContext, type, (Ecore_IMF_Event*)&ecoreEvent) == EINA_TRUE)
1173                 {
1174                         return true;
1175                 }
1176         }
1177         return false;
1178 }
1179
1180 bool
1181 _InputConnectionImpl::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1182 {
1183         if (__IsKeyEventSkipped)
1184         {
1185                 return false;
1186         }
1187
1188         _KeyCode keyCode = keyInfo.GetKeyCode();
1189         if (keyCode == _KEY_OEM_1)
1190         {
1191                 return false;
1192         }
1193
1194         Ecore_Event_Key* pEvent = static_cast<Ecore_Event_Key*>(keyInfo.GetUserData());
1195         SysTryReturn(NID_UI, pEvent, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1196
1197         Ecore_IMF_Event_Key_Down* pKeyDown = (Ecore_IMF_Event_Key_Down*)malloc(sizeof(Ecore_IMF_Event_Key_Down));
1198         SysTryReturn(NID_UI, pKeyDown, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1199
1200         pKeyDown->keyname = pEvent->keyname;
1201
1202         //need to check with SLP
1203         int modifiers = ECORE_IMF_KEYBOARD_MODIFIER_NONE;
1204
1205         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
1206         {
1207                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;
1208         }
1209         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_CTRL)
1210         {
1211                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
1212         }
1213         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_ALT)
1214         {
1215                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
1216         }
1217         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_WIN)
1218         {
1219                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
1220         }
1221         pKeyDown->modifiers = static_cast<Ecore_IMF_Keyboard_Modifiers>(modifiers);
1222
1223         int locks = ECORE_IMF_KEYBOARD_LOCK_NONE;
1224         if (pEvent->modifiers & ECORE_EVENT_LOCK_SCROLL)
1225         {
1226                 locks |= ECORE_IMF_KEYBOARD_LOCK_SCROLL;
1227         }
1228         if (pEvent->modifiers & ECORE_EVENT_LOCK_NUM)
1229         {
1230                 locks |= ECORE_IMF_KEYBOARD_LOCK_NUM;
1231         }
1232         if (pEvent->modifiers & ECORE_EVENT_LOCK_CAPS)
1233         {
1234                 locks |= ECORE_IMF_KEYBOARD_LOCK_CAPS;
1235         }
1236         pKeyDown->locks = static_cast<Ecore_IMF_Keyboard_Locks>(locks);
1237
1238         pKeyDown->key = pEvent->key;
1239         pKeyDown->string = pEvent->string;
1240         pKeyDown->compose = pEvent->compose;
1241         pKeyDown->timestamp = pEvent->timestamp;
1242
1243         const _Control* pControl = _ControlManager::GetInstance()->GetObject(__controlHandle);
1244
1245         if (&source == pControl)
1246         {
1247                 if(CheckUSBKeyboardStatus() && pKeyDown->string)//usb keyboard exist
1248                 {
1249                                 const char* key = const_cast<char*>(pKeyDown->string);
1250                                 if(FilterKeyOnUSBMode(GetInputPanelStyle(), key, true) == E_SUCCESS)
1251                         {
1252                                 free(pKeyDown);
1253                                 return false;
1254                         }
1255                 }
1256
1257                 if (ecore_imf_context_filter_event(__pContext, ECORE_IMF_EVENT_KEY_DOWN, (Ecore_IMF_Event*)pKeyDown) == EINA_TRUE)
1258                 {
1259                         free(pKeyDown);
1260
1261                         return false;
1262                 }
1263                 else
1264                 {
1265                         if ((pEvent->modifiers & ECORE_EVENT_MODIFIER_CTRL) || (pEvent->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_ALT) || (pEvent->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_WIN))
1266                         {
1267                                 return false;
1268                         }
1269
1270                         if (!pEvent->compose)
1271                         {
1272                                 return false;
1273                         }
1274
1275                         InputConnection* pInputConnection = GetInputConnection();
1276                         String commitText(pEvent->compose);
1277                         wchar_t commitChar= '\0';
1278                         commitText.GetCharAt(0, commitChar);
1279                         IInputConnectionEventListener* pListener = GetInputConnectionListener();
1280                         IInputConnectionEventListenerF* pListenerF = GetInputConnectionListenerF();
1281                         if (Character::IsAlphaNumeric(commitChar))
1282                         {
1283                                 if (pListener)
1284                                 {
1285                                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1286                                 }
1287                                 if (pListenerF)
1288                                 {
1289                                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1290                                 }
1291                         }
1292                         if (commitText == L" " || commitText == L"\t")
1293                         {
1294                                 if (pListener)
1295                                 {
1296                                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1297                                 }
1298                                 if (pListenerF)
1299                                 {
1300                                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1301                                 }
1302                         }
1303                         if (commitText == L"\n" || commitText == L"\r")
1304                         {
1305                                 if (pListener)
1306                                 {
1307                                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1308                                 }
1309                                 if (pListenerF)
1310                                 {
1311                                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1312                                 }
1313                         }
1314                         if ( (commitChar >= 0x21 && commitChar <= 0x2F) || (commitChar >= 0x3A && commitChar <= 0x40) ||
1315                          (commitChar >= 0x5B && commitChar <= 0x60) || (commitChar >= 0x7B && commitChar<= 0x7E) )
1316                         {
1317                                 if (pListener)
1318                                 {
1319                                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1320                                 }
1321                                 if (pListenerF)
1322                                 {
1323                                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1324                                 }
1325                         }
1326
1327                         free(pKeyDown);
1328
1329                         return false;
1330                 }
1331         }
1332
1333         free(pKeyDown);
1334
1335         SetLastResult(E_SUCCESS);
1336
1337         return false;
1338 }
1339
1340 bool
1341 _InputConnectionImpl::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1342 {
1343         if (__IsKeyEventSkipped)
1344         {
1345                 return false;
1346         }
1347
1348         _KeyCode keyCode = keyInfo.GetKeyCode();
1349         if (keyCode == _KEY_OEM_1)
1350         {
1351                 return false;
1352         }
1353
1354         Ecore_Event_Key* pEvent = static_cast<Ecore_Event_Key*>(keyInfo.GetUserData());
1355         SysTryReturn(NID_UI, pEvent, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1356
1357         Ecore_IMF_Event_Key_Up* pKeyUp = (Ecore_IMF_Event_Key_Up*)malloc(sizeof(Ecore_IMF_Event_Key_Up));
1358         SysTryReturn(NID_UI, pKeyUp, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1359
1360         pKeyUp->keyname = pEvent->keyname;
1361
1362         //need to check with SLP
1363         int modifiers = ECORE_IMF_KEYBOARD_MODIFIER_NONE;
1364
1365         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
1366         {
1367                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;
1368         }
1369         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_CTRL)
1370         {
1371                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
1372         }
1373         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_ALT)
1374         {
1375                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
1376         }
1377         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_WIN)
1378         {
1379                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
1380         }
1381         pKeyUp->modifiers = static_cast<Ecore_IMF_Keyboard_Modifiers>(modifiers);
1382
1383         int locks = ECORE_IMF_KEYBOARD_LOCK_NONE;
1384         if (pEvent->modifiers & ECORE_EVENT_LOCK_SCROLL)
1385         {
1386                 locks |= ECORE_IMF_KEYBOARD_LOCK_SCROLL;
1387         }
1388         if (pEvent->modifiers & ECORE_EVENT_LOCK_NUM)
1389         {
1390                 locks |= ECORE_IMF_KEYBOARD_LOCK_NUM;
1391         }
1392         if (pEvent->modifiers & ECORE_EVENT_LOCK_CAPS)
1393         {
1394                 locks |= ECORE_IMF_KEYBOARD_LOCK_CAPS;
1395         }
1396         pKeyUp->locks = static_cast<Ecore_IMF_Keyboard_Locks>(locks);
1397
1398         pKeyUp->key = pEvent->key;
1399         pKeyUp->string = pEvent->string;
1400         pKeyUp->compose = pEvent->compose;
1401         pKeyUp->timestamp = pEvent->timestamp;
1402
1403         const _Control* pControl = _ControlManager::GetInstance()->GetObject(__controlHandle);
1404
1405         if (&source == pControl)
1406         {
1407         if(CheckUSBKeyboardStatus() && pKeyUp->string)//usb keyboard exist
1408         {
1409                         const char* key = const_cast<char*>(pKeyUp->string);
1410                         if(FilterKeyOnUSBMode(GetInputPanelStyle(), key) == E_SUCCESS)
1411                 {
1412                         free(pKeyUp);
1413                         return false;
1414                 }
1415         }
1416
1417                 if (ecore_imf_context_filter_event(__pContext, ECORE_IMF_EVENT_KEY_UP, (Ecore_IMF_Event*)pKeyUp) == EINA_TRUE)
1418                 {
1419                         free(pKeyUp);
1420
1421                         return false;
1422                 }
1423         }
1424
1425         free(pKeyUp);
1426
1427         SetLastResult(E_SUCCESS);
1428
1429         return false;
1430 }
1431
1432 void
1433 _InputConnectionImpl::AddInputPanelCallback(void)
1434 {
1435         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, OnInputPanelShowStateEvent, this);
1436         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, OnInputPanelLanguageEvent, this);
1437         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, OnInputPanelSizeChangedEvent, this);
1438         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_CANDIDATE_PANEL_STATE_EVENT, OnInputPanelPredictionModeEvent, this);
1439         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_CANDIDATE_PANEL_GEOMETRY_EVENT, OnInputPanelPredictionSizeChangedEvent, this);
1440         ecore_imf_context_retrieve_surrounding_callback_set(__pContext, OnRetrieveSurrounding, this);
1441
1442         return;
1443 }
1444
1445 void
1446 _InputConnectionImpl::AddEcoreEventCallback(void)
1447 {
1448         ecore_imf_context_event_callback_add(__pContext, ECORE_IMF_CALLBACK_COMMIT, OnCommitTextEcoreEvent, this);
1449         ecore_imf_context_event_callback_add(__pContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, OnComposeTextEcoreEvent, this);
1450         ecore_imf_context_event_callback_add(__pContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, OnDeleteSurroundingTextEcoreEvent, this);
1451
1452 /*
1453         //Internal USB Check
1454         Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
1455         ecore_x_event_mask_set(rootWindow, ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
1456     __pUSBEventHandler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, OnUSBKeyboardEcoreEvent, this);
1457     */
1458         return;
1459 }
1460
1461 void
1462 _InputConnectionImpl::AddEvasObjectEventCallback(void)
1463 {
1464         result r = _UiEventManager::GetInstance()->AddTargetPostKeyEventListener(*this);
1465         SysTryReturnVoidResult(NID_UI,  r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1466
1467         return;
1468 }
1469
1470 void
1471 _InputConnectionImpl::RemoveInputPanelCallback(void)
1472 {
1473         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, OnInputPanelShowStateEvent);
1474         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, OnInputPanelLanguageEvent);
1475         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, OnInputPanelSizeChangedEvent);
1476         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_CANDIDATE_PANEL_STATE_EVENT, OnInputPanelPredictionModeEvent);
1477         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_CANDIDATE_PANEL_GEOMETRY_EVENT, OnInputPanelPredictionSizeChangedEvent);
1478
1479         return;
1480 }
1481
1482 void
1483 _InputConnectionImpl::RemoveEcoreEventCallback(void)
1484 {
1485         ecore_imf_context_event_callback_del(__pContext, ECORE_IMF_CALLBACK_COMMIT, OnCommitTextEcoreEvent);
1486         ecore_imf_context_event_callback_del(__pContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, OnComposeTextEcoreEvent);
1487         ecore_imf_context_event_callback_del(__pContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, OnDeleteSurroundingTextEcoreEvent);
1488
1489 /*
1490         //Internal USB Check Release
1491         if (__pUSBEventHandler)
1492         {
1493                 ecore_event_handler_del(__pUSBEventHandler);
1494                 __pUSBEventHandler = null;
1495         }
1496         */
1497         return;
1498 }
1499
1500 void
1501 _InputConnectionImpl::RemoveEvasObjectEventCallback(void)
1502 {
1503         result r = _UiEventManager::GetInstance()->RemoveTargetPostKeyEventListener(*this);
1504         SysTryReturnVoidResult(NID_UI,  r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1505
1506         return;
1507 }
1508
1509 _InputConnectionImpl*
1510 _InputConnectionImpl::GetInstance(InputConnection& inputConnection)
1511 {
1512         return inputConnection.__pInputConnectionImpl;
1513 }
1514 const _InputConnectionImpl*
1515 _InputConnectionImpl::GetInstance(const InputConnection& inputConnection)
1516 {
1517         return inputConnection.__pInputConnectionImpl;
1518 }
1519
1520 int
1521 _InputConnectionImpl::CheckUSBKeyboardStatus(void)
1522 {
1523         return _InputConnectionUtils::CheckUSBKeyboardStatus();
1524 }
1525
1526 result
1527 _InputConnectionImpl::FilterKeyOnUSBMode(InputPanelStyle style, const char* key, bool commit)
1528 {
1529         if(!(style == INPUT_PANEL_STYLE_NUMBER_ONLY || style == INPUT_PANEL_STYLE_PHONE_NUMBER || style == INPUT_PANEL_STYLE_IP))
1530         {
1531                 return E_INVALID_ARG;
1532         }
1533
1534         SysTryReturn(NID_UI, key, E_INVALID_ARG, E_INVALID_ARG, "key is null");
1535
1536         char TempKey[20] = {0,};
1537         const char keyOnNumOnlyStyle[10] = { 0x30/*0*/, 0x31/*1*/, 0x32/*2*/, 0x33/*3*/, 0x34/*4*/, 0x35/*5*/, 0x36/*6*/, 0x37/*7*/, 0x38/*8*/, 0x39/*9*/};
1538         const char keyOnPhoneNumStyle[14] = { 0x30/*0*/, 0x31/*1*/, 0x32/*2*/, 0x33/*3*/, 0x34/*4*/, 0x35/*5*/, 0x36/*6*/, 0x37/*7*/, 0x38/*8*/, 0x39/*9*/,
1539                                                                         0x2a/***/, 0x2b/*+*/, 0x23/*#*/, 0x70/*p*/};
1540         const char keyOnIPStyle[18] = { 0x30/*0*/, 0x31/*1*/, 0x32/*2*/, 0x33/*3*/, 0x34/*4*/, 0x35/*5*/, 0x36/*6*/, 0x37/*7*/, 0x38/*8*/, 0x39/*9*/,
1541                                                                         0x3a/*:*/, 0x2e/*.*/, 0x61/*a*/, 0x62/*b*/, 0x63/*c*/, 0x64/*d*/, 0x65/*e*/, 0x66/*f*/};
1542         bool isExist = false;
1543         int keyCount = 0;
1544
1545         if(style == INPUT_PANEL_STYLE_NUMBER_ONLY)
1546         {
1547                 keyCount = 10;
1548                 memcpy(TempKey, keyOnNumOnlyStyle, keyCount*sizeof(char));
1549         }
1550         else if(style == INPUT_PANEL_STYLE_PHONE_NUMBER)
1551         {
1552                 keyCount = 13;
1553                 memcpy(TempKey, keyOnPhoneNumStyle, keyCount*sizeof(char));
1554         }
1555         else if(style == INPUT_PANEL_STYLE_IP)
1556         {
1557                 keyCount = 18;
1558                 memcpy(TempKey, keyOnIPStyle, keyCount*sizeof(char));
1559         }
1560
1561         for (int i = 0; i < keyCount ; i++)
1562         {
1563                 if(TempKey[i] == key[0])
1564                 {
1565                         isExist = true;
1566                         break;
1567                 }
1568         }
1569
1570         if (isExist == true && commit == true)
1571         {
1572                 String commitText(key);
1573                 if (commitText.GetLength() > 1)
1574                 {
1575                         return E_SUCCESS;
1576                 }
1577                 InputConnection* pInputConnection = GetInputConnection();
1578                 IInputConnectionEventListener* pListener = GetInputConnectionListener();
1579                 IInputConnectionEventListenerF* pListenerF = GetInputConnectionListenerF();
1580                 if (pListener)
1581                 {
1582                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1583                 }
1584                 if (pListenerF)
1585                 {
1586                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1587                 }
1588         }
1589
1590         return E_SUCCESS;
1591 }
1592
1593 void
1594 _InputConnectionImpl::SetKeyEventSkipped(bool enabled)
1595 {
1596         __IsKeyEventSkipped = enabled;
1597 }
1598
1599 }} // Tizen::Ui