2007-11-07 Geoff Norton <gnorton@novell.com>
authorGeoff Norton <grompf@sublimeintervention.com>
Wed, 7 Nov 2007 17:56:07 +0000 (17:56 -0000)
committerGeoff Norton <grompf@sublimeintervention.com>
Wed, 7 Nov 2007 17:56:07 +0000 (17:56 -0000)
    * OSXStructs.cs: Add the kEventClassApplication constants.
    * XplatUIOSX.cs: Send a WM_LBUTTONDOWN to the Grab window when the
    application is deactivated otherwise Menu overlays linger on top of
    other application windows.

svn path=/trunk/mcs/; revision=89132

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/OSXStructs.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIOSX.cs

index 3e4c37b2478966ff74c7e61567cb846d654917af..85ea49863593345c13d08cc8607021d15231070a 100644 (file)
@@ -4,6 +4,13 @@
        getting a Select call on click, so this call needs to be here for now.
        Unfixes #325809
 
+2007-11-07  Geoff Norton  <gnorton@novell.com>
+
+       * OSXStructs.cs: Add the kEventClassApplication constants.
+       * XplatUIOSX.cs: Send a WM_LBUTTONDOWN to the Grab window when the 
+       application is deactivated otherwise Menu overlays linger on top of
+       other application windows.
+
 2007-11-07  Geoff Norton  <gnorton@novell.com>
 
        * XplatUIOSX.cs: Dont throw an exception on OverrideCursor as we
index 2ad8186348608b58cae36ed575b3a66595803807..6abd813075a5fe87953ec1017bbd657226c2462f 100644 (file)
@@ -80,7 +80,25 @@ namespace System.Windows.Forms {
                #endregion
                
                #region kEventClassApplication constants
-               // TODO: We dont use these yet; fill if needed
+               internal const uint kEventAppActivated = 1;
+               internal const uint kEventAppDeactivated = 2;
+               internal const uint kEventAppQuit = 3;
+               internal const uint kEventAppLaunchNotification = 4;
+               internal const uint kEventAppLaunched = 5;
+               internal const uint kEventAppTerminated = 6;
+               internal const uint kEventAppFrontSwitched = 7;
+               internal const uint kEventAppFocusMenuBar = 8;
+               internal const uint kEventAppFocusNextDocumentWindow = 9;
+               internal const uint kEventAppFocusNextFloatingWindow = 10;
+               internal const uint kEventAppFocusToolbar = 11;
+               internal const uint kEventAppFocusDrawer = 12;
+               internal const uint kEventAppGetDockTileMenu = 20;
+               internal const uint kEventAppIsEventInInstantMouser = 104;
+               internal const uint kEventAppHidden = 107;
+               internal const uint kEventAppShown = 108;
+               internal const uint kEventAppSystemUIModeChanged = 109;
+               internal const uint kEventAppAvailableWindowBoundsChanged = 110;
+               internal const uint kEventAppActiveWindowChanged = 111;
                #endregion
 
                #region kEventClassAppleEvent constants
index 60b160dabfee62373f63e417f51def79c36eb875..557f0683030b39009d6ed8b9e011196f95c2ca98 100644 (file)
@@ -97,6 +97,10 @@ namespace System.Windows.Forms {
                                                                        new EventTypeSpec (OSXConstants.kEventClassKeyboard, OSXConstants.kEventRawKeyRepeat),
                                                                        new EventTypeSpec (OSXConstants.kEventClassKeyboard, OSXConstants.kEventRawKeyUp)
                                                                        };
+               private static EventTypeSpec [] application_events = new EventTypeSpec[] {
+                                                                       new EventTypeSpec (OSXConstants.kEventClassApplication, OSXConstants.kEventAppActivated),
+                                                                       new EventTypeSpec (OSXConstants.kEventClassApplication, OSXConstants.kEventAppDeactivated)
+                                                                       };
                                                                        
                
                // Message loop
@@ -183,13 +187,16 @@ namespace System.Windows.Forms {
                        SetRect (ref rect, (short)0, (short)0, (short)0, (short)0);
                        ProcessSerialNumber psn = new ProcessSerialNumber();
 
-                       CheckError (GetCurrentProcess( ref psn ), "GetCurrentProcess ()");
-                       CheckError (TransformProcessType (ref psn, 1), "TransformProcessType ()");
-                       CheckError (SetFrontProcess (ref psn), "SetFrontProcess ()");
-                       CheckError (CreateNewWindow (WindowClass.kDocumentWindowClass, WindowAttributes.kWindowStandardHandlerAttribute | WindowAttributes.kWindowCloseBoxAttribute | WindowAttributes.kWindowFullZoomAttribute | WindowAttributes.kWindowCollapseBoxAttribute | WindowAttributes.kWindowResizableAttribute | WindowAttributes.kWindowCompositingAttribute, ref rect, ref FosterParent), "CreateFosterParent ()");
+                       InstallEventHandler (GetApplicationEventTarget (), CarbonEventHandler, (uint)application_events.Length, application_events, IntPtr.Zero, IntPtr.Zero);
+                       GetCurrentProcess( ref psn );
+                       TransformProcessType (ref psn, 1);
+                       SetFrontProcess (ref psn);
+
+                       CreateNewWindow (WindowClass.kDocumentWindowClass, WindowAttributes.kWindowStandardHandlerAttribute | WindowAttributes.kWindowCloseBoxAttribute | WindowAttributes.kWindowFullZoomAttribute | WindowAttributes.kWindowCollapseBoxAttribute | WindowAttributes.kWindowResizableAttribute | WindowAttributes.kWindowCompositingAttribute, ref rect, ref FosterParent);
                        
                        CreateNewWindow (WindowClass.kOverlayWindowClass, WindowAttributes.kWindowNoUpdatesAttribute | WindowAttributes.kWindowNoActivatesAttribute, ref rect, ref ReverseWindow);
                        InstallEventHandler (GetWindowEventTarget (ReverseWindow), CarbonEventHandler, (uint)window_events.Length, window_events, ReverseWindow, IntPtr.Zero);
+
                        
                        // Get some values about bar heights
                        Rect structRect = new Rect ();
@@ -265,6 +272,11 @@ namespace System.Windows.Forms {
                                                retVal = ProcessControlEvent (inEvent, eventKind, handle);
                                                break;
                                        }
+                                       // application
+                                       case OSXConstants.kEventClassApplication: {
+                                               retVal = ProcessApplicationEvent (inEvent, eventKind, handle);
+                                               break;
+                                       }
                                        default: {
                                                break;
                                        }
@@ -373,6 +385,23 @@ namespace System.Windows.Forms {
                        return -9874;
                }
                                
+               private int ProcessApplicationEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
+                       switch (eventKind) {
+                               case OSXConstants.kEventAppDeactivated: {
+                                       if (FocusWindow != IntPtr.Zero) {
+                                               SendMessage(FocusWindow, Msg.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);
+                                       } 
+                                       /* If we deactivate we need to send a MOUSEDOWN/MOUSEUP to kill overlay windows */
+                                       if (GrabWindowHwnd != null) {
+                                               SendMessage(GrabWindowHwnd.Handle, Msg.WM_LBUTTONDOWN, (IntPtr)MsgButtons.MK_LBUTTON, (IntPtr) (mouse_position.X << 16 | mouse_position.Y));
+                                       }
+                                       break;
+                               }
+                       }
+
+                       return -9874;
+               }
+
                private int ProcessMouseEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
                        MSG msg = new MSG ();           
                        
@@ -2312,10 +2341,6 @@ namespace System.Windows.Forms {
                                        }
                                        break;
                                }
-                               case Msg.WM_SETFOCUS: {
-                                       break;   
-                               }                                       
-                               
                        }
                        
                        return Keyboard.TranslateMessage (ref msg);
@@ -2535,6 +2560,8 @@ namespace System.Windows.Forms {
                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
                static extern int SetKeyboardFocus (IntPtr windowHdn, IntPtr cntrlHnd, short partcode);
 
+               [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+               static extern IntPtr GetApplicationEventTarget ();
                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
                internal static extern IntPtr GetWindowEventTarget (IntPtr window);
                [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]