merge with master
[framework/osp/ime.git] / src / FUiImeInputMethod.cpp
1 //\r
2 // Open Service Platform\r
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.\r
4 //\r
5 // Licensed under the Apache License, Version 2.0 (the License);\r
6 // you may not use this file except in compliance with the License.\r
7 // You may obtain a copy of the License at\r
8 //\r
9 //     http://www.apache.org/licenses/LICENSE-2.0\r
10 //\r
11 // Unless required by applicable law or agreed to in writing, software\r
12 // distributed under the License is distributed on an "AS IS" BASIS,\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 // See the License for the specific language governing permissions and\r
15 // limitations under the License.\r
16 //\r
17 \r
18 /**\r
19  * @file        FUiImeInputMethod.cpp\r
20  * @brief       This is the implementation file for the %InputMethod class.\r
21  *\r
22  * This implementation file contains definition of the %InputMethod class.\r
23  */\r
24 \r
25 #include <new>\r
26 \r
27 #include <FBaseSysLog.h>\r
28 #include <FUiImeInputMethod.h>\r
29 \r
30 #include <FSec_AccessController.h>\r
31 #include "FUiIme_InputMethodImpl.h"\r
32 \r
33 using namespace Tizen::Base;\r
34 using namespace Tizen::Security;\r
35 using namespace Tizen::Ui;\r
36 \r
37 namespace Tizen { namespace Ui { namespace Ime {\r
38 \r
39 static InputMethod* __pInputMethod = null;\r
40 \r
41 InputMethod::InputMethod(void)\r
42         :__pInputMethodImpl(null)\r
43 {\r
44 }\r
45 \r
46 InputMethod::~InputMethod(void)\r
47 {\r
48         __pInputMethod = null;\r
49         __pInputMethodImpl = null;\r
50 }\r
51 \r
52 result\r
53 InputMethod::Construct(void)\r
54 {\r
55         result r = E_SUCCESS;\r
56 \r
57         __pInputMethodImpl = new(std::nothrow) _InputMethodImpl();\r
58         SysTryReturnResult(NID_UI_IME, __pInputMethodImpl, E_OUT_OF_MEMORY, "Memory allocation failed.");\r
59 \r
60         r = __pInputMethodImpl->Construct();\r
61         SysTryCatch(NID_UI_IME, r == E_SUCCESS, , r, "Propagating.");\r
62 \r
63         return r;\r
64 \r
65 CATCH:\r
66         delete __pInputMethodImpl;\r
67         __pInputMethodImpl = null;\r
68 \r
69         return r;\r
70 }\r
71 \r
72 InputMethod*\r
73 InputMethod::GetInstance(void)\r
74 {\r
75         result r = E_SUCCESS;\r
76 \r
77         r = _AccessController::CheckUserPrivilege(_PRV_IME);\r
78         SysTryReturn(NID_UI_IME, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");\r
79 \r
80         if (__pInputMethod == null)\r
81         {\r
82                 __pInputMethod = new(std::nothrow) InputMethod();\r
83                 SysTryReturn(NID_UI_IME, __pInputMethod, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");\r
84 \r
85                 r = __pInputMethod->Construct();\r
86                 r = ((r == E_SUCCESS) || (r == E_CONNECTION_FAILED) || (r == E_SYSTEM)) ? r : E_SYSTEM;\r
87                 SysTryCatch(NID_UI_IME, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));\r
88         }\r
89 \r
90         return __pInputMethod;\r
91 \r
92 CATCH:\r
93         delete __pInputMethod;\r
94         __pInputMethod = null;\r
95 \r
96         return null;\r
97 }\r
98 \r
99 void\r
100 InputMethod::SetInputMethodProvider(IInputMethodProvider* pProvider)\r
101 {\r
102         __pInputMethodImpl->SetInputMethodProvider(pProvider);\r
103 }\r
104 \r
105 void\r
106 InputMethod::SetInputMethodListener(IInputMethodListener* pListener)\r
107 {\r
108         __pInputMethodImpl->SetInputMethodListener(pListener);\r
109 }\r
110 \r
111 result\r
112 InputMethod::DeleteText(int cursorOffset, int length)\r
113 {\r
114         return __pInputMethodImpl->DeleteText(cursorOffset, length);\r
115 }\r
116 \r
117 result\r
118 InputMethod::NotifyInputPanelState(InputPanelShowState state)\r
119 {\r
120         return __pInputMethodImpl->NotifyInputPanelState(state);\r
121 }\r
122 \r
123 result\r
124 InputMethod::NotifyLanguageChanged(void)\r
125 {\r
126         return __pInputMethodImpl->NotifyLanguageChanged();\r
127 }\r
128 \r
129 result\r
130 InputMethod::RequestSurroundingText(int lengthBeforeCursor, int lengthAfterCursor)\r
131 {\r
132         return __pInputMethodImpl->RequestSurroundingText(lengthBeforeCursor, lengthAfterCursor);\r
133 }\r
134 \r
135 result\r
136 InputMethod::SendCompositeText(const String& text)\r
137 {\r
138         return __pInputMethodImpl->SendCompositeText(text);\r
139 }\r
140 \r
141 result\r
142 InputMethod::SendKeyEvent(KeyCode code, KeyState state)\r
143 {\r
144         return __pInputMethodImpl->SendKeyEvent(code, state);\r
145 }\r
146 \r
147 result\r
148 InputMethod::SendText(const String& text)\r
149 {\r
150         return __pInputMethodImpl->SendText(text);\r
151 }\r
152 \r
153 }}} // Tizen::Ui::Ime\r