Commit 2c7b8e00 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

win32u: Move NtUserEnableMenuItem implementation from user32.

parent a4d6198a
......@@ -3302,22 +3302,29 @@ static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y)
HMENU popup = GetSubMenu(menu, 0);
UINT start = es->selection_start;
UINT end = es->selection_end;
BOOL enabled;
UINT cmd;
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 | (NtUserIsClipboardFormatAvailable(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));
/* undo */
enabled = EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY);
NtUserEnableMenuItem( popup, 0, MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED) );
/* cut */
enabled = (end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY);
NtUserEnableMenuItem( popup, 2, MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED) );
/* copy */
enabled = (end - start) && !(es->style & ES_PASSWORD);
NtUserEnableMenuItem( popup, 3, MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED) );
/* paste */
enabled = NtUserIsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY);
NtUserEnableMenuItem( popup, 4, MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED) );
/* delete */
enabled = (end - start) && !(es->style & ES_READONLY);
NtUserEnableMenuItem( popup, 5, MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED) );
/* select all */
enabled = start || end != get_text_length(es);
NtUserEnableMenuItem( popup, 7, MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED) );
if (x == -1 && y == -1) /* passed via VK_APPS press/release */
{
......
......@@ -891,9 +891,9 @@ static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
return FALSE;
}
EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
NtUserEnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
NtUserEnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
NtUserEnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
/* redraw menu */
......
......@@ -447,20 +447,20 @@ static void MENU_InitSysMenuPopup( HMENU hmenu, DWORD style, DWORD clsStyle )
BOOL gray;
gray = !(style & WS_THICKFRAME) || (style & (WS_MAXIMIZE | WS_MINIMIZE));
EnableMenuItem( hmenu, SC_SIZE, (gray ? MF_GRAYED : MF_ENABLED) );
NtUserEnableMenuItem( hmenu, SC_SIZE, (gray ? MF_GRAYED : MF_ENABLED) );
gray = ((style & WS_MAXIMIZE) != 0);
EnableMenuItem( hmenu, SC_MOVE, (gray ? MF_GRAYED : MF_ENABLED) );
NtUserEnableMenuItem( hmenu, SC_MOVE, (gray ? MF_GRAYED : MF_ENABLED) );
gray = !(style & WS_MINIMIZEBOX) || (style & WS_MINIMIZE);
EnableMenuItem( hmenu, SC_MINIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
NtUserEnableMenuItem( hmenu, SC_MINIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
gray = !(style & WS_MAXIMIZEBOX) || (style & WS_MAXIMIZE);
EnableMenuItem( hmenu, SC_MAXIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
NtUserEnableMenuItem( hmenu, SC_MAXIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
gray = !(style & (WS_MAXIMIZE | WS_MINIMIZE));
EnableMenuItem( hmenu, SC_RESTORE, (gray ? MF_GRAYED : MF_ENABLED) );
NtUserEnableMenuItem( hmenu, SC_RESTORE, (gray ? MF_GRAYED : MF_ENABLED) );
gray = (clsStyle & CS_NOCLOSE) != 0;
/* The menu item must keep its state if it's disabled */
if(gray)
EnableMenuItem( hmenu, SC_CLOSE, MF_GRAYED);
NtUserEnableMenuItem( hmenu, SC_CLOSE, MF_GRAYED);
}
......@@ -3644,53 +3644,6 @@ BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data,
}
/**********************************************************************
* EnableMenuItem (USER32.@)
*/
BOOL WINAPI EnableMenuItem( HMENU hMenu, UINT id, UINT wFlags )
{
UINT oldflags, pos;
POPUPMENU *menu;
MENUITEM *item;
TRACE("(%p, %04x, %04x)\n", hMenu, id, wFlags);
/* Get the Popupmenu to access the owner menu */
if (!(menu = find_menu_item(hMenu, id, wFlags, &pos)))
return (UINT)-1;
item = &menu->items[pos];
oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
item->fState ^= (oldflags ^ wFlags) & (MF_GRAYED | MF_DISABLED);
/* If the close item in the system menu change update the close button */
if ((item->wID == SC_CLOSE) && (oldflags != wFlags) && menu->hSysMenuOwner)
{
RECT rc;
POPUPMENU* parentMenu;
HWND hwnd;
/* Get the parent menu to access */
parentMenu = grab_menu_ptr(menu->hSysMenuOwner);
release_menu_ptr(menu);
if (!parentMenu)
return (UINT)-1;
hwnd = parentMenu->hWnd;
release_menu_ptr(parentMenu);
/* Refresh the frame to reflect the change */
WIN_GetRectangles(hwnd, COORDS_CLIENT, &rc, NULL);
rc.bottom = 0;
NtUserRedrawWindow( hwnd, &rc, 0, RDW_FRAME | RDW_INVALIDATE | RDW_NOCHILDREN );
}
else
release_menu_ptr(menu);
return oldflags;
}
/*******************************************************************
* GetMenuStringA (USER32.@)
*/
......
......@@ -203,7 +203,7 @@
@ stdcall DrawTextW(long wstr long ptr long)
@ stdcall EditWndProc(long long long long) EditWndProcA
@ stdcall EmptyClipboard()
@ stdcall EnableMenuItem(long long long)
@ stdcall EnableMenuItem(long long long) NtUserEnableMenuItem
@ stdcall EnableMouseInPointer(long)
@ stdcall EnableNonClientDpiScaling(long)
@ stdcall EnableScrollBar(long long long)
......
......@@ -1150,6 +1150,7 @@ static struct unix_funcs unix_funcs =
NtUserDestroyWindow,
NtUserDispatchMessage,
NtUserDrawIconEx,
NtUserEnableMenuItem,
NtUserEndDeferWindowPosEx,
NtUserEndPaint,
NtUserEnumDisplayDevices,
......
......@@ -25,6 +25,7 @@
#include "win32u_private.h"
#include "ntuser_private.h"
#include "wine/server.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(menu);
......@@ -272,3 +273,49 @@ DWORD WINAPI NtUserCheckMenuItem( HMENU handle, UINT id, UINT flags )
release_menu_ptr(menu);
return ret;
}
/**********************************************************************
* NtUserEnableMenuItem (win32u.@)
*/
BOOL WINAPI NtUserEnableMenuItem( HMENU handle, UINT id, UINT flags )
{
UINT oldflags, pos;
POPUPMENU *menu;
MENUITEM *item;
TRACE( "(%p, %04x, %04x)\n", handle, id, flags );
/* Get the Popupmenu to access the owner menu */
if (!(menu = find_menu_item( handle, id, flags, &pos )))
return ~0u;
item = &menu->items[pos];
oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
item->fState ^= (oldflags ^ flags) & (MF_GRAYED | MF_DISABLED);
/* If the close item in the system menu change update the close button */
if (item->wID == SC_CLOSE && oldflags != flags && menu->hSysMenuOwner)
{
POPUPMENU *parent_menu;
RECT rc;
HWND hwnd;
/* Get the parent menu to access */
parent_menu = grab_menu_ptr( menu->hSysMenuOwner );
release_menu_ptr( menu );
if (!parent_menu)
return ~0u;
hwnd = parent_menu->hWnd;
release_menu_ptr( parent_menu );
/* Refresh the frame to reflect the change */
get_window_rects( hwnd, COORDS_CLIENT, &rc, NULL, get_thread_dpi() );
rc.bottom = 0;
NtUserRedrawWindow( hwnd, &rc, 0, RDW_FRAME | RDW_INVALIDATE | RDW_NOCHILDREN );
}
else
release_menu_ptr( menu );
return oldflags;
}
......@@ -860,7 +860,7 @@
@ stub NtUserEmptyClipboard
@ stub NtUserEnableChildWindowDpiMessage
@ stub NtUserEnableIAMAccess
@ stub NtUserEnableMenuItem
@ stdcall NtUserEnableMenuItem(long long long)
@ stub NtUserEnableMouseInPointer
@ stub NtUserEnableMouseInPointerForWindow
@ stub NtUserEnableMouseInputForCursorSuppression
......
......@@ -210,6 +210,7 @@ struct unix_funcs
LRESULT (WINAPI *pNtUserDispatchMessage)( const MSG *msg );
BOOL (WINAPI *pNtUserDrawIconEx)( HDC hdc, INT x0, INT y0, HICON icon, INT width,
INT height, UINT istep, HBRUSH hbr, UINT flags );
BOOL (WINAPI *pNtUserEnableMenuItem)( HMENU handle, UINT id, UINT flags );
BOOL (WINAPI *pNtUserEndDeferWindowPosEx)( HDWP hdwp, BOOL async );
BOOL (WINAPI *pNtUserEndPaint)( HWND hwnd, const PAINTSTRUCT *ps );
NTSTATUS (WINAPI *pNtUserEnumDisplayDevices)( UNICODE_STRING *device, DWORD index,
......
......@@ -826,6 +826,12 @@ BOOL WINAPI NtUserDrawIconEx( HDC hdc, INT x0, INT y0, HICON icon, INT width,
return unix_funcs->pNtUserDrawIconEx( hdc, x0, y0, icon, width, height, istep, hbr, flags );
}
BOOL WINAPI NtUserEnableMenuItem( HMENU handle, UINT id, UINT flags )
{
if (!unix_funcs) return FALSE;
return unix_funcs->pNtUserEnableMenuItem( handle, id, flags );
}
BOOL WINAPI NtUserEndDeferWindowPosEx( HDWP hdwp, BOOL async )
{
if (!unix_funcs) return FALSE;
......
......@@ -431,6 +431,7 @@ BOOL WINAPI NtUserDestroyWindow( HWND hwnd );
LRESULT WINAPI NtUserDispatchMessage( const MSG *msg );
BOOL WINAPI NtUserDrawIconEx( HDC hdc, INT x0, INT y0, HICON icon, INT width,
INT height, UINT istep, HBRUSH hbr, UINT flags );
BOOL WINAPI NtUserEnableMenuItem( HMENU handle, UINT id, UINT flags );
BOOL WINAPI NtUserEndDeferWindowPosEx( HDWP hdwp, BOOL async );
BOOL WINAPI NtUserEndPaint( HWND hwnd, const PAINTSTRUCT *ps );
NTSTATUS WINAPI NtUserEnumDisplayDevices( UNICODE_STRING *device, DWORD index,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment