| 1 | /* $Id: menu.cpp,v 1.8 2000-01-12 12:40:43 sandervl Exp $*/
|
|---|
| 2 | /*
|
|---|
| 3 | * Menu functions
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1993 Martin Ayotte
|
|---|
| 6 | * Copyright 1994 Alexandre Julliard
|
|---|
| 7 | * Copyright 1997 Morten Welinder
|
|---|
| 8 | *
|
|---|
| 9 | * Copyright 1999 Christoph Bratschi
|
|---|
| 10 | *
|
|---|
| 11 | * WINE version: 991212
|
|---|
| 12 | *
|
|---|
| 13 | * Status: ???
|
|---|
| 14 | * Version: ???
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | /*
|
|---|
| 18 | * Note: the style MF_MOUSESELECT is used to mark popup items that
|
|---|
| 19 | * have been selected, i.e. their popup menu is currently displayed.
|
|---|
| 20 | * This is probably not the meaning this style has in MS-Windows.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | #include <assert.h>
|
|---|
| 24 | #include <ctype.h>
|
|---|
| 25 | #include <stdlib.h>
|
|---|
| 26 | #include <string.h>
|
|---|
| 27 | #include <os2win.h>
|
|---|
| 28 | #include <heapstring.h>
|
|---|
| 29 | #include "controls.h"
|
|---|
| 30 | #include "menu.h"
|
|---|
| 31 |
|
|---|
| 32 | //DEFAULT_DEBUG_CHANNEL(menu)
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | /* internal popup menu window messages */
|
|---|
| 36 |
|
|---|
| 37 | #define MM_SETMENUHANDLE (WM_USER + 0)
|
|---|
| 38 | #define MM_GETMENUHANDLE (WM_USER + 1)
|
|---|
| 39 |
|
|---|
| 40 | /* Menu item structure */
|
|---|
| 41 | typedef struct {
|
|---|
| 42 | /* ----------- MENUITEMINFO Stuff ----------- */
|
|---|
| 43 | UINT fType; /* Item type. */
|
|---|
| 44 | UINT fState; /* Item state. */
|
|---|
| 45 | UINT wID; /* Item id. */
|
|---|
| 46 | HMENU hSubMenu; /* Pop-up menu. */
|
|---|
| 47 | HBITMAP hCheckBit; /* Bitmap when checked. */
|
|---|
| 48 | HBITMAP hUnCheckBit; /* Bitmap when unchecked. */
|
|---|
| 49 | LPSTR text; /* Item text or bitmap handle. */
|
|---|
| 50 | DWORD dwItemData; /* Application defined. */
|
|---|
| 51 | DWORD dwTypeData; /* depends on fMask */
|
|---|
| 52 | HBITMAP hbmpItem; /* bitmap in win98 style menus */
|
|---|
| 53 | /* ----------- Wine stuff ----------- */
|
|---|
| 54 | RECT rect; /* Item area (relative to menu window) */
|
|---|
| 55 | UINT xTab; /* X position of text after Tab */
|
|---|
| 56 | } MENUITEM;
|
|---|
| 57 |
|
|---|
| 58 | /* Popup menu structure */
|
|---|
| 59 | typedef struct {
|
|---|
| 60 | WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */
|
|---|
| 61 | WORD wMagic; /* Magic number */
|
|---|
| 62 | HQUEUE hTaskQ; /* Task queue for this menu */
|
|---|
| 63 | WORD Width; /* Width of the whole menu */
|
|---|
| 64 | WORD Height; /* Height of the whole menu */
|
|---|
| 65 | WORD nItems; /* Number of items in the menu */
|
|---|
| 66 | HWND hWnd; /* Window containing the menu */
|
|---|
| 67 | MENUITEM *items; /* Array of menu items */
|
|---|
| 68 | UINT FocusedItem; /* Currently focused item */
|
|---|
| 69 | HWND hwndOwner; /* window receiving the messages for ownerdraw */
|
|---|
| 70 | BOOL bTimeToHide; /* Request hiding when receiving a second click in the top-level menu item */
|
|---|
| 71 | /* ------------ MENUINFO members ------ */
|
|---|
| 72 | DWORD dwStyle; /* Extended mennu style */
|
|---|
| 73 | UINT cyMax; /* max hight of the whole menu, 0 is screen hight */
|
|---|
| 74 | HBRUSH hbrBack; /* brush for menu background */
|
|---|
| 75 | DWORD dwContextHelpID;
|
|---|
| 76 | DWORD dwMenuData; /* application defined value */
|
|---|
| 77 | HMENU hSysMenuOwner; /* Handle to the dummy sys menu holder */
|
|---|
| 78 | } POPUPMENU, *LPPOPUPMENU;
|
|---|
| 79 |
|
|---|
| 80 | /* internal flags for menu tracking */
|
|---|
| 81 |
|
|---|
| 82 | #define TF_ENDMENU 0x0001
|
|---|
| 83 | #define TF_SUSPENDPOPUP 0x0002
|
|---|
| 84 | #define TF_SKIPREMOVE 0x0004
|
|---|
| 85 |
|
|---|
| 86 | typedef struct
|
|---|
| 87 | {
|
|---|
| 88 | UINT trackFlags;
|
|---|
| 89 | HMENU hCurrentMenu; /* current submenu (can be equal to hTopMenu)*/
|
|---|
| 90 | HMENU hTopMenu; /* initial menu */
|
|---|
| 91 | HWND hOwnerWnd; /* where notifications are sent */
|
|---|
| 92 | POINT pt;
|
|---|
| 93 | } MTRACKER;
|
|---|
| 94 |
|
|---|
| 95 | #define MENU_MAGIC 0x554d /* 'MU' */
|
|---|
| 96 | #define IS_A_MENU(pmenu) ((pmenu) && (pmenu)->wMagic == MENU_MAGIC)
|
|---|
| 97 |
|
|---|
| 98 | #define ITEM_PREV -1
|
|---|
| 99 | #define ITEM_NEXT 1
|
|---|
| 100 |
|
|---|
| 101 | /* Internal MENU_TrackMenu() flags */
|
|---|
| 102 | #define TPM_INTERNAL 0xF0000000
|
|---|
| 103 | #define TPM_ENTERIDLEEX 0x80000000 /* set owner window for WM_ENTERIDLE */
|
|---|
| 104 | #define TPM_BUTTONDOWN 0x40000000 /* menu was clicked before tracking */
|
|---|
| 105 | #define TPM_POPUPMENU 0x20000000 /* menu is a popup menu */
|
|---|
| 106 |
|
|---|
| 107 | /* popup menu shade thickness */
|
|---|
| 108 | #define POPUP_XSHADE 4
|
|---|
| 109 | #define POPUP_YSHADE 4
|
|---|
| 110 |
|
|---|
| 111 | /* Space between 2 menu bar items */
|
|---|
| 112 | #define MENU_BAR_ITEMS_SPACE 12
|
|---|
| 113 |
|
|---|
| 114 | /* Minimum width of a tab character */
|
|---|
| 115 | #define MENU_TAB_SPACE 8
|
|---|
| 116 |
|
|---|
| 117 | /* Height of a separator item */
|
|---|
| 118 | #define SEPARATOR_HEIGHT 5
|
|---|
| 119 |
|
|---|
| 120 | /* (other menu->FocusedItem values give the position of the focused item) */
|
|---|
| 121 | #define NO_SELECTED_ITEM 0xffff
|
|---|
| 122 |
|
|---|
| 123 | #define MENU_ITEM_TYPE(flags) \
|
|---|
| 124 | ((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
|
|---|
| 125 |
|
|---|
| 126 | #define IS_STRING_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_STRING)
|
|---|
| 127 | #define IS_BITMAP_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_BITMAP)
|
|---|
| 128 |
|
|---|
| 129 | #define IS_SYSTEM_MENU(menu) \
|
|---|
| 130 | (!((menu)->wFlags & MF_POPUP) && (menu)->wFlags & MF_SYSMENU)
|
|---|
| 131 |
|
|---|
| 132 | #define IS_SYSTEM_POPUP(menu) \
|
|---|
| 133 | ((menu)->wFlags & MF_POPUP && (menu)->wFlags & MF_SYSMENU)
|
|---|
| 134 |
|
|---|
| 135 | #define TYPE_MASK (MFT_STRING | MFT_BITMAP | MFT_OWNERDRAW | MFT_SEPARATOR | \
|
|---|
| 136 | MFT_MENUBARBREAK | MFT_MENUBREAK | MFT_RADIOCHECK | \
|
|---|
| 137 | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY | \
|
|---|
| 138 | MF_POPUP | MF_SYSMENU | MF_HELP)
|
|---|
| 139 | #define STATE_MASK (~TYPE_MASK)
|
|---|
| 140 |
|
|---|
| 141 | /* Dimension of the menu bitmaps */
|
|---|
| 142 | static WORD check_bitmap_width = 0, check_bitmap_height = 0;
|
|---|
| 143 | static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0;
|
|---|
| 144 |
|
|---|
| 145 | static HBITMAP hStdRadioCheck = 0;
|
|---|
| 146 | static HBITMAP hStdCheck = 0;
|
|---|
| 147 | static HBITMAP hStdMnArrow = 0;
|
|---|
| 148 |
|
|---|
| 149 | /* Minimze/restore/close buttons to be inserted in menubar */
|
|---|
| 150 | static HBITMAP hBmpMinimize = 0;
|
|---|
| 151 | static HBITMAP hBmpMinimizeD = 0;
|
|---|
| 152 | static HBITMAP hBmpMaximize = 0;
|
|---|
| 153 | static HBITMAP hBmpMaximizeD = 0;
|
|---|
| 154 | static HBITMAP hBmpClose = 0;
|
|---|
| 155 | static HBITMAP hBmpCloseD = 0;
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 | static HBRUSH hShadeBrush = 0;
|
|---|
| 159 | static HFONT hMenuFont = 0;
|
|---|
| 160 | static HFONT hMenuFontBold = 0;
|
|---|
| 161 |
|
|---|
| 162 | static HMENU MENU_DefSysPopup = 0; /* Default system menu popup */
|
|---|
| 163 |
|
|---|
| 164 | /* Use global popup window because there's no way 2 menus can
|
|---|
| 165 | * be tracked at the same time. */
|
|---|
| 166 |
|
|---|
| 167 | static HWND pTopPopupWnd = 0;
|
|---|
| 168 | static UINT uSubPWndLevel = 0;
|
|---|
| 169 |
|
|---|
| 170 | /* Flag set by EndMenu() to force an exit from menu tracking */
|
|---|
| 171 | static BOOL fEndMenu = FALSE;
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 | /***********************************************************************
|
|---|
| 175 | * debug_print_menuitem
|
|---|
| 176 | *
|
|---|
| 177 | * Print a menuitem in readable form.
|
|---|
| 178 | */
|
|---|
| 179 |
|
|---|
| 180 | #define debug_print_menuitem(pre, mp, post) \
|
|---|
| 181 | if(!TRACE_ON(menu)) ; else do_debug_print_menuitem(pre, mp, post)
|
|---|
| 182 |
|
|---|
| 183 | #define MENUOUT(text) \
|
|---|
| 184 | DPRINTF("%s%s", (count++ ? "," : ""), (text))
|
|---|
| 185 |
|
|---|
| 186 | #define MENUFLAG(bit,text) \
|
|---|
| 187 | do { \
|
|---|
| 188 | if (flags & (bit)) { flags &= ~(bit); MENUOUT ((text)); } \
|
|---|
| 189 | } while (0)
|
|---|
| 190 |
|
|---|
| 191 | #if 0
|
|---|
| 192 | static void do_debug_print_menuitem(const char *prefix, MENUITEM * mp,
|
|---|
| 193 | const char *postfix)
|
|---|
| 194 | {
|
|---|
| 195 | TRACE("%s ", prefix);
|
|---|
| 196 | if (mp) {
|
|---|
| 197 | UINT flags = mp->fType;
|
|---|
| 198 | int typ = MENU_ITEM_TYPE(flags);
|
|---|
| 199 | DPRINTF( "{ ID=0x%x", mp->wID);
|
|---|
| 200 | if (flags & MF_POPUP)
|
|---|
| 201 | DPRINTF( ", Sub=0x%x", mp->hSubMenu);
|
|---|
| 202 | if (flags) {
|
|---|
| 203 | int count = 0;
|
|---|
| 204 | DPRINTF( ", Typ=");
|
|---|
| 205 | if (typ == MFT_STRING)
|
|---|
| 206 | /* Nothing */ ;
|
|---|
| 207 | else if (typ == MFT_SEPARATOR)
|
|---|
| 208 | MENUOUT("sep");
|
|---|
| 209 | else if (typ == MFT_OWNERDRAW)
|
|---|
| 210 | MENUOUT("own");
|
|---|
| 211 | else if (typ == MFT_BITMAP)
|
|---|
| 212 | MENUOUT("bit");
|
|---|
| 213 | else
|
|---|
| 214 | MENUOUT("???");
|
|---|
| 215 | flags -= typ;
|
|---|
| 216 |
|
|---|
| 217 | MENUFLAG(MF_POPUP, "pop");
|
|---|
| 218 | MENUFLAG(MFT_MENUBARBREAK, "barbrk");
|
|---|
| 219 | MENUFLAG(MFT_MENUBREAK, "brk");
|
|---|
| 220 | MENUFLAG(MFT_RADIOCHECK, "radio");
|
|---|
| 221 | MENUFLAG(MFT_RIGHTORDER, "rorder");
|
|---|
| 222 | MENUFLAG(MF_SYSMENU, "sys");
|
|---|
| 223 | MENUFLAG(MFT_RIGHTJUSTIFY, "right"); /* same as MF_HELP */
|
|---|
| 224 |
|
|---|
| 225 | if (flags)
|
|---|
| 226 | DPRINTF( "+0x%x", flags);
|
|---|
| 227 | }
|
|---|
| 228 | flags = mp->fState;
|
|---|
| 229 | if (flags) {
|
|---|
| 230 | int count = 0;
|
|---|
| 231 | DPRINTF( ", State=");
|
|---|
| 232 | MENUFLAG(MFS_GRAYED, "grey");
|
|---|
| 233 | MENUFLAG(MFS_DEFAULT, "default");
|
|---|
| 234 | MENUFLAG(MFS_DISABLED, "dis");
|
|---|
| 235 | MENUFLAG(MFS_CHECKED, "check");
|
|---|
| 236 | MENUFLAG(MFS_HILITE, "hi");
|
|---|
| 237 | MENUFLAG(MF_USECHECKBITMAPS, "usebit");
|
|---|
| 238 | MENUFLAG(MF_MOUSESELECT, "mouse");
|
|---|
| 239 | if (flags)
|
|---|
| 240 | DPRINTF( "+0x%x", flags);
|
|---|
| 241 | }
|
|---|
| 242 | if (mp->hCheckBit)
|
|---|
| 243 | DPRINTF( ", Chk=0x%x", mp->hCheckBit);
|
|---|
| 244 | if (mp->hUnCheckBit)
|
|---|
| 245 | DPRINTF( ", Unc=0x%x", mp->hUnCheckBit);
|
|---|
| 246 |
|
|---|
| 247 | if (typ == MFT_STRING) {
|
|---|
| 248 | if (mp->text)
|
|---|
| 249 | DPRINTF( ", Text=\"%s\"", mp->text);
|
|---|
| 250 | else
|
|---|
| 251 | DPRINTF( ", Text=Null");
|
|---|
| 252 | } else if (mp->text == NULL)
|
|---|
| 253 | /* Nothing */ ;
|
|---|
| 254 | else
|
|---|
| 255 | DPRINTF( ", Text=%p", mp->text);
|
|---|
| 256 | if (mp->dwItemData)
|
|---|
| 257 | DPRINTF( ", ItemData=0x%08lx", mp->dwItemData);
|
|---|
| 258 | DPRINTF( " }");
|
|---|
| 259 | } else {
|
|---|
| 260 | DPRINTF( "NULL");
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | DPRINTF(" %s\n", postfix);
|
|---|
| 264 | }
|
|---|
| 265 | #endif
|
|---|
| 266 |
|
|---|
| 267 | #undef MENUOUT
|
|---|
| 268 | #undef MENUFLAG
|
|---|
| 269 |
|
|---|
| 270 | //#define USER_HEAP_ALLOC(size) HeapAlloc(GetProcessHeap(),0,size)
|
|---|
| 271 | //#define USER_HEAP_FREE(handle) HeapFree(GetProcessHeap(),0,(LPVOID)handle)
|
|---|
| 272 |
|
|---|
| 273 | HMENU getMenu(HWND hwnd)
|
|---|
| 274 | {
|
|---|
| 275 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 276 |
|
|---|
| 277 | return win32wnd ? win32wnd->GetMenu():(HMENU)0;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | VOID setMenu(HWND hwnd,HMENU hMenu)
|
|---|
| 281 | {
|
|---|
| 282 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 283 |
|
|---|
| 284 | if (win32wnd) win32wnd->SetMenu(hMenu);
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | HMENU getSysMenu(HWND hwnd)
|
|---|
| 288 | {
|
|---|
| 289 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 290 |
|
|---|
| 291 | return win32wnd ? win32wnd->GetSysMenu():(HMENU)0;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | VOID setSysMenu(HWND hwnd,HMENU hMenu)
|
|---|
| 295 | {
|
|---|
| 296 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 297 |
|
|---|
| 298 | win32wnd->SetSysMenu(hMenu);
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | /***********************************************************************
|
|---|
| 302 | * MENU_CopySysPopup
|
|---|
| 303 | *
|
|---|
| 304 | * Return the default system menu.
|
|---|
| 305 | */
|
|---|
| 306 | static HMENU MENU_CopySysPopup(void)
|
|---|
| 307 | {
|
|---|
| 308 | HMENU hMenu = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU");
|
|---|
| 309 |
|
|---|
| 310 | if( hMenu ) {
|
|---|
| 311 | POPUPMENU* menu = (POPUPMENU*)hMenu;
|
|---|
| 312 | menu->wFlags |= MF_SYSMENU | MF_POPUP;
|
|---|
| 313 | SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE);
|
|---|
| 314 | }
|
|---|
| 315 | else {
|
|---|
| 316 | hMenu = 0;
|
|---|
| 317 | //ERR("Unable to load default system menu\n" );
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | //TRACE("returning %x.\n", hMenu );
|
|---|
| 321 |
|
|---|
| 322 | return hMenu;
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | /***********************************************************************
|
|---|
| 326 | * MENU_GetTopPopupWnd()
|
|---|
| 327 | *
|
|---|
| 328 | * Return the locked pointer pTopPopupWnd.
|
|---|
| 329 | */
|
|---|
| 330 | static HWND MENU_GetTopPopupWnd()
|
|---|
| 331 | {
|
|---|
| 332 | return pTopPopupWnd;
|
|---|
| 333 | }
|
|---|
| 334 | /***********************************************************************
|
|---|
| 335 | * MENU_ReleaseTopPopupWnd()
|
|---|
| 336 | *
|
|---|
| 337 | * Realease the locked pointer pTopPopupWnd.
|
|---|
| 338 | */
|
|---|
| 339 | static void MENU_ReleaseTopPopupWnd()
|
|---|
| 340 | {
|
|---|
| 341 | }
|
|---|
| 342 | /***********************************************************************
|
|---|
| 343 | * MENU_DestroyTopPopupWnd()
|
|---|
| 344 | *
|
|---|
| 345 | * Destroy the locked pointer pTopPopupWnd.
|
|---|
| 346 | */
|
|---|
| 347 | static void MENU_DestroyTopPopupWnd()
|
|---|
| 348 | {
|
|---|
| 349 | pTopPopupWnd = NULL;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 | /**********************************************************************
|
|---|
| 355 | * MENU_GetSysMenu
|
|---|
| 356 | *
|
|---|
| 357 | * Create a copy of the system menu. System menu in Windows is
|
|---|
| 358 | * a special menu-bar with the single entry - system menu popup.
|
|---|
| 359 | * This popup is presented to the outside world as a "system menu".
|
|---|
| 360 | * However, the real system menu handle is sometimes seen in the
|
|---|
| 361 | * WM_MENUSELECT paramemters (and Word 6 likes it this way).
|
|---|
| 362 | */
|
|---|
| 363 | HMENU MENU_GetSysMenu( HWND hWnd, HMENU hPopupMenu )
|
|---|
| 364 | {
|
|---|
| 365 | HMENU hMenu;
|
|---|
| 366 |
|
|---|
| 367 | hMenu = CreateMenu();
|
|---|
| 368 | if (hMenu)
|
|---|
| 369 | {
|
|---|
| 370 | POPUPMENU *menu = (POPUPMENU*)hMenu;
|
|---|
| 371 | menu->wFlags = MF_SYSMENU;
|
|---|
| 372 | menu->hWnd = hWnd;
|
|---|
| 373 |
|
|---|
| 374 | if (hPopupMenu == (HMENU)(-1))
|
|---|
| 375 | hPopupMenu = MENU_CopySysPopup();
|
|---|
| 376 | else if( !hPopupMenu ) hPopupMenu = MENU_DefSysPopup;
|
|---|
| 377 |
|
|---|
| 378 | if (hPopupMenu)
|
|---|
| 379 | {
|
|---|
| 380 | InsertMenuA( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, hPopupMenu, NULL );
|
|---|
| 381 |
|
|---|
| 382 | menu->items[0].fType = MF_SYSMENU | MF_POPUP;
|
|---|
| 383 | menu->items[0].fState = 0;
|
|---|
| 384 | menu = (POPUPMENU*)hPopupMenu;
|
|---|
| 385 | menu->wFlags |= MF_SYSMENU;
|
|---|
| 386 |
|
|---|
| 387 | //TRACE("GetSysMenu hMenu=%04x (%04x)\n", hMenu, hPopupMenu );
|
|---|
| 388 | return hMenu;
|
|---|
| 389 | }
|
|---|
| 390 | DestroyMenu( hMenu );
|
|---|
| 391 | }
|
|---|
| 392 | //ERR("failed to load system menu!\n");
|
|---|
| 393 | return 0;
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 | /***********************************************************************
|
|---|
| 398 | * MENU_Init
|
|---|
| 399 | *
|
|---|
| 400 | * Menus initialisation.
|
|---|
| 401 | */
|
|---|
| 402 | BOOL MENU_Init()
|
|---|
| 403 | {
|
|---|
| 404 | HBITMAP hBitmap;
|
|---|
| 405 | NONCLIENTMETRICSA ncm;
|
|---|
| 406 |
|
|---|
| 407 | static unsigned char shade_bits[16] = { 0x55, 0, 0xAA, 0,
|
|---|
| 408 | 0x55, 0, 0xAA, 0,
|
|---|
| 409 | 0x55, 0, 0xAA, 0,
|
|---|
| 410 | 0x55, 0, 0xAA, 0 };
|
|---|
| 411 |
|
|---|
| 412 | /* Load menu bitmaps */
|
|---|
| 413 | hStdCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECK));
|
|---|
| 414 | hStdRadioCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RADIOCHECK));
|
|---|
| 415 | hStdMnArrow = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW));
|
|---|
| 416 | /* Load system buttons bitmaps */
|
|---|
| 417 | hBmpMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
|
|---|
| 418 | hBmpMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
|
|---|
| 419 | hBmpMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
|
|---|
| 420 | hBmpMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
|
|---|
| 421 | hBmpClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE));
|
|---|
| 422 | hBmpCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
|
|---|
| 423 |
|
|---|
| 424 | if (hStdCheck)
|
|---|
| 425 | {
|
|---|
| 426 | BITMAP bm;
|
|---|
| 427 | GetObjectA( hStdCheck, sizeof(bm), &bm );
|
|---|
| 428 | check_bitmap_width = bm.bmWidth;
|
|---|
| 429 | check_bitmap_height = bm.bmHeight;
|
|---|
| 430 | } else
|
|---|
| 431 | return FALSE;
|
|---|
| 432 |
|
|---|
| 433 | /* Assume that radio checks have the same size as regular check. */
|
|---|
| 434 | if (!hStdRadioCheck)
|
|---|
| 435 | return FALSE;
|
|---|
| 436 |
|
|---|
| 437 | if (hStdMnArrow)
|
|---|
| 438 | {
|
|---|
| 439 | BITMAP bm;
|
|---|
| 440 | GetObjectA( hStdMnArrow, sizeof(bm), &bm );
|
|---|
| 441 | arrow_bitmap_width = bm.bmWidth;
|
|---|
| 442 | arrow_bitmap_height = bm.bmHeight;
|
|---|
| 443 | } else
|
|---|
| 444 | return FALSE;
|
|---|
| 445 |
|
|---|
| 446 | if (! (hBitmap = CreateBitmap( 8, 8, 1, 1, shade_bits)))
|
|---|
| 447 | return FALSE;
|
|---|
| 448 |
|
|---|
| 449 | if(!(hShadeBrush = CreatePatternBrush( hBitmap )))
|
|---|
| 450 | return FALSE;
|
|---|
| 451 |
|
|---|
| 452 | DeleteObject( hBitmap );
|
|---|
| 453 | if (!(MENU_DefSysPopup = MENU_CopySysPopup()))
|
|---|
| 454 | return FALSE;
|
|---|
| 455 |
|
|---|
| 456 | ncm.cbSize = sizeof (NONCLIENTMETRICSA);
|
|---|
| 457 | if (!(SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSA), &ncm, 0)))
|
|---|
| 458 | return FALSE;
|
|---|
| 459 |
|
|---|
| 460 | if (!(hMenuFont = CreateFontIndirectA( &ncm.lfMenuFont )))
|
|---|
| 461 | return FALSE;
|
|---|
| 462 |
|
|---|
| 463 | ncm.lfMenuFont.lfWeight += 300;
|
|---|
| 464 | if ( ncm.lfMenuFont.lfWeight > 1000)
|
|---|
| 465 | ncm.lfMenuFont.lfWeight = 1000;
|
|---|
| 466 |
|
|---|
| 467 | if (!(hMenuFontBold = CreateFontIndirectA( &ncm.lfMenuFont )))
|
|---|
| 468 | return FALSE;
|
|---|
| 469 |
|
|---|
| 470 | return TRUE;
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | /***********************************************************************
|
|---|
| 474 | * MENU_InitSysMenuPopup
|
|---|
| 475 | *
|
|---|
| 476 | * Grey the appropriate items in System menu.
|
|---|
| 477 | */
|
|---|
| 478 | static void MENU_InitSysMenuPopup( HMENU hmenu, DWORD style, DWORD clsStyle )
|
|---|
| 479 | {
|
|---|
| 480 | BOOL gray;
|
|---|
| 481 |
|
|---|
| 482 | gray = !(style & WS_THICKFRAME) || (style & (WS_MAXIMIZE | WS_MINIMIZE));
|
|---|
| 483 | EnableMenuItem( hmenu, SC_SIZE, (gray ? MF_GRAYED : MF_ENABLED) );
|
|---|
| 484 | gray = ((style & WS_MAXIMIZE) != 0);
|
|---|
| 485 | EnableMenuItem( hmenu, SC_MOVE, (gray ? MF_GRAYED : MF_ENABLED) );
|
|---|
| 486 | gray = !(style & WS_MINIMIZEBOX) || (style & WS_MINIMIZE);
|
|---|
| 487 | EnableMenuItem( hmenu, SC_MINIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
|
|---|
| 488 | gray = !(style & WS_MAXIMIZEBOX) || (style & WS_MAXIMIZE);
|
|---|
| 489 | EnableMenuItem( hmenu, SC_MAXIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
|
|---|
| 490 | gray = !(style & (WS_MAXIMIZE | WS_MINIMIZE));
|
|---|
| 491 | EnableMenuItem( hmenu, SC_RESTORE, (gray ? MF_GRAYED : MF_ENABLED) );
|
|---|
| 492 | gray = (clsStyle & CS_NOCLOSE) != 0;
|
|---|
| 493 |
|
|---|
| 494 | /* The menu item must keep its state if it's disabled */
|
|---|
| 495 | if(gray)
|
|---|
| 496 | EnableMenuItem( hmenu, SC_CLOSE, MF_GRAYED);
|
|---|
| 497 | }
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 | /******************************************************************************
|
|---|
| 501 | *
|
|---|
| 502 | * UINT32 MENU_GetStartOfNextColumn(
|
|---|
| 503 | * HMENU32 hMenu )
|
|---|
| 504 | *
|
|---|
| 505 | *****************************************************************************/
|
|---|
| 506 |
|
|---|
| 507 | static UINT MENU_GetStartOfNextColumn(
|
|---|
| 508 | HMENU hMenu )
|
|---|
| 509 | {
|
|---|
| 510 | POPUPMENU *menu = (POPUPMENU*)hMenu;
|
|---|
| 511 | UINT i = menu->FocusedItem + 1;
|
|---|
| 512 |
|
|---|
| 513 | if(!menu)
|
|---|
| 514 | return NO_SELECTED_ITEM;
|
|---|
| 515 |
|
|---|
| 516 | if( i == NO_SELECTED_ITEM )
|
|---|
| 517 | return i;
|
|---|
| 518 |
|
|---|
| 519 | for( ; i < menu->nItems; ++i ) {
|
|---|
| 520 | if (menu->items[i].fType & MF_MENUBARBREAK)
|
|---|
| 521 | return i;
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | return NO_SELECTED_ITEM;
|
|---|
| 525 | }
|
|---|
| 526 |
|
|---|
| 527 |
|
|---|
| 528 | /******************************************************************************
|
|---|
| 529 | *
|
|---|
| 530 | * UINT32 MENU_GetStartOfPrevColumn(
|
|---|
| 531 | * HMENU32 hMenu )
|
|---|
| 532 | *
|
|---|
| 533 | *****************************************************************************/
|
|---|
| 534 |
|
|---|
| 535 | static UINT MENU_GetStartOfPrevColumn(
|
|---|
| 536 | HMENU hMenu )
|
|---|
| 537 | {
|
|---|
| 538 | POPUPMENU const *menu = (POPUPMENU*)hMenu;
|
|---|
| 539 | UINT i;
|
|---|
| 540 |
|
|---|
| 541 | if( !menu )
|
|---|
| 542 | return NO_SELECTED_ITEM;
|
|---|
| 543 |
|
|---|
| 544 | if( menu->FocusedItem == 0 || menu->FocusedItem == NO_SELECTED_ITEM )
|
|---|
| 545 | return NO_SELECTED_ITEM;
|
|---|
| 546 |
|
|---|
| 547 | /* Find the start of the column */
|
|---|
| 548 |
|
|---|
| 549 | for(i = menu->FocusedItem; i != 0 &&
|
|---|
| 550 | !(menu->items[i].fType & MF_MENUBARBREAK);
|
|---|
| 551 | --i); /* empty */
|
|---|
| 552 |
|
|---|
| 553 | if(i == 0)
|
|---|
| 554 | return NO_SELECTED_ITEM;
|
|---|
| 555 |
|
|---|
| 556 | for(--i; i != 0; --i) {
|
|---|
| 557 | if (menu->items[i].fType & MF_MENUBARBREAK)
|
|---|
| 558 | break;
|
|---|
| 559 | }
|
|---|
| 560 |
|
|---|
| 561 | //TRACE("ret %d.\n", i );
|
|---|
| 562 |
|
|---|
| 563 | return i;
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 | /***********************************************************************
|
|---|
| 569 | * MENU_FindItem
|
|---|
| 570 | *
|
|---|
| 571 | * Find a menu item. Return a pointer on the item, and modifies *hmenu
|
|---|
| 572 | * in case the item was in a sub-menu.
|
|---|
| 573 | */
|
|---|
| 574 | static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags )
|
|---|
| 575 | {
|
|---|
| 576 | POPUPMENU *menu;
|
|---|
| 577 | UINT i;
|
|---|
| 578 |
|
|---|
| 579 | if (((*hmenu)==0xffff) || (!(menu = (POPUPMENU*)*hmenu))) return NULL;
|
|---|
| 580 | if (wFlags & MF_BYPOSITION)
|
|---|
| 581 | {
|
|---|
| 582 | if (*nPos >= menu->nItems) return NULL;
|
|---|
| 583 | return &menu->items[*nPos];
|
|---|
| 584 | }
|
|---|
| 585 | else
|
|---|
| 586 | {
|
|---|
| 587 | MENUITEM *item = menu->items;
|
|---|
| 588 |
|
|---|
| 589 | for (i = 0; i < menu->nItems; i++, item++)
|
|---|
| 590 | {
|
|---|
| 591 | if (item->wID == *nPos)
|
|---|
| 592 | {
|
|---|
| 593 | *nPos = i;
|
|---|
| 594 | return item;
|
|---|
| 595 | }
|
|---|
| 596 | else if (item->fType & MF_POPUP)
|
|---|
| 597 | {
|
|---|
| 598 | HMENU hsubmenu = item->hSubMenu;
|
|---|
| 599 | MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags );
|
|---|
| 600 | if (subitem)
|
|---|
| 601 | {
|
|---|
| 602 | *hmenu = hsubmenu;
|
|---|
| 603 | return subitem;
|
|---|
| 604 | }
|
|---|
| 605 | }
|
|---|
| 606 | }
|
|---|
| 607 | }
|
|---|
| 608 | return NULL;
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | /***********************************************************************
|
|---|
| 612 | * MENU_FindSubMenu
|
|---|
| 613 | *
|
|---|
| 614 | * Find a Sub menu. Return the position of the submenu, and modifies
|
|---|
| 615 | * *hmenu in case it is found in another sub-menu.
|
|---|
| 616 | * If the submenu cannot be found, NO_SELECTED_ITEM is returned.
|
|---|
| 617 | */
|
|---|
| 618 | UINT MENU_FindSubMenu( HMENU *hmenu, HMENU hSubTarget )
|
|---|
| 619 | {
|
|---|
| 620 | POPUPMENU *menu;
|
|---|
| 621 | UINT i;
|
|---|
| 622 | MENUITEM *item;
|
|---|
| 623 | if (((*hmenu)==0xffff) ||
|
|---|
| 624 | (!(menu = (POPUPMENU*)*hmenu)))
|
|---|
| 625 | return NO_SELECTED_ITEM;
|
|---|
| 626 | item = menu->items;
|
|---|
| 627 | for (i = 0; i < menu->nItems; i++, item++) {
|
|---|
| 628 | if(!(item->fType & MF_POPUP)) continue;
|
|---|
| 629 | if (item->hSubMenu == hSubTarget) {
|
|---|
| 630 | return i;
|
|---|
| 631 | }
|
|---|
| 632 | else {
|
|---|
| 633 | HMENU hsubmenu = item->hSubMenu;
|
|---|
| 634 | UINT pos = MENU_FindSubMenu( &hsubmenu, hSubTarget );
|
|---|
| 635 | if (pos != NO_SELECTED_ITEM) {
|
|---|
| 636 | *hmenu = hsubmenu;
|
|---|
| 637 | return pos;
|
|---|
| 638 | }
|
|---|
| 639 | }
|
|---|
| 640 | }
|
|---|
| 641 | return NO_SELECTED_ITEM;
|
|---|
| 642 | }
|
|---|
| 643 |
|
|---|
| 644 | /***********************************************************************
|
|---|
| 645 | * MENU_FreeItemData
|
|---|
| 646 | */
|
|---|
| 647 | static void MENU_FreeItemData( MENUITEM* item )
|
|---|
| 648 | {
|
|---|
| 649 | /* delete text */
|
|---|
| 650 | if (IS_STRING_ITEM(item->fType) && item->text)
|
|---|
| 651 | HeapFree(GetProcessHeap(), 0, item->text );
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | /***********************************************************************
|
|---|
| 655 | * MENU_FindItemByCoords
|
|---|
| 656 | *
|
|---|
| 657 | * Find the item at the specified coordinates (screen coords). Does
|
|---|
| 658 | * not work for child windows and therefore should not be called for
|
|---|
| 659 | * an arbitrary system menu.
|
|---|
| 660 | */
|
|---|
| 661 | static MENUITEM *MENU_FindItemByCoords( POPUPMENU *menu,
|
|---|
| 662 | POINT pt, UINT *pos )
|
|---|
| 663 | {
|
|---|
| 664 | MENUITEM *item;
|
|---|
| 665 | UINT i;
|
|---|
| 666 | RECT wrect;
|
|---|
| 667 |
|
|---|
| 668 | if (!GetWindowRect(menu->hWnd,&wrect)) return NULL;
|
|---|
| 669 | pt.x -= wrect.left;pt.y -= wrect.top;
|
|---|
| 670 | item = menu->items;
|
|---|
| 671 | for (i = 0; i < menu->nItems; i++, item++)
|
|---|
| 672 | {
|
|---|
| 673 | if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) &&
|
|---|
| 674 | (pt.y >= item->rect.top) && (pt.y < item->rect.bottom))
|
|---|
| 675 | {
|
|---|
| 676 | if (pos) *pos = i;
|
|---|
| 677 | return item;
|
|---|
| 678 | }
|
|---|
| 679 | }
|
|---|
| 680 | return NULL;
|
|---|
| 681 | }
|
|---|
| 682 |
|
|---|
| 683 |
|
|---|
| 684 | /***********************************************************************
|
|---|
| 685 | * MENU_FindItemByKey
|
|---|
| 686 | *
|
|---|
| 687 | * Find the menu item selected by a key press.
|
|---|
| 688 | * Return item id, -1 if none, -2 if we should close the menu.
|
|---|
| 689 | */
|
|---|
| 690 | static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu,
|
|---|
| 691 | UINT key, BOOL forceMenuChar )
|
|---|
| 692 | {
|
|---|
| 693 | //TRACE("\tlooking for '%c' in [%04x]\n", (char)key, (UINT16)hmenu );
|
|---|
| 694 |
|
|---|
| 695 | if (!IsMenu( hmenu ))
|
|---|
| 696 | {
|
|---|
| 697 | hmenu = GetSubMenu(getSysMenu(hwndOwner), 0);
|
|---|
| 698 | }
|
|---|
| 699 |
|
|---|
| 700 | if (hmenu)
|
|---|
| 701 | {
|
|---|
| 702 | POPUPMENU *menu = (POPUPMENU*)hmenu;
|
|---|
| 703 | MENUITEM *item = menu->items;
|
|---|
| 704 | LONG menuchar;
|
|---|
| 705 |
|
|---|
| 706 | if( !forceMenuChar )
|
|---|
| 707 | {
|
|---|
| 708 | UINT i;
|
|---|
| 709 |
|
|---|
| 710 | key = toupper(key);
|
|---|
| 711 | for (i = 0; i < menu->nItems; i++, item++)
|
|---|
| 712 | {
|
|---|
| 713 | if (item->text && (IS_STRING_ITEM(item->fType)))
|
|---|
| 714 | {
|
|---|
| 715 | char *p = item->text - 2;
|
|---|
| 716 | do
|
|---|
| 717 | {
|
|---|
| 718 | p = strchr (p + 2, '&');
|
|---|
| 719 | }
|
|---|
| 720 | while (p != NULL && p [1] == '&');
|
|---|
| 721 | if (p && (toupper(p[1]) == key)) return i;
|
|---|
| 722 | }
|
|---|
| 723 | }
|
|---|
| 724 | }
|
|---|
| 725 | menuchar = SendMessageA( hwndOwner, WM_MENUCHAR,
|
|---|
| 726 | MAKEWPARAM( key, menu->wFlags ), hmenu );
|
|---|
| 727 | if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
|
|---|
| 728 | if (HIWORD(menuchar) == 1) return (UINT)(-2);
|
|---|
| 729 | }
|
|---|
| 730 | return (UINT)(-1);
|
|---|
| 731 | }
|
|---|
| 732 | /***********************************************************************
|
|---|
| 733 | * MENU_LoadMagicItem
|
|---|
| 734 | *
|
|---|
| 735 | * Load the bitmap associated with the magic menu item and its style
|
|---|
| 736 | */
|
|---|
| 737 |
|
|---|
| 738 | static HBITMAP MENU_LoadMagicItem(UINT id, BOOL hilite, DWORD dwItemData)
|
|---|
| 739 | {
|
|---|
| 740 | /*
|
|---|
| 741 | * Magic menu item id's section
|
|---|
| 742 | * These magic id's are used by windows to insert "standard" mdi
|
|---|
| 743 | * buttons (minimize,restore,close) on menu. Under windows,
|
|---|
| 744 | * these magic id's make sure the right things appear when those
|
|---|
| 745 | * bitmap buttons are pressed/selected/released.
|
|---|
| 746 | */
|
|---|
| 747 |
|
|---|
| 748 | switch(id & 0xffff)
|
|---|
| 749 | { case HBMMENU_SYSTEM:
|
|---|
| 750 | return (dwItemData) ?
|
|---|
| 751 | (HBITMAP)dwItemData :
|
|---|
| 752 | (hilite ? hBmpMinimizeD : hBmpMinimize);
|
|---|
| 753 | case HBMMENU_MBAR_RESTORE:
|
|---|
| 754 | return (hilite ? hBmpMaximizeD: hBmpMaximize);
|
|---|
| 755 | case HBMMENU_MBAR_MINIMIZE:
|
|---|
| 756 | return (hilite ? hBmpMinimizeD : hBmpMinimize);
|
|---|
| 757 | case HBMMENU_MBAR_CLOSE:
|
|---|
| 758 | return (hilite ? hBmpCloseD : hBmpClose);
|
|---|
| 759 | case HBMMENU_CALLBACK:
|
|---|
| 760 | case HBMMENU_MBAR_CLOSE_D:
|
|---|
| 761 | case HBMMENU_MBAR_MINIMIZE_D:
|
|---|
| 762 | case HBMMENU_POPUP_CLOSE:
|
|---|
| 763 | case HBMMENU_POPUP_RESTORE:
|
|---|
| 764 | case HBMMENU_POPUP_MAXIMIZE:
|
|---|
| 765 | case HBMMENU_POPUP_MINIMIZE:
|
|---|
| 766 | default:
|
|---|
| 767 | //FIXME("Magic 0x%08x not implemented\n", id);
|
|---|
| 768 | return 0;
|
|---|
| 769 | }
|
|---|
| 770 |
|
|---|
| 771 | }
|
|---|
| 772 |
|
|---|
| 773 | /***********************************************************************
|
|---|
| 774 | * MENU_CalcItemSize
|
|---|
| 775 | *
|
|---|
| 776 | * Calculate the size of the menu item and store it in lpitem->rect.
|
|---|
| 777 | */
|
|---|
| 778 | static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner,
|
|---|
| 779 | INT orgX, INT orgY, BOOL menuBar )
|
|---|
| 780 | {
|
|---|
| 781 | char *p;
|
|---|
| 782 |
|
|---|
| 783 | //TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY);
|
|---|
| 784 | //debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem,
|
|---|
| 785 | // (menuBar ? " (MenuBar)" : ""));
|
|---|
| 786 |
|
|---|
| 787 | SetRect( &lpitem->rect, orgX, orgY, orgX, orgY );
|
|---|
| 788 |
|
|---|
| 789 | if (lpitem->fType & MF_OWNERDRAW)
|
|---|
| 790 | {
|
|---|
| 791 | MEASUREITEMSTRUCT mis;
|
|---|
| 792 | mis.CtlType = ODT_MENU;
|
|---|
| 793 | mis.CtlID = 0;
|
|---|
| 794 | mis.itemID = lpitem->wID;
|
|---|
| 795 | mis.itemData = (DWORD)lpitem->dwItemData;
|
|---|
| 796 | mis.itemHeight = 0;
|
|---|
| 797 | mis.itemWidth = 0;
|
|---|
| 798 | SendMessageA( hwndOwner, WM_MEASUREITEM, 0, (LPARAM)&mis );
|
|---|
| 799 | lpitem->rect.bottom += mis.itemHeight;
|
|---|
| 800 | lpitem->rect.right += mis.itemWidth;
|
|---|
| 801 | //TRACE("id=%04x size=%dx%d\n",
|
|---|
| 802 | // lpitem->wID, mis.itemWidth, mis.itemHeight);
|
|---|
| 803 | return;
|
|---|
| 804 | }
|
|---|
| 805 |
|
|---|
| 806 | if (lpitem->fType & MF_SEPARATOR)
|
|---|
| 807 | {
|
|---|
| 808 | lpitem->rect.bottom += SEPARATOR_HEIGHT;
|
|---|
| 809 | return;
|
|---|
| 810 | }
|
|---|
| 811 |
|
|---|
| 812 | if (!menuBar)
|
|---|
| 813 | {
|
|---|
| 814 | lpitem->rect.right += 2 * check_bitmap_width;
|
|---|
| 815 | if (lpitem->fType & MF_POPUP)
|
|---|
| 816 | lpitem->rect.right += arrow_bitmap_width;
|
|---|
| 817 | }
|
|---|
| 818 |
|
|---|
| 819 | if (IS_BITMAP_ITEM(lpitem->fType))
|
|---|
| 820 | {
|
|---|
| 821 | BITMAP bm;
|
|---|
| 822 | HBITMAP resBmp = 0;
|
|---|
| 823 |
|
|---|
| 824 | /* Check if there is a magic menu item associated with this item */
|
|---|
| 825 | if((LOWORD((int)lpitem->text))<12)
|
|---|
| 826 | {
|
|---|
| 827 | resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fType & MF_HILITE),
|
|---|
| 828 | lpitem->dwItemData);
|
|---|
| 829 | }
|
|---|
| 830 | else
|
|---|
| 831 | resBmp = (HBITMAP)lpitem->text;
|
|---|
| 832 |
|
|---|
| 833 | if (GetObjectA(resBmp, sizeof(bm), &bm ))
|
|---|
| 834 | {
|
|---|
| 835 | lpitem->rect.right += bm.bmWidth;
|
|---|
| 836 | lpitem->rect.bottom += bm.bmHeight;
|
|---|
| 837 |
|
|---|
| 838 | }
|
|---|
| 839 | }
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 | /* If we get here, then it must be a text item */
|
|---|
| 843 | if (IS_STRING_ITEM( lpitem->fType ))
|
|---|
| 844 | { SIZE size;
|
|---|
| 845 |
|
|---|
| 846 | GetTextExtentPoint32A(hdc, lpitem->text, strlen(lpitem->text), &size);
|
|---|
| 847 |
|
|---|
| 848 | lpitem->rect.right += size.cx;
|
|---|
| 849 | lpitem->rect.bottom += MAX (size.cy, GetSystemMetrics(SM_CYMENU)-1);
|
|---|
| 850 | lpitem->xTab = 0;
|
|---|
| 851 |
|
|---|
| 852 | if (menuBar)
|
|---|
| 853 | {
|
|---|
| 854 | lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
|
|---|
| 855 | }
|
|---|
| 856 | else if ((p = strchr( lpitem->text, '\t' )) != NULL)
|
|---|
| 857 | {
|
|---|
| 858 | /* Item contains a tab (only meaningful in popup menus) */
|
|---|
| 859 | GetTextExtentPoint32A(hdc, lpitem->text, (int)(p - lpitem->text) , &size);
|
|---|
| 860 | lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE + size.cx;
|
|---|
| 861 | lpitem->rect.right += MENU_TAB_SPACE;
|
|---|
| 862 | }
|
|---|
| 863 | else
|
|---|
| 864 | {
|
|---|
| 865 | if (strchr( lpitem->text, '\b' ))
|
|---|
| 866 | lpitem->rect.right += MENU_TAB_SPACE;
|
|---|
| 867 | lpitem->xTab = lpitem->rect.right - check_bitmap_width
|
|---|
| 868 | - arrow_bitmap_width;
|
|---|
| 869 | }
|
|---|
| 870 | }
|
|---|
| 871 | //TRACE("(%d,%d)-(%d,%d)\n", lpitem->rect.left, lpitem->rect.top, lpitem->rect.right, lpitem->rect.bottom);
|
|---|
| 872 | }
|
|---|
| 873 |
|
|---|
| 874 |
|
|---|
| 875 | /***********************************************************************
|
|---|
| 876 | * MENU_PopupMenuCalcSize
|
|---|
| 877 | *
|
|---|
| 878 | * Calculate the size of a popup menu.
|
|---|
| 879 | */
|
|---|
| 880 | static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop, HWND hwndOwner )
|
|---|
| 881 | {
|
|---|
| 882 | MENUITEM *lpitem;
|
|---|
| 883 | HDC hdc;
|
|---|
| 884 | int start, i;
|
|---|
| 885 | int orgX, orgY, maxX, maxTab, maxTabWidth;
|
|---|
| 886 |
|
|---|
| 887 | lppop->Width = lppop->Height = 0;
|
|---|
| 888 | if (lppop->nItems == 0) return;
|
|---|
| 889 | hdc = GetDC( 0 );
|
|---|
| 890 |
|
|---|
| 891 | SelectObject( hdc, hMenuFont);
|
|---|
| 892 |
|
|---|
| 893 | start = 0;
|
|---|
| 894 | maxX = 2 ;
|
|---|
| 895 |
|
|---|
| 896 | while (start < lppop->nItems)
|
|---|
| 897 | {
|
|---|
| 898 | lpitem = &lppop->items[start];
|
|---|
| 899 | orgX = maxX;
|
|---|
| 900 | orgY = 2;
|
|---|
| 901 |
|
|---|
| 902 | maxTab = maxTabWidth = 0;
|
|---|
| 903 |
|
|---|
| 904 | /* Parse items until column break or end of menu */
|
|---|
| 905 | for (i = start; i < lppop->nItems; i++, lpitem++)
|
|---|
| 906 | {
|
|---|
| 907 | if ((i != start) &&
|
|---|
| 908 | (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
|
|---|
| 909 |
|
|---|
| 910 | MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
|
|---|
| 911 |
|
|---|
| 912 | if (lpitem->fType & MF_MENUBARBREAK) orgX++;
|
|---|
| 913 | maxX = MAX( maxX, lpitem->rect.right );
|
|---|
| 914 | orgY = lpitem->rect.bottom;
|
|---|
| 915 | if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
|
|---|
| 916 | {
|
|---|
| 917 | maxTab = MAX( maxTab, lpitem->xTab );
|
|---|
| 918 | maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab);
|
|---|
| 919 | }
|
|---|
| 920 | }
|
|---|
| 921 |
|
|---|
| 922 | /* Finish the column (set all items to the largest width found) */
|
|---|
| 923 | maxX = MAX( maxX, maxTab + maxTabWidth );
|
|---|
| 924 | for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
|
|---|
| 925 | {
|
|---|
| 926 | lpitem->rect.right = maxX;
|
|---|
| 927 | if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
|
|---|
| 928 | lpitem->xTab = maxTab;
|
|---|
| 929 |
|
|---|
| 930 | }
|
|---|
| 931 | lppop->Height = MAX( lppop->Height, orgY );
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | lppop->Width = maxX;
|
|---|
| 935 |
|
|---|
| 936 | /* space for 3d border */
|
|---|
| 937 | lppop->Height += 2;
|
|---|
| 938 | lppop->Width += 2;
|
|---|
| 939 |
|
|---|
| 940 | ReleaseDC( 0, hdc );
|
|---|
| 941 | }
|
|---|
| 942 |
|
|---|
| 943 |
|
|---|
| 944 | /***********************************************************************
|
|---|
| 945 | * MENU_MenuBarCalcSize
|
|---|
| 946 | *
|
|---|
| 947 | * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
|
|---|
| 948 | * height is off by 1 pixel which causes lengthy window relocations when
|
|---|
| 949 | * active document window is maximized/restored.
|
|---|
| 950 | *
|
|---|
| 951 | * Calculate the size of the menu bar.
|
|---|
| 952 | */
|
|---|
| 953 | static void MENU_MenuBarCalcSize( HDC hdc, LPRECT lprect,
|
|---|
| 954 | LPPOPUPMENU lppop, HWND hwndOwner )
|
|---|
| 955 | {
|
|---|
| 956 | MENUITEM *lpitem;
|
|---|
| 957 | int start, i, orgX, orgY, maxY, helpPos;
|
|---|
| 958 |
|
|---|
| 959 | if ((lprect == NULL) || (lppop == NULL)) return;
|
|---|
| 960 | if (lppop->nItems == 0) return;
|
|---|
| 961 | //TRACE("left=%d top=%d right=%d bottom=%d\n",
|
|---|
| 962 | // lprect->left, lprect->top, lprect->right, lprect->bottom);
|
|---|
| 963 | lppop->Width = lprect->right - lprect->left;
|
|---|
| 964 | lppop->Height = 0;
|
|---|
| 965 | maxY = lprect->top;
|
|---|
| 966 | start = 0;
|
|---|
| 967 | helpPos = -1;
|
|---|
| 968 | while (start < lppop->nItems)
|
|---|
| 969 | {
|
|---|
| 970 | lpitem = &lppop->items[start];
|
|---|
| 971 | orgX = lprect->left;
|
|---|
| 972 | orgY = maxY;
|
|---|
| 973 |
|
|---|
| 974 | /* Parse items until line break or end of menu */
|
|---|
| 975 | for (i = start; i < lppop->nItems; i++, lpitem++)
|
|---|
| 976 | {
|
|---|
| 977 | if ((helpPos == -1) && (lpitem->fType & MF_HELP)) helpPos = i;
|
|---|
| 978 | if ((i != start) &&
|
|---|
| 979 | (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
|
|---|
| 980 |
|
|---|
| 981 | //TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
|
|---|
| 982 | // orgX, orgY );
|
|---|
| 983 | //debug_print_menuitem (" item: ", lpitem, "");
|
|---|
| 984 | MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE );
|
|---|
| 985 |
|
|---|
| 986 | if (lpitem->rect.right > lprect->right)
|
|---|
| 987 | {
|
|---|
| 988 | if (i != start) break;
|
|---|
| 989 | else lpitem->rect.right = lprect->right;
|
|---|
| 990 | }
|
|---|
| 991 | maxY = MAX( maxY, lpitem->rect.bottom );
|
|---|
| 992 | orgX = lpitem->rect.right;
|
|---|
| 993 | }
|
|---|
| 994 |
|
|---|
| 995 | /* Finish the line (set all items to the largest height found) */
|
|---|
| 996 | while (start < i) lppop->items[start++].rect.bottom = maxY;
|
|---|
| 997 | }
|
|---|
| 998 |
|
|---|
| 999 | lprect->bottom = maxY;
|
|---|
| 1000 | lppop->Height = lprect->bottom - lprect->top;
|
|---|
| 1001 |
|
|---|
| 1002 | /* Flush right all magic items and items between the MF_HELP and */
|
|---|
| 1003 | /* the last item (if several lines, only move the last line) */
|
|---|
| 1004 | lpitem = &lppop->items[lppop->nItems-1];
|
|---|
| 1005 | orgY = lpitem->rect.top;
|
|---|
| 1006 | orgX = lprect->right;
|
|---|
| 1007 | for (i = lppop->nItems - 1; i >= helpPos; i--, lpitem--)
|
|---|
| 1008 | {
|
|---|
| 1009 | if ( !IS_BITMAP_ITEM(lpitem->fType) && ((helpPos ==-1) ? TRUE : (helpPos>i) ))
|
|---|
| 1010 | break; /* done */
|
|---|
| 1011 | if (lpitem->rect.top != orgY) break; /* Other line */
|
|---|
| 1012 | if (lpitem->rect.right >= orgX) break; /* Too far right already */
|
|---|
| 1013 | lpitem->rect.left += orgX - lpitem->rect.right;
|
|---|
| 1014 | lpitem->rect.right = orgX;
|
|---|
| 1015 | orgX = lpitem->rect.left;
|
|---|
| 1016 | }
|
|---|
| 1017 | }
|
|---|
| 1018 |
|
|---|
| 1019 | /***********************************************************************
|
|---|
| 1020 | * MENU_DrawMenuItem
|
|---|
| 1021 | *
|
|---|
| 1022 | * Draw a single menu item.
|
|---|
| 1023 | */
|
|---|
| 1024 | static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc, MENUITEM *lpitem,
|
|---|
| 1025 | UINT height, BOOL menuBar, UINT odaction )
|
|---|
| 1026 | {
|
|---|
| 1027 | RECT rect;
|
|---|
| 1028 |
|
|---|
| 1029 | //debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, "");
|
|---|
| 1030 |
|
|---|
| 1031 | if (lpitem->fType & MF_SYSMENU)
|
|---|
| 1032 | {
|
|---|
| 1033 | if( !IsIconic(hwnd) )
|
|---|
| 1034 | {
|
|---|
| 1035 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 1036 |
|
|---|
| 1037 | if (win32wnd) win32wnd->DrawSysButton(hdc,lpitem->fState & (MF_HILITE | MF_MOUSESELECT));
|
|---|
| 1038 | }
|
|---|
| 1039 |
|
|---|
| 1040 | return;
|
|---|
| 1041 | }
|
|---|
| 1042 |
|
|---|
| 1043 | if (lpitem->fType & MF_OWNERDRAW)
|
|---|
| 1044 | {
|
|---|
| 1045 | DRAWITEMSTRUCT dis;
|
|---|
| 1046 |
|
|---|
| 1047 | dis.CtlType = ODT_MENU;
|
|---|
| 1048 | dis.CtlID = 0;
|
|---|
| 1049 | dis.itemID = lpitem->wID;
|
|---|
| 1050 | dis.itemData = (DWORD)lpitem->dwItemData;
|
|---|
| 1051 | dis.itemState = 0;
|
|---|
| 1052 | if (lpitem->fState & MF_CHECKED) dis.itemState |= ODS_CHECKED;
|
|---|
| 1053 | if (lpitem->fState & MF_GRAYED) dis.itemState |= ODS_GRAYED;
|
|---|
| 1054 | if (lpitem->fState & MF_HILITE) dis.itemState |= ODS_SELECTED;
|
|---|
| 1055 | dis.itemAction = odaction; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */
|
|---|
| 1056 | dis.hwndItem = hmenu;
|
|---|
| 1057 | dis.hDC = hdc;
|
|---|
| 1058 | dis.rcItem = lpitem->rect;
|
|---|
| 1059 | //TRACE("Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
|
|---|
| 1060 | // "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner,
|
|---|
| 1061 | // dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
|
|---|
| 1062 | // dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right,
|
|---|
| 1063 | // dis.rcItem.bottom);
|
|---|
| 1064 | SendMessageA( hwndOwner, WM_DRAWITEM, 0, (LPARAM)&dis );
|
|---|
| 1065 | return;
|
|---|
| 1066 | }
|
|---|
| 1067 |
|
|---|
| 1068 | //TRACE("rect={%d,%d,%d,%d}\n", lpitem->rect.left, lpitem->rect.top,
|
|---|
| 1069 | // lpitem->rect.right,lpitem->rect.bottom);
|
|---|
| 1070 |
|
|---|
| 1071 | if (menuBar && (lpitem->fType & MF_SEPARATOR)) return;
|
|---|
| 1072 |
|
|---|
| 1073 | rect = lpitem->rect;
|
|---|
| 1074 |
|
|---|
| 1075 | if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)))
|
|---|
| 1076 | if (menuBar)
|
|---|
| 1077 | DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
|
|---|
| 1078 | else
|
|---|
| 1079 | FillRect( hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT) );
|
|---|
| 1080 | else {
|
|---|
| 1081 | //SvL: TODO: Bug in GDI32; draws black rectangle instead of menu color
|
|---|
| 1082 | /// for everything except the 1st menu item
|
|---|
| 1083 | RECT dummy = rect;
|
|---|
| 1084 | dummy.bottom = dummy.top+1;
|
|---|
| 1085 | dummy.right = dummy.right+1;
|
|---|
| 1086 | FillRect( hdc, &dummy, GetSysColorBrush(COLOR_HIGHLIGHT) );
|
|---|
| 1087 | FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) );
|
|---|
| 1088 | }
|
|---|
| 1089 |
|
|---|
| 1090 | SetBkMode( hdc, TRANSPARENT );
|
|---|
| 1091 |
|
|---|
| 1092 | /* vertical separator */
|
|---|
| 1093 | if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
|
|---|
| 1094 | {
|
|---|
| 1095 | RECT rc = rect;
|
|---|
| 1096 | rc.top = 3;
|
|---|
| 1097 | rc.bottom = height - 3;
|
|---|
| 1098 | DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT);
|
|---|
| 1099 | }
|
|---|
| 1100 |
|
|---|
| 1101 | /* horizontal separator */
|
|---|
| 1102 | if (lpitem->fType & MF_SEPARATOR)
|
|---|
| 1103 | {
|
|---|
| 1104 | RECT rc = rect;
|
|---|
| 1105 | rc.left++;
|
|---|
| 1106 | rc.right--;
|
|---|
| 1107 | rc.top += SEPARATOR_HEIGHT / 2;
|
|---|
| 1108 | DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
|
|---|
| 1109 | return;
|
|---|
| 1110 | }
|
|---|
| 1111 |
|
|---|
| 1112 | /* Setup colors */
|
|---|
| 1113 |
|
|---|
| 1114 | if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)) )
|
|---|
| 1115 | {
|
|---|
| 1116 | if (lpitem->fState & MF_GRAYED)
|
|---|
| 1117 | SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
|
|---|
| 1118 | else
|
|---|
| 1119 | SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
|
|---|
| 1120 | SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
|
|---|
| 1121 | }
|
|---|
| 1122 | else
|
|---|
| 1123 | {
|
|---|
| 1124 | if (lpitem->fState & MF_GRAYED)
|
|---|
| 1125 | SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
|
|---|
| 1126 | else
|
|---|
| 1127 | SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) );
|
|---|
| 1128 | SetBkColor( hdc, GetSysColor( COLOR_MENU ) );
|
|---|
| 1129 | }
|
|---|
| 1130 |
|
|---|
| 1131 | /* helper lines for debugging */
|
|---|
| 1132 | /* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
|
|---|
| 1133 | SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
|
|---|
| 1134 | MoveTo( hdc, rect.left, (rect.top + rect.bottom)/2,NULL);
|
|---|
| 1135 | LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
|
|---|
| 1136 | */
|
|---|
| 1137 |
|
|---|
| 1138 | if (!menuBar)
|
|---|
| 1139 | {
|
|---|
| 1140 | INT y = rect.top + rect.bottom;
|
|---|
| 1141 |
|
|---|
| 1142 | /* Draw the check mark
|
|---|
| 1143 | *
|
|---|
| 1144 | * FIXME:
|
|---|
| 1145 | * Custom checkmark bitmaps are monochrome but not always 1bpp.
|
|---|
| 1146 | */
|
|---|
| 1147 |
|
|---|
| 1148 | if (lpitem->fState & MF_CHECKED)
|
|---|
| 1149 | {
|
|---|
| 1150 | HBITMAP bm = lpitem->hCheckBit ? lpitem->hCheckBit :
|
|---|
| 1151 | ((lpitem->fType & MFT_RADIOCHECK) ? hStdRadioCheck : hStdCheck);
|
|---|
| 1152 | HDC hdcMem = CreateCompatibleDC( hdc );
|
|---|
| 1153 |
|
|---|
| 1154 | SelectObject( hdcMem, bm );
|
|---|
| 1155 | BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
|
|---|
| 1156 | check_bitmap_width, check_bitmap_height,
|
|---|
| 1157 | hdcMem, 0, 0, SRCCOPY );
|
|---|
| 1158 | DeleteDC( hdcMem );
|
|---|
| 1159 | }
|
|---|
| 1160 | else if (lpitem->hUnCheckBit)
|
|---|
| 1161 | {
|
|---|
| 1162 | HDC hdcMem = CreateCompatibleDC( hdc );
|
|---|
| 1163 |
|
|---|
| 1164 | SelectObject( hdcMem, lpitem->hUnCheckBit );
|
|---|
| 1165 | BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
|
|---|
| 1166 | check_bitmap_width, check_bitmap_height,
|
|---|
| 1167 | hdcMem, 0, 0, SRCCOPY );
|
|---|
| 1168 | DeleteDC( hdcMem );
|
|---|
| 1169 | }
|
|---|
| 1170 |
|
|---|
| 1171 | /* Draw the popup-menu arrow */
|
|---|
| 1172 | if (lpitem->fType & MF_POPUP)
|
|---|
| 1173 | {
|
|---|
| 1174 | HDC hdcMem = CreateCompatibleDC( hdc );
|
|---|
| 1175 |
|
|---|
| 1176 | SelectObject( hdcMem, hStdMnArrow );
|
|---|
| 1177 | BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
|
|---|
| 1178 | (y - arrow_bitmap_height) / 2,
|
|---|
| 1179 | arrow_bitmap_width, arrow_bitmap_height,
|
|---|
| 1180 | hdcMem, 0, 0, SRCCOPY );
|
|---|
| 1181 | DeleteDC( hdcMem );
|
|---|
| 1182 | }
|
|---|
| 1183 |
|
|---|
| 1184 | rect.left += check_bitmap_width;
|
|---|
| 1185 | rect.right -= arrow_bitmap_width;
|
|---|
| 1186 | }
|
|---|
| 1187 |
|
|---|
| 1188 | /* Draw the item text or bitmap */
|
|---|
| 1189 | if (IS_BITMAP_ITEM(lpitem->fType))
|
|---|
| 1190 | { int top;
|
|---|
| 1191 |
|
|---|
| 1192 | HBITMAP resBmp = 0;
|
|---|
| 1193 |
|
|---|
| 1194 | HDC hdcMem = CreateCompatibleDC( hdc );
|
|---|
| 1195 |
|
|---|
| 1196 | /*
|
|---|
| 1197 | * Check if there is a magic menu item associated with this item
|
|---|
| 1198 | * and load the appropriate bitmap
|
|---|
| 1199 | */
|
|---|
| 1200 | if((LOWORD((int)lpitem->text)) < 12)
|
|---|
| 1201 | {
|
|---|
| 1202 | resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fState & MF_HILITE),
|
|---|
| 1203 | lpitem->dwItemData);
|
|---|
| 1204 | }
|
|---|
| 1205 | else
|
|---|
| 1206 | resBmp = (HBITMAP)lpitem->text;
|
|---|
| 1207 |
|
|---|
| 1208 | if (resBmp)
|
|---|
| 1209 | {
|
|---|
| 1210 | BITMAP bm;
|
|---|
| 1211 | GetObjectA( resBmp, sizeof(bm), &bm );
|
|---|
| 1212 |
|
|---|
| 1213 | SelectObject(hdcMem,resBmp );
|
|---|
| 1214 |
|
|---|
| 1215 | /* handle fontsize > bitmap_height */
|
|---|
| 1216 | top = ((rect.bottom-rect.top)>bm.bmHeight) ?
|
|---|
| 1217 | rect.top+(rect.bottom-rect.top-bm.bmHeight)/2 : rect.top;
|
|---|
| 1218 |
|
|---|
| 1219 | BitBlt( hdc, rect.left, top, rect.right - rect.left,
|
|---|
| 1220 | rect.bottom - rect.top, hdcMem, 0, 0, SRCCOPY );
|
|---|
| 1221 | }
|
|---|
| 1222 | DeleteDC( hdcMem );
|
|---|
| 1223 |
|
|---|
| 1224 | return;
|
|---|
| 1225 |
|
|---|
| 1226 | }
|
|---|
| 1227 | /* No bitmap - process text if present */
|
|---|
| 1228 | else if (IS_STRING_ITEM(lpitem->fType))
|
|---|
| 1229 | {
|
|---|
| 1230 | register int i;
|
|---|
| 1231 | HFONT hfontOld = 0;
|
|---|
| 1232 |
|
|---|
| 1233 | UINT uFormat = (menuBar) ?
|
|---|
| 1234 | DT_CENTER | DT_VCENTER | DT_SINGLELINE :
|
|---|
| 1235 | DT_LEFT | DT_VCENTER | DT_SINGLELINE;
|
|---|
| 1236 |
|
|---|
| 1237 | if ( lpitem->fState & MFS_DEFAULT )
|
|---|
| 1238 | {
|
|---|
| 1239 | hfontOld = SelectObject( hdc, hMenuFontBold);
|
|---|
| 1240 | }
|
|---|
| 1241 |
|
|---|
| 1242 | if (menuBar)
|
|---|
| 1243 | {
|
|---|
| 1244 | rect.left += MENU_BAR_ITEMS_SPACE / 2;
|
|---|
| 1245 | rect.right -= MENU_BAR_ITEMS_SPACE / 2;
|
|---|
| 1246 | i = strlen( lpitem->text );
|
|---|
| 1247 | }
|
|---|
| 1248 | else
|
|---|
| 1249 | {
|
|---|
| 1250 | for (i = 0; lpitem->text[i]; i++)
|
|---|
| 1251 | if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b'))
|
|---|
| 1252 | break;
|
|---|
| 1253 | }
|
|---|
| 1254 |
|
|---|
| 1255 | if(lpitem->fState & MF_GRAYED)
|
|---|
| 1256 | {
|
|---|
| 1257 | if (!(lpitem->fState & MF_HILITE) )
|
|---|
| 1258 | {
|
|---|
| 1259 | ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
|
|---|
| 1260 | SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
|
|---|
| 1261 | DrawTextA( hdc, lpitem->text, i, &rect, uFormat );
|
|---|
| 1262 | --rect.left; --rect.top; --rect.right; --rect.bottom;
|
|---|
| 1263 | }
|
|---|
| 1264 | SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
|
|---|
| 1265 | }
|
|---|
| 1266 |
|
|---|
| 1267 | DrawTextA( hdc, lpitem->text, i, &rect, uFormat);
|
|---|
| 1268 |
|
|---|
| 1269 | /* paint the shortcut text */
|
|---|
| 1270 | if (lpitem->text[i]) /* There's a tab or flush-right char */
|
|---|
| 1271 | {
|
|---|
| 1272 | if (lpitem->text[i] == '\t')
|
|---|
| 1273 | {
|
|---|
| 1274 | rect.left = lpitem->xTab;
|
|---|
| 1275 | uFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
|
|---|
| 1276 | }
|
|---|
| 1277 | else
|
|---|
| 1278 | {
|
|---|
| 1279 | uFormat = DT_RIGHT | DT_VCENTER | DT_SINGLELINE;
|
|---|
| 1280 | }
|
|---|
| 1281 |
|
|---|
| 1282 | if(lpitem->fState & MF_GRAYED)
|
|---|
| 1283 | {
|
|---|
| 1284 | if (!(lpitem->fState & MF_HILITE) )
|
|---|
| 1285 | {
|
|---|
| 1286 | ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
|
|---|
| 1287 | SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
|
|---|
| 1288 | DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
|
|---|
| 1289 | --rect.left; --rect.top; --rect.right; --rect.bottom;
|
|---|
| 1290 | }
|
|---|
| 1291 | SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
|
|---|
| 1292 | }
|
|---|
| 1293 | DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
|
|---|
| 1294 | }
|
|---|
| 1295 |
|
|---|
| 1296 | if (hfontOld)
|
|---|
| 1297 | SelectObject (hdc, hfontOld);
|
|---|
| 1298 | }
|
|---|
| 1299 | }
|
|---|
| 1300 |
|
|---|
| 1301 |
|
|---|
| 1302 | /***********************************************************************
|
|---|
| 1303 | * MENU_DrawPopupMenu
|
|---|
| 1304 | *
|
|---|
| 1305 | * Paint a popup menu.
|
|---|
| 1306 | */
|
|---|
| 1307 | static void MENU_DrawPopupMenu( HWND hwnd, HDC hdc, HMENU hmenu )
|
|---|
| 1308 | {
|
|---|
| 1309 | HBRUSH hPrevBrush = 0;
|
|---|
| 1310 | RECT rect;
|
|---|
| 1311 |
|
|---|
| 1312 | //TRACE("wnd=0x%04x dc=0x%04x menu=0x%04x\n", hwnd, hdc, hmenu);
|
|---|
| 1313 |
|
|---|
| 1314 | GetClientRect( hwnd, &rect );
|
|---|
| 1315 |
|
|---|
| 1316 | if((hPrevBrush = SelectObject( hdc, GetSysColorBrush(COLOR_MENU) ))
|
|---|
| 1317 | && (SelectObject( hdc, hMenuFont)))
|
|---|
| 1318 | {
|
|---|
| 1319 | HPEN hPrevPen;
|
|---|
| 1320 |
|
|---|
| 1321 | Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
|
|---|
| 1322 |
|
|---|
| 1323 | hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) );
|
|---|
| 1324 | if( hPrevPen )
|
|---|
| 1325 | {
|
|---|
| 1326 | INT ropPrev, i;
|
|---|
| 1327 | POPUPMENU *menu;
|
|---|
| 1328 |
|
|---|
| 1329 | /* draw 3-d shade */
|
|---|
| 1330 | DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT);
|
|---|
| 1331 |
|
|---|
| 1332 | /* draw menu items */
|
|---|
| 1333 |
|
|---|
| 1334 | menu = (POPUPMENU*)hmenu;
|
|---|
| 1335 | if (menu && menu->nItems)
|
|---|
| 1336 | {
|
|---|
| 1337 | MENUITEM *item;
|
|---|
| 1338 | UINT u;
|
|---|
| 1339 |
|
|---|
| 1340 | for (u = menu->nItems, item = menu->items; u > 0; u--, item++)
|
|---|
| 1341 | MENU_DrawMenuItem( hwnd, hmenu, menu->hwndOwner, hdc, item,
|
|---|
| 1342 | menu->Height, FALSE, ODA_DRAWENTIRE );
|
|---|
| 1343 |
|
|---|
| 1344 | }
|
|---|
| 1345 | } else
|
|---|
| 1346 | {
|
|---|
| 1347 | SelectObject( hdc, hPrevBrush );
|
|---|
| 1348 | }
|
|---|
| 1349 | }
|
|---|
| 1350 | }
|
|---|
| 1351 |
|
|---|
| 1352 | /***********************************************************************
|
|---|
| 1353 | * MENU_DrawMenuBar
|
|---|
| 1354 | *
|
|---|
| 1355 | * Paint a menu bar. Returns the height of the menu bar.
|
|---|
| 1356 | * called from [windows/nonclient.c]
|
|---|
| 1357 | */
|
|---|
| 1358 | UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd,
|
|---|
| 1359 | BOOL suppress_draw)
|
|---|
| 1360 | {
|
|---|
| 1361 | LPPOPUPMENU lppop;
|
|---|
| 1362 | UINT i,retvalue;
|
|---|
| 1363 | HFONT hfontOld = 0;
|
|---|
| 1364 |
|
|---|
| 1365 | lppop = (LPPOPUPMENU)getMenu(hwnd);
|
|---|
| 1366 | if (lppop == NULL || lprect == NULL)
|
|---|
| 1367 | {
|
|---|
| 1368 | retvalue = GetSystemMetrics(SM_CYMENU);
|
|---|
| 1369 | goto END;
|
|---|
| 1370 | }
|
|---|
| 1371 |
|
|---|
| 1372 | //TRACE("(%04x, %p, %p)\n", hDC, lprect, lppop);
|
|---|
| 1373 |
|
|---|
| 1374 | hfontOld = SelectObject( hDC, hMenuFont);
|
|---|
| 1375 |
|
|---|
| 1376 | if (lppop->Height == 0)
|
|---|
| 1377 | MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd);
|
|---|
| 1378 |
|
|---|
| 1379 | lprect->bottom = lprect->top + lppop->Height;
|
|---|
| 1380 |
|
|---|
| 1381 | if (suppress_draw)
|
|---|
| 1382 | {
|
|---|
| 1383 | retvalue = lppop->Height;
|
|---|
| 1384 | goto END;
|
|---|
| 1385 | }
|
|---|
| 1386 |
|
|---|
| 1387 | FillRect(hDC, lprect, GetSysColorBrush(COLOR_MENU) );
|
|---|
| 1388 |
|
|---|
| 1389 | SelectObject( hDC, GetSysColorPen(COLOR_3DFACE));
|
|---|
| 1390 | MoveToEx( hDC, lprect->left, lprect->bottom,NULL);
|
|---|
| 1391 | LineTo( hDC, lprect->right, lprect->bottom );
|
|---|
| 1392 |
|
|---|
| 1393 | if (lppop->nItems == 0)
|
|---|
| 1394 | {
|
|---|
| 1395 | retvalue = GetSystemMetrics(SM_CYMENU);
|
|---|
| 1396 | goto END;
|
|---|
| 1397 | }
|
|---|
| 1398 |
|
|---|
| 1399 | for (i = 0; i < lppop->nItems; i++)
|
|---|
| 1400 | {
|
|---|
| 1401 | MENU_DrawMenuItem( hwnd,getMenu(hwnd), GetWindow(hwnd,GW_OWNER),
|
|---|
| 1402 | hDC, &lppop->items[i], lppop->Height, TRUE, ODA_DRAWENTIRE );
|
|---|
| 1403 | }
|
|---|
| 1404 | retvalue = lppop->Height;
|
|---|
| 1405 |
|
|---|
| 1406 | END:
|
|---|
| 1407 | if (hfontOld)
|
|---|
| 1408 | SelectObject (hDC, hfontOld);
|
|---|
| 1409 |
|
|---|
| 1410 | return retvalue;
|
|---|
| 1411 | }
|
|---|
| 1412 |
|
|---|
| 1413 | /***********************************************************************
|
|---|
| 1414 | * MENU_PatchResidentPopup
|
|---|
| 1415 | */
|
|---|
| 1416 | BOOL MENU_PatchResidentPopup( HQUEUE checkQueue, HWND checkWnd )
|
|---|
| 1417 | {
|
|---|
| 1418 | HWND pTPWnd = MENU_GetTopPopupWnd();
|
|---|
| 1419 | #if 0 //CB: todo
|
|---|
| 1420 | if( pTPWnd )
|
|---|
| 1421 | {
|
|---|
| 1422 | HTASK hTask = 0;
|
|---|
| 1423 |
|
|---|
| 1424 | //TRACE("patching resident popup: %04x %04x [%04x %04x]\n",
|
|---|
| 1425 | // checkQueue, checkWnd ? checkWnd->hwndSelf : 0, pTPWnd->hmemTaskQ,
|
|---|
| 1426 | // pTPWnd->owner ? pTPWnd->owner->hwndSelf : 0);
|
|---|
| 1427 |
|
|---|
| 1428 | switch( checkQueue )
|
|---|
| 1429 | {
|
|---|
| 1430 | case 0: /* checkWnd is the new popup owner */
|
|---|
| 1431 | if( checkWnd )
|
|---|
| 1432 | {
|
|---|
| 1433 | pTPWnd->owner = checkWnd;
|
|---|
| 1434 | if( pTPWnd->hmemTaskQ != checkWnd->hmemTaskQ )
|
|---|
| 1435 | hTask = QUEUE_GetQueueTask( checkWnd->hmemTaskQ );
|
|---|
| 1436 | }
|
|---|
| 1437 | break;
|
|---|
| 1438 |
|
|---|
| 1439 | case 0xFFFF: /* checkWnd is destroyed */
|
|---|
| 1440 | if( pTPWnd->owner == checkWnd )
|
|---|
| 1441 | pTPWnd->owner = NULL;
|
|---|
| 1442 | MENU_ReleaseTopPopupWnd();
|
|---|
| 1443 | return TRUE;
|
|---|
| 1444 |
|
|---|
| 1445 | default: /* checkQueue is exiting */
|
|---|
| 1446 | if( pTPWnd->hmemTaskQ == checkQueue )
|
|---|
| 1447 | {
|
|---|
| 1448 | hTask = QUEUE_GetQueueTask( pTPWnd->hmemTaskQ );
|
|---|
| 1449 | hTask = TASK_GetNextTask( hTask );
|
|---|
| 1450 | }
|
|---|
| 1451 | break;
|
|---|
| 1452 | }
|
|---|
| 1453 |
|
|---|
| 1454 | if( hTask )
|
|---|
| 1455 | {
|
|---|
| 1456 | TDB* task = (TDB*)GlobalLock( hTask );
|
|---|
| 1457 | if( task )
|
|---|
| 1458 | {
|
|---|
| 1459 | pTPWnd->hInstance = task->hInstance;
|
|---|
| 1460 | pTPWnd->hmemTaskQ = task->hQueue;
|
|---|
| 1461 | MENU_ReleaseTopPopupWnd();
|
|---|
| 1462 | return TRUE;
|
|---|
| 1463 | }
|
|---|
| 1464 | //else WARN("failed to patch resident popup.\n");
|
|---|
| 1465 | }
|
|---|
| 1466 | }
|
|---|
| 1467 | #endif
|
|---|
| 1468 | MENU_ReleaseTopPopupWnd();
|
|---|
| 1469 | return FALSE;
|
|---|
| 1470 | }
|
|---|
| 1471 |
|
|---|
| 1472 | /***********************************************************************
|
|---|
| 1473 | * MENU_ShowPopup
|
|---|
| 1474 | *
|
|---|
| 1475 | * Display a popup menu.
|
|---|
| 1476 | */
|
|---|
| 1477 | static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id,
|
|---|
| 1478 | INT x, INT y, INT xanchor, INT yanchor )
|
|---|
| 1479 | {
|
|---|
| 1480 | POPUPMENU *menu;
|
|---|
| 1481 |
|
|---|
| 1482 | //TRACE("owner=0x%04x hmenu=0x%04x id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n",
|
|---|
| 1483 | //hwndOwner, hmenu, id, x, y, xanchor, yanchor);
|
|---|
| 1484 |
|
|---|
| 1485 | if (!(menu = (POPUPMENU*)hmenu)) return FALSE;
|
|---|
| 1486 | if (menu->FocusedItem != NO_SELECTED_ITEM)
|
|---|
| 1487 | {
|
|---|
| 1488 | menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
|
|---|
| 1489 | menu->FocusedItem = NO_SELECTED_ITEM;
|
|---|
| 1490 | }
|
|---|
| 1491 |
|
|---|
| 1492 | /* store the owner for DrawItem*/
|
|---|
| 1493 | menu->hwndOwner = hwndOwner;
|
|---|
| 1494 |
|
|---|
| 1495 | if(IsWindow(hwndOwner))
|
|---|
| 1496 | {
|
|---|
| 1497 | UINT width, height;
|
|---|
| 1498 |
|
|---|
| 1499 | MENU_PopupMenuCalcSize( menu, hwndOwner );
|
|---|
| 1500 |
|
|---|
| 1501 | /* adjust popup menu pos so that it fits within the desktop */
|
|---|
| 1502 |
|
|---|
| 1503 | width = menu->Width + GetSystemMetrics(SM_CXBORDER);
|
|---|
| 1504 | height = menu->Height + GetSystemMetrics(SM_CYBORDER);
|
|---|
| 1505 |
|
|---|
| 1506 | if( x + width > GetSystemMetrics(SM_CXSCREEN ))
|
|---|
| 1507 | {
|
|---|
| 1508 | if( xanchor )
|
|---|
| 1509 | x -= width - xanchor;
|
|---|
| 1510 | if( x + width > GetSystemMetrics(SM_CXSCREEN))
|
|---|
| 1511 | x = GetSystemMetrics(SM_CXSCREEN) - width;
|
|---|
| 1512 | }
|
|---|
| 1513 | if( x < 0 ) x = 0;
|
|---|
| 1514 |
|
|---|
| 1515 | if( y + height > GetSystemMetrics(SM_CYSCREEN ))
|
|---|
| 1516 | {
|
|---|
| 1517 | if( yanchor )
|
|---|
| 1518 | y -= height + yanchor;
|
|---|
| 1519 | if( y + height > GetSystemMetrics(SM_CYSCREEN ))
|
|---|
| 1520 | y = GetSystemMetrics(SM_CYSCREEN) - height;
|
|---|
| 1521 | }
|
|---|
| 1522 | if( y < 0 ) y = 0;
|
|---|
| 1523 |
|
|---|
| 1524 | /* NOTE: In Windows, top menu popup is not owned. */
|
|---|
| 1525 | if (!pTopPopupWnd) /* create top level popup menu window */
|
|---|
| 1526 | {
|
|---|
| 1527 | assert( uSubPWndLevel == 0 );
|
|---|
| 1528 |
|
|---|
| 1529 | pTopPopupWnd = CreateWindowA( POPUPMENUCLASSNAME, NULL,
|
|---|
| 1530 | WS_POPUP, x, y, width, height,
|
|---|
| 1531 | hwndOwner, 0, GetWindowLongA(hwndOwner,GWL_HINSTANCE),
|
|---|
| 1532 | (LPVOID)hmenu );
|
|---|
| 1533 | if (!pTopPopupWnd)
|
|---|
| 1534 | {
|
|---|
| 1535 | return FALSE;
|
|---|
| 1536 | }
|
|---|
| 1537 | menu->hWnd = pTopPopupWnd;
|
|---|
| 1538 | MENU_ReleaseTopPopupWnd();
|
|---|
| 1539 | }
|
|---|
| 1540 | else
|
|---|
| 1541 | if( uSubPWndLevel )
|
|---|
| 1542 | {
|
|---|
| 1543 | /* create a new window for the submenu */
|
|---|
| 1544 |
|
|---|
| 1545 | menu->hWnd = CreateWindowA( POPUPMENUCLASSNAME, NULL,
|
|---|
| 1546 | WS_POPUP, x, y, width, height,
|
|---|
| 1547 | hwndOwner, 0, GetWindowLongA(hwndOwner,GWL_HINSTANCE),
|
|---|
| 1548 | (LPVOID)hmenu );
|
|---|
| 1549 | if( !menu->hWnd )
|
|---|
| 1550 | {
|
|---|
| 1551 | return FALSE;
|
|---|
| 1552 | }
|
|---|
| 1553 | }
|
|---|
| 1554 | else /* top level popup menu window already exists */
|
|---|
| 1555 | {
|
|---|
| 1556 | HWND pTPWnd = MENU_GetTopPopupWnd();
|
|---|
| 1557 | menu->hWnd = pTPWnd;
|
|---|
| 1558 |
|
|---|
| 1559 | MENU_PatchResidentPopup( 0, hwndOwner );
|
|---|
| 1560 | SendMessageA( pTPWnd, MM_SETMENUHANDLE, (WPARAM)hmenu, 0L);
|
|---|
| 1561 |
|
|---|
| 1562 | /* adjust its size */
|
|---|
| 1563 |
|
|---|
| 1564 | SetWindowPos( menu->hWnd, 0, x, y, width, height,
|
|---|
| 1565 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
|
|---|
| 1566 | MENU_ReleaseTopPopupWnd();
|
|---|
| 1567 | }
|
|---|
| 1568 |
|
|---|
| 1569 | uSubPWndLevel++; /* menu level counter */
|
|---|
| 1570 |
|
|---|
| 1571 | /* Display the window */
|
|---|
| 1572 |
|
|---|
| 1573 | SetWindowPos( menu->hWnd, HWND_TOP, 0, 0, 0, 0,
|
|---|
| 1574 | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
|
|---|
| 1575 | UpdateWindow( menu->hWnd );
|
|---|
| 1576 | return TRUE;
|
|---|
| 1577 | }
|
|---|
| 1578 | return FALSE;
|
|---|
| 1579 | }
|
|---|
| 1580 |
|
|---|
| 1581 |
|
|---|
| 1582 | /***********************************************************************
|
|---|
| 1583 | * MENU_SelectItem
|
|---|
| 1584 | */
|
|---|
| 1585 | static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
|
|---|
| 1586 | BOOL sendMenuSelect, HMENU topmenu )
|
|---|
| 1587 | {
|
|---|
| 1588 | LPPOPUPMENU lppop;
|
|---|
| 1589 | HDC hdc;
|
|---|
| 1590 |
|
|---|
| 1591 | //TRACE("owner=0x%04x menu=0x%04x index=0x%04x select=0x%04x\n", hwndOwner, hmenu, wIndex, sendMenuSelect);
|
|---|
| 1592 |
|
|---|
| 1593 | lppop = (POPUPMENU*)hmenu;
|
|---|
| 1594 | if (!lppop->nItems) return;
|
|---|
| 1595 |
|
|---|
| 1596 | if (lppop->FocusedItem == wIndex) return;
|
|---|
| 1597 | if (lppop->wFlags & MF_POPUP) hdc = GetDC( lppop->hWnd );
|
|---|
| 1598 | else hdc = GetDCEx( lppop->hWnd, 0, DCX_CACHE | DCX_WINDOW);
|
|---|
| 1599 |
|
|---|
| 1600 | SelectObject( hdc, hMenuFont);
|
|---|
| 1601 |
|
|---|
| 1602 | /* Clear previous highlighted item */
|
|---|
| 1603 | if (lppop->FocusedItem != NO_SELECTED_ITEM)
|
|---|
| 1604 | {
|
|---|
| 1605 | lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
|
|---|
| 1606 | MENU_DrawMenuItem(lppop->hWnd, hmenu, hwndOwner, hdc,&lppop->items[lppop->FocusedItem],
|
|---|
| 1607 | lppop->Height, !(lppop->wFlags & MF_POPUP),
|
|---|
| 1608 | ODA_SELECT );
|
|---|
| 1609 | }
|
|---|
| 1610 |
|
|---|
| 1611 | /* Highlight new item (if any) */
|
|---|
| 1612 | lppop->FocusedItem = wIndex;
|
|---|
| 1613 | if (lppop->FocusedItem != NO_SELECTED_ITEM)
|
|---|
| 1614 | {
|
|---|
| 1615 | if(!(lppop->items[wIndex].fType & MF_SEPARATOR)) {
|
|---|
| 1616 | lppop->items[wIndex].fState |= MF_HILITE;
|
|---|
| 1617 | MENU_DrawMenuItem( lppop->hWnd, hmenu, hwndOwner, hdc,
|
|---|
| 1618 | &lppop->items[wIndex], lppop->Height,
|
|---|
| 1619 | !(lppop->wFlags & MF_POPUP), ODA_SELECT );
|
|---|
| 1620 | }
|
|---|
| 1621 | if (sendMenuSelect)
|
|---|
| 1622 | {
|
|---|
| 1623 | MENUITEM *ip = &lppop->items[lppop->FocusedItem];
|
|---|
| 1624 | SendMessageA( hwndOwner, WM_MENUSELECT,
|
|---|
| 1625 | MAKELONG(ip->fType & MF_POPUP ? wIndex: ip->wID,
|
|---|
| 1626 | ip->fType | ip->fState | MF_MOUSESELECT |
|
|---|
| 1627 | (lppop->wFlags & MF_SYSMENU)), hmenu);
|
|---|
| 1628 | }
|
|---|
| 1629 | }
|
|---|
| 1630 | else if (sendMenuSelect) {
|
|---|
| 1631 | if(topmenu){
|
|---|
| 1632 | int pos;
|
|---|
| 1633 | if((pos=MENU_FindSubMenu(&topmenu, hmenu))!=NO_SELECTED_ITEM){
|
|---|
| 1634 | POPUPMENU *ptm = (POPUPMENU*)topmenu;
|
|---|
| 1635 | MENUITEM *ip = &ptm->items[pos];
|
|---|
| 1636 | SendMessageA( hwndOwner, WM_MENUSELECT, MAKELONG(pos,
|
|---|
| 1637 | ip->fType | ip->fState | MF_MOUSESELECT |
|
|---|
| 1638 | (ptm->wFlags & MF_SYSMENU)), topmenu);
|
|---|
| 1639 | }
|
|---|
| 1640 | }
|
|---|
| 1641 | }
|
|---|
| 1642 | ReleaseDC( lppop->hWnd, hdc );
|
|---|
| 1643 | }
|
|---|
| 1644 |
|
|---|
| 1645 |
|
|---|
| 1646 | /***********************************************************************
|
|---|
| 1647 | * MENU_MoveSelection
|
|---|
| 1648 | *
|
|---|
| 1649 | * Moves currently selected item according to the offset parameter.
|
|---|
| 1650 | * If there is no selection then it should select the last item if
|
|---|
| 1651 | * offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
|
|---|
| 1652 | */
|
|---|
| 1653 | static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
|
|---|
| 1654 | {
|
|---|
| 1655 | INT i;
|
|---|
| 1656 | POPUPMENU *menu;
|
|---|
| 1657 |
|
|---|
| 1658 | //TRACE("hwnd=0x%04x hmenu=0x%04x off=0x%04x\n", hwndOwner, hmenu, offset);
|
|---|
| 1659 |
|
|---|
| 1660 | menu = (POPUPMENU*)hmenu;
|
|---|
| 1661 | if (!menu->items) return;
|
|---|
| 1662 |
|
|---|
| 1663 | if ( menu->FocusedItem != NO_SELECTED_ITEM )
|
|---|
| 1664 | {
|
|---|
| 1665 | if( menu->nItems == 1 ) return; else
|
|---|
| 1666 | for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems
|
|---|
| 1667 | ; i += offset)
|
|---|
| 1668 | if (!(menu->items[i].fType & MF_SEPARATOR))
|
|---|
| 1669 | {
|
|---|
| 1670 | MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
|
|---|
| 1671 | return;
|
|---|
| 1672 | }
|
|---|
| 1673 | }
|
|---|
| 1674 |
|
|---|
| 1675 | for ( i = (offset > 0) ? 0 : menu->nItems - 1;
|
|---|
| 1676 | i >= 0 && i < menu->nItems ; i += offset)
|
|---|
| 1677 | if (!(menu->items[i].fType & MF_SEPARATOR))
|
|---|
| 1678 | {
|
|---|
| 1679 | MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
|
|---|
| 1680 | return;
|
|---|
| 1681 | }
|
|---|
| 1682 | }
|
|---|
| 1683 |
|
|---|
| 1684 |
|
|---|
| 1685 | /**********************************************************************
|
|---|
| 1686 | * MENU_SetItemData
|
|---|
| 1687 | *
|
|---|
| 1688 | * Set an item flags, id and text ptr. Called by InsertMenu() and
|
|---|
| 1689 | * ModifyMenu().
|
|---|
| 1690 | */
|
|---|
| 1691 | static BOOL MENU_SetItemData( MENUITEM *item, UINT flags, UINT id,
|
|---|
| 1692 | LPCSTR str )
|
|---|
| 1693 | {
|
|---|
| 1694 | LPSTR prevText = IS_STRING_ITEM(item->fType) ? item->text : NULL;
|
|---|
| 1695 |
|
|---|
| 1696 | //debug_print_menuitem("MENU_SetItemData from: ", item, "");
|
|---|
| 1697 |
|
|---|
| 1698 | if (IS_STRING_ITEM(flags))
|
|---|
| 1699 | {
|
|---|
| 1700 | if (!str || !*str)
|
|---|
| 1701 | {
|
|---|
| 1702 | flags |= MF_SEPARATOR;
|
|---|
| 1703 | item->text = NULL;
|
|---|
| 1704 | }
|
|---|
| 1705 | else
|
|---|
| 1706 | {
|
|---|
| 1707 | LPSTR text;
|
|---|
| 1708 | /* Item beginning with a backspace is a help item */
|
|---|
| 1709 | if (*str == '\b')
|
|---|
| 1710 | {
|
|---|
| 1711 | flags |= MF_HELP;
|
|---|
| 1712 | str++;
|
|---|
| 1713 | }
|
|---|
| 1714 | if (!(text = HEAP_strdupA(GetProcessHeap(), 0, str ))) return FALSE;
|
|---|
| 1715 | item->text = text;
|
|---|
| 1716 | }
|
|---|
| 1717 | }
|
|---|
| 1718 | else if (IS_BITMAP_ITEM(flags))
|
|---|
| 1719 | item->text = (LPSTR)(HBITMAP)LOWORD(str);
|
|---|
| 1720 | else item->text = NULL;
|
|---|
| 1721 |
|
|---|
| 1722 | if (flags & MF_OWNERDRAW)
|
|---|
| 1723 | item->dwItemData = (DWORD)str;
|
|---|
| 1724 | else
|
|---|
| 1725 | item->dwItemData = 0;
|
|---|
| 1726 |
|
|---|
| 1727 | if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
|
|---|
| 1728 | DestroyMenu( item->hSubMenu ); /* ModifyMenu() spec */
|
|---|
| 1729 |
|
|---|
| 1730 | if (flags & MF_POPUP)
|
|---|
| 1731 | {
|
|---|
| 1732 | POPUPMENU *menu = (POPUPMENU*)(UINT)id;
|
|---|
| 1733 | if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP;
|
|---|
| 1734 | else
|
|---|
| 1735 | {
|
|---|
| 1736 | item->wID = 0;
|
|---|
| 1737 | item->hSubMenu = 0;
|
|---|
| 1738 | item->fType = 0;
|
|---|
| 1739 | item->fState = 0;
|
|---|
| 1740 | return FALSE;
|
|---|
| 1741 | }
|
|---|
| 1742 | }
|
|---|
| 1743 |
|
|---|
| 1744 | item->wID = id;
|
|---|
| 1745 | if (flags & MF_POPUP)
|
|---|
| 1746 | item->hSubMenu = id;
|
|---|
| 1747 |
|
|---|
| 1748 | if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) )
|
|---|
| 1749 | flags |= MF_POPUP; /* keep popup */
|
|---|
| 1750 |
|
|---|
| 1751 | item->fType = flags & TYPE_MASK;
|
|---|
| 1752 | item->fState = (flags & STATE_MASK) &
|
|---|
| 1753 | ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
|
|---|
| 1754 |
|
|---|
| 1755 |
|
|---|
| 1756 | /* Don't call SetRectEmpty here! */
|
|---|
| 1757 |
|
|---|
| 1758 |
|
|---|
| 1759 | if (prevText) HeapFree(GetProcessHeap(), 0, prevText );
|
|---|
| 1760 |
|
|---|
| 1761 | //debug_print_menuitem("MENU_SetItemData to : ", item, "");
|
|---|
| 1762 | return TRUE;
|
|---|
| 1763 | }
|
|---|
| 1764 |
|
|---|
| 1765 |
|
|---|
| 1766 | /**********************************************************************
|
|---|
| 1767 | * MENU_InsertItem
|
|---|
| 1768 | *
|
|---|
| 1769 | * Insert a new item into a menu.
|
|---|
| 1770 | */
|
|---|
| 1771 | static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
|
|---|
| 1772 | {
|
|---|
| 1773 | MENUITEM *newItems;
|
|---|
| 1774 | POPUPMENU *menu;
|
|---|
| 1775 |
|
|---|
| 1776 | if (!(menu = (POPUPMENU*)hMenu))
|
|---|
| 1777 | {
|
|---|
| 1778 | //WARN("%04x not a menu handle\n",
|
|---|
| 1779 | // hMenu );
|
|---|
| 1780 | return NULL;
|
|---|
| 1781 | }
|
|---|
| 1782 |
|
|---|
| 1783 | /* Find where to insert new item */
|
|---|
| 1784 |
|
|---|
| 1785 | if ((pos==(UINT)-1) || ((flags & MF_BYPOSITION) && (pos == menu->nItems)))
|
|---|
| 1786 | {
|
|---|
| 1787 | /* Special case: append to menu */
|
|---|
| 1788 | /* Some programs specify the menu length to do that */
|
|---|
| 1789 | pos = menu->nItems;
|
|---|
| 1790 | }
|
|---|
| 1791 | else
|
|---|
| 1792 | {
|
|---|
| 1793 | if (!MENU_FindItem( &hMenu, &pos, flags ))
|
|---|
| 1794 | {
|
|---|
| 1795 | //WARN("item %x not found\n",
|
|---|
| 1796 | // pos );
|
|---|
| 1797 | return NULL;
|
|---|
| 1798 | }
|
|---|
| 1799 | if (!(menu = (LPPOPUPMENU)hMenu))
|
|---|
| 1800 | {
|
|---|
| 1801 | //WARN("%04x not a menu handle\n",
|
|---|
| 1802 | // hMenu);
|
|---|
| 1803 | return NULL;
|
|---|
| 1804 | }
|
|---|
| 1805 | }
|
|---|
| 1806 |
|
|---|
| 1807 | /* Create new items array */
|
|---|
| 1808 |
|
|---|
| 1809 | newItems = (MENUITEM*)HeapAlloc(GetProcessHeap(), 0, sizeof(MENUITEM) * (menu->nItems+1) );
|
|---|
| 1810 | if (!newItems)
|
|---|
| 1811 | {
|
|---|
| 1812 | //WARN("allocation failed\n" );
|
|---|
| 1813 | return NULL;
|
|---|
| 1814 | }
|
|---|
| 1815 | if (menu->nItems > 0)
|
|---|
| 1816 | {
|
|---|
| 1817 | /* Copy the old array into the new */
|
|---|
| 1818 | if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
|
|---|
| 1819 | if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
|
|---|
| 1820 | (menu->nItems-pos)*sizeof(MENUITEM) );
|
|---|
| 1821 | HeapFree(GetProcessHeap(), 0, menu->items );
|
|---|
| 1822 | }
|
|---|
| 1823 | menu->items = newItems;
|
|---|
| 1824 | menu->nItems++;
|
|---|
| 1825 | memset( &newItems[pos], 0, sizeof(*newItems) );
|
|---|
| 1826 | menu->Height = 0; /* force size recalculate */
|
|---|
| 1827 | return &newItems[pos];
|
|---|
| 1828 | }
|
|---|
| 1829 |
|
|---|
| 1830 |
|
|---|
| 1831 | /**********************************************************************
|
|---|
| 1832 | * MENU_ParseResource
|
|---|
| 1833 | *
|
|---|
| 1834 | * Parse a standard menu resource and add items to the menu.
|
|---|
| 1835 | * Return a pointer to the end of the resource.
|
|---|
| 1836 | */
|
|---|
| 1837 | static LPCSTR MENU_ParseResource( LPCSTR res, HMENU hMenu, BOOL unicode )
|
|---|
| 1838 | {
|
|---|
| 1839 | WORD flags, id = 0;
|
|---|
| 1840 | LPCSTR str;
|
|---|
| 1841 |
|
|---|
| 1842 | do
|
|---|
| 1843 | {
|
|---|
| 1844 | flags = GET_WORD(res);
|
|---|
| 1845 | res += sizeof(WORD);
|
|---|
| 1846 | if (!(flags & MF_POPUP))
|
|---|
| 1847 | {
|
|---|
| 1848 | id = GET_WORD(res);
|
|---|
| 1849 | res += sizeof(WORD);
|
|---|
| 1850 | }
|
|---|
| 1851 | //if (!IS_STRING_ITEM(flags))
|
|---|
| 1852 | // ERR("not a string item %04x\n", flags );
|
|---|
| 1853 | str = res;
|
|---|
| 1854 | if (!unicode) res += strlen(str) + 1;
|
|---|
| 1855 | else res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
|
|---|
| 1856 | if (flags & MF_POPUP)
|
|---|
| 1857 | {
|
|---|
| 1858 | HMENU hSubMenu = CreatePopupMenu();
|
|---|
| 1859 | if (!hSubMenu) return NULL;
|
|---|
| 1860 | if (!(res = MENU_ParseResource( res, hSubMenu, unicode )))
|
|---|
| 1861 | return NULL;
|
|---|
| 1862 | if (!unicode) AppendMenuA( hMenu, flags, (UINT)hSubMenu, str );
|
|---|
| 1863 | else AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str );
|
|---|
| 1864 | }
|
|---|
| 1865 | else /* Not a popup */
|
|---|
| 1866 | {
|
|---|
| 1867 | if (!unicode) AppendMenuA( hMenu, flags, id, *str ? str : NULL );
|
|---|
| 1868 | else AppendMenuW( hMenu, flags, id,
|
|---|
| 1869 | *(LPCWSTR)str ? (LPCWSTR)str : NULL );
|
|---|
| 1870 | }
|
|---|
| 1871 | } while (!(flags & MF_END));
|
|---|
| 1872 | return res;
|
|---|
| 1873 | }
|
|---|
| 1874 |
|
|---|
| 1875 |
|
|---|
| 1876 | /**********************************************************************
|
|---|
| 1877 | * MENUEX_ParseResource
|
|---|
| 1878 | *
|
|---|
| 1879 | * Parse an extended menu resource and add items to the menu.
|
|---|
| 1880 | * Return a pointer to the end of the resource.
|
|---|
| 1881 | */
|
|---|
| 1882 | static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU hMenu)
|
|---|
| 1883 | {
|
|---|
| 1884 | WORD resinfo;
|
|---|
| 1885 | do {
|
|---|
| 1886 | MENUITEMINFOW mii;
|
|---|
| 1887 |
|
|---|
| 1888 | mii.cbSize = sizeof(mii);
|
|---|
| 1889 | mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
|
|---|
| 1890 | mii.fType = GET_DWORD(res);
|
|---|
| 1891 | res += sizeof(DWORD);
|
|---|
| 1892 | mii.fState = GET_DWORD(res);
|
|---|
| 1893 | res += sizeof(DWORD);
|
|---|
| 1894 | mii.wID = GET_DWORD(res);
|
|---|
| 1895 | res += sizeof(DWORD);
|
|---|
| 1896 | resinfo = GET_WORD(res);
|
|---|
| 1897 | res += sizeof(WORD);
|
|---|
| 1898 | /* Align the text on a word boundary. */
|
|---|
| 1899 | res += (~((int)res - 1)) & 1;
|
|---|
| 1900 | mii.dwTypeData = (LPWSTR) res;
|
|---|
| 1901 | res += (1 + lstrlenW(mii.dwTypeData)) * sizeof(WCHAR);
|
|---|
| 1902 | /* Align the following fields on a dword boundary. */
|
|---|
| 1903 | res += (~((int)res - 1)) & 3;
|
|---|
| 1904 |
|
|---|
| 1905 | /* FIXME: This is inefficient and cannot be optimised away by gcc. */
|
|---|
| 1906 | {
|
|---|
| 1907 | LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
|
|---|
| 1908 | 0, mii.dwTypeData);
|
|---|
| 1909 | //TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
|
|---|
| 1910 | // mii.fType, mii.fState, mii.wID, resinfo, newstr);
|
|---|
| 1911 | HeapFree( GetProcessHeap(), 0, newstr );
|
|---|
| 1912 | }
|
|---|
| 1913 |
|
|---|
| 1914 | if (resinfo & 1) { /* Pop-up? */
|
|---|
| 1915 | /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
|
|---|
| 1916 | res += sizeof(DWORD);
|
|---|
| 1917 | mii.hSubMenu = CreatePopupMenu();
|
|---|
| 1918 | if (!mii.hSubMenu)
|
|---|
| 1919 | return NULL;
|
|---|
| 1920 | if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
|
|---|
| 1921 | DestroyMenu(mii.hSubMenu);
|
|---|
| 1922 | return NULL;
|
|---|
| 1923 | }
|
|---|
| 1924 | mii.fMask |= MIIM_SUBMENU;
|
|---|
| 1925 | mii.fType |= MF_POPUP;
|
|---|
| 1926 | }
|
|---|
| 1927 | InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
|
|---|
| 1928 | } while (!(resinfo & MF_END));
|
|---|
| 1929 | return res;
|
|---|
| 1930 | }
|
|---|
| 1931 |
|
|---|
| 1932 |
|
|---|
| 1933 | /***********************************************************************
|
|---|
| 1934 | * MENU_GetSubPopup
|
|---|
| 1935 | *
|
|---|
| 1936 | * Return the handle of the selected sub-popup menu (if any).
|
|---|
| 1937 | */
|
|---|
| 1938 | static HMENU MENU_GetSubPopup( HMENU hmenu )
|
|---|
| 1939 | {
|
|---|
| 1940 | POPUPMENU *menu;
|
|---|
| 1941 | MENUITEM *item;
|
|---|
| 1942 |
|
|---|
| 1943 | menu = (POPUPMENU*)hmenu;
|
|---|
| 1944 |
|
|---|
| 1945 | if (menu->FocusedItem == NO_SELECTED_ITEM) return 0;
|
|---|
| 1946 |
|
|---|
| 1947 | item = &menu->items[menu->FocusedItem];
|
|---|
| 1948 | if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT))
|
|---|
| 1949 | return item->hSubMenu;
|
|---|
| 1950 | return 0;
|
|---|
| 1951 | }
|
|---|
| 1952 |
|
|---|
| 1953 |
|
|---|
| 1954 | /***********************************************************************
|
|---|
| 1955 | * MENU_HideSubPopups
|
|---|
| 1956 | *
|
|---|
| 1957 | * Hide the sub-popup menus of this menu.
|
|---|
| 1958 | */
|
|---|
| 1959 | static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu,
|
|---|
| 1960 | BOOL sendMenuSelect )
|
|---|
| 1961 | {
|
|---|
| 1962 | POPUPMENU *menu = (POPUPMENU*)hmenu;
|
|---|
| 1963 |
|
|---|
| 1964 | //TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, sendMenuSelect);
|
|---|
| 1965 |
|
|---|
| 1966 | if (menu && uSubPWndLevel)
|
|---|
| 1967 | {
|
|---|
| 1968 | HMENU hsubmenu;
|
|---|
| 1969 | POPUPMENU *submenu;
|
|---|
| 1970 | MENUITEM *item;
|
|---|
| 1971 |
|
|---|
| 1972 | if (menu->FocusedItem != NO_SELECTED_ITEM)
|
|---|
| 1973 | {
|
|---|
| 1974 | item = &menu->items[menu->FocusedItem];
|
|---|
| 1975 | if (!(item->fType & MF_POPUP) ||
|
|---|
| 1976 | !(item->fState & MF_MOUSESELECT)) return;
|
|---|
| 1977 | item->fState &= ~MF_MOUSESELECT;
|
|---|
| 1978 | hsubmenu = item->hSubMenu;
|
|---|
| 1979 | } else return;
|
|---|
| 1980 |
|
|---|
| 1981 | submenu = (POPUPMENU*)hsubmenu;
|
|---|
| 1982 | MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
|
|---|
| 1983 | MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect, 0 );
|
|---|
| 1984 |
|
|---|
| 1985 | if (submenu->hWnd == MENU_GetTopPopupWnd() )
|
|---|
| 1986 | {
|
|---|
| 1987 | ShowWindow( submenu->hWnd, SW_HIDE );
|
|---|
| 1988 | uSubPWndLevel = 0;
|
|---|
| 1989 | }
|
|---|
| 1990 | else
|
|---|
| 1991 | {
|
|---|
| 1992 | DestroyWindow( submenu->hWnd );
|
|---|
| 1993 | submenu->hWnd = 0;
|
|---|
| 1994 | }
|
|---|
| 1995 | MENU_ReleaseTopPopupWnd();
|
|---|
| 1996 | }
|
|---|
| 1997 | }
|
|---|
| 1998 |
|
|---|
| 1999 |
|
|---|
| 2000 | /***********************************************************************
|
|---|
| 2001 | * MENU_ShowSubPopup
|
|---|
| 2002 | *
|
|---|
| 2003 | * Display the sub-menu of the selected item of this menu.
|
|---|
| 2004 | * Return the handle of the submenu, or hmenu if no submenu to display.
|
|---|
| 2005 | */
|
|---|
| 2006 | static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu,
|
|---|
| 2007 | BOOL selectFirst, UINT wFlags )
|
|---|
| 2008 | {
|
|---|
| 2009 | RECT rect;
|
|---|
| 2010 | POPUPMENU *menu;
|
|---|
| 2011 | MENUITEM *item;
|
|---|
| 2012 | HDC hdc;
|
|---|
| 2013 |
|
|---|
| 2014 | //TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, selectFirst);
|
|---|
| 2015 |
|
|---|
| 2016 | if (!(menu = (POPUPMENU*)hmenu)) return hmenu;
|
|---|
| 2017 |
|
|---|
| 2018 | if (menu->FocusedItem == NO_SELECTED_ITEM)
|
|---|
| 2019 | {
|
|---|
| 2020 | return hmenu;
|
|---|
| 2021 | }
|
|---|
| 2022 |
|
|---|
| 2023 | item = &menu->items[menu->FocusedItem];
|
|---|
| 2024 | if (!(item->fType & MF_POPUP) ||
|
|---|
| 2025 | (item->fState & (MF_GRAYED | MF_DISABLED)))
|
|---|
| 2026 | {
|
|---|
| 2027 | return hmenu;
|
|---|
| 2028 | }
|
|---|
| 2029 |
|
|---|
| 2030 | /* message must be send before using item,
|
|---|
| 2031 | because nearly everything may by changed by the application ! */
|
|---|
| 2032 |
|
|---|
| 2033 | /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
|
|---|
| 2034 | if (!(wFlags & TPM_NONOTIFY))
|
|---|
| 2035 | SendMessageA( hwndOwner, WM_INITMENUPOPUP, item->hSubMenu,
|
|---|
| 2036 | MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
|
|---|
| 2037 |
|
|---|
| 2038 | item = &menu->items[menu->FocusedItem];
|
|---|
| 2039 | rect = item->rect;
|
|---|
| 2040 |
|
|---|
| 2041 | /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
|
|---|
| 2042 | if (!(item->fState & MF_HILITE))
|
|---|
| 2043 | {
|
|---|
| 2044 | if (menu->wFlags & MF_POPUP) hdc = GetDC( menu->hWnd );
|
|---|
| 2045 | else hdc = GetDCEx( menu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
|
|---|
| 2046 |
|
|---|
| 2047 | SelectObject( hdc, hMenuFont);
|
|---|
| 2048 |
|
|---|
| 2049 | item->fState |= MF_HILITE;
|
|---|
| 2050 | MENU_DrawMenuItem( menu->hWnd, hmenu, hwndOwner, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE );
|
|---|
| 2051 | ReleaseDC( menu->hWnd, hdc );
|
|---|
| 2052 | }
|
|---|
| 2053 | if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right)
|
|---|
| 2054 | item->rect = rect;
|
|---|
| 2055 |
|
|---|
| 2056 | item->fState |= MF_MOUSESELECT;
|
|---|
| 2057 |
|
|---|
| 2058 | if (IS_SYSTEM_MENU(menu))
|
|---|
| 2059 | {
|
|---|
| 2060 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(menu->hWnd);
|
|---|
| 2061 |
|
|---|
| 2062 | MENU_InitSysMenuPopup(item->hSubMenu,GetWindowLongA(menu->hWnd,GWL_STYLE), GetClassLongA(menu->hWnd, GCL_STYLE));
|
|---|
| 2063 |
|
|---|
| 2064 | if (win32wnd) win32wnd->GetSysPopupPos(&rect);
|
|---|
| 2065 | rect.top = rect.bottom;
|
|---|
| 2066 | rect.right = GetSystemMetrics(SM_CXSIZE);
|
|---|
| 2067 | rect.bottom = GetSystemMetrics(SM_CYSIZE);
|
|---|
| 2068 | }
|
|---|
| 2069 | else
|
|---|
| 2070 | {
|
|---|
| 2071 | if (menu->wFlags & MF_POPUP)
|
|---|
| 2072 | {
|
|---|
| 2073 | RECT rectWindow;
|
|---|
| 2074 |
|
|---|
| 2075 | GetWindowRect(menu->hWnd,&rectWindow);
|
|---|
| 2076 | rect.left = rectWindow.left + item->rect.right-arrow_bitmap_width;
|
|---|
| 2077 | rect.top = rectWindow.top + item->rect.top;
|
|---|
| 2078 | rect.right = item->rect.left - item->rect.right + 2*arrow_bitmap_width;
|
|---|
| 2079 | rect.bottom = item->rect.top - item->rect.bottom;
|
|---|
| 2080 | }
|
|---|
| 2081 | else
|
|---|
| 2082 | {
|
|---|
| 2083 | RECT rectWindow;
|
|---|
| 2084 |
|
|---|
| 2085 | GetWindowRect(menu->hWnd,&rectWindow);
|
|---|
| 2086 | rect.left = rectWindow.left + item->rect.left;
|
|---|
| 2087 | rect.top = rectWindow.top + item->rect.bottom;
|
|---|
| 2088 | rect.right = item->rect.right - item->rect.left;
|
|---|
| 2089 | rect.bottom = item->rect.bottom - item->rect.top;
|
|---|
| 2090 | }
|
|---|
| 2091 | }
|
|---|
| 2092 |
|
|---|
| 2093 | MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
|
|---|
| 2094 | rect.left, rect.top, rect.right, rect.bottom );
|
|---|
| 2095 | if (selectFirst)
|
|---|
| 2096 | MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
|
|---|
| 2097 | return item->hSubMenu;
|
|---|
| 2098 | }
|
|---|
| 2099 |
|
|---|
| 2100 | /***********************************************************************
|
|---|
| 2101 | * MENU_PtMenu
|
|---|
| 2102 | *
|
|---|
| 2103 | * Walks menu chain trying to find a menu pt maps to.
|
|---|
| 2104 | */
|
|---|
| 2105 | static HMENU MENU_PtMenu( HMENU hMenu, POINT pt )
|
|---|
| 2106 | {
|
|---|
| 2107 | POPUPMENU *menu = (POPUPMENU*)hMenu;
|
|---|
| 2108 | register UINT ht = menu->FocusedItem;
|
|---|
| 2109 |
|
|---|
| 2110 | /* try subpopup first (if any) */
|
|---|
| 2111 | ht = (ht != NO_SELECTED_ITEM &&
|
|---|
| 2112 | (menu->items[ht].fType & MF_POPUP) &&
|
|---|
| 2113 | (menu->items[ht].fState & MF_MOUSESELECT))
|
|---|
| 2114 | ? (UINT) MENU_PtMenu(menu->items[ht].hSubMenu, pt) : 0;
|
|---|
| 2115 |
|
|---|
| 2116 | if( !ht ) /* check the current window (avoiding WM_HITTEST) */
|
|---|
| 2117 | {
|
|---|
| 2118 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(menu->hWnd);
|
|---|
| 2119 | if(win32wnd==NULL)
|
|---|
| 2120 | DebugInt3();
|
|---|
| 2121 |
|
|---|
| 2122 | ht = win32wnd->HandleNCHitTest(pt);
|
|---|
| 2123 | if( menu->wFlags & MF_POPUP )
|
|---|
| 2124 | ht = (ht != (UINT)HTNOWHERE &&
|
|---|
| 2125 | ht != (UINT)HTERROR) ? (UINT)hMenu : 0;
|
|---|
| 2126 | else
|
|---|
| 2127 | {
|
|---|
| 2128 | ht = ( ht == HTSYSMENU ) ? (UINT)(getSysMenu(menu->hWnd))
|
|---|
| 2129 | : ( ht == HTMENU ) ? (UINT)(getMenu(menu->hWnd)) : 0;
|
|---|
| 2130 | }
|
|---|
| 2131 | }
|
|---|
| 2132 | return (HMENU)ht;
|
|---|
| 2133 | }
|
|---|
| 2134 |
|
|---|
| 2135 | /***********************************************************************
|
|---|
| 2136 | * MENU_ExecFocusedItem
|
|---|
| 2137 | *
|
|---|
| 2138 | * Execute a menu item (for instance when user pressed Enter).
|
|---|
| 2139 | * Return the wID of the executed item. Otherwise, -1 indicating
|
|---|
| 2140 | * that no menu item wase executed;
|
|---|
| 2141 | * Have to receive the flags for the TrackPopupMenu options to avoid
|
|---|
| 2142 | * sending unwanted message.
|
|---|
| 2143 | *
|
|---|
| 2144 | */
|
|---|
| 2145 | static INT MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu, UINT wFlags )
|
|---|
| 2146 | {
|
|---|
| 2147 | MENUITEM *item;
|
|---|
| 2148 | POPUPMENU *menu = (POPUPMENU*)hMenu;
|
|---|
| 2149 |
|
|---|
| 2150 | //TRACE("%p hmenu=0x%04x\n", pmt, hMenu);
|
|---|
| 2151 |
|
|---|
| 2152 | if (!menu || !menu->nItems ||
|
|---|
| 2153 | (menu->FocusedItem == NO_SELECTED_ITEM)) return -1;
|
|---|
| 2154 |
|
|---|
| 2155 | item = &menu->items[menu->FocusedItem];
|
|---|
| 2156 |
|
|---|
| 2157 | //TRACE("%08x %08x %08x\n",
|
|---|
| 2158 | // hMenu, item->wID, item->hSubMenu);
|
|---|
| 2159 |
|
|---|
| 2160 | if (!(item->fType & MF_POPUP))
|
|---|
| 2161 | {
|
|---|
| 2162 | if (!(item->fState & (MF_GRAYED | MF_DISABLED)))
|
|---|
| 2163 | {
|
|---|
| 2164 | /* If TPM_RETURNCMD is set you return the id, but
|
|---|
| 2165 | do not send a message to the owner */
|
|---|
| 2166 | if(!(wFlags & TPM_RETURNCMD))
|
|---|
| 2167 | {
|
|---|
| 2168 | if( menu->wFlags & MF_SYSMENU )
|
|---|
| 2169 | PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
|
|---|
| 2170 | MAKELPARAM(pmt->pt.x, pmt->pt.y) );
|
|---|
| 2171 | else
|
|---|
| 2172 | PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
|
|---|
| 2173 | }
|
|---|
| 2174 | return item->wID;
|
|---|
| 2175 | }
|
|---|
| 2176 | }
|
|---|
| 2177 | else
|
|---|
| 2178 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hMenu, TRUE, wFlags);
|
|---|
| 2179 |
|
|---|
| 2180 | return -1;
|
|---|
| 2181 | }
|
|---|
| 2182 |
|
|---|
| 2183 | /***********************************************************************
|
|---|
| 2184 | * MENU_SwitchTracking
|
|---|
| 2185 | *
|
|---|
| 2186 | * Helper function for menu navigation routines.
|
|---|
| 2187 | */
|
|---|
| 2188 | static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id )
|
|---|
| 2189 | {
|
|---|
| 2190 | POPUPMENU *ptmenu = (POPUPMENU*)hPtMenu;
|
|---|
| 2191 | POPUPMENU *topmenu = (POPUPMENU*)pmt->hTopMenu;
|
|---|
| 2192 |
|
|---|
| 2193 | //TRACE("%p hmenu=0x%04x 0x%04x\n", pmt, hPtMenu, id);
|
|---|
| 2194 |
|
|---|
| 2195 | if( pmt->hTopMenu != hPtMenu &&
|
|---|
| 2196 | !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
|
|---|
| 2197 | {
|
|---|
| 2198 | /* both are top level menus (system and menu-bar) */
|
|---|
| 2199 | MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
|
|---|
| 2200 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
|
|---|
| 2201 | pmt->hTopMenu = hPtMenu;
|
|---|
| 2202 | }
|
|---|
| 2203 | else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE );
|
|---|
| 2204 | MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE, 0 );
|
|---|
| 2205 | }
|
|---|
| 2206 |
|
|---|
| 2207 |
|
|---|
| 2208 | /***********************************************************************
|
|---|
| 2209 | * MENU_ButtonDown
|
|---|
| 2210 | *
|
|---|
| 2211 | * Return TRUE if we can go on with menu tracking.
|
|---|
| 2212 | */
|
|---|
| 2213 | static BOOL MENU_ButtonDown( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
|
|---|
| 2214 | {
|
|---|
| 2215 | //TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
|
|---|
| 2216 |
|
|---|
| 2217 | if (hPtMenu)
|
|---|
| 2218 | {
|
|---|
| 2219 | UINT id = 0;
|
|---|
| 2220 | POPUPMENU *ptmenu = (POPUPMENU*)hPtMenu;
|
|---|
| 2221 | MENUITEM *item;
|
|---|
| 2222 |
|
|---|
| 2223 | if( IS_SYSTEM_MENU(ptmenu) )
|
|---|
| 2224 | item = ptmenu->items;
|
|---|
| 2225 | else
|
|---|
| 2226 | item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
|
|---|
| 2227 |
|
|---|
| 2228 | if( item )
|
|---|
| 2229 | {
|
|---|
| 2230 | if( ptmenu->FocusedItem != id )
|
|---|
| 2231 | MENU_SwitchTracking( pmt, hPtMenu, id );
|
|---|
| 2232 |
|
|---|
| 2233 | /* If the popup menu is not already "popped" */
|
|---|
| 2234 | if(!(item->fState & MF_MOUSESELECT ))
|
|---|
| 2235 | {
|
|---|
| 2236 | pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE, wFlags );
|
|---|
| 2237 | }
|
|---|
| 2238 |
|
|---|
| 2239 | return TRUE;
|
|---|
| 2240 | }
|
|---|
| 2241 | /* Else the click was on the menu bar, finish the tracking */
|
|---|
| 2242 | }
|
|---|
| 2243 | return FALSE;
|
|---|
| 2244 | }
|
|---|
| 2245 |
|
|---|
| 2246 | /***********************************************************************
|
|---|
| 2247 | * MENU_ButtonUp
|
|---|
| 2248 | *
|
|---|
| 2249 | * Return the value of MENU_ExecFocusedItem if
|
|---|
| 2250 | * the selected item was not a popup. Else open the popup.
|
|---|
| 2251 | * A -1 return value indicates that we go on with menu tracking.
|
|---|
| 2252 | *
|
|---|
| 2253 | */
|
|---|
| 2254 | static INT MENU_ButtonUp( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags)
|
|---|
| 2255 | {
|
|---|
| 2256 | //TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
|
|---|
| 2257 |
|
|---|
| 2258 | if (hPtMenu)
|
|---|
| 2259 | {
|
|---|
| 2260 | UINT id = 0;
|
|---|
| 2261 | POPUPMENU *ptmenu = (POPUPMENU*)hPtMenu;
|
|---|
| 2262 | MENUITEM *item;
|
|---|
| 2263 |
|
|---|
| 2264 | if( IS_SYSTEM_MENU(ptmenu) )
|
|---|
| 2265 | item = ptmenu->items;
|
|---|
| 2266 | else
|
|---|
| 2267 | item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
|
|---|
| 2268 |
|
|---|
| 2269 | if( item && (ptmenu->FocusedItem == id ))
|
|---|
| 2270 | {
|
|---|
| 2271 | if( !(item->fType & MF_POPUP) )
|
|---|
| 2272 | return MENU_ExecFocusedItem( pmt, hPtMenu, wFlags);
|
|---|
| 2273 |
|
|---|
| 2274 | /* If we are dealing with the top-level menu and that this */
|
|---|
| 2275 | /* is a click on an already "poppped" item */
|
|---|
| 2276 | /* Stop the menu tracking and close the opened submenus */
|
|---|
| 2277 | if((pmt->hTopMenu == hPtMenu) && (ptmenu->bTimeToHide == TRUE))
|
|---|
| 2278 | return 0;
|
|---|
| 2279 | }
|
|---|
| 2280 | ptmenu->bTimeToHide = TRUE;
|
|---|
| 2281 | }
|
|---|
| 2282 | return -1;
|
|---|
| 2283 | }
|
|---|
| 2284 |
|
|---|
| 2285 |
|
|---|
| 2286 | /***********************************************************************
|
|---|
| 2287 | * MENU_MouseMove
|
|---|
| 2288 | *
|
|---|
| 2289 | * Return TRUE if we can go on with menu tracking.
|
|---|
| 2290 | */
|
|---|
| 2291 | static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
|
|---|
| 2292 | {
|
|---|
| 2293 | UINT id = NO_SELECTED_ITEM;
|
|---|
| 2294 | POPUPMENU *ptmenu = NULL;
|
|---|
| 2295 |
|
|---|
| 2296 | if( hPtMenu )
|
|---|
| 2297 | {
|
|---|
| 2298 | ptmenu = (POPUPMENU*)hPtMenu;
|
|---|
| 2299 | if( IS_SYSTEM_MENU(ptmenu) )
|
|---|
| 2300 | id = 0;
|
|---|
| 2301 | else
|
|---|
| 2302 | MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
|
|---|
| 2303 | }
|
|---|
| 2304 |
|
|---|
| 2305 | if( id == NO_SELECTED_ITEM )
|
|---|
| 2306 | {
|
|---|
| 2307 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
|
|---|
| 2308 | NO_SELECTED_ITEM, TRUE, pmt->hTopMenu);
|
|---|
| 2309 |
|
|---|
| 2310 | }
|
|---|
| 2311 | else if( ptmenu->FocusedItem != id )
|
|---|
| 2312 | {
|
|---|
| 2313 | MENU_SwitchTracking( pmt, hPtMenu, id );
|
|---|
| 2314 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hPtMenu, FALSE, wFlags);
|
|---|
| 2315 | }
|
|---|
| 2316 | return TRUE;
|
|---|
| 2317 | }
|
|---|
| 2318 |
|
|---|
| 2319 |
|
|---|
| 2320 | /***********************************************************************
|
|---|
| 2321 | * MENU_DoNextMenu
|
|---|
| 2322 | *
|
|---|
| 2323 | * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
|
|---|
| 2324 | */
|
|---|
| 2325 | static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk )
|
|---|
| 2326 | {
|
|---|
| 2327 | POPUPMENU *menu = (POPUPMENU*)pmt->hTopMenu;
|
|---|
| 2328 |
|
|---|
| 2329 | if( (vk == VK_LEFT && menu->FocusedItem == 0 ) ||
|
|---|
| 2330 | (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1))
|
|---|
| 2331 | {
|
|---|
| 2332 | HMENU hNewMenu;
|
|---|
| 2333 | HWND hNewWnd;
|
|---|
| 2334 | UINT id = 0;
|
|---|
| 2335 | LRESULT l = SendMessageA( pmt->hOwnerWnd, WM_NEXTMENU, vk,
|
|---|
| 2336 | (IS_SYSTEM_MENU(menu)) ? GetSubMenu(pmt->hTopMenu,0) : pmt->hTopMenu );
|
|---|
| 2337 |
|
|---|
| 2338 | //TRACE("%04x [%04x] -> %04x [%04x]\n",
|
|---|
| 2339 | // (UINT16)pmt->hCurrentMenu, (UINT16)pmt->hOwnerWnd, LOWORD(l), HIWORD(l) );
|
|---|
| 2340 |
|
|---|
| 2341 | if( l == 0 )
|
|---|
| 2342 | {
|
|---|
| 2343 | hNewWnd = pmt->hOwnerWnd;
|
|---|
| 2344 | if( IS_SYSTEM_MENU(menu) )
|
|---|
| 2345 | {
|
|---|
| 2346 | /* switch to the menu bar */
|
|---|
| 2347 |
|
|---|
| 2348 | if( (GetWindowLongA(pmt->hOwnerWnd,GWL_STYLE) & WS_CHILD) || !getMenu(pmt->hOwnerWnd) )
|
|---|
| 2349 | {
|
|---|
| 2350 | return FALSE;
|
|---|
| 2351 | }
|
|---|
| 2352 |
|
|---|
| 2353 | hNewMenu = getMenu(pmt->hOwnerWnd);
|
|---|
| 2354 | if( vk == VK_LEFT )
|
|---|
| 2355 | {
|
|---|
| 2356 | menu = (POPUPMENU*)hNewMenu;
|
|---|
| 2357 | id = menu->nItems - 1;
|
|---|
| 2358 | }
|
|---|
| 2359 | }
|
|---|
| 2360 | else if( GetWindowLongA(pmt->hOwnerWnd,GWL_STYLE) & WS_SYSMENU )
|
|---|
| 2361 | {
|
|---|
| 2362 | /* switch to the system menu */
|
|---|
| 2363 | hNewMenu = getSysMenu(pmt->hOwnerWnd);
|
|---|
| 2364 | }
|
|---|
| 2365 | else
|
|---|
| 2366 | {
|
|---|
| 2367 | return FALSE;
|
|---|
| 2368 | }
|
|---|
| 2369 | }
|
|---|
| 2370 | else /* application returned a new menu to switch to */
|
|---|
| 2371 | {
|
|---|
| 2372 | hNewMenu = LOWORD(l); hNewWnd = HIWORD(l);
|
|---|
| 2373 |
|
|---|
| 2374 | if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
|
|---|
| 2375 | {
|
|---|
| 2376 | if( (GetWindowLongA(hNewWnd,GWL_STYLE) & WS_SYSMENU) &&
|
|---|
| 2377 | GetSubMenu(getSysMenu(hNewWnd), 0) == hNewMenu )
|
|---|
| 2378 | {
|
|---|
| 2379 | /* get the real system menu */
|
|---|
| 2380 | hNewMenu = getSysMenu(hNewWnd);
|
|---|
| 2381 | }
|
|---|
| 2382 | else if( (GetWindowLongA(hNewWnd,GWL_STYLE) & WS_CHILD) || (getMenu(hNewWnd) != hNewMenu) )
|
|---|
| 2383 | {
|
|---|
| 2384 | /* FIXME: Not sure what to do here, perhaps,
|
|---|
| 2385 | * try to track hNewMenu as a popup? */
|
|---|
| 2386 |
|
|---|
| 2387 | //TRACE(" -- got confused.\n");
|
|---|
| 2388 | return FALSE;
|
|---|
| 2389 | }
|
|---|
| 2390 | }
|
|---|
| 2391 | else return FALSE;
|
|---|
| 2392 | }
|
|---|
| 2393 |
|
|---|
| 2394 | if( hNewMenu != pmt->hTopMenu )
|
|---|
| 2395 | {
|
|---|
| 2396 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM,
|
|---|
| 2397 | FALSE, 0 );
|
|---|
| 2398 | if( pmt->hCurrentMenu != pmt->hTopMenu )
|
|---|
| 2399 | MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
|
|---|
| 2400 | }
|
|---|
| 2401 |
|
|---|
| 2402 | if( hNewWnd != pmt->hOwnerWnd )
|
|---|
| 2403 | {
|
|---|
| 2404 | ReleaseCapture();
|
|---|
| 2405 | pmt->hOwnerWnd = hNewWnd;
|
|---|
| 2406 | SetCapture(pmt->hOwnerWnd); //SvL: Don't know if this is good enough
|
|---|
| 2407 | //EVENT_Capture( pmt->hOwnerWnd, HTMENU ); //CB: todo
|
|---|
| 2408 | }
|
|---|
| 2409 |
|
|---|
| 2410 | pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
|
|---|
| 2411 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE, 0 );
|
|---|
| 2412 |
|
|---|
| 2413 | return TRUE;
|
|---|
| 2414 | }
|
|---|
| 2415 | return FALSE;
|
|---|
| 2416 | }
|
|---|
| 2417 |
|
|---|
| 2418 | /***********************************************************************
|
|---|
| 2419 | * MENU_SuspendPopup
|
|---|
| 2420 | *
|
|---|
| 2421 | * The idea is not to show the popup if the next input message is
|
|---|
| 2422 | * going to hide it anyway.
|
|---|
| 2423 | */
|
|---|
| 2424 | static BOOL MENU_SuspendPopup( MTRACKER* pmt, UINT uMsg )
|
|---|
| 2425 | {
|
|---|
| 2426 | MSG msg;
|
|---|
| 2427 |
|
|---|
| 2428 | msg.hwnd = pmt->hOwnerWnd;
|
|---|
| 2429 |
|
|---|
| 2430 | PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
|
|---|
| 2431 | pmt->trackFlags |= TF_SKIPREMOVE;
|
|---|
| 2432 |
|
|---|
| 2433 | switch( uMsg )
|
|---|
| 2434 | {
|
|---|
| 2435 | case WM_KEYDOWN:
|
|---|
| 2436 | PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
|
|---|
| 2437 | if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
|
|---|
| 2438 | {
|
|---|
| 2439 | PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
|
|---|
| 2440 | PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
|
|---|
| 2441 | if( msg.message == WM_KEYDOWN &&
|
|---|
| 2442 | (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
|
|---|
| 2443 | {
|
|---|
| 2444 | pmt->trackFlags |= TF_SUSPENDPOPUP;
|
|---|
| 2445 | return TRUE;
|
|---|
| 2446 | }
|
|---|
| 2447 | }
|
|---|
| 2448 | break;
|
|---|
| 2449 | }
|
|---|
| 2450 |
|
|---|
| 2451 | /* failures go through this */
|
|---|
| 2452 | pmt->trackFlags &= ~TF_SUSPENDPOPUP;
|
|---|
| 2453 | return FALSE;
|
|---|
| 2454 | }
|
|---|
| 2455 |
|
|---|
| 2456 | /***********************************************************************
|
|---|
| 2457 | * MENU_KeyLeft
|
|---|
| 2458 | *
|
|---|
| 2459 | * Handle a VK_LEFT key event in a menu.
|
|---|
| 2460 | */
|
|---|
| 2461 | static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags )
|
|---|
| 2462 | {
|
|---|
| 2463 | POPUPMENU *menu;
|
|---|
| 2464 | HMENU hmenutmp, hmenuprev;
|
|---|
| 2465 | UINT prevcol;
|
|---|
| 2466 |
|
|---|
| 2467 | hmenuprev = hmenutmp = pmt->hTopMenu;
|
|---|
| 2468 | menu = (POPUPMENU*)hmenutmp;
|
|---|
| 2469 |
|
|---|
| 2470 | /* Try to move 1 column left (if possible) */
|
|---|
| 2471 | if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
|
|---|
| 2472 | NO_SELECTED_ITEM ) {
|
|---|
| 2473 |
|
|---|
| 2474 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
|
|---|
| 2475 | prevcol, TRUE, 0 );
|
|---|
| 2476 | return;
|
|---|
| 2477 | }
|
|---|
| 2478 |
|
|---|
| 2479 | /* close topmost popup */
|
|---|
| 2480 | while (hmenutmp != pmt->hCurrentMenu)
|
|---|
| 2481 | {
|
|---|
| 2482 | hmenuprev = hmenutmp;
|
|---|
| 2483 | hmenutmp = MENU_GetSubPopup( hmenuprev );
|
|---|
| 2484 | }
|
|---|
| 2485 |
|
|---|
| 2486 | MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE );
|
|---|
| 2487 | pmt->hCurrentMenu = hmenuprev;
|
|---|
| 2488 |
|
|---|
| 2489 | if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) )
|
|---|
| 2490 | {
|
|---|
| 2491 | /* move menu bar selection if no more popups are left */
|
|---|
| 2492 |
|
|---|
| 2493 | if( !MENU_DoNextMenu( pmt, VK_LEFT) )
|
|---|
| 2494 | MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
|
|---|
| 2495 |
|
|---|
| 2496 | if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
|
|---|
| 2497 | {
|
|---|
| 2498 | /* A sublevel menu was displayed - display the next one
|
|---|
| 2499 | * unless there is another displacement coming up */
|
|---|
| 2500 |
|
|---|
| 2501 | if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
|
|---|
| 2502 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
|
|---|
| 2503 | pmt->hTopMenu, TRUE, wFlags);
|
|---|
| 2504 | }
|
|---|
| 2505 | }
|
|---|
| 2506 | }
|
|---|
| 2507 |
|
|---|
| 2508 |
|
|---|
| 2509 | /***********************************************************************
|
|---|
| 2510 | * MENU_KeyRight
|
|---|
| 2511 | *
|
|---|
| 2512 | * Handle a VK_RIGHT key event in a menu.
|
|---|
| 2513 | */
|
|---|
| 2514 | static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags )
|
|---|
| 2515 | {
|
|---|
| 2516 | HMENU hmenutmp;
|
|---|
| 2517 | POPUPMENU *menu = (POPUPMENU*)pmt->hTopMenu;
|
|---|
| 2518 | UINT nextcol;
|
|---|
| 2519 |
|
|---|
| 2520 | //TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
|
|---|
| 2521 | // pmt->hCurrentMenu,
|
|---|
| 2522 | // ((POPUPMENU *)USER_HEAP_LIN_ADDR(pmt->hCurrentMenu))->
|
|---|
| 2523 | // items[0].text,
|
|---|
| 2524 | // pmt->hTopMenu, menu->items[0].text );
|
|---|
| 2525 |
|
|---|
| 2526 | if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu))
|
|---|
| 2527 | {
|
|---|
| 2528 | /* If already displaying a popup, try to display sub-popup */
|
|---|
| 2529 |
|
|---|
| 2530 | hmenutmp = pmt->hCurrentMenu;
|
|---|
| 2531 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hmenutmp, TRUE, wFlags);
|
|---|
| 2532 |
|
|---|
| 2533 | /* if subpopup was displayed then we are done */
|
|---|
| 2534 | if (hmenutmp != pmt->hCurrentMenu) return;
|
|---|
| 2535 | }
|
|---|
| 2536 |
|
|---|
| 2537 | /* Check to see if there's another column */
|
|---|
| 2538 | if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
|
|---|
| 2539 | NO_SELECTED_ITEM ) {
|
|---|
| 2540 | //TRACE("Going to %d.\n", nextcol );
|
|---|
| 2541 | MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
|
|---|
| 2542 | nextcol, TRUE, 0 );
|
|---|
| 2543 | return;
|
|---|
| 2544 | }
|
|---|
| 2545 |
|
|---|
| 2546 | if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */
|
|---|
| 2547 | {
|
|---|
| 2548 | if( pmt->hCurrentMenu != pmt->hTopMenu )
|
|---|
| 2549 | {
|
|---|
| 2550 | MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
|
|---|
| 2551 | hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
|
|---|
| 2552 | } else hmenutmp = 0;
|
|---|
| 2553 |
|
|---|
| 2554 | /* try to move to the next item */
|
|---|
| 2555 | if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
|
|---|
| 2556 | MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
|
|---|
| 2557 |
|
|---|
| 2558 | if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
|
|---|
| 2559 | if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
|
|---|
| 2560 | pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
|
|---|
| 2561 | pmt->hTopMenu, TRUE, wFlags);
|
|---|
| 2562 | }
|
|---|
| 2563 | }
|
|---|
| 2564 |
|
|---|
| 2565 | /***********************************************************************
|
|---|
| 2566 | * MENU_TrackMenu
|
|---|
| 2567 | *
|
|---|
| 2568 | * Menu tracking code.
|
|---|
| 2569 | */
|
|---|
| 2570 | static INT MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
|
|---|
| 2571 | HWND hwnd, const RECT *lprect )
|
|---|
| 2572 | {
|
|---|
| 2573 | MSG msg;
|
|---|
| 2574 | POPUPMENU *menu;
|
|---|
| 2575 | BOOL fRemove;
|
|---|
| 2576 | INT executedMenuId = -1;
|
|---|
| 2577 | MTRACKER mt;
|
|---|
| 2578 | BOOL enterIdleSent = FALSE;
|
|---|
| 2579 |
|
|---|
| 2580 | mt.trackFlags = 0;
|
|---|
| 2581 | mt.hCurrentMenu = hmenu;
|
|---|
| 2582 | mt.hTopMenu = hmenu;
|
|---|
| 2583 | mt.hOwnerWnd = hwnd;
|
|---|
| 2584 | mt.pt.x = x;
|
|---|
| 2585 | mt.pt.y = y;
|
|---|
| 2586 |
|
|---|
| 2587 | //TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
|
|---|
| 2588 | // hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
|
|---|
| 2589 | // (lprect) ? lprect->right : 0, (lprect) ? lprect->bottom : 0);
|
|---|
| 2590 |
|
|---|
| 2591 | fEndMenu = FALSE;
|
|---|
| 2592 | if (!(menu = (POPUPMENU*)hmenu)) return FALSE;
|
|---|
| 2593 |
|
|---|
| 2594 | if (wFlags & TPM_BUTTONDOWN) MENU_ButtonDown( &mt, hmenu, wFlags );
|
|---|
| 2595 |
|
|---|
| 2596 | //EVENT_Capture( mt.hOwnerWnd, HTMENU ); //CB: todo
|
|---|
| 2597 | //SvL: Set keyboard & mouse event capture
|
|---|
| 2598 | SetCapture(mt.hOwnerWnd);
|
|---|
| 2599 |
|
|---|
| 2600 | while (!fEndMenu)
|
|---|
| 2601 | {
|
|---|
| 2602 | menu = (POPUPMENU*)mt.hCurrentMenu;
|
|---|
| 2603 | msg.hwnd = (wFlags & TPM_ENTERIDLEEX && menu->wFlags & MF_POPUP) ? menu->hWnd : 0;
|
|---|
| 2604 |
|
|---|
| 2605 | /* we have to keep the message in the queue until it's
|
|---|
| 2606 | * clear that menu loop is not over yet. */
|
|---|
| 2607 | // if (!GetMessageA(&msg,msg.hwnd,0,0)) break;
|
|---|
| 2608 | //SvL: Getting messages for only the menu delays background paints (i.e. VPBuddy logo)
|
|---|
| 2609 | if (!GetMessageA(&msg,0,0,0)) break;
|
|---|
| 2610 | TranslateMessage( &msg );
|
|---|
| 2611 | mt.pt = msg.pt;
|
|---|
| 2612 |
|
|---|
| 2613 | if ( (msg.hwnd==menu->hWnd) || (msg.message!=WM_TIMER) )
|
|---|
| 2614 | enterIdleSent=FALSE;
|
|---|
| 2615 |
|
|---|
| 2616 | fRemove = FALSE;
|
|---|
| 2617 | if((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
|
|---|
| 2618 | {
|
|---|
| 2619 | /* Find a menu for this mouse event */
|
|---|
| 2620 | POINT pt = msg.pt;
|
|---|
| 2621 | hmenu = MENU_PtMenu( mt.hTopMenu, pt );
|
|---|
| 2622 |
|
|---|
| 2623 | switch(msg.message)
|
|---|
| 2624 | {
|
|---|
| 2625 | /* no WM_NC... messages in captured state */
|
|---|
| 2626 |
|
|---|
| 2627 | case WM_RBUTTONDBLCLK:
|
|---|
| 2628 | case WM_RBUTTONDOWN:
|
|---|
| 2629 | if (!(wFlags & TPM_RIGHTBUTTON)) break;
|
|---|
| 2630 | /* fall through */
|
|---|
| 2631 | case WM_LBUTTONDBLCLK:
|
|---|
| 2632 | case WM_LBUTTONDOWN:
|
|---|
| 2633 | /* If the message belongs to the menu, removes it from the queue */
|
|---|
| 2634 | /* Else, end menu tracking */
|
|---|
| 2635 | fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
|
|---|
| 2636 | fEndMenu = !fRemove;
|
|---|
| 2637 | break;
|
|---|
| 2638 |
|
|---|
| 2639 | case WM_RBUTTONUP:
|
|---|
| 2640 | if (!(wFlags & TPM_RIGHTBUTTON)) break;
|
|---|
| 2641 | /* fall through */
|
|---|
| 2642 | case WM_LBUTTONUP:
|
|---|
| 2643 | /* Check if a menu was selected by the mouse */
|
|---|
| 2644 | if (hmenu)
|
|---|
| 2645 | {
|
|---|
| 2646 | executedMenuId = MENU_ButtonUp( &mt, hmenu, wFlags);
|
|---|
| 2647 |
|
|---|
| 2648 | /* End the loop if executedMenuId is an item ID */
|
|---|
| 2649 | /* or if the job was done (executedMenuId = 0). */
|
|---|
| 2650 | fEndMenu = fRemove = (executedMenuId != -1);
|
|---|
| 2651 | }
|
|---|
| 2652 | /* No menu was selected by the mouse */
|
|---|
| 2653 | /* if the function was called by TrackPopupMenu, continue
|
|---|
| 2654 | with the menu tracking. If not, stop it */
|
|---|
| 2655 | else
|
|---|
| 2656 | fEndMenu = ((wFlags & TPM_POPUPMENU) ? FALSE : TRUE);
|
|---|
| 2657 |
|
|---|
| 2658 | break;
|
|---|
| 2659 |
|
|---|
| 2660 | case WM_MOUSEMOVE:
|
|---|
| 2661 | /* In win95 winelook, the selected menu item must be changed every time the
|
|---|
| 2662 | mouse moves. In Win31 winelook, the mouse button has to be held down */
|
|---|
| 2663 |
|
|---|
| 2664 | fEndMenu |= !MENU_MouseMove( &mt, hmenu, wFlags );
|
|---|
| 2665 |
|
|---|
| 2666 | } /* switch(msg.message) - mouse */
|
|---|
| 2667 | }
|
|---|
| 2668 | else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
|
|---|
| 2669 | {
|
|---|
| 2670 | fRemove = TRUE; /* Keyboard messages are always removed */
|
|---|
| 2671 | switch(msg.message)
|
|---|
| 2672 | {
|
|---|
| 2673 | case WM_KEYDOWN:
|
|---|
| 2674 | switch(msg.wParam)
|
|---|
| 2675 | {
|
|---|
| 2676 | case VK_HOME:
|
|---|
| 2677 | case VK_END:
|
|---|
| 2678 | MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
|
|---|
| 2679 | NO_SELECTED_ITEM, FALSE, 0 );
|
|---|
| 2680 | /* fall through */
|
|---|
| 2681 | case VK_UP:
|
|---|
| 2682 | MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
|
|---|
| 2683 | (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
|
|---|
| 2684 | break;
|
|---|
| 2685 |
|
|---|
| 2686 | case VK_DOWN: /* If on menu bar, pull-down the menu */
|
|---|
| 2687 |
|
|---|
| 2688 | menu = (POPUPMENU*)mt.hCurrentMenu;
|
|---|
| 2689 | if (!(menu->wFlags & MF_POPUP))
|
|---|
| 2690 | mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags);
|
|---|
| 2691 | else /* otherwise try to move selection */
|
|---|
| 2692 | MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
|
|---|
| 2693 | break;
|
|---|
| 2694 |
|
|---|
| 2695 | case VK_LEFT:
|
|---|
| 2696 | MENU_KeyLeft( &mt, wFlags );
|
|---|
| 2697 | break;
|
|---|
| 2698 |
|
|---|
| 2699 | case VK_RIGHT:
|
|---|
| 2700 | MENU_KeyRight( &mt, wFlags );
|
|---|
| 2701 | break;
|
|---|
| 2702 |
|
|---|
| 2703 | case VK_ESCAPE:
|
|---|
| 2704 | fEndMenu = TRUE;
|
|---|
| 2705 | break;
|
|---|
| 2706 |
|
|---|
| 2707 | default:
|
|---|
| 2708 | break;
|
|---|
| 2709 | }
|
|---|
| 2710 | break; /* WM_KEYDOWN */
|
|---|
| 2711 |
|
|---|
| 2712 | case WM_SYSKEYDOWN:
|
|---|
| 2713 | switch(msg.wParam)
|
|---|
| 2714 | {
|
|---|
| 2715 | case VK_MENU:
|
|---|
| 2716 | fEndMenu = TRUE;
|
|---|
| 2717 | break;
|
|---|
| 2718 |
|
|---|
| 2719 | }
|
|---|
| 2720 | break; /* WM_SYSKEYDOWN */
|
|---|
| 2721 |
|
|---|
| 2722 | case WM_CHAR:
|
|---|
| 2723 | {
|
|---|
| 2724 | UINT pos;
|
|---|
| 2725 |
|
|---|
| 2726 | if (msg.wParam == '\r' || msg.wParam == ' ')
|
|---|
| 2727 | {
|
|---|
| 2728 | executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
|
|---|
| 2729 | fEndMenu = (executedMenuId != -1);
|
|---|
| 2730 |
|
|---|
| 2731 | break;
|
|---|
| 2732 | }
|
|---|
| 2733 |
|
|---|
| 2734 | /* Hack to avoid control chars. */
|
|---|
| 2735 | /* We will find a better way real soon... */
|
|---|
| 2736 | if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
|
|---|
| 2737 |
|
|---|
| 2738 | pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
|
|---|
| 2739 | LOWORD(msg.wParam), FALSE );
|
|---|
| 2740 | if (pos == (UINT)-2) fEndMenu = TRUE;
|
|---|
| 2741 | else if (pos == (UINT)-1) MessageBeep(0);
|
|---|
| 2742 | else
|
|---|
| 2743 | {
|
|---|
| 2744 | MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos,
|
|---|
| 2745 | TRUE, 0 );
|
|---|
| 2746 | executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
|
|---|
| 2747 | fEndMenu = (executedMenuId != -1);
|
|---|
| 2748 | }
|
|---|
| 2749 | }
|
|---|
| 2750 | break;
|
|---|
| 2751 | } /* switch(msg.message) - kbd */
|
|---|
| 2752 | }
|
|---|
| 2753 | else
|
|---|
| 2754 | {
|
|---|
| 2755 | DispatchMessageA( &msg );
|
|---|
| 2756 | }
|
|---|
| 2757 |
|
|---|
| 2758 | if (!fEndMenu) fRemove = TRUE;
|
|---|
| 2759 |
|
|---|
| 2760 | /* finally remove message from the queue */
|
|---|
| 2761 |
|
|---|
| 2762 | if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) )
|
|---|
| 2763 | PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
|
|---|
| 2764 | else mt.trackFlags &= ~TF_SKIPREMOVE;
|
|---|
| 2765 | }
|
|---|
| 2766 |
|
|---|
| 2767 | ReleaseCapture();
|
|---|
| 2768 |
|
|---|
| 2769 | menu = (POPUPMENU*)mt.hTopMenu;
|
|---|
| 2770 |
|
|---|
| 2771 | if( IsWindow( mt.hOwnerWnd ) )
|
|---|
| 2772 | {
|
|---|
| 2773 | MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
|
|---|
| 2774 |
|
|---|
| 2775 | if (menu && menu->wFlags & MF_POPUP)
|
|---|
| 2776 | {
|
|---|
| 2777 | ShowWindow( menu->hWnd, SW_HIDE );
|
|---|
| 2778 | uSubPWndLevel = 0;
|
|---|
| 2779 | }
|
|---|
| 2780 | MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
|
|---|
| 2781 | SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 );
|
|---|
| 2782 | }
|
|---|
| 2783 |
|
|---|
| 2784 | /* Reset the variable for hiding menu */
|
|---|
| 2785 | menu->bTimeToHide = FALSE;
|
|---|
| 2786 |
|
|---|
| 2787 | /* The return value is only used by TrackPopupMenu */
|
|---|
| 2788 | return ((executedMenuId != -1) ? executedMenuId : 0);
|
|---|
| 2789 | }
|
|---|
| 2790 |
|
|---|
| 2791 | /***********************************************************************
|
|---|
| 2792 | * MENU_InitTracking
|
|---|
| 2793 | */
|
|---|
| 2794 | static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup, UINT wFlags)
|
|---|
| 2795 | {
|
|---|
| 2796 | //TRACE("hwnd=0x%04x hmenu=0x%04x\n", hWnd, hMenu);
|
|---|
| 2797 |
|
|---|
| 2798 | HideCaret(0);
|
|---|
| 2799 |
|
|---|
| 2800 | /* Send WM_ENTERMENULOOP and WM_INITMENU message only if TPM_NONOTIFY flag is not specified */
|
|---|
| 2801 | if (!(wFlags & TPM_NONOTIFY))
|
|---|
| 2802 | SendMessageA( hWnd, WM_ENTERMENULOOP, bPopup, 0 );
|
|---|
| 2803 |
|
|---|
| 2804 | SendMessageA( hWnd, WM_SETCURSOR, hWnd, HTCAPTION );
|
|---|
| 2805 |
|
|---|
| 2806 | if (!(wFlags & TPM_NONOTIFY))
|
|---|
| 2807 | SendMessageA( hWnd, WM_INITMENU, hMenu, 0 );
|
|---|
| 2808 |
|
|---|
| 2809 | return TRUE;
|
|---|
| 2810 | }
|
|---|
| 2811 | /***********************************************************************
|
|---|
| 2812 | * MENU_ExitTracking
|
|---|
| 2813 | */
|
|---|
| 2814 | static BOOL MENU_ExitTracking(HWND hWnd)
|
|---|
| 2815 | {
|
|---|
| 2816 | //TRACE("hwnd=0x%04x\n", hWnd);
|
|---|
| 2817 |
|
|---|
| 2818 | SendMessageA( hWnd, WM_EXITMENULOOP, 0, 0 );
|
|---|
| 2819 | ShowCaret(0);
|
|---|
| 2820 | return TRUE;
|
|---|
| 2821 | }
|
|---|
| 2822 |
|
|---|
| 2823 | /***********************************************************************
|
|---|
| 2824 | * MENU_TrackMouseMenuBar
|
|---|
| 2825 | *
|
|---|
| 2826 | * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
|
|---|
| 2827 | */
|
|---|
| 2828 | void MENU_TrackMouseMenuBar( HWND hWnd, INT ht, POINT pt )
|
|---|
| 2829 | {
|
|---|
| 2830 | HMENU hMenu = (ht == HTSYSMENU) ? getSysMenu(hWnd):getMenu(hWnd);
|
|---|
| 2831 | UINT wFlags = TPM_ENTERIDLEEX | TPM_BUTTONDOWN | TPM_LEFTALIGN | TPM_LEFTBUTTON;
|
|---|
| 2832 |
|
|---|
| 2833 | //TRACE("pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr, ht, pt.x, pt.y);
|
|---|
| 2834 |
|
|---|
| 2835 | if (IsMenu(hMenu))
|
|---|
| 2836 | {
|
|---|
| 2837 | MENU_InitTracking( hWnd, hMenu, FALSE, wFlags );
|
|---|
| 2838 | MENU_TrackMenu( hMenu, wFlags, pt.x, pt.y, hWnd, NULL );
|
|---|
| 2839 | MENU_ExitTracking(hWnd);
|
|---|
| 2840 | }
|
|---|
| 2841 | }
|
|---|
| 2842 |
|
|---|
| 2843 |
|
|---|
| 2844 | /***********************************************************************
|
|---|
| 2845 | * MENU_TrackKbdMenuBar
|
|---|
| 2846 | *
|
|---|
| 2847 | * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
|
|---|
| 2848 | */
|
|---|
| 2849 | void MENU_TrackKbdMenuBar( HWND hWnd, UINT wParam, INT vkey)
|
|---|
| 2850 | {
|
|---|
| 2851 | UINT uItem = NO_SELECTED_ITEM;
|
|---|
| 2852 | HMENU hTrackMenu;
|
|---|
| 2853 | UINT wFlags = TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON;
|
|---|
| 2854 |
|
|---|
| 2855 | /* find window that has a menu */
|
|---|
| 2856 |
|
|---|
| 2857 | while(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD)
|
|---|
| 2858 | if( !(hWnd = GetParent(hWnd)) ) return;
|
|---|
| 2859 |
|
|---|
| 2860 | /* check if we have to track a system menu */
|
|---|
| 2861 |
|
|---|
| 2862 | if( (GetWindowLongA(hWnd,GWL_STYLE) & (WS_CHILD | WS_MINIMIZE)) ||
|
|---|
| 2863 | !getMenu(hWnd) || vkey == VK_SPACE )
|
|---|
| 2864 | {
|
|---|
| 2865 | if( !(GetWindowLongA(hWnd,GWL_STYLE) & WS_SYSMENU) ) return;
|
|---|
| 2866 | hTrackMenu = getSysMenu(hWnd);
|
|---|
| 2867 | uItem = 0;
|
|---|
| 2868 | wParam |= HTSYSMENU; /* prevent item lookup */
|
|---|
| 2869 | }
|
|---|
| 2870 | else
|
|---|
| 2871 | hTrackMenu = getMenu(hWnd);
|
|---|
| 2872 |
|
|---|
| 2873 | if (IsMenu( hTrackMenu ))
|
|---|
| 2874 | {
|
|---|
| 2875 | MENU_InitTracking( hWnd, hTrackMenu, FALSE, wFlags );
|
|---|
| 2876 |
|
|---|
| 2877 | if( vkey && vkey != VK_SPACE )
|
|---|
| 2878 | {
|
|---|
| 2879 | uItem = MENU_FindItemByKey( hWnd, hTrackMenu,
|
|---|
| 2880 | vkey, (wParam & HTSYSMENU) );
|
|---|
| 2881 | if( uItem >= (UINT)(-2) )
|
|---|
| 2882 | {
|
|---|
| 2883 | if( uItem == (UINT)(-1) ) MessageBeep(0);
|
|---|
| 2884 | hTrackMenu = 0;
|
|---|
| 2885 | }
|
|---|
| 2886 | }
|
|---|
| 2887 |
|
|---|
| 2888 | if( hTrackMenu )
|
|---|
| 2889 | {
|
|---|
| 2890 | MENU_SelectItem( hWnd, hTrackMenu, uItem, TRUE, 0 );
|
|---|
| 2891 |
|
|---|
| 2892 | if( uItem == NO_SELECTED_ITEM )
|
|---|
| 2893 | MENU_MoveSelection( hWnd, hTrackMenu, ITEM_NEXT );
|
|---|
| 2894 | else if( vkey )
|
|---|
| 2895 | PostMessageA( hWnd, WM_KEYDOWN, VK_DOWN, 0L );
|
|---|
| 2896 |
|
|---|
| 2897 | MENU_TrackMenu( hTrackMenu, wFlags, 0, 0, hWnd, NULL );
|
|---|
| 2898 | }
|
|---|
| 2899 |
|
|---|
| 2900 | MENU_ExitTracking (hWnd);
|
|---|
| 2901 | }
|
|---|
| 2902 | }
|
|---|
| 2903 |
|
|---|
| 2904 |
|
|---|
| 2905 | /**********************************************************************
|
|---|
| 2906 | * TrackPopupMenu (USER32.549)
|
|---|
| 2907 | *
|
|---|
| 2908 | * Like the win32 API, the function return the command ID only if the
|
|---|
| 2909 | * flag TPM_RETURNCMD is on.
|
|---|
| 2910 | *
|
|---|
| 2911 | */
|
|---|
| 2912 | BOOL WINAPI TrackPopupMenu( HMENU hMenu, UINT wFlags, INT x, INT y,
|
|---|
| 2913 | INT nReserved, HWND hWnd, const RECT *lpRect )
|
|---|
| 2914 | {
|
|---|
| 2915 | BOOL ret = FALSE;
|
|---|
| 2916 |
|
|---|
| 2917 | dprintf(("USER32: TrackPopupMenu"));
|
|---|
| 2918 |
|
|---|
| 2919 | MENU_InitTracking(hWnd, hMenu, TRUE, wFlags);
|
|---|
| 2920 |
|
|---|
| 2921 | /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
|
|---|
| 2922 | if (!(wFlags & TPM_NONOTIFY))
|
|---|
| 2923 | SendMessageA( hWnd, WM_INITMENUPOPUP, hMenu, 0);
|
|---|
| 2924 |
|
|---|
| 2925 | if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
|
|---|
| 2926 | ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpRect );
|
|---|
| 2927 | MENU_ExitTracking(hWnd);
|
|---|
| 2928 |
|
|---|
| 2929 | if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
|
|---|
| 2930 | ret = 1;
|
|---|
| 2931 |
|
|---|
| 2932 | return ret;
|
|---|
| 2933 | }
|
|---|
| 2934 |
|
|---|
| 2935 | /**********************************************************************
|
|---|
| 2936 | * TrackPopupMenuEx (USER32.550)
|
|---|
| 2937 | */
|
|---|
| 2938 | BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y,
|
|---|
| 2939 | HWND hWnd, LPTPMPARAMS lpTpm )
|
|---|
| 2940 | {
|
|---|
| 2941 | dprintf(("USER32: TrackPopupMenuEx"));
|
|---|
| 2942 | //FIXME("not fully implemented\n" );
|
|---|
| 2943 | return TrackPopupMenu( hMenu, wFlags, x, y, 0, hWnd,
|
|---|
| 2944 | lpTpm ? &lpTpm->rcExclude : NULL );
|
|---|
| 2945 | }
|
|---|
| 2946 |
|
|---|
| 2947 | /***********************************************************************
|
|---|
| 2948 | * PopupMenuWndProc
|
|---|
| 2949 | *
|
|---|
| 2950 | * NOTE: Windows has totally different (and undocumented) popup wndproc.
|
|---|
| 2951 | */
|
|---|
| 2952 | LRESULT WINAPI PopupMenuWndProc( HWND hwnd, UINT message, WPARAM wParam,
|
|---|
| 2953 | LPARAM lParam )
|
|---|
| 2954 | {
|
|---|
| 2955 | LRESULT retvalue;
|
|---|
| 2956 |
|
|---|
| 2957 | //TRACE("hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
|
|---|
| 2958 | //hwnd, message, wParam, lParam);
|
|---|
| 2959 |
|
|---|
| 2960 | switch(message)
|
|---|
| 2961 | {
|
|---|
| 2962 | case WM_CREATE:
|
|---|
| 2963 | {
|
|---|
| 2964 | CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
|
|---|
| 2965 | SetWindowLongA( hwnd, 0, (LONG)cs->lpCreateParams );
|
|---|
| 2966 | retvalue = 0;
|
|---|
| 2967 | goto END;
|
|---|
| 2968 | }
|
|---|
| 2969 |
|
|---|
| 2970 | case WM_MOUSEACTIVATE: /* We don't want to be activated */
|
|---|
| 2971 | retvalue = MA_NOACTIVATE;
|
|---|
| 2972 | goto END;
|
|---|
| 2973 |
|
|---|
| 2974 | case WM_PAINT:
|
|---|
| 2975 | {
|
|---|
| 2976 | PAINTSTRUCT ps;
|
|---|
| 2977 | BeginPaint( hwnd, &ps );
|
|---|
| 2978 | MENU_DrawPopupMenu( hwnd, ps.hdc,
|
|---|
| 2979 | (HMENU)GetWindowLongA( hwnd, 0 ) );
|
|---|
| 2980 | EndPaint( hwnd, &ps );
|
|---|
| 2981 | retvalue = 0;
|
|---|
| 2982 | goto END;
|
|---|
| 2983 | }
|
|---|
| 2984 | case WM_ERASEBKGND:
|
|---|
| 2985 | retvalue = 1;
|
|---|
| 2986 | goto END;
|
|---|
| 2987 |
|
|---|
| 2988 | case WM_DESTROY:
|
|---|
| 2989 |
|
|---|
| 2990 | /* zero out global pointer in case resident popup window
|
|---|
| 2991 | * was somehow destroyed. */
|
|---|
| 2992 |
|
|---|
| 2993 | if(MENU_GetTopPopupWnd() )
|
|---|
| 2994 | {
|
|---|
| 2995 | if( hwnd == pTopPopupWnd )
|
|---|
| 2996 | {
|
|---|
| 2997 | //ERR("resident popup destroyed!\n");
|
|---|
| 2998 |
|
|---|
| 2999 | MENU_DestroyTopPopupWnd();
|
|---|
| 3000 | uSubPWndLevel = 0;
|
|---|
| 3001 | }
|
|---|
| 3002 | else
|
|---|
| 3003 | uSubPWndLevel--;
|
|---|
| 3004 | MENU_ReleaseTopPopupWnd();
|
|---|
| 3005 | }
|
|---|
| 3006 | break;
|
|---|
| 3007 |
|
|---|
| 3008 | case WM_SHOWWINDOW:
|
|---|
| 3009 |
|
|---|
| 3010 | if( wParam )
|
|---|
| 3011 | {
|
|---|
| 3012 | //if( !(*(HMENU*)wndPtr->wExtra) )
|
|---|
| 3013 | // ERR("no menu to display\n");
|
|---|
| 3014 | }
|
|---|
| 3015 | else
|
|---|
| 3016 | SetWindowLongA(hwnd,0,0);
|
|---|
| 3017 | break;
|
|---|
| 3018 |
|
|---|
| 3019 | case MM_SETMENUHANDLE:
|
|---|
| 3020 |
|
|---|
| 3021 | SetWindowLongA(hwnd,0,wParam);
|
|---|
| 3022 | break;
|
|---|
| 3023 |
|
|---|
| 3024 | case MM_GETMENUHANDLE:
|
|---|
| 3025 |
|
|---|
| 3026 | retvalue = GetWindowLongA(hwnd,0);
|
|---|
| 3027 | goto END;
|
|---|
| 3028 |
|
|---|
| 3029 | default:
|
|---|
| 3030 | retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
|
|---|
| 3031 | goto END;
|
|---|
| 3032 | }
|
|---|
| 3033 | retvalue = 0;
|
|---|
| 3034 | END:
|
|---|
| 3035 | return retvalue;
|
|---|
| 3036 | }
|
|---|
| 3037 |
|
|---|
| 3038 |
|
|---|
| 3039 | /***********************************************************************
|
|---|
| 3040 | * MENU_GetMenuBarHeight
|
|---|
| 3041 | *
|
|---|
| 3042 | * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
|
|---|
| 3043 | */
|
|---|
| 3044 | UINT MENU_GetMenuBarHeight(HWND hwnd,UINT menubarWidth,INT orgX,INT orgY)
|
|---|
| 3045 | {
|
|---|
| 3046 | HDC hdc;
|
|---|
| 3047 | RECT rectBar;
|
|---|
| 3048 | LPPOPUPMENU lppop;
|
|---|
| 3049 | UINT retvalue;
|
|---|
| 3050 |
|
|---|
| 3051 | //TRACE("HWND 0x%x, width %d, at (%d, %d).\n",
|
|---|
| 3052 | // hwnd, menubarWidth, orgX, orgY );
|
|---|
| 3053 |
|
|---|
| 3054 | if (!(lppop = (LPPOPUPMENU)getMenu(hwnd)))
|
|---|
| 3055 | {
|
|---|
| 3056 | return 0;
|
|---|
| 3057 | }
|
|---|
| 3058 |
|
|---|
| 3059 | hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
|
|---|
| 3060 | SelectObject( hdc, hMenuFont);
|
|---|
| 3061 | SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+GetSystemMetrics(SM_CYMENU));
|
|---|
| 3062 | MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd );
|
|---|
| 3063 | ReleaseDC( hwnd, hdc );
|
|---|
| 3064 | retvalue = lppop->Height;
|
|---|
| 3065 | return retvalue;
|
|---|
| 3066 | }
|
|---|
| 3067 |
|
|---|
| 3068 |
|
|---|
| 3069 | /*******************************************************************
|
|---|
| 3070 | * ChangeMenu32A (USER32.23)
|
|---|
| 3071 | */
|
|---|
| 3072 | BOOL WINAPI ChangeMenuA( HMENU hMenu, UINT pos, LPCSTR data,
|
|---|
| 3073 | UINT id, UINT flags )
|
|---|
| 3074 | {
|
|---|
| 3075 | dprintf(("USER32: ChangeMenuA"));
|
|---|
| 3076 |
|
|---|
| 3077 | //TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
|
|---|
| 3078 | // hMenu, pos, (DWORD)data, id, flags );
|
|---|
| 3079 | if (flags & MF_APPEND) return AppendMenuA( hMenu, flags & ~MF_APPEND,
|
|---|
| 3080 | id, data );
|
|---|
| 3081 | if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
|
|---|
| 3082 | if (flags & MF_CHANGE) return ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE,
|
|---|
| 3083 | id, data );
|
|---|
| 3084 | if (flags & MF_REMOVE) return RemoveMenu( hMenu,
|
|---|
| 3085 | flags & MF_BYPOSITION ? pos : id,
|
|---|
| 3086 | flags & ~MF_REMOVE );
|
|---|
| 3087 | /* Default: MF_INSERT */
|
|---|
| 3088 | return InsertMenuA( hMenu, pos, flags, id, data );
|
|---|
| 3089 | }
|
|---|
| 3090 |
|
|---|
| 3091 |
|
|---|
| 3092 | /*******************************************************************
|
|---|
| 3093 | * ChangeMenu32W (USER32.24)
|
|---|
| 3094 | */
|
|---|
| 3095 | BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data,
|
|---|
| 3096 | UINT id, UINT flags )
|
|---|
| 3097 | {
|
|---|
| 3098 | dprintf(("USER32: ChangeMenuW"));
|
|---|
| 3099 |
|
|---|
| 3100 | //TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
|
|---|
| 3101 | // hMenu, pos, (DWORD)data, id, flags );
|
|---|
| 3102 | if (flags & MF_APPEND) return AppendMenuW( hMenu, flags & ~MF_APPEND,
|
|---|
| 3103 | id, data );
|
|---|
| 3104 | if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
|
|---|
| 3105 | if (flags & MF_CHANGE) return ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE,
|
|---|
| 3106 | id, data );
|
|---|
| 3107 | if (flags & MF_REMOVE) return RemoveMenu( hMenu,
|
|---|
| 3108 | flags & MF_BYPOSITION ? pos : id,
|
|---|
| 3109 | flags & ~MF_REMOVE );
|
|---|
| 3110 | /* Default: MF_INSERT */
|
|---|
| 3111 | return InsertMenuW( hMenu, pos, flags, id, data );
|
|---|
| 3112 | }
|
|---|
| 3113 |
|
|---|
| 3114 |
|
|---|
| 3115 | /*******************************************************************
|
|---|
| 3116 | * CheckMenuItem (USER32.46)
|
|---|
| 3117 | */
|
|---|
| 3118 | DWORD WINAPI CheckMenuItem( HMENU hMenu, UINT id, UINT flags )
|
|---|
| 3119 | {
|
|---|
| 3120 | MENUITEM *item;
|
|---|
| 3121 | DWORD ret;
|
|---|
| 3122 |
|
|---|
| 3123 | dprintf(("USER32: CheckMenuItem"));
|
|---|
| 3124 |
|
|---|
| 3125 | //TRACE("menu=%04x id=%04x flags=%04x\n", hMenu, id, flags );
|
|---|
| 3126 | if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1;
|
|---|
| 3127 | ret = item->fState & MF_CHECKED;
|
|---|
| 3128 | if (flags & MF_CHECKED) item->fState |= MF_CHECKED;
|
|---|
| 3129 | else item->fState &= ~MF_CHECKED;
|
|---|
| 3130 | return ret;
|
|---|
| 3131 | }
|
|---|
| 3132 |
|
|---|
| 3133 |
|
|---|
| 3134 | /**********************************************************************
|
|---|
| 3135 | * EnableMenuItem32 (USER32.170)
|
|---|
| 3136 | */
|
|---|
| 3137 | ULONG WINAPI EnableMenuItem( HMENU hMenu, UINT wItemID, UINT wFlags )
|
|---|
| 3138 | {
|
|---|
| 3139 | UINT oldflags;
|
|---|
| 3140 | MENUITEM *item;
|
|---|
| 3141 | POPUPMENU *menu;
|
|---|
| 3142 |
|
|---|
| 3143 | dprintf(("USER32: EnableMenuItem"));
|
|---|
| 3144 |
|
|---|
| 3145 | //TRACE("(%04x, %04X, %04X) !\n",
|
|---|
| 3146 | // hMenu, wItemID, wFlags);
|
|---|
| 3147 |
|
|---|
| 3148 | /* Get the Popupmenu to access the owner menu */
|
|---|
| 3149 | if (!(menu = (POPUPMENU*)hMenu))
|
|---|
| 3150 | return (UINT)-1;
|
|---|
| 3151 |
|
|---|
| 3152 | if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags )))
|
|---|
| 3153 | return (UINT)-1;
|
|---|
| 3154 |
|
|---|
| 3155 | oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
|
|---|
| 3156 | item->fState ^= (oldflags ^ wFlags) & (MF_GRAYED | MF_DISABLED);
|
|---|
| 3157 |
|
|---|
| 3158 | /* In win95 if the close item in the system menu change update the close button */
|
|---|
| 3159 | if((item->wID == SC_CLOSE) && (oldflags != wFlags))
|
|---|
| 3160 | {
|
|---|
| 3161 | if (menu->hSysMenuOwner != 0)
|
|---|
| 3162 | {
|
|---|
| 3163 | POPUPMENU* parentMenu;
|
|---|
| 3164 |
|
|---|
| 3165 | /* Get the parent menu to access*/
|
|---|
| 3166 | if (!(parentMenu = (POPUPMENU*)menu->hSysMenuOwner))
|
|---|
| 3167 | return (UINT)-1;
|
|---|
| 3168 |
|
|---|
| 3169 | /* Refresh the frame to reflect the change*/
|
|---|
| 3170 | SetWindowPos(parentMenu->hWnd, 0, 0, 0, 0, 0,
|
|---|
| 3171 | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
|
|---|
| 3172 | }
|
|---|
| 3173 | }
|
|---|
| 3174 |
|
|---|
| 3175 | return oldflags;
|
|---|
| 3176 | }
|
|---|
| 3177 |
|
|---|
| 3178 |
|
|---|
| 3179 | /*******************************************************************
|
|---|
| 3180 | * GetMenuString32A (USER32.268)
|
|---|
| 3181 | */
|
|---|
| 3182 | INT WINAPI GetMenuStringA( HMENU hMenu, UINT wItemID,
|
|---|
| 3183 | LPSTR str, INT nMaxSiz, UINT wFlags )
|
|---|
| 3184 | {
|
|---|
| 3185 | MENUITEM *item;
|
|---|
| 3186 |
|
|---|
| 3187 | dprintf(("USER32: GetMenuStringA"));
|
|---|
| 3188 |
|
|---|
| 3189 | //TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
|
|---|
| 3190 | // hMenu, wItemID, str, nMaxSiz, wFlags );
|
|---|
| 3191 | if (!str || !nMaxSiz) return 0;
|
|---|
| 3192 | str[0] = '\0';
|
|---|
| 3193 | if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
|
|---|
| 3194 | if (!IS_STRING_ITEM(item->fType)) return 0;
|
|---|
| 3195 | lstrcpynA( str, item->text, nMaxSiz );
|
|---|
| 3196 | //TRACE("returning '%s'\n", str );
|
|---|
| 3197 | return strlen(str);
|
|---|
| 3198 | }
|
|---|
| 3199 |
|
|---|
| 3200 |
|
|---|
| 3201 | /*******************************************************************
|
|---|
| 3202 | * GetMenuString32W (USER32.269)
|
|---|
| 3203 | */
|
|---|
| 3204 | INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID,
|
|---|
| 3205 | LPWSTR str, INT nMaxSiz, UINT wFlags )
|
|---|
| 3206 | {
|
|---|
| 3207 | MENUITEM *item;
|
|---|
| 3208 |
|
|---|
| 3209 | dprintf(("USER32: GetMenuStringW"));
|
|---|
| 3210 |
|
|---|
| 3211 | //TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
|
|---|
| 3212 | // hMenu, wItemID, str, nMaxSiz, wFlags );
|
|---|
| 3213 | if (!str || !nMaxSiz) return 0;
|
|---|
| 3214 | str[0] = '\0';
|
|---|
| 3215 | if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
|
|---|
| 3216 | if (!IS_STRING_ITEM(item->fType)) return 0;
|
|---|
| 3217 | lstrcpynAtoW( str, item->text, nMaxSiz );
|
|---|
| 3218 | return lstrlenW(str);
|
|---|
| 3219 | }
|
|---|
| 3220 |
|
|---|
| 3221 |
|
|---|
| 3222 | /**********************************************************************
|
|---|
| 3223 | * HiliteMenuItem32 (USER32.318)
|
|---|
| 3224 | */
|
|---|
| 3225 | BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID,
|
|---|
| 3226 | UINT wHilite )
|
|---|
| 3227 | {
|
|---|
| 3228 | LPPOPUPMENU menu;
|
|---|
| 3229 |
|
|---|
| 3230 | dprintf(("USER32: HiliteMenuItem"));
|
|---|
| 3231 |
|
|---|
| 3232 | //TRACE("(%04x, %04x, %04x, %04x);\n",
|
|---|
| 3233 | // hWnd, hMenu, wItemID, wHilite);
|
|---|
| 3234 | if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE;
|
|---|
| 3235 | if (!(menu = (LPPOPUPMENU)hMenu)) return FALSE;
|
|---|
| 3236 | if (menu->FocusedItem == wItemID) return TRUE;
|
|---|
| 3237 | MENU_HideSubPopups( hWnd, hMenu, FALSE );
|
|---|
| 3238 | MENU_SelectItem( hWnd, hMenu, wItemID, TRUE, 0 );
|
|---|
| 3239 | return TRUE;
|
|---|
| 3240 | }
|
|---|
| 3241 |
|
|---|
| 3242 |
|
|---|
| 3243 | /**********************************************************************
|
|---|
| 3244 | * GetMenuState (USER32.267)
|
|---|
| 3245 | */
|
|---|
| 3246 | UINT WINAPI GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags )
|
|---|
| 3247 | {
|
|---|
| 3248 | MENUITEM *item;
|
|---|
| 3249 |
|
|---|
| 3250 | dprintf(("USER32: GetMenuState %d %d",wItemID,wFlags));
|
|---|
| 3251 |
|
|---|
| 3252 | //TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
|
|---|
| 3253 | // hMenu, wItemID, wFlags);
|
|---|
| 3254 |
|
|---|
| 3255 | if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
|
|---|
| 3256 |
|
|---|
| 3257 | //debug_print_menuitem (" item: ", item, "");
|
|---|
| 3258 | if (item->fType & MF_POPUP)
|
|---|
| 3259 | {
|
|---|
| 3260 | POPUPMENU *menu = (POPUPMENU*)item->hSubMenu;
|
|---|
| 3261 | if (!menu) return -1;
|
|---|
| 3262 | else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
|
|---|
| 3263 | }
|
|---|
| 3264 | else
|
|---|
| 3265 | {
|
|---|
| 3266 | /* We used to (from way back then) mask the result to 0xff. */
|
|---|
| 3267 | /* I don't know why and it seems wrong as the documented */
|
|---|
| 3268 | /* return flag MF_SEPARATOR is outside that mask. */
|
|---|
| 3269 | return (item->fType | item->fState);
|
|---|
| 3270 | }
|
|---|
| 3271 | }
|
|---|
| 3272 |
|
|---|
| 3273 |
|
|---|
| 3274 | /**********************************************************************
|
|---|
| 3275 | * GetMenuItemCount32 (USER32.262)
|
|---|
| 3276 | */
|
|---|
| 3277 | INT WINAPI GetMenuItemCount( HMENU hMenu )
|
|---|
| 3278 | {
|
|---|
| 3279 | LPPOPUPMENU menu = (LPPOPUPMENU)hMenu;
|
|---|
| 3280 |
|
|---|
| 3281 | dprintf(("USER32: GetMenuItemCount"));
|
|---|
| 3282 |
|
|---|
| 3283 | if (!IS_A_MENU(menu)) return -1;
|
|---|
| 3284 | //TRACE("(%04x) returning %d\n",
|
|---|
| 3285 | // hMenu, menu->nItems );
|
|---|
| 3286 | return menu->nItems;
|
|---|
| 3287 | }
|
|---|
| 3288 |
|
|---|
| 3289 | /**********************************************************************
|
|---|
| 3290 | * GetMenuItemID32 (USER32.263)
|
|---|
| 3291 | */
|
|---|
| 3292 | UINT WINAPI GetMenuItemID( HMENU hMenu, INT nPos )
|
|---|
| 3293 | {
|
|---|
| 3294 | MENUITEM * lpmi;
|
|---|
| 3295 |
|
|---|
| 3296 | dprintf(("USER32: GetMenuItemID"));
|
|---|
| 3297 |
|
|---|
| 3298 | if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return 0;
|
|---|
| 3299 | if (lpmi->fType & MF_POPUP) return -1;
|
|---|
| 3300 | return lpmi->wID;
|
|---|
| 3301 |
|
|---|
| 3302 | }
|
|---|
| 3303 |
|
|---|
| 3304 | /*******************************************************************
|
|---|
| 3305 | * InsertMenu32A (USER32.322)
|
|---|
| 3306 | */
|
|---|
| 3307 | BOOL WINAPI InsertMenuA( HMENU hMenu, UINT pos, UINT flags,
|
|---|
| 3308 | UINT id, LPCSTR str )
|
|---|
| 3309 | {
|
|---|
| 3310 | MENUITEM *item;
|
|---|
| 3311 |
|
|---|
| 3312 | dprintf(("USER32: InsertMenuA"));
|
|---|
| 3313 |
|
|---|
| 3314 | //if (IS_STRING_ITEM(flags) && str)
|
|---|
| 3315 | // TRACE("hMenu %04x, pos %d, flags %08x, "
|
|---|
| 3316 | // "id %04x, str '%s'\n",
|
|---|
| 3317 | // hMenu, pos, flags, id, str );
|
|---|
| 3318 | //else TRACE("hMenu %04x, pos %d, flags %08x, "
|
|---|
| 3319 | // "id %04x, str %08lx (not a string)\n",
|
|---|
| 3320 | // hMenu, pos, flags, id, (DWORD)str );
|
|---|
| 3321 |
|
|---|
| 3322 | if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
|
|---|
| 3323 |
|
|---|
| 3324 | if (!(MENU_SetItemData( item, flags, id, str )))
|
|---|
| 3325 | {
|
|---|
| 3326 | RemoveMenu( hMenu, pos, flags );
|
|---|
| 3327 | return FALSE;
|
|---|
| 3328 | }
|
|---|
| 3329 |
|
|---|
| 3330 | if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */
|
|---|
| 3331 | ((POPUPMENU *)(HMENU)id)->wFlags |= MF_POPUP;
|
|---|
| 3332 |
|
|---|
| 3333 | item->hCheckBit = item->hUnCheckBit = 0;
|
|---|
| 3334 | return TRUE;
|
|---|
| 3335 | }
|
|---|
| 3336 |
|
|---|
| 3337 |
|
|---|
| 3338 | /*******************************************************************
|
|---|
| 3339 | * InsertMenu32W (USER32.325)
|
|---|
| 3340 | */
|
|---|
| 3341 | BOOL WINAPI InsertMenuW( HMENU hMenu, UINT pos, UINT flags,
|
|---|
| 3342 | UINT id, LPCWSTR str )
|
|---|
| 3343 | {
|
|---|
| 3344 | BOOL ret;
|
|---|
| 3345 |
|
|---|
| 3346 | dprintf(("USER32: InsertMenuW"));
|
|---|
| 3347 |
|
|---|
| 3348 | if (IS_STRING_ITEM(flags) && str)
|
|---|
| 3349 | {
|
|---|
| 3350 | LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
|
|---|
| 3351 | ret = InsertMenuA( hMenu, pos, flags, id, newstr );
|
|---|
| 3352 | HeapFree( GetProcessHeap(), 0, newstr );
|
|---|
| 3353 | return ret;
|
|---|
| 3354 | }
|
|---|
| 3355 | else return InsertMenuA( hMenu, pos, flags, id, (LPCSTR)str );
|
|---|
| 3356 | }
|
|---|
| 3357 |
|
|---|
| 3358 |
|
|---|
| 3359 | /*******************************************************************
|
|---|
| 3360 | * AppendMenu32A (USER32.5)
|
|---|
| 3361 | */
|
|---|
| 3362 | BOOL WINAPI AppendMenuA( HMENU hMenu, UINT flags,
|
|---|
| 3363 | UINT id, LPCSTR data )
|
|---|
| 3364 | {
|
|---|
| 3365 | dprintf(("USER32: AppendMenuA"));
|
|---|
| 3366 |
|
|---|
| 3367 | return InsertMenuA( hMenu, -1, flags | MF_BYPOSITION, id, data );
|
|---|
| 3368 | }
|
|---|
| 3369 |
|
|---|
| 3370 |
|
|---|
| 3371 | /*******************************************************************
|
|---|
| 3372 | * AppendMenu32W (USER32.6)
|
|---|
| 3373 | */
|
|---|
| 3374 | BOOL WINAPI AppendMenuW( HMENU hMenu, UINT flags,
|
|---|
| 3375 | UINT id, LPCWSTR data )
|
|---|
| 3376 | {
|
|---|
| 3377 | dprintf(("USER32: AppendMenuW"));
|
|---|
| 3378 |
|
|---|
| 3379 | return InsertMenuW( hMenu, -1, flags | MF_BYPOSITION, id, data );
|
|---|
| 3380 | }
|
|---|
| 3381 |
|
|---|
| 3382 |
|
|---|
| 3383 | /**********************************************************************
|
|---|
| 3384 | * RemoveMenu (USER32.441)
|
|---|
| 3385 | */
|
|---|
| 3386 | BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags )
|
|---|
| 3387 | {
|
|---|
| 3388 | LPPOPUPMENU menu;
|
|---|
| 3389 | MENUITEM *item;
|
|---|
| 3390 |
|
|---|
| 3391 | dprintf(("USER32: RemoveMenu"));
|
|---|
| 3392 |
|
|---|
| 3393 | //TRACE("(menu=%04x pos=%04x flags=%04x)\n",hMenu, nPos, wFlags);
|
|---|
| 3394 | if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
|
|---|
| 3395 | if (!(menu = (LPPOPUPMENU)hMenu)) return FALSE;
|
|---|
| 3396 |
|
|---|
| 3397 | /* Remove item */
|
|---|
| 3398 |
|
|---|
| 3399 | MENU_FreeItemData( item );
|
|---|
| 3400 |
|
|---|
| 3401 | if (--menu->nItems == 0)
|
|---|
| 3402 | {
|
|---|
| 3403 | HeapFree(GetProcessHeap(), 0, menu->items );
|
|---|
| 3404 | menu->items = NULL;
|
|---|
| 3405 | }
|
|---|
| 3406 | else
|
|---|
| 3407 | {
|
|---|
| 3408 | while(nPos < menu->nItems)
|
|---|
| 3409 | {
|
|---|
| 3410 | *item = *(item+1);
|
|---|
| 3411 | item++;
|
|---|
| 3412 | nPos++;
|
|---|
| 3413 | }
|
|---|
| 3414 | menu->items = (MENUITEM*)HeapReAlloc(GetProcessHeap(), 0, menu->items,
|
|---|
| 3415 | menu->nItems * sizeof(MENUITEM) );
|
|---|
| 3416 | }
|
|---|
| 3417 | return TRUE;
|
|---|
| 3418 | }
|
|---|
| 3419 |
|
|---|
| 3420 |
|
|---|
| 3421 | /**********************************************************************
|
|---|
| 3422 | * DeleteMenu32 (USER32.129)
|
|---|
| 3423 | */
|
|---|
| 3424 | BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags )
|
|---|
| 3425 | {
|
|---|
| 3426 | MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
|
|---|
| 3427 |
|
|---|
| 3428 | dprintf(("USER32: DeleteMenu"));
|
|---|
| 3429 |
|
|---|
| 3430 | if (!item) return FALSE;
|
|---|
| 3431 | if (item->fType & MF_POPUP) DestroyMenu( item->hSubMenu );
|
|---|
| 3432 | /* nPos is now the position of the item */
|
|---|
| 3433 | RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION );
|
|---|
| 3434 | return TRUE;
|
|---|
| 3435 | }
|
|---|
| 3436 |
|
|---|
| 3437 |
|
|---|
| 3438 | /*******************************************************************
|
|---|
| 3439 | * ModifyMenu32A (USER32.397)
|
|---|
| 3440 | */
|
|---|
| 3441 | BOOL WINAPI ModifyMenuA( HMENU hMenu, UINT pos, UINT flags,
|
|---|
| 3442 | UINT id, LPCSTR str )
|
|---|
| 3443 | {
|
|---|
| 3444 | MENUITEM *item;
|
|---|
| 3445 |
|
|---|
| 3446 | dprintf(("USER32: ModifyMenuA"));
|
|---|
| 3447 |
|
|---|
| 3448 | if (IS_STRING_ITEM(flags))
|
|---|
| 3449 | {
|
|---|
| 3450 | //TRACE("%04x %d %04x %04x '%s'\n",
|
|---|
| 3451 | // hMenu, pos, flags, id, str ? str : "#NULL#" );
|
|---|
| 3452 | if (!str) return FALSE;
|
|---|
| 3453 | }
|
|---|
| 3454 | else
|
|---|
| 3455 | {
|
|---|
| 3456 | //TRACE("%04x %d %04x %04x %08lx\n",
|
|---|
| 3457 | // hMenu, pos, flags, id, (DWORD)str );
|
|---|
| 3458 | }
|
|---|
| 3459 |
|
|---|
| 3460 | if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) return FALSE;
|
|---|
| 3461 | return MENU_SetItemData( item, flags, id, str );
|
|---|
| 3462 | }
|
|---|
| 3463 |
|
|---|
| 3464 |
|
|---|
| 3465 | /*******************************************************************
|
|---|
| 3466 | * ModifyMenu32W (USER32.398)
|
|---|
| 3467 | */
|
|---|
| 3468 | BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags,
|
|---|
| 3469 | UINT id, LPCWSTR str )
|
|---|
| 3470 | {
|
|---|
| 3471 | BOOL ret;
|
|---|
| 3472 |
|
|---|
| 3473 | dprintf(("USER32: ModifyMenuW"));
|
|---|
| 3474 |
|
|---|
| 3475 | if (IS_STRING_ITEM(flags) && str)
|
|---|
| 3476 | {
|
|---|
| 3477 | LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
|
|---|
| 3478 | ret = ModifyMenuA( hMenu, pos, flags, id, newstr );
|
|---|
| 3479 | HeapFree( GetProcessHeap(), 0, newstr );
|
|---|
| 3480 | return ret;
|
|---|
| 3481 | }
|
|---|
| 3482 | else return ModifyMenuA( hMenu, pos, flags, id, (LPCSTR)str );
|
|---|
| 3483 | }
|
|---|
| 3484 |
|
|---|
| 3485 |
|
|---|
| 3486 | /**********************************************************************
|
|---|
| 3487 | * CreatePopupMenu32 (USER32.82)
|
|---|
| 3488 | */
|
|---|
| 3489 | HMENU WINAPI CreatePopupMenu(void)
|
|---|
| 3490 | {
|
|---|
| 3491 | HMENU hmenu;
|
|---|
| 3492 | POPUPMENU *menu;
|
|---|
| 3493 |
|
|---|
| 3494 | dprintf(("USER32: CreatePopupMenu"));
|
|---|
| 3495 |
|
|---|
| 3496 | if (!(hmenu = CreateMenu())) return 0;
|
|---|
| 3497 | menu = (POPUPMENU*)hmenu;
|
|---|
| 3498 | menu->wFlags |= MF_POPUP;
|
|---|
| 3499 | menu->bTimeToHide = FALSE;
|
|---|
| 3500 | return hmenu;
|
|---|
| 3501 | }
|
|---|
| 3502 |
|
|---|
| 3503 |
|
|---|
| 3504 | /**********************************************************************
|
|---|
| 3505 | * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
|
|---|
| 3506 | */
|
|---|
| 3507 | DWORD WINAPI GetMenuCheckMarkDimensions(void)
|
|---|
| 3508 | {
|
|---|
| 3509 | dprintf(("USER32: GetMenuCheckMarkDimensions"));
|
|---|
| 3510 |
|
|---|
| 3511 | return MAKELONG( check_bitmap_width, check_bitmap_height );
|
|---|
| 3512 | }
|
|---|
| 3513 |
|
|---|
| 3514 |
|
|---|
| 3515 | /**********************************************************************
|
|---|
| 3516 | * SetMenuItemBitmaps32 (USER32.490)
|
|---|
| 3517 | */
|
|---|
| 3518 | BOOL WINAPI SetMenuItemBitmaps( HMENU hMenu, UINT nPos, UINT wFlags,
|
|---|
| 3519 | HBITMAP hNewUnCheck, HBITMAP hNewCheck)
|
|---|
| 3520 | {
|
|---|
| 3521 | MENUITEM *item;
|
|---|
| 3522 |
|
|---|
| 3523 | dprintf(("USER32: SetMenuItemBitmaps"));
|
|---|
| 3524 |
|
|---|
| 3525 | //TRACE("(%04x, %04x, %04x, %04x, %04x)\n",
|
|---|
| 3526 | // hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
|
|---|
| 3527 | if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
|
|---|
| 3528 |
|
|---|
| 3529 | if (!hNewCheck && !hNewUnCheck)
|
|---|
| 3530 | {
|
|---|
| 3531 | item->fState &= ~MF_USECHECKBITMAPS;
|
|---|
| 3532 | }
|
|---|
| 3533 | else /* Install new bitmaps */
|
|---|
| 3534 | {
|
|---|
| 3535 | item->hCheckBit = hNewCheck;
|
|---|
| 3536 | item->hUnCheckBit = hNewUnCheck;
|
|---|
| 3537 | item->fState |= MF_USECHECKBITMAPS;
|
|---|
| 3538 | }
|
|---|
| 3539 | return TRUE;
|
|---|
| 3540 | }
|
|---|
| 3541 |
|
|---|
| 3542 |
|
|---|
| 3543 | /**********************************************************************
|
|---|
| 3544 | * CreateMenu (USER32.81)
|
|---|
| 3545 | */
|
|---|
| 3546 | HMENU WINAPI CreateMenu(void)
|
|---|
| 3547 | {
|
|---|
| 3548 | HMENU hMenu;
|
|---|
| 3549 | LPPOPUPMENU menu;
|
|---|
| 3550 |
|
|---|
| 3551 | dprintf(("USER32: CreateMenu"));
|
|---|
| 3552 |
|
|---|
| 3553 | if (!(hMenu = (HMENU)HeapAlloc(GetProcessHeap(),0,sizeof(POPUPMENU)))) return 0;
|
|---|
| 3554 | menu = (LPPOPUPMENU)hMenu;
|
|---|
| 3555 |
|
|---|
| 3556 | ZeroMemory(menu, sizeof(POPUPMENU));
|
|---|
| 3557 | menu->wMagic = MENU_MAGIC;
|
|---|
| 3558 | menu->FocusedItem = NO_SELECTED_ITEM;
|
|---|
| 3559 | menu->bTimeToHide = FALSE;
|
|---|
| 3560 |
|
|---|
| 3561 | //TRACE("return %04x\n", hMenu );
|
|---|
| 3562 |
|
|---|
| 3563 | return hMenu;
|
|---|
| 3564 | }
|
|---|
| 3565 |
|
|---|
| 3566 |
|
|---|
| 3567 | /**********************************************************************
|
|---|
| 3568 | * DestroyMenu32 (USER32.134)
|
|---|
| 3569 | */
|
|---|
| 3570 | BOOL WINAPI DestroyMenu( HMENU hMenu )
|
|---|
| 3571 | {
|
|---|
| 3572 | //TRACE("(%04x)\n", hMenu);
|
|---|
| 3573 |
|
|---|
| 3574 | dprintf(("USER32: DestroyMenu"));
|
|---|
| 3575 |
|
|---|
| 3576 | /* Silently ignore attempts to destroy default system popup */
|
|---|
| 3577 |
|
|---|
| 3578 | if (hMenu && hMenu != MENU_DefSysPopup)
|
|---|
| 3579 | {
|
|---|
| 3580 | LPPOPUPMENU lppop = (LPPOPUPMENU)hMenu;
|
|---|
| 3581 | HWND pTPWnd = MENU_GetTopPopupWnd();
|
|---|
| 3582 |
|
|---|
| 3583 | if( pTPWnd && (hMenu == GetWindowLongA(pTPWnd,0)) )
|
|---|
| 3584 | SetWindowLongA(pTPWnd,0,0);
|
|---|
| 3585 |
|
|---|
| 3586 | if (IS_A_MENU( lppop ))
|
|---|
| 3587 | {
|
|---|
| 3588 | lppop->wMagic = 0; /* Mark it as destroyed */
|
|---|
| 3589 |
|
|---|
| 3590 | if ((lppop->wFlags & MF_POPUP) && lppop->hWnd &&
|
|---|
| 3591 | (!pTPWnd || (lppop->hWnd != pTPWnd)))
|
|---|
| 3592 | DestroyWindow( lppop->hWnd );
|
|---|
| 3593 |
|
|---|
| 3594 | if (lppop->items) /* recursively destroy submenus */
|
|---|
| 3595 | {
|
|---|
| 3596 | int i;
|
|---|
| 3597 | MENUITEM *item = lppop->items;
|
|---|
| 3598 | for (i = lppop->nItems; i > 0; i--, item++)
|
|---|
| 3599 | {
|
|---|
| 3600 | if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu);
|
|---|
| 3601 | MENU_FreeItemData( item );
|
|---|
| 3602 | }
|
|---|
| 3603 | HeapFree(GetProcessHeap(), 0, lppop->items );
|
|---|
| 3604 | }
|
|---|
| 3605 | HeapFree(GetProcessHeap(),0,(LPVOID)hMenu);
|
|---|
| 3606 | MENU_ReleaseTopPopupWnd();
|
|---|
| 3607 | }
|
|---|
| 3608 | else
|
|---|
| 3609 | {
|
|---|
| 3610 | MENU_ReleaseTopPopupWnd();
|
|---|
| 3611 | return FALSE;
|
|---|
| 3612 | }
|
|---|
| 3613 | }
|
|---|
| 3614 | return (hMenu != MENU_DefSysPopup);
|
|---|
| 3615 | }
|
|---|
| 3616 |
|
|---|
| 3617 | /**********************************************************************
|
|---|
| 3618 | * GetSystemMenu32 (USER32.291)
|
|---|
| 3619 | */
|
|---|
| 3620 | HMENU WINAPI GetSystemMenu( HWND hWnd, BOOL bRevert )
|
|---|
| 3621 | {
|
|---|
| 3622 | HMENU retvalue = 0;
|
|---|
| 3623 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hWnd);
|
|---|
| 3624 |
|
|---|
| 3625 | dprintf(("USER32: GetSystemMenu"));
|
|---|
| 3626 |
|
|---|
| 3627 | if (win32wnd)
|
|---|
| 3628 | {
|
|---|
| 3629 | HMENU hSysMenu = getSysMenu(hWnd);
|
|---|
| 3630 | if(hSysMenu)
|
|---|
| 3631 | {
|
|---|
| 3632 | if( bRevert )
|
|---|
| 3633 | {
|
|---|
| 3634 | DestroyMenu(hSysMenu);
|
|---|
| 3635 | hSysMenu = 0;
|
|---|
| 3636 | setSysMenu(hWnd,hSysMenu);
|
|---|
| 3637 | }
|
|---|
| 3638 | else
|
|---|
| 3639 | {
|
|---|
| 3640 | POPUPMENU *menu = (POPUPMENU*)hSysMenu;
|
|---|
| 3641 | if( IS_A_MENU(menu) )
|
|---|
| 3642 | {
|
|---|
| 3643 | if( menu->nItems > 0 && menu->items[0].hSubMenu == MENU_DefSysPopup )
|
|---|
| 3644 | menu->items[0].hSubMenu = MENU_CopySysPopup();
|
|---|
| 3645 | }
|
|---|
| 3646 | else
|
|---|
| 3647 | {
|
|---|
| 3648 | //WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
|
|---|
| 3649 | // wndPtr->hSysMenu, hWnd);
|
|---|
| 3650 | hSysMenu = 0;
|
|---|
| 3651 | setSysMenu(hWnd,hSysMenu);
|
|---|
| 3652 | }
|
|---|
| 3653 | }
|
|---|
| 3654 | }
|
|---|
| 3655 |
|
|---|
| 3656 | if(!hSysMenu && (GetWindowLongA(hWnd,GWL_STYLE) & WS_SYSMENU) )
|
|---|
| 3657 | {
|
|---|
| 3658 | hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
|
|---|
| 3659 | setSysMenu(hWnd,hSysMenu);
|
|---|
| 3660 | }
|
|---|
| 3661 |
|
|---|
| 3662 | if( hSysMenu )
|
|---|
| 3663 | {
|
|---|
| 3664 | POPUPMENU *menu;
|
|---|
| 3665 | retvalue = GetSubMenu(hSysMenu, 0);
|
|---|
| 3666 |
|
|---|
| 3667 | /* Store the dummy sysmenu handle to facilitate the refresh */
|
|---|
| 3668 | /* of the close button if the SC_CLOSE item change */
|
|---|
| 3669 | menu = (POPUPMENU*)retvalue;
|
|---|
| 3670 | if ( IS_A_MENU(menu) )
|
|---|
| 3671 | menu->hSysMenuOwner = hSysMenu;
|
|---|
| 3672 | }
|
|---|
| 3673 | }
|
|---|
| 3674 | return retvalue;
|
|---|
| 3675 | }
|
|---|
| 3676 |
|
|---|
| 3677 |
|
|---|
| 3678 | /*******************************************************************
|
|---|
| 3679 | * SetSystemMenu32 (USER32.508)
|
|---|
| 3680 | */
|
|---|
| 3681 | BOOL WINAPI SetSystemMenu( HWND hwnd, HMENU hMenu )
|
|---|
| 3682 | {
|
|---|
| 3683 | Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 3684 |
|
|---|
| 3685 | dprintf(("USER32: SetSystemMenu"));
|
|---|
| 3686 |
|
|---|
| 3687 | if (win32wnd)
|
|---|
| 3688 | {
|
|---|
| 3689 | if (win32wnd->GetSysMenu()) DestroyMenu(win32wnd->GetSysMenu());
|
|---|
| 3690 | win32wnd->SetSysMenu(MENU_GetSysMenu( hwnd, hMenu ));
|
|---|
| 3691 | return TRUE;
|
|---|
| 3692 | }
|
|---|
| 3693 | return FALSE;
|
|---|
| 3694 | }
|
|---|
| 3695 |
|
|---|
| 3696 | /**********************************************************************
|
|---|
| 3697 | * GetMenu32 (USER32.257)
|
|---|
| 3698 | */
|
|---|
| 3699 | HMENU WINAPI GetMenu( HWND hWnd )
|
|---|
| 3700 | {
|
|---|
| 3701 | HMENU retvalue;
|
|---|
| 3702 |
|
|---|
| 3703 | dprintf(("USER32: GetMenu"));
|
|---|
| 3704 |
|
|---|
| 3705 | if (GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD) return 0;
|
|---|
| 3706 | else return getMenu(hWnd);
|
|---|
| 3707 | }
|
|---|
| 3708 |
|
|---|
| 3709 | /**********************************************************************
|
|---|
| 3710 | * SetMenu32 (USER32.487)
|
|---|
| 3711 | */
|
|---|
| 3712 | BOOL WINAPI SetMenu( HWND hWnd, HMENU hMenu )
|
|---|
| 3713 | {
|
|---|
| 3714 | //TRACE("(%04x, %04x);\n", hWnd, hMenu);
|
|---|
| 3715 |
|
|---|
| 3716 | dprintf(("USER32: SetMenu"));
|
|---|
| 3717 |
|
|---|
| 3718 | if (hMenu && !IsMenu(hMenu))
|
|---|
| 3719 | {
|
|---|
| 3720 | //WARN("hMenu is not a menu handle\n");
|
|---|
| 3721 | return FALSE;
|
|---|
| 3722 | }
|
|---|
| 3723 |
|
|---|
| 3724 |
|
|---|
| 3725 | if (!(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD))
|
|---|
| 3726 | {
|
|---|
| 3727 | if (GetCapture() == hWnd) ReleaseCapture();
|
|---|
| 3728 |
|
|---|
| 3729 | setMenu(hWnd,hMenu);
|
|---|
| 3730 | if (hMenu != 0)
|
|---|
| 3731 | {
|
|---|
| 3732 | LPPOPUPMENU lpmenu;
|
|---|
| 3733 |
|
|---|
| 3734 | if (!(lpmenu = (LPPOPUPMENU)hMenu))
|
|---|
| 3735 | {
|
|---|
| 3736 | return FALSE;
|
|---|
| 3737 | }
|
|---|
| 3738 | lpmenu->hWnd = hWnd;
|
|---|
| 3739 | lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */
|
|---|
| 3740 | lpmenu->Height = 0; /* Make sure we recalculate the size */
|
|---|
| 3741 | }
|
|---|
| 3742 | if (IsWindowVisible(hWnd))
|
|---|
| 3743 | SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
|
|---|
| 3744 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
|
|---|
| 3745 | return TRUE;
|
|---|
| 3746 | }
|
|---|
| 3747 | return FALSE;
|
|---|
| 3748 | }
|
|---|
| 3749 |
|
|---|
| 3750 |
|
|---|
| 3751 | /**********************************************************************
|
|---|
| 3752 | * GetSubMenu32 (USER32.288)
|
|---|
| 3753 | */
|
|---|
| 3754 | HMENU WINAPI GetSubMenu( HMENU hMenu, INT nPos )
|
|---|
| 3755 | {
|
|---|
| 3756 | MENUITEM * lpmi;
|
|---|
| 3757 |
|
|---|
| 3758 | dprintf(("USER32: GetSubMenu"));
|
|---|
| 3759 |
|
|---|
| 3760 | if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return 0;
|
|---|
| 3761 | if (!(lpmi->fType & MF_POPUP)) return 0;
|
|---|
| 3762 | return lpmi->hSubMenu;
|
|---|
| 3763 | }
|
|---|
| 3764 |
|
|---|
| 3765 |
|
|---|
| 3766 | /**********************************************************************
|
|---|
| 3767 | * DrawMenuBar (USER32.161)
|
|---|
| 3768 | */
|
|---|
| 3769 | BOOL WINAPI DrawMenuBar( HWND hWnd )
|
|---|
| 3770 | {
|
|---|
| 3771 | LPPOPUPMENU lppop;
|
|---|
| 3772 |
|
|---|
| 3773 | dprintf(("USER32: DrawMenuBar"));
|
|---|
| 3774 |
|
|---|
| 3775 | if (!(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD) && getMenu(hWnd))
|
|---|
| 3776 | {
|
|---|
| 3777 | lppop = (LPPOPUPMENU)getMenu(hWnd);
|
|---|
| 3778 | if (lppop == NULL)
|
|---|
| 3779 | {
|
|---|
| 3780 | return FALSE;
|
|---|
| 3781 | }
|
|---|
| 3782 |
|
|---|
| 3783 | lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */
|
|---|
| 3784 | lppop->hwndOwner = hWnd;
|
|---|
| 3785 | SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
|
|---|
| 3786 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
|
|---|
| 3787 | return TRUE;
|
|---|
| 3788 | }
|
|---|
| 3789 | return FALSE;
|
|---|
| 3790 | }
|
|---|
| 3791 |
|
|---|
| 3792 |
|
|---|
| 3793 | /***********************************************************************
|
|---|
| 3794 | * EndMenu (USER.187) (USER32.175)
|
|---|
| 3795 | */
|
|---|
| 3796 | void WINAPI EndMenu(void)
|
|---|
| 3797 | {
|
|---|
| 3798 | dprintf(("USER32: EndMenu not implemented!"));
|
|---|
| 3799 | /*
|
|---|
| 3800 | * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
|
|---|
| 3801 | */
|
|---|
| 3802 |
|
|---|
| 3803 | fEndMenu = TRUE;
|
|---|
| 3804 | }
|
|---|
| 3805 |
|
|---|
| 3806 |
|
|---|
| 3807 | /*****************************************************************
|
|---|
| 3808 | * LoadMenu32A (USER32.370)
|
|---|
| 3809 | */
|
|---|
| 3810 | HMENU WINAPI LoadMenuA( HINSTANCE instance, LPCSTR name )
|
|---|
| 3811 | {
|
|---|
| 3812 | HRSRC hrsrc = FindResourceA( instance, name, RT_MENUA );
|
|---|
| 3813 |
|
|---|
| 3814 | dprintf(("USER32: LoadMenuA"));
|
|---|
| 3815 |
|
|---|
| 3816 | if (!hrsrc) return 0;
|
|---|
| 3817 | return LoadMenuIndirectA( (MENUITEMTEMPLATEHEADER*)LoadResource( instance, hrsrc ));
|
|---|
| 3818 | }
|
|---|
| 3819 |
|
|---|
| 3820 |
|
|---|
| 3821 | /*****************************************************************
|
|---|
| 3822 | * LoadMenu32W (USER32.373)
|
|---|
| 3823 | */
|
|---|
| 3824 | HMENU WINAPI LoadMenuW( HINSTANCE instance, LPCWSTR name )
|
|---|
| 3825 | {
|
|---|
| 3826 | HRSRC hrsrc = FindResourceW( instance, name, RT_MENUW );
|
|---|
| 3827 |
|
|---|
| 3828 | dprintf(("USER32: LoadMenuW"));
|
|---|
| 3829 |
|
|---|
| 3830 | if (!hrsrc) return 0;
|
|---|
| 3831 | return LoadMenuIndirectW( (MENUITEMTEMPLATEHEADER*)LoadResource( instance, hrsrc ));
|
|---|
| 3832 | }
|
|---|
| 3833 |
|
|---|
| 3834 |
|
|---|
| 3835 | /**********************************************************************
|
|---|
| 3836 | * LoadMenuIndirect32A (USER32.371)
|
|---|
| 3837 | */
|
|---|
| 3838 | HMENU WINAPI LoadMenuIndirectA(CONST MENUITEMTEMPLATEHEADER *lpMenuTemplate)
|
|---|
| 3839 | {
|
|---|
| 3840 | HMENU hMenu;
|
|---|
| 3841 | WORD version, offset;
|
|---|
| 3842 | LPCSTR p = (LPCSTR)lpMenuTemplate;
|
|---|
| 3843 |
|
|---|
| 3844 | dprintf(("USER32: LoadMenuIndirectA"));
|
|---|
| 3845 |
|
|---|
| 3846 | //TRACE("%p\n", template );
|
|---|
| 3847 | version = GET_WORD(p);
|
|---|
| 3848 | p += sizeof(WORD);
|
|---|
| 3849 | switch (version)
|
|---|
| 3850 | {
|
|---|
| 3851 | case 0:
|
|---|
| 3852 | offset = GET_WORD(p);
|
|---|
| 3853 | p += sizeof(WORD) + offset;
|
|---|
| 3854 | if (!(hMenu = CreateMenu())) return 0;
|
|---|
| 3855 | if (!MENU_ParseResource( p, hMenu, TRUE ))
|
|---|
| 3856 | {
|
|---|
| 3857 | DestroyMenu( hMenu );
|
|---|
| 3858 | return 0;
|
|---|
| 3859 | }
|
|---|
| 3860 | return hMenu;
|
|---|
| 3861 | case 1:
|
|---|
| 3862 | offset = GET_WORD(p);
|
|---|
| 3863 | p += sizeof(WORD) + offset;
|
|---|
| 3864 | if (!(hMenu = CreateMenu())) return 0;
|
|---|
| 3865 | if (!MENUEX_ParseResource( p, hMenu))
|
|---|
| 3866 | {
|
|---|
| 3867 | DestroyMenu( hMenu );
|
|---|
| 3868 | return 0;
|
|---|
| 3869 | }
|
|---|
| 3870 | return hMenu;
|
|---|
| 3871 | default:
|
|---|
| 3872 | //ERR("version %d not supported.\n", version);
|
|---|
| 3873 | return 0;
|
|---|
| 3874 | }
|
|---|
| 3875 | }
|
|---|
| 3876 |
|
|---|
| 3877 |
|
|---|
| 3878 | /**********************************************************************
|
|---|
| 3879 | * LoadMenuIndirect32W (USER32.372)
|
|---|
| 3880 | */
|
|---|
| 3881 | HMENU WINAPI LoadMenuIndirectW(CONST MENUITEMTEMPLATEHEADER *lpMenuTemplate )
|
|---|
| 3882 | {
|
|---|
| 3883 | dprintf(("USER32: LoadMenuIndirectW"));
|
|---|
| 3884 |
|
|---|
| 3885 | /* FIXME: is there anything different between A and W? */
|
|---|
| 3886 | return LoadMenuIndirectA(lpMenuTemplate);
|
|---|
| 3887 | }
|
|---|
| 3888 |
|
|---|
| 3889 |
|
|---|
| 3890 | /**********************************************************************
|
|---|
| 3891 | * IsMenu32 (USER32.346)
|
|---|
| 3892 | */
|
|---|
| 3893 | BOOL WINAPI IsMenu(HMENU hmenu)
|
|---|
| 3894 | {
|
|---|
| 3895 | LPPOPUPMENU menu = (LPPOPUPMENU)hmenu;
|
|---|
| 3896 |
|
|---|
| 3897 | dprintf(("USER32: IsMenu"));
|
|---|
| 3898 |
|
|---|
| 3899 | return IS_A_MENU(menu);
|
|---|
| 3900 | }
|
|---|
| 3901 |
|
|---|
| 3902 | /**********************************************************************
|
|---|
| 3903 | * GetMenuItemInfo32_common
|
|---|
| 3904 | */
|
|---|
| 3905 |
|
|---|
| 3906 | static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
|
|---|
| 3907 | LPMENUITEMINFOA lpmii, BOOL unicode)
|
|---|
| 3908 | {
|
|---|
| 3909 | MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0);
|
|---|
| 3910 |
|
|---|
| 3911 | //debug_print_menuitem("GetMenuItemInfo32_common: ", menu, "");
|
|---|
| 3912 |
|
|---|
| 3913 | if (!menu)
|
|---|
| 3914 | return FALSE;
|
|---|
| 3915 |
|
|---|
| 3916 | if (lpmii->fMask & MIIM_TYPE) {
|
|---|
| 3917 | lpmii->fType = menu->fType;
|
|---|
| 3918 | switch (MENU_ITEM_TYPE(menu->fType)) {
|
|---|
| 3919 | case MF_STRING:
|
|---|
| 3920 | if (menu->text && lpmii->dwTypeData && lpmii->cch) {
|
|---|
| 3921 | if (unicode) {
|
|---|
| 3922 | lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
|
|---|
| 3923 | lpmii->cch = lstrlenW((LPWSTR)menu->text);
|
|---|
| 3924 | } else {
|
|---|
| 3925 | lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
|
|---|
| 3926 | lpmii->cch = lstrlenA(menu->text);
|
|---|
| 3927 | }
|
|---|
| 3928 | }
|
|---|
| 3929 | break;
|
|---|
| 3930 | case MF_OWNERDRAW:
|
|---|
| 3931 | case MF_BITMAP:
|
|---|
| 3932 | lpmii->dwTypeData = menu->text;
|
|---|
| 3933 | /* fall through */
|
|---|
| 3934 | default:
|
|---|
| 3935 | lpmii->cch = 0;
|
|---|
| 3936 | }
|
|---|
| 3937 | }
|
|---|
| 3938 |
|
|---|
| 3939 | if (lpmii->fMask & MIIM_STRING) {
|
|---|
| 3940 | if (unicode) {
|
|---|
| 3941 | lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
|
|---|
| 3942 | lpmii->cch = lstrlenW((LPWSTR)menu->text);
|
|---|
| 3943 | } else {
|
|---|
| 3944 | lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
|
|---|
| 3945 | lpmii->cch = lstrlenA(menu->text);
|
|---|
| 3946 | }
|
|---|
| 3947 | }
|
|---|
| 3948 |
|
|---|
| 3949 | if (lpmii->fMask & MIIM_FTYPE)
|
|---|
| 3950 | lpmii->fType = menu->fType;
|
|---|
| 3951 |
|
|---|
| 3952 | if (lpmii->fMask & MIIM_BITMAP)
|
|---|
| 3953 | lpmii->hbmpItem = menu->hbmpItem;
|
|---|
| 3954 |
|
|---|
| 3955 | if (lpmii->fMask & MIIM_STATE)
|
|---|
| 3956 | lpmii->fState = menu->fState;
|
|---|
| 3957 |
|
|---|
| 3958 | if (lpmii->fMask & MIIM_ID)
|
|---|
| 3959 | lpmii->wID = menu->wID;
|
|---|
| 3960 |
|
|---|
| 3961 | if (lpmii->fMask & MIIM_SUBMENU)
|
|---|
| 3962 | lpmii->hSubMenu = menu->hSubMenu;
|
|---|
| 3963 |
|
|---|
| 3964 | if (lpmii->fMask & MIIM_CHECKMARKS) {
|
|---|
| 3965 | lpmii->hbmpChecked = menu->hCheckBit;
|
|---|
| 3966 | lpmii->hbmpUnchecked = menu->hUnCheckBit;
|
|---|
| 3967 | }
|
|---|
| 3968 | if (lpmii->fMask & MIIM_DATA)
|
|---|
| 3969 | lpmii->dwItemData = menu->dwItemData;
|
|---|
| 3970 |
|
|---|
| 3971 | return TRUE;
|
|---|
| 3972 | }
|
|---|
| 3973 |
|
|---|
| 3974 | /**********************************************************************
|
|---|
| 3975 | * GetMenuItemInfoA (USER32.264)
|
|---|
| 3976 | */
|
|---|
| 3977 | BOOL WINAPI GetMenuItemInfoA( HMENU hmenu, UINT item, BOOL bypos,
|
|---|
| 3978 | LPMENUITEMINFOA lpmii)
|
|---|
| 3979 | {
|
|---|
| 3980 | dprintf(("USER32: GetMenuItemInfoA"));
|
|---|
| 3981 |
|
|---|
| 3982 | return GetMenuItemInfo_common (hmenu, item, bypos, lpmii, FALSE);
|
|---|
| 3983 | }
|
|---|
| 3984 |
|
|---|
| 3985 | /**********************************************************************
|
|---|
| 3986 | * GetMenuItemInfoW (USER32.265)
|
|---|
| 3987 | */
|
|---|
| 3988 | BOOL WINAPI GetMenuItemInfoW( HMENU hmenu, UINT item, BOOL bypos,
|
|---|
| 3989 | LPMENUITEMINFOW lpmii)
|
|---|
| 3990 | {
|
|---|
| 3991 | dprintf(("USER32: GetMenuItemInfoW"));
|
|---|
| 3992 |
|
|---|
| 3993 | return GetMenuItemInfo_common (hmenu, item, bypos,
|
|---|
| 3994 | (LPMENUITEMINFOA)lpmii, TRUE);
|
|---|
| 3995 | }
|
|---|
| 3996 |
|
|---|
| 3997 | /**********************************************************************
|
|---|
| 3998 | * SetMenuItemInfo32_common
|
|---|
| 3999 | */
|
|---|
| 4000 |
|
|---|
| 4001 | static BOOL SetMenuItemInfo_common(MENUITEM * menu,
|
|---|
| 4002 | const MENUITEMINFOA *lpmii,
|
|---|
| 4003 | BOOL unicode)
|
|---|
| 4004 | {
|
|---|
| 4005 | if (!menu) return FALSE;
|
|---|
| 4006 |
|
|---|
| 4007 | if (lpmii->fMask & MIIM_TYPE ) {
|
|---|
| 4008 | /* Get rid of old string. */
|
|---|
| 4009 | if ( IS_STRING_ITEM(menu->fType) && menu->text) {
|
|---|
| 4010 | HeapFree(GetProcessHeap(), 0, menu->text);
|
|---|
| 4011 | menu->text = NULL;
|
|---|
| 4012 | }
|
|---|
| 4013 |
|
|---|
| 4014 | /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
|
|---|
| 4015 | menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
|
|---|
| 4016 | menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
|
|---|
| 4017 |
|
|---|
| 4018 | menu->text = lpmii->dwTypeData;
|
|---|
| 4019 |
|
|---|
| 4020 | if (IS_STRING_ITEM(menu->fType) && menu->text) {
|
|---|
| 4021 | if (unicode)
|
|---|
| 4022 | menu->text = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR) lpmii->dwTypeData);
|
|---|
| 4023 | else
|
|---|
| 4024 | menu->text = HEAP_strdupA(GetProcessHeap(), 0, lpmii->dwTypeData);
|
|---|
| 4025 | }
|
|---|
| 4026 | }
|
|---|
| 4027 |
|
|---|
| 4028 | if (lpmii->fMask & MIIM_FTYPE ) {
|
|---|
| 4029 | /* free the string when the type is changing */
|
|---|
| 4030 | if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
|
|---|
| 4031 | HeapFree(GetProcessHeap(), 0, menu->text);
|
|---|
| 4032 | menu->text = NULL;
|
|---|
| 4033 | }
|
|---|
| 4034 | menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
|
|---|
| 4035 | menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
|
|---|
| 4036 | }
|
|---|
| 4037 |
|
|---|
| 4038 | if (lpmii->fMask & MIIM_STRING ) {
|
|---|
| 4039 | /* free the string when used */
|
|---|
| 4040 | if ( IS_STRING_ITEM(menu->fType) && menu->text) {
|
|---|
| 4041 | HeapFree(GetProcessHeap(), 0, menu->text);
|
|---|
| 4042 | if (unicode)
|
|---|
| 4043 | menu->text = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR) lpmii->dwTypeData);
|
|---|
| 4044 | else
|
|---|
| 4045 | menu->text = HEAP_strdupA(GetProcessHeap(), 0, lpmii->dwTypeData);
|
|---|
| 4046 | }
|
|---|
| 4047 | }
|
|---|
| 4048 |
|
|---|
| 4049 | if (lpmii->fMask & MIIM_STATE)
|
|---|
| 4050 | {
|
|---|
| 4051 | /* fixme: MFS_DEFAULT do we have to reset the other menu items? */
|
|---|
| 4052 | menu->fState = lpmii->fState;
|
|---|
| 4053 | }
|
|---|
| 4054 |
|
|---|
| 4055 | if (lpmii->fMask & MIIM_ID)
|
|---|
| 4056 | menu->wID = lpmii->wID;
|
|---|
| 4057 |
|
|---|
| 4058 | if (lpmii->fMask & MIIM_SUBMENU) {
|
|---|
| 4059 | menu->hSubMenu = lpmii->hSubMenu;
|
|---|
| 4060 | if (menu->hSubMenu) {
|
|---|
| 4061 | POPUPMENU *subMenu = (POPUPMENU*)(UINT)menu->hSubMenu;
|
|---|
| 4062 | if (IS_A_MENU(subMenu)) {
|
|---|
| 4063 | subMenu->wFlags |= MF_POPUP;
|
|---|
| 4064 | menu->fType |= MF_POPUP;
|
|---|
| 4065 | }
|
|---|
| 4066 | else
|
|---|
| 4067 | /* FIXME: Return an error ? */
|
|---|
| 4068 | menu->fType &= ~MF_POPUP;
|
|---|
| 4069 | }
|
|---|
| 4070 | else
|
|---|
| 4071 | menu->fType &= ~MF_POPUP;
|
|---|
| 4072 | }
|
|---|
| 4073 |
|
|---|
| 4074 | if (lpmii->fMask & MIIM_CHECKMARKS)
|
|---|
| 4075 | {
|
|---|
| 4076 | menu->hCheckBit = lpmii->hbmpChecked;
|
|---|
| 4077 | menu->hUnCheckBit = lpmii->hbmpUnchecked;
|
|---|
| 4078 | }
|
|---|
| 4079 | if (lpmii->fMask & MIIM_DATA)
|
|---|
| 4080 | menu->dwItemData = lpmii->dwItemData;
|
|---|
| 4081 |
|
|---|
| 4082 | //debug_print_menuitem("SetMenuItemInfo32_common: ", menu, "");
|
|---|
| 4083 | return TRUE;
|
|---|
| 4084 | }
|
|---|
| 4085 |
|
|---|
| 4086 | /**********************************************************************
|
|---|
| 4087 | * SetMenuItemInfo32A (USER32.491)
|
|---|
| 4088 | */
|
|---|
| 4089 | BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
|
|---|
| 4090 | const MENUITEMINFOA *lpmii)
|
|---|
| 4091 | {
|
|---|
| 4092 | dprintf(("USER32: SetMenuItemInfoA"));
|
|---|
| 4093 |
|
|---|
| 4094 | return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
|
|---|
| 4095 | lpmii, FALSE);
|
|---|
| 4096 | }
|
|---|
| 4097 |
|
|---|
| 4098 | /**********************************************************************
|
|---|
| 4099 | * SetMenuItemInfo32W (USER32.492)
|
|---|
| 4100 | */
|
|---|
| 4101 | BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos,
|
|---|
| 4102 | const MENUITEMINFOW *lpmii)
|
|---|
| 4103 | {
|
|---|
| 4104 | dprintf(("USER32: SetMenuItemInfoW"));
|
|---|
| 4105 |
|
|---|
| 4106 | return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
|
|---|
| 4107 | (const MENUITEMINFOA*)lpmii, TRUE);
|
|---|
| 4108 | }
|
|---|
| 4109 |
|
|---|
| 4110 | /**********************************************************************
|
|---|
| 4111 | * SetMenuDefaultItem (USER32.489)
|
|---|
| 4112 | *
|
|---|
| 4113 | */
|
|---|
| 4114 | BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT uItem, UINT bypos)
|
|---|
| 4115 | {
|
|---|
| 4116 | UINT i;
|
|---|
| 4117 | POPUPMENU *menu;
|
|---|
| 4118 | MENUITEM *item;
|
|---|
| 4119 |
|
|---|
| 4120 |
|
|---|
| 4121 | dprintf(("USER32: SetMenuDefaultItem"));
|
|---|
| 4122 | //TRACE("(0x%x,%d,%d)\n", hmenu, uItem, bypos);
|
|---|
| 4123 |
|
|---|
| 4124 | if (!(menu = (POPUPMENU*)hmenu)) return FALSE;
|
|---|
| 4125 |
|
|---|
| 4126 | /* reset all default-item flags */
|
|---|
| 4127 | item = menu->items;
|
|---|
| 4128 | for (i = 0; i < menu->nItems; i++, item++)
|
|---|
| 4129 | {
|
|---|
| 4130 | item->fState &= ~MFS_DEFAULT;
|
|---|
| 4131 | }
|
|---|
| 4132 |
|
|---|
| 4133 | /* no default item */
|
|---|
| 4134 | if ( -1 == uItem)
|
|---|
| 4135 | {
|
|---|
| 4136 | return TRUE;
|
|---|
| 4137 | }
|
|---|
| 4138 |
|
|---|
| 4139 | item = menu->items;
|
|---|
| 4140 | if ( bypos )
|
|---|
| 4141 | {
|
|---|
| 4142 | if ( uItem >= menu->nItems ) return FALSE;
|
|---|
| 4143 | item[uItem].fState |= MFS_DEFAULT;
|
|---|
| 4144 | return TRUE;
|
|---|
| 4145 | }
|
|---|
| 4146 | else
|
|---|
| 4147 | {
|
|---|
| 4148 | for (i = 0; i < menu->nItems; i++, item++)
|
|---|
| 4149 | {
|
|---|
| 4150 | if (item->wID == uItem)
|
|---|
| 4151 | {
|
|---|
| 4152 | item->fState |= MFS_DEFAULT;
|
|---|
| 4153 | return TRUE;
|
|---|
| 4154 | }
|
|---|
| 4155 | }
|
|---|
| 4156 |
|
|---|
| 4157 | }
|
|---|
| 4158 | return FALSE;
|
|---|
| 4159 | }
|
|---|
| 4160 |
|
|---|
| 4161 | /**********************************************************************
|
|---|
| 4162 | * GetMenuDefaultItem (USER32.260)
|
|---|
| 4163 | */
|
|---|
| 4164 | UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags)
|
|---|
| 4165 | {
|
|---|
| 4166 | POPUPMENU *menu;
|
|---|
| 4167 | MENUITEM * item;
|
|---|
| 4168 | UINT i = 0;
|
|---|
| 4169 |
|
|---|
| 4170 | dprintf(("USER32: GetMenuDefaultItem"));
|
|---|
| 4171 | //TRACE("(0x%x,%d,%d)\n", hmenu, bypos, flags);
|
|---|
| 4172 |
|
|---|
| 4173 | if (!(menu = (POPUPMENU*)hmenu)) return -1;
|
|---|
| 4174 |
|
|---|
| 4175 | /* find default item */
|
|---|
| 4176 | item = menu->items;
|
|---|
| 4177 |
|
|---|
| 4178 | /* empty menu */
|
|---|
| 4179 | if (! item) return -1;
|
|---|
| 4180 |
|
|---|
| 4181 | while ( !( item->fState & MFS_DEFAULT ) )
|
|---|
| 4182 | {
|
|---|
| 4183 | i++; item++;
|
|---|
| 4184 | if (i >= menu->nItems ) return -1;
|
|---|
| 4185 | }
|
|---|
| 4186 |
|
|---|
| 4187 | /* default: don't return disabled items */
|
|---|
| 4188 | if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1;
|
|---|
| 4189 |
|
|---|
| 4190 | /* search rekursiv when needed */
|
|---|
| 4191 | if ( (item->fType & MF_POPUP) && (flags & GMDI_GOINTOPOPUPS) )
|
|---|
| 4192 | {
|
|---|
| 4193 | UINT ret;
|
|---|
| 4194 | ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags );
|
|---|
| 4195 | if ( -1 != ret ) return ret;
|
|---|
| 4196 |
|
|---|
| 4197 | /* when item not found in submenu, return the popup item */
|
|---|
| 4198 | }
|
|---|
| 4199 | return ( bypos ) ? i : item->wID;
|
|---|
| 4200 |
|
|---|
| 4201 | }
|
|---|
| 4202 |
|
|---|
| 4203 | /**********************************************************************
|
|---|
| 4204 | * InsertMenuItem32A (USER32.323)
|
|---|
| 4205 | */
|
|---|
| 4206 | BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
|
|---|
| 4207 | const MENUITEMINFOA *lpmii)
|
|---|
| 4208 | {
|
|---|
| 4209 | MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
|
|---|
| 4210 |
|
|---|
| 4211 | dprintf(("USER32: InsertMenuItemA"));
|
|---|
| 4212 |
|
|---|
| 4213 | return SetMenuItemInfo_common(item, lpmii, FALSE);
|
|---|
| 4214 | }
|
|---|
| 4215 |
|
|---|
| 4216 |
|
|---|
| 4217 | /**********************************************************************
|
|---|
| 4218 | * InsertMenuItem32W (USER32.324)
|
|---|
| 4219 | */
|
|---|
| 4220 | BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
|
|---|
| 4221 | const MENUITEMINFOW *lpmii)
|
|---|
| 4222 | {
|
|---|
| 4223 | MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
|
|---|
| 4224 |
|
|---|
| 4225 | dprintf(("USER32: InsertMenuItemW"));
|
|---|
| 4226 |
|
|---|
| 4227 | return SetMenuItemInfo_common(item, (const MENUITEMINFOA*)lpmii, TRUE);
|
|---|
| 4228 | }
|
|---|
| 4229 |
|
|---|
| 4230 | /**********************************************************************
|
|---|
| 4231 | * CheckMenuRadioItem32 (USER32.47)
|
|---|
| 4232 | */
|
|---|
| 4233 |
|
|---|
| 4234 | BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
|
|---|
| 4235 | UINT first, UINT last, UINT check,
|
|---|
| 4236 | UINT bypos)
|
|---|
| 4237 | {
|
|---|
| 4238 | MENUITEM *mifirst, *milast, *micheck;
|
|---|
| 4239 | HMENU mfirst = hMenu, mlast = hMenu, mcheck = hMenu;
|
|---|
| 4240 |
|
|---|
| 4241 | dprintf(("USER32: CheckMenuRadioItem"));
|
|---|
| 4242 | //TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
|
|---|
| 4243 | // hMenu, first, last, check, bypos);
|
|---|
| 4244 |
|
|---|
| 4245 | mifirst = MENU_FindItem (&mfirst, &first, bypos);
|
|---|
| 4246 | milast = MENU_FindItem (&mlast, &last, bypos);
|
|---|
| 4247 | micheck = MENU_FindItem (&mcheck, &check, bypos);
|
|---|
| 4248 |
|
|---|
| 4249 | if (mifirst == NULL || milast == NULL || micheck == NULL ||
|
|---|
| 4250 | mifirst > milast || mfirst != mlast || mfirst != mcheck ||
|
|---|
| 4251 | micheck > milast || micheck < mifirst)
|
|---|
| 4252 | return FALSE;
|
|---|
| 4253 |
|
|---|
| 4254 | while (mifirst <= milast)
|
|---|
| 4255 | {
|
|---|
| 4256 | if (mifirst == micheck)
|
|---|
| 4257 | {
|
|---|
| 4258 | mifirst->fType |= MFT_RADIOCHECK;
|
|---|
| 4259 | mifirst->fState |= MFS_CHECKED;
|
|---|
| 4260 | } else {
|
|---|
| 4261 | mifirst->fType &= ~MFT_RADIOCHECK;
|
|---|
| 4262 | mifirst->fState &= ~MFS_CHECKED;
|
|---|
| 4263 | }
|
|---|
| 4264 | mifirst++;
|
|---|
| 4265 | }
|
|---|
| 4266 |
|
|---|
| 4267 | return TRUE;
|
|---|
| 4268 | }
|
|---|
| 4269 |
|
|---|
| 4270 | /**********************************************************************
|
|---|
| 4271 | * GetMenuItemRect32 (USER32.266)
|
|---|
| 4272 | *
|
|---|
| 4273 | * ATTENTION: Here, the returned values in rect are the screen
|
|---|
| 4274 | * coordinates of the item just like if the menu was
|
|---|
| 4275 | * always on the upper left side of the application.
|
|---|
| 4276 | *
|
|---|
| 4277 | */
|
|---|
| 4278 | BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
|
|---|
| 4279 | LPRECT rect)
|
|---|
| 4280 | {
|
|---|
| 4281 | POPUPMENU *itemMenu;
|
|---|
| 4282 | MENUITEM *item;
|
|---|
| 4283 | HWND referenceHwnd;
|
|---|
| 4284 |
|
|---|
| 4285 | dprintf(("USER32: GetMenuItemRect"));
|
|---|
| 4286 | //TRACE("(0x%x,0x%x,%d,%p)\n", hwnd, hMenu, uItem, rect);
|
|---|
| 4287 |
|
|---|
| 4288 | item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
|
|---|
| 4289 | referenceHwnd = hwnd;
|
|---|
| 4290 |
|
|---|
| 4291 | if(!hwnd)
|
|---|
| 4292 | {
|
|---|
| 4293 | itemMenu = (POPUPMENU*)hMenu;
|
|---|
| 4294 | if (itemMenu == NULL)
|
|---|
| 4295 | return FALSE;
|
|---|
| 4296 |
|
|---|
| 4297 | if(itemMenu->hWnd == 0)
|
|---|
| 4298 | return FALSE;
|
|---|
| 4299 | referenceHwnd = itemMenu->hWnd;
|
|---|
| 4300 | }
|
|---|
| 4301 |
|
|---|
| 4302 | if ((rect == NULL) || (item == NULL))
|
|---|
| 4303 | return FALSE;
|
|---|
| 4304 |
|
|---|
| 4305 | *rect = item->rect;
|
|---|
| 4306 |
|
|---|
| 4307 | MapWindowPoints(referenceHwnd, 0, (LPPOINT)rect, 2);
|
|---|
| 4308 |
|
|---|
| 4309 | return TRUE;
|
|---|
| 4310 | }
|
|---|
| 4311 |
|
|---|
| 4312 | /**********************************************************************
|
|---|
| 4313 | * SetMenuInfo
|
|---|
| 4314 | *
|
|---|
| 4315 | * FIXME
|
|---|
| 4316 | * MIM_APPLYTOSUBMENUS
|
|---|
| 4317 | * actually use the items to draw the menu
|
|---|
| 4318 | */
|
|---|
| 4319 | BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
|
|---|
| 4320 | {
|
|---|
| 4321 | POPUPMENU *menu;
|
|---|
| 4322 |
|
|---|
| 4323 | dprintf(("USER32: SetMenuInfo"));
|
|---|
| 4324 | //TRACE("(0x%04x %p)\n", hMenu, lpmi);
|
|---|
| 4325 |
|
|---|
| 4326 | if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && (menu=(POPUPMENU*)hMenu))
|
|---|
| 4327 | {
|
|---|
| 4328 |
|
|---|
| 4329 | if (lpmi->fMask & MIM_BACKGROUND)
|
|---|
| 4330 | menu->hbrBack = lpmi->hbrBack;
|
|---|
| 4331 |
|
|---|
| 4332 | if (lpmi->fMask & MIM_HELPID)
|
|---|
| 4333 | menu->dwContextHelpID = lpmi->dwContextHelpID;
|
|---|
| 4334 |
|
|---|
| 4335 | if (lpmi->fMask & MIM_MAXHEIGHT)
|
|---|
| 4336 | menu->cyMax = lpmi->cyMax;
|
|---|
| 4337 |
|
|---|
| 4338 | if (lpmi->fMask & MIM_MENUDATA)
|
|---|
| 4339 | menu->dwMenuData = lpmi->dwMenuData;
|
|---|
| 4340 |
|
|---|
| 4341 | if (lpmi->fMask & MIM_STYLE)
|
|---|
| 4342 | menu->dwStyle = lpmi->dwStyle;
|
|---|
| 4343 |
|
|---|
| 4344 | return TRUE;
|
|---|
| 4345 | }
|
|---|
| 4346 | return FALSE;
|
|---|
| 4347 | }
|
|---|
| 4348 |
|
|---|
| 4349 | /**********************************************************************
|
|---|
| 4350 | * GetMenuInfo
|
|---|
| 4351 | *
|
|---|
| 4352 | * NOTES
|
|---|
| 4353 | * win98/NT5.0
|
|---|
| 4354 | *
|
|---|
| 4355 | */
|
|---|
| 4356 | BOOL WINAPI GetMenuInfo (HMENU hMenu, LPMENUINFO lpmi)
|
|---|
| 4357 | { POPUPMENU *menu;
|
|---|
| 4358 |
|
|---|
| 4359 | dprintf(("USER32: GetMenuInfo"));
|
|---|
| 4360 | //TRACE("(0x%04x %p)\n", hMenu, lpmi);
|
|---|
| 4361 |
|
|---|
| 4362 | if (lpmi && (menu = (POPUPMENU*)hMenu))
|
|---|
| 4363 | {
|
|---|
| 4364 |
|
|---|
| 4365 | if (lpmi->fMask & MIM_BACKGROUND)
|
|---|
| 4366 | lpmi->hbrBack = menu->hbrBack;
|
|---|
| 4367 |
|
|---|
| 4368 | if (lpmi->fMask & MIM_HELPID)
|
|---|
| 4369 | lpmi->dwContextHelpID = menu->dwContextHelpID;
|
|---|
| 4370 |
|
|---|
| 4371 | if (lpmi->fMask & MIM_MAXHEIGHT)
|
|---|
| 4372 | lpmi->cyMax = menu->cyMax;
|
|---|
| 4373 |
|
|---|
| 4374 | if (lpmi->fMask & MIM_MENUDATA)
|
|---|
| 4375 | lpmi->dwMenuData = menu->dwMenuData;
|
|---|
| 4376 |
|
|---|
| 4377 | if (lpmi->fMask & MIM_STYLE)
|
|---|
| 4378 | lpmi->dwStyle = menu->dwStyle;
|
|---|
| 4379 |
|
|---|
| 4380 | return TRUE;
|
|---|
| 4381 | }
|
|---|
| 4382 | return FALSE;
|
|---|
| 4383 | }
|
|---|
| 4384 |
|
|---|
| 4385 | /**********************************************************************
|
|---|
| 4386 | * SetMenuContextHelpId (USER32.488)
|
|---|
| 4387 | */
|
|---|
| 4388 | BOOL WINAPI SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpID)
|
|---|
| 4389 | {
|
|---|
| 4390 | LPPOPUPMENU menu;
|
|---|
| 4391 |
|
|---|
| 4392 | dprintf(("USER32: SetMenuContextHelpId"));
|
|---|
| 4393 | //TRACE("(0x%04x 0x%08lx)\n", hMenu, dwContextHelpID);
|
|---|
| 4394 |
|
|---|
| 4395 | menu = (POPUPMENU*)hMenu;
|
|---|
| 4396 | if (menu)
|
|---|
| 4397 | {
|
|---|
| 4398 | menu->dwContextHelpID = dwContextHelpID;
|
|---|
| 4399 | return TRUE;
|
|---|
| 4400 | }
|
|---|
| 4401 | return FALSE;
|
|---|
| 4402 | }
|
|---|
| 4403 |
|
|---|
| 4404 | /**********************************************************************
|
|---|
| 4405 | * GetMenuContextHelpId (USER32.488)
|
|---|
| 4406 | */
|
|---|
| 4407 | DWORD WINAPI GetMenuContextHelpId( HMENU hMenu )
|
|---|
| 4408 | {
|
|---|
| 4409 | LPPOPUPMENU menu;
|
|---|
| 4410 |
|
|---|
| 4411 | dprintf(("USER32: GetMenuContextHelpId"));
|
|---|
| 4412 | //TRACE("(0x%04x)\n", hMenu);
|
|---|
| 4413 |
|
|---|
| 4414 | menu = (POPUPMENU*)hMenu;
|
|---|
| 4415 | if (menu)
|
|---|
| 4416 | {
|
|---|
| 4417 | return menu->dwContextHelpID;
|
|---|
| 4418 | }
|
|---|
| 4419 | return 0;
|
|---|
| 4420 | }
|
|---|
| 4421 |
|
|---|
| 4422 | /**********************************************************************
|
|---|
| 4423 | * MenuItemFromPoint (USER32.387)
|
|---|
| 4424 | */
|
|---|
| 4425 | UINT WINAPI MenuItemFromPoint(HWND hWnd, HMENU hMenu, POINT ptScreen)
|
|---|
| 4426 | {
|
|---|
| 4427 | dprintf(("USER32: MenuItemFromPoint not implemented!"));
|
|---|
| 4428 | //FIXME("(0x%04x,0x%04x,(%ld,%ld)):stub\n",
|
|---|
| 4429 | // hWnd, hMenu, ptScreen.x, ptScreen.y);
|
|---|
| 4430 | return 0;
|
|---|
| 4431 | }
|
|---|
| 4432 |
|
|---|
| 4433 | BOOL POPUPMENU_Register()
|
|---|
| 4434 | {
|
|---|
| 4435 | WNDCLASSA wndClass;
|
|---|
| 4436 | BOOL rc;
|
|---|
| 4437 |
|
|---|
| 4438 | //SvL: Don't check this now
|
|---|
| 4439 | // if (GlobalFindAtomA(POPUPMENUCLASSNAME)) return FALSE;
|
|---|
| 4440 |
|
|---|
| 4441 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
|---|
| 4442 | wndClass.style = CS_GLOBALCLASS | CS_SAVEBITS;
|
|---|
| 4443 | wndClass.lpfnWndProc = (WNDPROC)PopupMenuWndProc;
|
|---|
| 4444 | wndClass.cbClsExtra = 0;
|
|---|
| 4445 | wndClass.cbWndExtra = sizeof(HMENU);
|
|---|
| 4446 | wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
|
|---|
| 4447 | wndClass.hbrBackground = NULL_BRUSH;
|
|---|
| 4448 | wndClass.lpszClassName = POPUPMENUCLASSNAME;
|
|---|
| 4449 |
|
|---|
| 4450 | rc = RegisterClassA(&wndClass);
|
|---|
| 4451 | MENU_Init();
|
|---|
| 4452 |
|
|---|
| 4453 | return rc;
|
|---|
| 4454 | }
|
|---|
| 4455 | //******************************************************************************
|
|---|
| 4456 | //******************************************************************************
|
|---|
| 4457 | BOOL POPUPMENU_Unregister()
|
|---|
| 4458 | {
|
|---|
| 4459 | if (GlobalFindAtomA(POPUPMENUCLASSNAME))
|
|---|
| 4460 | return UnregisterClassA(POPUPMENUCLASSNAME,(HINSTANCE)NULL);
|
|---|
| 4461 | else return FALSE;
|
|---|
| 4462 | }
|
|---|
| 4463 | //******************************************************************************
|
|---|
| 4464 | //******************************************************************************
|
|---|
| 4465 |
|
|---|