9aac4bdcfb99a1ae4db8bb247ed6e4d7fe8fee76
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / stylemanager-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 STYLEMANAGER_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22 %}
23 %enddef
24
25 %define STYLEMANAGER_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
26 %typemap(cscode) NameSpace::ClassName %{
27
28
29 /**
30   * @brief Event arguments that passed via StyleChanged signal
31   *
32   */
33 public class StyleChangedEventArgs : EventArgs
34 {
35    private StyleManager _styleManager;
36    private Dali.StyleChangeType _styleChange;
37
38    /**
39      * @brief StyleManager - is the StyleManager that informs applications of system theme change,
40      * and supports application theme change at runtime.
41      *
42      */
43    public StyleManager StyleManager
44    {
45       get
46       {
47          return _styleManager;
48       }
49       set
50       {
51          _styleManager = value;
52       }
53    }
54
55    /**
56      * @brief StyleChange - contains Style change information (default font changed or
57      * default font size changed or theme has changed)
58      *
59      */
60    public Dali.StyleChangeType StyleChange
61    {
62       get
63       {
64          return _styleChange;
65       }
66       set
67       {
68          _styleChange = value;
69       }
70    }
71
72 }
73
74   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
75   public delegate void StyleChangedEventHandler(object source, StyleChangedEventArgs e);
76
77   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
78   private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Dali.StyleChangeType styleChange);
79   private StyleChangedEventHandler _styleManagerStyleChangedEventHandler;
80   private StyleChangedCallbackDelegate _styleManagerStyleChangedCallbackDelegate;
81
82   /**
83     * @brief Event for StyleChanged signal which can be used to subscribe/unsubscribe the
84     * event handler (in the type of StyleChangedEventHandler) provided by the user.
85     * StyleChanged signal is is emitted after the style (e.g. theme/font change) has changed
86     * and the controls have been informed.
87     */
88   public event StyleChangedEventHandler StyleChanged
89   {
90      add
91      {
92         lock(this)
93         {
94            // Restricted to only one listener
95            if (_styleManagerStyleChangedEventHandler == null)
96            {
97               _styleManagerStyleChangedEventHandler += value;
98
99               _styleManagerStyleChangedCallbackDelegate = new StyleChangedCallbackDelegate(OnStyleChanged);
100               this.StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate);
101            }
102         }
103      }
104
105      remove
106      {
107         lock(this)
108         {
109            if (_styleManagerStyleChangedEventHandler != null)
110            {
111               this.StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
112            }
113
114            _styleManagerStyleChangedEventHandler -= value;
115         }
116      }
117   }
118
119   // Callback for StyleManager StyleChangedsignal
120   private void OnStyleChanged(IntPtr styleManager, Dali.StyleChangeType styleChange)
121   {
122      StyleChangedEventArgs e = new StyleChangedEventArgs();
123
124      // Populate all members of "e" (StyleChangedEventArgs) with real data
125      e.StyleManager = StyleManager.GetStyleManagerFromPtr( styleManager );
126      e.StyleChange = styleChange;
127
128      if (_styleManagerStyleChangedEventHandler != null)
129      {
130         //here we send all data to user event handlers
131         _styleManagerStyleChangedEventHandler(this, e);
132      }
133   }
134
135    public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
136       ClassName ret = new ClassName(cPtr, false);
137       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138       return ret;
139    }
140
141 %}
142
143 %enddef
144
145
146 %define DALI_STYLEMANAGER_EVENTHANDLER_PARAM( NameSpace, ClassName)
147
148   STYLEMANAGER_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
149   STYLEMANAGER_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
150
151 %enddef
152
153 namespace Dali
154 {
155   DALI_STYLEMANAGER_EVENTHANDLER_PARAM( Dali::Toolkit, StyleManager);
156 }