Attached is a sample implementation of native system menus for
Windows. I put it in the native dialog addon and updated the
native_file_chooser example. The API is functional, but not complete:
ALLEGRO_MENU *al_create_menu(void);
bool al_append_menu (ALLEGRO_MENU *parent, ALLEGRO_MENU *popup, char
const *title, int id);
void al_set_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu);
Basic usage:
ALLEGRO_MENU *menu = al_create_menu();
ALLEGRO_MENU *file = al_create_menu();
al_append_menu(file, NULL, "Open", OPEN_ID);
al_append_menu(file, NULL, "Exit", EXIT_ID);
al_append_menu(menu, file, "File", 0);
al_set_display_menu(display, menu);
A higher level function could take some sort of A4-like structure to
make creating the menu less verbose.
Events are sent via the display's event source:
if (event.type == ALLEGRO_EVENT_MENU_CLICK && event.menu.id == EXIT_ID)
Now to the dirty implementation details:
1) It requires hooking into the Allegro Windows message callback
(window_callback). I just hacked on an extra callback as part of the
ALLEGRO_DISPLAY_WIN structure that the native dialog addon uses.
Obviously that's not a great solution. What about adding a public
function like:
al_win_add_message_callback( /* my callback function */ );
That would add a callback that would be processed before Allegro's. If
it returns TRUE, then Allegro does not process the event. Obviously a
person could break things with this, but I don't see why that's our
concern.
2) I added a "first class" ALLEGRO_MENU_EVENT, but I assume addons
shouldn't do that.
I was going to just create and emit a user event (I assume that's what
the audio streams do), but I wanted to use the display's event source.
The docs say "The event source must have been initialised with
al_init_user_event_source." Does that mean I'm not allowed to emit a
user event through the display's event source?
3) I don't know about OS X or GTK menus, but I assume they could use
the same sort of API as above.
--
Matthew Leverton
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev