// RadRibbonViewEx.cs
// Copyright (c) 2018 Bentley Systems, Incorporated. All Rights Reserved.

using System;
using System.Windows.Controls;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.RibbonView.Primitives;

namespace Haestad.Framework.UI.Integration.Ribbon.Controls
{
    public class RadRibbonViewEx : RadRibbonView
    {
        #region Constructor
        public RadRibbonViewEx()
        {
            CollapseThresholdSize = new System.Windows.Size(0.0, 0.0);
        }
        #endregion

        #region Public Methods
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // In ordert o use the same instance as the private fields and property, need to use reflection here instead of using GetTemplateChild.

            var fieldInfo = GetType().BaseType.GetField("ribbonTitleBarPanel", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            if (fieldInfo != null)
                RibbonTitleBarPanel = fieldInfo.GetValue(this) as Panel;

            fieldInfo = GetType().BaseType.GetField("rootPanel", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            if (fieldInfo != null)
                RibbonRootPanel = fieldInfo.GetValue(this) as Grid;

            var propertyInfo = GetType().BaseType.GetProperty("WindowTitle",
                System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, typeof(WindowTitle), new Type[] { }, null);
            if (propertyInfo != null)
                WindowTitle = propertyInfo.GetValue(this) as WindowTitle;
        }
        #endregion

        #region Public Properties
        public Grid RibbonRootPanel { get; private set; }
        public Panel RibbonTitleBarPanel { get; private set; }
        public WindowTitle WindowTitle { get; private set; }
        #endregion
    }
}
