modify license, permission and remove ^M char
[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_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         _KeyCode keyCode = keyInfo.GetKeyCode();
1159         if (keyCode == _KEY_OEM_1)
1160         {
1161                 return false;
1162         }
1163
1164         Ecore_Event_Key* pEvent = static_cast<Ecore_Event_Key*>(keyInfo.GetUserData());
1165         SysTryReturn(NID_UI, pEvent, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1166
1167         Ecore_IMF_Event_Key_Down* pKeyDown = (Ecore_IMF_Event_Key_Down*)malloc(sizeof(Ecore_IMF_Event_Key_Down));
1168         SysTryReturn(NID_UI, pKeyDown, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1169
1170         pKeyDown->keyname = pEvent->keyname;
1171
1172         //need to check with SLP
1173         int modifiers = ECORE_IMF_KEYBOARD_MODIFIER_NONE;
1174
1175         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
1176         {
1177                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;
1178         }
1179         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_CTRL)
1180         {
1181                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
1182         }
1183         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_ALT)
1184         {
1185                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
1186         }
1187         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_WIN)
1188         {
1189                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
1190         }
1191         pKeyDown->modifiers = static_cast<Ecore_IMF_Keyboard_Modifiers>(modifiers);
1192
1193         int locks = ECORE_IMF_KEYBOARD_LOCK_NONE;
1194         if (pEvent->modifiers & ECORE_EVENT_LOCK_SCROLL)
1195         {
1196                 locks |= ECORE_IMF_KEYBOARD_LOCK_SCROLL;
1197         }
1198         if (pEvent->modifiers & ECORE_EVENT_LOCK_NUM)
1199         {
1200                 locks |= ECORE_IMF_KEYBOARD_LOCK_NUM;
1201         }
1202         if (pEvent->modifiers & ECORE_EVENT_LOCK_CAPS)
1203         {
1204                 locks |= ECORE_IMF_KEYBOARD_LOCK_CAPS;
1205         }
1206         pKeyDown->locks = static_cast<Ecore_IMF_Keyboard_Locks>(locks);
1207
1208         pKeyDown->key = pEvent->key;
1209         pKeyDown->string = pEvent->string;
1210         pKeyDown->compose = pEvent->compose;
1211         pKeyDown->timestamp = pEvent->timestamp;
1212
1213         const _Control* pControl = _ControlManager::GetInstance()->GetObject(__controlHandle);
1214
1215         if (&source == pControl)
1216         {
1217                 if(CheckUSBKeyboardStatus() && pKeyDown->string)//usb keyboard exist
1218                 {
1219                                 const char* key = const_cast<char*>(pKeyDown->string);
1220                                 if(FilterKeyOnUSBMode(GetInputPanelStyle(), key, true) == E_SUCCESS)
1221                         {
1222                                 free(pKeyDown);
1223                                 return false;
1224                         }
1225                 }
1226
1227                 if (ecore_imf_context_filter_event(__pContext, ECORE_IMF_EVENT_KEY_DOWN, (Ecore_IMF_Event*)pKeyDown) == EINA_TRUE)
1228                 {
1229                         free(pKeyDown);
1230
1231                         return false;
1232                 }
1233                 else
1234                 {
1235                         if ((pEvent->modifiers & ECORE_EVENT_MODIFIER_CTRL) || (pEvent->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_ALT) || (pEvent->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_WIN))
1236                         {
1237                                 return false;
1238                         }
1239
1240                         if (!pEvent->compose)
1241                         {
1242                                 return false;
1243                         }
1244
1245                         InputConnection* pInputConnection = GetInputConnection();
1246                         String commitText(pEvent->compose);
1247                         wchar_t commitChar= '\0';
1248                         commitText.GetCharAt(0, commitChar);
1249                         IInputConnectionEventListener* pListener = GetInputConnectionListener();
1250                         IInputConnectionEventListenerF* pListenerF = GetInputConnectionListenerF();
1251                         if (Character::IsAlphaNumeric(commitChar))
1252                         {
1253                                 if (pListener)
1254                                 {
1255                                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1256                                 }
1257                                 if (pListenerF)
1258                                 {
1259                                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1260                                 }
1261                         }
1262                         if (commitText == L" " || commitText == L"\t")
1263                         {
1264                                 if (pListener)
1265                                 {
1266                                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1267                                 }
1268                                 if (pListenerF)
1269                                 {
1270                                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1271                                 }
1272                         }
1273                         if (commitText == L"\n" || commitText == L"\r")
1274                         {
1275                                 if (pListener)
1276                                 {
1277                                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1278                                 }
1279                                 if (pListenerF)
1280                                 {
1281                                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1282                                 }
1283                         }
1284                         if ( (commitChar >= 0x21 && commitChar <= 0x2F) || (commitChar >= 0x3A && commitChar <= 0x40) ||
1285                          (commitChar >= 0x5B && commitChar <= 0x60) || (commitChar >= 0x7B && commitChar<= 0x7E) )
1286                         {
1287                                 if (pListener)
1288                                 {
1289                                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1290                                 }
1291                                 if (pListenerF)
1292                                 {
1293                                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1294                                 }
1295                         }
1296
1297                         free(pKeyDown);
1298
1299                         return false;
1300                 }
1301         }
1302
1303         free(pKeyDown);
1304
1305         SetLastResult(E_SUCCESS);
1306
1307         return false;
1308 }
1309
1310 bool
1311 _InputConnectionImpl::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1312 {
1313         if (__IsKeyEventSkipped)
1314         {
1315                 return false;
1316         }
1317
1318         _KeyCode keyCode = keyInfo.GetKeyCode();
1319         if (keyCode == _KEY_OEM_1)
1320         {
1321                 return false;
1322         }
1323
1324         Ecore_Event_Key* pEvent = static_cast<Ecore_Event_Key*>(keyInfo.GetUserData());
1325         SysTryReturn(NID_UI, pEvent, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1326
1327         Ecore_IMF_Event_Key_Up* pKeyUp = (Ecore_IMF_Event_Key_Up*)malloc(sizeof(Ecore_IMF_Event_Key_Up));
1328         SysTryReturn(NID_UI, pKeyUp, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1329
1330         pKeyUp->keyname = pEvent->keyname;
1331
1332         //need to check with SLP
1333         int modifiers = ECORE_IMF_KEYBOARD_MODIFIER_NONE;
1334
1335         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
1336         {
1337                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;
1338         }
1339         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_CTRL)
1340         {
1341                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
1342         }
1343         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_ALT)
1344         {
1345                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
1346         }
1347         if (pEvent->modifiers & ECORE_EVENT_MODIFIER_WIN)
1348         {
1349                 modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
1350         }
1351         pKeyUp->modifiers = static_cast<Ecore_IMF_Keyboard_Modifiers>(modifiers);
1352
1353         int locks = ECORE_IMF_KEYBOARD_LOCK_NONE;
1354         if (pEvent->modifiers & ECORE_EVENT_LOCK_SCROLL)
1355         {
1356                 locks |= ECORE_IMF_KEYBOARD_LOCK_SCROLL;
1357         }
1358         if (pEvent->modifiers & ECORE_EVENT_LOCK_NUM)
1359         {
1360                 locks |= ECORE_IMF_KEYBOARD_LOCK_NUM;
1361         }
1362         if (pEvent->modifiers & ECORE_EVENT_LOCK_CAPS)
1363         {
1364                 locks |= ECORE_IMF_KEYBOARD_LOCK_CAPS;
1365         }
1366         pKeyUp->locks = static_cast<Ecore_IMF_Keyboard_Locks>(locks);
1367
1368         pKeyUp->key = pEvent->key;
1369         pKeyUp->string = pEvent->string;
1370         pKeyUp->compose = pEvent->compose;
1371         pKeyUp->timestamp = pEvent->timestamp;
1372
1373         const _Control* pControl = _ControlManager::GetInstance()->GetObject(__controlHandle);
1374
1375         if (&source == pControl)
1376         {
1377         if(CheckUSBKeyboardStatus() && pKeyUp->string)//usb keyboard exist
1378         {
1379                         const char* key = const_cast<char*>(pKeyUp->string);
1380                         if(FilterKeyOnUSBMode(GetInputPanelStyle(), key) == E_SUCCESS)
1381                 {
1382                         free(pKeyUp);
1383                         return false;
1384                 }
1385         }
1386
1387                 if (ecore_imf_context_filter_event(__pContext, ECORE_IMF_EVENT_KEY_UP, (Ecore_IMF_Event*)pKeyUp) == EINA_TRUE)
1388                 {
1389                         free(pKeyUp);
1390
1391                         return false;
1392                 }
1393         }
1394
1395         free(pKeyUp);
1396
1397         SetLastResult(E_SUCCESS);
1398
1399         return false;
1400 }
1401
1402 void
1403 _InputConnectionImpl::AddInputPanelCallback(void)
1404 {
1405         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, OnInputPanelShowStateEvent, this);
1406         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, OnInputPanelLanguageEvent, this);
1407         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, OnInputPanelSizeChangedEvent, this);
1408         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_CANDIDATE_PANEL_STATE_EVENT, OnInputPanelPredictionModeEvent, this);
1409         ecore_imf_context_input_panel_event_callback_add(__pContext, ECORE_IMF_CANDIDATE_PANEL_GEOMETRY_EVENT, OnInputPanelPredictionSizeChangedEvent, this);
1410         ecore_imf_context_retrieve_surrounding_callback_set(__pContext, OnRetrieveSurrounding, this);
1411
1412         return;
1413 }
1414
1415 void
1416 _InputConnectionImpl::AddEcoreEventCallback(void)
1417 {
1418         ecore_imf_context_event_callback_add(__pContext, ECORE_IMF_CALLBACK_COMMIT, OnCommitTextEcoreEvent, this);
1419         ecore_imf_context_event_callback_add(__pContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, OnComposeTextEcoreEvent, this);
1420         ecore_imf_context_event_callback_add(__pContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, OnDeleteSurroundingTextEcoreEvent, this);
1421
1422 /*
1423         //Internal USB Check
1424         Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
1425         ecore_x_event_mask_set(rootWindow, ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
1426     __pUSBEventHandler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, OnUSBKeyboardEcoreEvent, this);
1427     */
1428         return;
1429 }
1430
1431 void
1432 _InputConnectionImpl::AddEvasObjectEventCallback(void)
1433 {
1434         result r = _UiEventManager::GetInstance()->AddPostKeyEventListener(*this);
1435         SysTryReturnVoidResult(NID_UI,  r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1436
1437         return;
1438 }
1439
1440 void
1441 _InputConnectionImpl::RemoveInputPanelCallback(void)
1442 {
1443         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, OnInputPanelShowStateEvent);
1444         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, OnInputPanelLanguageEvent);
1445         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, OnInputPanelSizeChangedEvent);
1446         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_CANDIDATE_PANEL_STATE_EVENT, OnInputPanelPredictionModeEvent);
1447         ecore_imf_context_input_panel_event_callback_del(__pContext, ECORE_IMF_CANDIDATE_PANEL_GEOMETRY_EVENT, OnInputPanelPredictionSizeChangedEvent);
1448
1449         return;
1450 }
1451
1452 void
1453 _InputConnectionImpl::RemoveEcoreEventCallback(void)
1454 {
1455         ecore_imf_context_event_callback_del(__pContext, ECORE_IMF_CALLBACK_COMMIT, OnCommitTextEcoreEvent);
1456         ecore_imf_context_event_callback_del(__pContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, OnComposeTextEcoreEvent);
1457         ecore_imf_context_event_callback_del(__pContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, OnDeleteSurroundingTextEcoreEvent);
1458
1459 /*
1460         //Internal USB Check Release
1461         if (__pUSBEventHandler)
1462         {
1463                 ecore_event_handler_del(__pUSBEventHandler);
1464                 __pUSBEventHandler = null;
1465         }
1466         */
1467         return;
1468 }
1469
1470 void
1471 _InputConnectionImpl::RemoveEvasObjectEventCallback(void)
1472 {
1473         result r = _UiEventManager::GetInstance()->RemovePostKeyEventListener(*this);
1474         SysTryReturnVoidResult(NID_UI,  r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1475
1476         return;
1477 }
1478
1479 _InputConnectionImpl*
1480 _InputConnectionImpl::GetInstance(InputConnection& inputConnection)
1481 {
1482         return inputConnection.__pInputConnectionImpl;
1483 }
1484 const _InputConnectionImpl*
1485 _InputConnectionImpl::GetInstance(const InputConnection& inputConnection)
1486 {
1487         return inputConnection.__pInputConnectionImpl;
1488 }
1489
1490 int
1491 _InputConnectionImpl::CheckUSBKeyboardStatus(void)
1492 {
1493         Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
1494         Ecore_X_Atom keyboardExist = 0;
1495         unsigned int keyboardNumber = 0;
1496         int ret = 0;
1497
1498         if (!keyboardExist)
1499         {
1500                 keyboardExist = ecore_x_atom_get("X External Keyboard Exist");
1501         }
1502         ret = ecore_x_window_prop_card32_get(rootWindow, keyboardExist, &keyboardNumber, 1);
1503
1504         return keyboardNumber;
1505 }
1506
1507 result
1508 _InputConnectionImpl::FilterKeyOnUSBMode(InputPanelStyle style, const char* key, bool commit)
1509 {
1510         if(!(style == INPUT_PANEL_STYLE_NUMBER_ONLY || style == INPUT_PANEL_STYLE_PHONE_NUMBER || style == INPUT_PANEL_STYLE_IP))
1511         {
1512                 return E_INVALID_ARG;
1513         }
1514
1515         SysTryReturn(NID_UI, key, E_INVALID_ARG, E_INVALID_ARG, "key is null");
1516
1517         char TempKey[20] = {0,};
1518         const char keyOnNumOnlyStyle[10] = { 0x30/*0*/, 0x31/*1*/, 0x32/*2*/, 0x33/*3*/, 0x34/*4*/, 0x35/*5*/, 0x36/*6*/, 0x37/*7*/, 0x38/*8*/, 0x39/*9*/};
1519         const char keyOnPhoneNumStyle[13] = { 0x30/*0*/, 0x31/*1*/, 0x32/*2*/, 0x33/*3*/, 0x34/*4*/, 0x35/*5*/, 0x36/*6*/, 0x37/*7*/, 0x38/*8*/, 0x39/*9*/,
1520                                                                         0x2a/***/, 0x2b/*+*/, 0x23/*#*/};
1521         const char keyOnIPStyle[18] = { 0x30/*0*/, 0x31/*1*/, 0x32/*2*/, 0x33/*3*/, 0x34/*4*/, 0x35/*5*/, 0x36/*6*/, 0x37/*7*/, 0x38/*8*/, 0x39/*9*/,
1522                                                                         0x3a/*:*/, 0x2e/*.*/, 0x61/*a*/, 0x62/*b*/, 0x63/*c*/, 0x64/*d*/, 0x65/*e*/, 0x66/*f*/};
1523         bool isExist = false;
1524         int keyCount = 0;
1525
1526         if(style == INPUT_PANEL_STYLE_NUMBER_ONLY)
1527         {
1528                 keyCount = 10;
1529                 memcpy(TempKey, keyOnNumOnlyStyle, keyCount*sizeof(char));
1530         }
1531         else if(style == INPUT_PANEL_STYLE_PHONE_NUMBER)
1532         {
1533                 keyCount = 13;
1534                 memcpy(TempKey, keyOnPhoneNumStyle, keyCount*sizeof(char));
1535         }
1536         else if(style == INPUT_PANEL_STYLE_IP)
1537         {
1538                 keyCount = 18;
1539                 memcpy(TempKey, keyOnIPStyle, keyCount*sizeof(char));
1540         }
1541
1542         for (int i = 0; i < keyCount ; i++)
1543         {
1544                 if(TempKey[i] == key[0])
1545                 {
1546                         isExist = true;
1547                         break;
1548                 }
1549         }
1550
1551         if (isExist == true && commit == true)
1552         {
1553                 String commitText(key);
1554                 if (commitText.GetLength() > 1)
1555                 {
1556                         return E_SUCCESS;
1557                 }
1558                 InputConnection* pInputConnection = GetInputConnection();
1559                 IInputConnectionEventListener* pListener = GetInputConnectionListener();
1560                 IInputConnectionEventListenerF* pListenerF = GetInputConnectionListenerF();
1561                 if (pListener)
1562                 {
1563                         pListener->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1564                 }
1565                 if (pListenerF)
1566                 {
1567                         pListenerF->OnInputConnectionTextCommitted( *pInputConnection, commitText);
1568                 }
1569         }
1570
1571         return E_SUCCESS;
1572 }
1573
1574 void
1575 _InputConnectionImpl::SetKeyEventSkipped(bool enabled)
1576 {
1577         __IsKeyEventSkipped = enabled;
1578 }
1579
1580 }} // Tizen::Ui