Merge "Move Event Handlers to View class" into devel/master
[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
54   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
55   private delegate void TextChangedCallbackDelegate(IntPtr textEditor);
56   private DaliEventHandler<object,TextChangedEventArgs> _textEditorTextChangedEventHandler;
57   private TextChangedCallbackDelegate _textEditorTextChangedCallbackDelegate;
58
59   /**
60     * @brief Event for TextChanged signal which can be used to subscribe/unsubscribe the event handler
61     * (in the type of TextChangedEventHandler-DaliEventHandler<object,TextChangedEventArgs>) 
62     * provided by the user. TextChanged signal is emitted when the text changes.
63     */
64   public event DaliEventHandler<object,TextChangedEventArgs> TextChanged
65   {
66      add
67      {
68         lock(this)
69         {
70            // Restricted to only one listener
71            if (_textEditorTextChangedEventHandler == null)
72            {
73               _textEditorTextChangedEventHandler += value;
74
75               _textEditorTextChangedCallbackDelegate = new TextChangedCallbackDelegate(OnTextChanged);
76               this.TextChangedSignal().Connect(_textEditorTextChangedCallbackDelegate);
77            }
78         }
79      }
80
81      remove
82      {
83         lock(this)
84         {
85            if (_textEditorTextChangedEventHandler != null)
86            {
87               this.TextChangedSignal().Disconnect(_textEditorTextChangedCallbackDelegate);
88            }
89
90            _textEditorTextChangedEventHandler -= value;
91         }
92      }
93   }
94
95  private void OnTextChanged(IntPtr textEditor)
96   {
97    TextChangedEventArgs e = new TextChangedEventArgs();
98
99    // Populate all members of "e" (TextChangedEventArgs) with real data
100    e.TextEditor = Dali.TextEditor.GetTextEditorFromPtr(textEditor);
101
102    if (_textEditorTextChangedEventHandler != null)
103    {
104       //here we send all data to user event handlers
105       _textEditorTextChangedEventHandler(this, e);
106    }
107
108   }
109
110  public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
111     ClassName ret = new ClassName(cPtr, false);
112    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113     return ret;
114   }
115
116 %}
117
118 %enddef
119
120 %define DALI_TEXTEDITOR_EVENTHANDLER_PARAM( NameSpace, ClassName)
121
122   TEXTEDITOR_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
123   TEXTEDITOR_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
124
125 %enddef
126
127 namespace Dali
128 {
129   DALI_TEXTEDITOR_EVENTHANDLER_PARAM( Dali::Toolkit, TextEditor);
130 }