]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/nonownedwnd.mm
Correct IsMaximized() in wxOSX for non-resizable windows.
[wxWidgets.git] / src / osx / cocoa / nonownedwnd.mm
index 46803a291d3b48a96605eda27bf6997c7aa80d9f..df2a8949529a08c708469e0fdc0a630a4eb85551 100644 (file)
@@ -100,6 +100,7 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector
 // even when the programmer explicitly wants to hide it.
 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
 {
+    wxUnusedVar(screen);
     return frameRect;
 }
 
@@ -194,7 +195,7 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector
 // controller
 //
 
-@interface wxNonOwnedWindowController : NSObject
+@interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
 {
 }
 
@@ -204,6 +205,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
 
@@ -327,6 +329,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 )
@@ -351,9 +366,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,
@@ -490,7 +505,7 @@ void wxNonOwnedWindowCocoaImpl::Lower()
 
 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
 {
-    [m_macWindow orderBack:nil];
+    [m_macWindow orderFront:nil];
     [[m_macWindow contentView] setNeedsDisplay: YES];
 }
 
@@ -629,7 +644,19 @@ void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding
 
 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
 {
-    return [m_macWindow isZoomed];
+    if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
+    {
+        return [m_macWindow isZoomed];
+    }
+    else
+    {
+        NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
+        NSRect rectWindow = [m_macWindow frame];
+        return (rectScreen.origin.x == rectWindow.origin.x &&
+                rectScreen.origin.y == rectWindow.origin.y &&
+                rectScreen.size.width == rectWindow.size.width &&
+                rectScreen.size.height == rectWindow.size.height);
+    }
 }
 
 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
@@ -692,8 +719,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 )
@@ -727,6 +771,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 )
 {