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 #include "wx/cocoa/autorelease.h"
28 #import <Foundation/NSString.h>
29 #import <AppKit/NSMenu.h>
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 // ============================================================================
38 // wxMenu implementation
39 // ============================================================================
41 IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
43 bool wxMenu::Create(const wxString& title, long style)
47 return CocoaCreate("wxMenu");
49 return CocoaCreate(title);
56 bool wxMenu::DoAppend(wxMenuItem *item)
58 wxAutoNSAutoreleasePool pool;
59 if(!wxMenuBase::DoAppend(item))
61 [m_cocoaNSMenu addItem: item->GetNSMenuItem()];
65 bool wxMenu::DoInsert(unsigned long pos, wxMenuItem *item)
67 wxAutoNSAutoreleasePool pool;
68 if(!wxMenuBase::DoInsert(pos,item))
70 [m_cocoaNSMenu insertItem:item->GetNSMenuItem() atIndex:pos];
74 wxMenuItem* wxMenu::DoRemove(wxMenuItem *item)
76 wxAutoNSAutoreleasePool pool;
77 wxMenuItem *retitem = wxMenuBase::DoRemove(item);
78 wxASSERT(retitem->GetNSMenuItem());
79 [m_cocoaNSMenu removeItem:retitem->GetNSMenuItem()];
83 // ============================================================================
84 // wxMenuBar implementation
85 // ============================================================================
86 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
88 bool wxMenuBar::Create(long style)
90 if(!CocoaCreate("wxMenuBar"))
95 wxMenuBar::~wxMenuBar()
99 bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
101 wxAutoNSAutoreleasePool pool;
102 wxLogDebug("append menu=%p, title=%s",menu,title.c_str());
103 if(!wxMenuBarBase::Append(menu,title))
106 wxASSERT(menu->GetNSMenu());
107 NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(title).c_str()];
108 NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
109 [menu->GetNSMenu() setTitle:menuTitle];
110 [newItem setSubmenu:menu->GetNSMenu()];
112 [m_cocoaNSMenu addItem:newItem];
119 bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
121 wxAutoNSAutoreleasePool pool;
122 wxLogDebug("insert pos=%lu, menu=%p, title=%s",pos,menu,title.c_str());
123 if(!wxMenuBarBase::Insert(pos,menu,title))
126 wxASSERT(menu->GetNSMenu());
127 NSString *menuTitle = [[NSString alloc] initWithCString: title.c_str()];
128 NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
129 [menu->GetNSMenu() setTitle:menuTitle];
130 [newItem setSubmenu:menu->GetNSMenu()];
132 [m_cocoaNSMenu insertItem:newItem atIndex:pos];
139 wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
144 wxMenu *wxMenuBar::Remove(size_t pos)
150 void wxMenuBar::EnableTop(size_t pos, bool enable)
154 bool wxMenuBar::IsEnabledTop(size_t pos) const
159 void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
163 wxString wxMenuBar::GetLabelTop(size_t pos) const
165 return wxEmptyString;
168 void wxMenuBar::Attach(wxFrame *frame)
172 void wxMenuBar::Detach()
176 wxSize wxMenuBar::DoGetBestClientSize() const
178 return wxDefaultSize;
181 #endif // wxUSE_MENUS