Send all menu item actions to a dedicated target. This is to ensure
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
This commit is contained in:
@@ -26,7 +26,6 @@ public:
|
|||||||
void DisassociateNSWindow(WX_NSWindow cocoaNSWindow);
|
void DisassociateNSWindow(WX_NSWindow cocoaNSWindow);
|
||||||
virtual void Cocoa_close(void) = 0;
|
virtual void Cocoa_close(void) = 0;
|
||||||
virtual bool Cocoa_windowShouldClose(void) = 0;
|
virtual bool Cocoa_windowShouldClose(void) = 0;
|
||||||
virtual void Cocoa_wxMenuItemAction(wxMenuItem& item) = 0;
|
|
||||||
virtual void CocoaNotification_DidBecomeKey(void) { }
|
virtual void CocoaNotification_DidBecomeKey(void) { }
|
||||||
virtual void CocoaNotification_DidResignKey(void) { }
|
virtual void CocoaNotification_DidResignKey(void) { }
|
||||||
protected:
|
protected:
|
||||||
|
@@ -13,7 +13,6 @@
|
|||||||
#define _WX_COCOA_FRAME_H_
|
#define _WX_COCOA_FRAME_H_
|
||||||
|
|
||||||
class WXDLLEXPORT wxMenuBar;
|
class WXDLLEXPORT wxMenuBar;
|
||||||
class WXDLLEXPORT wxMenuItem;
|
|
||||||
class WXDLLEXPORT wxStatusBar;
|
class WXDLLEXPORT wxStatusBar;
|
||||||
|
|
||||||
class WXDLLEXPORT wxFrame: public wxFrameBase
|
class WXDLLEXPORT wxFrame: public wxFrameBase
|
||||||
@@ -52,7 +51,6 @@ protected:
|
|||||||
// Cocoa specifics
|
// Cocoa specifics
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
protected:
|
protected:
|
||||||
virtual void Cocoa_wxMenuItemAction(wxMenuItem& item);
|
|
||||||
virtual void CocoaSetWxWindowSize(int width, int height);
|
virtual void CocoaSetWxWindowSize(int width, int height);
|
||||||
|
|
||||||
// Helper function to position status/tool bars
|
// Helper function to position status/tool bars
|
||||||
|
@@ -52,6 +52,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
WX_NSMenuItem m_cocoaNSMenuItem;
|
WX_NSMenuItem m_cocoaNSMenuItem;
|
||||||
static wxMenuItemCocoaHash sm_cocoaHash;
|
static wxMenuItemCocoaHash sm_cocoaHash;
|
||||||
|
static struct objc_object *sm_cocoaTarget;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Implementation
|
// Implementation
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@@ -61,7 +61,6 @@ public:
|
|||||||
inline WX_NSWindow GetNSWindow() { return m_cocoaNSWindow; }
|
inline WX_NSWindow GetNSWindow() { return m_cocoaNSWindow; }
|
||||||
virtual void Cocoa_close(void);
|
virtual void Cocoa_close(void);
|
||||||
virtual bool Cocoa_windowShouldClose(void);
|
virtual bool Cocoa_windowShouldClose(void);
|
||||||
virtual void Cocoa_wxMenuItemAction(wxMenuItem& item);
|
|
||||||
virtual void CocoaNotification_DidBecomeKey(void);
|
virtual void CocoaNotification_DidBecomeKey(void);
|
||||||
virtual void CocoaNotification_DidResignKey(void);
|
virtual void CocoaNotification_DidResignKey(void);
|
||||||
protected:
|
protected:
|
||||||
|
@@ -98,7 +98,6 @@ void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
|
|||||||
- (void)close;
|
- (void)close;
|
||||||
- (BOOL)windowShouldClose: (id)sender;
|
- (BOOL)windowShouldClose: (id)sender;
|
||||||
|
|
||||||
- (BOOL)wxMenuItemAction: (id)sender;
|
|
||||||
@end // wxPoserNSwindow
|
@end // wxPoserNSwindow
|
||||||
|
|
||||||
WX_IMPLEMENT_POSER(wxPoserNSWindow);
|
WX_IMPLEMENT_POSER(wxPoserNSWindow);
|
||||||
@@ -125,17 +124,5 @@ WX_IMPLEMENT_POSER(wxPoserNSWindow);
|
|||||||
return YES;
|
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
|
@end // implementation wxPoserNSWindow
|
||||||
|
|
||||||
|
@@ -19,8 +19,6 @@
|
|||||||
#include "wx/statusbr.h"
|
#include "wx/statusbr.h"
|
||||||
#endif // WX_PRECOMP
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
#include "wx/menuitem.h"
|
|
||||||
|
|
||||||
#include "wx/cocoa/autorelease.h"
|
#include "wx/cocoa/autorelease.h"
|
||||||
|
|
||||||
#import <AppKit/NSWindow.h>
|
#import <AppKit/NSWindow.h>
|
||||||
@@ -57,11 +55,6 @@ wxFrame::~wxFrame()
|
|||||||
[m_frameNSView release];
|
[m_frameNSView release];
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFrame::Cocoa_wxMenuItemAction(wxMenuItem& item)
|
|
||||||
{
|
|
||||||
Command(item.GetId());
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxFrame::AttachMenuBar(wxMenuBar *mbar)
|
void wxFrame::AttachMenuBar(wxMenuBar *mbar)
|
||||||
{
|
{
|
||||||
wxFrameBase::AttachMenuBar(mbar);
|
wxFrameBase::AttachMenuBar(mbar);
|
||||||
|
@@ -167,10 +167,12 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const
|
|||||||
|
|
||||||
void wxMenuBar::Attach(wxFrame *frame)
|
void wxMenuBar::Attach(wxFrame *frame)
|
||||||
{
|
{
|
||||||
|
wxMenuBarBase::Attach(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMenuBar::Detach()
|
void wxMenuBar::Detach()
|
||||||
{
|
{
|
||||||
|
wxMenuBarBase::Detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxMenuBar::DoGetBestClientSize() const
|
wxSize wxMenuBar::DoGetBestClientSize() const
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "wx/menuitem.h"
|
#include "wx/menuitem.h"
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
#include "wx/frame.h"
|
#include "wx/frame.h"
|
||||||
|
#include "wx/log.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/cocoa/ObjcPose.h"
|
#include "wx/cocoa/ObjcPose.h"
|
||||||
@@ -34,15 +35,41 @@
|
|||||||
|
|
||||||
#if wxUSE_MENUS
|
#if wxUSE_MENUS
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// globals
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
wxMenuItemCocoaHash wxMenuItemCocoa::sm_cocoaHash;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// functions prototypes
|
// 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
|
// @class wxPoserNSMenuItem
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -61,6 +88,9 @@ WX_IMPLEMENT_POSER(wxPoserNSMenuItem);
|
|||||||
// wxMenuItemCocoa implementation
|
// wxMenuItemCocoa implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
|
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
|
||||||
|
wxMenuItemCocoaHash wxMenuItemCocoa::sm_cocoaHash;
|
||||||
|
|
||||||
|
struct objc_object *wxMenuItemCocoa::sm_cocoaTarget = [[wxNSMenuItemTarget alloc] init];
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxMenuItemBase
|
// wxMenuItemBase
|
||||||
@@ -97,6 +127,7 @@ wxMenuItemCocoa::wxMenuItemCocoa(wxMenu *pParentMenu,
|
|||||||
NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(strName).c_str()];
|
NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(strName).c_str()];
|
||||||
m_cocoaNSMenuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(wxMenuItemAction:) keyEquivalent:@""];
|
m_cocoaNSMenuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(wxMenuItemAction:) keyEquivalent:@""];
|
||||||
sm_cocoaHash.insert(wxMenuItemCocoaHash::value_type(m_cocoaNSMenuItem,this));
|
sm_cocoaHash.insert(wxMenuItemCocoaHash::value_type(m_cocoaNSMenuItem,this));
|
||||||
|
[m_cocoaNSMenuItem setTarget:sm_cocoaTarget];
|
||||||
if(pSubMenu)
|
if(pSubMenu)
|
||||||
{
|
{
|
||||||
wxASSERT(pSubMenu->GetNSMenu());
|
wxASSERT(pSubMenu->GetNSMenu());
|
||||||
|
@@ -128,10 +128,6 @@ void wxTopLevelWindowCocoa::CocoaReplaceView(WX_NSView oldView, WX_NSView newVie
|
|||||||
[m_cocoaNSWindow setContentView:newView];
|
[m_cocoaNSWindow setContentView:newView];
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTopLevelWindowCocoa::Cocoa_wxMenuItemAction(wxMenuItem& item)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxTopLevelWindowCocoa::CocoaNotification_DidBecomeKey(void)
|
void wxTopLevelWindowCocoa::CocoaNotification_DidBecomeKey(void)
|
||||||
{
|
{
|
||||||
wxLogDebug("wxTopLevelWindowCocoa=%p::CocoaNotification_DidBecomeKey",this);
|
wxLogDebug("wxTopLevelWindowCocoa=%p::CocoaNotification_DidBecomeKey",this);
|
||||||
|
Reference in New Issue
Block a user