[NUI] Remove duplicate getCPtr from BaseHandle subclasses (#3545)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Animation / TransitionOptions.cs
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18 using System.ComponentModel;
19 using Tizen.Applications;
20 using Tizen.NUI.BaseComponents;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// This TransitionOptions class is a class to control Transition motion.
26     /// This class includes multiple options for the Transition.
27     /// NUI supports various kinds of Transitions such as App transition, Page transition, and so on.
28     /// </summary>
29     /// <seealso cref="NUIApplication.TransitionOptions" />
30     /// <since_tizen> 9 </since_tizen>
31     public class TransitionOptions : IDisposable
32     {
33         private bool disposed = false;
34         private FrameProvider frameProvider;
35         private DefaultFrameBroker frameBroker;
36         private bool enableTransition = false;
37         private Window mainWindow;
38         private View animatedTarget;
39
40         /// <summary>
41         /// Initializes the TransitionOptions class.
42         /// </summary>
43         /// <param name="window">The window instance of NUI Window</param>
44         [EditorBrowsable(EditorBrowsableState.Never)]
45         public TransitionOptions(Window window)
46         {
47             mainWindow = window;
48         }
49
50         /// <summary>
51         /// Initializes the TransitionOptions class.
52         /// </summary>
53         /// <since_tizen> 9 </since_tizen>
54         public TransitionOptions()
55         {
56         }
57
58         /// <summary>
59         /// Set animated view of seamless animation.
60         /// </summary>
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public View AnimatedTarget
63         {
64             get
65             {
66                 return animatedTarget;
67             }
68             set
69             {
70                 animatedTarget = value;
71             }
72         }
73
74         /// <summary>
75         /// Gets or sets transition enable
76         /// </summary>
77         [EditorBrowsable(EditorBrowsableState.Never)]
78         public bool EnableTransition
79         {
80             get
81             {
82                 return enableTransition;
83             }
84
85             set
86             {
87                 if (value)
88                 {
89                     frameBroker = new DefaultFrameBroker(mainWindow);
90                     frameBroker.mainView = animatedTarget;
91                     frameBroker.AnimationInitialized += FrameBroker_TransitionAnimationInitialized;
92                     frameBroker.AnimationFinished += FrameBroker_TransitionAnimationFinished;
93                     EnableProvider();
94                 }
95                 enableTransition = value;
96             }
97         }
98
99         private void EnableProvider()
100         {
101             frameProvider = new FrameProvider(mainWindow);
102             frameProvider.Shown += FrameProvider_Shown;
103             frameProvider.Hidden += FrameProvider_Hidden;
104         }
105
106         /// <summary>
107         /// String tag to find View pair to be used in Page transition.
108         /// If there is a View have same TransitionTag in a next or previous Page.
109         /// The View will be pair for transition.
110         /// This is property for Page Transition.
111         /// </summary>
112         /// <since_tizen> 9 </since_tizen>
113         public string TransitionTag { set; get; } = null;
114
115         /// <summary>
116         /// Property for Page transition.
117         /// A View could be transition with its child Views or without them.
118         /// Default value is false
119         /// </summary>
120         /// <since_tizen> 9 </since_tizen>
121         public bool TransitionWithChild { set; get; } = false;
122
123         /// <summary>
124         /// Gets or sets the forward animation of launching
125         /// </summary>
126         [EditorBrowsable(EditorBrowsableState.Never)]
127         public TransitionAnimation ForwardAnimation
128         {
129             get
130             {
131                 return frameBroker?.ForwardAnimation;
132             }
133             set
134             {
135                 if (frameBroker != null)
136                 {
137                     frameBroker.ForwardAnimation = value;
138                 }
139             }
140         }
141
142         /// <summary>
143         /// Gets or sets the backward animation of launching
144         /// </summary>
145         [EditorBrowsable(EditorBrowsableState.Never)]
146         public TransitionAnimation BackwardAnimation
147
148         {
149             get
150             {
151                 return frameBroker?.BackwardAnimation;
152             }
153             set
154             {
155                 if (frameBroker != null)
156                 {
157                     frameBroker.BackwardAnimation = value;
158                 }
159             }
160         }
161
162         /// <summary>
163         /// Emits the event when the animation is started.
164         /// </summary>
165         [EditorBrowsable(EditorBrowsableState.Never)]
166         public delegate void AnimationEventHandler(bool direction);
167
168         /// <summary>
169         /// Emits the event when the animation is started.
170         /// </summary>
171         [EditorBrowsable(EditorBrowsableState.Never)]
172         public event AnimationEventHandler AnimationInitialized;
173
174         /// <summary>
175         /// Emits the event when the animation is finished.
176         /// </summary>
177         [EditorBrowsable(EditorBrowsableState.Never)]
178         public event AnimationEventHandler AnimationFinished;
179
180         private void FrameBroker_TransitionAnimationFinished(bool direction)
181         {
182             AnimationFinished?.Invoke(direction);
183         }
184
185         private void FrameBroker_TransitionAnimationInitialized(bool direction)
186         {
187             AnimationInitialized?.Invoke(direction);
188         }
189
190         /// <summary>
191         /// Occurs whenever the window is shown on caller application.
192         /// </summary>
193         [EditorBrowsable(EditorBrowsableState.Never)]
194         public event EventHandler CallerScreenShown;
195
196         /// <summary>
197         /// Occurs whenever the window is hidden on caller application.
198         /// </summary>
199         [EditorBrowsable(EditorBrowsableState.Never)]
200         public event EventHandler CallerScreenHidden;
201
202         private void FrameProvider_Shown(object sender, EventArgs e)
203         {
204             Bundle bundle = new Bundle();
205             //Set information of shared object
206             frameProvider?.NotifyShowStatus(bundle);
207
208             CallerScreenShown?.Invoke(this, e);
209             bundle.Dispose();
210             bundle = null;
211         }
212
213         private void FrameProvider_Hidden(object sender, EventArgs e)
214         {
215             Bundle bundle = new Bundle();
216             //Set information of shared object
217             frameProvider?.NotifyHideStatus(bundle);
218
219             CallerScreenHidden?.Invoke(this, e);
220             bundle.Dispose();
221             bundle = null;
222         }
223
224         internal void SendLaunchRequest(AppControl appControl)
225         {
226             this.frameBroker.SendLaunchRequest(appControl, true);
227         }
228
229         /// <summary>
230         /// Hidden API (Inhouse API).
231         /// Dispose.
232         /// </summary>
233         /// <param name="disposing"></param>
234         [EditorBrowsable(EditorBrowsableState.Never)]
235         protected virtual void Dispose(bool disposing)
236         {
237             if (!disposed)
238             {
239                 if (frameBroker != null)
240                 {
241                     frameBroker.Dispose();
242                 }
243
244                 if (frameProvider != null)
245                 {
246                     frameProvider.Dispose();
247                 }
248                 disposed = true;
249             }
250         }
251
252         /// <summary>
253         /// Dispose for IDisposable pattern
254         /// </summary>
255         [EditorBrowsable(EditorBrowsableState.Never)]
256         public void Dispose()
257         {
258             Dispose(true);
259             System.GC.SuppressFinalize(this);
260         }
261     }
262 }