using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.IO;
using System.Windows.Markup;

namespace HistoryWallEditTool.ControlsForData
{
    /// <summary>
    /// TaskDialogMsg.xaml 的互動邏輯
    /// </summary>
    public partial class TaskDialogMsg : Window
    {
        public bool isCheck = false;
        private const int GWL_STYLE = -16;
        private const int WS_SYSMENU = 0x80000;
        [DllImport("user32.dll", SetLastError = true)]
        private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll")]
        private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        public static CurrentDisplayLanguage cdl;
        //隱藏 Menubar 中的工具
        private void TaskDialog_Loaded(object sender, RoutedEventArgs e)
        {
            var hwnd = new WindowInteropHelper(this).Handle;
            SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
        }

        public TaskDialogMsg()
        {
            InitializeComponent();

            SysLanChange();
            uxMainWindow.Width = 150;
            uxMainWindow.Height = 100;

            uxMainScript.SetResourceReference(TextBlock.TextProperty, "msgcopyfile");
            uxOperatorPanel.Opacity = 0;
            uxOperatorPanel.IsEnabled = false;

            this.Loaded += new RoutedEventHandler(TaskDialog_Loaded);
        }

        private void SysLanChange()
        {
            string resourcePrefix = "StringResources";
            string culturesFolder = "Culture";

            this.Resources.MergedDictionaries.Clear();
            string loadedFileName = string.Format("{0}\\{1}\\{2}.{3}.xaml", GlobalFunction.rootPath, culturesFolder, resourcePrefix, "zh-TW");

            if (cdl == CurrentDisplayLanguage.ENG)
            {
                loadedFileName = string.Format("{0}\\{1}\\{2}.{3}.xaml", GlobalFunction.rootPath, culturesFolder, resourcePrefix, "en-US");
            }

            FileStream fileStream = new FileStream(loadedFileName, FileMode.Open);
            ResourceDictionary resourceDictionary = XamlReader.Load(fileStream) as ResourceDictionary;
            this.Resources.MergedDictionaries.Add(resourceDictionary);
        }

        public TaskDialogMsg(EventCreatorClass ecc)
        {
            InitializeComponent();

            SysLanChange();
            uxMainWindow.SetResourceReference(TitleProperty, "msgwarnTitle");

            if (ecc == EventCreatorClass.MainEvent)
            {
                uxMainScript.SetResourceReference(TextBlock.TextProperty, "msgmainscript");
            }
            else
            {
                uxMainScript.SetResourceReference(TextBlock.TextProperty, "msgsubscript");
            }

            this.Loaded += new RoutedEventHandler(TaskDialog_Loaded);
        }

        public void DestroyTaskDialogMsg()
        {
            this.Close();
        }

        private void BtnYes_Click(object sender, RoutedEventArgs e)
        {
            isCheck = true;
            DestroyTaskDialogMsg();
        }

        private void BtnNo_Click(object sender, RoutedEventArgs e)
        {
            isCheck = false;
            DestroyTaskDialogMsg();
        }
    }
}
