Merge "DALi Version 1.2.40" into devel/master
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / stage-event.i
1 /*
2  * Copyright (c) 2016 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 %define STAGE_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22
23 %}
24 %enddef
25
26 %define STAGE_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
27 %typemap(cscode) NameSpace::ClassName %{
28
29
30   /**
31     * @brief Event arguments that passed via Touch signal
32     *
33     */
34   public class TouchEventArgs : EventArgs
35   {
36      private Touch _touch;
37
38      /**
39        * @brief Touch - contains the information of touch points
40        *
41        */
42      public Touch Touch
43      {
44         get
45         {
46            return _touch;
47         }
48         set
49         {
50            _touch = value;
51         }
52      }
53   }
54
55   private event EventHandler<TouchEventArgs> _stageTouchHandler;
56   private EventCallbackDelegateType1<IntPtr> _stageTouchCallbackDelegate;
57
58   /**
59     * @brief Event for TouchEvent signal which can be used to subscribe/unsubscribe the event handler
60     * TouchEvent signal is emitted when the screen is touched and when the touch ends
61     * (i.e. the down & up touch events only).
62     *
63     */
64   public event EventHandler<TouchEventArgs> Touch
65   {
66      add
67      {
68         lock(this)
69         {
70           _stageTouchHandler += value;
71           _stageTouchCallbackDelegate = OnStageTouch;
72           this.TouchSignal().Connect(_stageTouchCallbackDelegate);
73         }
74      }
75      remove
76      {
77         lock(this)
78         {
79            if (_stageTouchHandler != null)
80            {
81               this.TouchSignal().Disconnect(_stageTouchCallbackDelegate);
82            }
83            _stageTouchHandler -= value;
84         }
85      }
86   }
87
88   private void OnStageTouch(IntPtr data)
89   {
90     TouchEventArgs e = new TouchEventArgs();
91
92     if( data != null )
93     {
94       e.Touch = Dali.Touch.GetTouchFromPtr( data );
95     }
96
97     if (_stageTouchHandler != null)
98     {
99       _stageTouchHandler(this, e);
100     }
101   }
102
103   /**
104     * @brief Wheel arguments that passed via Wheel signal
105     *
106     */
107   public class WheelEventArgs : EventArgs
108   {
109      private Wheel _wheel;
110
111      /**
112        * @brief Wheel - store a wheel rolling type MOUSE_WHEEL or CUSTOM_WHEEL
113        *
114        */
115      public Wheel Wheel
116      {
117         get
118         {
119            return _wheel;
120         }
121         set
122         {
123            _wheel = value;
124         }
125      }
126   }
127
128   private event EventHandler<WheelEventArgs> _stageWheelHandler;
129   private EventCallbackDelegateType1<IntPtr> _stageWheelCallbackDelegate;
130
131   /**
132     * @brief Event for Wheel signal which can be used to subscribe/unsubscribe the event handler
133     * Wheel signal is emitted is emitted when wheel event is received.
134     *
135     */
136   public event EventHandler<WheelEventArgs> Wheel
137   {
138      add
139      {
140         lock(this)
141         {
142           _stageWheelHandler += value;
143           _stageWheelCallbackDelegate = OnStageWheel;
144           this.WheelEventSignal().Connect(_stageWheelCallbackDelegate);
145         }
146      }
147      remove
148      {
149         lock(this)
150         {
151            if (_stageWheelHandler != null)
152            {
153               this.WheelEventSignal().Disconnect(_stageWheelCallbackDelegate);
154            }
155            _stageWheelHandler -= value;
156         }
157      }
158   }
159
160   private void OnStageWheel(IntPtr data)
161   {
162     WheelEventArgs e = new WheelEventArgs();
163
164     if( data != null )
165     {
166       e.Wheel = Dali.Wheel.GetWheelFromPtr( data );
167     }
168
169     if (_stageWheelHandler != null)
170     {
171       _stageWheelHandler(this, e);
172     }
173   }
174
175   /**
176     * @brief Event arguments that passed via Key signal
177     *
178     */
179   public class KeyEventArgs : EventArgs
180   {
181      private Key _key;
182
183      /**
184        * @brief Key - is the keyevent sent to Stage.
185        *
186        */
187      public Key Key
188      {
189         get
190         {
191            return _key;
192         }
193         set
194         {
195            _key = value;
196         }
197      }
198   }
199
200   private event EventHandler<KeyEventArgs> _stageKeyHandler;
201   private EventCallbackDelegateType1<IntPtr> _stageKeyCallbackDelegate;
202
203   /**
204     * @brief Event for Key signal which can be used to subscribe/unsubscribe the event handler
205     * Key signal is emitted is emitted when key event is received.
206     *
207     */
208   public event EventHandler<KeyEventArgs> Key
209   {
210      add
211      {
212         lock(this)
213         {
214             _stageKeyHandler += value;
215             _stageKeyCallbackDelegate = OnStageKey;
216             this.KeyEventSignal().Connect(_stageKeyCallbackDelegate);
217         }
218      }
219      remove
220      {
221         lock(this)
222         {
223            if (_stageKeyHandler != null)
224            {
225               this.KeyEventSignal().Disconnect(_stageKeyCallbackDelegate);
226            }
227            _stageKeyHandler -= value;
228         }
229      }
230   }
231
232   // Callback for Stage KeyEventsignal
233   private void OnStageKey(IntPtr data)
234   {
235     KeyEventArgs e = new KeyEventArgs();
236
237     if( data != null )
238     {
239       e.Key = Dali.Key.GetKeyFromPtr( data );
240     }
241
242     if (_stageKeyHandler != null)
243     {
244       //here we send all data to user event handlers
245       _stageKeyHandler(this, e);
246     }
247   }
248
249
250   private event EventHandler _stageEventProcessingFinishedEventHandler;
251   private EventCallbackDelegateType0 _stageEventProcessingFinishedEventCallbackDelegate;
252
253   /**
254     * @brief Event for EventProcessingFinished signal which can be used to subscribe/unsubscribe the event handler
255     * provided by the user. EventProcessingFinished signal is emitted just after the event processing is finished.
256     *
257     */
258   public event EventHandler EventProcessingFinished
259   {
260      add
261      {
262         lock(this)
263         {
264           _stageEventProcessingFinishedEventHandler += value;
265           _stageEventProcessingFinishedEventCallbackDelegate = OnEventProcessingFinished;
266           this.EventProcessingFinishedSignal().Connect(_stageEventProcessingFinishedEventCallbackDelegate);
267         }
268      }
269      remove
270      {
271         lock(this)
272         {
273            if (_stageEventProcessingFinishedEventHandler != null)
274            {
275               this.EventProcessingFinishedSignal().Disconnect(_stageEventProcessingFinishedEventCallbackDelegate);
276            }
277            _stageEventProcessingFinishedEventHandler -= value;
278         }
279      }
280   }
281
282   // Callback for Stage EventProcessingFinishedSignal
283   private void OnEventProcessingFinished()
284   {
285      if (_stageEventProcessingFinishedEventHandler != null)
286      {
287         _stageEventProcessingFinishedEventHandler(this, null);
288      }
289   }
290
291
292   private EventHandler _stageContextLostEventHandler;
293   private EventCallbackDelegateType0 _stageContextLostEventCallbackDelegate;
294
295   /**
296     * @brief Event for ContextLost signal which can be used to subscribe/unsubscribe the event handler
297     * ContextLost signal is emitted when the GL context is lost (Platform specific behaviour).
298     *
299     */
300   public event EventHandler ContextLost
301   {
302      add
303      {
304         lock(this)
305         {
306             _stageContextLostEventHandler += value;
307             _stageContextLostEventCallbackDelegate = OnContextLost;
308             this.ContextLostSignal().Connect(_stageContextLostEventCallbackDelegate);
309         }
310      }
311      remove
312      {
313         lock(this)
314         {
315            if (_stageContextLostEventHandler != null)
316            {
317               this.ContextLostSignal().Disconnect(_stageContextLostEventCallbackDelegate);
318            }
319
320            _stageContextLostEventHandler -= value;
321         }
322      }
323   }
324
325   // Callback for Stage ContextLostSignal
326   private void OnContextLost()
327   {
328      if (_stageContextLostEventHandler != null)
329      {
330         _stageContextLostEventHandler(this, null);
331      }
332   }
333
334
335   private EventHandler _stageContextRegainedEventHandler;
336   private EventCallbackDelegateType0 _stageContextRegainedEventCallbackDelegate;
337
338   /**
339     * @brief Event for ContextRegained signal which can be used to subscribe/unsubscribe the event handler
340     * provided by the user. ContextRegained signal is emitted when the GL context is regained (Platform specific
341     * behaviour).
342     *
343     */
344   public event EventHandler ContextRegained
345   {
346      add
347      {
348         lock(this)
349         {
350             _stageContextRegainedEventHandler += value;
351             _stageContextRegainedEventCallbackDelegate = OnContextRegained;
352             this.ContextRegainedSignal().Connect(_stageContextRegainedEventCallbackDelegate);
353         }
354      }
355      remove
356      {
357         lock(this)
358         {
359            if (_stageContextRegainedEventHandler != null)
360            {
361               this.ContextRegainedSignal().Disconnect(_stageContextRegainedEventCallbackDelegate);
362            }
363
364            _stageContextRegainedEventHandler -= value;
365         }
366      }
367   }
368
369   // Callback for Stage ContextRegainedSignal
370   private void OnContextRegained()
371   {
372      if (_stageContextRegainedEventHandler != null)
373      {
374         _stageContextRegainedEventHandler(this, null);
375      }
376   }
377
378
379   private EventHandler _stageSceneCreatedEventHandler;
380   private EventCallbackDelegateType0 _stageSceneCreatedEventCallbackDelegate;
381
382   /**
383     * @brief Event for SceneCreated signal which can be used to subscribe/unsubscribe the event handler
384     * SceneCreated signal is emitted after the initial scene is created.
385     *
386     */
387   public event EventHandler SceneCreated
388   {
389      add
390      {
391         lock(this)
392         {
393             _stageSceneCreatedEventHandler += value;
394             _stageSceneCreatedEventCallbackDelegate = OnSceneCreated;
395             this.SceneCreatedSignal().Connect(_stageSceneCreatedEventCallbackDelegate);
396         }
397      }
398      remove
399      {
400         lock(this)
401         {
402            if (_stageSceneCreatedEventHandler != null)
403            {
404               this.SceneCreatedSignal().Disconnect(_stageSceneCreatedEventCallbackDelegate);
405            }
406
407            _stageSceneCreatedEventHandler -= value;
408         }
409      }
410   }
411
412   // Callback for Stage SceneCreatedSignal
413   private void OnSceneCreated()
414   {
415      if (_stageSceneCreatedEventHandler != null)
416      {
417         _stageSceneCreatedEventHandler(this, null);
418      }
419   }
420
421
422   public Vector2 Size
423   {
424      get
425      {
426         Vector2 ret = GetSize();
427         return ret;
428      }
429   }
430
431   public Vector4 BackgroundColor
432   {
433      set
434      {
435         SetBackgroundColor(value);
436      }
437      get
438      {
439         Vector4 ret = GetBackgroundColor();
440         return ret;
441      }
442    }
443
444   private static readonly Stage instance = Stage.GetCurrent();
445
446   public static Stage Instance
447   {
448       get
449       {
450           return instance;
451       }
452   }
453
454   public Layer GetDefaultLayer()
455   {
456     return this.GetRootLayer();
457   }
458
459   public void AddLayer(Layer layer)
460   {
461     this.Add( (Actor)layer );
462   }
463
464   public void RemoveLayer(Layer layer)
465   {
466     this.Remove( (Actor)layer );
467   }
468
469
470 %}
471
472 %enddef
473
474
475 %define DALI_STAGE_EVENTHANDLER_PARAM( NameSpace, ClassName)
476
477   STAGE_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
478   STAGE_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
479
480 %enddef
481
482 namespace Dali
483 {
484   DALI_STAGE_EVENTHANDLER_PARAM( Dali, Stage);
485 }