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