Support legacy way to create InputMethodContext
[platform/core/uifw/dali-csharp-binder.git] / dali-csharp-binder / src / key-grab.cpp
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 #include "common.h"
18
19 #include <dali/dali.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/adaptor-framework/key-grab.h>
24 #include <dali/public-api/adaptor-framework/window.h>
25
26 #include <stdexcept>
27 #include <exception>
28
29
30 #ifdef TIZEN_BUILD
31 #ifdef ECORE_WL2
32 #include <Ecore_Wl2.h>
33 #else
34 #include <Ecore_Wayland.h>
35 #endif
36 #endif
37
38 #undef LOG
39 //#define LOG DALI_LOG_ERROR
40 #define LOG(a...)
41
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_GrabKeyTopmost(void * window, int daliKey)
48 {
49   Dali::Window *_win = (Dali::Window *)window;
50   bool ret;
51
52   LOG("CSharp_Dali_GrabKeyTopmost() [DP1] window=%d, dalikey=%d", window, daliKey);
53
54   {
55     try {
56       ret = Dali::KeyGrab::GrabKeyTopmost(*_win, (Dali::KEY)daliKey);
57     } catch (std::out_of_range& e) {
58     {
59       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return false;
60     };
61     } catch (std::exception& e) {
62     {
63       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return false;
64     };
65     } catch (Dali::DaliException e) {
66       {
67         SWIG_CSharpException(SWIG_UnknownError, e.condition); return 0;
68       };
69     } catch (...) {
70       {
71         SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
72       };
73     }
74   }
75
76
77   LOG("CSharp_Dali_GrabKeyTopmost() [DP2] ret=%d", ret);
78
79   return ret;
80 }
81
82 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_UngrabKeyTopmost(void * window, int daliKey)
83 {
84   Dali::Window *_win = (Dali::Window *)window;
85   bool ret;
86
87   LOG("CSharp_Dali_UngrabKeyTopmost() [DP1] window=%d, dalikey=%d", window, daliKey);
88
89   {
90     try {
91       ret = Dali::KeyGrab::UngrabKeyTopmost(*_win, (Dali::KEY)daliKey);
92     } catch (std::out_of_range& e) {
93     {
94       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return false;
95     };
96     } catch (std::exception& e) {
97     {
98       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return false;
99     };
100     } catch (Dali::DaliException e) {
101       {
102         SWIG_CSharpException(SWIG_UnknownError, e.condition); return 0;
103       };
104     } catch (...) {
105       {
106         SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
107       };
108     }
109   }
110
111
112   LOG("CSharp_Dali_UngrabKeyTopmost() [DP2] ret=%d", ret);
113
114   return ret;
115 }
116
117 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_GrabKey(void * window, int daliKey, int grabMode)
118 {
119   Dali::Window *_win = (Dali::Window *)window;
120   bool ret;
121
122   LOG("CSharp_Dali_GrabKey() [DP1] window=%d, dalikey=%d, grabmode=%d", window, daliKey, grabMode);
123
124   {
125     try {
126       ret = Dali::KeyGrab::GrabKey(*_win, (Dali::KEY)daliKey, (Dali::KeyGrab::KeyGrabMode)grabMode);
127     } catch (std::out_of_range& e) {
128     {
129       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return false;
130     };
131     } catch (std::exception& e) {
132     {
133       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return false;
134     };
135     } catch (Dali::DaliException e) {
136       {
137         SWIG_CSharpException(SWIG_UnknownError, e.condition); return 0;
138       };
139     } catch (...) {
140       {
141         SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
142       };
143     }
144   }
145
146
147   DALI_LOG_ERROR("CSharp_Dali_GrabKey() [DP2] ret=%d", ret);
148
149   return ret;
150 }
151
152 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_UngrabKey(void * window, int daliKey)
153 {
154   Dali::Window *_win = (Dali::Window *)window;
155   bool ret;
156
157   LOG("CSharp_Dali_UngrabKey() [DP1] window=%d, dalikey=%d", window, daliKey);
158
159   {
160     try {
161       ret = Dali::KeyGrab::UngrabKey(*_win, (Dali::KEY)daliKey);
162     } catch (std::out_of_range& e) {
163     {
164       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return false;
165     };
166     } catch (std::exception& e) {
167     {
168       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return false;
169     };
170     } catch (Dali::DaliException e) {
171       {
172         SWIG_CSharpException(SWIG_UnknownError, e.condition); return 0;
173       };
174     } catch (...) {
175       {
176         SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
177       };
178     }
179   }
180
181
182   LOG("CSharp_Dali_UngrabKey() [DP2] ret=%d", ret);
183
184   return ret;
185 }
186
187 SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_GetNativeWindowHandler( void* window )
188 {
189   Dali::Window *_win = (Dali::Window *)window;
190   void * ret = NULL;
191
192   LOG("CSharp_Dali_GetNativeWindowHandler() [DP1] window=%d", window);
193
194   {
195     Dali::Any result;
196     try {
197       result = _win->GetNativeHandle();
198 #ifdef TIZEN_BUILD
199 #ifdef ECORE_WL2
200       Ecore_Wl2_Window * ecore_win = Dali::AnyCast<Ecore_Wl2_Window*>(result);
201 #else
202       Ecore_Wl_Window * ecore_win = Dali::AnyCast<Ecore_Wl_Window*>(result);
203 #endif
204 #endif
205       ret = (void*)ecore_win;
206
207     } catch (std::out_of_range& e) {
208     {
209       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return NULL;
210     };
211     } catch (std::exception& e) {
212     {
213       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return NULL;
214     };
215     } catch (...) {
216     {
217       SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return NULL;
218     };
219     }
220   }
221
222   if(ret != NULL)
223   {
224     LOG("CSharp_Dali_GetNativeWindowHandler() [DP2] ret=%d", ret);
225   }
226
227   return ret;
228 }
229
230
231 #ifdef __cplusplus
232 }
233 #endif
234