In CustomView handling Actor, changed as View
[platform/core/csapi/nui.git] / Tizen.NUI / src / public / CustomView / Spin.cs
index ae473ac..79ad32f 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (c) 2017 Samsung Electronics Co., Ltd.
+// 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.
 //
 // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
 // Some have been manually changed
-\r
-using System;\r
-using System.Runtime.InteropServices;\r
-using Tizen.NUI;\r
-\r
-// A spin control (for continously changing values when users can easily predict a set of values)\r
-\r
-namespace Tizen.NUI\r
-{\r
-    ///<summary>\r
-    ///Spin CustomView class\r
-    /// </summary>\r
-    public class Spin : CustomView\r
-    {\r
-        private VisualBase _arrowVisual;\r
-        private TextField _textField;\r
-        private int _arrowVisualPropertyIndex;\r
-        private string _arrowImage;\r
-        private int _currentValue;\r
-        private int _minValue;\r
-        private int _maxValue;\r
-        private int _singleStep;\r
-        private bool _wrappingEnabled;\r
-        private string _fontFamily;\r
-        private string _fontStyle;\r
-        private int _pointSize;\r
-        private Color _textColor;\r
-        private Color _textBackgroundColor;\r
-        private int _maxTextLength;\r
-\r
-        // Called by DALi Builder if it finds a Spin control in a JSON file\r
-        static CustomView CreateInstance()\r
-        {\r
-            return new Spin();\r
-        }\r
-\r
-        // static constructor registers the control type (only runs once)\r
-        static Spin()\r
-        {\r
-            // ViewRegistry registers control type with DALi type registery\r
-            // also uses introspection to find any properties that need to be registered with type registry\r
-            ViewRegistry.Instance.Register(CreateInstance, typeof(Spin));\r
-        }\r
-\r
-        public Spin() : base(typeof(Spin).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)\r
-        {\r
-\r
-        }\r
-\r
-        /// <summary>\r
-        /// Override method of OnInitialize() for CustomView class.\r
-        /// This method is called after the Control has been initialized.\r
-        /// Derived classes should do any second phase initialization by overriding this method.\r
-        /// </summary>\r
-        public override void OnInitialize()\r
-        {\r
-            // Initialize the propertiesControl\r
-            _arrowImage = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/arrow.png";\r
-            _textBackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);\r
-            _currentValue = 0;\r
-            _minValue = 0;\r
-            _maxValue = 0;\r
-            _singleStep = 1;\r
-            _maxTextLength = 0;\r
-\r
-            // Create image visual for the arrow keys\r
-            _arrowVisualPropertyIndex = RegisterProperty("ArrowImage", new PropertyValue(_arrowImage), Tizen.NUI.PropertyAccessMode.ReadWrite);\r
-            _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));\r
-            RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);\r
-\r
-            // Create a text field\r
-            _textField = new TextField();\r
-            _textField.ParentOrigin = Tizen.NUI.ParentOrigin.Center;\r
-            _textField.AnchorPoint = Tizen.NUI.AnchorPoint.Center;\r
-            _textField.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;\r
-            _textField.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;\r
-            _textField.SizeModeFactor = new Vector3(1.0f, 0.45f, 1.0f);\r
-            _textField.PlaceholderText = "----";\r
-            _textField.BackgroundColor = _textBackgroundColor;\r
-            _textField.HorizontalAlignment = "Center";\r
-            _textField.VerticalAlignment = "Center";\r
-            _textField.Focusable = (true);\r
-            _textField.Name = "_textField";\r
-\r
-            this.Add(_textField);\r
-\r
-            _textField.FocusGained += TextFieldKeyInputFocusGained;\r
-            _textField.FocusLost += TextFieldKeyInputFocusLost;\r
-        }\r
-\r
-        /// <summary>\r
-        /// Override method of GetNaturalSize() for CustomView class.\r
-        /// Return the natural size of the actor.\r
-        /// </summary>\r
-        /// <returns> Natural size of this Spin itself</returns>\r
-        public override Size GetNaturalSize()\r
-        {\r
-            return new Size(150.0f, 150.0f, 0.0f);\r
-        }\r
-\r
-        /// <summary>\r
-        /// Event handler when the TextField in Spin gets the Key focus\r
-        /// Make sure when the current spin that takes input focus also takes the keyboard focus\r
-        /// For example, when you tap the spin directly\r
-        /// </summary>\r
-        /// <param name="source">Sender of this event</param>\r
-        /// <param name="e">Event arguments</param>\r
-        public void TextFieldKeyInputFocusGained(object source, EventArgs e)\r
-        {\r
-            FocusManager.Instance.SetCurrentFocusView(_textField);\r
-        }\r
-\r
-        /// <summary>\r
-        /// Event handler when the TextField in Spin looses it's Key focus\r
-        /// </summary>\r
-        /// <param name="source"></param>\r
-        /// <param name="e"></param>\r
-        public void TextFieldKeyInputFocusLost(object source, EventArgs e)\r
-        {\r
-            int previousValue = _currentValue;\r
-\r
-            // If the input value is invalid, change it back to the previous valid value\r
-            if (int.TryParse(_textField.Text, out _currentValue))\r
-            {\r
-                if (_currentValue < _minValue || _currentValue > _maxValue)\r
-                {\r
-                    _currentValue = previousValue;\r
-                }\r
-            }\r
-            else\r
-            {\r
-                _currentValue = previousValue;\r
-            }\r
-\r
-            // Otherwise take the new value\r
-            this.Value = _currentValue;\r
-        }\r
-\r
-        /// <summary>\r
-        /// Override method of GetNextKeyboardFocusableActor() for CustomView class.\r
-        /// Gets the next key focusable actor in this View towards the given direction.\r
-        /// A View needs to override this function in order to support two dimensional key navigation.\r
-        /// </summary>\r
-        /// <param name="currentFocusedActor">The current focused actor</param>\r
-        /// <param name="direction">The direction to move the focus towards</param>\r
-        /// <param name="loopEnabled">Whether the focus movement should be looped within the control</param>\r
-        /// <returns>The next keyboard focusable actor in this control or an empty handle if no actor can be focused</returns>\r
-        public override Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, View.FocusDirection direction, bool loopEnabled)\r
-        {\r
-            // Respond to Up/Down keys to change the value while keeping the current spin focused\r
-            Actor nextFocusedActor = currentFocusedActor;\r
-            if (direction == View.FocusDirection.Up)\r
-            {\r
-                this.Value += this.Step;\r
-                nextFocusedActor = _textField;\r
-            }\r
-            else if (direction == View.FocusDirection.Down)\r
-            {\r
-                this.Value -= this.Step;\r
-                nextFocusedActor = _textField;\r
-            }\r
-            else\r
-            {\r
-                // Return a native empty handle as nothing can be focused in the left or right\r
-                nextFocusedActor = new Actor();\r
-                nextFocusedActor.Reset();\r
-            }\r
-\r
-            return nextFocusedActor;\r
-        }\r
-\r
-        /// <summary>\r
-        /// Value to be set in Spin\r
-        /// </summary>\r
-        [ScriptableProperty()]\r
-        public int Value\r
-        {\r
-            get\r
-            {\r
-                return _currentValue;\r
-            }\r
-            set\r
-            {\r
-\r
-                Console.WriteLine("Value set to " + value);\r
-                _currentValue = value;\r
-\r
-                // Make sure no invalid value is accepted\r
-                if (_currentValue < _minValue)\r
-                {\r
-                    _currentValue = _minValue;\r
-                }\r
-\r
-                if (_currentValue > _maxValue)\r
-                {\r
-                    _currentValue = _maxValue;\r
-                }\r
-\r
-                _textField.Text = _currentValue.ToString();\r
-            }\r
-        }\r
-        \r
-        /// <summary>\r
-        /// Minimum Value of Spin Value\r
-        /// </summary>\r
-        // MinValue property of type int:\r
-        [ScriptableProperty()]\r
-        public int MinValue\r
-        {\r
-            get\r
-            {\r
-                return _minValue;\r
-            }\r
-            set\r
-            {\r
-                _minValue = value;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Maximum Value of Spin Value\r
-        /// </summary>\r
-        // MaxValue property of type int:\r
-        [ScriptableProperty()]\r
-        public int MaxValue\r
-        {\r
-            get\r
-            {\r
-                return _maxValue;\r
-            }\r
-            set\r
-            {\r
-                _maxValue = value;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        ///  Increasing, decresing step of Spin Value when Up or Down key is pressed\r
-        /// </summary>\r
-        // Step property of type int:\r
-        [ScriptableProperty()]\r
-        public int Step\r
-        {\r
-            get\r
-            {\r
-                return _singleStep;\r
-            }\r
-            set\r
-            {\r
-                _singleStep = value;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Wrapping enabled status\r
-        /// </summary>\r
-        // WrappingEnabled property of type bool:\r
-        [ScriptableProperty()]\r
-        public bool WrappingEnabled\r
-        {\r
-            get\r
-            {\r
-                return _wrappingEnabled;\r
-            }\r
-            set\r
-            {\r
-                _wrappingEnabled = value;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        ///  Text point size of Spin Value\r
-        /// </summary>\r
-        // TextPointSize property of type int:\r
-        [ScriptableProperty()]\r
-        public int TextPointSize\r
-        {\r
-            get\r
-            {\r
-                return _pointSize;\r
-            }\r
-            set\r
-            {\r
-                _pointSize = value;\r
-                _textField.PointSize = _pointSize;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// The color of Spin Value\r
-        /// </summary>\r
-        // TextColor property of type Color:\r
-        [ScriptableProperty()]\r
-        public Color TextColor\r
-        {\r
-            get\r
-            {\r
-                return _textColor;\r
-            }\r
-            set\r
-            {\r
-                Console.WriteLine("TextColor set to " + value.R + "," + value.G + "," + value.B);\r
-\r
-                _textColor = value;\r
-                _textField.TextColor = _textColor;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Maximum text lengh of Spin Value\r
-        /// </summary>\r
-        // MaxTextLength property of type int:\r
-        [ScriptableProperty()]\r
-        public int MaxTextLength\r
-        {\r
-            get\r
-            {\r
-                return _maxTextLength;\r
-            }\r
-            set\r
-            {\r
-                _maxTextLength = value;\r
-                _textField.MaxLength = _maxTextLength;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Reference of TextField of Spin\r
-        /// </summary>\r
-        public TextField SpinText\r
-        {\r
-            get\r
-            {\r
-                return _textField;\r
-            }\r
-            set\r
-            {\r
-                _textField = value;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Show indicator image, for example Up/Down Arrow image.\r
-        /// </summary>\r
-        // Indicator property of type string:\r
-        public string IndicatorImage\r
-        {\r
-            get\r
-            {\r
-                return _arrowImage;\r
-            }\r
-            set\r
-            {\r
-                _arrowImage = value;\r
-                _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));\r
-                RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);\r
-            }\r
-        }\r
-    }\r
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.NUI;
+
+// A spin control (for continously changing values when users can easily predict a set of values)
+
+namespace Tizen.NUI
+{
+    ///<summary>
+    ///Spin CustomView class
+    /// </summary>
+    public class Spin : CustomView
+    {
+        private VisualBase _arrowVisual;
+        private TextField _textField;
+        private int _arrowVisualPropertyIndex;
+        private string _arrowImage;
+        private int _currentValue;
+        private int _minValue;
+        private int _maxValue;
+        private int _singleStep;
+        private bool _wrappingEnabled;
+        private string _fontFamily;
+        private string _fontStyle;
+        private int _pointSize;
+        private Color _textColor;
+        private Color _textBackgroundColor;
+        private int _maxTextLength;
+
+        // Called by DALi Builder if it finds a Spin control in a JSON file
+        static CustomView CreateInstance()
+        {
+            return new Spin();
+        }
+
+        // static constructor registers the control type (only runs once)
+        static Spin()
+        {
+            // ViewRegistry registers control type with DALi type registery
+            // also uses introspection to find any properties that need to be registered with type registry
+            ViewRegistry.Instance.Register(CreateInstance, typeof(Spin));
+        }
+
+        public Spin() : base(typeof(Spin).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)
+        {
+
+        }
+
+        /// <summary>
+        /// Override method of OnInitialize() for CustomView class.
+        /// This method is called after the Control has been initialized.
+        /// Derived classes should do any second phase initialization by overriding this method.
+        /// </summary>
+        public override void OnInitialize()
+        {
+            // Initialize the propertiesControl
+            _arrowImage = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/arrow.png";
+            _textBackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
+            _currentValue = 0;
+            _minValue = 0;
+            _maxValue = 0;
+            _singleStep = 1;
+            _maxTextLength = 0;
+
+            // Create image visual for the arrow keys
+            _arrowVisualPropertyIndex = RegisterProperty("ArrowImage", new PropertyValue(_arrowImage), Tizen.NUI.PropertyAccessMode.ReadWrite);
+            _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));
+            RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);
+
+            // Create a text field
+            _textField = new TextField();
+            _textField.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
+            _textField.AnchorPoint = Tizen.NUI.AnchorPoint.Center;
+            _textField.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
+            _textField.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
+            _textField.SizeModeFactor = new Vector3(1.0f, 0.45f, 1.0f);
+            _textField.PlaceholderText = "----";
+            _textField.BackgroundColor = _textBackgroundColor;
+            _textField.HorizontalAlignment = "Center";
+            _textField.VerticalAlignment = "Center";
+            _textField.Focusable = (true);
+            _textField.Name = "_textField";
+
+            this.Add(_textField);
+
+            _textField.FocusGained += TextFieldKeyInputFocusGained;
+            _textField.FocusLost += TextFieldKeyInputFocusLost;
+        }
+
+        /// <summary>
+        /// Override method of GetNaturalSize() for CustomView class.
+        /// Return the natural size of the actor.
+        /// </summary>
+        /// <returns> Natural size of this Spin itself</returns>
+        public override Size GetNaturalSize()
+        {
+            return new Size(150.0f, 150.0f, 0.0f);
+        }
+
+        /// <summary>
+        /// Event handler when the TextField in Spin gets the Key focus
+        /// Make sure when the current spin that takes input focus also takes the keyboard focus
+        /// For example, when you tap the spin directly
+        /// </summary>
+        /// <param name="source">Sender of this event</param>
+        /// <param name="e">Event arguments</param>
+        public void TextFieldKeyInputFocusGained(object source, EventArgs e)
+        {
+            FocusManager.Instance.SetCurrentFocusView(_textField);
+        }
+
+        /// <summary>
+        /// Event handler when the TextField in Spin looses it's Key focus
+        /// </summary>
+        /// <param name="source"></param>
+        /// <param name="e"></param>
+        public void TextFieldKeyInputFocusLost(object source, EventArgs e)
+        {
+            int previousValue = _currentValue;
+
+            // If the input value is invalid, change it back to the previous valid value
+            if (int.TryParse(_textField.Text, out _currentValue))
+            {
+                if (_currentValue < _minValue || _currentValue > _maxValue)
+                {
+                    _currentValue = previousValue;
+                }
+            }
+            else
+            {
+                _currentValue = previousValue;
+            }
+
+            // Otherwise take the new value
+            this.Value = _currentValue;
+        }
+
+        /// <summary>
+        /// Override method of GetNextKeyboardFocusableView() for CustomView class.
+        /// Gets the next key focusable view in this View towards the given direction.
+        /// A View needs to override this function in order to support two dimensional key navigation.
+        /// </summary>
+        /// <param name="currentFocusedView">The current focused view</param>
+        /// <param name="direction">The direction to move the focus towards</param>
+        /// <param name="loopEnabled">Whether the focus movement should be looped within the control</param>
+        /// <returns>The next keyboard focusable view in this control or an empty handle if no view can be focused</returns>
+        public override View GetNextKeyboardFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
+        {
+            // Respond to Up/Down keys to change the value while keeping the current spin focused
+            View nextFocusedView = currentFocusedView;
+            if (direction == View.FocusDirection.Up)
+            {
+                this.Value += this.Step;
+                nextFocusedView = _textField;
+            }
+            else if (direction == View.FocusDirection.Down)
+            {
+                this.Value -= this.Step;
+                nextFocusedView = _textField;
+            }
+            else
+            {
+                // Return a native empty handle as nothing can be focused in the left or right
+                nextFocusedView = new View();
+                nextFocusedView.Reset();
+            }
+
+            return nextFocusedView;
+        }
+
+        /// <summary>
+        /// Value to be set in Spin
+        /// </summary>
+        [ScriptableProperty()]
+        public int Value
+        {
+            get
+            {
+                return _currentValue;
+            }
+            set
+            {
+
+                Console.WriteLine("Value set to " + value);
+                _currentValue = value;
+
+                // Make sure no invalid value is accepted
+                if (_currentValue < _minValue)
+                {
+                    _currentValue = _minValue;
+                }
+
+                if (_currentValue > _maxValue)
+                {
+                    _currentValue = _maxValue;
+                }
+
+                _textField.Text = _currentValue.ToString();
+            }
+        }
+        
+        /// <summary>
+        /// Minimum Value of Spin Value
+        /// </summary>
+        // MinValue property of type int:
+        [ScriptableProperty()]
+        public int MinValue
+        {
+            get
+            {
+                return _minValue;
+            }
+            set
+            {
+                _minValue = value;
+            }
+        }
+
+        /// <summary>
+        /// Maximum Value of Spin Value
+        /// </summary>
+        // MaxValue property of type int:
+        [ScriptableProperty()]
+        public int MaxValue
+        {
+            get
+            {
+                return _maxValue;
+            }
+            set
+            {
+                _maxValue = value;
+            }
+        }
+
+        /// <summary>
+        ///  Increasing, decresing step of Spin Value when Up or Down key is pressed
+        /// </summary>
+        // Step property of type int:
+        [ScriptableProperty()]
+        public int Step
+        {
+            get
+            {
+                return _singleStep;
+            }
+            set
+            {
+                _singleStep = value;
+            }
+        }
+
+        /// <summary>
+        /// Wrapping enabled status
+        /// </summary>
+        // WrappingEnabled property of type bool:
+        [ScriptableProperty()]
+        public bool WrappingEnabled
+        {
+            get
+            {
+                return _wrappingEnabled;
+            }
+            set
+            {
+                _wrappingEnabled = value;
+            }
+        }
+
+        /// <summary>
+        ///  Text point size of Spin Value
+        /// </summary>
+        // TextPointSize property of type int:
+        [ScriptableProperty()]
+        public int TextPointSize
+        {
+            get
+            {
+                return _pointSize;
+            }
+            set
+            {
+                _pointSize = value;
+                _textField.PointSize = _pointSize;
+            }
+        }
+
+        /// <summary>
+        /// The color of Spin Value
+        /// </summary>
+        // TextColor property of type Color:
+        [ScriptableProperty()]
+        public Color TextColor
+        {
+            get
+            {
+                return _textColor;
+            }
+            set
+            {
+                Console.WriteLine("TextColor set to " + value.R + "," + value.G + "," + value.B);
+
+                _textColor = value;
+                _textField.TextColor = _textColor;
+            }
+        }
+
+        /// <summary>
+        /// Maximum text lengh of Spin Value
+        /// </summary>
+        // MaxTextLength property of type int:
+        [ScriptableProperty()]
+        public int MaxTextLength
+        {
+            get
+            {
+                return _maxTextLength;
+            }
+            set
+            {
+                _maxTextLength = value;
+                _textField.MaxLength = _maxTextLength;
+            }
+        }
+
+        /// <summary>
+        /// Reference of TextField of Spin
+        /// </summary>
+        public TextField SpinText
+        {
+            get
+            {
+                return _textField;
+            }
+            set
+            {
+                _textField = value;
+            }
+        }
+
+        /// <summary>
+        /// Show indicator image, for example Up/Down Arrow image.
+        /// </summary>
+        // Indicator property of type string:
+        public string IndicatorImage
+        {
+            get
+            {
+                return _arrowImage;
+            }
+            set
+            {
+                _arrowImage = value;
+                _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));
+                RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);
+            }
+        }
+    }
 }
\ No newline at end of file