c++ - Empty wxWidgets menus on OSX -
i'm using wxwidgets 2.9.4 on osx 10.8.3 , built library cocoa.
i want add menu bar menus wxframe:
wxmenubar* menubar = new wxmenubar(); wxmenu* filemenu = new wxmenu(); wxmenu* helpmenu = new wxmenu(); helpmenu->append(wxid_about, wxt("about")); filemenu->append(wxid_exit, wxt("exit")); menubar->append(filemenu, wxt("file")); menubar->append(helpmenu, wxt("about")); setmenubar(menubar); since i'm using standard ids adding menu items(as described here), automatically moves about , exit application menu(i think it's called apple menu), makes file , help menus empty:

are there ways hide empty menus?
actually tried remove them:
#if defined(__wxmac__) || defined(__wxosx__) || defined(__wxosx_cocoa__) menubar->remove(0); menubar->remove(0); #endif but caused , exit menu items helptext, not displayed on frame statusbar (might have other side effects well.)
it seems there's no standard way hiding menus in wxwidgets.
i ended writing few lines of objective-c code find , hide empty menus:
// macmenuworkaround.h #import <cocoa/cocoa.h> @interface macmenuworkaround : nsobject +(void) hideemptymenus; @end // macmenuworkaround.m #import "macmenuworkaround.h" @implementation macmenuworkaround +(void) hideemptymenus { nsmenu* mainmenu = [[nsapplication sharedapplication] mainmenu]; (nsmenuitem* item in [mainmenu itemarray]) { nsmenu* menu = [item submenu]; if ([[menu itemarray] count] < 2) { [item sethidden:yes]; } } } @end // macmenuworkaroundbridge.h #ifndef __wxstarter__macmenuworkaroundbridge__ #define __wxstarter__macmenuworkaroundbridge__ namespace cocoabridge { void hideemptymenus(); } #endif /* defined(__wxstarter__macmenuworkaroundbridge__) */ // macmenuworkaroundbridge.cpp // set file type objective-c++ source #import "macmenuworkaround.h" #include "macmenuworkaroundbridge.h" namespace cocoabridge { void hideemptymenus() { [macmenuworkaround hideemptymenus]; } } then in code:
#include "macmenuworkaroundbridge.h" //... #if defined(__wxmac__) || defined(__wxosx__) || defined(__wxosx_cocoa__) cocoabridge::hideemptymenus(); #endif
Comments
Post a Comment