Ported downstream changes into devel/master
[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 #include <Ecore_Wayland.h>
32 #endif
33
34 #undef LOG
35 //#define LOG DALI_LOG_ERROR
36 #define LOG(a...)
37
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_GrabKeyTopmost(void * window, int daliKey)
44 {
45   Dali::Window *_win = (Dali::Window *)window;
46   bool ret;
47
48   LOG("CSharp_Dali_GrabKeyTopmost() [DP1] window=%d, dalikey=%d", window, daliKey);
49
50   {
51     try {
52       ret = Dali::KeyGrab::GrabKeyTopmost(*_win, (Dali::KEY)daliKey);
53     } catch (std::out_of_range& e) {
54     {
55       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return false;
56     };
57     } catch (std::exception& e) {
58     {
59       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return false;
60     };
61     } catch (Dali::DaliException e) {
62       {
63         SWIG_CSharpException(SWIG_UnknownError, e.condition); return 0;
64       };
65     } catch (...) {
66       {
67         SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
68       };
69     }
70   }
71
72
73   LOG("CSharp_Dali_GrabKeyTopmost() [DP2] ret=%d", ret);
74
75   return ret;
76 }
77
78 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_UngrabKeyTopmost(void * window, int daliKey)
79 {
80   Dali::Window *_win = (Dali::Window *)window;
81   bool ret;
82
83   LOG("CSharp_Dali_UngrabKeyTopmost() [DP1] window=%d, dalikey=%d", window, daliKey);
84
85   {
86     try {
87       ret = Dali::KeyGrab::UngrabKeyTopmost(*_win, (Dali::KEY)daliKey);
88     } catch (std::out_of_range& e) {
89     {
90       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return false;
91     };
92     } catch (std::exception& e) {
93     {
94       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return false;
95     };
96     } catch (Dali::DaliException e) {
97       {
98         SWIG_CSharpException(SWIG_UnknownError, e.condition); return 0;
99       };
100     } catch (...) {
101       {
102         SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
103       };
104     }
105   }
106
107
108   LOG("CSharp_Dali_UngrabKeyTopmost() [DP2] ret=%d", ret);
109
110   return ret;
111 }
112
113 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_GrabKey(void * window, int daliKey, int grabMode)
114 {
115   Dali::Window *_win = (Dali::Window *)window;
116   bool ret;
117
118   LOG("CSharp_Dali_GrabKey() [DP1] window=%d, dalikey=%d, grabmode=%d", window, daliKey, grabMode);
119
120   {
121     try {
122       ret = Dali::KeyGrab::GrabKey(*_win, (Dali::KEY)daliKey, (Dali::KeyGrab::KeyGrabMode)grabMode);
123     } catch (std::out_of_range& e) {
124     {
125       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return false;
126     };
127     } catch (std::exception& e) {
128     {
129       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return false;
130     };
131     } catch (Dali::DaliException e) {
132       {
133         SWIG_CSharpException(SWIG_UnknownError, e.condition); return 0;
134       };
135     } catch (...) {
136       {
137         SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
138       };
139     }
140   }
141
142
143   DALI_LOG_ERROR("CSharp_Dali_GrabKey() [DP2] ret=%d", ret);
144
145   return ret;
146 }
147
148 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_UngrabKey(void * window, int daliKey)
149 {
150   Dali::Window *_win = (Dali::Window *)window;
151   bool ret;
152
153   LOG("CSharp_Dali_UngrabKey() [DP1] window=%d, dalikey=%d", window, daliKey);
154
155   {
156     try {
157       ret = Dali::KeyGrab::UngrabKey(*_win, (Dali::KEY)daliKey);
158     } catch (std::out_of_range& e) {
159     {
160       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return false;
161     };
162     } catch (std::exception& e) {
163     {
164       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return false;
165     };
166     } catch (Dali::DaliException e) {
167       {
168         SWIG_CSharpException(SWIG_UnknownError, e.condition); return 0;
169       };
170     } catch (...) {
171       {
172         SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0;
173       };
174     }
175   }
176
177
178   LOG("CSharp_Dali_UngrabKey() [DP2] ret=%d", ret);
179
180   return ret;
181 }
182
183 SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_GetNativeWindowHandler( void* window )
184 {
185   Dali::Window *_win = (Dali::Window *)window;
186   void * ret = NULL;
187
188   LOG("CSharp_Dali_GetNativeWindowHandler() [DP1] window=%d", window);
189
190   {
191     Dali::Any result;
192     try {
193       result = _win->GetNativeHandle();
194
195       Ecore_Wl_Window * ecore_win = Dali::AnyCast<Ecore_Wl_Window*>(result);
196       ret = (void*)ecore_win;
197
198     } catch (std::out_of_range& e) {
199     {
200       SWIG_CSharpException(SWIG_IndexError, const_cast<char*>(e.what())); return NULL;
201     };
202     } catch (std::exception& e) {
203     {
204       SWIG_CSharpException(SWIG_RuntimeError, const_cast<char*>(e.what())); return NULL;
205     };
206     } catch (...) {
207     {
208       SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return NULL;
209     };
210     }
211   }
212
213   if(ret != NULL)
214   {
215     LOG("CSharp_Dali_GetNativeWindowHandler() [DP2] ret=%d", ret);
216   }
217
218   return ret;
219 }
220
221
222 #ifdef __cplusplus
223 }
224 #endif
225