using AIProofread.Util;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace AIProofread.Controls
{
    public partial class FormDialog : Form
    {
        public FormDialog()
        {
            InitializeComponent();
        }
        private static FormMask mask;

        private void SetMessage(string message)
        {
            LabelMeesage.Text = message;
        }
        private void SetButtonText(string yesButtonText, string noButtonText)
        {
            BtnClose.Text = noButtonText;
            BtnConfirm.Text = yesButtonText;
        }

        public static DialogResult Show(string message, string caption, string yesButtonText, string noButtonText)
        {
            FormDialog formMessage = new FormDialog();
            mask = new FormMask(formMessage);
            mask.ShowOverWord();
            formMessage.SetMessage(message);
            formMessage.Text = caption;
            formMessage.SetButtonText(yesButtonText, noButtonText);
            formMessage.TopMost = true;
            IntPtr wordHandle = new IntPtr(Globals.ThisAddIn.Application.ActiveWindow.Hwnd);  // 获取Word窗口句柄
            User32Util.SetParent(formMessage.Handle,wordHandle);
            formMessage.Show();
            return DialogResult.Yes;
        }
        public static DialogResult Show(string message)
        {
            return Show(message, "", "是", "否");
        }

        private void BtnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.TopMost = false;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void FormDialog_Deactivate(object sender, EventArgs e)
        {
        //    SetForegroundWindow(this.Handle);
        //    this.Activate();
        }

        private void FormDialog_FormClosed(object sender, FormClosedEventArgs e)
        {
            mask.Close();
            mask = null;
        }
    }
}
