/*
* 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;
using System.ComponentModel;
namespace Tizen.NUI
{
///
/// Widget provides some common functionality required by all custom widget.
///
/// 4
public class Widget : BaseHandle
{
internal WidgetImpl widgetImpl;
///
/// Creates a Widget handle.
///
/// 4
public Widget() : this(new WidgetImpl(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal Widget(WidgetImpl widgetImpl, bool swigCMemOwn) : this(Interop.Widget.Widget_New__SWIG_1(WidgetImpl.getCPtr(widgetImpl)), swigCMemOwn)
{
this.widgetImpl = widgetImpl;
widgetImpl.WidgetInstanceCreated += OnWidgetInstanceCreated;
widgetImpl.WidgetInstanceDestroyed += OnWidgetInstanceDestroyed;
widgetImpl.WidgetInstancePaused += OnWidgetInstancePaused;
widgetImpl.WidgetInstanceResumed += OnWidgetInstanceResumed;
widgetImpl.WidgetInstanceResized += OnWidgetInstanceResized;
widgetImpl.WidgetInstanceUpdated += OnWidgetInstanceUpdated;
(WidgetApplication.Instance as WidgetApplication)?.AddWidgetInstance(this);
}
internal Widget(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Widget.Widget_SWIGUpcast(cPtr), cMemoryOwn)
{
}
///
/// Enumeration for termination type of widget
///
/// 4
public enum TerminationType
{
///
/// User deleted this widget from the viewer
///
/// 4
Permanent,
///
/// Widget is deleted because of other reasons (e.g. widget process is terminated temporarily by system)
///
/// 4
Temporary
}
///
/// Set content info to WidgetView.
///
/// Content info is kind of context information which contains current status of widget.
/// 4
public void SetContentInfo(string contentInfo)
{
widgetImpl.SetContentInfo(contentInfo);
}
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Widget obj)
{
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
internal System.IntPtr GetIntPtr()
{
return swigCPtr.Handle;
}
internal Widget Assign(Widget widget)
{
Widget ret = new Widget(Interop.Widget.Widget_Assign(swigCPtr, Widget.getCPtr(widget)), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// The user should override this function to determine when they create widget.
///
/// Information from WidgetView for creating. It contains previous status of widget which is sent by SetContentInfo before.
/// Window for widget
/// 4
protected virtual void OnCreate(string contentInfo, Window window)
{
}
///
/// The user should override this function to determine when they terminate widget.
///
/// Data from WidgetView for deleting
/// Termination type. When user delete widget view, termination type is PERMANENT.
/// 4
protected virtual void OnTerminate(string contentInfo, Widget.TerminationType type)
{
}
///
/// The user should override this function to determine when they pause widget.
///
/// 4
protected virtual void OnPause()
{
}
///
/// The user should override this function to determine when they resume widget.
///
/// 4
protected virtual void OnResume()
{
}
///
/// The user should override this function to determine when they resize widget.
///
/// Window for widget
/// 4
protected virtual void OnResize(Window window)
{
}
///
/// The user should override this function to determine when they update widget.
///
/// Data from WidgetView for updating
/// Although the widget is paused, if it is true, the widget can be updated
/// 4
protected virtual void OnUpdate(string contentInfo, int force)
{
}
/// This will not be public opened.
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
{
Interop.Widget.delete_Widget(swigCPtr);
}
private void OnWidgetInstanceCreated(object sender, WidgetImpl.WIdgetInstanceOnCreateArgs e)
{
OnCreate(e.ContentInfo, e.Window);
}
private void OnWidgetInstanceDestroyed(object sender, WidgetImpl.WIdgetInstanceOnDestroyArgs e)
{
OnTerminate(e.ContentInfo, e.TerminateType);
}
private void OnWidgetInstancePaused(object sender, EventArgs e)
{
OnPause();
}
private void OnWidgetInstanceResumed(object sender, EventArgs e)
{
OnResume();
}
private void OnWidgetInstanceResized(object sender, WidgetImpl.WidgetInstanceOnResizeArgs e)
{
OnResize(e.Window);
}
private void OnWidgetInstanceUpdated(object sender, WidgetImpl.WidgetInstanceOnUpdateArgs e)
{
OnUpdate(e.ContentInfo, e.Force);
}
}
}