]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/nonownedwnd.mm
Since wxDialog::Show(false) only calls wxWindow::Show, we must explicitly hide the...
[wxWidgets.git] / src / osx / cocoa / nonownedwnd.mm
index e5e031a6046bf90a7a4ed9bd7bbebd6fcbe01382..2cd07f9ef2f3beba4dd2ac96511a1ee6d60f1a03 100644 (file)
@@ -132,6 +132,14 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector
     }
 }
 
+// We need this for borderless windows, i.e. shaped windows or windows without  
+// a title bar. For more info, see:
+// http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html
+- (BOOL)canBecomeKeyWindow
+{
+    return YES;
+}
+
 @end
 
 @interface wxNSPanel : NSPanel
@@ -186,7 +194,7 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector
 // controller
 //
 
-@interface wxNonOwnedWindowController : NSObject
+@interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
 {
 }
 
@@ -196,6 +204,7 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector
 - (void)windowDidBecomeKey:(NSNotification *)notification;
 - (void)windowDidMove:(NSNotification *)notification;
 - (BOOL)windowShouldClose:(id)window;
+- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
 
 @end
 
@@ -319,6 +328,19 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector
     return nil;
 }
 
+- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
+{
+    wxNonOwnedWindowCocoaImpl* windowimpl = [(wxNSWindow*)window implementation];
+    if ( windowimpl )
+    {
+        wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
+        wxMaximizeEvent event(wxpeer->GetId());
+        event.SetEventObject(wxpeer);
+        return !wxpeer->HandleWindowEvent(event);
+    }
+    return true;
+}
+
 @end
 
 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
@@ -343,9 +365,9 @@ wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
     [m_macWindow release];
 }
 
-void wxNonOwnedWindowCocoaImpl::Destroy()
+void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
 {
-    wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) );
+    [m_macWindow setDelegate:nil];
 }
 
 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), const wxPoint& pos, const wxSize& size,
@@ -449,6 +471,7 @@ long style, long extraStyle, const wxString& WXUNUSED(name) )
     NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
 
     [m_macWindow setImplementation:this];
+    r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
 
     [m_macWindow initWithContentRect:r
         styleMask:windowstyle
@@ -481,7 +504,8 @@ void wxNonOwnedWindowCocoaImpl::Lower()
 
 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
 {
-    [[m_macWindow contentView] setNeedsDisplay:YES];
+    [m_macWindow orderFront:nil];
+    [[m_macWindow contentView] setNeedsDisplay: YES];
 }
 
 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
@@ -493,7 +517,7 @@ bool wxNonOwnedWindowCocoaImpl::Show(bool show)
             [m_macWindow makeKeyAndOrderFront:nil];
         else 
             [m_macWindow orderFront:nil]; 
-        ShowWithoutActivating();
+        [[m_macWindow contentView] setNeedsDisplay: YES];
     }
     else
         [m_macWindow orderOut:nil];
@@ -556,8 +580,14 @@ void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
     }
 }
 
-bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle WXUNUSED(style))
+bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
 {
+    if ( style == wxBG_STYLE_TRANSPARENT )
+    {
+        [m_macWindow setOpaque:NO];
+        [m_macWindow setBackgroundColor:[NSColor clearColor]];
+    }
+
     return true;
 }
 
@@ -600,7 +630,10 @@ void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width,
 
 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
 {
-    return false;
+    [m_macWindow setOpaque:NO];
+    [m_macWindow setBackgroundColor:[NSColor clearColor]];
+
+    return true;
 }
 
 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
@@ -673,8 +706,25 @@ bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
     return true;
 }
 
-void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int WXUNUSED(flags))
+void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
 {
+    NSRequestUserAttentionType flagsOSX;
+    switch ( flagsWX )
+    {
+        case wxUSER_ATTENTION_INFO:
+            flagsOSX = NSInformationalRequest;
+            break;
+
+        case wxUSER_ATTENTION_ERROR:
+            flagsOSX = NSCriticalRequest;
+            break;
+
+        default:
+            wxFAIL_MSG( "invalid RequestUserAttention() flags" );
+            return;
+    }
+
+    [NSApp requestUserAttention:flagsOSX];
 }
 
 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
@@ -708,6 +758,16 @@ bool wxNonOwnedWindowCocoaImpl::IsActive()
     return [m_macWindow isKeyWindow];
 }
 
+void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
+{
+    [m_macWindow setDocumentEdited:modified];
+}
+
+bool wxNonOwnedWindowCocoaImpl::IsModified() const
+{
+    return [m_macWindow isDocumentEdited];
+}
+
 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
     long style, long extraStyle, const wxString& name )
 {