bool wxMenu::Create(const wxString& title, long style)
{
-#if 0
- if(!title)
- return CocoaCreate("wxMenu");
-#endif
- return CocoaCreate(title);
+ wxAutoNSAutoreleasePool pool;
+ m_cocoaNSMenu = [[NSMenu alloc] initWithTitle: [NSString stringWithCString: title.c_str()]];
+ return true;
}
wxMenu::~wxMenu()
{
+ [m_cocoaNSMenu release];
}
bool wxMenu::DoAppend(wxMenuItem *item)
bool wxMenuBar::Create(long style)
{
- if(!CocoaCreate("wxMenuBar"))
- return false;
+ wxAutoNSAutoreleasePool pool;
+ m_cocoaNSMenu = [[NSMenu alloc] initWithTitle: @"wxMenuBar"];
+
+ NSMenuItem *dummyItem = [[NSMenuItem alloc] initWithTitle:@"App menu"
+ /* Note: title gets clobbered by app name anyway */
+ action:nil keyEquivalent:@""];
+ [m_cocoaNSMenu addItem:dummyItem];
+ [dummyItem release];
return true;
}
wxMenuBar::~wxMenuBar()
{
+ [m_cocoaNSMenu release];
}
bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
{
wxAutoNSAutoreleasePool pool;
wxLogDebug("insert pos=%lu, menu=%p, title=%s",pos,menu,title.c_str());
+ // Get the current menu at this position
+ wxMenu *nextmenu = GetMenu(pos);
if(!wxMenuBarBase::Insert(pos,menu,title))
return false;
wxASSERT(menu);
[menu->GetNSMenu() setTitle:menuTitle];
[newItem setSubmenu:menu->GetNSMenu()];
- [m_cocoaNSMenu insertItem:newItem atIndex:pos];
+ int itemindex = [m_cocoaNSMenu indexOfItemWithSubmenu:nextmenu->GetNSMenu()];
+ wxASSERT(itemindex>=0);
+ [m_cocoaNSMenu insertItem:newItem atIndex:itemindex];
[menuTitle release];
[newItem release];
wxMenu *wxMenuBar::Remove(size_t pos)
{
- return NULL;
+ wxMenu *menu = wxMenuBarBase::Remove(pos);
+ wxASSERT(menu);
+ int itemindex = [GetNSMenu() indexOfItemWithSubmenu:menu->GetNSMenu()];
+ wxASSERT(itemindex>=0);
+ [m_cocoaNSMenu removeItemAtIndex:itemindex];
+ return menu;
}
wxString wxMenuBar::GetLabelTop(size_t pos) const
{
- return wxEmptyString;
+ wxMenu *menu = GetMenu(pos);
+ int itemindex = [m_cocoaNSMenu indexOfItemWithSubmenu:menu->GetNSMenu()];
+ wxASSERT(itemindex>=0);
+ return wxString([[[m_cocoaNSMenu itemAtIndex:itemindex] title] lossyCString]);
}
void wxMenuBar::Attach(wxFrame *frame)