]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/nonownedwnd.mm
Another place we need an autorelease pool.
[wxWidgets.git] / src / osx / cocoa / nonownedwnd.mm
index e2ce53b5a6bd2f6eeb60a96b1fbd29b702bb6091..48abcb3a90a347e52596e3d7b443daa16e0b3928 100644 (file)
@@ -61,6 +61,8 @@ wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
 // wx native implementation classes
 //
 
+typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector);
+
 @interface wxNSWindow : NSWindow
 
 {
@@ -69,7 +71,7 @@ wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
 
 - (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation;
 - (wxNonOwnedWindowCocoaImpl*) implementation;
-
+- (void)noResponderFor: (SEL) selector;
 @end
 
 @implementation wxNSWindow
@@ -84,18 +86,56 @@ wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
     return impl;
 }
 
+// NB: if we don't do this, all key downs that get handled lead to a NSBeep
+- (void)noResponderFor: (SEL) selector
+{
+    if (selector != @selector(keyDown:))
+    {
+        wxOSX_NoResponderHandlerPtr superimpl = (wxOSX_NoResponderHandlerPtr) [[self superclass] instanceMethodForSelector:@selector(noResponderFor:)];
+        superimpl(self, @selector(noResponderFor:), selector);
+    }
+}
 
 @end
 
-@interface wxNSPanel : wxNSWindow
+@interface wxNSPanel : NSPanel
 
 {
+    wxNonOwnedWindowCocoaImpl* impl;
 }
 
+- (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation;
+- (wxNonOwnedWindowCocoaImpl*) implementation;
+- (void)noResponderFor: (SEL) selector;
 @end
 
 @implementation wxNSPanel 
 
+- (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation
+{
+    impl = theImplementation;
+}
+
+- (BOOL)canBecomeKeyWindow
+{
+    return YES;
+}
+
+- (wxNonOwnedWindowCocoaImpl*) implementation
+{
+    return impl;
+}
+
+// NB: if we don't do this, all key downs that get handled lead to a NSBeep
+- (void)noResponderFor: (SEL) selector
+{
+    if (selector != @selector(keyDown:))
+    {
+        wxOSX_NoResponderHandlerPtr superimpl = (wxOSX_NoResponderHandlerPtr) [[self superclass] instanceMethodForSelector:@selector(noResponderFor:)];
+        superimpl(self, @selector(noResponderFor:), selector);
+    }
+}
+
 @end
 
 
@@ -109,8 +149,8 @@ wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
 
 - (void)windowDidResize:(NSNotification *)notification;
 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
-- (void)windowDidResignMain:(NSNotification *)notification;
-- (void)windowDidBecomeMain:(NSNotification *)notification;
+- (void)windowDidResignKey:(NSNotification *)notification;
+- (void)windowDidBecomeKey:(NSNotification *)notification;
 - (void)windowDidMove:(NSNotification *)notification;
 - (BOOL)windowShouldClose:(id)window;
 
@@ -184,7 +224,7 @@ wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
     }
 }
 
-- (void)windowDidBecomeMain:(NSNotification *)notification
+- (void)windowDidBecomeKey:(NSNotification *)notification
 {
     wxNSWindow* window = (wxNSWindow*) [notification object];
     wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
@@ -196,7 +236,7 @@ wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
     }
 }
 
-- (void)windowDidResignMain:(NSNotification *)notification
+- (void)windowDidResignKey:(NSNotification *)notification
 {
     wxNSWindow* window = (wxNSWindow*) [notification object];
     wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
@@ -204,7 +244,15 @@ wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
     {
         wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
         if ( wxpeer )
+        {
             wxpeer->HandleActivated(0, false);
+            // Needed for popup window since the firstResponder 
+            // (focus in wx) doesn't change when this 
+            // TLW becomes inactive.
+            wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
+            event.SetEventObject(wxpeer);
+            wxpeer->HandleWindowEvent(event);
+        }
     }
 }
 
@@ -248,8 +296,11 @@ long style, long extraStyle, const wxString& name )
 
     int windowstyle = NSBorderlessWindowMask;
     
-    if ( style & wxFRAME_TOOL_WINDOW )
+    if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) || 
+            GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
+    {
         m_macWindow = [wxNSPanel alloc];
+    }
     else
         m_macWindow = [wxNSWindow alloc];
     
@@ -257,11 +308,12 @@ long style, long extraStyle, const wxString& name )
     
     if ( style & wxFRAME_TOOL_WINDOW )
     {
-        if ( ( style & wxSTAY_ON_TOP ) )
-            level = kCGUtilityWindowLevel;
-        else
-            level = kCGFloatingWindowLevel ;
-        
+        windowstyle |= NSUtilityWindowMask;
+        if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
+            ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
+        {
+            windowstyle |= NSTitledWindowMask ;
+        }
     }
     else if ( ( style & wxPOPUP_WINDOW ) )
     {
@@ -325,12 +377,11 @@ long style, long extraStyle, const wxString& name )
     if ( extraStyle & wxFRAME_EX_METAL)
         windowstyle |= NSTexturedBackgroundWindowMask;
 
+    if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
+        level = kCGFloatingWindowLevel;
+
     if ( ( style & wxSTAY_ON_TOP ) )
         level = kCGUtilityWindowLevel;
-/*
-    if ( ( style & wxFRAME_FLOAT_ON_PARENT ) )
-        group = GetWindowGroupOfClass(kFloatingWindowClass);
-        */
     
     NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
     
@@ -346,7 +397,7 @@ long style, long extraStyle, const wxString& name )
 
     [m_macWindow setDelegate:controller];
     
-    // [m_macWindow makeKeyAndOrderFront:nil];
+    [m_macWindow setAcceptsMouseMovedEvents: YES];
 }
 
 
@@ -369,7 +420,7 @@ bool wxNonOwnedWindowCocoaImpl::Show(bool show)
 {
     if ( show )
     {
-        [m_macWindow orderFront:nil];
+        [m_macWindow makeKeyAndOrderFront:nil];
         [[m_macWindow contentView] setNeedsDisplay:YES];
     }
     else 
@@ -446,11 +497,13 @@ void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
     height = rect.size.height;
 }
 
-void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &right, int &width, int &height ) const
+void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
 {
     NSRect outer = NSMakeRect(100,100,100,100);
     NSRect content = [NSWindow contentRectForFrameRect:outer styleMask:[m_macWindow styleMask] ];
     NSRect rect = [[m_macWindow contentView] frame];
+    left = rect.origin.x;
+    top = rect.origin.y;
     width = rect.size.width;
     height = rect.size.height;
 }