]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/frame.mm
deal correctly with vsnprintf() implementations which always NUL-terminate the buffer...
[wxWidgets.git] / src / cocoa / frame.mm
index 7ed2c50c8f809595dc1427bef11a855eeb28caad..4a3569d81e6dea670c1666c54f80d66d723166ba 100644 (file)
@@ -1,19 +1,21 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        cocoa/frame.mm
+// Name:        src/cocoa/frame.mm
 // Purpose:     wxFrame
 // Author:      David Elliott
 // Modified by:
 // Created:     2003/03/16
 // Purpose:     wxFrame
 // Author:      David Elliott
 // Modified by:
 // Created:     2003/03/16
-// RCS-ID:      $Id:
+// RCS-ID:      $Id$
 // Copyright:   (c) 2003 David Elliott
 // Copyright:   (c) 2003 David Elliott
-// Licence:     wxWindows license
+// Licence:     wxWidgets licence
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/wxprec.h"
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/wxprec.h"
+
+#include "wx/frame.h"
+
 #ifndef WX_PRECOMP
     #include "wx/log.h"
     #include "wx/app.h"
 #ifndef WX_PRECOMP
     #include "wx/log.h"
     #include "wx/app.h"
-    #include "wx/frame.h"
     #include "wx/menu.h"
     #include "wx/toolbar.h"
     #include "wx/statusbr.h"
     #include "wx/menu.h"
     #include "wx/toolbar.h"
     #include "wx/statusbr.h"
@@ -25,6 +27,7 @@
 #import <AppKit/NSWindow.h>
 #import <AppKit/NSApplication.h>
 #import <AppKit/NSView.h>
 #import <AppKit/NSWindow.h>
 #import <AppKit/NSApplication.h>
 #import <AppKit/NSView.h>
+#import <AppKit/NSMenuItem.h>
 
 // wxFrame
 
 
 // wxFrame
 
@@ -56,6 +59,8 @@ wxFrame::~wxFrame()
     [m_frameNSView release];
 }
 
     [m_frameNSView release];
 }
 
+// -------------------------------------------------------------------
+// Menubar
 void wxFrame::AttachMenuBar(wxMenuBar *mbar)
 {
     wxFrameBase::AttachMenuBar(mbar);
 void wxFrame::AttachMenuBar(wxMenuBar *mbar)
 {
     wxFrameBase::AttachMenuBar(mbar);
@@ -88,6 +93,45 @@ wxMenuBar* wxFrame::GetAppMenuBar(wxCocoaNSWindow *win)
     return wxFrameBase::GetAppMenuBar(win);
 }
 
     return wxFrameBase::GetAppMenuBar(win);
 }
 
+void wxFrame::CocoaDelegate_wxMenuItemAction(WX_NSMenuItem menuItem)
+{
+    wxLogTrace(wxTRACE_COCOA,wxT("wxFrame::wxMenuItemAction"));
+    wxMenuItem *item = wxMenuItem::GetFromCocoa(menuItem);
+    wxCHECK_RET(item,wxT("wxMenuItemAction received but no wxMenuItem exists!"));
+
+    wxMenu *menu = item->GetMenu();
+    wxCHECK_RET(menu,wxT("wxMenuItemAction received but wxMenuItem is not in a wxMenu!"));
+
+    // Since we're handling the delegate messages there's a very good chance
+    // we'll receive a menu action from an item with a nil target.
+    wxMenuBar *menubar = menu->GetMenuBar();
+    if(menubar)
+    {
+        wxFrame *frame = menubar->GetFrame();
+        wxASSERT_MSG(frame==this, wxT("Received wxMenuItemAction in NSWindow delegate from a menu item attached to a different frame."));
+        frame->ProcessCommand(item->GetId());
+    }
+    else
+        wxLogDebug(wxT("Received wxMenuItemAction in NSWindow delegate from an unknown menu item."));
+}
+
+bool wxFrame::CocoaDelegate_validateMenuItem(WX_NSMenuItem menuItem)
+{
+    SEL itemAction = [menuItem action];
+    if(itemAction == @selector(wxMenuItemAction:))
+    {
+        wxMenuItem *item = wxMenuItem::GetFromCocoa(menuItem);
+        wxCHECK_MSG(item,false,wxT("validateMenuItem received but no wxMenuItem exists!"));
+        // TODO: do more sanity checking
+        return item->IsEnabled();
+    }
+    // TODO: else if cut/copy/paste
+    wxLogDebug(wxT("Asked to validate an unknown menu item"));
+    return false;
+}
+
+// -------------------------------------------------------------------
+// Origin/Size
 wxPoint wxFrame::GetClientAreaOrigin() const
 {
     return wxPoint(0,0);
 wxPoint wxFrame::GetClientAreaOrigin() const
 {
     return wxPoint(0,0);
@@ -104,6 +148,7 @@ void wxFrame::CocoaSetWxWindowSize(int width, int height)
     wxTopLevelWindow::CocoaSetWxWindowSize(width,height);
 }
 
     wxTopLevelWindow::CocoaSetWxWindowSize(width,height);
 }
 
+// -------------------------------------------------------------------
 WX_NSView wxFrame::GetNonClientNSView()
 {
     if(m_frameNSView)
 WX_NSView wxFrame::GetNonClientNSView()
 {
     if(m_frameNSView)
@@ -136,6 +181,8 @@ void wxFrame::UpdateFrameNSView()
     if(m_frameToolBar)
     {
         NSView *tbarNSView = m_frameToolBar->GetNSViewForSuperview();
     if(m_frameToolBar)
     {
         NSView *tbarNSView = m_frameToolBar->GetNSViewForSuperview();
+        // If the toolbar doesn't have a superview then set it to our
+        // content view.
         if(![tbarNSView superview])
             [m_frameNSView addSubview: tbarNSView];
         // Do this after addSubView so that SetSize can work
         if(![tbarNSView superview])
             [m_frameNSView addSubview: tbarNSView];
         // Do this after addSubView so that SetSize can work
@@ -235,18 +282,10 @@ wxToolBar* wxFrame::CreateToolBar(long style,
                                       const wxString& name)
 {
     wxAutoNSAutoreleasePool pool;
                                       const wxString& name)
 {
     wxAutoNSAutoreleasePool pool;
-    wxFrameBase::CreateToolBar(style,winid,name);
-    if(m_frameToolBar)
-    {
-        m_frameToolBar->CocoaRemoveFromParent();
-        m_frameToolBar->SetOwningFrame(this);
-    }
-    UpdateFrameNSView();
-    return m_frameToolBar;
+    return wxFrameBase::CreateToolBar(style,winid,name);
 }
 #endif // wxUSE_TOOLBAR
 
 void wxFrame::PositionStatusBar()
 {
 }
 }
 #endif // wxUSE_TOOLBAR
 
 void wxFrame::PositionStatusBar()
 {
 }
-