2 * Copyright(c) 2017 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.
17 using System.ComponentModel;
22 using System.Runtime.InteropServices;
23 using Tizen.NUI.BaseComponents;
26 /// The WidgetView is a class for displaying the widget image and controlling the widget.<br />
27 /// Input events that the WidgetView gets are delivered to the widget.
29 /// <since_tizen> 3 </since_tizen>
30 public class WidgetView : View
32 private EventHandler<WidgetViewEventArgs> _widgetAddedEventHandler;
33 private WidgetAddedEventCallbackType _widgetAddedEventCallback;
34 private EventHandler<WidgetViewEventArgs> _widgetContentUpdatedEventHandler;
35 private WidgetContentUpdatedEventCallbackType _widgetContentUpdatedEventCallback;
36 private EventHandler<WidgetViewEventArgs> _widgetDeletedEventHandler;
37 private WidgetDeletedEventCallbackType _widgetDeletedEventCallback;
38 private EventHandler<WidgetViewEventArgs> _widgetCreationAbortedEventHandler;
39 private WidgetCreationAbortedEventCallbackType _widgetCreationAbortedEventCallback;
40 private EventHandler<WidgetViewEventArgs> _widgetUpdatePeriodChangedEventHandler;
41 private WidgetUpdatePeriodChangedEventCallbackType _widgetUpdatePeriodChangedEventCallback;
42 private EventHandler<WidgetViewEventArgs> _widgetFaultedEventHandler;
43 private WidgetFaultedEventCallbackType _widgetFaultedEventCallback;
45 /// Creates a new WidgetView.
47 /// <since_tizen> 3 </since_tizen>
48 public WidgetView(string widgetId, string contentInfo, int width, int height, float updatePeriod) : this(Interop.WidgetView.New(widgetId, contentInfo, width, height, updatePeriod), true)
50 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
54 internal WidgetView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.WidgetView.Upcast(cPtr), cMemoryOwn)
57 internal WidgetView(WidgetView handle) : this(Interop.WidgetView.NewWidgetView(WidgetView.getCPtr(handle)), true)
59 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
62 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
63 private delegate void WidgetAddedEventCallbackType(IntPtr data);
64 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
65 private delegate void WidgetContentUpdatedEventCallbackType(IntPtr data);
66 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
67 private delegate void WidgetDeletedEventCallbackType(IntPtr data);
68 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
69 private delegate void WidgetCreationAbortedEventCallbackType(IntPtr data);
70 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
71 private delegate void WidgetUpdatePeriodChangedEventCallbackType(IntPtr data);
72 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
73 private delegate void WidgetFaultedEventCallbackType(IntPtr data);
76 /// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
77 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
78 /// Most resources are only loaded when the control is placed on the stage.<br />
80 /// <since_tizen> 3 </since_tizen>
81 public event EventHandler<WidgetViewEventArgs> WidgetAdded
85 if (_widgetAddedEventHandler == null)
87 _widgetAddedEventCallback = OnWidgetAdded;
88 WidgetAddedSignal().Connect(_widgetAddedEventCallback);
91 _widgetAddedEventHandler += value;
96 _widgetAddedEventHandler -= value;
98 if (_widgetAddedEventHandler == null && WidgetAddedSignal().Empty() == false)
100 WidgetAddedSignal().Disconnect(_widgetAddedEventCallback);
106 /// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
107 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
108 /// Most resources are only loaded when the control is placed on the stage.<br />
110 /// <since_tizen> 3 </since_tizen>
111 public event EventHandler<WidgetViewEventArgs> WidgetContentUpdated
115 if (_widgetContentUpdatedEventHandler == null)
117 _widgetContentUpdatedEventCallback = OnWidgetContentUpdated;
118 WidgetContentUpdatedSignal().Connect(_widgetContentUpdatedEventCallback);
121 _widgetContentUpdatedEventHandler += value;
126 _widgetContentUpdatedEventHandler -= value;
128 if (_widgetContentUpdatedEventHandler == null && WidgetContentUpdatedSignal().Empty() == false)
130 WidgetContentUpdatedSignal().Disconnect(_widgetContentUpdatedEventCallback);
136 /// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
137 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
138 /// Most resources are only loaded when the control is placed on the stage.<br />
140 /// <since_tizen> 3 </since_tizen>
141 public event EventHandler<WidgetViewEventArgs> WidgetDeleted
145 if (_widgetDeletedEventHandler == null)
147 _widgetDeletedEventCallback = OnWidgetDeleted;
148 WidgetDeletedSignal().Connect(_widgetDeletedEventCallback);
151 _widgetDeletedEventHandler += value;
156 _widgetDeletedEventHandler -= value;
158 if (_widgetDeletedEventHandler == null && WidgetDeletedSignal().Empty() == false)
160 WidgetDeletedSignal().Disconnect(_widgetDeletedEventCallback);
166 /// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
167 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
168 /// Most resources are only loaded when the control is placed on the stage.<br />
170 /// <since_tizen> 3 </since_tizen>
171 public event EventHandler<WidgetViewEventArgs> WidgetCreationAborted
175 if (_widgetCreationAbortedEventHandler == null)
177 _widgetCreationAbortedEventCallback = OnWidgetCreationAborted;
178 WidgetCreationAbortedSignal().Connect(_widgetCreationAbortedEventCallback);
181 _widgetCreationAbortedEventHandler += value;
186 _widgetCreationAbortedEventHandler -= value;
188 if (_widgetCreationAbortedEventHandler == null && WidgetCreationAbortedSignal().Empty() == false)
190 WidgetCreationAbortedSignal().Disconnect(_widgetCreationAbortedEventCallback);
196 /// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
197 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
198 /// Most resources are only loaded when the control is placed on the stage.<br />
200 /// <since_tizen> 3 </since_tizen>
201 public event EventHandler<WidgetViewEventArgs> WidgetUpdatePeriodChanged
205 if (_widgetUpdatePeriodChangedEventHandler == null)
207 _widgetUpdatePeriodChangedEventCallback = OnWidgetUpdatePeriodChanged;
208 WidgetUpdatePeriodChangedSignal().Connect(_widgetUpdatePeriodChangedEventCallback);
211 _widgetUpdatePeriodChangedEventHandler += value;
216 _widgetUpdatePeriodChangedEventHandler -= value;
218 if (_widgetUpdatePeriodChangedEventHandler == null && WidgetUpdatePeriodChangedSignal().Empty() == false)
220 WidgetUpdatePeriodChangedSignal().Disconnect(_widgetUpdatePeriodChangedEventCallback);
226 /// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
227 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
228 /// Most resources are only loaded when the control is placed on the stage.<br />
230 /// <since_tizen> 3 </since_tizen>
231 public event EventHandler<WidgetViewEventArgs> WidgetFaulted
235 if (_widgetFaultedEventHandler == null)
237 _widgetFaultedEventCallback = OnWidgetFaulted;
238 WidgetFaultedSignal().Connect(_widgetFaultedEventCallback);
241 _widgetFaultedEventHandler += value;
246 _widgetFaultedEventHandler -= value;
248 if (_widgetFaultedEventHandler == null && WidgetFaultedSignal().Empty() == false)
250 WidgetFaultedSignal().Disconnect(_widgetFaultedEventCallback);
256 /// Gets the ID of the widget.
258 /// <since_tizen> 3 </since_tizen>
259 public string WidgetID
264 GetProperty(WidgetView.Property.WidgetId).Get(out temp);
270 /// Gets the ID of the instance.
272 /// <since_tizen> 3 </since_tizen>
273 public string InstanceID
278 GetProperty(WidgetView.Property.InstanceId).Get(out temp);
284 /// Gets the content info.
286 /// <since_tizen> 3 </since_tizen>
287 public string ContentInfo
292 GetProperty(WidgetView.Property.ContentInfo).Get(out temp);
300 /// <since_tizen> 3 </since_tizen>
306 GetProperty(WidgetView.Property.TITLE).Get(out temp);
312 /// Gets the update peroid.
314 /// <since_tizen> 3 </since_tizen>
315 public float UpdatePeriod
320 GetProperty(WidgetView.Property.UpdatePeriod).Get(out temp);
326 /// Gets or sets the preview.
328 /// <since_tizen> 3 </since_tizen>
334 GetProperty(WidgetView.Property.PREVIEW).Get(out temp);
339 SetProperty(WidgetView.Property.PREVIEW, new Tizen.NUI.PropertyValue(value));
344 /// Gets or sets the loading text.
346 /// <since_tizen> 3 </since_tizen>
347 public bool LoadingText
352 GetProperty(WidgetView.Property.LoadingText).Get(out temp);
357 SetProperty(WidgetView.Property.LoadingText, new Tizen.NUI.PropertyValue(value));
362 /// Gets or sets whether the widget state is faulted or not.
364 /// <since_tizen> 3 </since_tizen>
365 public bool WidgetStateFaulted
370 GetProperty(WidgetView.Property.WidgetStateFaulted).Get(out temp);
375 SetProperty(WidgetView.Property.WidgetStateFaulted, new Tizen.NUI.PropertyValue(value));
380 /// Gets or sets whether the widget is to delete permanently or not.
382 /// <since_tizen> 3 </since_tizen>
383 public bool PermanentDelete
388 GetProperty(WidgetView.Property.PermanentDelete).Get(out temp);
393 SetProperty(WidgetView.Property.PermanentDelete, new Tizen.NUI.PropertyValue(value));
398 /// Gets or sets retry text.
400 /// <since_tizen> 4 </since_tizen>
401 public PropertyMap RetryText
405 PropertyMap temp = new PropertyMap();
406 GetProperty(WidgetView.Property.RetryText).Get(temp);
411 SetProperty(WidgetView.Property.RetryText, new Tizen.NUI.PropertyValue(value));
416 /// Gets or sets effect.
418 /// <since_tizen> 4 </since_tizen>
419 public PropertyMap Effect
423 PropertyMap temp = new PropertyMap();
424 GetProperty(WidgetView.Property.EFFECT).Get(temp);
429 SetProperty(WidgetView.Property.EFFECT, new Tizen.NUI.PropertyValue(value));
434 /// Pauses a given widget.
436 /// <returns>True on success, false otherwise.</returns>
437 /// <since_tizen> 3 </since_tizen>
438 public bool PauseWidget()
440 bool ret = Interop.WidgetView.PauseWidget(swigCPtr);
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
446 /// Resumes a given widget.
448 /// <returns>True on success, false otherwise.</returns>
449 /// <since_tizen> 3 </since_tizen>
450 public bool ResumeWidget()
452 bool ret = Interop.WidgetView.ResumeWidget(swigCPtr);
453 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
458 /// Cancels the touch event procedure.
459 /// If you call this function after feed the touch down event, the widget will get ON_HOLD events.
460 /// If a widget gets ON_HOLD event, it will not do anything even if you feed touch up event.
462 /// <returns>True on success, false otherwise.</returns>
463 /// <since_tizen> 3 </since_tizen>
464 public bool CancelTouchEvent()
466 bool ret = Interop.WidgetView.CancelTouchEvent(swigCPtr);
467 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
472 /// Activates a widget in the faulted state.
473 /// A widget in faulted state must be activated before adding the widget.
475 /// <since_tizen> 3 </since_tizen>
476 public void ActivateFaultedWidget()
478 Interop.WidgetView.ActivateFaultedWidget(swigCPtr);
479 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 /// Terminate a widget instance.
485 /// <returns>True on success, false otherwise</returns>
486 /// <since_tizen> 4 </since_tizen>
487 public bool TerminateWidget()
489 bool ret = Interop.WidgetView.TerminateWidget(swigCPtr);
490 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
494 internal static WidgetView DownCast(BaseHandle handle)
496 WidgetView ret = new WidgetView(Interop.WidgetView.DownCast(BaseHandle.getCPtr(handle)), true);
497 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
501 internal static WidgetView GetWidgetViewFromPtr(global::System.IntPtr cPtr)
503 WidgetView ret = new WidgetView(cPtr, false);
504 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
508 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WidgetView obj)
510 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
513 internal WidgetView Assign(WidgetView handle)
515 WidgetView ret = new WidgetView(Interop.WidgetView.Assign(swigCPtr, WidgetView.getCPtr(handle)), false);
516 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
520 internal WidgetViewSignal WidgetAddedSignal()
522 WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetAddedSignal(swigCPtr), false);
523 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
527 internal WidgetViewSignal WidgetDeletedSignal()
529 WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetDeletedSignal(swigCPtr), false);
530 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
534 internal WidgetViewSignal WidgetCreationAbortedSignal()
536 WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetCreationAbortedSignal(swigCPtr), false);
537 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
541 internal WidgetViewSignal WidgetContentUpdatedSignal()
543 WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetContentUpdatedSignal(swigCPtr), false);
544 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
548 internal WidgetViewSignal WidgetUpdatePeriodChangedSignal()
550 WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetUpdatePeriodChangedSignal(swigCPtr), false);
551 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
555 internal WidgetViewSignal WidgetFaultedSignal()
557 WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetFaultedSignal(swigCPtr), false);
558 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
563 /// To make the Button instance be disposed.
565 /// <since_tizen> 3 </since_tizen>
566 protected override void Dispose(DisposeTypes type)
573 //Release your own unmanaged resources here.
574 //You should not access any managed member here except static instance.
575 //because the execution order of Finalizes is non-deterministic.
577 if (_widgetAddedEventCallback != null)
579 this.WidgetAddedSignal().Disconnect(_widgetAddedEventCallback);
582 if (_widgetContentUpdatedEventCallback != null)
584 this.WidgetContentUpdatedSignal().Disconnect(_widgetContentUpdatedEventCallback);
587 if (_widgetCreationAbortedEventCallback != null)
589 this.WidgetCreationAbortedSignal().Disconnect(_widgetCreationAbortedEventCallback);
592 if (_widgetDeletedEventCallback != null)
594 this.WidgetDeletedSignal().Disconnect(_widgetDeletedEventCallback);
597 if (_widgetFaultedEventCallback != null)
599 this.WidgetFaultedSignal().Disconnect(_widgetFaultedEventCallback);
602 if (_widgetUpdatePeriodChangedEventCallback != null)
604 this.WidgetUpdatePeriodChangedSignal().Disconnect(_widgetUpdatePeriodChangedEventCallback);
610 /// This will not be public opened.
611 [EditorBrowsable(EditorBrowsableState.Never)]
612 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
614 Interop.WidgetView.DeleteWidgetView(swigCPtr);
617 // Callback for WidgetView WidgetAdded signal
618 private void OnWidgetAdded(IntPtr data)
620 WidgetViewEventArgs e = new WidgetViewEventArgs();
623 e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
626 if (_widgetAddedEventHandler != null)
628 _widgetAddedEventHandler(this, e);
632 // Callback for WidgetView WidgetDeleted signal
633 private void OnWidgetDeleted(IntPtr data)
635 WidgetViewEventArgs e = new WidgetViewEventArgs();
638 e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
641 if (_widgetDeletedEventHandler != null)
643 _widgetDeletedEventHandler(this, e);
647 // Callback for WidgetView WidgetCreationAborted signal
648 private void OnWidgetCreationAborted(IntPtr data)
650 WidgetViewEventArgs e = new WidgetViewEventArgs();
653 e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
656 if (_widgetCreationAbortedEventHandler != null)
658 _widgetCreationAbortedEventHandler(this, e);
664 // Callback for WidgetView WidgetContentUpdated signal
665 private void OnWidgetContentUpdated(IntPtr data)
667 WidgetViewEventArgs e = new WidgetViewEventArgs();
670 e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
673 if (_widgetContentUpdatedEventHandler != null)
675 _widgetContentUpdatedEventHandler(this, e);
679 // Callback for WidgetView WidgetUpdatePeriodChanged signal
680 private void OnWidgetUpdatePeriodChanged(IntPtr data)
682 WidgetViewEventArgs e = new WidgetViewEventArgs();
685 e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
688 if (_widgetUpdatePeriodChangedEventHandler != null)
690 _widgetUpdatePeriodChangedEventHandler(this, e);
694 // Callback for WidgetView WidgetFaulted signal
695 private void OnWidgetFaulted(IntPtr data)
697 WidgetViewEventArgs e = new WidgetViewEventArgs();
700 e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
703 if (_widgetFaultedEventHandler != null)
705 _widgetFaultedEventHandler(this, e);
710 /// Event arguments of the widget view.
712 /// <since_tizen> 3 </since_tizen>
713 public class WidgetViewEventArgs : EventArgs
715 private WidgetView _widgetView;
720 /// <since_tizen> 3 </since_tizen>
721 public WidgetView WidgetView
734 internal new class Property
736 internal static readonly int WidgetId = Interop.WidgetView.WidgetIdGet();
737 internal static readonly int InstanceId = Interop.WidgetView.InstanceIdGet();
738 internal static readonly int ContentInfo = Interop.WidgetView.ContentInfoGet();
739 internal static readonly int TITLE = Interop.WidgetView.TitleGet();
740 internal static readonly int UpdatePeriod = Interop.WidgetView.UpdatePeriodGet();
741 internal static readonly int PREVIEW = Interop.WidgetView.PreviewGet();
742 internal static readonly int LoadingText = Interop.WidgetView.LoadingTextGet();
743 internal static readonly int WidgetStateFaulted = Interop.WidgetView.WidgetStateFaultedGet();
744 internal static readonly int PermanentDelete = Interop.WidgetView.PermanentDeleteGet();
745 internal static readonly int RetryText = Interop.WidgetView.RetryTextGet();
746 internal static readonly int EFFECT = Interop.WidgetView.EffectGet();