using System; using System.CodeDom.Compiler; using System.ComponentModel; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Markup; using System.Windows.Media; using System.Windows.Shapes; using System.Windows.Shell; using System.Windows.Threading; using Gestor.Application.Actions; using MaterialDesignThemes.Wpf; namespace Gestor.Application.Views.Generic; public class HosterWindow : Window, IComponentConnector { private enum MonitorOptions : uint { MonitorDefaulttoprimary = 1u, MonitorDefaulttonearest } public struct Point { public int X; public int Y; public Point(int x, int y) { X = x; Y = y; } } private struct Minmaxinfo { private readonly Point ptReserved; public Point ptMaxSize; public Point ptMaxPosition; private readonly Point ptMinTrackSize; private readonly Point ptMaxTrackSize; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] private class Monitorinfo { private readonly int cbSize = Marshal.SizeOf(typeof(Monitorinfo)); public readonly Rect rcMonitor; public readonly Rect rcWork; private readonly int dwFlags; } public struct Rect { public int Left; public int Top; public int Right; public int Bottom; } private bool _buttonClickable; internal WindowChrome WindowChrome; internal Grid Menu; internal Grid MinimizeButton; internal Path MinimizeButtonPath; internal Grid MaximizeButton; internal Path MaximizeButtonPath; internal Grid CloseButton; internal ContentControl ContentControl; internal DialogHost HosterDialog; internal DrawerHost DrawerHost; internal Snackbar Snackbar; private bool _contentLoaded; public string Tela { get; set; } private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == 36) { WmGetMinMaxInfo(lParam); } return IntPtr.Zero; } private void WmGetMinMaxInfo(IntPtr lParam) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) ((FrameworkElement)this).MaxHeight = Screen.FromHandle(new WindowInteropHelper((Window)(object)this).Handle).WorkingArea.Height; GetCursorPos(out var lpPoint); IntPtr hMonitor = MonitorFromPoint(new Point(0, 0), MonitorOptions.MonitorDefaulttoprimary); Monitorinfo monitorinfo = new Monitorinfo(); if (GetMonitorInfo(hMonitor, monitorinfo)) { IntPtr intPtr = MonitorFromPoint(lpPoint, MonitorOptions.MonitorDefaulttonearest); Minmaxinfo structure = (Minmaxinfo)Marshal.PtrToStructure(lParam, typeof(Minmaxinfo)); if (hMonitor.Equals((object?)(nint)intPtr)) { structure.ptMaxPosition.X = monitorinfo.rcWork.Left; structure.ptMaxPosition.Y = monitorinfo.rcWork.Top; structure.ptMaxSize.X = monitorinfo.rcWork.Right - monitorinfo.rcWork.Left; structure.ptMaxSize.Y = monitorinfo.rcWork.Bottom - monitorinfo.rcWork.Top; } else { structure.ptMaxPosition.X = monitorinfo.rcMonitor.Left; structure.ptMaxPosition.Y = monitorinfo.rcMonitor.Top; structure.ptMaxSize.X = monitorinfo.rcMonitor.Right - monitorinfo.rcMonitor.Left; structure.ptMaxSize.Y = monitorinfo.rcMonitor.Bottom - monitorinfo.rcMonitor.Top; } Marshal.StructureToPtr(structure, lParam, fDeleteOld: true); } } [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool GetCursorPos(out Point lpPoint); [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr MonitorFromPoint(Point pt, MonitorOptions dwFlags); [DllImport("user32.dll")] private static extern bool GetMonitorInfo(IntPtr hMonitor, Monitorinfo lpmi); private void TopControls_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown _buttonClickable = true; if (((FrameworkElement)(Grid)sender).Name == "CloseButton") { ((Panel)(Grid)sender).Background = (Brush)new SolidColorBrush(Colors.Red); DependencyObject child = VisualTreeHelper.GetChild((DependencyObject)(Grid)sender, 0); Path val = (Path)(object)((child is Path) ? child : null); if (val != null) { ((Shape)val).Stroke = (Brush)new SolidColorBrush(Colors.Black); } } else { ((Panel)(Grid)sender).Background = (Brush)new SolidColorBrush(Colors.DimGray); } } private void TopControls_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (_buttonClickable) { ((object)this).GetType().GetMethod(((FrameworkElement)(Grid)sender).Name + "_Click")?.Invoke(this, null); } } private static void TopControls_OnMouseEnter(object sender, MouseEventArgs e) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown ((Panel)(Grid)sender).Background = (Brush)((((FrameworkElement)(Grid)sender).Name == "CloseButton") ? new SolidColorBrush(Colors.IndianRed) : new SolidColorBrush(Colors.Gray)); DependencyObject child = VisualTreeHelper.GetChild((DependencyObject)(Grid)sender, 0); Path val = (Path)(object)((child is Path) ? child : null); if (val != null) { ((Shape)val).Stroke = (Brush)new SolidColorBrush(Colors.White); } } private void TopControls_OnMouseLeave(object sender, MouseEventArgs e) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown _buttonClickable = false; ((Panel)(Grid)sender).Background = (Brush)new SolidColorBrush(Colors.Transparent); DependencyObject child = VisualTreeHelper.GetChild((DependencyObject)(Grid)sender, 0); Path val = (Path)(object)((child is Path) ? child : null); if (val != null) { ((Shape)val).Stroke = (Brush)new SolidColorBrush(Colors.White); } } public void MinimizeButton_Click() { ((Window)this).WindowState = (WindowState)1; } public void MaximizeButton_Click() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) ((Window)this).WindowState = (WindowState)(((int)((Window)this).WindowState == 0) ? 2 : 0); } public void CloseButton_Click() { ((Window)this).Close(); } protected sealed override void OnStateChanged(EventArgs e) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Invalid comparison between Unknown and I4 //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Invalid comparison between Unknown and I4 ((Control)this).BorderThickness = new Thickness((double)(((int)((Window)this).WindowState != 2) ? 1 : 0)); WindowChrome.ResizeBorderThickness = new Thickness((double)(((int)((Window)this).WindowState != 2) ? 4 : 0)); WindowChrome.CaptionHeight = (((int)((Window)this).WindowState == 2) ? 32 : 29); MaximizeButtonPath.Data = (((int)((Window)this).WindowState == 2) ? Geometry.Parse((string)Application.Current.Resources[(object)"Restore"]) : Geometry.Parse((string)Application.Current.Resources[(object)"Maximize"])); ((Window)this).OnStateChanged(e); } private void Window_OnInitialized(object sender, EventArgs e) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown WindowInteropHelper val = new WindowInteropHelper((Window)(object)this); val.EnsureHandle(); HwndSource obj = HwndSource.FromHwnd(val.Handle); if (obj != null) { obj.AddHook(new HwndSourceHook(WindowProc)); } } public HosterWindow(ContentControl control, string titulo, double? x = null, double? y = null, bool canMaximize = false) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Expected O, but got Unknown //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Expected O, but got Unknown InitializeComponent(); Gestor.Application.Actions.Actions.EnableMainMenu = (Action)Delegate.Combine(Gestor.Application.Actions.Actions.EnableMainMenu, new Action(HabilitarMenu)); Gestor.Application.Actions.Actions.CloseHoster = (Action)Delegate.Combine(Gestor.Application.Actions.Actions.CloseHoster, new Action(base.Close)); ((UIElement)MinimizeButton).MouseEnter += new MouseEventHandler(TopControls_OnMouseEnter); ((UIElement)MinimizeButton).MouseLeave += new MouseEventHandler(TopControls_OnMouseLeave); ((UIElement)MaximizeButton).MouseEnter += new MouseEventHandler(TopControls_OnMouseEnter); ((UIElement)MaximizeButton).MouseLeave += new MouseEventHandler(TopControls_OnMouseLeave); ((UIElement)CloseButton).MouseEnter += new MouseEventHandler(TopControls_OnMouseEnter); ((UIElement)CloseButton).MouseLeave += new MouseEventHandler(TopControls_OnMouseLeave); ContentControl.Content = control.Content; ((FrameworkElement)ContentControl).DataContext = ((FrameworkElement)control).DataContext; ((FrameworkElement)ContentControl).Tag = titulo; MaximizeButtonPath.Data = Geometry.Parse((string)Application.Current.Resources[(object)"Restore"]); if ((x.HasValue || y.HasValue) && !canMaximize) { ((Window)this).WindowState = (WindowState)0; ((Control)this).BorderThickness = new Thickness(1.0); WindowChrome.ResizeBorderThickness = new Thickness(4.0); WindowChrome.CaptionHeight = 30.0; MaximizeButtonPath.Data = Geometry.Parse((string)Application.Current.Resources[(object)"Maximize"]); } if (x.HasValue) { if (x.Value < ((FrameworkElement)this).Width) { ((FrameworkElement)this).MinWidth = x.Value; if (!canMaximize) { ((FrameworkElement)this).Width = x.Value; ((FrameworkElement)this).MaxWidth = x.Value; } } else { if (!canMaximize) { ((FrameworkElement)this).MaxWidth = x.Value; ((FrameworkElement)this).Width = x.Value; } ((FrameworkElement)this).MinWidth = x.Value; } } if (y.HasValue) { if (y.Value < ((FrameworkElement)this).Height) { ((FrameworkElement)this).MinHeight = y.Value; if (!canMaximize) { ((FrameworkElement)this).Height = y.Value; ((FrameworkElement)this).MaxHeight = y.Value; } } else { if (!canMaximize) { ((FrameworkElement)this).MaxHeight = y.Value; ((FrameworkElement)this).Height = y.Value; } ((FrameworkElement)this).MinHeight = y.Value; } } if (x.HasValue && y.HasValue && !canMaximize) { ((UIElement)MaximizeButton).IsEnabled = false; ((UIElement)MinimizeButton).IsEnabled = false; ((Shape)MaximizeButtonPath).Stroke = (Brush)new SolidColorBrush(Colors.Gray); ((Shape)MinimizeButtonPath).Stroke = (Brush)new SolidColorBrush(Colors.Gray); } else { ((Window)this).ResizeMode = (ResizeMode)2; } ((Window)this).Title = titulo; Tela = ((object)control).GetType().Name; HosterDialog.Identifier = $"Dialog{Tela}{Guid.NewGuid()}"; } private void HabilitarMenu(bool enable) { ((UIElement)Menu).IsEnabled = enable; } private void SnackbarMessage_ActionClick(object sender, RoutedEventArgs e) { Snackbar.IsActive = false; } private void HosterWindow_OnLoaded(object sender, RoutedEventArgs e) { Task.Run(delegate { Thread.Sleep(500); ((DispatcherObject)Application.Current).Dispatcher.Invoke((Action)delegate { ((Window)this).Topmost = false; }); }); } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] public void InitializeComponent() { if (!_contentLoaded) { _contentLoaded = true; Uri uri = new Uri("/Gestor.Application;component/views/generic/hosterwindow.xaml", UriKind.Relative); Application.LoadComponent((object)this, uri); } } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] [EditorBrowsable(EditorBrowsableState.Never)] void IComponentConnector.Connect(int connectionId, object target) { //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Expected O, but got Unknown //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Expected O, but got Unknown //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Expected O, but got Unknown //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Expected O, but got Unknown //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Expected O, but got Unknown //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Expected O, but got Unknown //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Expected O, but got Unknown switch (connectionId) { case 1: ((FrameworkElement)(HosterWindow)target).Initialized += Window_OnInitialized; ((FrameworkElement)(HosterWindow)target).Loaded += new RoutedEventHandler(HosterWindow_OnLoaded); break; case 2: WindowChrome = (WindowChrome)target; break; case 3: Menu = (Grid)target; break; case 4: MinimizeButton = (Grid)target; ((UIElement)MinimizeButton).MouseLeftButtonDown += new MouseButtonEventHandler(TopControls_OnMouseLeftButtonDown); ((UIElement)MinimizeButton).MouseLeftButtonUp += new MouseButtonEventHandler(TopControls_OnMouseLeftButtonUp); break; case 5: MinimizeButtonPath = (Path)target; break; case 6: MaximizeButton = (Grid)target; ((UIElement)MaximizeButton).MouseLeftButtonDown += new MouseButtonEventHandler(TopControls_OnMouseLeftButtonDown); ((UIElement)MaximizeButton).MouseLeftButtonUp += new MouseButtonEventHandler(TopControls_OnMouseLeftButtonUp); break; case 7: MaximizeButtonPath = (Path)target; break; case 8: CloseButton = (Grid)target; ((UIElement)CloseButton).MouseLeftButtonDown += new MouseButtonEventHandler(TopControls_OnMouseLeftButtonDown); ((UIElement)CloseButton).MouseLeftButtonUp += new MouseButtonEventHandler(TopControls_OnMouseLeftButtonUp); break; case 9: ContentControl = (ContentControl)target; break; case 10: HosterDialog = (DialogHost)target; break; case 11: DrawerHost = (DrawerHost)target; break; case 12: Snackbar = (Snackbar)target; break; case 13: ((SnackbarMessage)target).ActionClick += new RoutedEventHandler(SnackbarMessage_ActionClick); break; default: _contentLoaded = true; break; } } }