using ESBasic;
using OMCS.Passive;
using OMCS.Passive.RemoteDesktop;
using OVCS.Core;
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;

namespace OVCS.ClientWpf
{
    /// <summary>
    /// 全屏显示远程桌面共享
    /// </summary>
    public partial class BigDeskTopWindow : Window
    {
        private DynamicDesktopConnector dynamicDesktopConnector = new DynamicDesktopConnector();
        private MultiVideoChatContainer multiVideoChatContainer;
        public BigDeskTopWindow(string ownerID, MultiVideoChatContainer _multiVideoChatContainer)
        {
            InitializeComponent();
            this.multiVideoChatContainer = _multiVideoChatContainer;
            this.dynamicDesktopConnector.VideoDrawMode = VideoDrawMode.Scale;
            this.dynamicDesktopConnector.SetViewer(this.fullDeskTop);
            this.dynamicDesktopConnector.ConnectEnded += DynamicDesktopConnector_ConnectEnded;
            this.dynamicDesktopConnector.Disconnected += DynamicDesktopConnector_Disconnected;
            this.dynamicDesktopConnector.BeginConnect(ownerID);
            this.Closed += BigDeskTopWindow_Closed;
        }

        private void DynamicDesktopConnector_Disconnected(string ownerID, OMCS.Passive.ConnectorDisconnectedType type)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.BeginInvoke(new CbGeneric<string, OMCS.Passive.ConnectorDisconnectedType>(this.DynamicDesktopConnector_Disconnected), ownerID, type);
            }
            else
            {
                
            }
        }

        private void DynamicDesktopConnector_ConnectEnded(string ownerID, OMCS.Passive.ConnectResult res)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.BeginInvoke(new CbGeneric<string, OMCS.Passive.ConnectResult>(this.DynamicDesktopConnector_ConnectEnded), ownerID, res);
            }
            else
            {
                if(res != OMCS.Passive.ConnectResult.Succeed)
                {
                    MessageBox.Show(res.ToString());
                }
            }
        }

        
        private void BigDeskTopWindow_Closed(object sender, EventArgs e)
        {
            //this.dynamicDesktopConnector.SetViewer(this.multiVideoChatContainer.desktopPanel);
            this.dynamicDesktopConnector.Disconnect();
            this.multiVideoChatContainer.DeskTopBtnHitTestVisibleChange(true);
        }
    }
}
