[GUI] Menu Command Events
Wolfgang Thaller
wolfgang.thaller@gmx.net
Tue, 18 Mar 2003 00:18:14 +0100
Another discussion topic for everyone...
I'm bringing this up now because it has to do with event handling -
there'll (hopefully) be another menu-related discussion later, but we
should think a little about the event handling related things now.
How should menu commands be handled in the CGA?
I don't think that simply attaching a callback to the menu item is a
good solution - consider the following:
The "About", "Quit", "Open", etc. menu commands are handled by the
application - they are the same regardless of which window or widget
has the input focus.
The "Close", "Save", etc. menu commands are handled by the front
window[MacOS] / the window to which the menu bar is attached[other
platforms].
The "Cut", "Copy", "Paste" etc. menu commands are handled by the widget
that currently has the input focus.
In many (OO) toolkits that I know, a "menu command" event is first
passed to the widget that has the focus. If that widget doesn't handle
it, the event is passed on to the widget that contains it, and so on,
then to the window, and finally to the application object.
I've also seen toolkits where this "responder chain" (as it's called in
Cocoa) can be freely configured.
Also, should enabling/disabling menu items be handled in a similar way,
using a callback, or should menu items be explicitly enabled/disabled
by IO actions like enableMenuItem and disableMenuItem? The first is
probably much more practical...
Cheers,
Wolfgang