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