mercredi 18 mars 2015

Toggleable MenuBar in wxWidgets (when to hide?)


I would like to make the menubar in my wxWidgets application toggleable in the way for example Firefox and Windows Explorer are doing it. This means when it's hidden and you press the ALT-Key it get's shown. This is relatively easy: i save the menu when it is created in a member variable m_pMenuBarand capture wxEVT_CHAR_HOOK enabling the menu with wxFrame::SetMenuBar(m_pMenuBar) when GetKeyCode() == WXK_ALT.


But now i wonder when to disable the menu again. I know disabling can be done with wxFrame::SetMenuBar(nullptr). Obviously when a menu item is clicked in the corresponding wxEVT_MENU event. But in programs that support such toggleable menus the menu also gets hidden when you press a key (that is not a shortcut) or click somewhere to the screen (and don't hit the menu). It feels like the menu "looses it's focus and disapears". Since i am already capturing wxEVT_CHAR_HOOK, hiding on key press would be possible. The thing with the mouse is more complicated. I tried a timer that checks if mouse buttons are pressed, but that seems rather ugly and doesn't work when you select sub menus.


So my question is: when or on which events should i hide the menu?


Thank you very much!


jffmichi




Aucun commentaire:

Enregistrer un commentaire