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