// This is a part of the Smart PropertyGrid Library
// Copyright (C) 2001-2006 VisualHint
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions
// of the accompanying license agreement.

#region Using directives

using System.Drawing;

#endregion

namespace VisualHint.SmartPropertyGrid
{
    internal class PropertyUpDownFeel : PropertyFeel
    {
        private bool _editable;

        public PropertyUpDownFeel(PropertyGrid grid, bool editable) : base(grid)
        {
            _editable = editable;
        }

        public override System.Windows.Forms.Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum)
        {
            if ((propEnum.Property.Value.IsReadOnly(propEnum)) && !_editable)
                return null;

            PropInPlaceUpDown upDown;

            if (mInPlaceCtrl == null)
            {
                upDown = new PropInPlaceUpDown(_editable);
                upDown.Visible = false;
                upDown.Parent = mParentWnd;
                mInPlaceCtrl = upDown;
            }
            else
                upDown = (PropInPlaceUpDown)mInPlaceCtrl;

            upDown.Font = propEnum.Property.Value.Font;
            upDown.Text = propEnum.Property.Value.DisplayString;

            upDown.OwnerPropertyEnumerator = propEnum;

            MoveControl(valueRect, propEnum, false);

            if (upDown.Focused == false)		// are we already being editing ? If yes, don't touch the edit content
            {
//                if (upDown.Text != enumerator.Property.Value.DisplayString)
  //                  upDown.Text = enumerator.Property.Value.DisplayString;
            }

            return base.ShowControl(valueRect, propEnum);
        }
    }
}
