diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopupBase.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopupBase.cs index 2386e74b56..c40e37f23b 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopupBase.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopupBase.cs @@ -4,7 +4,7 @@ using System; using System.Windows.Controls.Primitives; using System.Windows.Input; - +using ICSharpCode.Core.Presentation; using ICSharpCode.SharpDevelop.Editor; namespace ICSharpCode.SharpDevelop.Refactoring @@ -12,7 +12,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring /// /// Description of ContextActionsPopupBase. /// - public abstract class ContextActionsPopupBase : Popup + public abstract class ContextActionsPopupBase : ExtendedPopup { protected ContextActionsPopupBase() { diff --git a/src/Main/ICSharpCode.Core.Presentation/ExtendedPopup.cs b/src/Main/ICSharpCode.Core.Presentation/ExtendedPopup.cs index cc0e2399ed..299e9955fd 100644 --- a/src/Main/ICSharpCode.Core.Presentation/ExtendedPopup.cs +++ b/src/Main/ICSharpCode.Core.Presentation/ExtendedPopup.cs @@ -14,41 +14,45 @@ namespace ICSharpCode.Core.Presentation /// public class ExtendedPopup : Popup { - RoutedEventHandler lostFocus; - RoutedEventHandler gotFocus; + Visibility oldState; + IntPtr hwnd; -// protected override void OnOpened(EventArgs e) -// { -// IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(Child)).Handle; -// SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); -// lostFocus = new RoutedEventHandler(MainWindowLostFocus); -// gotFocus = new RoutedEventHandler(MainWindowGotFocus); -// AddHandler(Window., lostFocus); -// AddHandler(Window.GotFocusEvent, gotFocus); -// -// } -// -// protected override void OnClosed(EventArgs e) -// { -// RemoveHandler(Window.LostFocusEvent, lostFocus); -// RemoveHandler(Window.GotFocusEvent, gotFocus); -// } -// -// void MainWindowLostFocus(object sender, RoutedEventArgs e) -// { -// Visibility = Visibility.Collapsed; -// } -// -// void MainWindowGotFocus(object sender, RoutedEventArgs e) -// { -// Visibility = Visibility.Visible; -// } + protected override void OnOpened(EventArgs e) + { + hwnd = ((HwndSource)PresentationSource.FromVisual(Child)).Handle; + SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + + Application.Current.Activated += ApplicationActivated; + Application.Current.Deactivated += ApplicationDeactivated; + } + + protected override void OnClosed(EventArgs e) + { + Application.Current.Activated -= ApplicationActivated; + Application.Current.Deactivated -= ApplicationDeactivated; + } + + void ApplicationActivated(object sender, EventArgs e) + { + Visibility = oldState; + SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + } + + void ApplicationDeactivated(object sender, EventArgs e) + { + oldState = Visibility; + Visibility = Visibility.Hidden; + } + #region Win32 API const int SWP_NOMOVE = 0x002; const int SWP_NOSIZE = 0x001; static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); + static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); + static readonly IntPtr HWND_TOP = new IntPtr(0); [DllImport("user32", EntryPoint="SetWindowPos")] - static extern int SetWindowPos(IntPtr hWnd, IntPtr hwndInsertAfter, int x, int y, int cx, int cy, uint uFlags); + static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); + #endregion } }