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