1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenuItem implementation
4 // Author: David Elliott
8 // Copyright: 2002 David Elliott
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
23 #include "wx/menuitem.h"
28 #include "wx/cocoa/ObjcPose.h"
30 #import <AppKit/NSMenuItem.h>
31 #import <AppKit/NSMenu.h>
32 #import <Foundation/NSString.h>
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
39 wxMenuItemCocoaHash wxMenuItemCocoa::sm_cocoaHash;
41 // ----------------------------------------------------------------------------
42 // functions prototypes
43 // ----------------------------------------------------------------------------
45 // ============================================================================
46 // @class wxPoserNSMenuItem
47 // ============================================================================
48 @interface wxPoserNSMenuItem : NSMenuItem
52 @end // wxPoserNSMenuItem
54 WX_IMPLEMENT_POSER(wxPoserNSMenuItem);
55 @implementation wxPoserNSMenuItem : NSMenuItem
57 @end // wxPoseRNSMenuItem
59 // ============================================================================
60 // wxMenuItemCocoa implementation
61 // ============================================================================
62 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
75 return new wxMenuItem(parentMenu, itemid, name, help, kind, subMenu);
79 wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
81 return wxStripMenuCodes(text);
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
87 wxMenuItemCocoa::wxMenuItemCocoa(wxMenu *pParentMenu,
89 const wxString& strName,
90 const wxString& strHelp,
93 : wxMenuItemBase(pParentMenu, itemid, strName, strHelp, kind, pSubMenu)
95 NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(strName).c_str()];
96 m_cocoaNSMenuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(wxMenuItemAction:) keyEquivalent:@""];
97 sm_cocoaHash.insert(wxMenuItemCocoaHash::value_type(m_cocoaNSMenuItem,this));
100 wxASSERT(pSubMenu->GetNSMenu());
101 [pSubMenu->GetNSMenu() setTitle:menuTitle];
102 [m_cocoaNSMenuItem setSubmenu:pSubMenu->GetNSMenu()];
107 wxMenuItem::~wxMenuItem()
109 sm_cocoaHash.erase(m_cocoaNSMenuItem);
110 [m_cocoaNSMenuItem release];
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
120 void wxMenuItem::Enable(bool bDoEnable)
122 wxMenuItemBase::Enable(bDoEnable);
125 void wxMenuItem::Check(bool bDoCheck)
127 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
128 wxMenuItemBase::Check(bDoCheck);
131 void wxMenuItem::SetText(const wxString& label)
133 wxMenuItemBase::SetText(label);
136 void wxMenuItem::SetCheckable(bool checkable)
138 wxMenuItemBase::SetCheckable(checkable);
141 #endif // wxUSE_MENUS