]> git.saurik.com Git - wxWidgets.git/commitdiff
Send all menu item actions to a dedicated target. This is to ensure
authorDavid Elliott <dfe@tgwbd.org>
Thu, 28 Aug 2003 17:49:51 +0000 (17:49 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Thu, 28 Aug 2003 17:49:51 +0000 (17:49 +0000)
the actions always make it to the proper wxFrame.

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

include/wx/cocoa/NSWindow.h
include/wx/cocoa/frame.h
include/wx/cocoa/menuitem.h
include/wx/cocoa/toplevel.h
src/cocoa/NSWindow.mm
src/cocoa/frame.mm
src/cocoa/menu.mm
src/cocoa/menuitem.mm
src/cocoa/toplevel.mm

index 29748141c9cc6b68b137ba4ae04aca155f439c06..f67430f86837508cac180ba31cff67365b0d49a1 100644 (file)
@@ -26,7 +26,6 @@ public:
     void DisassociateNSWindow(WX_NSWindow cocoaNSWindow);
     virtual void Cocoa_close(void) = 0;
     virtual bool Cocoa_windowShouldClose(void) = 0;
-    virtual void Cocoa_wxMenuItemAction(wxMenuItem& item) = 0;
     virtual void CocoaNotification_DidBecomeKey(void) { }
     virtual void CocoaNotification_DidResignKey(void) { }
 protected:
index 5190e59c414eee98c0bc53e8b5b123ccc5089735..041e7b399e9c348d78236b274b783782179548bd 100644 (file)
@@ -13,7 +13,6 @@
 #define _WX_COCOA_FRAME_H_
 
 class WXDLLEXPORT wxMenuBar;
-class WXDLLEXPORT wxMenuItem;
 class WXDLLEXPORT wxStatusBar;
 
 class WXDLLEXPORT wxFrame: public wxFrameBase 
@@ -52,7 +51,6 @@ protected:
 // Cocoa specifics
 // ------------------------------------------------------------------------
 protected:
-    virtual void Cocoa_wxMenuItemAction(wxMenuItem& item);
     virtual void CocoaSetWxWindowSize(int width, int height);
 
     // Helper function to position status/tool bars
index 303c73b6e7dfcf7df1aebd23f97516b39bb0b454..75e66b1d4cd768dbe93e2a2ddf7279ba0e0635fb 100644 (file)
@@ -52,6 +52,7 @@ public:
 protected:
     WX_NSMenuItem m_cocoaNSMenuItem;
     static wxMenuItemCocoaHash sm_cocoaHash;
+    static struct objc_object *sm_cocoaTarget;
 // ------------------------------------------------------------------------
 // Implementation
 // ------------------------------------------------------------------------
index 6283dabdfb9381769f81a37484ee27a5e6fc57f3..eb8996a4cd8b8f7a904bf1ce72f13a94dc902e43 100644 (file)
@@ -61,7 +61,6 @@ public:
     inline WX_NSWindow GetNSWindow() { return m_cocoaNSWindow; }
     virtual void Cocoa_close(void);
     virtual bool Cocoa_windowShouldClose(void);
-    virtual void Cocoa_wxMenuItemAction(wxMenuItem& item);
     virtual void CocoaNotification_DidBecomeKey(void);
     virtual void CocoaNotification_DidResignKey(void);
 protected:
index 15b3eb583e762e285bad0cfe124f3a679677f779..27d506a30b3c6a315bcb352044e3c4cca0ac6124 100644 (file)
@@ -98,7 +98,6 @@ void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
 - (void)close;
 - (BOOL)windowShouldClose: (id)sender;
 
-- (BOOL)wxMenuItemAction: (id)sender;
 @end // wxPoserNSwindow
 
 WX_IMPLEMENT_POSER(wxPoserNSWindow);
@@ -125,17 +124,5 @@ WX_IMPLEMENT_POSER(wxPoserNSWindow);
     return YES;
 }
 
-- (BOOL)wxMenuItemAction: (id)sender
-{
-    wxLogDebug("wxMenuItemAction");
-    wxMenuItem *item = wxMenuItem::GetFromCocoa(sender);
-    if(!item)
-        return NO;
-
-    wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
-    wxASSERT(tlw);
-    tlw->Cocoa_wxMenuItemAction(*item);
-    return YES;
-}
 @end // implementation wxPoserNSWindow
 
index d4b5fbfa8387d24585dddf996e47557f3fb0647b..3c40bc0f6637f5e66556dde1cc13e10e828445bc 100644 (file)
@@ -19,8 +19,6 @@
     #include "wx/statusbr.h"
 #endif // WX_PRECOMP
 
-#include "wx/menuitem.h"
-
 #include "wx/cocoa/autorelease.h"
 
 #import <AppKit/NSWindow.h>
@@ -57,11 +55,6 @@ wxFrame::~wxFrame()
     [m_frameNSView release];
 }
 
-void wxFrame::Cocoa_wxMenuItemAction(wxMenuItem& item)
-{
-    Command(item.GetId());
-}
-
 void wxFrame::AttachMenuBar(wxMenuBar *mbar)
 {
     wxFrameBase::AttachMenuBar(mbar);
index f0fc49998a942515f9420cc2f6dc85dd54fece28..57db00ae15c0f8ffa22070203f609ee4394f1c4b 100644 (file)
@@ -167,10 +167,12 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const
 
 void wxMenuBar::Attach(wxFrame *frame)
 {
+    wxMenuBarBase::Attach(frame);
 }
 
 void wxMenuBar::Detach()
 {
+    wxMenuBarBase::Detach();
 }
 
 wxSize wxMenuBar::DoGetBestClientSize() const
index 5b7882191849dfd630727dcdb42c4f981f141953..ba92f411a82411b18362aec801eb98b2f586e687 100644 (file)
@@ -23,6 +23,7 @@
     #include "wx/menuitem.h"
     #include "wx/utils.h"
     #include "wx/frame.h"
+    #include "wx/log.h"
 #endif
 
 #include "wx/cocoa/ObjcPose.h"
 
 #if wxUSE_MENUS
 
-// ----------------------------------------------------------------------------
-// globals
-// ----------------------------------------------------------------------------
-wxMenuItemCocoaHash wxMenuItemCocoa::sm_cocoaHash;
-
 // ----------------------------------------------------------------------------
 // functions prototypes
 // ----------------------------------------------------------------------------
 
+// ============================================================================
+// @class wxNSMenuItemTarget
+// ============================================================================
+@interface wxNSMenuItemTarget : NSObject
+{
+}
+
+- (void)wxMenuItemAction: (id)sender;
+@end //interface wxNSMenuItemTarget
+
+@implementation wxNSMenuItemTarget : NSObject
+
+- (void)wxMenuItemAction: (id)sender
+{
+    wxLogDebug("wxMenuItemAction");
+    wxMenuItem *item = wxMenuItem::GetFromCocoa(sender);
+    wxCHECK_RET(item,"wxMenuItemAction received but no wxMenuItem exists!");
+
+    wxMenu *menu = item->GetMenu();
+    wxCHECK_RET(menu,"wxMenuItemAction received but wxMenuItem is not in a wxMenu");
+    wxMenuBar *menubar = menu->GetMenuBar();
+    if(menubar)
+    {
+        wxFrame *frame = menubar->GetFrame();
+        wxCHECK_RET(frame, "wxMenuBar MUST be attached to a wxFrame!");
+        frame->Command(item->GetId());
+    }
+}
+
+@end //implementation wxNSMenuItemTarget
+
 // ============================================================================
 // @class wxPoserNSMenuItem
 // ============================================================================
@@ -61,6 +88,9 @@ WX_IMPLEMENT_POSER(wxPoserNSMenuItem);
 // wxMenuItemCocoa implementation
 // ============================================================================
 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
+wxMenuItemCocoaHash wxMenuItemCocoa::sm_cocoaHash;
+
+struct objc_object *wxMenuItemCocoa::sm_cocoaTarget = [[wxNSMenuItemTarget alloc] init];
 
 // ----------------------------------------------------------------------------
 // wxMenuItemBase
@@ -97,6 +127,7 @@ wxMenuItemCocoa::wxMenuItemCocoa(wxMenu *pParentMenu,
     NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(strName).c_str()];
     m_cocoaNSMenuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(wxMenuItemAction:) keyEquivalent:@""];
     sm_cocoaHash.insert(wxMenuItemCocoaHash::value_type(m_cocoaNSMenuItem,this));
+    [m_cocoaNSMenuItem setTarget:sm_cocoaTarget];
     if(pSubMenu)
     {
         wxASSERT(pSubMenu->GetNSMenu());
index a3b1398a35d4412e572f8be5680626b991a0d4f9..1b5703aa12c24dc7342afc7fde610bbd5f1ff562 100644 (file)
@@ -128,10 +128,6 @@ void wxTopLevelWindowCocoa::CocoaReplaceView(WX_NSView oldView, WX_NSView newVie
         [m_cocoaNSWindow setContentView:newView];
 }
 
-void wxTopLevelWindowCocoa::Cocoa_wxMenuItemAction(wxMenuItem& item)
-{
-}
-
 void wxTopLevelWindowCocoa::CocoaNotification_DidBecomeKey(void)
 {
     wxLogDebug("wxTopLevelWindowCocoa=%p::CocoaNotification_DidBecomeKey",this);