Merge "DALi C# binding - Generic Delegates support for EventHandlers" into devel...
[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       * @brief Event arguments that passed via Finished signal
31       *
32       */
33     public class FinishedEventArgs : EventArgs
34     {
35       private Animation _animation;
36
37       /**
38         * @brief Animation - is the Animation which has finished with the animation.
39         *
40         */
41       public Animation Animation
42       {
43         get
44         {
45           return _animation;
46         }
47         set
48         {
49           _animation = value;
50         }
51       }
52     }
53
54     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
55     private delegate void FinishedEventCallbackDelegate(IntPtr Animation);
56     private DaliEventHandler<object,FinishedEventArgs> _animationFinishedEventHandler;
57     private FinishedEventCallbackDelegate _animationFinishedEventCallbackDelegate;
58
59     /**
60       * @brief Event for Finished signal which can be used to subscribe/unsubscribe the event handler
61       * (in the type of FinishedEventHandler - DaliEventHandler<object,FinishedEventArgs>) provided by the user.
62       * Finished signal is emitted when an Animation's animations have finished.
63       */
64     public event DaliEventHandler<object,FinishedEventArgs> Finished
65     {
66       add
67       {
68         lock(this)
69         {
70           // Restricted to only one listener
71           if (_animationFinishedEventHandler == null)
72           {
73             _animationFinishedEventHandler += value;
74
75             _animationFinishedEventCallbackDelegate = new FinishedEventCallbackDelegate(OnFinished);
76             this.FinishedSignal().Connect(_animationFinishedEventCallbackDelegate);
77           }
78         }
79       }
80
81       remove
82       {
83         lock(this)
84         {
85           if (_animationFinishedEventHandler != null)
86           {
87             this.FinishedSignal().Disconnect(_animationFinishedEventCallbackDelegate);
88           }
89
90           _animationFinishedEventHandler -= value;
91         }
92       }
93     }
94
95     // Callback for Animation FinishedSignal
96     private void OnFinished(IntPtr data)
97     {
98       FinishedEventArgs e = new FinishedEventArgs();
99
100       // Populate all members of "e" (FinishedEventArgs) with real data
101       e.Animation = Animation.GetAnimationFromPtr(data);
102
103       if (_animationFinishedEventHandler != null)
104       {
105         //here we send all data to user event handlers
106         _animationFinishedEventHandler(this, e);
107       }
108     }
109
110
111   public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
112     ClassName ret = new ClassName(cPtr, false);
113     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114     return ret;
115   }
116
117
118   public float Duration
119   {
120     set
121     {
122        SetDuration(value);
123     }
124     get
125     {
126        float ret = GetDuration();
127        return ret;
128     }
129   }
130
131   public AlphaFunction DefaultAlphaFunction
132   {
133     set
134     {
135        SetDefaultAlphaFunction(value);
136     }
137     get
138     {
139        AlphaFunction ret = GetDefaultAlphaFunction();
140        return ret;
141     }
142   }
143
144   public Animation.State Status
145   {
146     get
147     {
148        Animation.State ret = GetState();
149        return ret;
150     }
151   }
152
153 %}
154
155 %enddef
156
157
158 %define DALI_animation_EVENTHANDLER_PARAM( NameSpace, ClassName)
159   Animation_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
160   Animation_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
161   %enddef
162
163   namespace Dali
164 {
165   DALI_animation_EVENTHANDLER_PARAM( Dali, Animation);
166 }