OSX - Removing menus

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
User avatar
xaviou
Super wx Problem Solver
Super wx Problem Solver
Posts: 437
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

OSX - Removing menus

Post by xaviou »

Hi.

I would just like to know if it is safe to remove menus just after their creation on OSX.

My app has just 2 menu entries : Exit and About.
On OSX, these 2 menu items are handled by the osx-specific menu so I don't need the "File" and "Help" menus witch became empty.

But I have to create them in order to let the About and Exit entries created and affected to the specific menu.
So, here is what I've done :

Code: Select all

// Create the menu bar
wxMenuBar *menuBar = new wxMenuBar();
	// File menu
	wxMenu *fileMenu = new wxMenu();
	fileMenu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT, wxSTOCK_WITH_MNEMONIC|wxSTOCK_WITH_ACCELERATOR), wxGetStockHelpString(wxID_EXIT));
	menuBar->Append(fileMenu, wxGetStockLabel(wxID_FILE));
	// Help menu
	wxMenu* helpMenu = new wxMenu();
	helpMenu->Append(wxID_ABOUT, wxGetStockLabel(wxID_ABOUT, wxSTOCK_WITH_MNEMONIC|wxSTOCK_WITH_ACCELERATOR), wxGetStockHelpString(wxID_ABOUT));
	menuBar->Append(helpMenu, wxGetStockLabel(wxID_HELP));
SetMenuBar(menuBar);
#ifdef __WXMAC__
	menuBar->Remove(1); // Remove the empty help menu
	menuBar->Remove(0); // Remove the empty File menu
#endif // __WXMAC__
It seems to work, but perhaps there is another solution to create these 2 entries on Mac.

Regards
Xav'
My wxWidgets stuff web page : X@v's wxStuff
User avatar
xaviou
Super wx Problem Solver
Super wx Problem Solver
Posts: 437
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

Re: OSX - Removing menus

Post by xaviou »

Ooooops : I forget to delete the related menus

Code: Select all

// Create the menu bar
wxMenuBar *menuBar = new wxMenuBar();
   // File menu
   wxMenu *fileMenu = new wxMenu();
   fileMenu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT, wxSTOCK_WITH_MNEMONIC|wxSTOCK_WITH_ACCELERATOR), wxGetStockHelpString(wxID_EXIT));
   menuBar->Append(fileMenu, wxGetStockLabel(wxID_FILE));
   // Help menu
   wxMenu* helpMenu = new wxMenu();
   helpMenu->Append(wxID_ABOUT, wxGetStockLabel(wxID_ABOUT, wxSTOCK_WITH_MNEMONIC|wxSTOCK_WITH_ACCELERATOR), wxGetStockHelpString(wxID_ABOUT));
   menuBar->Append(helpMenu, wxGetStockLabel(wxID_HELP));
SetMenuBar(menuBar);
#ifdef __WXMAC__
   menuBar->Remove(1); // Remove the empty help menu
   delete helpMenu;    // and delete it
   menuBar->Remove(0); // Remove the empty File menu
   delete fileMenu;    // and delete it
#endif // __WXMAC__
Regards
Xav'
My wxWidgets stuff web page : X@v's wxStuff
Post Reply