From e10209f8e419eb17ac3cf343d3b2d91784d9adbf Mon Sep 17 00:00:00 2001 From: "xb.teng" Date: Tue, 20 Jun 2017 16:04:08 +0800 Subject: [PATCH] manual binding for FocusManager and Window There are some changes: 1. Add MoveFocusBackward api for FocusManager; 2. Add Resized event for Window. Change-Id: I9c16790f9b0073e6706ea56436e79e9c5176717f Signed-off-by: xb.teng --- .../NUISamples.TizenTV/examples/dali-test.cs | 43 +++++++ .../NUISamples.TizenTV/examples/hello-world.cs | 5 + Tizen.NUI/Tizen.NUI.csproj | 1 + Tizen.NUI/src/internal/ManualPINVOKE.cs | 27 ++++ Tizen.NUI/src/internal/ResizedSignal.cs | 140 +++++++++++++++++++++ Tizen.NUI/src/public/FocusManager.cs | 9 ++ Tizen.NUI/src/public/Window.cs | 77 ++++++++++++ 7 files changed, 302 insertions(+) create mode 100755 Tizen.NUI/src/internal/ResizedSignal.cs diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/dali-test.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/dali-test.cs index c5c42fa..6a43310 100755 --- a/NUISamples/NUISamples/NUISamples.TizenTV/examples/dali-test.cs +++ b/NUISamples/NUISamples/NUISamples.TizenTV/examples/dali-test.cs @@ -131,6 +131,9 @@ namespace DaliTest VisibilityChangeTest(); ResourceReadyTest(); + + ViewFocusTest(); + WindowDevelPropertyTest(); Animatable handle = new Animatable(); @@ -587,6 +590,46 @@ namespace DaliTest Window.Instance.Add(image); } + public void ViewFocusTest() + { + View view1 = new View(); + view1.BackgroundColor = Color.Red; + view1.Size2D = new Size2D(80, 50); + view1.ParentOrigin = ParentOrigin.CenterLeft; + view1.PivotPoint = PivotPoint.CenterLeft; + view1.Position = new Position(10.0f, 50.0f, 0.0f); + view1.Focusable = true; + View view2 = new View(); + view2.BackgroundColor = Color.Cyan; + view2.Size2D = new Size2D(80, 50); + view2.ParentOrigin = ParentOrigin.CenterLeft; + view2.PivotPoint = PivotPoint.CenterLeft; + view2.Position = new Position(100.0f, 50.0f, 0.0f); + view2.Focusable = true; + view1.RightFocusableView = view2; + view2.LeftFocusableView = view1; + Window.Add(view1); + Window.Add(view2); + FocusManager.Instance.SetCurrentFocusView(view1); + + PushButton button = new PushButton(); + button.LabelText = "Focus Back"; + button.Size2D = new Size2D(150, 50); + button.ParentOrigin = ParentOrigin.CenterLeft; + button.PivotPoint = PivotPoint.CenterLeft; + button.Position = new Position(190.0f, 50.0f, 0.0f); + + button.Focusable = true; + view2.RightFocusableView = button; + + button.Pressed += (obj, e) => + { + FocusManager.Instance.MoveFocusBackward(); + return true; + }; + Window.Add(button); + } + public void WindowDevelPropertyTest() { Window window = Window.Instance; diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/hello-world.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/hello-world.cs index 71f2a62..ea3a59e 100755 --- a/NUISamples/NUISamples/NUISamples.TizenTV/examples/hello-world.cs +++ b/NUISamples/NUISamples/NUISamples.TizenTV/examples/hello-world.cs @@ -55,6 +55,11 @@ namespace HelloWorldTest window.BackgroundColor = Color.White; window.Touched += OnWindowTouched; window.KeyPressed += OnWindowKeyEvent; + window.Resized += (obj, e) => + { + Tizen.Log.Debug("NUI", "Height: " + e.Height); + Tizen.Log.Debug("NUI", "Width: " + e.Width); + }; TextLabel pixelLabel = new TextLabel("Test Pixel Size 32.0f"); pixelLabel.Position2D = new Position2D(10, 10); diff --git a/Tizen.NUI/Tizen.NUI.csproj b/Tizen.NUI/Tizen.NUI.csproj index 760a221..37d690b 100755 --- a/Tizen.NUI/Tizen.NUI.csproj +++ b/Tizen.NUI/Tizen.NUI.csproj @@ -168,6 +168,7 @@ + diff --git a/Tizen.NUI/src/internal/ManualPINVOKE.cs b/Tizen.NUI/src/internal/ManualPINVOKE.cs index 239784b..7b257e1 100755 --- a/Tizen.NUI/src/internal/ManualPINVOKE.cs +++ b/Tizen.NUI/src/internal/ManualPINVOKE.cs @@ -61,6 +61,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_KeyboardFocusManager_GetFocusIndicatorActor")] public static extern global::System.IntPtr FocusManager_GetFocusIndicatorActor(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_KeyboardFocusManager_MoveFocusBackward")] + public static extern void FocusManager_MoveFocusBackward(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_KeyboardFocusManager_PreFocusChangeSignal")] public static extern global::System.IntPtr FocusManager_PreFocusChangeSignal(global::System.Runtime.InteropServices.HandleRef jarg1); @@ -692,5 +695,29 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_delete_ScrollStateChangedSignal")] public static extern void delete_ScrollStateChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + // For windows resized signal + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_Window_ResizedSignal")] + public static extern global::System.IntPtr Window_ResizedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_ResizedSignal_Empty")] + public static extern bool ResizedSignal_Empty(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_ResizedSignal_GetConnectionCount")] + public static extern uint ResizedSignal_GetConnectionCount(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_ResizedSignal_Connect")] + public static extern void ResizedSignal_Connect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_ResizedSignal_Disconnect")] + public static extern void ResizedSignal_Disconnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_ResizedSignal_Emit")] + public static extern void ResizedSignal_Emit(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2, int jarg3); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_new_ResizedSignal")] + public static extern global::System.IntPtr new_ResizedSignal(); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_delete_ResizedSignal")] + public static extern void delete_ResizedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); } } diff --git a/Tizen.NUI/src/internal/ResizedSignal.cs b/Tizen.NUI/src/internal/ResizedSignal.cs new file mode 100755 index 0000000..0c8a61b --- /dev/null +++ b/Tizen.NUI/src/internal/ResizedSignal.cs @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// +// This file was automatically generated by SWIG (http://www.swig.org). +// Version 3.0.12 +// +// Do not make changes to this file unless you know what you are doing--modify +// the SWIG interface file instead. +//------------------------------------------------------------------------------ + +namespace Tizen.NUI +{ + + internal class ResizedSignal : global::System.IDisposable + { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + protected bool swigCMemOwn; + + internal ResizedSignal(global::System.IntPtr cPtr, bool cMemoryOwn) + { + swigCMemOwn = cMemoryOwn; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ResizedSignal obj) + { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } + + //A Flag to check who called Dispose(). (By User or DisposeQueue) + private bool isDisposeQueued = false; + //A Flat to check if it is already disposed. + protected bool disposed = false; + + ~ResizedSignal() + { + if (!isDisposeQueued) + { + isDisposeQueued = true; + DisposeQueue.Instance.Add(this); + } + } + + public void Dispose() + { + //Throw excpetion if Dispose() is called in separate thread. + if (!Window.IsInstalled()) + { + throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread."); + } + + if (isDisposeQueued) + { + Dispose(DisposeTypes.Implicit); + } + else + { + Dispose(DisposeTypes.Explicit); + System.GC.SuppressFinalize(this); + } + } + + protected virtual void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (type == DisposeTypes.Explicit) + { + //Called by User + //Release your own managed resources here. + //You should release all of your own disposable objects here. + } + + //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 (swigCPtr.Handle != global::System.IntPtr.Zero) + { + if (swigCMemOwn) + { + swigCMemOwn = false; + NDalicManualPINVOKE.delete_ResizedSignal(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + + disposed = true; + } + + + public bool Empty() + { + bool ret = NDalicManualPINVOKE.ResizedSignal_Empty(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + public uint GetConnectionCount() + { + uint ret = NDalicManualPINVOKE.ResizedSignal_GetConnectionCount(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + public void Connect(System.Delegate func) + { + System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); + { + NDalicManualPINVOKE.ResizedSignal_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + + public void Disconnect(System.Delegate func) + { + System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); + { + NDalicManualPINVOKE.ResizedSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + + public void Emit(int arg1, int arg2) + { + NDalicManualPINVOKE.ResizedSignal_Emit(swigCPtr, arg1, arg2); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + public ResizedSignal() : this(NDalicManualPINVOKE.new_ResizedSignal(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + } + +} diff --git a/Tizen.NUI/src/public/FocusManager.cs b/Tizen.NUI/src/public/FocusManager.cs index b1cfcbc..4ebae95 100755 --- a/Tizen.NUI/src/public/FocusManager.cs +++ b/Tizen.NUI/src/public/FocusManager.cs @@ -487,6 +487,15 @@ namespace Tizen.NUI } /// + /// Move the focus to prev focused view. + /// + public void MoveFocusBackward() + { + NDalicManualPINVOKE.FocusManager_MoveFocusBackward(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// /// Sets/Gets the status of whether the focus movement should be looped within the same focus group.
/// The focus movement is not looped by default.
///
diff --git a/Tizen.NUI/src/public/Window.cs b/Tizen.NUI/src/public/Window.cs index 68585f2..9718abd 100755 --- a/Tizen.NUI/src/public/Window.cs +++ b/Tizen.NUI/src/public/Window.cs @@ -677,6 +677,13 @@ namespace Tizen.NUI return ret; } + internal ResizedSignal ResizedSignal() + { + ResizedSignal ret = new ResizedSignal(NDalicManualPINVOKE.Window_ResizedSignal(stageCPtr), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + internal static Vector4 DEFAULT_BACKGROUND_COLOR { get @@ -1171,6 +1178,76 @@ namespace Tizen.NUI } } + public class ResizedEventArgs : EventArgs + { + int _width; + int _height; + + public int Width + { + get + { + return _width; + } + set + { + _width = value; + } + } + + public int Height + { + get + { + return _height; + } + set + { + _height = value; + } + } + } + + private WindowResizedEventCallbackType _windowResizedEventCallback; + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void WindowResizedEventCallbackType(int width, int height); + private event EventHandler _windowResizedEventHandler; + + public event EventHandler Resized + { + add + { + if (_windowResizedEventHandler == null) + { + _windowResizedEventCallback = OnResized; + ResizedSignal().Connect(_windowResizedEventCallback); + } + + _windowResizedEventHandler += value; + } + remove + { + _windowResizedEventHandler -= value; + + if (_windowResizedEventHandler == null && ResizedSignal().Empty() == false && _windowResizedEventCallback != null) + { + ResizedSignal().Disconnect(_windowResizedEventCallback); + } + } + } + + private void OnResized(int width, int height) + { + ResizedEventArgs e = new ResizedEventArgs(); + e.Width = width; + e.Height = height; + + if (_windowResizedEventHandler != null) + { + _windowResizedEventHandler(this, e); + } + } + /// /// Window size property (read-only). /// -- 2.7.4