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"
29 #include "wx/cocoa/autorelease.h"
31 #import <AppKit/NSMenuItem.h>
32 #import <AppKit/NSMenu.h>
33 #import <Foundation/NSString.h>
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
40 wxMenuItemCocoaHash wxMenuItemCocoa::sm_cocoaHash;
42 // ----------------------------------------------------------------------------
43 // functions prototypes
44 // ----------------------------------------------------------------------------
46 // ============================================================================
47 // @class wxPoserNSMenuItem
48 // ============================================================================
49 @interface wxPoserNSMenuItem : NSMenuItem
53 @end // wxPoserNSMenuItem
55 WX_IMPLEMENT_POSER(wxPoserNSMenuItem);
56 @implementation wxPoserNSMenuItem : NSMenuItem
58 @end // wxPoseRNSMenuItem
60 // ============================================================================
61 // wxMenuItemCocoa implementation
62 // ============================================================================
63 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
76 return new wxMenuItem(parentMenu, itemid, name, help, kind, subMenu);
80 wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
82 return wxStripMenuCodes(text);
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
88 wxMenuItemCocoa::wxMenuItemCocoa(wxMenu *pParentMenu,
90 const wxString& strName,
91 const wxString& strHelp,
94 : wxMenuItemBase(pParentMenu, itemid, strName, strHelp, kind, pSubMenu)
96 wxAutoNSAutoreleasePool pool;
97 NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(strName).c_str()];
98 m_cocoaNSMenuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(wxMenuItemAction:) keyEquivalent:@""];
99 sm_cocoaHash.insert(wxMenuItemCocoaHash::value_type(m_cocoaNSMenuItem,this));
102 wxASSERT(pSubMenu->GetNSMenu());
103 [pSubMenu->GetNSMenu() setTitle:menuTitle];
104 [m_cocoaNSMenuItem setSubmenu:pSubMenu->GetNSMenu()];
109 wxMenuItem::~wxMenuItem()
111 sm_cocoaHash.erase(m_cocoaNSMenuItem);
112 [m_cocoaNSMenuItem release];
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
122 void wxMenuItem::Enable(bool bDoEnable)
124 wxMenuItemBase::Enable(bDoEnable);
127 void wxMenuItem::Check(bool bDoCheck)
129 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
130 wxMenuItemBase::Check(bDoCheck);
133 void wxMenuItem::SetText(const wxString& label)
135 wxMenuItemBase::SetText(label);
138 void wxMenuItem::SetCheckable(bool checkable)
140 wxMenuItemBase::SetCheckable(checkable);
143 #endif // wxUSE_MENUS