Page 1 of 1

OSX - Removing menus

Posted: Fri Sep 22, 2017 7:33 pm
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'

Re: OSX - Removing menus

Posted: Sat Sep 23, 2017 8:17 am
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'