[4.0] Add DALI_KEY_DELETE to get Delete key event
[platform/core/uifw/dali-adaptor.git] / adaptors / common / widget-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "widget-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <system_info.h>
23 #include <string.h>
24
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/math/vector2.h>
27
28 // INTERNAL INCLUDES
29 #include <adaptor.h>
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35
36 namespace Adaptor
37 {
38
39 namespace
40 {
41
42 static bool IsWidgetFeatureEnabled()
43 {
44   static bool feature = false;
45   static bool retrieved = false;
46   int ret;
47
48   if(retrieved == true)
49     return feature;
50
51   ret = system_info_get_platform_bool("http://tizen.org/feature/shell.appwidget", &feature);
52   if(ret != SYSTEM_INFO_ERROR_NONE)
53   {
54     DALI_LOG_ERROR("failed to get system info\n"); /* LCOV_EXCL_LINE */
55     return false; /* LCOV_EXCL_LINE */
56   }
57
58   retrieved = true;
59
60   return feature;
61 }
62
63 } // anonymous namespace
64
65 Dali::Widget Widget::New( const std::string& id )
66 {
67   if(!IsWidgetFeatureEnabled())
68   {
69     DALI_LOG_ERROR("not supported");
70     Dali::Widget handle(NULL);
71     return handle;
72   }
73
74   if( id.size() < 1 )
75   {
76     DALI_LOG_ERROR("class id is NULL");
77     Dali::Widget handle(NULL);
78     return handle;
79   }
80
81   WidgetPtr widget ( new Widget( id ) );
82   Dali::Widget handle( widget.Get() );
83   return handle;
84 }
85
86 static int OnInit(widget_base_instance_h instance_h, bundle *content, int w, int h, void *classData)
87 {
88   char *id;
89   widget_base_context_get_id(instance_h, &id);
90   widget_base_class_on_create(instance_h, content, w, h);
91
92   Dali::Window window = Dali::Adaptor::Get().GetWindow();
93   Any nativeHandle = window.GetNativeHandle();
94   Ecore_Wl_Window * wlWindow = AnyCast<Ecore_Wl_Window*>( nativeHandle );
95   widget_base_context_window_bind( instance_h, id, wlWindow);
96   window.SetSize( Dali::Window::WindowSize( w, h ) );
97
98   Internal::Adaptor::Widget* widget = static_cast< Internal::Adaptor::Widget* >( classData );
99   widget->mCreateSignal.Emit( std::string(id), content, window );
100
101   return 0;
102 }
103
104 static int OnDestroy(widget_base_instance_h instance_h, widget_base_destroy_type_e reason, bundle *content, void *classData)
105 {
106   char *id;
107   widget_base_context_get_id(instance_h, &id);
108
109   Dali::Widget::WidgetTerminateType destroyReason = Dali::Widget::WidgetTerminateType::TEMPORARY;
110
111   if(reason == WIDGET_BASE_DESTROY_TYPE_PERMANENT)
112   {
113     destroyReason = Dali::Widget::WidgetTerminateType::PERMANENT;
114   }
115
116   Internal::Adaptor::Widget* widget = static_cast< Internal::Adaptor::Widget* >( classData );
117   widget->mTerminateSignal.Emit(std::string(id), content, destroyReason );
118
119   widget_base_class_on_destroy(instance_h, reason, content);
120
121   return 0;
122 }
123
124 static int OnPause(widget_base_instance_h instance_h, void *classData)
125 {
126   char *id;
127   widget_base_context_get_id(instance_h, &id);
128
129   widget_base_class_on_pause(instance_h);
130
131   Internal::Adaptor::Widget* widget = static_cast< Internal::Adaptor::Widget* >( classData );
132   widget->mPauseSignal.Emit(id);
133
134   return 0;
135 }
136
137 static int OnResume(widget_base_instance_h instance_h, void *classData)
138 {
139   char *id;
140   widget_base_context_get_id(instance_h, &id);
141
142   widget_base_class_on_resume(instance_h);
143
144   Internal::Adaptor::Widget* widget = static_cast< Internal::Adaptor::Widget* >( classData );
145   widget->mResumeSignal.Emit(id);
146
147   return 0;
148 }
149
150 static int OnResize(widget_base_instance_h instance_h, int w, int h, void *classData)
151 {
152   char *id;
153   widget_base_context_get_id(instance_h, &id);
154
155   widget_base_class_on_resize(instance_h, w, h);
156
157   Internal::Adaptor::Widget* widget = static_cast< Internal::Adaptor::Widget* >( classData );
158   Dali::Window window = Dali::Adaptor::Get().GetWindow();
159   window.SetSize( Dali::Window::WindowSize(w, h) );
160   widget->mResizeSignal.Emit(id, window);
161
162   return 0;
163 }
164
165 static int OnUpdate(widget_base_instance_h instance_h, bundle *content, int force, void *classData)
166 {
167   char *id;
168   widget_base_context_get_id(instance_h, &id);
169
170   widget_base_class_on_update(instance_h, content, force);
171
172   Internal::Adaptor::Widget* widget = static_cast< Internal::Adaptor::Widget* >( classData );
173   widget->mUpdateSignal.Emit(id, content, force);
174
175   return 0;
176 }
177
178 Widget::Widget( const std::string& id )
179 : mCreateSignal(),
180   mTerminateSignal(),
181   mPauseSignal(),
182   mResumeSignal(),
183   mResizeSignal(),
184   mUpdateSignal(),
185   mClassId(id),
186   mSlotDelegate(this)
187 {
188   widget_base_class cls = widget_base_class_get_default();
189   cls.ops.create = OnInit;
190   cls.ops.destroy = OnDestroy;
191   cls.ops.pause = OnPause;
192   cls.ops.resume = OnResume;
193   cls.ops.resize = OnResize;
194   cls.ops.update = OnUpdate;
195
196   widget_base_class_add(cls, mClassId.c_str(), this);
197 }
198
199 Widget::~Widget()
200 {
201 }
202
203 } // Adaptor
204
205 } // Internal
206
207 } // Dali