Index: dlls/user/menu.c =================================================================== RCS file: /home/wine/wine/dlls/user/menu.c,v retrieving revision 1.65 diff -u -r1.65 menu.c --- dlls/user/menu.c 12 Jun 2006 12:12:23 -0000 1.65 +++ dlls/user/menu.c 14 Jun 2006 21:43:33 -0000 @@ -6,6 +6,7 @@ * Copyright 1997 Morten Welinder * Copyright 2005 Maxime Bellengé * Copyright 2006 Phil Krylov + * Copyright 2006 Google (Thomas Kho) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -45,6 +46,7 @@ #include #include +#include #include "windef.h" #include "winbase.h" @@ -68,6 +70,7 @@ #define MM_SETMENUHANDLE (WM_USER + 0) #define MM_GETMENUHANDLE (WM_USER + 1) +/* MENUITEM and POPUPMENU duplicated in server/menu.c */ /* Menu item structure */ typedef struct { /* ----------- MENUITEMINFO Stuff ----------- */ @@ -282,19 +285,57 @@ /*********************************************************************** - * MENU_GetMenu + * SERVER_GetMenu * - * Validate the given menu handle and returns the menu structure pointer. + * Get a local copy of menu for given hMenu + * Return non-zero on success */ -static POPUPMENU *MENU_GetMenu(HMENU hMenu) +static int SERVER_GetMenu(HMENU hMenu, POPUPMENU *menu) { - POPUPMENU *menu = USER_HEAP_LIN_ADDR(hMenu); - if (!menu || menu->wMagic != MENU_MAGIC) + int ret = 0; + if (!menu) { - WARN("invalid menu handle=%p, ptr=%p, magic=%x\n", hMenu, menu, menu? menu->wMagic:0); - menu = NULL; + WARN("null pointer, hMenu=0x%x, menu=0x%x\n", (unsigned) hMenu, + (unsigned) menu); + return 0; } - return menu; + SERVER_START_REQ( menu_info ) + { + req->handle = hMenu; + req->mask = 0; + wine_server_set_reply(req, menu, sizeof(POPUPMENU)); + if (!wine_server_call_err( req )) + { + assert(wine_server_reply_size(reply) == sizeof(POPUPMENU)); + if (!(ret = reply->status)) + WARN("invalid menu handle %p\n", hMenu); + } + } + SERVER_END_REQ; + return ret; +} + +/*********************************************************************** + * SERVER_SetMenu + * + * Update specific fields in server's copy of menu + */ +static void SERVER_SetMenu(HMENU hMenu, POPUPMENU *menu, unsigned int mask) +{ + if (!menu) + { + WARN("null pointer, hMenu=0x%x, menu=0x%x\n", (unsigned) hMenu, + (unsigned) menu); + return; + } + SERVER_START_REQ( menu_info ) + { + req->handle = hMenu; + req->mask = mask; + wine_server_add_data(req, menu, sizeof(POPUPMENU)); + wine_server_call( req ); + } + SERVER_END_REQ; } /*********************************************************************** @@ -415,8 +456,11 @@ HMENU hMenu = LoadMenuW(user32_module, sysmenuW); if( hMenu ) { - POPUPMENU* menu = MENU_GetMenu(hMenu); + POPUPMENU tmpmenu; + POPUPMENU* menu = &tmpmenu; + SERVER_GetMenu(hMenu, menu); menu->wFlags |= MF_SYSMENU | MF_POPUP; + SERVER_SetMenu(hMenu, menu, SET_MI_FLAGS); SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE); } else @@ -444,9 +488,12 @@ TRACE("loading system menu, hWnd %p, hPopupMenu %p\n", hWnd, hPopupMenu); if ((hMenu = CreateMenu())) { - POPUPMENU *menu = MENU_GetMenu(hMenu); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; + SERVER_GetMenu(hMenu, menu); menu->wFlags = MF_SYSMENU; menu->hWnd = WIN_GetFullHandle( hWnd ); + SERVER_SetMenu(hMenu, menu, SET_MI_FLAGS|SET_MI_HWND); TRACE("hWnd %p (hMenu %p)\n", menu->hWnd, hMenu); if (!hPopupMenu) @@ -455,14 +502,21 @@ if (hPopupMenu) { if (GetClassLongW(hWnd, GCL_STYLE) & CS_NOCLOSE) + { DeleteMenu(hPopupMenu, SC_CLOSE, MF_BYCOMMAND); + } InsertMenuW( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, (UINT_PTR)hPopupMenu, NULL ); + SERVER_GetMenu(hMenu, menu); menu->items[0].fType = MF_SYSMENU | MF_POPUP; menu->items[0].fState = 0; - if ((menu = MENU_GetMenu(hPopupMenu))) menu->wFlags |= MF_SYSMENU; + if ((SERVER_GetMenu(hPopupMenu, menu))) + { + menu->wFlags |= MF_SYSMENU; + SERVER_SetMenu(hPopupMenu, menu, SET_MI_FLAGS); + } TRACE("hMenu=%p (hPopup %p)\n", hMenu, hPopupMenu ); return hMenu; @@ -511,10 +565,11 @@ static UINT MENU_GetStartOfNextColumn( HMENU hMenu ) { - POPUPMENU *menu = MENU_GetMenu(hMenu); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; UINT i; - if(!menu) + if(!SERVER_GetMenu(hMenu, menu)) return NO_SELECTED_ITEM; i = menu->FocusedItem + 1; @@ -540,10 +595,11 @@ static UINT MENU_GetStartOfPrevColumn( HMENU hMenu ) { - POPUPMENU *menu = MENU_GetMenu(hMenu); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; UINT i; - if( !menu ) + if( !SERVER_GetMenu(hMenu, menu) ) return NO_SELECTED_ITEM; if( menu->FocusedItem == 0 || menu->FocusedItem == NO_SELECTED_ITEM ) @@ -578,12 +634,14 @@ */ static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags ) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; MENUITEM *fallback = NULL; UINT fallback_pos = 0; UINT i; - if ((*hmenu == (HMENU)0xffff) || (!(menu = MENU_GetMenu(*hmenu)))) return NULL; + if ((*hmenu == (HMENU)0xffff) || (!(SERVER_GetMenu(*hmenu, menu)))) + return NULL; if (wFlags & MF_BYPOSITION) { if (*nPos >= menu->nItems) return NULL; @@ -633,11 +691,12 @@ */ UINT MENU_FindSubMenu( HMENU *hmenu, HMENU hSubTarget ) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; UINT i; MENUITEM *item; if (((*hmenu)==(HMENU)0xffff) || - (!(menu = MENU_GetMenu(*hmenu)))) + (!SERVER_GetMenu(*hmenu, menu))) return NO_SELECTED_ITEM; item = menu->items; for (i = 0; i < menu->nItems; i++, item++) { @@ -736,7 +795,9 @@ if (hmenu) { - POPUPMENU *menu = MENU_GetMenu( hmenu ); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; + SERVER_GetMenu(hmenu, menu); MENUITEM *item = menu->items; LRESULT menuchar; @@ -1338,7 +1399,8 @@ BOOL flat_menu = FALSE; int bkgnd; UINT arrow_bitmap_width = 0, arrow_bitmap_height = 0; - POPUPMENU *menu = MENU_GetMenu(hmenu); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; RECT bmprc; debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, ""); @@ -1386,7 +1448,8 @@ TRACE("rect=%s\n", wine_dbgstr_rect( &lpitem->rect)); rect = lpitem->rect; - MENU_AdjustMenuItemRect(MENU_GetMenu(hmenu), &rect); + SERVER_GetMenu(hmenu, menu); + MENU_AdjustMenuItemRect(menu, &rect); if (lpitem->fType & MF_OWNERDRAW) { @@ -1693,7 +1756,8 @@ hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) ); if( hPrevPen ) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; BOOL flat_menu = FALSE; SystemParametersInfoW (SPI_GETFLATMENU, 0, &flat_menu, 0); @@ -1702,7 +1766,7 @@ else DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT); - if( (menu = MENU_GetMenu( hmenu ))) + if( (SERVER_GetMenu( hmenu, menu ))) { /* draw menu items */ if( menu->nItems) @@ -1735,12 +1799,12 @@ UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd, BOOL suppress_draw) { - LPPOPUPMENU lppop; + POPUPMENU tmppop; + LPPOPUPMENU lppop = &tmppop; HFONT hfontOld = 0; HMENU hMenu = GetMenu(hwnd); - lppop = MENU_GetMenu( hMenu ); - if (lppop == NULL || lprect == NULL) + if (!SERVER_GetMenu(hMenu, lppop) || lprect == NULL) { return GetSystemMetrics(SM_CYMENU); } @@ -1750,7 +1814,10 @@ hfontOld = SelectObject( hDC, get_menu_font(FALSE)); if (lppop->Height == 0) + { MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd); + SERVER_SetMenu(hMenu, lppop, SET_MI_MAXBMPSIZE); + } lprect->bottom = lprect->top + lppop->Height; @@ -1770,17 +1837,19 @@ static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id, INT x, INT y, INT xanchor, INT yanchor ) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; UINT width, height; TRACE("owner=%p hmenu=%p id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n", hwndOwner, hmenu, id, x, y, xanchor, yanchor); - if (!(menu = MENU_GetMenu( hmenu ))) return FALSE; + if (!(SERVER_GetMenu( hmenu, menu ))) return FALSE; if (menu->FocusedItem != NO_SELECTED_ITEM) { menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT); menu->FocusedItem = NO_SELECTED_ITEM; + SERVER_SetMenu(hmenu, menu, SET_MI_FOCUSITEM); } /* store the owner for DrawItem */ @@ -1788,6 +1857,7 @@ menu->nScrollPos = 0; MENU_PopupMenuCalcSize( menu, hwndOwner ); + SERVER_SetMenu(hmenu, menu, SET_MI_WIDTH|SET_MI_HEIGHT|SET_MI_MAXBMPSIZE|SET_MI_TOTALHEIGHT|SET_MI_SCROLLING|SET_MI_SCROLLPOS|SET_MI_OWNER); /* adjust popup menu pos so that it fits within the desktop */ @@ -1819,6 +1889,7 @@ WS_POPUP, x, y, width, height, hwndOwner, 0, (HINSTANCE)GetWindowLongPtrW(hwndOwner, GWLP_HINSTANCE), (LPVOID)hmenu ); + SERVER_SetMenu( hmenu, menu, SET_MI_HWND ); if( !menu->hWnd ) return FALSE; if (!top_popup) top_popup = menu->hWnd; @@ -1878,13 +1949,14 @@ static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex, BOOL sendMenuSelect, HMENU topmenu ) { - LPPOPUPMENU lppop; + POPUPMENU tmppop; + LPPOPUPMENU lppop = &tmppop; HDC hdc; TRACE("owner=%p menu=%p index=0x%04x select=0x%04x\n", hwndOwner, hmenu, wIndex, sendMenuSelect); - lppop = MENU_GetMenu( hmenu ); - if ((!lppop) || (!lppop->nItems) || (!lppop->hWnd)) return; + if (!SERVER_GetMenu( hmenu, lppop ) || (!lppop->nItems) + || (!lppop->hWnd)) return; if (lppop->FocusedItem == wIndex) return; if (lppop->wFlags & MF_POPUP) hdc = GetDC( lppop->hWnd ); @@ -1904,6 +1976,7 @@ /* Highlight new item (if any) */ lppop->FocusedItem = wIndex; + SERVER_SetMenu(hmenu, lppop, SET_MI_FOCUSITEM); if (lppop->FocusedItem != NO_SELECTED_ITEM) { if(!(lppop->items[wIndex].fType & MF_SEPARATOR)) { @@ -1926,7 +1999,9 @@ if(topmenu){ int pos; if((pos=MENU_FindSubMenu(&topmenu, hmenu))!=NO_SELECTED_ITEM){ - POPUPMENU *ptm = MENU_GetMenu( topmenu ); + POPUPMENU tmpptm; + POPUPMENU *ptm = &tmpptm; + SERVER_GetMenu( topmenu, ptm ); MENUITEM *ip = &ptm->items[pos]; SendMessageW( hwndOwner, WM_MENUSELECT, MAKELONG(pos, ip->fType | ip->fState | @@ -1948,12 +2023,12 @@ static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset ) { INT i; - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; TRACE("hwnd=%p hmenu=%p off=0x%04x\n", hwndOwner, hmenu, offset); - menu = MENU_GetMenu( hmenu ); - if ((!menu) || (!menu->items)) return; + if ((!SERVER_GetMenu(hmenu, menu)) || (!menu->items)) return; if ( menu->FocusedItem != NO_SELECTED_ITEM ) { @@ -2031,8 +2106,13 @@ if (flags & MF_POPUP) { - POPUPMENU *menu = MENU_GetMenu((HMENU)id); - if (menu) menu->wFlags |= MF_POPUP; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; + if (SERVER_GetMenu((HMENU)id, menu)) + { + menu->wFlags |= MF_POPUP; + SERVER_SetMenu((HMENU)id, menu, SET_MI_FLAGS); + } else { item->wID = 0; @@ -2068,9 +2148,10 @@ static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags ) { MENUITEM *newItems; - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; - if (!(menu = MENU_GetMenu(hMenu))) + if (!SERVER_GetMenu(hMenu, menu)) return NULL; /* Find where to insert new item */ @@ -2082,7 +2163,7 @@ if (!MENU_FindItem( &hMenu, &pos, flags )) pos = menu->nItems; else { - if (!(menu = MENU_GetMenu( hMenu ))) + if (!SERVER_GetMenu(hMenu, menu)) return NULL; } } @@ -2107,6 +2188,7 @@ menu->nItems++; memset( &newItems[pos], 0, sizeof(*newItems) ); menu->Height = 0; /* force size recalculate */ + SERVER_SetMenu(hMenu, menu, SET_MI_ITEMS|SET_MI_NITEMS|SET_MI_HEIGHT); return &newItems[pos]; } @@ -2220,12 +2302,12 @@ */ static HMENU MENU_GetSubPopup( HMENU hmenu ) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; MENUITEM *item; - menu = MENU_GetMenu( hmenu ); - - if ((!menu) || (menu->FocusedItem == NO_SELECTED_ITEM)) return 0; + if (!SERVER_GetMenu( hmenu, menu ) + || (menu->FocusedItem == NO_SELECTED_ITEM)) return 0; item = &menu->items[menu->FocusedItem]; if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT)) @@ -2242,14 +2324,16 @@ static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu, BOOL sendMenuSelect ) { - POPUPMENU *menu = MENU_GetMenu( hmenu ); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; TRACE("owner=%p hmenu=%p 0x%04x\n", hwndOwner, hmenu, sendMenuSelect); - if (menu && top_popup) + if (SERVER_GetMenu( hmenu, menu ) && top_popup) { HMENU hsubmenu; - POPUPMENU *submenu; + POPUPMENU tmpsubmenu; + POPUPMENU *submenu = &tmpsubmenu; MENUITEM *item; if (menu->FocusedItem != NO_SELECTED_ITEM) @@ -2261,11 +2345,12 @@ hsubmenu = item->hSubMenu; } else return; - submenu = MENU_GetMenu( hsubmenu ); + SERVER_GetMenu( hsubmenu, submenu ); MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE ); MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect, 0 ); DestroyWindow( submenu->hWnd ); submenu->hWnd = 0; + SERVER_SetMenu(hsubmenu, submenu, SET_MI_HWND); } } @@ -2280,13 +2365,14 @@ BOOL selectFirst, UINT wFlags ) { RECT rect; - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; MENUITEM *item; HDC hdc; TRACE("owner=%p hmenu=%p 0x%04x\n", hwndOwner, hmenu, selectFirst); - if (!(menu = MENU_GetMenu( hmenu ))) return hmenu; + if (!(SERVER_GetMenu( hmenu, menu ))) return hmenu; if (menu->FocusedItem == NO_SELECTED_ITEM) return hmenu; @@ -2383,7 +2469,9 @@ */ static HMENU MENU_PtMenu( HMENU hMenu, POINT pt ) { - POPUPMENU *menu = MENU_GetMenu( hMenu ); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; + SERVER_GetMenu( hMenu, menu ); UINT item = menu->FocusedItem; HMENU ret; @@ -2421,11 +2509,12 @@ static INT MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu, UINT wFlags ) { MENUITEM *item; - POPUPMENU *menu = MENU_GetMenu( hMenu ); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; TRACE("%p hmenu=%p\n", pmt, hMenu); - if (!menu || !menu->nItems || + if (!SERVER_GetMenu( hMenu, menu ) || !menu->nItems || (menu->FocusedItem == NO_SELECTED_ITEM)) return -1; item = &menu->items[menu->FocusedItem]; @@ -2465,8 +2554,10 @@ */ static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id ) { - POPUPMENU *ptmenu = MENU_GetMenu( hPtMenu ); - POPUPMENU *topmenu = MENU_GetMenu( pmt->hTopMenu ); + POPUPMENU tmpptmenu, tmptopmenu; + POPUPMENU *ptmenu = &tmpptmenu, *topmenu = &tmptopmenu; + SERVER_GetMenu( hPtMenu, ptmenu ); + SERVER_GetMenu( pmt->hTopMenu, topmenu ); TRACE("%p hmenu=%p 0x%04x\n", pmt, hPtMenu, id); @@ -2495,8 +2586,10 @@ if (hPtMenu) { UINT id = 0; - POPUPMENU *ptmenu = MENU_GetMenu( hPtMenu ); + POPUPMENU tmpptmenu; + POPUPMENU *ptmenu = &tmpptmenu; MENUITEM *item; + SERVER_GetMenu( hPtMenu, ptmenu ); if( IS_SYSTEM_MENU(ptmenu) ) item = ptmenu->items; @@ -2536,8 +2629,10 @@ if (hPtMenu) { UINT id = 0; - POPUPMENU *ptmenu = MENU_GetMenu( hPtMenu ); MENUITEM *item; + POPUPMENU tmpptmenu; + POPUPMENU *ptmenu = &tmpptmenu; + SERVER_GetMenu( hPtMenu, ptmenu ); if( IS_SYSTEM_MENU(ptmenu) ) item = ptmenu->items; @@ -2559,6 +2654,7 @@ return 0; } ptmenu->bTimeToHide = TRUE; + SERVER_SetMenu( hPtMenu, ptmenu, SET_MI_TIMETOHIDE ); } return -1; } @@ -2572,11 +2668,12 @@ static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags ) { UINT id = NO_SELECTED_ITEM; - POPUPMENU *ptmenu = NULL; + POPUPMENU tmpptmenu; + POPUPMENU *ptmenu = &tmpptmenu; if( hPtMenu ) { - ptmenu = MENU_GetMenu( hPtMenu ); + SERVER_GetMenu( hPtMenu, ptmenu ); if( IS_SYSTEM_MENU(ptmenu) ) id = 0; else @@ -2629,7 +2726,9 @@ */ static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk ) { - POPUPMENU *menu = MENU_GetMenu( pmt->hTopMenu ); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; + SERVER_GetMenu( pmt->hTopMenu, menu ); if( (vk == VK_LEFT && menu->FocusedItem == 0 ) || (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1)) @@ -2659,7 +2758,7 @@ if( vk == VK_LEFT ) { - menu = MENU_GetMenu( hNewMenu ); + SERVER_GetMenu( hNewMenu, menu ); id = menu->nItems - 1; } } @@ -2768,7 +2867,9 @@ if (pmt->hCurrentMenu != pmt->hTopMenu) { - POPUPMENU *menu = MENU_GetMenu(pmt->hCurrentMenu); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; + SERVER_GetMenu(pmt->hCurrentMenu, menu); if (menu->wFlags & MF_POPUP) { @@ -2799,12 +2900,13 @@ */ static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags ) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; HMENU hmenutmp, hmenuprev; UINT prevcol; hmenuprev = hmenutmp = pmt->hTopMenu; - menu = MENU_GetMenu( hmenutmp ); + SERVER_GetMenu( hmenutmp, menu ); /* Try to move 1 column left (if possible) */ if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) != @@ -2853,12 +2955,15 @@ static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags ) { HMENU hmenutmp; - POPUPMENU *menu = MENU_GetMenu( pmt->hTopMenu ); + POPUPMENU tmpmenu, tmpcurmenu; + POPUPMENU *menu = &tmpmenu, *curmenu = &tmpcurmenu; + SERVER_GetMenu( pmt->hTopMenu, menu); UINT nextcol; + SERVER_GetMenu(pmt->hCurrentMenu, curmenu); TRACE("MENU_KeyRight called, cur %p (%s), top %p (%s).\n", pmt->hCurrentMenu, - debugstr_w((MENU_GetMenu(pmt->hCurrentMenu))->items[0].text), + debugstr_w(curmenu->items[0].text), pmt->hTopMenu, debugstr_w(menu->items[0].text) ); if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu)) @@ -2909,7 +3014,8 @@ HWND hwnd, const RECT *lprect ) { MSG msg; - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; BOOL fRemove; INT executedMenuId = -1; MTRACKER mt; @@ -2926,7 +3032,7 @@ hmenu, wFlags, x, y, hwnd, wine_dbgstr_rect( lprect)); fEndMenu = FALSE; - if (!(menu = MENU_GetMenu( hmenu ))) + if (!SERVER_GetMenu( hmenu, menu )) { WARN("Invalid menu handle %p\n", hmenu); SetLastError(ERROR_INVALID_MENU_HANDLE); @@ -2946,9 +3052,11 @@ while (!fEndMenu) { - menu = MENU_GetMenu( mt.hCurrentMenu ); - if (!menu) /* sometimes happens if I do a window manager close */ + if (!SERVER_GetMenu( mt.hCurrentMenu, menu )) + { + /* sometimes happens if I do a window manager close */ break; + } /* we have to keep the message in the queue until it's * clear that menu loop is not over yet. */ @@ -3076,7 +3184,7 @@ case VK_UP: case VK_DOWN: /* If on menu bar, pull-down the menu */ - menu = MENU_GetMenu( mt.hCurrentMenu ); + SERVER_GetMenu( mt.hCurrentMenu, menu ); if (!(menu->wFlags & MF_POPUP)) mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags); else /* otherwise try to move selection */ @@ -3173,23 +3281,28 @@ check for this first. */ if( IsMenu( mt.hTopMenu ) ) { - menu = MENU_GetMenu( mt.hTopMenu ); + int ret = SERVER_GetMenu( mt.hTopMenu, menu ); if( IsWindow( mt.hOwnerWnd ) ) { MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE ); - if (menu && (menu->wFlags & MF_POPUP)) + if (ret && (menu->wFlags & MF_POPUP)) { DestroyWindow( menu->hWnd ); menu->hWnd = 0; + SERVER_SetMenu(mt.hTopMenu, menu, SET_MI_HWND); } MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 ); SendMessageW( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 ); } /* Reset the variable for hiding menu */ - if( menu ) menu->bTimeToHide = FALSE; + if( ret ) + { + menu->bTimeToHide = FALSE; + SERVER_SetMenu(mt.hTopMenu, menu, SET_MI_TIMETOHIDE); + } } /* The return value is only used by TrackPopupMenu */ @@ -3203,7 +3316,8 @@ */ static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup, UINT wFlags) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; TRACE("hwnd=%p hmenu=%p\n", hWnd, hMenu); @@ -3227,7 +3341,11 @@ * It also enables menus to be displayed in more than one window, * but there are some bugs left that need to be fixed in this case. */ - if ((menu = MENU_GetMenu( hMenu ))) menu->hWnd = hWnd; + if (SERVER_GetMenu( hMenu, menu )) + { + menu->hWnd = hWnd; + SERVER_SetMenu( hMenu, menu, SET_MI_HWND ); + } return TRUE; } @@ -3440,16 +3558,18 @@ { HDC hdc; RECT rectBar; - LPPOPUPMENU lppop; + POPUPMENU tmppop; + LPPOPUPMENU lppop = &tmppop; TRACE("HWND %p, width %d, at (%d, %d).\n", hwnd, menubarWidth, orgX, orgY ); - if (!(lppop = MENU_GetMenu( GetMenu(hwnd) ))) return 0; + if (!SERVER_GetMenu( GetMenu(hwnd), lppop )) return 0; hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW ); SelectObject( hdc, get_menu_font(FALSE)); SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+GetSystemMetrics(SM_CYMENU)); MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd ); + SERVER_SetMenu( GetMenu(hwnd), lppop, SET_MI_WIDTH|SET_MI_HEIGHT|SET_MI_MAXBMPSIZE|SET_MI_TOTALHEIGHT|SET_MI_SCROLLING); ReleaseDC( hwnd, hdc ); return lppop->Height; } @@ -3519,12 +3639,13 @@ { UINT oldflags; MENUITEM *item; - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; TRACE("(%p, %04x, %04x) !\n", hMenu, wItemID, wFlags); /* Get the Popupmenu to access the owner menu */ - if (!(menu = MENU_GetMenu(hMenu))) + if (!SERVER_GetMenu(hMenu, menu)) return (UINT)-1; if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) @@ -3539,10 +3660,11 @@ if (menu->hSysMenuOwner != 0) { RECT rc; - POPUPMENU* parentMenu; + POPUPMENU tmpparentMenu; + POPUPMENU *parentMenu = &tmpparentMenu; /* Get the parent menu to access*/ - if (!(parentMenu = MENU_GetMenu(menu->hSysMenuOwner))) + if (!SERVER_GetMenu(menu->hSysMenuOwner, parentMenu)) return (UINT)-1; /* Refresh the frame to reflect the change */ @@ -3614,10 +3736,11 @@ BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID, UINT wHilite ) { - LPPOPUPMENU menu; + POPUPMENU tmpmenu; + LPPOPUPMENU menu = &tmpmenu; TRACE("(%p, %p, %04x, %04x);\n", hWnd, hMenu, wItemID, wHilite); if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE; - if (!(menu = MENU_GetMenu(hMenu))) return FALSE; + if (!SERVER_GetMenu(hMenu, menu)) return FALSE; if (menu->FocusedItem == wItemID) return TRUE; MENU_HideSubPopups( hWnd, hMenu, FALSE ); MENU_SelectItem( hWnd, hMenu, wItemID, TRUE, 0 ); @@ -3636,8 +3759,9 @@ debug_print_menuitem (" item: ", item, ""); if (item->fType & MF_POPUP) { - POPUPMENU *menu = MENU_GetMenu( item->hSubMenu ); - if (!menu) return -1; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; + if (!SERVER_GetMenu( item->hSubMenu, menu )) return -1; else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff); } else @@ -3655,8 +3779,9 @@ */ INT WINAPI GetMenuItemCount( HMENU hMenu ) { - LPPOPUPMENU menu = MENU_GetMenu(hMenu); - if (!menu) return -1; + POPUPMENU tmpmenu; + LPPOPUPMENU menu = &tmpmenu; + if (!SERVER_GetMenu(hMenu, menu)) return -1; TRACE("(%p) returning %d\n", hMenu, menu->nItems ); return menu->nItems; } @@ -3699,7 +3824,13 @@ } if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */ - (MENU_GetMenu((HMENU)id))->wFlags |= MF_POPUP; + { + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; + SERVER_GetMenu((HMENU)id, menu); + menu->wFlags |= MF_POPUP; + SERVER_SetMenu((HMENU)id, menu, SET_MI_FLAGS); + } item->hCheckBit = item->hUnCheckBit = 0; return TRUE; @@ -3755,12 +3886,13 @@ */ BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags ) { - LPPOPUPMENU menu; + POPUPMENU tmpmenu; + LPPOPUPMENU menu = &tmpmenu; MENUITEM *item; TRACE("(menu=%p pos=%04x flags=%04x)\n",hMenu, nPos, wFlags); if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE; - if (!(menu = MENU_GetMenu(hMenu))) return FALSE; + if (!SERVER_GetMenu(hMenu, menu)) return FALSE; /* Remove item */ @@ -3782,6 +3914,7 @@ menu->items = HeapReAlloc( GetProcessHeap(), 0, menu->items, menu->nItems * sizeof(MENUITEM) ); } + SERVER_SetMenu(hMenu, menu, SET_MI_NITEMS|SET_MI_ITEMS); return TRUE; } @@ -3807,6 +3940,8 @@ UINT_PTR id, LPCWSTR str ) { MENUITEM *item; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; if (IS_STRING_ITEM(flags)) TRACE("%p %d %04x %04x %s\n", hMenu, pos, flags, id, debugstr_w(str) ); @@ -3814,7 +3949,9 @@ TRACE("%p %d %04x %04x %p\n", hMenu, pos, flags, id, str ); if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) return FALSE; - MENU_GetMenu(hMenu)->Height = 0; /* force size recalculate */ + SERVER_GetMenu(hMenu, menu); + menu->Height = 0; /* force size recalculate */ + SERVER_SetMenu(hMenu, menu, SET_MI_HEIGHT); return MENU_SetItemData( item, flags, id, str ); } @@ -3849,12 +3986,14 @@ HMENU WINAPI CreatePopupMenu(void) { HMENU hmenu; - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; if (!(hmenu = CreateMenu())) return 0; - menu = MENU_GetMenu( hmenu ); + SERVER_GetMenu(hmenu, menu); menu->wFlags |= MF_POPUP; menu->bTimeToHide = FALSE; + SERVER_SetMenu(hmenu, menu, SET_MI_FLAGS|SET_MI_TIMETOHIDE); return hmenu; } @@ -3899,15 +4038,14 @@ */ HMENU WINAPI CreateMenu(void) { - HMENU hMenu; - LPPOPUPMENU menu; - if (!(hMenu = USER_HEAP_ALLOC( sizeof(POPUPMENU) ))) return 0; - menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu); - - ZeroMemory(menu, sizeof(POPUPMENU)); - menu->wMagic = MENU_MAGIC; - menu->FocusedItem = NO_SELECTED_ITEM; - menu->bTimeToHide = FALSE; + HMENU hMenu = 0; + + SERVER_START_REQ( create_menu ) + { + if (!wine_server_call_err( req )) + hMenu = reply->handle; + } + SERVER_END_REQ; TRACE("return %p\n", hMenu ); @@ -3920,12 +4058,12 @@ */ BOOL WINAPI DestroyMenu( HMENU hMenu ) { - LPPOPUPMENU lppop = MENU_GetMenu(hMenu); + POPUPMENU tmppop; + LPPOPUPMENU lppop = &tmppop; TRACE("(%p)\n", hMenu); - - if (!lppop) return FALSE; + if (!SERVER_GetMenu(hMenu, lppop)) return FALSE; lppop->wMagic = 0; /* Mark it as destroyed */ @@ -3947,7 +4085,15 @@ } HeapFree( GetProcessHeap(), 0, lppop->items ); } - USER_HEAP_FREE( hMenu ); + + SERVER_START_REQ( destroy_menu ) + { + req->handle = hMenu; + if (!wine_server_call_err( req )) + { + } + } + SERVER_END_REQ; return TRUE; } @@ -3978,14 +4124,17 @@ if( wndPtr->hSysMenu ) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; retvalue = GetSubMenu(wndPtr->hSysMenu, 0); /* Store the dummy sysmenu handle to facilitate the refresh */ /* of the close button if the SC_CLOSE item change */ - menu = MENU_GetMenu(retvalue); - if ( menu ) + if (SERVER_GetMenu(retvalue, menu)) + { menu->hSysMenuOwner = wndPtr->hSysMenu; + SERVER_SetMenu(retvalue, menu, SET_MI_OWNER); + } } WIN_ReleasePtr( wndPtr ); } @@ -4053,12 +4202,14 @@ if (hMenu != 0) { - LPPOPUPMENU lpmenu; + POPUPMENU tmpmenu; + LPPOPUPMENU lpmenu = &tmpmenu; - if (!(lpmenu = MENU_GetMenu(hMenu))) return FALSE; + if (!SERVER_GetMenu(hMenu, lpmenu)) return FALSE; lpmenu->hWnd = hWnd; lpmenu->Height = 0; /* Make sure we recalculate the size */ + SERVER_SetMenu(hMenu, lpmenu, SET_MI_HWND|SET_MI_HEIGHT); } SetWindowLongPtrW( hWnd, GWLP_ID, (LONG_PTR)hMenu ); return TRUE; @@ -4097,15 +4248,17 @@ */ BOOL WINAPI DrawMenuBar( HWND hWnd ) { - LPPOPUPMENU lppop; + POPUPMENU tmppop; + LPPOPUPMENU lppop = &tmppop; HMENU hMenu = GetMenu(hWnd); if (!WIN_ALLOWED_MENU(GetWindowLongW( hWnd, GWL_STYLE ))) return FALSE; - if (!hMenu || !(lppop = MENU_GetMenu( hMenu ))) return FALSE; + if (!hMenu || !SERVER_GetMenu( hMenu, lppop )) return FALSE; lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */ lppop->hwndOwner = hWnd; + SERVER_SetMenu( hMenu, lppop, SET_MI_HEIGHT|SET_MI_OWNER ); SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED ); return TRUE; @@ -4122,7 +4275,8 @@ */ DWORD WINAPI DrawMenuBarTemp(HWND hwnd, HDC hDC, LPRECT lprect, HMENU hMenu, HFONT hFont) { - LPPOPUPMENU lppop; + POPUPMENU tmppop; + LPPOPUPMENU lppop = &tmppop; UINT i,retvalue; HFONT hfontOld = 0; BOOL flat_menu = FALSE; @@ -4135,8 +4289,7 @@ if (!hFont) hFont = get_menu_font(FALSE); - lppop = MENU_GetMenu( hMenu ); - if (lppop == NULL || lprect == NULL) + if (!SERVER_GetMenu(hMenu, lppop) || lprect == NULL) { retvalue = GetSystemMetrics(SM_CYMENU); goto END; @@ -4147,7 +4300,10 @@ hfontOld = SelectObject( hDC, hFont); if (lppop->Height == 0) + { MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd); + SERVER_SetMenu(hMenu, lppop, SET_MI_MAXBMPSIZE); + } lprect->bottom = lprect->top + lppop->Height; @@ -4335,9 +4491,9 @@ */ BOOL WINAPI IsMenu(HMENU hmenu) { - LPPOPUPMENU menu = MENU_GetMenu(hmenu); - - if (!menu) + POPUPMENU menu; + + if (!SERVER_GetMenu(hmenu, &menu)) { SetLastError(ERROR_INVALID_MENU_HANDLE); return FALSE; @@ -4570,9 +4726,12 @@ if (lpmii->fMask & MIIM_SUBMENU) { menu->hSubMenu = lpmii->hSubMenu; if (menu->hSubMenu) { - POPUPMENU *subMenu = MENU_GetMenu(menu->hSubMenu); - if (subMenu) { + POPUPMENU tmpsubMenu; + POPUPMENU *subMenu = &tmpsubMenu; + if (SERVER_GetMenu(menu->hSubMenu, subMenu)) + { subMenu->wFlags |= MF_POPUP; + SERVER_SetMenu(menu->hSubMenu, subMenu, SET_MI_FLAGS); menu->fType |= MF_POPUP; } else { @@ -4654,12 +4813,13 @@ BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT uItem, UINT bypos) { UINT i; - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; MENUITEM *item; TRACE("(%p,%d,%d)\n", hmenu, uItem, bypos); - if (!(menu = MENU_GetMenu(hmenu))) return FALSE; + if (!SERVER_GetMenu(hmenu, menu)) return FALSE; /* reset all default-item flags */ item = menu->items; @@ -4701,13 +4861,14 @@ */ UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; MENUITEM * item; UINT i = 0; TRACE("(%p,%d,%d)\n", hmenu, bypos, flags); - if (!(menu = MENU_GetMenu(hmenu))) return -1; + if (!SERVER_GetMenu(hmenu, menu)) return -1; /* find default item */ item = menu->items; @@ -4831,7 +4992,8 @@ BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem, LPRECT rect) { - POPUPMENU *itemMenu; + POPUPMENU tmpitemMenu; + POPUPMENU *itemMenu = &tmpitemMenu; MENUITEM *item; HWND referenceHwnd; @@ -4842,8 +5004,7 @@ if(!hwnd) { - itemMenu = MENU_GetMenu(hMenu); - if (itemMenu == NULL) + if (!SERVER_GetMenu(hMenu, itemMenu)) return FALSE; if(itemMenu->hWnd == 0) @@ -4871,11 +5032,12 @@ */ BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi) { - POPUPMENU *menu; + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; TRACE("(%p %p)\n", hMenu, lpmi); - if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && (menu = MENU_GetMenu(hMenu))) + if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && SERVER_GetMenu(hMenu, menu)) { if (lpmi->fMask & MIM_BACKGROUND) @@ -4899,6 +5061,8 @@ if (menu->dwStyle & MNS_NOTIFYBYPOS) FIXME("MNS_NOTIFYBYPOS unimplemented\n"); } + SERVER_SetMenu(hMenu, menu, lpmi->fMask & (MIM_BACKGROUND|MIM_HELPID|MIM_MAXHEIGHT|MIM_MENUDATA|MIM_STYLE)); + return TRUE; } return FALSE; @@ -4912,11 +5076,13 @@ * */ BOOL WINAPI GetMenuInfo (HMENU hMenu, LPMENUINFO lpmi) -{ POPUPMENU *menu; +{ + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; TRACE("(%p %p)\n", hMenu, lpmi); - if (lpmi && (menu = MENU_GetMenu(hMenu))) + if (lpmi && SERVER_GetMenu(hMenu, menu)) { if (lpmi->fMask & MIM_BACKGROUND) @@ -4945,11 +5111,12 @@ */ BOOL WINAPI SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpID) { - LPPOPUPMENU menu; + POPUPMENU tmpmenu; + LPPOPUPMENU menu = &tmpmenu; TRACE("(%p 0x%08lx)\n", hMenu, dwContextHelpID); - if ((menu = MENU_GetMenu(hMenu))) + if (SERVER_GetMenu(hMenu, menu)) { menu->dwContextHelpID = dwContextHelpID; return TRUE; @@ -4963,11 +5130,12 @@ */ DWORD WINAPI GetMenuContextHelpId( HMENU hMenu ) { - LPPOPUPMENU menu; + POPUPMENU tmpmenu; + LPPOPUPMENU menu = &tmpmenu; TRACE("(%p)\n", hMenu); - if ((menu = MENU_GetMenu(hMenu))) + if (SERVER_GetMenu(hMenu, menu)) { return menu->dwContextHelpID; } @@ -4979,11 +5147,12 @@ */ INT WINAPI MenuItemFromPoint(HWND hWnd, HMENU hMenu, POINT ptScreen) { - POPUPMENU *menu = MENU_GetMenu(hMenu); + POPUPMENU tmpmenu; + POPUPMENU *menu = &tmpmenu; UINT pos; /*FIXME: Do we have to handle hWnd here? */ - if (!menu) return -1; + if (!SERVER_GetMenu(hMenu, menu)) return -1; if (!MENU_FindItemByCoords(menu, ptScreen, &pos)) return -1; return pos; } Index: include/wine/server_protocol.h =================================================================== RCS file: /home/wine/wine/include/wine/server_protocol.h,v retrieving revision 1.200 diff -u -r1.200 server_protocol.h --- include/wine/server_protocol.h 7 Jun 2006 12:51:16 -0000 1.200 +++ include/wine/server_protocol.h 14 Jun 2006 21:43:34 -0000 @@ -3492,6 +3492,58 @@ #define SET_GLOBAL_TASKMAN_WINDOW 0x04 +struct menu_info_request +{ + struct request_header __header; + user_handle_t handle; + unsigned int mask; + /* VARARG(data,bytes); */ +}; +struct menu_info_reply +{ + struct reply_header __header; + unsigned int status; + /* VARARG(data,bytes); */ +}; + + +struct create_menu_request +{ + struct request_header __header; +}; +struct create_menu_reply +{ + struct reply_header __header; + user_handle_t handle; +}; + + +struct destroy_menu_request +{ + struct request_header __header; + user_handle_t handle; +}; +struct destroy_menu_reply +{ + struct reply_header __header; +}; + +#define SET_MI_FLAGS 0x80000000 +#define SET_MI_HWND 0x40000000 +#define SET_MI_SYSMENU 0x20000000 +#define SET_MI_OWNER 0x10000000 +#define SET_MI_FOCUSITEM 0x08000000 +#define SET_MI_TIMETOHIDE 0x04000000 +#define SET_MI_WIDTH 0x02000000 +#define SET_MI_HEIGHT 0x01000000 +#define SET_MI_SCROLLING 0x00800000 +#define SET_MI_SCROLLPOS 0x00400000 +#define SET_MI_TOTALHEIGHT 0x00200000 +#define SET_MI_MAXBMPSIZE 0x00100000 +#define SET_MI_ITEMS 0x00080000 +#define SET_MI_NITEMS 0x00040000 + + struct adjust_token_privileges_request { struct request_header __header; @@ -3927,6 +3979,9 @@ REQ_set_clipboard_info, REQ_open_token, REQ_set_global_windows, + REQ_menu_info, + REQ_create_menu, + REQ_destroy_menu, REQ_adjust_token_privileges, REQ_get_token_privileges, REQ_check_token_privileges, @@ -4147,6 +4202,9 @@ struct set_clipboard_info_request set_clipboard_info_request; struct open_token_request open_token_request; struct set_global_windows_request set_global_windows_request; + struct menu_info_request menu_info_request; + struct create_menu_request create_menu_request; + struct destroy_menu_request destroy_menu_request; struct adjust_token_privileges_request adjust_token_privileges_request; struct get_token_privileges_request get_token_privileges_request; struct check_token_privileges_request check_token_privileges_request; @@ -4365,6 +4423,9 @@ struct set_clipboard_info_reply set_clipboard_info_reply; struct open_token_reply open_token_reply; struct set_global_windows_reply set_global_windows_reply; + struct menu_info_reply menu_info_reply; + struct create_menu_reply create_menu_reply; + struct destroy_menu_reply destroy_menu_reply; struct adjust_token_privileges_reply adjust_token_privileges_reply; struct get_token_privileges_reply get_token_privileges_reply; struct check_token_privileges_reply check_token_privileges_reply; @@ -4382,6 +4443,6 @@ struct query_symlink_reply query_symlink_reply; }; -#define SERVER_PROTOCOL_VERSION 236 +#define SERVER_PROTOCOL_VERSION 11 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */ Index: server/Makefile.in =================================================================== RCS file: /home/wine/wine/server/Makefile.in,v retrieving revision 1.62 diff -u -r1.62 Makefile.in --- server/Makefile.in 20 Feb 2006 11:43:12 -0000 1.62 +++ server/Makefile.in 14 Jun 2006 21:43:34 -0000 @@ -26,6 +26,7 @@ mailslot.c \ main.c \ mapping.c \ + menu.c \ mutex.c \ named_pipe.c \ object.c \ Index: server/protocol.def =================================================================== RCS file: /home/wine/wine/server/protocol.def,v retrieving revision 1.200 diff -u -r1.200 protocol.def --- server/protocol.def 7 Jun 2006 12:51:16 -0000 1.200 +++ server/protocol.def 14 Jun 2006 21:43:35 -0000 @@ -2456,6 +2456,43 @@ #define SET_GLOBAL_PROGMAN_WINDOW 0x02 #define SET_GLOBAL_TASKMAN_WINDOW 0x04 +/* Set/get menu info */ +@REQ(menu_info) + user_handle_t handle; + unsigned int mask; + VARARG(data,bytes); +@REPLY + unsigned int status; + VARARG(data,bytes); +@END + +/* create a menu */ +@REQ(create_menu) +@REPLY + user_handle_t handle; +@END + +/* destroy menu */ +@REQ(destroy_menu) + user_handle_t handle; +@REPLY +@END + +#define SET_MI_FLAGS 0x80000000 +#define SET_MI_HWND 0x40000000 +#define SET_MI_SYSMENU 0x20000000 +#define SET_MI_OWNER 0x10000000 +#define SET_MI_FOCUSITEM 0x08000000 +#define SET_MI_TIMETOHIDE 0x04000000 +#define SET_MI_WIDTH 0x02000000 +#define SET_MI_HEIGHT 0x01000000 +#define SET_MI_SCROLLING 0x00800000 +#define SET_MI_SCROLLPOS 0x00400000 +#define SET_MI_TOTALHEIGHT 0x00200000 +#define SET_MI_MAXBMPSIZE 0x00100000 +#define SET_MI_ITEMS 0x00080000 +#define SET_MI_NITEMS 0x00040000 + /* Adjust the privileges held by a token */ @REQ(adjust_token_privileges) obj_handle_t handle; /* handle to the token */ Index: server/request.h =================================================================== RCS file: /home/wine/wine/server/request.h,v retrieving revision 1.132 diff -u -r1.132 request.h --- server/request.h 23 May 2006 12:49:34 -0000 1.132 +++ server/request.h 14 Jun 2006 21:43:35 -0000 @@ -308,6 +308,9 @@ DECL_HANDLER(set_clipboard_info); DECL_HANDLER(open_token); DECL_HANDLER(set_global_windows); +DECL_HANDLER(menu_info); +DECL_HANDLER(create_menu); +DECL_HANDLER(destroy_menu); DECL_HANDLER(adjust_token_privileges); DECL_HANDLER(get_token_privileges); DECL_HANDLER(check_token_privileges); @@ -527,6 +530,9 @@ (req_handler)req_set_clipboard_info, (req_handler)req_open_token, (req_handler)req_set_global_windows, + (req_handler)req_menu_info, + (req_handler)req_create_menu, + (req_handler)req_destroy_menu, (req_handler)req_adjust_token_privileges, (req_handler)req_get_token_privileges, (req_handler)req_check_token_privileges, Index: server/trace.c =================================================================== RCS file: /home/wine/wine/server/trace.c,v retrieving revision 1.313 diff -u -r1.313 trace.c --- server/trace.c 8 Jun 2006 10:07:22 -0000 1.313 +++ server/trace.c 14 Jun 2006 21:43:35 -0000 @@ -3044,6 +3044,35 @@ fprintf( stderr, " old_taskman_window=%p", req->old_taskman_window ); } +static void dump_menu_info_request( const struct menu_info_request *req ) +{ + fprintf( stderr, " handle=%p,", req->handle ); + fprintf( stderr, " mask=%08x,", req->mask ); + fprintf( stderr, " data=" ); + dump_varargs_bytes( cur_size ); +} + +static void dump_menu_info_reply( const struct menu_info_reply *req ) +{ + fprintf( stderr, " status=%08x,", req->status ); + fprintf( stderr, " data=" ); + dump_varargs_bytes( cur_size ); +} + +static void dump_create_menu_request( const struct create_menu_request *req ) +{ +} + +static void dump_create_menu_reply( const struct create_menu_reply *req ) +{ + fprintf( stderr, " handle=%p", req->handle ); +} + +static void dump_destroy_menu_request( const struct destroy_menu_request *req ) +{ + fprintf( stderr, " handle=%p", req->handle ); +} + static void dump_adjust_token_privileges_request( const struct adjust_token_privileges_request *req ) { fprintf( stderr, " handle=%p,", req->handle ); @@ -3462,6 +3491,9 @@ (dump_func)dump_set_clipboard_info_request, (dump_func)dump_open_token_request, (dump_func)dump_set_global_windows_request, + (dump_func)dump_menu_info_request, + (dump_func)dump_create_menu_request, + (dump_func)dump_destroy_menu_request, (dump_func)dump_adjust_token_privileges_request, (dump_func)dump_get_token_privileges_request, (dump_func)dump_check_token_privileges_request, @@ -3678,6 +3710,9 @@ (dump_func)dump_set_clipboard_info_reply, (dump_func)dump_open_token_reply, (dump_func)dump_set_global_windows_reply, + (dump_func)dump_menu_info_reply, + (dump_func)dump_create_menu_reply, + (dump_func)0, (dump_func)dump_adjust_token_privileges_reply, (dump_func)dump_get_token_privileges_reply, (dump_func)dump_check_token_privileges_reply, @@ -3894,6 +3929,9 @@ "set_clipboard_info", "open_token", "set_global_windows", + "menu_info", + "create_menu", + "destroy_menu", "adjust_token_privileges", "get_token_privileges", "check_token_privileges", Index: server/user.h =================================================================== RCS file: /home/wine/wine/server/user.h,v retrieving revision 1.43 diff -u -r1.43 user.h --- server/user.h 8 Jun 2006 10:07:25 -0000 1.43 +++ server/user.h 14 Jun 2006 21:43:35 -0000 @@ -32,10 +32,12 @@ struct atom_table; struct clipboard; +/* from http://www.ddj.com/dept/windows/184416526?pgno=3 */ enum user_object { USER_WINDOW = 1, - USER_HOOK + USER_MENU = 2, + USER_HOOK = 5 }; #define DESKTOP_ATOM ((atom_t)32769) --- /dev/null 2006-05-31 09:29:03.272380500 -0700 +++ server/menu.c 2006-06-09 16:15:43.000000000 -0700 @@ -0,0 +1,207 @@ +/* + * Server-side menu handling + * + * Copyright (C) 2004 Ulrich Czekalla for CodeWeavers Inc. + * Copyright (C) 2006 Google (Thomas Kho) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "config.h" +#include "wine/port.h" + +#include + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winbase.h" +#include "wingdi.h" +#include "winuser.h" +#include "winternl.h" + +#include "object.h" +#include "request.h" +#include "user.h" +#include "unicode.h" + +/* MENUITEM and POPUPMENU duplicated in dlls/user/menu.c */ +/* Menu item structure */ +typedef struct { + /* ----------- MENUITEMINFO Stuff ----------- */ + UINT fType; /* Item type. */ + UINT fState; /* Item state. */ + UINT_PTR wID; /* Item id. */ + HMENU hSubMenu; /* Pop-up menu. */ + HBITMAP hCheckBit; /* Bitmap when checked. */ + HBITMAP hUnCheckBit; /* Bitmap when unchecked. */ + LPWSTR text; /* Item text. */ + ULONG_PTR dwItemData; /* Application defined. */ + LPWSTR dwTypeData; /* depends on fMask */ + HBITMAP hbmpItem; /* bitmap */ + /* ----------- Wine stuff ----------- */ + RECT rect; /* Item area (relative to menu window) */ + UINT xTab; /* X position of text after Tab */ + SIZE bmpsize; /* size needed for the HBMMENU_CALLBACK + * bitmap */ +} MENUITEM; + +/* Popup menu structure */ +typedef struct { + WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */ + WORD wMagic; /* Magic number */ + WORD Width; /* Width of the whole menu */ + WORD Height; /* Height of the whole menu */ + UINT nItems; /* Number of items in the menu */ + HWND hWnd; /* Window containing the menu */ + MENUITEM *items; /* Array of menu items */ + UINT FocusedItem; /* Currently focused item */ + HWND hwndOwner; /* window receiving the messages for ownerdraw */ + BOOL bTimeToHide; /* Request hiding when receiving a second click in the top-level menu item */ + BOOL bScrolling; /* Scroll arrows are active */ + UINT nScrollPos; /* Current scroll position */ + UINT nTotalHeight; /* Total height of menu items inside menu */ + /* ------------ MENUINFO members ------ */ + DWORD dwStyle; /* Extended menu style */ + UINT cyMax; /* max height of the whole menu, 0 is screen height */ + HBRUSH hbrBack; /* brush for menu background */ + DWORD dwContextHelpID; + DWORD dwMenuData; /* application defined value */ + HMENU hSysMenuOwner; /* Handle to the dummy sys menu holder */ + SIZE maxBmpSize; /* Maximum size of the bitmap items */ +} POPUPMENU, *LPPOPUPMENU; + +struct menu +{ + user_handle_t handle; + POPUPMENU p; +}; + + +/* (other menu->FocusedItem values give the position of the focused item) */ +#define NO_SELECTED_ITEM 0xffff + + +/* retrive a pointer to a menu given its handle */ +static struct menu *get_menu(user_handle_t handle) +{ + struct menu *ret = get_user_object(handle, USER_MENU); + if (!ret) set_error(STATUS_INVALID_HANDLE); + return ret; +} + + +/* create a new menu structure */ +static struct menu *create_menu() +{ + struct menu *pmenu; + + if (!(pmenu = mem_alloc(sizeof(struct menu)))) + return NULL; + + ZeroMemory(pmenu, sizeof(struct menu)); + + if (!(pmenu->handle = alloc_user_handle(pmenu, USER_MENU))) + { + free(pmenu); + return NULL; + } + + return pmenu; +} + + +/* destroy a menu */ +static void destroy_menu(struct menu *pmenu) +{ + free_user_handle(pmenu->handle); + free(pmenu); +} + + +/* create a menu */ +DECL_HANDLER(create_menu) +{ + struct menu *pmenu; + + reply->handle = 0; + + if ((pmenu = create_menu())) + { + pmenu->p.FocusedItem = NO_SELECTED_ITEM; + pmenu->p.bTimeToHide = FALSE; + reply->handle = pmenu->handle; + } +} + + +/* destroy a menu */ +DECL_HANDLER(destroy_menu) +{ + struct menu *pmenu = get_menu(req->handle); + + if (pmenu) + destroy_menu(pmenu); +} + + +/* validate the given menu handle and set/get menu info */ +DECL_HANDLER(menu_info) +{ + struct menu *pmenu = get_menu(req->handle); + + if (pmenu) + { + if (req->mask && get_req_data_size() == sizeof(POPUPMENU)) + { + const POPUPMENU *p = get_req_data(); + + if (req->mask & SET_MI_FLAGS) pmenu->p.wFlags = p->wFlags; + if (req->mask & SET_MI_WIDTH) pmenu->p.Width = p->Width; + if (req->mask & SET_MI_HEIGHT) pmenu->p.Height = p->Height; + if (req->mask & SET_MI_NITEMS) pmenu->p.nItems = p->nItems; + if (req->mask & SET_MI_HWND) pmenu->p.hWnd = p->hWnd; + if (req->mask & SET_MI_ITEMS) pmenu->p.items = p->items; + if (req->mask & SET_MI_FOCUSITEM) + pmenu->p.FocusedItem = p->FocusedItem; + if (req->mask & SET_MI_OWNER) pmenu->p.hwndOwner = p->hwndOwner; + if (req->mask & SET_MI_TIMETOHIDE) + pmenu->p.bTimeToHide = p->bTimeToHide; + if (req->mask & SET_MI_SCROLLING) + pmenu->p.bScrolling = p->bScrolling; + if (req->mask & SET_MI_SCROLLPOS) + pmenu->p.nScrollPos = p->nScrollPos; + if (req->mask & SET_MI_TOTALHEIGHT) + pmenu->p.nTotalHeight = p->nTotalHeight; + + if (req->mask & MIM_STYLE) pmenu->p.dwStyle = p->dwStyle; + if (req->mask & MIM_MAXHEIGHT) pmenu->p.cyMax = p->cyMax; + if (req->mask & MIM_BACKGROUND) pmenu->p.hbrBack = p->hbrBack; + if (req->mask & MIM_HELPID) + pmenu->p.dwContextHelpID= p->dwContextHelpID; + if (req->mask & MIM_MENUDATA) pmenu->p.dwMenuData = p->dwMenuData; + if (req->mask & SET_MI_SYSMENU) + pmenu->p.hSysMenuOwner = p->hSysMenuOwner; + if (req->mask & SET_MI_MAXBMPSIZE) + pmenu->p.maxBmpSize = p->maxBmpSize; + } + + if (get_reply_max_size() == sizeof(POPUPMENU)) + { + set_reply_data(&pmenu->p, sizeof(POPUPMENU)); + } + } + reply->status = (int) pmenu; +}