Author: mjmartin Date: Mon Nov 2 22:17:50 2009 New Revision: 43925
URL: http://svn.reactos.org/svn/reactos?rev=43925&view=rev Log: [user32] - Reapply changes from 40677 as the edit control does not receive the WM_COMMAND message from its context menu when doing clipboard ops. - Fixes crashes in applications created with visual basic when using edit controls context menu. - If we lose this in next sync, ill grovel and beg.
Modified: trunk/reactos/dll/win32/user32/controls/edit.c
Modified: trunk/reactos/dll/win32/user32/controls/edit.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/e... ============================================================================== --- trunk/reactos/dll/win32/user32/controls/edit.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/controls/edit.c [iso-8859-1] Mon Nov 2 22:17:50 2009 @@ -3383,15 +3383,60 @@
/********************************************************************* * - * WM_COMMAND - * - */ -static void EDIT_WM_Command(EDITSTATE *es, INT code, INT id, HWND control) -{ - if (code || control) - return; - - switch (id) { + * WM_CONTEXTMENU + * + * Note: the resource files resource/sysres_??.rc cannot define a + * single popup menu. Hence we use a (dummy) menubar + * containing the single popup menu as its first item. + * + * FIXME: the message identifiers have been chosen arbitrarily, + * hence we use MF_BYPOSITION. + * We might as well use the "real" values (anybody knows ?) + * The menu definition is in resources/sysres_??.rc. + * Once these are OK, we better use MF_BYCOMMAND here + * (as we do in EDIT_WM_Command()). + * + */ +static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y) +{ +#ifdef __REACTOS__ + HMENU menu = LoadMenuA(User32Instance, "EDITMENU"); +#else + HMENU menu = LoadMenuA(user32_module, "EDITMENU"); +#endif + HMENU popup = GetSubMenu(menu, 0); + UINT start = es->selection_start; + UINT end = es->selection_end; + + BOOL selectedItem; + ORDER_UINT(start, end); + + /* undo */ + EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); + /* cut */ + EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); + /* copy */ + EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); + /* paste */ + EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); + /* delete */ + EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); + /* select all */ + EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != get_text_length(es)) ? MF_ENABLED : MF_GRAYED)); + + if (x == -1 && y == -1) /* passed via VK_APPS press/release */ + { + RECT rc; + /* Windows places the menu at the edit's center in this case */ + GetClientRect(es->hwndSelf, &rc); + MapWindowPoints(es->hwndSelf, 0, (POINT *)&rc, 2); + x = rc.left + (rc.right - rc.left) / 2; + y = rc.top + (rc.bottom - rc.top) / 2; + } + + selectedItem = TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, x, y, 0, es->hwndSelf, NULL); + + switch (selectedItem) { case EM_UNDO: SendMessageW(es->hwndSelf, WM_UNDO, 0, 0); break; @@ -3415,62 +3460,7 @@ ERR("unknown menu item, please report\n"); break; } -} - - -/********************************************************************* - * - * WM_CONTEXTMENU - * - * Note: the resource files resource/sysres_??.rc cannot define a - * single popup menu. Hence we use a (dummy) menubar - * containing the single popup menu as its first item. - * - * FIXME: the message identifiers have been chosen arbitrarily, - * hence we use MF_BYPOSITION. - * We might as well use the "real" values (anybody knows ?) - * The menu definition is in resources/sysres_??.rc. - * Once these are OK, we better use MF_BYCOMMAND here - * (as we do in EDIT_WM_Command()). - * - */ -static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y) -{ -#ifdef __REACTOS__ - HMENU menu = LoadMenuA(User32Instance, "EDITMENU"); -#else - HMENU menu = LoadMenuA(user32_module, "EDITMENU"); -#endif - HMENU popup = GetSubMenu(menu, 0); - UINT start = es->selection_start; - UINT end = es->selection_end; - - ORDER_UINT(start, end); - - /* undo */ - EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); - /* cut */ - EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); - /* copy */ - EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); - /* paste */ - EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); - /* delete */ - EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); - /* select all */ - EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != get_text_length(es)) ? MF_ENABLED : MF_GRAYED)); - - if (x == -1 && y == -1) /* passed via VK_APPS press/release */ - { - RECT rc; - /* Windows places the menu at the edit's center in this case */ - GetClientRect(es->hwndSelf, &rc); - MapWindowPoints(es->hwndSelf, 0, (POINT *)&rc, 2); - x = rc.left + (rc.right - rc.left) / 2; - y = rc.top + (rc.bottom - rc.top) / 2; - } - - TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, es->hwndSelf, NULL); + DestroyMenu(menu); }
@@ -5300,11 +5290,7 @@ EDIT_WM_Clear(es); break;
- case WM_COMMAND: - EDIT_WM_Command(es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam); - break; - - case WM_CONTEXTMENU: + case WM_CONTEXTMENU: EDIT_WM_ContextMenu(es, (short)LOWORD(lParam), (short)HIWORD(lParam)); break;