From: <kon...@us...> - 2011-07-15 03:52:00
|
Revision: 14845 http://alleg.svn.sourceforge.net/alleg/?rev=14845&view=rev Author: konforce Date: 2011-07-15 03:51:54 +0000 (Fri, 15 Jul 2011) Log Message: ----------- native menus: simplify context menus to always show at current mouse location Modified Paths: -------------- allegro/branches/5.1/addons/native_dialog/allegro5/allegro_native_dialog.h allegro/branches/5.1/addons/native_dialog/allegro5/internal/aintern_native_dialog.h allegro/branches/5.1/addons/native_dialog/gtk_dialog.c allegro/branches/5.1/addons/native_dialog/menu.c allegro/branches/5.1/addons/native_dialog/osx_dialog.m allegro/branches/5.1/addons/native_dialog/win_dialog.c allegro/branches/5.1/docs/src/refman/native_dialog.txt allegro/branches/5.1/examples/ex_menu.c Modified: allegro/branches/5.1/addons/native_dialog/allegro5/allegro_native_dialog.h =================================================================== --- allegro/branches/5.1/addons/native_dialog/allegro5/allegro_native_dialog.h 2011-07-13 22:18:09 UTC (rev 14844) +++ allegro/branches/5.1/addons/native_dialog/allegro5/allegro_native_dialog.h 2011-07-15 03:51:54 UTC (rev 14845) @@ -104,7 +104,7 @@ /* displaying menus */ ALLEGRO_DIALOG_FUNC(ALLEGRO_MENU *, al_get_display_menu, (ALLEGRO_DISPLAY *display)); ALLEGRO_DIALOG_FUNC(bool, al_set_display_menu, (ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu)); -ALLEGRO_DIALOG_FUNC(bool, al_popup_menu, (ALLEGRO_MENU *popup, ALLEGRO_DISPLAY *display, int x, int y, int flags)); +ALLEGRO_DIALOG_FUNC(bool, al_popup_menu, (ALLEGRO_MENU *popup, ALLEGRO_DISPLAY *display)); ALLEGRO_DIALOG_FUNC(ALLEGRO_MENU *, al_remove_display_menu, (ALLEGRO_DISPLAY *display)); ALLEGRO_DIALOG_FUNC(uint32_t, al_get_allegro_native_dialog_version, (void)); Modified: allegro/branches/5.1/addons/native_dialog/allegro5/internal/aintern_native_dialog.h =================================================================== --- allegro/branches/5.1/addons/native_dialog/allegro5/internal/aintern_native_dialog.h 2011-07-13 22:18:09 UTC (rev 14844) +++ allegro/branches/5.1/addons/native_dialog/allegro5/internal/aintern_native_dialog.h 2011-07-15 03:51:54 UTC (rev 14845) @@ -111,7 +111,6 @@ extern bool _al_show_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu); extern bool _al_hide_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu); -extern bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu, - int x, int y, int flags); +extern bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu); #endif Modified: allegro/branches/5.1/addons/native_dialog/gtk_dialog.c =================================================================== --- allegro/branches/5.1/addons/native_dialog/gtk_dialog.c 2011-07-13 22:18:09 UTC (rev 14844) +++ allegro/branches/5.1/addons/native_dialog/gtk_dialog.c 2011-07-15 03:51:54 UTC (rev 14845) @@ -568,8 +568,6 @@ ALLEGRO_MENU *menu; ALLEGRO_MENU_ITEM *item; int i; - int x, y; - int flags; }; static void build_menu(GtkWidget *gmenu, ALLEGRO_MENU *amenu); @@ -989,8 +987,7 @@ return FALSE; } -bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu, - int x, int y, int flags) +bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu) { ARGS *args; @@ -1002,9 +999,6 @@ args->display = display; args->menu = menu; - args->x = x; - args->y = y; - args->flags = flags; return wait_for_args(do_show_popup_menu, args); } Modified: allegro/branches/5.1/addons/native_dialog/menu.c =================================================================== --- allegro/branches/5.1/addons/native_dialog/menu.c 2011-07-13 22:18:09 UTC (rev 14844) +++ allegro/branches/5.1/addons/native_dialog/menu.c 2011-07-15 03:51:54 UTC (rev 14845) @@ -716,22 +716,20 @@ /* Function: al_popup_menu */ -bool al_popup_menu(ALLEGRO_MENU *popup, ALLEGRO_DISPLAY *display, int x, int y, - int flags) +bool al_popup_menu(ALLEGRO_MENU *popup, ALLEGRO_DISPLAY *display) { ASSERT(popup); - ASSERT(display); - (void) flags; - if (!popup->is_popup_menu || popup->parent) return false; + if (!display) + display = al_get_current_display(); + /* Set the entire menu tree as owned by the display */ _al_walk_over_menu(popup, set_menu_display_r, display); - /* note the first two arguments are swapped */ - return _al_show_popup_menu(display, popup, x, y, flags); + return _al_show_popup_menu(display, popup); } /* Function: al_remove_display_menu Modified: allegro/branches/5.1/addons/native_dialog/osx_dialog.m =================================================================== --- allegro/branches/5.1/addons/native_dialog/osx_dialog.m 2011-07-13 22:18:09 UTC (rev 14844) +++ allegro/branches/5.1/addons/native_dialog/osx_dialog.m 2011-07-15 03:51:54 UTC (rev 14845) @@ -382,13 +382,9 @@ return false; } -bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu, - int x, int y, int flags) +bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu) { (void) display; (void) menu; - (void) x; - (void) y; - (void) flags; return false; } Modified: allegro/branches/5.1/addons/native_dialog/win_dialog.c =================================================================== --- allegro/branches/5.1/addons/native_dialog/win_dialog.c 2011-07-13 22:18:09 UTC (rev 14844) +++ allegro/branches/5.1/addons/native_dialog/win_dialog.c 2011-07-15 03:51:54 UTC (rev 14845) @@ -23,17 +23,6 @@ ALLEGRO_DEBUG_CHANNEL("win_dialog") -/* It looks like Windows only shows popups if triggered from - the main thread. To get around that, the WM_SHOW_POPUP - message is posted along with the POPUP_INFO when the user - opens a popup window. */ -typedef struct POPUP_INFO POPUP_INFO; -struct POPUP_INFO -{ - ALLEGRO_MENU *menu; - int x, y; - int flags; -}; #define WM_SHOW_POPUP (WM_APP + 42) /* Non-zero if text log window class was registered. */ @@ -635,12 +624,12 @@ } } else if (msg == WM_SHOW_POPUP) { - POPUP_INFO *info = (POPUP_INFO *) lParam; + ALLEGRO_MENU *menu = (ALLEGRO_MENU *) lParam; HWND hwnd = al_get_win_window_handle(display); - + POINT pos; + GetCursorPos(&pos); SetForegroundWindow(hwnd); - TrackPopupMenuEx((HMENU) info->menu->extra1, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, info->x, info->y, hwnd, NULL); - al_free(info); + TrackPopupMenuEx((HMENU) menu->extra1, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pos.x, pos.y, hwnd, NULL); return true; } @@ -747,29 +736,21 @@ SetMenu(hwnd, NULL); al_remove_win_window_callback(display, menu_callback); + + (void) menu; return true; } -bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu, - int x, int y, int flags) +bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu) { - /* (See earlier comment regarding Windows & popups) */ - POPUP_INFO *info = al_malloc(sizeof(*info)); - if (!info) + /* The popup request must come from the main thread. */ + + if (!display) return false; - al_get_window_position(display, &info->x, &info->y); - - /* XXX: maybe automatically add the height of the display menu (if present) */ - - info->flags = flags; - info->x += x; - info->y += y; - info->menu = menu; - al_add_win_window_callback(display, menu_callback); - PostMessage(al_get_win_window_handle(display), WM_SHOW_POPUP, 0, (LPARAM) info); + PostMessage(al_get_win_window_handle(display), WM_SHOW_POPUP, 0, (LPARAM) menu); return true; } Modified: allegro/branches/5.1/docs/src/refman/native_dialog.txt =================================================================== --- allegro/branches/5.1/docs/src/refman/native_dialog.txt 2011-07-13 22:18:09 UTC (rev 14844) +++ allegro/branches/5.1/docs/src/refman/native_dialog.txt 2011-07-15 03:51:54 UTC (rev 14845) @@ -556,12 +556,14 @@ ### API: al_popup_menu -Displays a context menu on the given display at location (x,y). The menu -must have been created with [al_create_popup_menu]. It generates events -just like a regular display menu does. It is possible that the menu will -be canceled without any selection being made. +Displays a context menu next to the mouse cursor. The menu must have been +created with [al_create_popup_menu]. It generates events just like a regular +display menu does. It is possible that the menu will be canceled without any +selection being made. -The `flags` parameter is currently unused. +The `display` parameter indicates which window the menu is associated with +(when you process the menu click event), but does not actually affect where +the menu is located on the screen. Returns `true` if the context menu was displayed. @@ -579,4 +581,4 @@ Since: 5.1.0 -See also: [al_set_display_menu] \ No newline at end of file +See also: [al_set_display_menu] Modified: allegro/branches/5.1/examples/ex_menu.c =================================================================== --- allegro/branches/5.1/examples/ex_menu.c 2011-07-13 22:18:09 UTC (rev 14844) +++ allegro/branches/5.1/examples/ex_menu.c 2011-07-15 03:51:54 UTC (rev 14845) @@ -193,7 +193,7 @@ /* Popup a context menu on a right click. */ if (event.mouse.display == display && event.mouse.button == 2) { if (pmenu) - al_popup_menu(pmenu, display, event.mouse.x, event.mouse.y + menu_height, 0); + al_popup_menu(pmenu, display); } } else if (event.type == ALLEGRO_EVENT_KEY_CHAR) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |