wxCocoa: Implement wxTopLevelWindow::SetDefaultItem
authorDavid Elliott <dfe@tgwbd.org>
Fri, 20 Jul 2007 20:35:57 +0000 (20:35 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Fri, 20 Jul 2007 20:35:57 +0000 (20:35 +0000)
Copyright 2007, Software 2000 Ltd.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47600 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/toplevel.h
src/cocoa/toplevel.mm

index da0129e07db3323e00b65d6e03ac1e95afc89959..4a4780e9b65c297173210df0d082a80e085cf3d6 100644 (file)
@@ -106,6 +106,8 @@ public:
     virtual void SetTitle( const wxString& title);
     virtual wxString GetTitle() const;
 
+    // Default button (item)
+    wxWindow *SetDefaultItem(wxWindow *win);
 
 // Things I may/may not do
 //    virtual void SetIcons(const wxIconBundle& icons);
index 83dd00623d1cc066665c0a69cb0063b0c3af6bb2..f2e44d4b44e36da529cded0376d5552409f5dbbd 100644 (file)
@@ -36,6 +36,8 @@
 #include "wx/cocoa/objc/NSView.h"
 #include "wx/cocoa/objc/NSWindow.h"
 #import <AppKit/NSPanel.h>
+#import <AppKit/NSButtonCell.h>
+#import <AppKit/NSControl.h>
 
 // ----------------------------------------------------------------------------
 // globals
@@ -353,6 +355,28 @@ wxString wxTopLevelWindowCocoa::GetTitle() const
     return wxStringWithNSString([m_cocoaNSWindow title]);
 }
 
+wxWindow* wxTopLevelWindowCocoa::SetDefaultItem(wxWindow *win)
+{
+    wxWindow *old = wxTopLevelWindowBase::SetDefaultItem(win);
+    NSView *newView = win->GetNSView();
+
+    NSCell *newCell;
+    // newView does not have to be an NSControl, we only cast to NSControl*
+    // to silence the warning about cell not being implemented.
+    if(newView != nil && [newView respondsToSelector:@selector(cell)])
+        newCell = [(NSControl*)newView cell];
+    else
+        newCell = nil;
+
+    if(newCell != nil && ![newCell isKindOfClass:[NSButtonCell class]])
+    {   // It's not an NSButtonCell, set the default to nil.
+        newCell = nil;
+    }
+
+    [GetNSWindow() setDefaultButtonCell:(NSButtonCell*)newCell];
+    return old;
+}
+
 bool wxTopLevelWindowCocoa::ShowFullScreen(bool show, long style)
 {
     return false;