using System;
using System.Windows.Forms;
using FastReport.Utils;

namespace FastReport.Forms
{
    internal partial class PreviewForm : BaseForm
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            // restore form state in OnLoad event. This solves the problem with Maximized window state (bad behavior on dual monitor setup, and also windows focus issues)
            // also we have to remove WindowState = Maximized from InitializeComponent code
            Init();
        }

        private void PreviewForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Done();
        }

        private void PreviewForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Escape)
                Close();
        }

        private void PreviewForm_Shown(object sender, EventArgs e)
        {
            Preview.Focus();
        }

        private void Init()
        {
            if (Config.RestoreFormState(this, true))
                WindowState = FormWindowState.Maximized;
        }

        private void Done()
        {
            Config.SaveFormState(this);
        }

        public override void UpdateDpiDependencies()
        {
            base.UpdateDpiDependencies();
            Preview.UpdateDpiDependencies();
        }

        public PreviewForm()
        {
            InitializeComponent();
            UIUtils.CheckRTL(this);
            UpdateDpiDependencies();
        }
    }
}