2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 using System.ComponentModel;
22 using System.Runtime.InteropServices;
25 /// TransitionSet is used to control lifetime of multiple Transitions.
26 /// For the one page transition, may multiple transitions are played coincidently.
27 /// Every transitions added on a TransitionSet have same play lifetime. And emit a single Finished signal.
29 internal class TransitionSet : BaseHandle
31 private TransitionSetFinishedEventCallbackType transitionSetFinishedEventCallback;
32 private System.IntPtr finishedCallbackOfNative;
35 /// Creates an initialized transitionSet.<br />
37 /// <remarks>DurationmSeconds must be greater than zero.</remarks>
38 public TransitionSet() : this(Interop.TransitionSet.New(), true)
40 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43 internal TransitionSet(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
45 transitionSetFinishedEventCallback = OnFinished;
46 finishedCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(transitionSetFinishedEventCallback);
49 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
50 private delegate void TransitionSetFinishedEventCallbackType(IntPtr data);
52 private event EventHandler transitionSetFinishedEventHandler;
55 * @brief Event for the finished signal which can be used to subscribe or unsubscribe the event handler.
56 * The finished signal is emitted when an transitionSet's transitionSets have finished.
58 public event EventHandler Finished
62 if (transitionSetFinishedEventHandler == null && disposed == false)
64 TransitionSetFinishedSignal finishedSignal = FinishedSignal();
65 finishedSignal.Connect(finishedCallbackOfNative);
66 finishedSignal.Dispose();
68 transitionSetFinishedEventHandler += value;
72 transitionSetFinishedEventHandler -= value;
74 TransitionSetFinishedSignal finishedSignal = FinishedSignal();
75 if (transitionSetFinishedEventHandler == null && finishedSignal.Empty() == false)
77 finishedSignal.Disconnect(finishedCallbackOfNative);
79 finishedSignal.Dispose();
84 /// Downcasts a handle to transitionSet handle.<br />
85 /// If handle points to an transitionSet object, the downcast produces a valid handle.<br />
86 /// If not, the returned handle is left uninitialized.<br />
88 /// <param name="handle">Handle to an object.</param>
89 /// <returns>Handle to an transitionSet object or an uninitialized handle.</returns>
90 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
91 internal static TransitionSet DownCast(BaseHandle handle)
95 throw new ArgumentNullException(nameof(handle));
97 TransitionSet ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TransitionSet;
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102 public void AddTransition(TransitionItemBase transition)
104 Interop.TransitionSet.AddTransition(SwigCPtr, transition.SwigCPtr);
105 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108 public TransitionItemBase GetTransitionAt(uint index)
110 //to fix memory leak issue, match the handle count with native side.
111 IntPtr cPtr = Interop.TransitionSet.GetTransitionAt(SwigCPtr, index);
112 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
113 TransitionItemBase ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as TransitionItemBase;
114 if (cPtr != null && ret == null)
116 ret = new TransitionItemBase(cPtr, false);
117 if (NDalicPINVOKE.SWIGPendingException.Pending)
118 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121 Interop.BaseHandle.DeleteBaseHandle(CPtr);
122 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
124 if (NDalicPINVOKE.SWIGPendingException.Pending)
125 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129 public uint GetTransitionCount()
131 uint ret = Interop.TransitionSet.GetTransitionCount(SwigCPtr);
132 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 /// Plays the transitionSet.
141 Interop.TransitionSet.Play(SwigCPtr);
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TransitionSet obj)
147 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
150 internal TransitionSet(TransitionSet handle) : this(Interop.TransitionSet.NewTransitionSet(TransitionSet.getCPtr(handle)), true)
152 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155 internal TransitionSet Assign(TransitionSet rhs)
157 TransitionSet ret = new TransitionSet(Interop.TransitionSet.Assign(SwigCPtr, TransitionSet.getCPtr(rhs)), false);
158 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 internal TransitionSetFinishedSignal FinishedSignal()
164 TransitionSetFinishedSignal ret = new TransitionSetFinishedSignal(Interop.TransitionSet.FinishedSignal(SwigCPtr), false);
165 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170 /// To make transitionSet instance be disposed.
172 protected override void Dispose(DisposeTypes type)
179 if (transitionSetFinishedEventHandler != null)
181 TransitionSetFinishedSignal finishedSignal = FinishedSignal();
182 finishedSignal?.Disconnect(finishedCallbackOfNative);
183 finishedSignal?.Dispose();
184 transitionSetFinishedEventHandler = null;
190 /// This will not be public opened.
191 [EditorBrowsable(EditorBrowsableState.Never)]
192 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
194 if (swigCPtr.Handle == IntPtr.Zero || this.HasBody() == false)
196 Tizen.Log.Fatal("NUI", $"[ERROR] TransitionSet ReleaseSwigCPtr()! IntPtr=0x{swigCPtr.Handle:X} HasBody={this.HasBody()}");
199 Interop.TransitionSet.Delete(swigCPtr);
202 private void OnFinished(IntPtr data)
204 if (transitionSetFinishedEventHandler != null)
206 //here we send all data to user event handlers
207 transitionSetFinishedEventHandler(this, null);