DALi Version 1.2.9
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / animation-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 Animation_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 Animation_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
27   %typemap(cscode) NameSpace::ClassName %{
28
29
30     /**
31       * @brief Event arguments that passed via Finished signal
32       *
33       */
34     public class FinishedEventArgs : EventArgs
35     {
36       private Animation _animation;
37
38       /**
39         * @brief Animation - is the Animation which has finished with the animation.
40         *
41         */
42       public Animation Animation
43       {
44         get
45         {
46           return _animation;
47         }
48         set
49         {
50           _animation = value;
51         }
52       }
53     }
54
55     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
56     public delegate void FinishedEventHandler(object source, FinishedEventArgs e);
57
58     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
59     private delegate void FinishedEventCallbackDelegate(IntPtr Animation);
60     private FinishedEventHandler _animationFinishedEventHandler;
61     private FinishedEventCallbackDelegate _animationFinishedEventCallbackDelegate;
62
63     /**
64       * @brief Event for Finished signal which can be used to subscribe/unsubscribe the event handler
65       * (in the type of FinishedEventHandler) provided by the user.
66       * Finished signal is emitted when an Animation's animations have finished.
67       */
68     public event FinishedEventHandler Finished
69     {
70       add
71       {
72         lock(this)
73         {
74           // Restricted to only one listener
75           if (_animationFinishedEventHandler == null)
76           {
77             _animationFinishedEventHandler += value;
78
79             _animationFinishedEventCallbackDelegate = new FinishedEventCallbackDelegate(OnFinished);
80             this.FinishedSignal().Connect(_animationFinishedEventCallbackDelegate);
81           }
82         }
83       }
84
85       remove
86       {
87         lock(this)
88         {
89           if (_animationFinishedEventHandler != null)
90           {
91             this.FinishedSignal().Disconnect(_animationFinishedEventCallbackDelegate);
92           }
93
94           _animationFinishedEventHandler -= value;
95         }
96       }
97     }
98
99     // Callback for Animation FinishedSignal
100     private void OnFinished(IntPtr data)
101     {
102       FinishedEventArgs e = new FinishedEventArgs();
103
104       // Populate all members of "e" (FinishedEventArgs) with real data
105       e.Animation = Animation.GetAnimationFromPtr(data);
106
107       if (_animationFinishedEventHandler != null)
108       {
109         //here we send all data to user event handlers
110         _animationFinishedEventHandler(this, e);
111       }
112     }
113
114
115     public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
116       ClassName ret = new ClassName(cPtr, false);
117       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
118       return ret;
119     }
120
121     %}
122
123     %enddef
124
125
126 %define DALI_animation_EVENTHANDLER_PARAM( NameSpace, ClassName)
127   Animation_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
128   Animation_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
129   %enddef
130
131   namespace Dali
132 {
133   DALI_animation_EVENTHANDLER_PARAM( Dali, Animation);
134 }