From f4f1f421c081e4007d3e1d52211ed3db72707ecd Mon Sep 17 00:00:00 2001 From: "dongsug.song" Date: Wed, 20 Sep 2017 13:26:26 +0900 Subject: [PATCH] [NUI] Added bindings for signal, properties for layout direction Signed-off-by: Feng Jin Change-Id: I2226f9ce181ae31a13fa16ca2d0c955c4a684d0e --- NUIsamples/NUIsamples/src/examples/hello-world.cs | 5 +- src/Tizen.NUI/src/internal/ManualPINVOKE.cs | 34 +++++ .../internal/ViewLayoutDirectionChangedSignal.cs | 146 +++++++++++++++++++++ src/Tizen.NUI/src/public/BaseComponents/View.cs | 141 +++++++++++++++++++- 4 files changed, 321 insertions(+), 5 deletions(-) create mode 100755 src/Tizen.NUI/src/internal/ViewLayoutDirectionChangedSignal.cs diff --git a/NUIsamples/NUIsamples/src/examples/hello-world.cs b/NUIsamples/NUIsamples/src/examples/hello-world.cs index b2bbab0..78895a9 100755 --- a/NUIsamples/NUIsamples/src/examples/hello-world.cs +++ b/NUIsamples/NUIsamples/src/examples/hello-world.cs @@ -112,10 +112,10 @@ namespace HelloWorldTest Tizen.Log.Debug("NUI", "[2]_view SizeWidth=" + _view.SizeWidth); TextLabelLineWrapModeTest(); - //ViewLayoutDirectionTest(); + ViewLayoutDirectionTest(); } - /* + private View view1, view11, view12, view111, view121; public void ViewLayoutDirectionTest() { @@ -150,7 +150,6 @@ namespace HelloWorldTest { NUILog.Error("View1_LayoutDirectionChanged()! e.Type=" + e.Type); } - */ public void AnimationFinished(object sender, EventArgs e) { diff --git a/src/Tizen.NUI/src/internal/ManualPINVOKE.cs b/src/Tizen.NUI/src/internal/ManualPINVOKE.cs index e6870e6..18432e3 100755 --- a/src/Tizen.NUI/src/internal/ManualPINVOKE.cs +++ b/src/Tizen.NUI/src/internal/ManualPINVOKE.cs @@ -1295,5 +1295,39 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WidgetData_SWIGUpcast")] public static extern global::System.IntPtr WidgetData_SWIGUpcast(global::System.IntPtr jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Actor_Property_INHERIT_LAYOUT_DIRECTION_get")] + public static extern int Actor_Property_INHERIT_LAYOUT_DIRECTION_get(); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Actor_Property_LAYOUT_DIRECTION_get")] + public static extern int Actor_Property_LAYOUT_DIRECTION_get(); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_LayoutDirectionChangedSignal")] + public static extern global::System.IntPtr LayoutDirectionChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_ViewLayoutDirectionChangedSignal_Empty")] + public static extern bool ViewLayoutDirectionChangedSignal_Empty(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_ViewLayoutDirectionSignal_GetConnectionCount")] + public static extern uint ViewLayoutDirectionChangedSignal_GetConnectionCount(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_ViewLayoutDirectionSignal_Connect")] + public static extern void ViewLayoutDirectionChangedSignal_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_ViewLayoutDirectionSignal_Disconnect")] + public static extern void ViewLayoutDirectionChangedSignal_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_ViewLayoutDirectionSignal_Emit")] + public static extern void ViewLayoutDirectionChangedSignal_Emit(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_new_ViewLayoutDirectionSignal")] + public static extern global::System.IntPtr new_ViewLayoutDirectionChangedSignal(); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_delete_ViewLayoutDirectionSignal")] + public static extern void delete_ViewLayoutDirectionChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_Adaptor_RenderOnce")] + public static extern void Window_RenderOnce(global::System.Runtime.InteropServices.HandleRef jarg1); + } } diff --git a/src/Tizen.NUI/src/internal/ViewLayoutDirectionChangedSignal.cs b/src/Tizen.NUI/src/internal/ViewLayoutDirectionChangedSignal.cs new file mode 100755 index 0000000..d376113 --- /dev/null +++ b/src/Tizen.NUI/src/internal/ViewLayoutDirectionChangedSignal.cs @@ -0,0 +1,146 @@ +/** 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 Tizen.NUI.BaseComponents; + +namespace Tizen.NUI +{ + + internal class ViewLayoutDirectionChangedSignal : global::System.IDisposable + { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + protected bool swigCMemOwn; + + internal ViewLayoutDirectionChangedSignal(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(ViewLayoutDirectionChangedSignal 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; + + ~ViewLayoutDirectionChangedSignal() + { + 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_ViewLayoutDirectionChangedSignal(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + + disposed = true; + } + + public bool Empty() + { + bool ret = NDalicManualPINVOKE.ViewLayoutDirectionChangedSignal_Empty(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + public uint GetConnectionCount() + { + uint ret = NDalicManualPINVOKE.ViewLayoutDirectionChangedSignal_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.ViewLayoutDirectionChangedSignal_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.ViewLayoutDirectionChangedSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + + public void Emit(View arg) + { + NDalicManualPINVOKE.ViewLayoutDirectionChangedSignal_Emit(swigCPtr, View.getCPtr(arg)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + public ViewLayoutDirectionChangedSignal() : this(NDalicManualPINVOKE.new_ViewLayoutDirectionChangedSignal(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 3f3b97b..6e63bee 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -857,6 +857,101 @@ namespace Tizen.NUI.BaseComponents } } + + /// + /// Event arguments of layout direction changed. + /// + public class LayoutDirectionChangedEventArgs : EventArgs + { + private View _view; + private ViewLayoutDirectionType _type; + + /// + /// The view, or child of view, whose layout direction has changed. + /// + public View View + { + get + { + return _view; + } + set + { + _view = value; + } + } + + /// + /// Whether the view's layout direction property has changed or a parent's. + /// + public ViewLayoutDirectionType Type + { + get + { + return _type; + } + set + { + _type = value; + } + } + } + + private EventHandler _layoutDirectionChangedEventHandler; + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void LayoutDirectionChangedEventCallbackType(IntPtr data, ViewLayoutDirectionType type); + private LayoutDirectionChangedEventCallbackType _layoutDirectionChangedEventCallback; + + /// + /// Event for layout direction change which can be used to subscribe/unsubscribe the event handler.
+ /// This signal is emitted when the layout direction property of this or a parent view is changed.
+ ///
+ public event EventHandler LayoutDirectionChanged + { + add + { + if (_layoutDirectionChangedEventHandler == null) + { + _layoutDirectionChangedEventCallback = OnLayoutDirectionChanged; + LayoutDirectionChangedSignal(this).Connect(_layoutDirectionChangedEventCallback); + } + + _layoutDirectionChangedEventHandler += value; + } + + remove + { + _layoutDirectionChangedEventHandler -= value; + + if (_layoutDirectionChangedEventHandler == null && LayoutDirectionChangedSignal(this).Empty() == false) + { + LayoutDirectionChangedSignal(this).Disconnect(_layoutDirectionChangedEventCallback); + } + } + } + + // Callback for View layout direction change signal + private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type) + { + LayoutDirectionChangedEventArgs e = new LayoutDirectionChangedEventArgs(); + if (data != null) + { + e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View; + } + e.Type = type; + + if (_layoutDirectionChangedEventHandler != null) + { + _layoutDirectionChangedEventHandler(this, e); + } + } + + + + + + + // Resource Ready Signal private EventHandler _resourcesLoadedEventHandler; @@ -967,6 +1062,8 @@ namespace Tizen.NUI.BaseComponents internal static readonly int MAXIMUM_SIZE = NDalicPINVOKE.Actor_Property_MAXIMUM_SIZE_get(); internal static readonly int INHERIT_POSITION = NDalicPINVOKE.Actor_Property_INHERIT_POSITION_get(); internal static readonly int CLIPPING_MODE = NDalicPINVOKE.Actor_Property_CLIPPING_MODE_get(); + internal static readonly int INHERIT_LAYOUT_DIRECTION = NDalicManualPINVOKE.Actor_Property_INHERIT_LAYOUT_DIRECTION_get(); + internal static readonly int LAYOUT_DIRECTION = NDalicManualPINVOKE.Actor_Property_LAYOUT_DIRECTION_get(); } /// @@ -2900,6 +2997,14 @@ namespace Tizen.NUI.BaseComponents return ret; } + + internal ViewLayoutDirectionChangedSignal LayoutDirectionChangedSignal(View view) { + ViewLayoutDirectionChangedSignal ret = new ViewLayoutDirectionChangedSignal(NDalicManualPINVOKE.LayoutDirectionChangedSignal(View.getCPtr(view)), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal ViewSignal ResourcesLoadedSignal() { ViewSignal ret = new ViewSignal(NDalicPINVOKE.ResourceReadySignal(swigCPtr), false); @@ -3986,9 +4091,41 @@ namespace Tizen.NUI.BaseComponents } } + public bool InheritLayoutDirection + { + get + { + bool temp = false; + GetProperty(View.Property.INHERIT_LAYOUT_DIRECTION).Get(out temp); + return temp; + } + set + { + SetProperty(View.Property.INHERIT_LAYOUT_DIRECTION, new Tizen.NUI.PropertyValue(value)); + } + } + public ViewLayoutDirectionType LayoutDirection + { + get + { + int temp; + if (GetProperty(View.Property.LAYOUT_DIRECTION).Get(out temp) == false) + { + NUILog.Error("LAYOUT_DIRECTION get error!"); + } + return (ViewLayoutDirectionType)temp; + } + set + { + SetProperty(View.Property.LAYOUT_DIRECTION, new Tizen.NUI.PropertyValue((int)value)); + } + } + } - - + public enum ViewLayoutDirectionType + { + LTR, + RTL } } -- 2.7.4