Keyboard shortcuts
There are three kind of shortcuts:
- Global shortcuts, such as PrintScreen, CTRL+alt+delete and other things, like a hotkey for starting your favourite app with CTRL+F<x>.
- Menu accelerators (showing e.g CTRL+V by the Paste menu item). These shortcuts are specific to a certain window.
- Widget text shortcuts (eg. "&Quit" results in "Quit" and the key Q will activate the widget). These shortcuts are also specific to a certain window.
API requirements (or wishlist)
- An '&' in a widget label will automatically underscore the following character and create a shortcut.
- Two '&&' renders a single '&'.
- MenuItems' contructor takes an additional parameter, that will be a string like "CTRL+V" or "ALT+Z" etc. The reasons for making it a string are: 1) simplifies localization 2) very flexible 3) easy to use.
- A method to register events with the AppServer, for instance Application::RegisterInputEvent(). Can be used to register keyboard events, mouse events, etc.
Solution
1. The Window holds a key -> widget map, widgets register/unregister themselves with the window.
2. Each View has a method that gets called whenever a key down event is rejected by the View in focus (and any parent Views).
The second alternative seems to be the best one, as it's both the simplest to implement and the most flexible.
In conclusion:
- I'll add a method to View, looking just like KeyDown, but with a different name. (Don't quite like to name it AcceleratorEvent(), but it's the only thing I can come up with right now. Better suggestions, anyone?)
- Window::TopView will get a KeyDown() method that calls AcceleratorEvent() on each and every of it's children. (TopView::KeyDown() is called when the View in focus has called it's parent View's KeyDown() method, and so on, all the way to the top view.)
- The Window will call TopView::KeyDown() directly, if no View should have focus.
Comments?
Editing is temporarily disabled!