#endif // WX_PRECOMP
#include "wx/cocoa/autorelease.h"
+#include "wx/cocoa/string.h"
#import <Foundation/NSString.h>
#import <AppKit/NSMenu.h>
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: wxNSStringWithWxString(title)];
+ return true;
}
wxMenu::~wxMenu()
{
+ [m_cocoaNSMenu release];
}
-bool wxMenu::DoAppend(wxMenuItem *item)
+wxMenuItem* wxMenu::DoAppend(wxMenuItem *item)
{
wxAutoNSAutoreleasePool pool;
if(!wxMenuBase::DoAppend(item))
- return false;
+ return NULL;
[m_cocoaNSMenu addItem: item->GetNSMenuItem()];
- return true;
+ return item;
}
-bool wxMenu::DoInsert(unsigned long pos, wxMenuItem *item)
+wxMenuItem* wxMenu::DoInsert(unsigned long pos, wxMenuItem *item)
{
wxAutoNSAutoreleasePool pool;
if(!wxMenuBase::DoInsert(pos,item))
- return false;
+ return NULL;
[m_cocoaNSMenu insertItem:item->GetNSMenuItem() atIndex:pos];
- return true;
+ return item;
}
wxMenuItem* wxMenu::DoRemove(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:@""];
wxMenuBar::~wxMenuBar()
{
+ [m_cocoaNSMenu release];
}
bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
{
wxAutoNSAutoreleasePool pool;
- wxLogDebug("append menu=%p, title=%s",menu,title.c_str());
+ wxLogDebug(wxT("append menu=%p, title=%s"),menu,title.c_str());
if(!wxMenuBarBase::Append(menu,title))
return false;
wxASSERT(menu);
wxASSERT(menu->GetNSMenu());
- NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(title).c_str()];
+ NSString *menuTitle = wxInitNSStringWithWxString([NSString alloc], wxStripMenuCodes(title));
NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
[menu->GetNSMenu() setTitle:menuTitle];
[newItem setSubmenu:menu->GetNSMenu()];
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
{
wxAutoNSAutoreleasePool pool;
- wxLogDebug("insert pos=%lu, menu=%p, title=%s",pos,menu,title.c_str());
+ wxLogDebug(wxT("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);
wxASSERT(menu->GetNSMenu());
- NSString *menuTitle = [[NSString alloc] initWithCString: title.c_str()];
+ NSString *menuTitle = wxInitNSStringWithWxString([NSString alloc], title);
NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
[menu->GetNSMenu() setTitle:menuTitle];
[newItem setSubmenu:menu->GetNSMenu()];
wxMenu *menu = GetMenu(pos);
int itemindex = [m_cocoaNSMenu indexOfItemWithSubmenu:menu->GetNSMenu()];
wxASSERT(itemindex>=0);
- return wxString([[[m_cocoaNSMenu itemAtIndex:itemindex] title] lossyCString]);
+ return wxStringWithNSString([[m_cocoaNSMenu itemAtIndex:itemindex] title]);
}
void wxMenuBar::Attach(wxFrame *frame)