[NUI] Split NUI Assemblies (#865)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / View.cs
index 56a4fee..4a8e259 100755 (executable)
@@ -20,7 +20,6 @@ using System.ComponentModel;
 using System.IO;
 using System.Runtime.InteropServices;
 using Tizen.NUI.Binding;
-using Tizen.NUI.Xaml;
 
 namespace Tizen.NUI.BaseComponents
 {
@@ -90,7 +89,7 @@ namespace Tizen.NUI.BaseComponents
     /// View is the base class for all views.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
-    public class View : Container, IResourcesProvider
+    public class View : Container
     {
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
@@ -1273,9 +1272,6 @@ namespace Tizen.NUI.BaseComponents
             Tizen.NUI.Object.GetProperty(view.swigCPtr, View.Property.MARGIN).Get(temp);
             return temp;
         });
-        /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public static readonly BindableProperty StyleProperty = BindableProperty.Create("Style", typeof(Style), typeof(View), default(Style), propertyChanged: (bindable, oldvalue, newvalue) => ((View)bindable)._mergedStyle.Style = (Style)newvalue);
 
         /// <summary>
         /// Flag to indicate if layout set explicitly via API call or View was automatically given a Layout.
@@ -1293,7 +1289,6 @@ namespace Tizen.NUI.BaseComponents
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static bool layoutingDisabled{get; set;} = true;
 
-        internal readonly MergedStyle _mergedStyle;
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
         private LayoutItem _layout; // Exclusive layout assigned to this View.
         private int _widthPolicy = LayoutParamPolicies.WrapContent; // Layout width policy
@@ -1357,7 +1352,6 @@ namespace Tizen.NUI.BaseComponents
             {
                 PositionUsesPivotPoint = false;
             }
-            _mergedStyle = new MergedStyle(GetType(), this);
 
             _onWindowSendEventCallback = SendViewAddedEventToWindow;
             this.OnWindowSignal().Connect(_onWindowSendEventCallback);
@@ -1399,12 +1393,12 @@ namespace Tizen.NUI.BaseComponents
         /// Event when a child is removed.
         /// </summary>
         /// <since_tizen> 5 </since_tizen>
-        public new event EventHandler<ChildRemovedEventArgs> ChildRemoved;
+        public event EventHandler<ChildRemovedEventArgs> ChildRemoved;
         /// <summary>
         /// Event when a child is added.
         /// </summary>
         /// <since_tizen> 5 </since_tizen>
-        public new event EventHandler<ChildAddedEventArgs> ChildAdded;
+        public event EventHandler<ChildAddedEventArgs> ChildAdded;
 
         /// <summary>
         /// An event for the KeyInputFocusGained signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
@@ -1846,30 +1840,6 @@ namespace Tizen.NUI.BaseComponents
             CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000
         }
 
-        /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool IsResourcesCreated
-        {
-            get
-            {
-                return Application.Current.IsResourcesCreated;
-            }
-        }
-
-        /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public ResourceDictionary XamlResources
-        {
-            get
-            {
-                return Application.Current.XamlResources;
-            }
-            set
-            {
-                Application.Current.XamlResources = value;
-            }
-        }
-
         /// <summary>
         /// The StyleName, type string.
         /// </summary>
@@ -3090,11 +3060,35 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                return (Extents)GetValue(PaddingProperty);
+                // If View has a Layout then padding in stored in the base Layout class
+                if (Layout !=null)
+                {
+                    return Layout.Padding;
+                }
+                else
+                {
+                    return (Extents)GetValue(PaddingProperty);
+                }
+                // Two return points to prevent creating a zeroed Extent native object before assignment
             }
             set
             {
-                SetValue(PaddingProperty, value);
+                Extents padding = value;
+                if (Layout !=null)
+                {
+                    // Layout set so store Padding in LayoutItem instead of in View.
+                    // If View stores the Padding value then Legacy Size Negotiation will overwrite
+                    // the position and sizes measure in the Layouting.
+                    Layout.Padding = value;
+                    // If Layout is a LayoutItem then it could be a View that handles it's own padding.
+                    // Let the View keeps it's padding.  Still store Padding in Layout to reduce code paths.
+                    if( Layout.GetType() != typeof(LayoutItem)) // If a Layout container of some kind.
+                    {
+                        padding =  new Extents(0,0,0,0); // Reset value stored in View.
+                    }
+                    _layout?.RequestLayout();
+                }
+                SetValue(PaddingProperty, padding);
                 NotifyPropertyChanged();
                 _layout?.RequestLayout();
             }
@@ -3342,11 +3336,33 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                return (Extents)GetValue(MarginProperty);
+                // If View has a Layout then margin is stored in Layout.
+                if (Layout != null)
+                {
+                    return Layout.Margin;
+                }
+                else
+                {
+                    // If Layout not set then return margin stored in View.
+                    return (Extents)GetValue(MarginProperty);
+                }
+                // Two return points to prevent creating a zeroed Extent native object before assignment
             }
             set
             {
-                SetValue(MarginProperty, value);
+                if (Layout != null)
+                {
+                    // Layout set so store Margin in LayoutItem instead of View.
+                    // If View stores the Margin too then the Legacy Size Negotiation will
+                    // overwrite the position and size values measured in the Layouting.
+                    Layout.Margin = value;
+                    SetValue(MarginProperty, new Extents(0,0,0,0));
+                    _layout?.RequestLayout();
+                }
+                else
+                {
+                    SetValue(MarginProperty, value);
+                }
                 NotifyPropertyChanged();
                 _layout?.RequestLayout();
             }
@@ -3398,6 +3414,7 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+
         /// <summary>
         /// [Obsolete("Please do not use! this will be deprecated")]
         /// </summary>
@@ -3422,18 +3439,6 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        internal Style Style
-        {
-            get
-            {
-                return (Style)GetValue(StyleProperty);
-            }
-            set
-            {
-                SetValue(StyleProperty, value);
-            }
-        }
-
         /// <summary>
         /// Child property to specify desired width
         /// </summary>
@@ -3608,11 +3613,59 @@ namespace Tizen.NUI.BaseComponents
 
                 // If new layout being set already has a owner then that owner receives a replacement default layout.
                 // First check if the layout to be set already has a owner.
-                if ( value.Owner != null )
+                if (value?.Owner != null)
                 {
                     Log.Info("NUI", "Set layout already in use by another View: " + value.Owner.Name + "will get a LayoutGroup\n");
                     // Previous owner of the layout gets a default layout as a replacement.
                     value.Owner.Layout = new LayoutGroup();
+
+                    // Copy Margin and Padding to replacement LayoutGroup.
+                    value.Owner.Layout.Margin = value.Margin;
+                    value.Owner.Layout.Padding = value.Padding;
+                }
+
+                // Copy Margin and Padding to new layout being set or restore padding and margin back to
+                // View if no replacement. Previously margin and padding values would have been moved from
+                // the View to the layout.
+                if (_layout != null ) // Existing layout
+                {
+                    if (value != null)
+                    {
+                        // Existing layout being replaced so copy over margin and padding values.
+                        value.Margin = _layout.Margin;
+                        value.Padding = _layout.Padding;
+                    }
+                    else
+                    {
+                      // Layout not being replaced so restore margin and padding to View.
+                      SetValue(MarginProperty, _layout.Margin);
+                      SetValue(PaddingProperty, _layout.Padding);
+                      NotifyPropertyChanged();
+                    }
+                }
+                else
+                {
+                    // First Layout to be added to the View hence copy
+
+                    // Do not try to set Margins or Padding on a null Layout (when a layout is being removed from a View)
+                    if (value !=null)
+                    {
+                        if (Margin.Top != 0 || Margin.Bottom !=0 || Margin.Start !=0 || Margin.End != 0)
+                        {
+                            // If View already has a margin set then store it in Layout instead.
+                            value.Margin = Margin;
+                            SetValue(MarginProperty, new Extents(0,0,0,0));
+                            NotifyPropertyChanged();
+                        }
+
+                        if (Padding.Top != 0 || Padding.Bottom !=0 || Padding.Start !=0 || Padding.End != 0)
+                        {
+                            // If View already has a padding set then store it in Layout instead.
+                            value.Padding = Padding;
+                            SetValue(PaddingProperty, new Extents(0,0,0,0));
+                            NotifyPropertyChanged();
+                        }
+                    }
                 }
 
                 // Remove existing layout from it's parent layout group.
@@ -3626,8 +3679,8 @@ namespace Tizen.NUI.BaseComponents
         internal void SetLayout(LayoutItem layout)
         {
             _layout = layout;
-            _layout.AttachToOwner(this);
-            _layout.RequestLayout();
+            _layout?.AttachToOwner(this);
+            _layout?.RequestLayout();
         }
 
         /// <summary>
@@ -4008,8 +4061,16 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public bool HasFocus()
         {
-            bool ret = Interop.View.View_HasKeyInputFocus(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            bool ret = false;
+            if (swigCPtr.Handle != global::System.IntPtr.Zero)
+            {
+                ret = Interop.View.View_HasKeyInputFocus(swigCPtr);
+                               if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+            else
+            {
+                Tizen.Log.Error("NUI", "swigCPtr of view is aleady disposed.");
+            }
             return ret;
         }
 
@@ -5744,56 +5805,6 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-
-        private Dictionary<string, Transition> transDictionary = new Dictionary<string, Transition>();
-
-        /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public Transition GetTransition(string transitionName)
-        {
-            Transition trans = null;
-            transDictionary.TryGetValue(transitionName, out trans);
-            return trans;
-        }
-
-        private void LoadTransitions()
-        {
-            foreach (string str in transitionNames)
-            {
-                string resourceName = str + ".xaml";
-                Transition trans = null;
-
-                string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
-
-                string likelyResourcePath = resource + "animation/" + resourceName;
-
-                if (File.Exists(likelyResourcePath))
-                {
-                    trans = Extensions.LoadObject<Transition>(likelyResourcePath);
-                }
-                if (trans)
-                {
-                    transDictionary.Add(trans.Name, trans);
-                }
-            }
-        }
-
-        /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public string[] TransitionNames
-        {
-            get
-            {
-                return transitionNames;
-            }
-            set
-            {
-                transitionNames = value;
-                LoadTransitions();
-            }
-        }
-        private string[] transitionNames;
-
         internal class BackgroundResourceLoadedEventArgs : EventArgs
         {
             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;