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