/*
* Copyright(c) 2017 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.ComponentModel;
namespace Tizen.NUI
{
using System;
using System.Runtime.InteropServices;
using Tizen.NUI.BaseComponents;
///
/// The WidgetView is a class for displaying the widget image and controlling the widget.
/// Input events that the WidgetView gets are delivered to the widget.
///
/// 3
public class WidgetView : View
{
private EventHandler _widgetAddedEventHandler;
private WidgetAddedEventCallbackType _widgetAddedEventCallback;
private EventHandler _widgetContentUpdatedEventHandler;
private WidgetContentUpdatedEventCallbackType _widgetContentUpdatedEventCallback;
private EventHandler _widgetDeletedEventHandler;
private WidgetDeletedEventCallbackType _widgetDeletedEventCallback;
private EventHandler _widgetCreationAbortedEventHandler;
private WidgetCreationAbortedEventCallbackType _widgetCreationAbortedEventCallback;
private EventHandler _widgetUpdatePeriodChangedEventHandler;
private WidgetUpdatePeriodChangedEventCallbackType _widgetUpdatePeriodChangedEventCallback;
private EventHandler _widgetFaultedEventHandler;
private WidgetFaultedEventCallbackType _widgetFaultedEventCallback;
///
/// Creates a new WidgetView.
///
/// 3
public WidgetView(string widgetId, string contentInfo, int width, int height, float updatePeriod) : this(Interop.WidgetView.New(widgetId, contentInfo, width, height, updatePeriod), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal WidgetView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.WidgetView.Upcast(cPtr), cMemoryOwn)
{
}
internal WidgetView(WidgetView handle) : this(Interop.WidgetView.NewWidgetView(WidgetView.getCPtr(handle)), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void WidgetAddedEventCallbackType(IntPtr data);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void WidgetContentUpdatedEventCallbackType(IntPtr data);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void WidgetDeletedEventCallbackType(IntPtr data);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void WidgetCreationAbortedEventCallbackType(IntPtr data);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void WidgetUpdatePeriodChangedEventCallbackType(IntPtr data);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void WidgetFaultedEventCallbackType(IntPtr data);
///
/// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted after all resources required by a control are loaded and ready.
/// Most resources are only loaded when the control is placed on the stage.
///
/// 3
public event EventHandler WidgetAdded
{
add
{
if (_widgetAddedEventHandler == null)
{
_widgetAddedEventCallback = OnWidgetAdded;
WidgetAddedSignal().Connect(_widgetAddedEventCallback);
}
_widgetAddedEventHandler += value;
}
remove
{
_widgetAddedEventHandler -= value;
if (_widgetAddedEventHandler == null && WidgetAddedSignal().Empty() == false)
{
WidgetAddedSignal().Disconnect(_widgetAddedEventCallback);
}
}
}
///
/// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted after all resources required by a control are loaded and ready.
/// Most resources are only loaded when the control is placed on the stage.
///
/// 3
public event EventHandler WidgetContentUpdated
{
add
{
if (_widgetContentUpdatedEventHandler == null)
{
_widgetContentUpdatedEventCallback = OnWidgetContentUpdated;
WidgetContentUpdatedSignal().Connect(_widgetContentUpdatedEventCallback);
}
_widgetContentUpdatedEventHandler += value;
}
remove
{
_widgetContentUpdatedEventHandler -= value;
if (_widgetContentUpdatedEventHandler == null && WidgetContentUpdatedSignal().Empty() == false)
{
WidgetContentUpdatedSignal().Disconnect(_widgetContentUpdatedEventCallback);
}
}
}
///
/// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted after all resources required by a control are loaded and ready.
/// Most resources are only loaded when the control is placed on the stage.
///
/// 3
public event EventHandler WidgetDeleted
{
add
{
if (_widgetDeletedEventHandler == null)
{
_widgetDeletedEventCallback = OnWidgetDeleted;
WidgetDeletedSignal().Connect(_widgetDeletedEventCallback);
}
_widgetDeletedEventHandler += value;
}
remove
{
_widgetDeletedEventHandler -= value;
if (_widgetDeletedEventHandler == null && WidgetDeletedSignal().Empty() == false)
{
WidgetDeletedSignal().Disconnect(_widgetDeletedEventCallback);
}
}
}
///
/// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted after all resources required by a control are loaded and ready.
/// Most resources are only loaded when the control is placed on the stage.
///
/// 3
public event EventHandler WidgetCreationAborted
{
add
{
if (_widgetCreationAbortedEventHandler == null)
{
_widgetCreationAbortedEventCallback = OnWidgetCreationAborted;
WidgetCreationAbortedSignal().Connect(_widgetCreationAbortedEventCallback);
}
_widgetCreationAbortedEventHandler += value;
}
remove
{
_widgetCreationAbortedEventHandler -= value;
if (_widgetCreationAbortedEventHandler == null && WidgetCreationAbortedSignal().Empty() == false)
{
WidgetCreationAbortedSignal().Disconnect(_widgetCreationAbortedEventCallback);
}
}
}
///
/// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted after all resources required by a control are loaded and ready.
/// Most resources are only loaded when the control is placed on the stage.
///
/// 3
public event EventHandler WidgetUpdatePeriodChanged
{
add
{
if (_widgetUpdatePeriodChangedEventHandler == null)
{
_widgetUpdatePeriodChangedEventCallback = OnWidgetUpdatePeriodChanged;
WidgetUpdatePeriodChangedSignal().Connect(_widgetUpdatePeriodChangedEventCallback);
}
_widgetUpdatePeriodChangedEventHandler += value;
}
remove
{
_widgetUpdatePeriodChangedEventHandler -= value;
if (_widgetUpdatePeriodChangedEventHandler == null && WidgetUpdatePeriodChangedSignal().Empty() == false)
{
WidgetUpdatePeriodChangedSignal().Disconnect(_widgetUpdatePeriodChangedEventCallback);
}
}
}
///
/// An event for the ResourceReady signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted after all resources required by a control are loaded and ready.
/// Most resources are only loaded when the control is placed on the stage.
///
/// 3
public event EventHandler WidgetFaulted
{
add
{
if (_widgetFaultedEventHandler == null)
{
_widgetFaultedEventCallback = OnWidgetFaulted;
WidgetFaultedSignal().Connect(_widgetFaultedEventCallback);
}
_widgetFaultedEventHandler += value;
}
remove
{
_widgetFaultedEventHandler -= value;
if (_widgetFaultedEventHandler == null && WidgetFaultedSignal().Empty() == false)
{
WidgetFaultedSignal().Disconnect(_widgetFaultedEventCallback);
}
}
}
///
/// Gets the ID of the widget.
///
/// 3
public string WidgetID
{
get
{
string temp;
GetProperty(WidgetView.Property.WidgetId).Get(out temp);
return temp;
}
}
///
/// Gets the ID of the instance.
///
/// 3
public string InstanceID
{
get
{
string temp;
GetProperty(WidgetView.Property.InstanceId).Get(out temp);
return temp;
}
}
///
/// Gets the content info.
///
/// 3
public string ContentInfo
{
get
{
string temp;
GetProperty(WidgetView.Property.ContentInfo).Get(out temp);
return temp;
}
}
///
/// Gets the title.
///
/// 3
public string Title
{
get
{
string temp;
GetProperty(WidgetView.Property.TITLE).Get(out temp);
return temp;
}
}
///
/// Gets the update peroid.
///
/// 3
public float UpdatePeriod
{
get
{
float temp;
GetProperty(WidgetView.Property.UpdatePeriod).Get(out temp);
return temp;
}
}
///
/// Gets or sets the preview.
///
/// 3
public bool Preview
{
get
{
bool temp;
GetProperty(WidgetView.Property.PREVIEW).Get(out temp);
return temp;
}
set
{
SetProperty(WidgetView.Property.PREVIEW, new Tizen.NUI.PropertyValue(value));
}
}
///
/// Gets or sets the loading text.
///
/// 3
public bool LoadingText
{
get
{
bool temp;
GetProperty(WidgetView.Property.LoadingText).Get(out temp);
return temp;
}
set
{
SetProperty(WidgetView.Property.LoadingText, new Tizen.NUI.PropertyValue(value));
}
}
///
/// Gets or sets whether the widget state is faulted or not.
///
/// 3
public bool WidgetStateFaulted
{
get
{
bool temp;
GetProperty(WidgetView.Property.WidgetStateFaulted).Get(out temp);
return temp;
}
set
{
SetProperty(WidgetView.Property.WidgetStateFaulted, new Tizen.NUI.PropertyValue(value));
}
}
///
/// Gets or sets whether the widget is to delete permanently or not.
///
/// 3
public bool PermanentDelete
{
get
{
bool temp;
GetProperty(WidgetView.Property.PermanentDelete).Get(out temp);
return temp;
}
set
{
SetProperty(WidgetView.Property.PermanentDelete, new Tizen.NUI.PropertyValue(value));
}
}
///
/// Gets or sets retry text.
///
/// 4
public PropertyMap RetryText
{
get
{
PropertyMap temp = new PropertyMap();
GetProperty(WidgetView.Property.RetryText).Get(temp);
return temp;
}
set
{
SetProperty(WidgetView.Property.RetryText, new Tizen.NUI.PropertyValue(value));
}
}
///
/// Gets or sets effect.
///
/// 4
public PropertyMap Effect
{
get
{
PropertyMap temp = new PropertyMap();
GetProperty(WidgetView.Property.EFFECT).Get(temp);
return temp;
}
set
{
SetProperty(WidgetView.Property.EFFECT, new Tizen.NUI.PropertyValue(value));
}
}
///
/// Pauses a given widget.
///
/// True on success, false otherwise.
/// 3
public bool PauseWidget()
{
bool ret = Interop.WidgetView.PauseWidget(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Resumes a given widget.
///
/// True on success, false otherwise.
/// 3
public bool ResumeWidget()
{
bool ret = Interop.WidgetView.ResumeWidget(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Cancels the touch event procedure.
/// If you call this function after feed the touch down event, the widget will get ON_HOLD events.
/// If a widget gets ON_HOLD event, it will not do anything even if you feed touch up event.
///
/// True on success, false otherwise.
/// 3
public bool CancelTouchEvent()
{
bool ret = Interop.WidgetView.CancelTouchEvent(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Activates a widget in the faulted state.
/// A widget in faulted state must be activated before adding the widget.
///
/// 3
public void ActivateFaultedWidget()
{
Interop.WidgetView.ActivateFaultedWidget(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Terminate a widget instance.
///
/// True on success, false otherwise
/// 4
public bool TerminateWidget()
{
bool ret = Interop.WidgetView.TerminateWidget(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal static WidgetView DownCast(BaseHandle handle)
{
WidgetView ret = new WidgetView(Interop.WidgetView.DownCast(BaseHandle.getCPtr(handle)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal static WidgetView GetWidgetViewFromPtr(global::System.IntPtr cPtr)
{
WidgetView ret = new WidgetView(cPtr, false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WidgetView obj)
{
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
internal WidgetView Assign(WidgetView handle)
{
WidgetView ret = new WidgetView(Interop.WidgetView.Assign(swigCPtr, WidgetView.getCPtr(handle)), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal WidgetViewSignal WidgetAddedSignal()
{
WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetAddedSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal WidgetViewSignal WidgetDeletedSignal()
{
WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetDeletedSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal WidgetViewSignal WidgetCreationAbortedSignal()
{
WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetCreationAbortedSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal WidgetViewSignal WidgetContentUpdatedSignal()
{
WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetContentUpdatedSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal WidgetViewSignal WidgetUpdatePeriodChangedSignal()
{
WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetUpdatePeriodChangedSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal WidgetViewSignal WidgetFaultedSignal()
{
WidgetViewSignal ret = new WidgetViewSignal(Interop.WidgetView.WidgetFaultedSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// To make the Button instance be disposed.
///
/// 3
protected override void Dispose(DisposeTypes type)
{
if (disposed)
{
return;
}
//Release your own unmanaged resources here.
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
if (_widgetAddedEventCallback != null)
{
this.WidgetAddedSignal().Disconnect(_widgetAddedEventCallback);
}
if (_widgetContentUpdatedEventCallback != null)
{
this.WidgetContentUpdatedSignal().Disconnect(_widgetContentUpdatedEventCallback);
}
if (_widgetCreationAbortedEventCallback != null)
{
this.WidgetCreationAbortedSignal().Disconnect(_widgetCreationAbortedEventCallback);
}
if (_widgetDeletedEventCallback != null)
{
this.WidgetDeletedSignal().Disconnect(_widgetDeletedEventCallback);
}
if (_widgetFaultedEventCallback != null)
{
this.WidgetFaultedSignal().Disconnect(_widgetFaultedEventCallback);
}
if (_widgetUpdatePeriodChangedEventCallback != null)
{
this.WidgetUpdatePeriodChangedSignal().Disconnect(_widgetUpdatePeriodChangedEventCallback);
}
base.Dispose(type);
}
/// This will not be public opened.
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
{
Interop.WidgetView.DeleteWidgetView(swigCPtr);
}
// Callback for WidgetView WidgetAdded signal
private void OnWidgetAdded(IntPtr data)
{
WidgetViewEventArgs e = new WidgetViewEventArgs();
if (data != null)
{
e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
}
if (_widgetAddedEventHandler != null)
{
_widgetAddedEventHandler(this, e);
}
}
// Callback for WidgetView WidgetDeleted signal
private void OnWidgetDeleted(IntPtr data)
{
WidgetViewEventArgs e = new WidgetViewEventArgs();
if (data != null)
{
e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
}
if (_widgetDeletedEventHandler != null)
{
_widgetDeletedEventHandler(this, e);
}
}
// Callback for WidgetView WidgetCreationAborted signal
private void OnWidgetCreationAborted(IntPtr data)
{
WidgetViewEventArgs e = new WidgetViewEventArgs();
if (data != null)
{
e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
}
if (_widgetCreationAbortedEventHandler != null)
{
_widgetCreationAbortedEventHandler(this, e);
}
}
// Callback for WidgetView WidgetContentUpdated signal
private void OnWidgetContentUpdated(IntPtr data)
{
WidgetViewEventArgs e = new WidgetViewEventArgs();
if (data != null)
{
e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
}
if (_widgetContentUpdatedEventHandler != null)
{
_widgetContentUpdatedEventHandler(this, e);
}
}
// Callback for WidgetView WidgetUpdatePeriodChanged signal
private void OnWidgetUpdatePeriodChanged(IntPtr data)
{
WidgetViewEventArgs e = new WidgetViewEventArgs();
if (data != null)
{
e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
}
if (_widgetUpdatePeriodChangedEventHandler != null)
{
_widgetUpdatePeriodChangedEventHandler(this, e);
}
}
// Callback for WidgetView WidgetFaulted signal
private void OnWidgetFaulted(IntPtr data)
{
WidgetViewEventArgs e = new WidgetViewEventArgs();
if (data != null)
{
e.WidgetView = WidgetView.GetWidgetViewFromPtr(data);
}
if (_widgetFaultedEventHandler != null)
{
_widgetFaultedEventHandler(this, e);
}
}
///
/// Event arguments of the widget view.
///
/// 3
public class WidgetViewEventArgs : EventArgs
{
private WidgetView _widgetView;
///
/// The widet view.
///
/// 3
public WidgetView WidgetView
{
get
{
return _widgetView;
}
set
{
_widgetView = value;
}
}
}
internal new class Property
{
internal static readonly int WidgetId = Interop.WidgetView.WidgetIdGet();
internal static readonly int InstanceId = Interop.WidgetView.InstanceIdGet();
internal static readonly int ContentInfo = Interop.WidgetView.ContentInfoGet();
internal static readonly int TITLE = Interop.WidgetView.TitleGet();
internal static readonly int UpdatePeriod = Interop.WidgetView.UpdatePeriodGet();
internal static readonly int PREVIEW = Interop.WidgetView.PreviewGet();
internal static readonly int LoadingText = Interop.WidgetView.LoadingTextGet();
internal static readonly int WidgetStateFaulted = Interop.WidgetView.WidgetStateFaultedGet();
internal static readonly int PermanentDelete = Interop.WidgetView.PermanentDeleteGet();
internal static readonly int RetryText = Interop.WidgetView.RetryTextGet();
internal static readonly int EFFECT = Interop.WidgetView.EffectGet();
}
}
}