// RibbonUIButton.cs
// Copyright (c) 2016 Bentley Systems, Incorporated. All Rights Reserved.

using System;
using Haestad.Framework.UI.Integration;
using Haestad.Support.Storage;

namespace Haestad.Framework.UI.Integration
{
    /// <summary>
    /// Class that defines RibbonUIButtons that can be placed into the Ribbon using the TelerikWPFRibbonBuilder API.
    /// Elements know how to persist themselves to disk and read themselves from disk.
    /// </summary>
    public class RibbonUIButton : RibbonUIElementBase, IRibbonUIButton 
    {
        #region Constructor
        public RibbonUIButton(int id, RibbonUIElementManagerBase manager)
            : base(id, manager)
        {
        }
        #endregion

        #region IRibbonUIButton Members
        public ButtonSize ButtonSize
        {
            get;
            set;
        }

        public ButtonStyle ButtonStyle
        {
            get;
            set;
        }
        #endregion

        #region Public Override Methods
        public override void Read(IStorageReadStream stream, int version)
        {
            base.Read(stream, version);

            if (version >= 1)
            {
                ButtonSize = (ButtonSize)stream.ReadIntAttribute(RibbonUIButtonNames.ButtonSize);
                ButtonStyle = (ButtonStyle)stream.ReadIntAttribute(RibbonUIButtonNames.ButtonStyle);
            }
        }

        public override void Write(IStorageWriteStream stream)
        {
            base.Write(stream);

            stream.WriteAttribute(RibbonUIButtonNames.ButtonSize, (int)ButtonSize);
            stream.WriteAttribute(RibbonUIButtonNames.ButtonStyle, (int)ButtonStyle);
        }
        #endregion

        #region Protected Override Methods
        protected override void CloneProperties(RibbonUIElementBase clone)
        {
            RibbonUIButton buttonClone = clone as RibbonUIButton;
            buttonClone.ButtonSize = ButtonSize;
            buttonClone.ButtonStyle = ButtonStyle;

            base.CloneProperties(clone);
        }
        #endregion

        #region Private Structs
        private struct RibbonUIButtonNames
        {
            public const string ButtonSize = "ButtonSize";
            public const string ButtonStyle = "ButtonStyle";
        }
        #endregion
    }
}
