DALi C# binding - EventHandler Support
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / texteditor-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 TEXTEDITOR_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22
23 %}
24
25 %enddef
26
27 %define TEXTEDITOR_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
28 %typemap(cscode) NameSpace::ClassName %{
29
30 /**
31   * @brief Event arguments that passed via TextChanged signal
32   *
33   */
34 public class TextChangedEventArgs : EventArgs
35 {
36    private TextEditor _textEditor;
37    /**
38      * @brief TextEditor - is the texteditor control which has the text contents changed.
39      *
40      */
41    public TextEditor TextEditor
42    {
43       get
44       {
45          return _textEditor;
46       }
47       set
48       {
49          _textEditor = value;
50       }
51    }
52 }
53   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
54   public delegate void TextChangedEventHandler(object source, TextChangedEventArgs e);
55
56   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
57   private delegate void TextChangedCallbackDelegate(IntPtr textEditor);
58   private TextChangedEventHandler _textEditorTextChangedEventHandler;
59   private TextChangedCallbackDelegate _textEditorTextChangedCallbackDelegate;
60
61   /**
62     * @brief Event for TextChanged signal which can be used to subscribe/unsubscribe the event handler
63     * (in the type of TextChangedEventHandler) provided by the user.
64     * TextChanged signal is emitted when the text changes.
65     */
66   public event TextChangedEventHandler TextChanged
67   {
68      add
69      {
70         lock(this)
71         {
72            // Restricted to only one listener
73            if (_textEditorTextChangedEventHandler == null)
74            {
75               _textEditorTextChangedEventHandler += value;
76
77               _textEditorTextChangedCallbackDelegate = new TextChangedCallbackDelegate(OnTextChanged);
78               this.TextChangedSignal().Connect(_textEditorTextChangedCallbackDelegate);
79            }
80         }
81      }
82
83      remove
84      {
85         lock(this)
86         {
87            if (_textEditorTextChangedEventHandler != null)
88            {
89               this.TextChangedSignal().Disconnect(_textEditorTextChangedCallbackDelegate);
90            }
91
92            _textEditorTextChangedEventHandler -= value;
93         }
94      }
95   }
96
97  private void OnTextChanged(IntPtr textEditor)
98   {
99    TextChangedEventArgs e = new TextChangedEventArgs();
100
101    // Populate all members of "e" (TextChangedEventArgs) with real data
102    e.TextEditor = Dali.TextEditor.GetTextEditorFromPtr(textEditor);
103
104    if (_textEditorTextChangedEventHandler != null)
105    {
106       //here we send all data to user event handlers
107       _textEditorTextChangedEventHandler(this, e);
108    }
109
110   }
111
112  public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
113     ClassName ret = new ClassName(cPtr, false);
114    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115     return ret;
116   }
117
118 %}
119
120 %enddef
121
122 %define DALI_TEXTEDITOR_EVENTHANDLER_PARAM( NameSpace, ClassName)
123
124   TEXTEDITOR_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
125   TEXTEDITOR_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
126
127 %enddef
128
129 namespace Dali
130 {
131   DALI_TEXTEDITOR_EVENTHANDLER_PARAM( Dali::Toolkit, TextEditor);
132 }