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