SEBWIN-326: Disabled close button for main browser window.
This commit is contained in:
		
							parent
							
								
									305110f239
								
							
						
					
					
						commit
						931228b6f1
					
				
					 4 changed files with 59 additions and 0 deletions
				
			
		|  | @ -142,6 +142,14 @@ namespace SafeExamBrowser.UserInterface.Desktop | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		private void BrowserWindow_Loaded(object sender, RoutedEventArgs e) | ||||||
|  | 		{ | ||||||
|  | 			if (isMainWindow) | ||||||
|  | 			{ | ||||||
|  | 				WindowUtility.DisableCloseButtonFor(this); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		private CustomPopupPlacement[] MenuPopup_PlacementCallback(Size popupSize, Size targetSize, Point offset) | 		private CustomPopupPlacement[] MenuPopup_PlacementCallback(Size popupSize, Size targetSize, Point offset) | ||||||
| 		{ | 		{ | ||||||
| 			return new[] | 			return new[] | ||||||
|  | @ -196,6 +204,7 @@ namespace SafeExamBrowser.UserInterface.Desktop | ||||||
| 			BackwardButton.Click += (o, args) => BackwardNavigationRequested?.Invoke(); | 			BackwardButton.Click += (o, args) => BackwardNavigationRequested?.Invoke(); | ||||||
| 			Closing += BrowserWindow_Closing; | 			Closing += BrowserWindow_Closing; | ||||||
| 			ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke(); | 			ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke(); | ||||||
|  | 			Loaded += BrowserWindow_Loaded; | ||||||
| 			MenuButton.Click += (o, args) => MenuPopup.IsOpen = !MenuPopup.IsOpen; | 			MenuButton.Click += (o, args) => MenuPopup.IsOpen = !MenuPopup.IsOpen; | ||||||
| 			MenuButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver)); | 			MenuButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver)); | ||||||
| 			MenuPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(MenuPopup_PlacementCallback); | 			MenuPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(MenuPopup_PlacementCallback); | ||||||
|  |  | ||||||
|  | @ -142,6 +142,14 @@ namespace SafeExamBrowser.UserInterface.Mobile | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		private void BrowserWindow_Loaded(object sender, RoutedEventArgs e) | ||||||
|  | 		{ | ||||||
|  | 			if (isMainWindow) | ||||||
|  | 			{ | ||||||
|  | 				WindowUtility.DisableCloseButtonFor(this); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		private CustomPopupPlacement[] MenuPopup_PlacementCallback(Size popupSize, Size targetSize, Point offset) | 		private CustomPopupPlacement[] MenuPopup_PlacementCallback(Size popupSize, Size targetSize, Point offset) | ||||||
| 		{ | 		{ | ||||||
| 			return new[] | 			return new[] | ||||||
|  | @ -196,6 +204,7 @@ namespace SafeExamBrowser.UserInterface.Mobile | ||||||
| 			BackwardButton.Click += (o, args) => BackwardNavigationRequested?.Invoke(); | 			BackwardButton.Click += (o, args) => BackwardNavigationRequested?.Invoke(); | ||||||
| 			Closing += BrowserWindow_Closing; | 			Closing += BrowserWindow_Closing; | ||||||
| 			ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke(); | 			ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke(); | ||||||
|  | 			Loaded += BrowserWindow_Loaded; | ||||||
| 			MenuButton.Click += (o, args) => MenuPopup.IsOpen = !MenuPopup.IsOpen; | 			MenuButton.Click += (o, args) => MenuPopup.IsOpen = !MenuPopup.IsOpen; | ||||||
| 			MenuButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver)); | 			MenuButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver)); | ||||||
| 			MenuPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(MenuPopup_PlacementCallback); | 			MenuPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(MenuPopup_PlacementCallback); | ||||||
|  |  | ||||||
|  | @ -67,6 +67,7 @@ | ||||||
|     <Compile Include="Utilities\IconResourceLoader.cs" /> |     <Compile Include="Utilities\IconResourceLoader.cs" /> | ||||||
|     <Compile Include="Utilities\UrlRandomizer.cs" /> |     <Compile Include="Utilities\UrlRandomizer.cs" /> | ||||||
|     <Compile Include="Utilities\VisualExtensions.cs" /> |     <Compile Include="Utilities\VisualExtensions.cs" /> | ||||||
|  |     <Compile Include="Utilities\WindowUtility.cs" /> | ||||||
|     <Compile Include="Utilities\XamlIconResource.cs" /> |     <Compile Include="Utilities\XamlIconResource.cs" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|  |  | ||||||
|  | @ -0,0 +1,40 @@ | ||||||
|  | /* | ||||||
|  |  * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) | ||||||
|  |  *  | ||||||
|  |  * This Source Code Form is subject to the terms of the Mozilla Public | ||||||
|  |  * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||
|  |  * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | using System; | ||||||
|  | using System.Runtime.InteropServices; | ||||||
|  | using System.Windows; | ||||||
|  | using System.Windows.Interop; | ||||||
|  | 
 | ||||||
|  | namespace SafeExamBrowser.UserInterface.Shared.Utilities | ||||||
|  | { | ||||||
|  | 	public static class WindowUtility | ||||||
|  | 	{ | ||||||
|  | 		private const uint MF_BYCOMMAND = 0x00000000; | ||||||
|  | 		private const uint MF_GRAYED = 0x00000001; | ||||||
|  | 		private const uint MF_ENABLED = 0x00000000; | ||||||
|  | 		private const uint SC_CLOSE = 0xF060; | ||||||
|  | 
 | ||||||
|  | 		public static void DisableCloseButtonFor(Window window) | ||||||
|  | 		{ | ||||||
|  | 			var handle = new WindowInteropHelper(window); | ||||||
|  | 			var systemMenu = GetSystemMenu(handle.Handle, false); | ||||||
|  | 
 | ||||||
|  | 			if (systemMenu != IntPtr.Zero) | ||||||
|  | 			{ | ||||||
|  | 				EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		[DllImport("user32.dll")] | ||||||
|  | 		private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert); | ||||||
|  | 
 | ||||||
|  | 		[DllImport("user32.dll")] | ||||||
|  | 		private static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable); | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 dbuechel
						dbuechel