[NUI] SafeNativeWindowHandle, VideoView, Layer changed
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Window.cs
1 /*
2  * Copyright(c) 2017 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 namespace Tizen.NUI
19 {
20
21     using System;
22     using System.Runtime.InteropServices;
23     using Tizen.NUI.BaseComponents;
24     using System.ComponentModel;
25
26     /// <summary>
27     /// The window class is used internally for drawing.<br />
28     /// The window has an orientation and indicator properties.<br />
29     /// </summary>
30     public class Window : BaseHandle
31     {
32         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
33         private global::System.Runtime.InteropServices.HandleRef stageCPtr;
34         private Layer _rootLayer;
35         private string _windowTitle;
36
37         internal Window(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Window_SWIGUpcast(cPtr), cMemoryOwn)
38         {
39             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40             if (NDalicPINVOKE.Stage_IsInstalled())
41             {
42                 stageCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.Stage_GetCurrent());
43             }
44         }
45
46         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Window obj)
47         {
48             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
49         }
50
51         /// <summary>
52         /// To make the window instance be disposed.
53         /// </summary>
54         protected override void Dispose(DisposeTypes type)
55         {
56             if (disposed)
57             {
58                 return;
59             }
60
61             if (type == DisposeTypes.Explicit)
62             {
63                 //Called by User
64                 //Release your own managed resources here.
65                 //You should release all of your own disposable objects here.
66             }
67
68             //Release your own unmanaged resources here.
69             //You should not access any managed member here except static instance.
70             //because the execution order of Finalizes is non-deterministic.
71
72             if (_windowFocusChangedEventCallback != null)
73             {
74                 WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback);
75             }
76
77             if (_stageTouchCallbackDelegate != null)
78             {
79                 TouchSignal().Disconnect(_stageTouchCallbackDelegate);
80             }
81
82             if (_stageWheelCallbackDelegate != null)
83             {
84                 WheelEventSignal().Disconnect(_stageWheelCallbackDelegate);
85             }
86
87             if (_stageKeyCallbackDelegate != null)
88             {
89                 KeyEventSignal().Disconnect(_stageKeyCallbackDelegate);
90             }
91
92             if (_stageEventProcessingFinishedEventCallbackDelegate != null)
93             {
94                 EventProcessingFinishedSignal().Disconnect(_stageEventProcessingFinishedEventCallbackDelegate);
95             }
96
97             if (_stageContextLostEventCallbackDelegate != null)
98             {
99                 ContextLostSignal().Disconnect(_stageContextLostEventCallbackDelegate);
100             }
101
102             if (_stageContextRegainedEventCallbackDelegate != null)
103             {
104                 this.ContextRegainedSignal().Disconnect(_stageContextRegainedEventCallbackDelegate);
105             }
106
107             if (_stageSceneCreatedEventCallbackDelegate != null)
108             {
109                 SceneCreatedSignal().Disconnect(_stageSceneCreatedEventCallbackDelegate);
110             }
111
112             if (_windowResizedEventCallback != null)
113             {
114                 ResizedSignal().Disconnect(_windowResizedEventCallback);
115             }
116
117             if (_windowFocusChangedEventCallback2 != null)
118             {
119                 WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback2);
120             }
121
122             if (swigCPtr.Handle != global::System.IntPtr.Zero)
123             {
124                 if (swigCMemOwn)
125                 {
126                     swigCMemOwn = false;
127                     NDalicPINVOKE.delete_Window(swigCPtr);
128                     NDalicPINVOKE.delete_Stage(stageCPtr);
129                 }
130                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
131             }
132
133             base.Dispose(type);
134         }
135
136         internal static Window GetCurrent()
137         {
138             Window ret = new Window(NDalicPINVOKE.Stage_GetCurrent(), true);
139             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140             return ret;
141         }
142
143         internal static bool IsInstalled()
144         {
145             bool ret = NDalicPINVOKE.Stage_IsInstalled();
146             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147             return ret;
148         }
149
150         /// <summary>
151         /// Sets whether the window accepts a focus or not.
152         /// </summary>
153         /// <param name="accept">If a focus is accepted or not. The default is true.</param>
154         /// <since_tizen> 3 </since_tizen>
155         public void SetAcceptFocus(bool accept)
156         {
157             NDalicPINVOKE.SetAcceptFocus(swigCPtr, accept);
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159         }
160
161         /// <summary>
162         /// Returns whether the window accepts a focus or not.
163         /// </summary>
164         /// <returns>True if the window accepts a focus, false otherwise.</returns>
165         /// <since_tizen> 3 </since_tizen>
166         public bool IsFocusAcceptable()
167         {
168             bool ret = NDalicPINVOKE.IsFocusAcceptable(swigCPtr);
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170
171             return ret;
172         }
173
174         /// <summary>
175         /// Shows the window if it is hidden.
176         /// </summary>
177         /// <since_tizen> 3 </since_tizen>
178         public void Show()
179         {
180             NDalicPINVOKE.Show(swigCPtr);
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182         }
183
184         /// <summary>
185         /// Hides the window if it is showing.
186         /// </summary>
187         /// <since_tizen> 3 </since_tizen>
188         public void Hide()
189         {
190             NDalicPINVOKE.Hide(swigCPtr);
191             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192         }
193
194         /// <summary>
195         /// Retrieves whether the window is visible or not.
196         /// </summary>
197         /// <returns>True if the window is visible.</returns>
198         /// <since_tizen> 3 </since_tizen>
199         public bool IsVisible()
200         {
201             bool temp = NDalicPINVOKE.IsVisible(swigCPtr);
202             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203             return temp;
204         }
205
206         /// <summary>
207         /// Gets the count of supported auxiliary hints of the window.
208         /// </summary>
209         /// <returns>The number of supported auxiliary hints.</returns>
210         /// <since_tizen> 3 </since_tizen>
211         public uint GetSupportedAuxiliaryHintCount()
212         {
213             uint ret = NDalicPINVOKE.GetSupportedAuxiliaryHintCount(swigCPtr);
214             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215             return ret;
216         }
217
218         /// <summary>
219         /// Gets the supported auxiliary hint string of the window.
220         /// </summary>
221         /// <param name="index">The index of the supported auxiliary hint lists.</param>
222         /// <returns>The auxiliary hint string of the index.</returns>
223         /// <since_tizen> 3 </since_tizen>
224         public string GetSupportedAuxiliaryHint(uint index)
225         {
226             string ret = NDalicPINVOKE.GetSupportedAuxiliaryHint(swigCPtr, index);
227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228             return ret;
229         }
230
231         /// <summary>
232         /// Creates an auxiliary hint of the window.
233         /// </summary>
234         /// <param name="hint">The auxiliary hint string.</param>
235         /// <param name="value">The value string.</param>
236         /// <returns>The ID of created auxiliary hint, or 0 on failure.</returns>
237         /// <since_tizen> 3 </since_tizen>
238         public uint AddAuxiliaryHint(string hint, string value)
239         {
240             uint ret = NDalicPINVOKE.AddAuxiliaryHint(swigCPtr, hint, value);
241             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242             return ret;
243         }
244
245         /// <summary>
246         /// Removes an auxiliary hint of the window.
247         /// </summary>
248         /// <param name="id">The ID of the auxiliary hint.</param>
249         /// <returns>True if no error occurred, false otherwise.</returns>
250         /// <since_tizen> 3 </since_tizen>
251         public bool RemoveAuxiliaryHint(uint id)
252         {
253             bool ret = NDalicPINVOKE.RemoveAuxiliaryHint(swigCPtr, id);
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255             return ret;
256         }
257
258         /// <summary>
259         /// Changes a value of the auxiliary hint.
260         /// </summary>
261         /// <param name="id">The auxiliary hint ID.</param>
262         /// <param name="value">The value string to be set.</param>
263         /// <returns>True if no error occurred, false otherwise.</returns>
264         /// <since_tizen> 3 </since_tizen>
265         public bool SetAuxiliaryHintValue(uint id, string value)
266         {
267             bool ret = NDalicPINVOKE.SetAuxiliaryHintValue(swigCPtr, id, value);
268             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269             return ret;
270         }
271
272         /// <summary>
273         /// Gets a value of the auxiliary hint.
274         /// </summary>
275         /// <param name="id">The auxiliary hint ID.</param>
276         /// <returns>The string value of the auxiliary hint ID, or an empty string if none exists.</returns>
277         /// <since_tizen> 3 </since_tizen>
278         public string GetAuxiliaryHintValue(uint id)
279         {
280             string ret = NDalicPINVOKE.GetAuxiliaryHintValue(swigCPtr, id);
281             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282             return ret;
283         }
284
285         /// <summary>
286         /// Gets an ID of the auxiliary hint string.
287         /// </summary>
288         /// <param name="hint">The auxiliary hint string.</param>
289         /// <returns>The ID of auxiliary hint string, or 0 on failure.</returns>
290         /// <since_tizen> 3 </since_tizen>
291         public uint GetAuxiliaryHintId(string hint)
292         {
293             uint ret = NDalicPINVOKE.GetAuxiliaryHintId(swigCPtr, hint);
294             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295             return ret;
296         }
297
298         /// <summary>
299         /// Sets a region to accept input events.
300         /// </summary>
301         /// <param name="inputRegion">The region to accept input events.</param>
302         /// <since_tizen> 3 </since_tizen>
303         public void SetInputRegion(Rectangle inputRegion)
304         {
305             NDalicPINVOKE.SetInputRegion(swigCPtr, Rectangle.getCPtr(inputRegion));
306             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307         }
308
309         /// <summary>
310         /// Gets or sets a window type.
311         /// </summary>
312         /// <since_tizen> 3 </since_tizen>
313         public WindowType Type
314         {
315             get
316             {
317                 WindowType ret = (WindowType)NDalicPINVOKE.GetType(swigCPtr);
318                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319                 return ret;
320             }
321             set
322             {
323                 NDalicPINVOKE.SetType(swigCPtr, (int)value);
324                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325             }
326         }
327
328         /// <summary>
329         /// Sets a priority level for the specified notification window.
330         /// </summary>
331         /// <param name="level">The notification window level.</param>
332         /// <returns>True if no error occurred, false otherwise.</returns>
333         /// <since_tizen> 3 </since_tizen>
334         public bool SetNotificationLevel(NotificationLevel level)
335         {
336             bool ret = NDalicPINVOKE.SetNotificationLevel(swigCPtr, (int)level);
337             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338             return ret;
339         }
340
341         /// <summary>
342         /// Gets a priority level for the specified notification window.
343         /// </summary>
344         /// <returns>The notification window level.</returns>
345         /// <since_tizen> 3 </since_tizen>
346         public NotificationLevel GetNotificationLevel()
347         {
348             NotificationLevel ret = (NotificationLevel)NDalicPINVOKE.GetNotificationLevel(swigCPtr);
349             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350             return ret;
351         }
352
353         /// <summary>
354         /// Sets a transparent window's visual state to opaque.
355         /// </summary>
356         /// <param name="opaque">Whether the window's visual state is opaque.</param>
357         /// <since_tizen> 3 </since_tizen>
358         public void SetOpaqueState(bool opaque)
359         {
360             NDalicPINVOKE.SetOpaqueState(swigCPtr, opaque);
361             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362         }
363
364         /// <summary>
365         /// Returns whether a transparent window's visual state is opaque or not.
366         /// </summary>
367         /// <returns>True if the window's visual state is opaque, false otherwise.</returns>
368         /// <since_tizen> 3 </since_tizen>
369         public bool IsOpaqueState()
370         {
371             bool ret = NDalicPINVOKE.IsOpaqueState(swigCPtr);
372             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373             return ret;
374         }
375
376         /// <summary>
377         /// Sets a window's screen off mode.
378         /// </summary>
379         /// <param name="screenOffMode">The screen mode.</param>
380         /// <returns>True if no error occurred, false otherwise.</returns>
381         /// <since_tizen> 3 </since_tizen>
382         public bool SetScreenOffMode(ScreenOffMode screenOffMode)
383         {
384             bool ret = NDalicPINVOKE.SetScreenOffMode(swigCPtr, (int)screenOffMode);
385             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386             return ret;
387         }
388
389         /// <summary>
390         /// Gets the screen mode of the window.
391         /// </summary>
392         /// <returns>The screen off mode.</returns>
393         /// <since_tizen> 3 </since_tizen>
394         public ScreenOffMode GetScreenOffMode()
395         {
396             ScreenOffMode ret = (ScreenOffMode)NDalicPINVOKE.GetScreenOffMode(swigCPtr);
397             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398             return ret;
399         }
400
401         /// <summary>
402         /// Sets preferred brightness of the window.
403         /// </summary>
404         /// <param name="brightness">The preferred brightness (0 to 100).</param>
405         /// <returns>True if no error occurred, false otherwise.</returns>
406         /// <since_tizen> 3 </since_tizen>
407         public bool SetBrightness(int brightness)
408         {
409             bool ret = NDalicPINVOKE.SetBrightness(swigCPtr, brightness);
410             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411             return ret;
412         }
413
414         /// <summary>
415         /// Gets the preferred brightness of the window.
416         /// </summary>
417         /// <returns>The preferred brightness.</returns>
418         /// <since_tizen> 3 </since_tizen>
419         public int GetBrightness()
420         {
421             int ret = NDalicPINVOKE.GetBrightness(swigCPtr);
422             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
423             return ret;
424         }
425
426         /// <summary>
427         /// The focus changed event argument.
428         /// </summary>
429         public class FocusChangedEventArgs : EventArgs
430         {
431             /// <summary>
432             /// FocusGained flag.
433             /// </summary>
434             /// <since_tizen> 3 </since_tizen>
435             public bool FocusGained
436             {
437                 get;
438                 set;
439             }
440         }
441
442         private WindowFocusChangedEventCallbackType _windowFocusChangedEventCallback;
443         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
444         private delegate void WindowFocusChangedEventCallbackType(bool focusGained);
445         private event EventHandler<FocusChangedEventArgs> _windowFocusChangedEventHandler;
446
447         /// <summary>
448         /// FocusChanged event.
449         /// </summary>
450         /// <since_tizen> 4 </since_tizen>
451         public event EventHandler<FocusChangedEventArgs> FocusChanged
452         {
453             add
454             {
455                 if (_windowFocusChangedEventHandler == null)
456                 {
457                     _windowFocusChangedEventCallback = OnWindowFocusedChanged;
458                     WindowFocusChangedSignal().Connect(_windowFocusChangedEventCallback);
459                 }
460
461                 _windowFocusChangedEventHandler += value;
462             }
463             remove
464             {
465                 _windowFocusChangedEventHandler -= value;
466
467                 if (_windowFocusChangedEventHandler == null && WindowFocusChangedSignal().Empty() == false && _windowFocusChangedEventCallback != null)
468                 {
469                     WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback);
470                 }
471             }
472         }
473
474         private void OnWindowFocusedChanged(bool focusGained)
475         {
476             FocusChangedEventArgs e = new FocusChangedEventArgs();
477
478             e.FocusGained = focusGained;
479
480             if (_windowFocusChangedEventHandler != null)
481             {
482                 _windowFocusChangedEventHandler(this, e);
483             }
484         }
485
486         /// <summary>
487         /// Gets/Sets a window title.
488         /// </summary>
489         /// <since_tizen> 4 </since_tizen>
490         public string Title
491         {
492             get
493             {
494                 return _windowTitle;
495             }
496             set
497             {
498                 _windowTitle = value;
499                 SetClass(_windowTitle, "");
500             }
501         }
502
503         internal WindowFocusSignalType WindowFocusChangedSignal()
504         {
505             WindowFocusSignalType ret = new WindowFocusSignalType(NDalicPINVOKE.FocusChangedSignal(swigCPtr), false);
506             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507             return ret;
508         }
509
510         internal Window(Rectangle windowPosition, string name, bool isTransparent) : this(NDalicPINVOKE.Window_New__SWIG_0(Rectangle.getCPtr(windowPosition), name, isTransparent), true)
511         {
512             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
513         }
514
515         internal Window(Rectangle windowPosition, string name) : this(NDalicPINVOKE.Window_New__SWIG_1(Rectangle.getCPtr(windowPosition), name), true)
516         {
517             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518         }
519
520         internal Window(Rectangle windowPosition, string name, string className, bool isTransparent) : this(NDalicPINVOKE.Window_New__SWIG_2(Rectangle.getCPtr(windowPosition), name, className, isTransparent), true)
521         {
522             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
523         }
524
525         internal Window(Rectangle windowPosition, string name, string className) : this(NDalicPINVOKE.Window_New__SWIG_3(Rectangle.getCPtr(windowPosition), name, className), true)
526         {
527             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
528         }
529
530         internal void ShowIndicator(Window.IndicatorVisibleMode visibleMode)
531         {
532             NDalicPINVOKE.Window_ShowIndicator(swigCPtr, (int)visibleMode);
533             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
534         }
535
536         internal void SetIndicatorBackgroundOpacity(Window.IndicatorBackgroundOpacity opacity)
537         {
538             NDalicPINVOKE.Window_SetIndicatorBgOpacity(swigCPtr, (int)opacity);
539             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
540         }
541
542         internal void RotateIndicator(Window.WindowOrientation orientation)
543         {
544             NDalicPINVOKE.Window_RotateIndicator(swigCPtr, (int)orientation);
545             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
546         }
547
548         /// <summary>
549         /// Sets the window name and the class string.
550         /// </summary>
551         /// <param name="name">The name of the window.</param>
552         /// <param name="klass">The class of the window.</param>
553         /// <since_tizen> 4 </since_tizen>
554         public void SetClass(string name, string klass)
555         {
556             NDalicPINVOKE.Window_SetClass(swigCPtr, name, klass);
557             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
558         }
559
560         /// <summary>
561         /// Raises the window to the top of the window stack.
562         /// </summary>
563         /// <since_tizen> 3 </since_tizen>
564         public void Raise()
565         {
566             NDalicPINVOKE.Window_Raise(swigCPtr);
567             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
568         }
569
570         /// <summary>
571         /// Lowers the window to the bottom of the window stack.
572         /// </summary>
573         /// <since_tizen> 3 </since_tizen>
574         public void Lower()
575         {
576             NDalicPINVOKE.Window_Lower(swigCPtr);
577             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
578         }
579
580         /// <summary>
581         /// Activates the window to the top of the window stack even it is iconified.
582         /// </summary>
583         /// <since_tizen> 3 </since_tizen>
584         public void Activate()
585         {
586             NDalicPINVOKE.Window_Activate(swigCPtr);
587             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
588         }
589
590         internal void AddAvailableOrientation(Window.WindowOrientation orientation)
591         {
592             NDalicPINVOKE.Window_AddAvailableOrientation(swigCPtr, (int)orientation);
593             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
594         }
595
596         internal void RemoveAvailableOrientation(Window.WindowOrientation orientation)
597         {
598             NDalicPINVOKE.Window_RemoveAvailableOrientation(swigCPtr, (int)orientation);
599             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
600         }
601
602         internal void SetPreferredOrientation(Window.WindowOrientation orientation)
603         {
604             NDalicPINVOKE.Window_SetPreferredOrientation(swigCPtr, (int)orientation);
605             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
606         }
607
608         internal Window.WindowOrientation GetPreferredOrientation()
609         {
610             Window.WindowOrientation ret = (Window.WindowOrientation)NDalicPINVOKE.Window_GetPreferredOrientation(swigCPtr);
611             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
612             return ret;
613         }
614
615         internal DragAndDropDetector GetDragAndDropDetector()
616         {
617             DragAndDropDetector ret = new DragAndDropDetector(NDalicPINVOKE.Window_GetDragAndDropDetector(swigCPtr), true);
618             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
619             return ret;
620         }
621
622         internal Any GetNativeHandle()
623         {
624             Any ret = new Any(NDalicPINVOKE.Window_GetNativeHandle(swigCPtr), true);
625             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
626             return ret;
627         }
628
629         internal WindowFocusSignalType FocusChangedSignal()
630         {
631             WindowFocusSignalType ret = new WindowFocusSignalType(NDalicPINVOKE.FocusChangedSignal(swigCPtr), false);
632             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
633             return ret;
634         }
635
636         /// <summary>
637         /// Gets the default ( root ) layer.
638         /// </summary>
639         /// <returns>The root layer.</returns>
640         /// <since_tizen> 3 </since_tizen>
641         public Layer GetDefaultLayer()
642         {
643             return this.GetRootLayer();
644         }
645
646         internal void Add(Layer layer)
647         {
648             NDalicPINVOKE.Stage_Add(stageCPtr, Layer.getCPtr(layer));
649             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
650         }
651
652         internal void Remove(Layer layer)
653         {
654             NDalicPINVOKE.Stage_Remove(stageCPtr, Layer.getCPtr(layer));
655             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
656         }
657
658         /// <summary>
659         /// Add a child view to window.
660         /// </summary>
661         /// <param name="view">the child should be added to the window.</param>
662         /// <since_tizen> 3 </since_tizen>
663         public void Add(View view)
664         {
665             GetRootLayer()?.Add(view);
666         }
667
668         /// <summary>
669         /// Remove a child view from window.
670         /// </summary>
671         /// <param name="view">the child to be removed.</param>
672         /// <since_tizen> 3 </since_tizen>
673         public void Remove(View view)
674         {
675             GetRootLayer()?.Remove(view);
676         }
677
678         internal Vector2 GetSize()
679         {
680             Vector2 ret = new Vector2(NDalicPINVOKE.Stage_GetSize(stageCPtr), true);
681             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
682             return ret;
683         }
684
685         internal RenderTaskList GetRenderTaskList()
686         {
687             RenderTaskList ret = new RenderTaskList(NDalicPINVOKE.Stage_GetRenderTaskList(stageCPtr), true);
688             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
689             return ret;
690         }
691
692         /// <summary>
693         /// Queries the number of on-window layers.
694         /// </summary>
695         /// <returns>The number of layers.</returns>
696         /// <remarks>Note that a default layer is always provided (count >= 1).</remarks>
697         internal uint GetLayerCount()
698         {
699             uint ret = NDalicPINVOKE.Stage_GetLayerCount(stageCPtr);
700             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
701             return ret;
702         }
703
704         /// <summary>
705         /// Retrieves the layer at a specified depth.
706         /// </summary>
707         /// <param name="depth">The layer's depth index.</param>
708         /// <returns>The layer found at the given depth.</returns>
709         /// <since_tizen> 3 </since_tizen>
710         public Layer GetLayer(uint depth)
711         {
712             IntPtr cPtr = NDalicPINVOKE.Stage_GetLayer(stageCPtr, depth);
713             Layer ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Layer;
714
715             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
716             return ret;
717         }
718
719         internal Layer GetRootLayer()
720         {
721             // Window.IsInstalled() is actually true only when called from event thread and
722             // Core has been initialized, not when Stage is ready.
723             if (_rootLayer == null && Window.IsInstalled())
724             {
725                 _rootLayer = new Layer(NDalicPINVOKE.Stage_GetRootLayer(stageCPtr), true);
726                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
727             }
728             return _rootLayer;
729         }
730
731         internal void SetBackgroundColor(Vector4 color)
732         {
733             NDalicPINVOKE.Stage_SetBackgroundColor(stageCPtr, Vector4.getCPtr(color));
734             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
735         }
736
737         internal Vector4 GetBackgroundColor()
738         {
739             Vector4 ret = new Vector4(NDalicPINVOKE.Stage_GetBackgroundColor(stageCPtr), true);
740             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
741             return ret;
742         }
743
744         internal Vector2 GetDpi()
745         {
746             Vector2 ret = new Vector2(NDalicPINVOKE.Stage_GetDpi(stageCPtr), true);
747             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
748             return ret;
749         }
750
751         internal ObjectRegistry GetObjectRegistry()
752         {
753             ObjectRegistry ret = new ObjectRegistry(NDalicPINVOKE.Stage_GetObjectRegistry(stageCPtr), true);
754             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
755             return ret;
756         }
757
758         /// <summary>
759         /// Keep rendering for at least the given amount of time.
760         /// </summary>
761         /// <param name="durationSeconds">Time to keep rendering, 0 means render at least one more frame.</param>
762         /// <since_tizen> 3 </since_tizen>
763         public void KeepRendering(float durationSeconds)
764         {
765             NDalicPINVOKE.Stage_KeepRendering(stageCPtr, durationSeconds);
766             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
767         }
768
769         internal KeyEventSignal KeyEventSignal()
770         {
771             KeyEventSignal ret = new KeyEventSignal(NDalicPINVOKE.Stage_KeyEventSignal(stageCPtr), false);
772             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
773             return ret;
774         }
775
776         internal VoidSignal EventProcessingFinishedSignal()
777         {
778             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_EventProcessingFinishedSignal(stageCPtr), false);
779             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
780             return ret;
781         }
782
783         internal TouchSignal TouchSignal()
784         {
785             TouchSignal ret = new TouchSignal(NDalicPINVOKE.Stage_TouchSignal(stageCPtr), false);
786             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
787             return ret;
788         }
789
790         private StageWheelSignal WheelEventSignal()
791         {
792             StageWheelSignal ret = new StageWheelSignal(NDalicPINVOKE.Stage_WheelEventSignal(stageCPtr), false);
793             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
794             return ret;
795         }
796
797         internal VoidSignal ContextLostSignal()
798         {
799             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_ContextLostSignal(stageCPtr), false);
800             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
801             return ret;
802         }
803
804         internal VoidSignal ContextRegainedSignal()
805         {
806             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_ContextRegainedSignal(stageCPtr), false);
807             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
808             return ret;
809         }
810
811         internal VoidSignal SceneCreatedSignal()
812         {
813             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_SceneCreatedSignal(stageCPtr), false);
814             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
815             return ret;
816         }
817
818         internal ResizedSignal ResizedSignal()
819         {
820             ResizedSignal ret = new ResizedSignal(NDalicManualPINVOKE.Window_ResizedSignal(swigCPtr), false);
821             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
822             return ret;
823         }
824
825         internal static Vector4 DEFAULT_BACKGROUND_COLOR
826         {
827             get
828             {
829                 global::System.IntPtr cPtr = NDalicPINVOKE.Stage_DEFAULT_BACKGROUND_COLOR_get();
830                 Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
831                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
832                 return ret;
833             }
834         }
835
836         internal static Vector4 DEBUG_BACKGROUND_COLOR
837         {
838             get
839             {
840                 global::System.IntPtr cPtr = NDalicPINVOKE.Stage_DEBUG_BACKGROUND_COLOR_get();
841                 Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
842                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
843                 return ret;
844             }
845         }
846
847         private static readonly Window instance = Application.Instance.GetWindow();
848
849         /// <summary>
850         /// The stage instance property (read-only).<br />
851         /// Gets the current window.<br />
852         /// </summary>
853         /// <since_tizen> 3 </since_tizen>
854         public static Window Instance
855         {
856             get
857             {
858                 return instance;
859             }
860         }
861
862         /// <summary>
863         /// Grabs the key specified by a key for a window only when a window is the topmost window.<br />
864         /// This function can be used for following example scenarios: <br />
865         /// - Mobile - Using volume up or down as zoom up or down in camera apps.<br />
866         /// </summary>
867         /// <param name="DaliKey">The key code to grab.</param>
868         /// <returns>True if the grab succeeds.</returns>
869         /// <since_tizen> 3 </since_tizen>
870         public bool GrabKeyTopmost(int DaliKey)
871         {
872             bool ret = NDalicManualPINVOKE.GrabKeyTopmost(HandleRef.ToIntPtr(this.swigCPtr), DaliKey);
873             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
874             return ret;
875         }
876
877         /// <summary>
878         /// Ungrabs the key specified by a key for the window.<br />
879         /// Note: If this function is called between key down and up events of a grabbed key, an application doesn't receive the key up event.<br />
880         /// </summary>
881         /// <param name="DaliKey">The key code to ungrab.</param>
882         /// <returns>True if the ungrab succeeds.</returns>
883         /// <since_tizen> 3 </since_tizen>
884         public bool UngrabKeyTopmost(int DaliKey)
885         {
886             bool ret = NDalicManualPINVOKE.UngrabKeyTopmost(HandleRef.ToIntPtr(this.swigCPtr), DaliKey);
887             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
888             return ret;
889         }
890
891         /// <summary>
892         ///  Grabs the key specified by a key for a window in a GrabMode. <br />
893         ///  Details: This function can be used for following example scenarios: <br />
894         ///  - TV - A user might want to change the volume or channel of the background TV contents while focusing on the foregrund app. <br />
895         ///  - Mobile - When a user presses the Home key, the homescreen appears regardless of the current foreground app. <br />
896         ///  - Mobile - Using the volume up or down as zoom up or down in camera apps. <br />
897         /// </summary>
898         /// <param name="DaliKey">The key code to grab.</param>
899         /// <param name="GrabMode">The grab mode for the key.</param>
900         /// <returns>True if the grab succeeds.</returns>
901         /// <since_tizen> 3 </since_tizen>
902         public bool GrabKey(int DaliKey, KeyGrabMode GrabMode)
903         {
904             bool ret = NDalicManualPINVOKE.GrabKey(HandleRef.ToIntPtr(this.swigCPtr), DaliKey, (int)GrabMode);
905             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
906             return ret;
907         }
908
909         /// <summary>
910         /// Ungrabs the key specified by a key for a window.<br />
911         /// Note: If this function is called between key down and up events of a grabbed key, an application doesn't receive the key up event. <br />
912         /// </summary>
913         /// <param name="DaliKey">The key code to ungrab.</param>
914         /// <returns>True if the ungrab succeeds.</returns>
915         /// <since_tizen> 3 </since_tizen>
916         public bool UngrabKey(int DaliKey)
917         {
918             bool ret = NDalicManualPINVOKE.UngrabKey(HandleRef.ToIntPtr(this.swigCPtr), DaliKey);
919             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
920             return ret;
921         }
922
923         internal System.IntPtr GetNativeWindowHandler()
924         {
925             System.IntPtr ret = NDalicManualPINVOKE.GetNativeWindowHandler(HandleRef.ToIntPtr(this.swigCPtr));
926             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
927             return ret;
928         }
929
930         /// <summary>
931         /// Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
932         /// </summary>
933         /// <since_tizen> 3 </since_tizen>
934         public enum WindowOrientation
935         {
936             /// <summary>
937             /// Portrait orientation. The height of the display area is greater than the width.
938             /// </summary>
939             /// <since_tizen> 3 </since_tizen>
940             Portrait = 0,
941             /// <summary>
942             /// Landscape orientation. A wide view area is needed.
943             /// </summary>
944             /// <since_tizen> 3 </since_tizen>
945             Landscape = 90,
946             /// <summary>
947             /// Portrait inverse orientation.
948             /// </summary>
949             /// <since_tizen> 3 </since_tizen>
950             PortraitInverse = 180,
951             /// <summary>
952             /// Landscape inverse orientation.
953             /// </summary>
954             /// <since_tizen> 3 </since_tizen>
955             LandscapeInverse = 270
956         }
957
958         /// <summary>
959         /// Enumeration for the key grab mode for platform-level APIs.
960         /// </summary>
961         /// <since_tizen> 3 </since_tizen>
962         public enum KeyGrabMode
963         {
964             /// <summary>
965             /// Grabs a key only when on the top of the grabbing-window stack mode.
966             /// </summary>
967             Topmost = 0,
968             /// <summary>
969             /// Grabs a key together with the other client window(s) mode.
970             /// </summary>
971             Shared,
972             /// <summary>
973             /// Grabs a key exclusively regardless of the grabbing-window's position on the window stack with the possibility of overriding the grab by the other client window mode.
974             /// </summary>
975             OverrideExclusive,
976             /// <summary>
977             /// Grabs a key exclusively regardless of the grabbing-window's position on the window stack mode.
978             /// </summary>
979             Exclusive
980         };
981
982         /// <summary>
983         /// Enumeration for opacity of the indicator.
984         /// </summary>
985         internal enum IndicatorBackgroundOpacity
986         {
987             Opaque = 100,
988             Translucent = 50,
989             Transparent = 0
990         }
991
992         /// <summary>
993         /// Enumeration for visible mode of the indicator.
994         /// </summary>
995         internal enum IndicatorVisibleMode
996         {
997             Invisible = 0,
998             Visible = 1,
999             Auto = 2
1000         }
1001
1002         /// <summary>
1003         /// The touch event argument.
1004         /// </summary>
1005         public class TouchEventArgs : EventArgs
1006         {
1007             private Touch _touch;
1008
1009             /// <summary>
1010             /// Touch.
1011             /// </summary>
1012             /// <since_tizen> 3 </since_tizen>
1013             public Touch Touch
1014             {
1015                 get
1016                 {
1017                     return _touch;
1018                 }
1019                 set
1020                 {
1021                     _touch = value;
1022                 }
1023             }
1024         }
1025
1026         private event EventHandler<TouchEventArgs> _stageTouchHandler;
1027         private EventCallbackDelegateType1 _stageTouchCallbackDelegate;
1028
1029         /// <summary>
1030         /// This event is emitted when the screen is touched and when the touch ends.<br />
1031         /// If there are multiple touch points, then this will be emitted when the first touch occurs and
1032         /// then when the last finger is lifted.<br />
1033         /// An interrupted event will also be emitted (if it occurs).<br />
1034         /// </summary>
1035         /// <since_tizen> 4 </since_tizen>
1036         public event EventHandler<TouchEventArgs> TouchEvent
1037         {
1038             add
1039             {
1040                 lock (this)
1041                 {
1042                     _stageTouchHandler += value;
1043                     _stageTouchCallbackDelegate = OnStageTouch;
1044                     this.TouchSignal().Connect(_stageTouchCallbackDelegate);
1045                 }
1046             }
1047             remove
1048             {
1049                 lock (this)
1050                 {
1051                     if (_stageTouchHandler != null)
1052                     {
1053                         this.TouchSignal().Disconnect(_stageTouchCallbackDelegate);
1054                     }
1055                     _stageTouchHandler -= value;
1056                 }
1057             }
1058         }
1059
1060         private void OnStageTouch(IntPtr data)
1061         {
1062             TouchEventArgs e = new TouchEventArgs();
1063
1064             if (data != null)
1065             {
1066                 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(data);
1067             }
1068
1069             if (_stageTouchHandler != null)
1070             {
1071                 _stageTouchHandler(this, e);
1072             }
1073         }
1074
1075         /// <summary>
1076         /// Wheel event arguments.
1077         /// </summary>
1078         public class WheelEventArgs : EventArgs
1079         {
1080             private Wheel _wheel;
1081
1082             /// <summary>
1083             /// Wheel.
1084             /// </summary>
1085             /// <since_tizen> 3 </since_tizen>
1086             public Wheel Wheel
1087             {
1088                 get
1089                 {
1090                     return _wheel;
1091                 }
1092                 set
1093                 {
1094                     _wheel = value;
1095                 }
1096             }
1097         }
1098
1099         private event EventHandler<WheelEventArgs> _stageWheelHandler;
1100         private EventCallbackDelegateType1 _stageWheelCallbackDelegate;
1101
1102         /// <summary>
1103         /// This event is emitted when the wheel event is received.
1104         /// </summary>
1105         /// <since_tizen> 4 </since_tizen>
1106         public event EventHandler<WheelEventArgs> WheelEvent
1107         {
1108             add
1109             {
1110                 if (_stageWheelHandler == null)
1111                 {
1112                     _stageWheelCallbackDelegate = OnStageWheel;
1113                     WheelEventSignal().Connect(_stageWheelCallbackDelegate);
1114                 }
1115                 _stageWheelHandler += value;
1116             }
1117             remove
1118             {
1119                 _stageWheelHandler -= value;
1120                 if (_stageWheelHandler == null && WheelEventSignal().Empty() == false)
1121                 {
1122                     WheelEventSignal().Disconnect(_stageWheelCallbackDelegate);
1123                 }
1124             }
1125         }
1126
1127         private void OnStageWheel(IntPtr data)
1128         {
1129             WheelEventArgs e = new WheelEventArgs();
1130
1131             if (data != null)
1132             {
1133                 e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(data);
1134             }
1135
1136             if (_stageWheelHandler != null)
1137             {
1138                 _stageWheelHandler(this, e);
1139             }
1140         }
1141
1142         /// <summary>
1143         /// Key event arguments.
1144         /// </summary>
1145         public class KeyEventArgs : EventArgs
1146         {
1147             private Key _key;
1148
1149             /// <summary>
1150             /// Key.
1151             /// </summary>
1152             /// <since_tizen> 3 </since_tizen>
1153             public Key Key
1154             {
1155                 get
1156                 {
1157                     return _key;
1158                 }
1159                 set
1160                 {
1161                     _key = value;
1162                 }
1163             }
1164         }
1165
1166         private event EventHandler<KeyEventArgs> _stageKeyHandler;
1167         private EventCallbackDelegateType1 _stageKeyCallbackDelegate;
1168
1169         /// <summary>
1170         /// This event is emitted when the key event is received.
1171         /// </summary>
1172         /// <since_tizen> 4 </since_tizen>
1173         public event EventHandler<KeyEventArgs> KeyEvent
1174         {
1175             add
1176             {
1177                 if (_stageKeyHandler == null)
1178                 {
1179                     _stageKeyCallbackDelegate = OnStageKey;
1180                     KeyEventSignal().Connect(_stageKeyCallbackDelegate);
1181                 }
1182                 _stageKeyHandler += value;
1183             }
1184             remove
1185             {
1186                 _stageKeyHandler -= value;
1187                 if (_stageKeyHandler == null && KeyEventSignal().Empty() == false)
1188                 {
1189                     KeyEventSignal().Disconnect(_stageKeyCallbackDelegate);
1190                 }
1191             }
1192         }
1193
1194         // Callback for Stage KeyEventsignal
1195         private void OnStageKey(IntPtr data)
1196         {
1197             KeyEventArgs e = new KeyEventArgs();
1198
1199             if (data != null)
1200             {
1201                 e.Key = Tizen.NUI.Key.GetKeyFromPtr(data);
1202             }
1203
1204             if (_stageKeyHandler != null)
1205             {
1206                 //here we send all data to user event handlers
1207                 _stageKeyHandler(this, e);
1208             }
1209         }
1210
1211
1212         private event EventHandler _stageEventProcessingFinishedEventHandler;
1213         private EventCallbackDelegateType0 _stageEventProcessingFinishedEventCallbackDelegate;
1214
1215         internal event EventHandler EventProcessingFinished
1216         {
1217             add
1218             {
1219                 if (_stageEventProcessingFinishedEventHandler == null)
1220                 {
1221                     _stageEventProcessingFinishedEventCallbackDelegate = OnEventProcessingFinished;
1222                     EventProcessingFinishedSignal().Connect(_stageEventProcessingFinishedEventCallbackDelegate);
1223                 }
1224                 _stageEventProcessingFinishedEventHandler += value;
1225
1226             }
1227             remove
1228             {
1229                 _stageEventProcessingFinishedEventHandler -= value;
1230                 if (_stageEventProcessingFinishedEventHandler == null && EventProcessingFinishedSignal().Empty() == false)
1231                 {
1232                     EventProcessingFinishedSignal().Disconnect(_stageEventProcessingFinishedEventCallbackDelegate);
1233                 }
1234             }
1235         }
1236
1237         // Callback for Stage EventProcessingFinishedSignal
1238         private void OnEventProcessingFinished()
1239         {
1240             if (_stageEventProcessingFinishedEventHandler != null)
1241             {
1242                 _stageEventProcessingFinishedEventHandler(this, null);
1243             }
1244         }
1245
1246
1247         private EventHandler _stageContextLostEventHandler;
1248         private EventCallbackDelegateType0 _stageContextLostEventCallbackDelegate;
1249
1250         internal event EventHandler ContextLost
1251         {
1252             add
1253             {
1254                 if (_stageContextLostEventHandler == null)
1255                 {
1256                     _stageContextLostEventCallbackDelegate = OnContextLost;
1257                     ContextLostSignal().Connect(_stageContextLostEventCallbackDelegate);
1258                 }
1259                 _stageContextLostEventHandler += value;
1260             }
1261             remove
1262             {
1263                 _stageContextLostEventHandler -= value;
1264                 if (_stageContextLostEventHandler == null && ContextLostSignal().Empty() == false)
1265                 {
1266                     ContextLostSignal().Disconnect(_stageContextLostEventCallbackDelegate);
1267                 }
1268             }
1269         }
1270
1271         // Callback for Stage ContextLostSignal
1272         private void OnContextLost()
1273         {
1274             if (_stageContextLostEventHandler != null)
1275             {
1276                 _stageContextLostEventHandler(this, null);
1277             }
1278         }
1279
1280
1281         private EventHandler _stageContextRegainedEventHandler;
1282         private EventCallbackDelegateType0 _stageContextRegainedEventCallbackDelegate;
1283
1284         internal event EventHandler ContextRegained
1285         {
1286             add
1287             {
1288                 if (_stageContextRegainedEventHandler == null)
1289                 {
1290                     _stageContextRegainedEventCallbackDelegate = OnContextRegained;
1291                     ContextRegainedSignal().Connect(_stageContextRegainedEventCallbackDelegate);
1292                 }
1293                 _stageContextRegainedEventHandler += value;
1294             }
1295             remove
1296             {
1297                 _stageContextRegainedEventHandler -= value;
1298                 if (_stageContextRegainedEventHandler == null && ContextRegainedSignal().Empty() == false)
1299                 {
1300                     this.ContextRegainedSignal().Disconnect(_stageContextRegainedEventCallbackDelegate);
1301                 }
1302             }
1303         }
1304
1305         // Callback for Stage ContextRegainedSignal
1306         private void OnContextRegained()
1307         {
1308             if (_stageContextRegainedEventHandler != null)
1309             {
1310                 _stageContextRegainedEventHandler(this, null);
1311             }
1312         }
1313
1314
1315         private EventHandler _stageSceneCreatedEventHandler;
1316         private EventCallbackDelegateType0 _stageSceneCreatedEventCallbackDelegate;
1317
1318         internal event EventHandler SceneCreated
1319         {
1320             add
1321             {
1322                 if (_stageSceneCreatedEventHandler == null)
1323                 {
1324                     _stageSceneCreatedEventCallbackDelegate = OnSceneCreated;
1325                     SceneCreatedSignal().Connect(_stageSceneCreatedEventCallbackDelegate);
1326                 }
1327                 _stageSceneCreatedEventHandler += value;
1328             }
1329             remove
1330             {
1331                 _stageSceneCreatedEventHandler -= value;
1332                 if (_stageSceneCreatedEventHandler == null && SceneCreatedSignal().Empty() == false)
1333                 {
1334                     SceneCreatedSignal().Disconnect(_stageSceneCreatedEventCallbackDelegate);
1335                 }
1336             }
1337         }
1338
1339         // Callback for Stage SceneCreatedSignal
1340         private void OnSceneCreated()
1341         {
1342             if (_stageSceneCreatedEventHandler != null)
1343             {
1344                 _stageSceneCreatedEventHandler(this, null);
1345             }
1346         }
1347
1348         /// <summary>
1349         /// This resized event arguments.
1350         /// </summary>
1351         /// <since_tizen> 4 </since_tizen>
1352         public class ResizedEventArgs : EventArgs
1353         {
1354             Size2D _windowSize;
1355
1356             /// <summary>
1357             /// This window size.
1358             /// </summary>
1359             /// <since_tizen> 4 </since_tizen>
1360             public Size2D WindowSize
1361             {
1362                 get
1363                 {
1364                     return _windowSize;
1365                 }
1366                 set
1367                 {
1368                     _windowSize = value;
1369                 }
1370             }
1371         }
1372
1373         private WindowResizedEventCallbackType _windowResizedEventCallback;
1374         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1375         private delegate void WindowResizedEventCallbackType(IntPtr windowSize);
1376         private event EventHandler<ResizedEventArgs> _windowResizedEventHandler;
1377
1378         /// <summary>
1379         /// This event is emitted when the window resized.
1380         /// </summary>
1381         /// <since_tizen> 4 </since_tizen>
1382         public event EventHandler<ResizedEventArgs> Resized
1383         {
1384             add
1385             {
1386                 if (_windowResizedEventHandler == null)
1387                 {
1388                     _windowResizedEventCallback = OnResized;
1389                     ResizedSignal().Connect(_windowResizedEventCallback);
1390                 }
1391
1392                 _windowResizedEventHandler += value;
1393             }
1394             remove
1395             {
1396                 _windowResizedEventHandler -= value;
1397
1398                 if (_windowResizedEventHandler == null && ResizedSignal().Empty() == false && _windowResizedEventCallback != null)
1399                 {
1400                     ResizedSignal().Disconnect(_windowResizedEventCallback);
1401                 }
1402             }
1403         }
1404
1405         private void OnResized(IntPtr windowSize)
1406         {
1407             ResizedEventArgs e = new ResizedEventArgs();
1408             var val = new Uint16Pair(windowSize, false);
1409             e.WindowSize = new Size2D(val.GetWidth(), val.GetHeight());
1410             val.Dispose();
1411
1412             if (_windowResizedEventHandler != null)
1413             {
1414                 _windowResizedEventHandler(this, e);
1415             }
1416         }
1417
1418         internal void SetWindowSize(Size2D size)
1419         {
1420             var val = new Uint16Pair((uint)size.Width, (uint)size.Height);
1421             NDalicManualPINVOKE.SetSize(swigCPtr, Uint16Pair.getCPtr(val));
1422
1423             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1424         }
1425
1426         internal Size2D GetWindowSize()
1427         {
1428             var val = new Uint16Pair(NDalicManualPINVOKE.GetSize(swigCPtr), false);
1429             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
1430
1431             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1432             return ret;
1433         }
1434
1435         internal void SetPosition(Position2D position)
1436         {
1437             var val = new Uint16Pair((uint)position.X, (uint)position.Y);
1438             NDalicManualPINVOKE.SetPosition(swigCPtr, Uint16Pair.getCPtr(val));
1439
1440             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1441         }
1442
1443         internal Position2D GetPosition()
1444         {
1445             var val = new Uint16Pair(NDalicManualPINVOKE.GetPosition(swigCPtr), true);
1446             Position2D ret = new Position2D(val.GetX(), val.GetY());
1447
1448             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1449             return ret;
1450         }
1451
1452         /// <summary>
1453         /// The window size property (read-only).
1454         /// </summary>
1455         /// <since_tizen> 3 </since_tizen>
1456         public Size2D Size
1457         {
1458             get
1459             {
1460                 Size2D ret = GetSize();
1461                 return ret;
1462             }
1463         }
1464
1465         /// <summary>
1466         /// The background color property.
1467         /// </summary>
1468         /// <since_tizen> 3 </since_tizen>
1469         public Color BackgroundColor
1470         {
1471             set
1472             {
1473                 SetBackgroundColor(value);
1474             }
1475             get
1476             {
1477                 Color ret = GetBackgroundColor();
1478                 return ret;
1479             }
1480         }
1481
1482         /// <summary>
1483         /// The DPI property (read-only).<br />
1484         /// Retrieves the DPI of the display device to which the Window is connected.<br />
1485         /// </summary>
1486         /// <since_tizen> 3 </since_tizen>
1487         public Vector2 Dpi
1488         {
1489             get
1490             {
1491                 return GetDpi();
1492             }
1493         }
1494
1495         /// <summary>
1496         /// The layer count property (read-only).<br />
1497         /// Queries the number of on-Window layers.<br />
1498         /// </summary>
1499         /// <since_tizen> 3 </since_tizen>
1500         public uint LayerCount
1501         {
1502             get
1503             {
1504                 return GetLayerCount();
1505             }
1506         }
1507
1508
1509         /// <summary>
1510         /// Adds a layer to the stage.
1511         /// </summary>
1512         /// <param name="layer">Layer to add.</param>
1513         /// <since_tizen> 3 </since_tizen>
1514         public void AddLayer(Layer layer)
1515         {
1516             NDalicPINVOKE.Stage_Add(stageCPtr, Layer.getCPtr(layer));
1517             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1518         }
1519
1520         /// <summary>
1521         /// Removes a layer from the stage.
1522         /// </summary>
1523         /// <param name="layer">Layer to remove.</param>
1524         /// <since_tizen> 4 </since_tizen>
1525         public void RemoveLayer(Layer layer)
1526         {
1527             NDalicPINVOKE.Stage_Remove(stageCPtr, Layer.getCPtr(layer));
1528             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1529         }
1530
1531         /// <summary>
1532         /// Please do not use! this will be deprecated
1533         /// </summary>
1534         /// <since_tizen> 3 </since_tizen>
1535         [EditorBrowsable(EditorBrowsableState.Never)]
1536         public class WindowFocusChangedEventArgs : EventArgs
1537         {
1538             /// <summary>
1539             /// Please do not use! this will be deprecated
1540             /// </summary>
1541             /// <since_tizen> 3 </since_tizen>
1542             public bool FocusGained
1543             {
1544                 get;
1545                 set;
1546             }
1547         }
1548
1549         private WindowFocusChangedEventCallbackType _windowFocusChangedEventCallback2;
1550         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1551         private delegate void WindowFocusChangedEventCallbackType2(bool focusGained);
1552         private event EventHandler<WindowFocusChangedEventArgs> _windowFocusChangedEventHandler2;
1553
1554         /// <summary>
1555         /// Please do not use! this will be deprecated. Please use 'FocusChanged' event instead.
1556         /// </summary>
1557         /// <since_tizen> 3 </since_tizen>
1558         [Obsolete("Please do not use! this will be deprecated. Please use 'FocusChanged' event instead")]
1559         public event EventHandler<WindowFocusChangedEventArgs> WindowFocusChanged
1560         {
1561             add
1562             {
1563                 if (_windowFocusChangedEventHandler2 == null)
1564                 {
1565                     _windowFocusChangedEventCallback2 = OnWindowFocusedChanged2;
1566                     WindowFocusChangedSignal().Connect(_windowFocusChangedEventCallback2);
1567                 }
1568
1569                 _windowFocusChangedEventHandler2 += value;
1570             }
1571             remove
1572             {
1573                 _windowFocusChangedEventHandler2 -= value;
1574
1575                 if (_windowFocusChangedEventHandler2 == null && WindowFocusChangedSignal().Empty() == false && _windowFocusChangedEventCallback2 != null)
1576                 {
1577                     WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback2);
1578                 }
1579             }
1580         }
1581
1582         private void OnWindowFocusedChanged2(bool focusGained)
1583         {
1584             WindowFocusChangedEventArgs e = new WindowFocusChangedEventArgs();
1585
1586             e.FocusGained = focusGained;
1587
1588             if (_windowFocusChangedEventHandler2 != null)
1589             {
1590                 _windowFocusChangedEventHandler2(this, e);
1591             }
1592         }
1593
1594         /// <summary>
1595         /// Gets or sets a size of the window.
1596         /// </summary>
1597         /// <since_tizen> 4 </since_tizen>
1598         public Size2D WindowSize
1599         {
1600             get
1601             {
1602                 return GetWindowSize();
1603             }
1604             set
1605             {
1606                 SetWindowSize(value);
1607             }
1608         }
1609
1610         /// <summary>
1611         /// Gets or sets a position of the window.
1612         /// </summary>
1613         /// <since_tizen> 4 </since_tizen>
1614         public Position2D WindowPosition
1615         {
1616             get
1617             {
1618                 return GetPosition();
1619             }
1620             set
1621             {
1622                 SetPosition(value);
1623             }
1624         }
1625
1626         /// <summary>
1627         /// Feed a key-event into the window.
1628         /// </summary>
1629         /// <since_tizen> 4 </since_tizen>
1630         public static void FeedKeyEvent(Key keyEvent)
1631         {
1632             NDalicManualPINVOKE.Window_FeedKeyEvent(Key.getCPtr(keyEvent));
1633             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1634         }
1635
1636         /// <summary>
1637         /// Allows at least one more render, even when paused.
1638         /// The window should be shown, not minimised.
1639         /// </summary>
1640         /// <since_tizen> 4 </since_tizen>
1641         public void RenderOnce()
1642         {
1643             NDalicManualPINVOKE.Window_RenderOnce(swigCPtr);
1644             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1645         }
1646
1647         /// <summary>
1648         /// Contains and encapsulates Native Window handle.
1649         /// </summary>
1650         /// <since_tizen> 4 </since_tizen>
1651         public class SafeNativeWindowHandle : SafeHandle
1652         {
1653             /// <summary>
1654             /// Contructor, Native window handle is set to handle.
1655             /// </summary>
1656             /// <since_tizen> 4 </since_tizen>
1657             public SafeNativeWindowHandle() : base(IntPtr.Zero, false)
1658             {
1659                 SetHandle(Tizen.NUI.Window.Instance.GetNativeWindowHandler());
1660             }
1661             /// <summary>
1662             /// Null check if the handle is valid or not.
1663             /// </summary>
1664             /// <since_tizen> 4 </since_tizen>
1665             public override bool IsInvalid
1666             {
1667                 get
1668                 {
1669                     return this.handle == IntPtr.Zero;
1670                 }
1671             }
1672             /// <summary>
1673             /// Release handle itself.
1674             /// </summary>
1675             /// <returns>true when released successfully.</returns>
1676             /// <since_tizen> 4 </since_tizen>
1677             protected override bool ReleaseHandle()
1678             {
1679                 return true;
1680             }
1681         }
1682
1683     }
1684 }