1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/menu.cpp
3 // Purpose: wxMenu and wxMenuBar implementation
4 // Author: David Elliott
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
26 #import <Foundation/NSString.h>
27 #import <AppKit/NSMenu.h>
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 // ============================================================================
36 // wxMenu implementation
37 // ============================================================================
39 IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
41 bool wxMenu::Create(const wxString& title, long style)
45 return CocoaCreate("wxMenu");
47 return CocoaCreate(title);
54 bool wxMenu::DoAppend(wxMenuItem *item)
56 if(!wxMenuBase::DoAppend(item))
58 [m_cocoaNSMenu addItem: item->GetNSMenuItem()];
62 bool wxMenu::DoInsert(unsigned long pos, wxMenuItem *item)
64 if(!wxMenuBase::DoInsert(pos,item))
66 [m_cocoaNSMenu insertItem:item->GetNSMenuItem() atIndex:pos];
70 wxMenuItem* wxMenu::DoRemove(wxMenuItem *item)
72 wxMenuItem *retitem = wxMenuBase::DoRemove(item);
73 wxASSERT(retitem->GetNSMenuItem());
74 [m_cocoaNSMenu removeItem:retitem->GetNSMenuItem()];
78 // ============================================================================
79 // wxMenuBar implementation
80 // ============================================================================
81 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
83 bool wxMenuBar::Create(long style)
85 if(!CocoaCreate("wxMenuBar"))
90 wxMenuBar::~wxMenuBar()
94 bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
96 wxLogDebug("append menu=%p, title=%s",menu,title.c_str());
97 if(!wxMenuBarBase::Append(menu,title))
100 wxASSERT(menu->GetNSMenu());
101 NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(title).c_str()];
102 NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
103 [menu->GetNSMenu() setTitle:menuTitle];
104 [newItem setSubmenu:menu->GetNSMenu()];
106 [m_cocoaNSMenu addItem:newItem];
113 bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
115 wxLogDebug("insert pos=%lu, menu=%p, title=%s",pos,menu,title.c_str());
116 if(!wxMenuBarBase::Insert(pos,menu,title))
119 wxASSERT(menu->GetNSMenu());
120 NSString *menuTitle = [[NSString alloc] initWithCString: title.c_str()];
121 NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
122 [menu->GetNSMenu() setTitle:menuTitle];
123 [newItem setSubmenu:menu->GetNSMenu()];
125 [m_cocoaNSMenu insertItem:newItem atIndex:pos];
132 wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
137 wxMenu *wxMenuBar::Remove(size_t pos)
143 void wxMenuBar::EnableTop(size_t pos, bool enable)
147 bool wxMenuBar::IsEnabledTop(size_t pos) const
152 void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
156 wxString wxMenuBar::GetLabelTop(size_t pos) const
158 return wxEmptyString;
161 void wxMenuBar::Attach(wxFrame *frame)
165 void wxMenuBar::Detach()
169 wxSize wxMenuBar::DoGetBestClientSize() const
171 return wxDefaultSize;
174 #endif // wxUSE_MENUS