Changeset 10190 for trunk/src


Ignore:
Timestamp:
Jul 31, 2003, 5:58:58 PM (22 years ago)
Author:
sandervl
Message:

KOMH: DBCS updates/fixes

Location:
trunk/src/user32
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/dbgwrap.cpp

    r9701 r10190  
    312312DEBUGWRAP8(GetMenuInfo)
    313313DEBUGWRAP8(SetMenuInfo)
     314DEBUGWRAP_LVL2_12(TranslateAcceleratorA)
    314315
    315316#undef DBG_LOCALLOG
     
    448449
    449450#undef DBG_LOCALLOG
    450 #define DBG_LOCALLOG    DBG_display
     451#define DBG_LOCALLOG    DBG_display
    451452DEBUGWRAP8(GetMonitorInfoW)
    452453DEBUGWRAP8(GetMonitorInfoA)
     
    479480
    480481#undef DBG_LOCALLOG
    481 #define DBG_LOCALLOG    DBG_hook
     482#define DBG_LOCALLOG    DBG_hook
    482483DEBUGWRAP16(CallNextHookEx)
    483484DEBUGWRAP8(SetWindowsHookA)
     
    489490
    490491#undef DBG_LOCALLOG
    491 #define DBG_LOCALLOG    DBG_windowmsg
     492#define DBG_LOCALLOG    DBG_windowmsg
    492493DEBUGWRAP20(MsgWaitForMultipleObjects)
    493494DEBUGWRAP20(BroadcastSystemMessage)
     
    547548
    548549#undef DBG_LOCALLOG
    549 #define DBG_LOCALLOG    DBG_defwndproc
     550#define DBG_LOCALLOG    DBG_defwndproc
    550551
    551552DEBUGWRAP_LVL2_16(DefDlgProcA)
     
    560561
    561562#undef DBG_LOCALLOG
    562 #define DBG_LOCALLOG    DBG_windlg
     563#define DBG_LOCALLOG    DBG_windlg
    563564DEBUGWRAP16(SetDlgItemInt)
    564565DEBUGWRAP12(SetDlgItemTextA)
     
    609610
    610611#undef DBG_LOCALLOG
    611 #define DBG_LOCALLOG    DBG_winmouse
     612#define DBG_LOCALLOG    DBG_winmouse
    612613DEBUGWRAP4(GetCursorPos)
    613614DEBUGWRAP8(SetCursorPos)
     
    623624
    624625#undef DBG_LOCALLOG
    625 #define DBG_LOCALLOG    DBG_caret
     626#define DBG_LOCALLOG    DBG_caret
    626627DEBUGWRAP16(CreateCaret)
    627628DEBUGWRAP0(DestroyCaret)
     
    662663
    663664#undef DBG_LOCALLOG
    664 #define DBG_LOCALLOG    DBG_timer
     665#define DBG_LOCALLOG    DBG_timer
    665666DEBUGWRAP8(KillTimer)
    666667DEBUGWRAP16(SetTimer)
     
    784785DEBUGWRAP8(CreateAcceleratorTableW)
    785786DEBUGWRAP4(DestroyAcceleratorTable)
    786 DEBUGWRAP12(TranslateAcceleratorA)
    787787DEBUGWRAP8(TranslateMDISysAccel)
    788788DEBUGWRAP8(LoadAcceleratorsA)
  • trunk/src/user32/menu.c

    r10102 r10190  
    4444#include "oslibmsg.h"
    4545#include "oslibwin.h"
     46#include "heapstring.h"
     47
    4648
    4749HBRUSH WIN32API GetOS2ColorBrush(int nIndex);
     
    5557DECLARE_DEBUG_CHANNEL(accel);
    5658
    57 #define HACCEL_16(h32)          (LOWORD(h32))
     59#define HACCEL_16(h32)      (LOWORD(h32))
    5860
    5961/* internal popup menu window messages */
    6062
    61 #define MM_SETMENUHANDLE        (WM_USER + 0)
    62 #define MM_GETMENUHANDLE        (WM_USER + 1)
     63#define MM_SETMENUHANDLE    (WM_USER + 0)
     64#define MM_GETMENUHANDLE    (WM_USER + 1)
    6365
    6466/* Menu item structure */
    6567typedef struct {
    6668    /* ----------- MENUITEMINFO Stuff ----------- */
    67     UINT fType;                 /* Item type. */
    68     UINT fState;                /* Item state.  */
    69     UINT wID;                   /* Item id.  */
    70     HMENU hSubMenu;             /* Pop-up menu.  */
    71     HBITMAP hCheckBit;          /* Bitmap when checked.  */
    72     HBITMAP hUnCheckBit;        /* Bitmap when unchecked.  */
    73     LPWSTR text;                        /* Item text or bitmap handle.  */
    74     DWORD dwItemData;           /* Application defined.  */
    75     DWORD dwTypeData;           /* depends on fMask */
    76     HBITMAP hbmpItem;           /* bitmap in win98 style menus */
     69    UINT fType;         /* Item type. */
     70    UINT fState;        /* Item state.  */
     71    UINT wID;           /* Item id.  */
     72    HMENU hSubMenu;     /* Pop-up menu.  */
     73    HBITMAP hCheckBit;      /* Bitmap when checked.  */
     74    HBITMAP hUnCheckBit;    /* Bitmap when unchecked.  */
     75    LPWSTR text;            /* Item text or bitmap handle.  */
     76    DWORD dwItemData;       /* Application defined.  */
     77    DWORD dwTypeData;       /* depends on fMask */
     78    HBITMAP hbmpItem;       /* bitmap in win98 style menus */
    7779    /* ----------- Wine stuff ----------- */
    78     RECT      rect;             /* Item area (relative to menu window) */
    79     UINT      xTab;             /* X position of text after Tab */
     80    RECT      rect;     /* Item area (relative to menu window) */
     81    UINT      xTab;     /* X position of text after Tab */
    8082} MENUITEM;
    8183
     
    8486    WORD        wFlags;       /* Menu flags (MF_POPUP, MF_SYSMENU) */
    8587    WORD        wMagic;       /* Magic number */
    86     WORD        Width;        /* Width of the whole menu */
    87     WORD        Height;       /* Height of the whole menu */
     88    WORD    Width;        /* Width of the whole menu */
     89    WORD    Height;       /* Height of the whole menu */
    8890    UINT        nItems;       /* Number of items in the menu */
    8991    HWND        hWnd;         /* Window containing the menu */
    9092    MENUITEM    *items;       /* Array of menu items */
    9193    UINT        FocusedItem;  /* Currently focused item */
    92     HWND        hwndOwner;    /* window receiving the messages for ownerdraw */
     94    HWND    hwndOwner;    /* window receiving the messages for ownerdraw */
    9395    BOOL        bTimeToHide;  /* Request hiding when receiving a second click in the top-level menu item */
    9496    /* ------------ MENUINFO members ------ */
    95     DWORD       dwStyle;        /* Extended mennu style */
    96     UINT        cyMax;          /* max hight of the whole menu, 0 is screen hight */
    97     HBRUSH      hbrBack;        /* brush for menu background */
    98     DWORD       dwContextHelpID;
    99     DWORD       dwMenuData;     /* application defined value */
     97    DWORD   dwStyle;    /* Extended mennu style */
     98    UINT    cyMax;      /* max hight of the whole menu, 0 is screen hight */
     99    HBRUSH  hbrBack;    /* brush for menu background */
     100    DWORD   dwContextHelpID;
     101    DWORD   dwMenuData; /* application defined value */
    100102    HMENU       hSysMenuOwner;  /* Handle to the dummy sys menu holder */
    101103} POPUPMENU, *LPPOPUPMENU;
     
    105107#define TF_ENDMENU              0x0001
    106108#define TF_SUSPENDPOPUP         0x0002
    107 #define TF_SKIPREMOVE           0x0004
     109#define TF_SKIPREMOVE       0x0004
    108110
    109111typedef struct
    110112{
    111     UINT        trackFlags;
    112     HMENU       hCurrentMenu; /* current submenu (can be equal to hTopMenu)*/
    113     HMENU       hTopMenu;     /* initial menu */
    114     HWND        hOwnerWnd;    /* where notifications are sent */
    115     POINT       pt;
     113    UINT    trackFlags;
     114    HMENU   hCurrentMenu; /* current submenu (can be equal to hTopMenu)*/
     115    HMENU   hTopMenu;     /* initial menu */
     116    HWND    hOwnerWnd;    /* where notifications are sent */
     117    POINT   pt;
    116118} MTRACKER;
    117119
    118120#define MENU_MAGIC   0x554d  /* 'MU' */
    119121
    120 #define ITEM_PREV               -1
    121 #define ITEM_NEXT                1
     122#define ITEM_PREV       -1
     123#define ITEM_NEXT        1
    122124
    123125  /* Internal MENU_TrackMenu() flags */
    124 #define TPM_INTERNAL            0xF0000000
    125 #define TPM_ENTERIDLEEX         0x80000000              /* set owner window for WM_ENTERIDLE */
    126 #define TPM_BUTTONDOWN          0x40000000              /* menu was clicked before tracking */
     126#define TPM_INTERNAL        0xF0000000
     127#define TPM_ENTERIDLEEX     0x80000000      /* set owner window for WM_ENTERIDLE */
     128#define TPM_BUTTONDOWN      0x40000000      /* menu was clicked before tracking */
    127129#define TPM_POPUPMENU           0x20000000              /* menu is a popup menu */
    128130
    129131  /* popup menu shade thickness */
    130 #define POPUP_XSHADE            4
    131 #define POPUP_YSHADE            4
     132#define POPUP_XSHADE        4
     133#define POPUP_YSHADE        4
    132134
    133135  /* Space between 2 menu bar items */
     
    151153
    152154#define IS_SYSTEM_MENU(menu)  \
    153         (!((menu)->wFlags & MF_POPUP) && (menu)->wFlags & MF_SYSMENU)
     155    (!((menu)->wFlags & MF_POPUP) && (menu)->wFlags & MF_SYSMENU)
    154156
    155157#define IS_SYSTEM_POPUP(menu) \
    156         ((menu)->wFlags & MF_POPUP && (menu)->wFlags & MF_SYSMENU)
     158    ((menu)->wFlags & MF_POPUP && (menu)->wFlags & MF_SYSMENU)
    157159
    158160#define TYPE_MASK (MFT_STRING | MFT_BITMAP | MFT_OWNERDRAW | MFT_SEPARATOR | \
    159                    MFT_MENUBARBREAK | MFT_MENUBREAK | MFT_RADIOCHECK | \
    160                    MFT_RIGHTORDER | MFT_RIGHTJUSTIFY | \
    161                    MF_POPUP | MF_SYSMENU | MF_HELP)
     161           MFT_MENUBARBREAK | MFT_MENUBREAK | MFT_RADIOCHECK | \
     162           MFT_RIGHTORDER | MFT_RIGHTJUSTIFY | \
     163           MF_POPUP | MF_SYSMENU | MF_HELP)
    162164#define STATE_MASK (~TYPE_MASK)
    163165
     
    168170static HBITMAP hBmpSysMenu = 0;
    169171
    170 static HBRUSH   hShadeBrush = 0;
    171 static HFONT    hMenuFont = 0;
    172 static HFONT    hMenuFontBold = 0;
     172static HBRUSH   hShadeBrush = 0;
     173static HFONT    hMenuFont = 0;
     174static HFONT    hMenuFontBold = 0;
    173175
    174176static HMENU MENU_DefSysPopup = 0;  /* Default system menu popup */
     
    217219
    218220static void do_debug_print_menuitem(const char *prefix, MENUITEM * mp,
    219                                     const char *postfix)
     221                    const char *postfix)
    220222{
    221223    TRACE("%s ", prefix);
    222224    if (mp) {
    223         UINT flags = mp->fType;
    224         int typ = MENU_ITEM_TYPE(flags);
    225         DPRINTF( "{ ID=0x%x", mp->wID);
    226         if (flags & MF_POPUP)
    227             DPRINTF( ", Sub=0x%x", mp->hSubMenu);
    228         if (flags) {
    229             int count = 0;
    230             DPRINTF( ", Typ=");
    231             if (typ == MFT_STRING)
    232                 /* Nothing */ ;
    233             else if (typ == MFT_SEPARATOR)
    234                 MENUOUT("sep");
    235             else if (typ == MFT_OWNERDRAW)
    236                 MENUOUT("own");
    237             else if (typ == MFT_BITMAP)
    238                 MENUOUT("bit");
    239             else
    240                 MENUOUT("???");
    241             flags -= typ;
    242 
    243             MENUFLAG(MF_POPUP, "pop");
    244             MENUFLAG(MFT_MENUBARBREAK, "barbrk");
    245             MENUFLAG(MFT_MENUBREAK, "brk");
    246             MENUFLAG(MFT_RADIOCHECK, "radio");
    247             MENUFLAG(MFT_RIGHTORDER, "rorder");
    248             MENUFLAG(MF_SYSMENU, "sys");
    249             MENUFLAG(MFT_RIGHTJUSTIFY, "right");        /* same as MF_HELP */
    250 
    251             if (flags)
    252                 DPRINTF( "+0x%x", flags);
    253         }
    254         flags = mp->fState;
    255         if (flags) {
    256             int count = 0;
    257             DPRINTF( ", State=");
    258             MENUFLAG(MFS_GRAYED, "grey");
    259             MENUFLAG(MFS_DEFAULT, "default");
    260             MENUFLAG(MFS_DISABLED, "dis");
    261             MENUFLAG(MFS_CHECKED, "check");
    262             MENUFLAG(MFS_HILITE, "hi");
    263             MENUFLAG(MF_USECHECKBITMAPS, "usebit");
    264             MENUFLAG(MF_MOUSESELECT, "mouse");
    265             if (flags)
    266                 DPRINTF( "+0x%x", flags);
    267         }
    268         if (mp->hCheckBit)
    269             DPRINTF( ", Chk=0x%x", mp->hCheckBit);
    270         if (mp->hUnCheckBit)
    271             DPRINTF( ", Unc=0x%x", mp->hUnCheckBit);
    272 
    273         if (typ == MFT_STRING) {
    274             if (mp->text)
    275                 DPRINTF( ", Text=%s", debugstr_w(mp->text));
    276             else
    277                 DPRINTF( ", Text=Null");
    278         } else if (mp->text == NULL)
    279             /* Nothing */ ;
    280         else
    281             DPRINTF( ", Text=%p", mp->text);
    282         if (mp->dwItemData)
    283             DPRINTF( ", ItemData=0x%08lx", mp->dwItemData);
    284         DPRINTF( " }");
     225    UINT flags = mp->fType;
     226    int typ = MENU_ITEM_TYPE(flags);
     227    DPRINTF( "{ ID=0x%x", mp->wID);
     228    if (flags & MF_POPUP)
     229        DPRINTF( ", Sub=0x%x", mp->hSubMenu);
     230    if (flags) {
     231        int count = 0;
     232        DPRINTF( ", Typ=");
     233        if (typ == MFT_STRING)
     234        /* Nothing */ ;
     235        else if (typ == MFT_SEPARATOR)
     236        MENUOUT("sep");
     237        else if (typ == MFT_OWNERDRAW)
     238        MENUOUT("own");
     239        else if (typ == MFT_BITMAP)
     240        MENUOUT("bit");
     241        else
     242        MENUOUT("???");
     243        flags -= typ;
     244
     245        MENUFLAG(MF_POPUP, "pop");
     246        MENUFLAG(MFT_MENUBARBREAK, "barbrk");
     247        MENUFLAG(MFT_MENUBREAK, "brk");
     248        MENUFLAG(MFT_RADIOCHECK, "radio");
     249        MENUFLAG(MFT_RIGHTORDER, "rorder");
     250        MENUFLAG(MF_SYSMENU, "sys");
     251        MENUFLAG(MFT_RIGHTJUSTIFY, "right");    /* same as MF_HELP */
     252
     253        if (flags)
     254        DPRINTF( "+0x%x", flags);
     255    }
     256    flags = mp->fState;
     257    if (flags) {
     258        int count = 0;
     259        DPRINTF( ", State=");
     260        MENUFLAG(MFS_GRAYED, "grey");
     261        MENUFLAG(MFS_DEFAULT, "default");
     262        MENUFLAG(MFS_DISABLED, "dis");
     263        MENUFLAG(MFS_CHECKED, "check");
     264        MENUFLAG(MFS_HILITE, "hi");
     265        MENUFLAG(MF_USECHECKBITMAPS, "usebit");
     266        MENUFLAG(MF_MOUSESELECT, "mouse");
     267        if (flags)
     268        DPRINTF( "+0x%x", flags);
     269    }
     270    if (mp->hCheckBit)
     271        DPRINTF( ", Chk=0x%x", mp->hCheckBit);
     272    if (mp->hUnCheckBit)
     273        DPRINTF( ", Unc=0x%x", mp->hUnCheckBit);
     274
     275    if (typ == MFT_STRING) {
     276        if (mp->text)
     277        DPRINTF( ", Text=%s", debugstr_w(mp->text));
     278        else
     279        DPRINTF( ", Text=Null");
     280    } else if (mp->text == NULL)
     281        /* Nothing */ ;
     282    else
     283        DPRINTF( ", Text=%p", mp->text);
     284    if (mp->dwItemData)
     285        DPRINTF( ", ItemData=0x%08lx", mp->dwItemData);
     286    DPRINTF( " }");
    285287    } else {
    286         DPRINTF( "NULL");
     288    DPRINTF( "NULL");
    287289    }
    288290
     
    355357        POPUPMENU* menu = MENU_GetMenu(hMenu);
    356358        menu->wFlags |= MF_SYSMENU | MF_POPUP;
    357         SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE);
     359    SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE);
    358360#ifdef __WIN32OS2__
    359361        if(!fDisableOdinSysMenuItems) {
     
    372374    }
    373375    else
    374         ERR("Unable to load default system menu\n" );
     376    ERR("Unable to load default system menu\n" );
    375377
    376378    TRACE("returning %x.\n", hMenu );
     
    395397    if ((hMenu = CreateMenu()))
    396398    {
    397         POPUPMENU *menu = MENU_GetMenu(hMenu);
    398         menu->wFlags = MF_SYSMENU;
    399         menu->hWnd = WIN_GetFullHandle( hWnd );
    400 
    401         if (hPopupMenu == (HMENU)(-1))
    402             hPopupMenu = MENU_CopySysPopup();
    403         else if( !hPopupMenu ) hPopupMenu = MENU_DefSysPopup;
    404 
    405         if (hPopupMenu)
    406         {
    407             InsertMenuA( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, hPopupMenu, NULL );
     399    POPUPMENU *menu = MENU_GetMenu(hMenu);
     400    menu->wFlags = MF_SYSMENU;
     401    menu->hWnd = WIN_GetFullHandle( hWnd );
     402
     403    if (hPopupMenu == (HMENU)(-1))
     404        hPopupMenu = MENU_CopySysPopup();
     405    else if( !hPopupMenu ) hPopupMenu = MENU_DefSysPopup;
     406
     407    if (hPopupMenu)
     408    {
     409        InsertMenuA( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, hPopupMenu, NULL );
    408410
    409411            menu->items[0].fType = MF_SYSMENU | MF_POPUP;
     
    411413            if ((menu = MENU_GetMenu(hPopupMenu))) menu->wFlags |= MF_SYSMENU;
    412414
    413             TRACE("GetSysMenu hMenu=%04x (%04x)\n", hMenu, hPopupMenu );
    414             return hMenu;
    415         }
    416         DestroyMenu( hMenu );
     415        TRACE("GetSysMenu hMenu=%04x (%04x)\n", hMenu, hPopupMenu );
     416        return hMenu;
     417    }
     418    DestroyMenu( hMenu );
    417419    }
    418420    ERR("failed to load system menu!\n");
     
    432434
    433435    static unsigned char shade_bits[16] = { 0x55, 0, 0xAA, 0,
    434                                             0x55, 0, 0xAA, 0,
    435                                             0x55, 0, 0xAA, 0,
    436                                             0x55, 0, 0xAA, 0 };
     436                        0x55, 0, 0xAA, 0,
     437                        0x55, 0, 0xAA, 0,
     438                        0x55, 0, 0xAA, 0 };
    437439
    438440    /* Load menu bitmaps */
     
    443445    if (hStdMnArrow)
    444446    {
    445         BITMAP bm;
    446         GetObjectA( hStdMnArrow, sizeof(bm), &bm );
    447         arrow_bitmap_width = bm.bmWidth;
    448         arrow_bitmap_height = bm.bmHeight;
     447    BITMAP bm;
     448    GetObjectA( hStdMnArrow, sizeof(bm), &bm );
     449    arrow_bitmap_width = bm.bmWidth;
     450    arrow_bitmap_height = bm.bmHeight;
    449451    } else
    450         return FALSE;
     452    return FALSE;
    451453
    452454    if (! (hBitmap = CreateBitmap( 8, 8, 1, 1, shade_bits)))
    453         return FALSE;
     455    return FALSE;
    454456
    455457    if(!(hShadeBrush = CreatePatternBrush( hBitmap )))
    456         return FALSE;
     458    return FALSE;
    457459
    458460    DeleteObject( hBitmap );
    459461    if (!(MENU_DefSysPopup = MENU_CopySysPopup()))
    460         return FALSE;
     462    return FALSE;
    461463
    462464    ncm.cbSize = sizeof (NONCLIENTMETRICSA);
    463465    if (!(SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSA), &ncm, 0)))
    464         return FALSE;
     466    return FALSE;
    465467
    466468    if (!(hMenuFont = CreateFontIndirectA( &ncm.lfMenuFont )))
    467         return FALSE;
     469    return FALSE;
    468470
    469471    ncm.lfMenuFont.lfWeight += 300;
    470472    if ( ncm.lfMenuFont.lfWeight > 1000)
    471         ncm.lfMenuFont.lfWeight = 1000;
     473    ncm.lfMenuFont.lfWeight = 1000;
    472474
    473475    if (!(hMenuFontBold = CreateFontIndirectA( &ncm.lfMenuFont )))
    474         return FALSE;
     476    return FALSE;
    475477
    476478    return TRUE;
     
    500502    /* The menu item must keep its state if it's disabled */
    501503    if(gray)
    502         EnableMenuItem( hmenu, SC_CLOSE, MF_GRAYED);
     504    EnableMenuItem( hmenu, SC_CLOSE, MF_GRAYED);
    503505}
    504506
     
    518520
    519521    if(!menu)
    520         return NO_SELECTED_ITEM;
     522    return NO_SELECTED_ITEM;
    521523
    522524    i = menu->FocusedItem + 1;
    523525    if( i == NO_SELECTED_ITEM )
    524         return i;
     526    return i;
    525527
    526528    for( ; i < menu->nItems; ++i ) {
    527         if (menu->items[i].fType & MF_MENUBARBREAK)
    528             return i;
     529    if (menu->items[i].fType & MF_MENUBARBREAK)
     530        return i;
    529531    }
    530532
     
    547549
    548550    if( !menu )
    549         return NO_SELECTED_ITEM;
     551    return NO_SELECTED_ITEM;
    550552
    551553    if( menu->FocusedItem == 0 || menu->FocusedItem == NO_SELECTED_ITEM )
    552         return NO_SELECTED_ITEM;
     554    return NO_SELECTED_ITEM;
    553555
    554556    /* Find the start of the column */
    555557
    556558    for(i = menu->FocusedItem; i != 0 &&
    557         !(menu->items[i].fType & MF_MENUBARBREAK);
    558         --i); /* empty */
     559    !(menu->items[i].fType & MF_MENUBARBREAK);
     560    --i); /* empty */
    559561
    560562    if(i == 0)
    561         return NO_SELECTED_ITEM;
     563    return NO_SELECTED_ITEM;
    562564
    563565    for(--i; i != 0; --i) {
    564         if (menu->items[i].fType & MF_MENUBARBREAK)
    565             break;
     566    if (menu->items[i].fType & MF_MENUBARBREAK)
     567        break;
    566568    }
    567569
     
    587589    if (wFlags & MF_BYPOSITION)
    588590    {
    589         if (*nPos >= menu->nItems) return NULL;
    590         return &menu->items[*nPos];
     591    if (*nPos >= menu->nItems) return NULL;
     592    return &menu->items[*nPos];
    591593    }
    592594    else
    593595    {
    594596        MENUITEM *item = menu->items;
    595         for (i = 0; i < menu->nItems; i++, item++)
    596         {
    597             if (item->wID == *nPos)
    598             {
    599                 *nPos = i;
    600                 return item;
    601             }
    602             else if (item->fType & MF_POPUP)
    603             {
    604                 HMENU hsubmenu = item->hSubMenu;
    605                 MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags );
     597    for (i = 0; i < menu->nItems; i++, item++)
     598    {
     599        if (item->wID == *nPos)
     600        {
     601        *nPos = i;
     602        return item;
     603        }
     604        else if (item->fType & MF_POPUP)
     605        {
     606        HMENU hsubmenu = item->hSubMenu;
     607        MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags );
    606608#ifdef __WIN32OS2__
    607609                //YD: 2000-12-01: extra check added for loops in menus
    608610                if (subitem && subitem!=item)
    609611#else
    610                 if (subitem)
     612        if (subitem)
    611613#endif
    612                 {
    613                     *hmenu = hsubmenu;
    614                     return subitem;
    615                 }
    616             }
    617         }
     614        {
     615            *hmenu = hsubmenu;
     616            return subitem;
     617        }
     618        }
     619    }
    618620    }
    619621    return NULL;
     
    671673 */
    672674static MENUITEM *MENU_FindItemByCoords( POPUPMENU *menu,
    673                                         POINT pt, UINT *pos )
     675                    POINT pt, UINT *pos )
    674676{
    675677    MENUITEM *item;
     
    682684    for (i = 0; i < menu->nItems; i++, item++)
    683685    {
    684         if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) &&
    685             (pt.y >= item->rect.top) && (pt.y < item->rect.bottom))
    686         {
    687             if (pos) *pos = i;
    688             return item;
    689         }
     686    if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) &&
     687        (pt.y >= item->rect.top) && (pt.y < item->rect.bottom))
     688    {
     689        if (pos) *pos = i;
     690        return item;
     691    }
    690692    }
    691693    return NULL;
     
    700702 */
    701703static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu,
    702                                   UINT key, BOOL forceMenuChar )
     704                  UINT key, BOOL forceMenuChar )
    703705{
    704706    TRACE("\tlooking for '%c' in [%04x]\n", (char)key, (UINT16)hmenu );
     
    708710    if (hmenu)
    709711    {
    710         POPUPMENU *menu = MENU_GetMenu( hmenu );
    711         MENUITEM *item = menu->items;
    712         LONG menuchar;
    713 
    714         if( !forceMenuChar )
    715         {
    716              UINT i;
    717 
    718              key = toupper(key);
    719              for (i = 0; i < menu->nItems; i++, item++)
    720              {
    721                 if (item->text && (IS_STRING_ITEM(item->fType)))
    722                 {
    723                     WCHAR *p = item->text - 2;
    724                     do
    725                     {
    726                         p = strchrW (p + 2, '&');
    727                     }
    728                     while (p != NULL && p [1] == '&');
    729                     if (p && (toupper(p[1]) == key)) return i;
    730                 }
    731              }
    732         }
    733         menuchar = SendMessageA( hwndOwner, WM_MENUCHAR,
     712    POPUPMENU *menu = MENU_GetMenu( hmenu );
     713    MENUITEM *item = menu->items;
     714    LONG menuchar;
     715
     716    if( !forceMenuChar )
     717    {
     718         UINT i;
     719
     720         key = toupper(key);
     721         for (i = 0; i < menu->nItems; i++, item++)
     722         {
     723        if (item->text && (IS_STRING_ITEM(item->fType)))
     724        {
     725            WCHAR *p = item->text - 2;
     726            do
     727            {
     728                p = strchrW (p + 2, '&');
     729            }
     730            while (p != NULL && p [1] == '&');
     731            if (p && (toupper(p[1]) == key)) return i;
     732        }
     733         }
     734    }
     735    menuchar = SendMessageA( hwndOwner, WM_MENUCHAR,
    734736                                   MAKEWPARAM( key, menu->wFlags ), hmenu );
    735         if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
    736         if (HIWORD(menuchar) == 1) return (UINT)(-2);
     737    if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
     738    if (HIWORD(menuchar) == 1) return (UINT)(-2);
    737739    }
    738740    return (UINT)(-1);
     
    888890 */
    889891static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner,
    890                                INT orgX, INT orgY, BOOL menuBar )
     892                   INT orgX, INT orgY, BOOL menuBar )
    891893{
    892894    WCHAR *p;
     
    895897    TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY);
    896898    debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem,
    897                         (menuBar ? " (MenuBar)" : ""));
     899            (menuBar ? " (MenuBar)" : ""));
    898900
    899901    SetRect( &lpitem->rect, orgX, orgY, orgX, orgY );
     
    918920        lpitem->rect.right  += mis.itemWidth;
    919921
    920         if (menuBar)
    921         {
    922              lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
     922    if (menuBar)
     923    {
     924         lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
    923925
    924926
     
    926928                height for the menu and the height value is ignored */
    927929
    928              if (TWEAK_WineLook == WIN31_LOOK)
    929                 lpitem->rect.bottom += GetSystemMetrics(SM_CYMENU);
    930              else
    931                 lpitem->rect.bottom += GetSystemMetrics(SM_CYMENU)-1;
     930         if (TWEAK_WineLook == WIN31_LOOK)
     931            lpitem->rect.bottom += GetSystemMetrics(SM_CYMENU);
     932         else
     933            lpitem->rect.bottom += GetSystemMetrics(SM_CYMENU)-1;
    932934        }
    933935        else
    934936            lpitem->rect.bottom += mis.itemHeight;
    935937
    936         TRACE("id=%04x size=%dx%d\n",
     938    TRACE("id=%04x size=%dx%d\n",
    937939                     lpitem->wID, mis.itemWidth, mis.itemHeight);
    938940        /* Fall through to get check/arrow width calculation. */
     
    941943    if (lpitem->fType & MF_SEPARATOR)
    942944    {
    943         lpitem->rect.bottom += SEPARATOR_HEIGHT;
    944         return;
     945    lpitem->rect.bottom += SEPARATOR_HEIGHT;
     946    return;
    945947    }
    946948
    947949    if (!menuBar)
    948950    {
    949         lpitem->rect.right += 2 * check_bitmap_width;
    950         if (lpitem->fType & MF_POPUP)
    951             lpitem->rect.right += arrow_bitmap_width;
     951    lpitem->rect.right += 2 * check_bitmap_width;
     952    if (lpitem->fType & MF_POPUP)
     953        lpitem->rect.right += arrow_bitmap_width;
    952954    }
    953955
     
    975977    {   SIZE size;
    976978
    977         GetTextExtentPoint32W(hdc, lpitem->text,  strlenW(lpitem->text), &size);
    978 
    979         lpitem->rect.right  += size.cx;
    980         if (TWEAK_WineLook == WIN31_LOOK)
    981             lpitem->rect.bottom += max( size.cy, GetSystemMetrics(SM_CYMENU) );
    982         else
    983             lpitem->rect.bottom += max(size.cy, GetSystemMetrics(SM_CYMENU)-1);
    984         lpitem->xTab = 0;
    985 
    986         if (menuBar)
    987         {
    988              lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
    989         }
    990         else if ((p = strchrW( lpitem->text, '\t' )) != NULL)
    991         {
    992             /* Item contains a tab (only meaningful in popup menus) */
    993             GetTextExtentPoint32W(hdc, lpitem->text, (int)(p - lpitem->text) , &size);
    994             lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE + size.cx;
    995             lpitem->rect.right += MENU_TAB_SPACE;
    996         }
    997         else
    998         {
    999             if (strchrW( lpitem->text, '\b' ))
    1000                 lpitem->rect.right += MENU_TAB_SPACE;
    1001             lpitem->xTab = lpitem->rect.right - check_bitmap_width
    1002                            - arrow_bitmap_width;
    1003         }
     979    GetTextExtentPoint32W(hdc, lpitem->text,  strlenW(lpitem->text), &size);
     980
     981    lpitem->rect.right  += size.cx;
     982    if (TWEAK_WineLook == WIN31_LOOK)
     983        lpitem->rect.bottom += max( size.cy, GetSystemMetrics(SM_CYMENU) );
     984    else
     985        lpitem->rect.bottom += max(size.cy, GetSystemMetrics(SM_CYMENU)-1);
     986    lpitem->xTab = 0;
     987
     988    if (menuBar)
     989    {
     990         lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
     991    }
     992    else if ((p = strchrW( lpitem->text, '\t' )) != NULL)
     993    {
     994        /* Item contains a tab (only meaningful in popup menus) */
     995        GetTextExtentPoint32W(hdc, lpitem->text, (int)(p - lpitem->text) , &size);
     996        lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE + size.cx;
     997        lpitem->rect.right += MENU_TAB_SPACE;
     998    }
     999    else
     1000    {
     1001        if (strchrW( lpitem->text, '\b' ))
     1002            lpitem->rect.right += MENU_TAB_SPACE;
     1003        lpitem->xTab = lpitem->rect.right - check_bitmap_width
     1004                       - arrow_bitmap_width;
     1005    }
    10041006    }
    10051007    TRACE("(%d,%d)-(%d,%d)\n", lpitem->rect.left, lpitem->rect.top, lpitem->rect.right, lpitem->rect.bottom);
     
    10341036    while (start < lppop->nItems)
    10351037    {
    1036         lpitem = &lppop->items[start];
    1037         orgX = maxX;
    1038         orgY = (TWEAK_WineLook == WIN31_LOOK) ? GetSystemMetrics(SM_CYBORDER) : 2;
    1039 
    1040         maxTab = maxTabWidth = 0;
    1041 
    1042           /* Parse items until column break or end of menu */
    1043         for (i = start; i < lppop->nItems; i++, lpitem++)
    1044         {
    1045             if ((i != start) &&
    1046                 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
    1047 
    1048             MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
    1049 
    1050             if (lpitem->fType & MF_MENUBARBREAK) orgX++;
    1051             maxX = max( maxX, lpitem->rect.right );
    1052             orgY = lpitem->rect.bottom;
    1053             if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
    1054             {
    1055                 maxTab = max( maxTab, lpitem->xTab );
    1056                 maxTabWidth = max(maxTabWidth,lpitem->rect.right-lpitem->xTab);
    1057             }
    1058         }
    1059 
    1060           /* Finish the column (set all items to the largest width found) */
    1061         maxX = max( maxX, maxTab + maxTabWidth );
    1062         for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
    1063         {
    1064             lpitem->rect.right = maxX;
    1065             if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
    1066                 lpitem->xTab = maxTab;
    1067 
    1068         }
    1069         lppop->Height = max( lppop->Height, orgY );
     1038    lpitem = &lppop->items[start];
     1039    orgX = maxX;
     1040    orgY = (TWEAK_WineLook == WIN31_LOOK) ? GetSystemMetrics(SM_CYBORDER) : 2;
     1041
     1042    maxTab = maxTabWidth = 0;
     1043
     1044      /* Parse items until column break or end of menu */
     1045    for (i = start; i < lppop->nItems; i++, lpitem++)
     1046    {
     1047        if ((i != start) &&
     1048        (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
     1049
     1050        MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
     1051
     1052        if (lpitem->fType & MF_MENUBARBREAK) orgX++;
     1053        maxX = max( maxX, lpitem->rect.right );
     1054        orgY = lpitem->rect.bottom;
     1055        if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
     1056        {
     1057        maxTab = max( maxTab, lpitem->xTab );
     1058        maxTabWidth = max(maxTabWidth,lpitem->rect.right-lpitem->xTab);
     1059        }
     1060    }
     1061
     1062      /* Finish the column (set all items to the largest width found) */
     1063    maxX = max( maxX, maxTab + maxTabWidth );
     1064    for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
     1065    {
     1066        lpitem->rect.right = maxX;
     1067        if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
     1068        lpitem->xTab = maxTab;
     1069
     1070    }
     1071    lppop->Height = max( lppop->Height, orgY );
    10701072    }
    10711073
     
    10751077    if(TWEAK_WineLook > WIN31_LOOK)
    10761078    {
    1077         lppop->Height += 2;
    1078         lppop->Width += 2;
     1079    lppop->Height += 2;
     1080    lppop->Width += 2;
    10791081    }
    10801082
     
    11131115    while (start < lppop->nItems)
    11141116    {
    1115         lpitem = &lppop->items[start];
    1116         orgX = lprect->left;
    1117         orgY = maxY;
    1118 
    1119           /* Parse items until line break or end of menu */
    1120         for (i = start; i < lppop->nItems; i++, lpitem++)
    1121         {
    1122             if ((helpPos == -1) && (lpitem->fType & MF_RIGHTJUSTIFY)) helpPos = i;
    1123             if ((i != start) &&
    1124                 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
    1125 
    1126             TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
    1127                         orgX, orgY );
    1128             debug_print_menuitem ("  item: ", lpitem, "");
    1129             MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE );
    1130 
    1131             if (lpitem->rect.right > lprect->right)
    1132             {
    1133                 if (i != start) break;
    1134                 else lpitem->rect.right = lprect->right;
    1135             }
    1136             maxY = max( maxY, lpitem->rect.bottom );
    1137             orgX = lpitem->rect.right;
    1138         }
    1139 
    1140           /* Finish the line (set all items to the largest height found) */
    1141         while (start < i) lppop->items[start++].rect.bottom = maxY;
     1117    lpitem = &lppop->items[start];
     1118    orgX = lprect->left;
     1119    orgY = maxY;
     1120
     1121      /* Parse items until line break or end of menu */
     1122    for (i = start; i < lppop->nItems; i++, lpitem++)
     1123    {
     1124        if ((helpPos == -1) && (lpitem->fType & MF_RIGHTJUSTIFY)) helpPos = i;
     1125        if ((i != start) &&
     1126        (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
     1127
     1128        TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
     1129            orgX, orgY );
     1130        debug_print_menuitem ("  item: ", lpitem, "");
     1131        MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE );
     1132
     1133        if (lpitem->rect.right > lprect->right)
     1134        {
     1135        if (i != start) break;
     1136        else lpitem->rect.right = lprect->right;
     1137        }
     1138        maxY = max( maxY, lpitem->rect.bottom );
     1139        orgX = lpitem->rect.right;
     1140    }
     1141
     1142      /* Finish the line (set all items to the largest height found) */
     1143    while (start < i) lppop->items[start++].rect.bottom = maxY;
    11421144    }
    11431145
     
    11521154    for (i = lppop->nItems - 1; i >= helpPos; i--, lpitem--) {
    11531155        if ( (helpPos==-1) || (helpPos>i) )
    1154             break;                              /* done */
    1155         if (lpitem->rect.top != orgY) break;    /* Other line */
    1156         if (lpitem->rect.right >= orgX) break;  /* Too far right already */
     1156            break;              /* done */
     1157        if (lpitem->rect.top != orgY) break;    /* Other line */
     1158        if (lpitem->rect.right >= orgX) break;  /* Too far right already */
    11571159        lpitem->rect.left += orgX - lpitem->rect.right;
    11581160        lpitem->rect.right = orgX;
     
    11671169 */
    11681170static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc, MENUITEM *lpitem,
    1169                                UINT height, BOOL menuBar, UINT odaction )
     1171                   UINT height, BOOL menuBar, UINT odaction )
    11701172{
    11711173    RECT rect;
     
    11751177    if (lpitem->fType & MF_SYSMENU)
    11761178    {
    1177         if( !IsIconic(hwnd) ) {
    1178             if (TWEAK_WineLook > WIN31_LOOK)
    1179                 NC_DrawSysButton95( hwnd, hdc,
    1180                                     lpitem->fState &
    1181                                     (MF_HILITE | MF_MOUSESELECT) );
    1182             else
    1183                 NC_DrawSysButton( hwnd, hdc,
    1184                                   lpitem->fState &
    1185                                   (MF_HILITE | MF_MOUSESELECT) );
    1186         }
    1187 
    1188         return;
     1179    if( !IsIconic(hwnd) ) {
     1180        if (TWEAK_WineLook > WIN31_LOOK)
     1181        NC_DrawSysButton95( hwnd, hdc,
     1182                    lpitem->fState &
     1183                    (MF_HILITE | MF_MOUSESELECT) );
     1184        else
     1185        NC_DrawSysButton( hwnd, hdc,
     1186                  lpitem->fState &
     1187                  (MF_HILITE | MF_MOUSESELECT) );
     1188    }
     1189
     1190    return;
    11891191    }
    11901192
     
    12031205
    12041206        dis.CtlType   = ODT_MENU;
    1205         dis.CtlID     = 0;
     1207    dis.CtlID     = 0;
    12061208        dis.itemID    = lpitem->wID;
    12071209        dis.itemData  = (DWORD)lpitem->dwItemData;
     
    12151217        dis.rcItem     = lpitem->rect;
    12161218        TRACE("Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
    1217               "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner,
    1218               dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
    1219               dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right,
    1220               dis.rcItem.bottom);
     1219          "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner,
     1220          dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
     1221          dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right,
     1222          dis.rcItem.bottom);
    12211223        SendMessageA( hwndOwner, WM_DRAWITEM, 0, (LPARAM)&dis );
    12221224        /* Fall through to draw popup-menu arrow */
     
    12241226
    12251227    TRACE("rect={%d,%d,%d,%d}\n", lpitem->rect.left, lpitem->rect.top,
    1226                                         lpitem->rect.right,lpitem->rect.bottom);
     1228                    lpitem->rect.right,lpitem->rect.bottom);
    12271229
    12281230    if (menuBar && (lpitem->fType & MF_SEPARATOR)) return;
     
    12321234    if (!(lpitem->fType & MF_OWNERDRAW))
    12331235    {
    1234         if (lpitem->fState & MF_HILITE)
    1235         {
     1236    if (lpitem->fState & MF_HILITE)
     1237    {
    12361238#ifdef __WIN32OS2__
    1237             if(!fOS2Look) 
     1239            if(!fOS2Look)
    12381240#else
    1239             if(TWEAK_WineLook == WIN98_LOOK)
     1241        if(TWEAK_WineLook == WIN98_LOOK)
    12401242#endif
    1241             {
    1242                 if(menuBar)
    1243                     DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
    1244                 else
    1245                     FillRect(hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT));
    1246             }
    1247             else /* Not Win98 Look */
    1248             {
    1249                 if(!IS_BITMAP_ITEM(lpitem->fType))
     1243        {
     1244        if(menuBar)
     1245            DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
     1246        else
     1247            FillRect(hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT));
     1248        }
     1249        else /* Not Win98 Look */
     1250        {
     1251        if(!IS_BITMAP_ITEM(lpitem->fType))
    12501252#ifdef __WIN32OS2__
    1251                     FillRect(hdc, &rect, GetOS2ColorBrush(PMSYSCLR_MENUHILITEBGND));
     1253            FillRect(hdc, &rect, GetOS2ColorBrush(PMSYSCLR_MENUHILITEBGND));
    12521254#else
    1253                     FillRect(hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT));
     1255            FillRect(hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT));
    12541256#endif
    1255             }
    1256         }
     1257        }
     1258    }
    12571259        else
    1258             FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) );
     1260        FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) );
    12591261    }
    12601262
     
    12661268        if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
    12671269        {
    1268             if (TWEAK_WineLook > WIN31_LOOK)
    1269             {
    1270                 RECT rc = rect;
    1271                 rc.top = 3;
    1272                 rc.bottom = height - 3;
    1273                 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT);
    1274             }
    1275             else
    1276             {
    1277                 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
    1278                 MoveToEx( hdc, rect.left, 0, NULL );
    1279                 LineTo( hdc, rect.left, height );
    1280             }
     1270        if (TWEAK_WineLook > WIN31_LOOK)
     1271        {
     1272            RECT rc = rect;
     1273            rc.top = 3;
     1274            rc.bottom = height - 3;
     1275            DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT);
     1276        }
     1277        else
     1278        {
     1279            SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
     1280            MoveToEx( hdc, rect.left, 0, NULL );
     1281            LineTo( hdc, rect.left, height );
     1282        }
    12811283        }
    12821284
     
    12841286        if (lpitem->fType & MF_SEPARATOR)
    12851287        {
    1286             if (TWEAK_WineLook > WIN31_LOOK)
    1287             {
    1288                 RECT rc = rect;
    1289                 rc.left++;
    1290                 rc.right--;
    1291                 rc.top += SEPARATOR_HEIGHT / 2;
    1292                 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
    1293             }
    1294             else
    1295             {
    1296                 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
    1297                 MoveToEx( hdc, rect.left, rect.top + SEPARATOR_HEIGHT/2, NULL );
    1298                 LineTo( hdc, rect.right, rect.top + SEPARATOR_HEIGHT/2 );
    1299             }
    1300             return;
     1288        if (TWEAK_WineLook > WIN31_LOOK)
     1289        {
     1290            RECT rc = rect;
     1291            rc.left++;
     1292            rc.right--;
     1293            rc.top += SEPARATOR_HEIGHT / 2;
     1294            DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
     1295        }
     1296        else
     1297        {
     1298            SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
     1299            MoveToEx( hdc, rect.left, rect.top + SEPARATOR_HEIGHT/2, NULL );
     1300            LineTo( hdc, rect.right, rect.top + SEPARATOR_HEIGHT/2 );
     1301        }
     1302        return;
    13011303        }
    13021304    }
     
    13071309    {
    13081310#ifdef __WIN32OS2__
    1309         if(!fOS2Look) 
     1311        if(!fOS2Look)
    13101312#else
    1311         if(TWEAK_WineLook == WIN98_LOOK)
     1313    if(TWEAK_WineLook == WIN98_LOOK)
    13121314#endif
    1313         {
     1315    {
    13141316            if(menuBar) {
    1315                 SetTextColor(hdc, GetSysColor(COLOR_MENUTEXT));
     1317        SetTextColor(hdc, GetSysColor(COLOR_MENUTEXT));
    13161318                SetBkColor(hdc, GetSysColor(COLOR_MENU));
    1317             } else {
    1318                 if(lpitem->fState & MF_GRAYED)
    1319                     SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
    1320                 else
    1321                     SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
     1319        } else {
     1320        if(lpitem->fState & MF_GRAYED)
     1321            SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
     1322        else
     1323            SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
    13221324                SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
    1323             }
    1324         }
    1325         else /* Not Win98 Look */
    1326         {
    1327             SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
    1328             if(!IS_BITMAP_ITEM(lpitem->fType))
     1325        }
     1326    }
     1327    else /* Not Win98 Look */
     1328    {
     1329        SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
     1330        if(!IS_BITMAP_ITEM(lpitem->fType))
    13291331#ifdef __WIN32OS2__
    1330                 SetBkColor(hdc, GetOS2Color(PMSYSCLR_MENUHILITEBGND));
     1332        SetBkColor(hdc, GetOS2Color(PMSYSCLR_MENUHILITEBGND));
    13311333#else
    1332                 SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
     1334        SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
    13331335#endif
    1334         }
     1336    }
    13351337    }
    13361338    else
    13371339    {
    1338         if (lpitem->fState & MF_GRAYED)
    1339             SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
    1340         else
    1341             SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) );
    1342         SetBkColor( hdc, GetSysColor( COLOR_MENU ) );
    1343     }
    1344 
    1345         /* helper lines for debugging */
    1346 /*      FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
    1347         SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
    1348         MoveToEx( hdc, rect.left, (rect.top + rect.bottom)/2, NULL );
    1349         LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
     1340    if (lpitem->fState & MF_GRAYED)
     1341        SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
     1342    else
     1343        SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) );
     1344    SetBkColor( hdc, GetSysColor( COLOR_MENU ) );
     1345    }
     1346
     1347    /* helper lines for debugging */
     1348/*  FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
     1349    SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
     1350    MoveToEx( hdc, rect.left, (rect.top + rect.bottom)/2, NULL );
     1351    LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
    13501352*/
    13511353
    13521354    if (!menuBar)
    13531355    {
    1354         INT     y = rect.top + rect.bottom;
     1356    INT y = rect.top + rect.bottom;
    13551357        UINT check_bitmap_width = GetSystemMetrics( SM_CXMENUCHECK );
    13561358        UINT check_bitmap_height = GetSystemMetrics( SM_CYMENUCHECK );
     
    13581360        if (!(lpitem->fType & MF_OWNERDRAW))
    13591361        {
    1360               /* Draw the check mark
    1361                *
    1362                * FIXME:
    1363                * Custom checkmark bitmaps are monochrome but not always 1bpp.
    1364                */
     1362          /* Draw the check mark
     1363           *
     1364           * FIXME:
     1365           * Custom checkmark bitmaps are monochrome but not always 1bpp.
     1366           */
    13651367            HBITMAP bm = (lpitem->fState & MF_CHECKED) ? lpitem->hCheckBit : lpitem->hUnCheckBit;
    13661368            if (bm)  /* we have a custom bitmap */
     
    13901392        }
    13911393
    1392           /* Draw the popup-menu arrow */
    1393         if (lpitem->fType & MF_POPUP)
    1394         {
    1395             HDC hdcMem = CreateCompatibleDC( hdc );
    1396             HBITMAP hOrigBitmap;
    1397 
    1398             hOrigBitmap = SelectObject( hdcMem, hStdMnArrow );
    1399             BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
    1400                       (y - arrow_bitmap_height) / 2,
    1401                       arrow_bitmap_width, arrow_bitmap_height,
    1402                       hdcMem, 0, 0, SRCCOPY );
     1394      /* Draw the popup-menu arrow */
     1395    if (lpitem->fType & MF_POPUP)
     1396    {
     1397        HDC hdcMem = CreateCompatibleDC( hdc );
     1398        HBITMAP hOrigBitmap;
     1399
     1400        hOrigBitmap = SelectObject( hdcMem, hStdMnArrow );
     1401        BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
     1402              (y - arrow_bitmap_height) / 2,
     1403              arrow_bitmap_width, arrow_bitmap_height,
     1404              hdcMem, 0, 0, SRCCOPY );
    14031405            SelectObject( hdcMem, hOrigBitmap );
    1404             DeleteDC( hdcMem );
    1405         }
    1406 
    1407         rect.left += check_bitmap_width;
    1408         rect.right -= arrow_bitmap_width;
     1406        DeleteDC( hdcMem );
     1407    }
     1408
     1409    rect.left += check_bitmap_width;
     1410    rect.right -= arrow_bitmap_width;
    14091411    }
    14101412
     
    14171419    {
    14181420        MENU_DrawBitmapItem( hdc, lpitem, &rect, menuBar );
    1419         return;
     1421    return;
    14201422
    14211423    }
     
    14231425    else if (IS_STRING_ITEM(lpitem->fType))
    14241426    {
    1425         register int i;
    1426         HFONT hfontOld = 0;
    1427 
    1428         UINT uFormat = (menuBar) ?
    1429                         DT_CENTER | DT_VCENTER | DT_SINGLELINE :
    1430                         DT_LEFT | DT_VCENTER | DT_SINGLELINE;
     1427    register int i;
     1428    HFONT hfontOld = 0;
     1429
     1430    UINT uFormat = (menuBar) ?
     1431            DT_CENTER | DT_VCENTER | DT_SINGLELINE :
     1432            DT_LEFT | DT_VCENTER | DT_SINGLELINE;
    14311433
    14321434#ifdef __WIN32OS2__
    1433         if ( lpitem->fState & MFS_DEFAULT && !fOS2Look)
     1435    if ( lpitem->fState & MFS_DEFAULT && !fOS2Look)
    14341436#else
    1435         if ( lpitem->fState & MFS_DEFAULT )
     1437    if ( lpitem->fState & MFS_DEFAULT )
    14361438#endif
    1437         {
    1438              hfontOld = SelectObject( hdc, hMenuFontBold);
    1439         }
    1440 
    1441         if (menuBar)
    1442         {
    1443             rect.left += MENU_BAR_ITEMS_SPACE / 2;
    1444             rect.right -= MENU_BAR_ITEMS_SPACE / 2;
    1445         }
    1446 
    1447         for (i = 0; lpitem->text[i]; i++)
    1448             if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b'))
    1449                 break;
    1450 
    1451         if( (TWEAK_WineLook != WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
    1452         {
    1453             if (!(lpitem->fState & MF_HILITE) )
    1454             {
    1455                 ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
    1456                 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
    1457                 DrawTextW( hdc, lpitem->text, i, &rect, uFormat );
    1458                 --rect.left; --rect.top; --rect.right; --rect.bottom;
    1459             }
    1460             SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
    1461         }
    1462 
    1463         DrawTextW( hdc, lpitem->text, i, &rect, uFormat);
    1464 
    1465         /* paint the shortcut text */
    1466         if (!menuBar && lpitem->text[i])  /* There's a tab or flush-right char */
    1467         {
    1468             if (lpitem->text[i] == '\t')
    1469             {
    1470                 rect.left = lpitem->xTab;
    1471                 uFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
    1472             }
    1473             else
    1474             {
    1475                 uFormat = DT_RIGHT | DT_VCENTER | DT_SINGLELINE;
    1476             }
    1477 
    1478             if( !(TWEAK_WineLook == WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
    1479             {
    1480                 if (!(lpitem->fState & MF_HILITE) )
    1481                 {
    1482                     ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
    1483                     SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
    1484                     DrawTextW( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
    1485                     --rect.left; --rect.top; --rect.right; --rect.bottom;
    1486                 }
    1487                 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
    1488             }
    1489             DrawTextW( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
    1490         }
    1491 
    1492         if (hfontOld)
    1493             SelectObject (hdc, hfontOld);
     1439    {
     1440         hfontOld = SelectObject( hdc, hMenuFontBold);
     1441    }
     1442
     1443    if (menuBar)
     1444    {
     1445        rect.left += MENU_BAR_ITEMS_SPACE / 2;
     1446        rect.right -= MENU_BAR_ITEMS_SPACE / 2;
     1447    }
     1448
     1449    for (i = 0; lpitem->text[i]; i++)
     1450        if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b'))
     1451            break;
     1452
     1453    if( (TWEAK_WineLook != WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
     1454    {
     1455        if (!(lpitem->fState & MF_HILITE) )
     1456        {
     1457        ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
     1458        SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
     1459        DrawTextW( hdc, lpitem->text, i, &rect, uFormat );
     1460        --rect.left; --rect.top; --rect.right; --rect.bottom;
     1461        }
     1462        SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
     1463    }
     1464
     1465    DrawTextW( hdc, lpitem->text, i, &rect, uFormat);
     1466
     1467    /* paint the shortcut text */
     1468    if (!menuBar && lpitem->text[i])  /* There's a tab or flush-right char */
     1469    {
     1470        if (lpitem->text[i] == '\t')
     1471        {
     1472        rect.left = lpitem->xTab;
     1473        uFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
     1474        }
     1475        else
     1476        {
     1477        uFormat = DT_RIGHT | DT_VCENTER | DT_SINGLELINE;
     1478        }
     1479
     1480        if( !(TWEAK_WineLook == WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
     1481        {
     1482        if (!(lpitem->fState & MF_HILITE) )
     1483        {
     1484            ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
     1485            SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
     1486            DrawTextW( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
     1487            --rect.left; --rect.top; --rect.right; --rect.bottom;
     1488        }
     1489        SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
     1490        }
     1491        DrawTextW( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
     1492    }
     1493
     1494    if (hfontOld)
     1495        SelectObject (hdc, hfontOld);
    14941496    }
    14951497}
     
    15121514    if(TWEAK_WineLook == WIN31_LOOK)
    15131515    {
    1514         rect.bottom -= POPUP_YSHADE * GetSystemMetrics(SM_CYBORDER);
    1515         rect.right -= POPUP_XSHADE * GetSystemMetrics(SM_CXBORDER);
     1516    rect.bottom -= POPUP_YSHADE * GetSystemMetrics(SM_CYBORDER);
     1517    rect.right -= POPUP_XSHADE * GetSystemMetrics(SM_CXBORDER);
    15161518    }
    15171519
     
    15191521        && (SelectObject( hdc, hMenuFont)))
    15201522    {
    1521         HPEN hPrevPen;
    1522 
    1523         Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
    1524 
    1525         hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) );
    1526         if( hPrevPen )
    1527         {
    1528             INT ropPrev, i;
    1529             POPUPMENU *menu;
    1530 
    1531             /* draw 3-d shade */
    1532             if(TWEAK_WineLook == WIN31_LOOK) {
    1533                 SelectObject( hdc, hShadeBrush );
    1534                 SetBkMode( hdc, TRANSPARENT );
    1535                 ropPrev = SetROP2( hdc, R2_MASKPEN );
    1536 
    1537                 i = rect.right;         /* why SetBrushOrg() doesn't? */
    1538                 PatBlt( hdc, i & 0xfffffffe,
    1539                           rect.top + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER),
    1540                           i%2 + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
    1541                           rect.bottom - rect.top, 0x00a000c9 );
    1542                 i = rect.bottom;
    1543                 PatBlt( hdc, rect.left + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
    1544                           i & 0xfffffffe,rect.right - rect.left,
    1545                           i%2 + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER), 0x00a000c9 );
    1546                 SelectObject( hdc, hPrevPen );
    1547                 SelectObject( hdc, hPrevBrush );
    1548                 SetROP2( hdc, ropPrev );
    1549             }
    1550             else
    1551                 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT);
    1552 
    1553             /* draw menu items */
    1554 
    1555             menu = MENU_GetMenu( hmenu );
    1556             if (menu && menu->nItems)
    1557             {
    1558                 MENUITEM *item;
    1559                 UINT u;
    1560 
    1561                 for (u = menu->nItems, item = menu->items; u > 0; u--, item++)
    1562                     MENU_DrawMenuItem( hwnd, hmenu, menu->hwndOwner, hdc, item,
    1563                                        menu->Height, FALSE, ODA_DRAWENTIRE );
    1564 
    1565             }
    1566         } else
    1567         {
    1568             SelectObject( hdc, hPrevBrush );
    1569         }
     1523    HPEN hPrevPen;
     1524
     1525    Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
     1526
     1527    hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) );
     1528    if( hPrevPen )
     1529    {
     1530        INT ropPrev, i;
     1531        POPUPMENU *menu;
     1532
     1533        /* draw 3-d shade */
     1534        if(TWEAK_WineLook == WIN31_LOOK) {
     1535        SelectObject( hdc, hShadeBrush );
     1536        SetBkMode( hdc, TRANSPARENT );
     1537        ropPrev = SetROP2( hdc, R2_MASKPEN );
     1538
     1539        i = rect.right;     /* why SetBrushOrg() doesn't? */
     1540        PatBlt( hdc, i & 0xfffffffe,
     1541              rect.top + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER),
     1542              i%2 + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
     1543              rect.bottom - rect.top, 0x00a000c9 );
     1544        i = rect.bottom;
     1545        PatBlt( hdc, rect.left + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
     1546              i & 0xfffffffe,rect.right - rect.left,
     1547              i%2 + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER), 0x00a000c9 );
     1548        SelectObject( hdc, hPrevPen );
     1549        SelectObject( hdc, hPrevBrush );
     1550        SetROP2( hdc, ropPrev );
     1551        }
     1552        else
     1553        DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT);
     1554
     1555        /* draw menu items */
     1556
     1557        menu = MENU_GetMenu( hmenu );
     1558        if (menu && menu->nItems)
     1559        {
     1560        MENUITEM *item;
     1561        UINT u;
     1562
     1563        for (u = menu->nItems, item = menu->items; u > 0; u--, item++)
     1564            MENU_DrawMenuItem( hwnd, hmenu, menu->hwndOwner, hdc, item,
     1565                       menu->Height, FALSE, ODA_DRAWENTIRE );
     1566
     1567        }
     1568    } else
     1569    {
     1570        SelectObject( hdc, hPrevBrush );
     1571    }
    15701572    }
    15711573}
     
    16111613    if (TWEAK_WineLook == WIN31_LOOK)
    16121614    {
    1613         SelectObject( hDC, GetSysColorPen(COLOR_WINDOWFRAME) );
    1614         MoveToEx( hDC, lprect->left, lprect->bottom, NULL );
    1615         LineTo( hDC, lprect->right, lprect->bottom );
     1615    SelectObject( hDC, GetSysColorPen(COLOR_WINDOWFRAME) );
     1616    MoveToEx( hDC, lprect->left, lprect->bottom, NULL );
     1617    LineTo( hDC, lprect->right, lprect->bottom );
    16161618    }
    16171619    else
    16181620    {
    1619         SelectObject( hDC, GetSysColorPen(COLOR_3DFACE));
    1620         MoveToEx( hDC, lprect->left, lprect->bottom, NULL );
    1621         LineTo( hDC, lprect->right, lprect->bottom );
     1621    SelectObject( hDC, GetSysColorPen(COLOR_3DFACE));
     1622    MoveToEx( hDC, lprect->left, lprect->bottom, NULL );
     1623    LineTo( hDC, lprect->right, lprect->bottom );
    16221624    }
    16231625
     
    16581660    if (menu->FocusedItem != NO_SELECTED_ITEM)
    16591661    {
    1660         menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
    1661         menu->FocusedItem = NO_SELECTED_ITEM;
     1662    menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
     1663    menu->FocusedItem = NO_SELECTED_ITEM;
    16621664    }
    16631665
     
    17371739    if (lppop->FocusedItem != NO_SELECTED_ITEM)
    17381740    {
    1739         lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
    1740         MENU_DrawMenuItem(lppop->hWnd, hmenu, hwndOwner, hdc,&lppop->items[lppop->FocusedItem],
     1741    lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
     1742    MENU_DrawMenuItem(lppop->hWnd, hmenu, hwndOwner, hdc,&lppop->items[lppop->FocusedItem],
    17411743                          lppop->Height, !(lppop->wFlags & MF_POPUP),
    1742                           ODA_SELECT );
     1744              ODA_SELECT );
    17431745    }
    17441746
     
    17561758        {
    17571759            MENUITEM *ip = &lppop->items[lppop->FocusedItem];
    1758             SendMessageA( hwndOwner, WM_MENUSELECT,
     1760        SendMessageA( hwndOwner, WM_MENUSELECT,
    17591761                     MAKELONG(ip->fType & MF_POPUP ? wIndex: ip->wID,
    17601762                     ip->fType | ip->fState | MF_MOUSESELECT |
     
    17971799    if ( menu->FocusedItem != NO_SELECTED_ITEM )
    17981800    {
    1799         if( menu->nItems == 1 ) return; else
    1800         for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems
    1801                                             ; i += offset)
    1802             if (!(menu->items[i].fType & MF_SEPARATOR))
    1803             {
    1804                 MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
    1805                 return;
    1806             }
     1801    if( menu->nItems == 1 ) return; else
     1802    for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems
     1803                        ; i += offset)
     1804        if (!(menu->items[i].fType & MF_SEPARATOR))
     1805        {
     1806        MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
     1807        return;
     1808        }
    18071809    }
    18081810
    18091811    for ( i = (offset > 0) ? 0 : menu->nItems - 1;
    1810                   i >= 0 && i < menu->nItems ; i += offset)
    1811         if (!(menu->items[i].fType & MF_SEPARATOR))
    1812         {
    1813             MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
    1814             return;
    1815         }
     1812          i >= 0 && i < menu->nItems ; i += offset)
     1813    if (!(menu->items[i].fType & MF_SEPARATOR))
     1814    {
     1815        MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
     1816        return;
     1817    }
    18161818}
    18171819
     
    18631865
    18641866    if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
    1865         DestroyMenu( item->hSubMenu );   /* ModifyMenu() spec */
     1867    DestroyMenu( item->hSubMenu );   /* ModifyMenu() spec */
    18661868
    18671869    if (flags & MF_POPUP)
    18681870    {
    1869         POPUPMENU *menu = MENU_GetMenu((UINT16)id);
     1871    POPUPMENU *menu = MENU_GetMenu((UINT16)id);
    18701872        if (menu) menu->wFlags |= MF_POPUP;
    1871         else
     1873    else
    18721874        {
    18731875            item->wID = 0;
     
    18751877            item->fType = 0;
    18761878            item->fState = 0;
    1877             return FALSE;
     1879        return FALSE;
    18781880        }
    18791881    }
     
    19291931
    19301932    /* Create new items array */
    1931 
    19321933    newItems = HeapAlloc( GetProcessHeap(), 0, sizeof(MENUITEM) * (menu->nItems+1) );
    19331934    if (!newItems)
     
    19381939    if (menu->nItems > 0)
    19391940    {
    1940           /* Copy the old array into the new one */
    1941         if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
    1942         if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
    1943                                         (menu->nItems-pos)*sizeof(MENUITEM) );
     1941      /* Copy the old array into the new one */
     1942    if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
     1943    if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
     1944                    (menu->nItems-pos)*sizeof(MENUITEM) );
    19441945        HeapFree( GetProcessHeap(), 0, menu->items );
    19451946    }
     
    20052006    WORD resinfo;
    20062007    do {
    2007         MENUITEMINFOW mii;
    2008 
    2009         mii.cbSize = sizeof(mii);
    2010         mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
    2011         mii.fType = GET_DWORD(res);
     2008    MENUITEMINFOW mii;
     2009
     2010    mii.cbSize = sizeof(mii);
     2011    mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
     2012    mii.fType = GET_DWORD(res);
    20122013        res += sizeof(DWORD);
    2013         mii.fState = GET_DWORD(res);
     2014    mii.fState = GET_DWORD(res);
    20142015        res += sizeof(DWORD);
    2015         mii.wID = GET_DWORD(res);
     2016    mii.wID = GET_DWORD(res);
    20162017        res += sizeof(DWORD);
    2017         resinfo = GET_WORD(res); /* FIXME: for 16-bit apps this is a byte.  */
     2018    resinfo = GET_WORD(res); /* FIXME: for 16-bit apps this is a byte.  */
    20182019        res += sizeof(WORD);
    2019         /* Align the text on a word boundary.  */
    2020         res += (~((int)res - 1)) & 1;
    2021         mii.dwTypeData = (LPWSTR) res;
    2022         res += (1 + strlenW(mii.dwTypeData)) * sizeof(WCHAR);
    2023         /* Align the following fields on a dword boundary.  */
    2024         res += (~((int)res - 1)) & 3;
     2020    /* Align the text on a word boundary.  */
     2021    res += (~((int)res - 1)) & 1;
     2022    mii.dwTypeData = (LPWSTR) res;
     2023    res += (1 + strlenW(mii.dwTypeData)) * sizeof(WCHAR);
     2024    /* Align the following fields on a dword boundary.  */
     2025    res += (~((int)res - 1)) & 3;
    20252026
    20262027        TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
    20272028              mii.fType, mii.fState, mii.wID, resinfo, debugstr_w(mii.dwTypeData));
    20282029
    2029         if (resinfo & 1) {      /* Pop-up? */
    2030             /* DWORD helpid = GET_DWORD(res); FIXME: use this.  */
    2031             res += sizeof(DWORD);
    2032             mii.hSubMenu = CreatePopupMenu();
    2033             if (!mii.hSubMenu)
    2034                 return NULL;
    2035             if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
    2036                 DestroyMenu(mii.hSubMenu);
     2030    if (resinfo & 1) {  /* Pop-up? */
     2031        /* DWORD helpid = GET_DWORD(res); FIXME: use this.  */
     2032        res += sizeof(DWORD);
     2033        mii.hSubMenu = CreatePopupMenu();
     2034        if (!mii.hSubMenu)
     2035        return NULL;
     2036        if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
     2037        DestroyMenu(mii.hSubMenu);
    20372038                return NULL;
    20382039            }
    2039             mii.fMask |= MIIM_SUBMENU;
    2040             mii.fType |= MF_POPUP;
    2041         }
    2042         else if(!*mii.dwTypeData && !(mii.fType & MF_SEPARATOR))
    2043         {
    2044             WARN("Converting NULL menu item %04x, type %04x to SEPARATOR\n",
    2045                 mii.wID, mii.fType);
    2046             mii.fType |= MF_SEPARATOR;
    2047         }
    2048         InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
     2040        mii.fMask |= MIIM_SUBMENU;
     2041        mii.fType |= MF_POPUP;
     2042        }
     2043    else if(!*mii.dwTypeData && !(mii.fType & MF_SEPARATOR))
     2044    {
     2045        WARN("Converting NULL menu item %04x, type %04x to SEPARATOR\n",
     2046        mii.wID, mii.fType);
     2047        mii.fType |= MF_SEPARATOR;
     2048    }
     2049    InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
    20492050    } while (!(resinfo & MF_END));
    20502051    return res;
     
    20872088    if (menu && top_popup)
    20882089    {
    2089         HMENU hsubmenu;
    2090         POPUPMENU *submenu;
    2091         MENUITEM *item;
    2092 
    2093         if (menu->FocusedItem != NO_SELECTED_ITEM)
    2094         {
    2095             item = &menu->items[menu->FocusedItem];
    2096             if (!(item->fType & MF_POPUP) ||
    2097                 !(item->fState & MF_MOUSESELECT)) return;
    2098             item->fState &= ~MF_MOUSESELECT;
    2099             hsubmenu = item->hSubMenu;
    2100         } else return;
    2101 
    2102         submenu = MENU_GetMenu( hsubmenu );
    2103         MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
    2104         MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect, 0 );
     2090    HMENU hsubmenu;
     2091    POPUPMENU *submenu;
     2092    MENUITEM *item;
     2093
     2094    if (menu->FocusedItem != NO_SELECTED_ITEM)
     2095    {
     2096        item = &menu->items[menu->FocusedItem];
     2097        if (!(item->fType & MF_POPUP) ||
     2098        !(item->fState & MF_MOUSESELECT)) return;
     2099        item->fState &= ~MF_MOUSESELECT;
     2100        hsubmenu = item->hSubMenu;
     2101    } else return;
     2102
     2103    submenu = MENU_GetMenu( hsubmenu );
     2104    MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
     2105    MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect, 0 );
    21052106        DestroyWindow( submenu->hWnd );
    21062107        submenu->hWnd = 0;
     
    21392140    if (!(wFlags & TPM_NONOTIFY))
    21402141       SendMessageA( hwndOwner, WM_INITMENUPOPUP, item->hSubMenu,
    2141                    MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
     2142           MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
    21422143
    21432144    item = &menu->items[menu->FocusedItem];
     
    21542155        item->fState |= MF_HILITE;
    21552156        MENU_DrawMenuItem( menu->hWnd, hmenu, hwndOwner, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE );
    2156         ReleaseDC( menu->hWnd, hdc );
     2157    ReleaseDC( menu->hWnd, hdc );
    21572158    }
    21582159    if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right)
     
    21632164    if (IS_SYSTEM_MENU(menu))
    21642165    {
    2165         MENU_InitSysMenuPopup(item->hSubMenu,
     2166    MENU_InitSysMenuPopup(item->hSubMenu,
    21662167                              GetWindowLongA( menu->hWnd, GWL_STYLE ),
    21672168                              GetClassLongA( menu->hWnd, GCL_STYLE));
    21682169
    2169         NC_GetSysPopupPos( menu->hWnd, &rect );
    2170         rect.top = rect.bottom;
    2171         rect.right = GetSystemMetrics(SM_CXSIZE);
     2170    NC_GetSysPopupPos( menu->hWnd, &rect );
     2171    rect.top = rect.bottom;
     2172    rect.right = GetSystemMetrics(SM_CXSIZE);
    21722173        rect.bottom = GetSystemMetrics(SM_CYSIZE);
    21732174    }
     
    21752176    {
    21762177        GetWindowRect( menu->hWnd, &rect );
    2177         if (menu->wFlags & MF_POPUP)
    2178         {
    2179             rect.left += item->rect.right - GetSystemMetrics(SM_CXBORDER);
    2180             rect.top += item->rect.top;
    2181             rect.right = item->rect.left - item->rect.right + GetSystemMetrics(SM_CXBORDER);
    2182             rect.bottom = item->rect.top - item->rect.bottom;
    2183         }
    2184         else
    2185         {
    2186             rect.left += item->rect.left;
    2187             rect.top += item->rect.bottom;
    2188             rect.right = item->rect.right - item->rect.left;
    2189             rect.bottom = item->rect.bottom - item->rect.top;
    2190         }
     2178    if (menu->wFlags & MF_POPUP)
     2179    {
     2180        rect.left += item->rect.right - GetSystemMetrics(SM_CXBORDER);
     2181        rect.top += item->rect.top;
     2182        rect.right = item->rect.left - item->rect.right + GetSystemMetrics(SM_CXBORDER);
     2183        rect.bottom = item->rect.top - item->rect.bottom;
     2184    }
     2185    else
     2186    {
     2187        rect.left += item->rect.left;
     2188        rect.top += item->rect.bottom;
     2189        rect.right = item->rect.right - item->rect.left;
     2190        rect.bottom = item->rect.bottom - item->rect.top;
     2191    }
    21912192    }
    21922193
    21932194    MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
    2194                     rect.left, rect.top, rect.right, rect.bottom );
     2195            rect.left, rect.top, rect.right, rect.bottom );
    21952196    if (selectFirst)
    21962197        MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
     
    22582259
    22592260    if (!menu || !menu->nItems ||
    2260         (menu->FocusedItem == NO_SELECTED_ITEM)) return -1;
     2261    (menu->FocusedItem == NO_SELECTED_ITEM)) return -1;
    22612262
    22622263    item = &menu->items[menu->FocusedItem];
     
    22672268    if (!(item->fType & MF_POPUP))
    22682269    {
    2269         if (!(item->fState & (MF_GRAYED | MF_DISABLED)) && !(item->fType & MF_SEPARATOR))
    2270         {
    2271             /* If TPM_RETURNCMD is set you return the id, but
    2272                do not send a message to the owner */
    2273             if(!(wFlags & TPM_RETURNCMD))
    2274             {
    2275                 if( menu->wFlags & MF_SYSMENU )
    2276                     PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
    2277                                   MAKELPARAM((INT16)pmt->pt.x, (INT16)pmt->pt.y) );
    2278                 else
    2279                     PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
    2280             }
    2281             return item->wID;
    2282         }
     2270    if (!(item->fState & (MF_GRAYED | MF_DISABLED)) && !(item->fType & MF_SEPARATOR))
     2271    {
     2272        /* If TPM_RETURNCMD is set you return the id, but
     2273           do not send a message to the owner */
     2274        if(!(wFlags & TPM_RETURNCMD))
     2275        {
     2276        if( menu->wFlags & MF_SYSMENU )
     2277            PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
     2278                  MAKELPARAM((INT16)pmt->pt.x, (INT16)pmt->pt.y) );
     2279        else
     2280            PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
     2281        }
     2282        return item->wID;
     2283    }
    22832284    }
    22842285    else
    2285         pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hMenu, TRUE, wFlags);
     2286    pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hMenu, TRUE, wFlags);
    22862287
    22872288    return -1;
     
    23012302
    23022303    if( pmt->hTopMenu != hPtMenu &&
    2303         !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
    2304     {
    2305         /* both are top level menus (system and menu-bar) */
    2306         MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
    2307         MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
     2304    !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
     2305    {
     2306    /* both are top level menus (system and menu-bar) */
     2307    MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
     2308    MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
    23082309        pmt->hTopMenu = hPtMenu;
    23092310    }
     
    23242325    if (hPtMenu)
    23252326    {
    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 )
    2336         {
    2337             if( ptmenu->FocusedItem != id )
    2338                 MENU_SwitchTracking( pmt, hPtMenu, id );
    2339 
    2340             /* If the popup menu is not already "popped" */
    2341             if(!(item->fState & MF_MOUSESELECT ))
    2342             {
    2343                 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE, wFlags );
    2344 
    2345                 /* In win31, a newly popped menu always remains opened for the next buttonup */
     2327    UINT id = 0;
     2328    POPUPMENU *ptmenu = MENU_GetMenu( hPtMenu );
     2329    MENUITEM *item;
     2330
     2331    if( IS_SYSTEM_MENU(ptmenu) )
     2332        item = ptmenu->items;
     2333    else
     2334        item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
     2335
     2336    if( item )
     2337    {
     2338        if( ptmenu->FocusedItem != id )
     2339        MENU_SwitchTracking( pmt, hPtMenu, id );
     2340
     2341        /* If the popup menu is not already "popped" */
     2342        if(!(item->fState & MF_MOUSESELECT ))
     2343        {
     2344        pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE, wFlags );
     2345
     2346        /* In win31, a newly popped menu always remains opened for the next buttonup */
    23462347#ifdef __WIN32OS2__
    2347                 if(fOS2Look)
    2348                     ptmenu->bTimeToHide = FALSE;                   
     2348        if(fOS2Look)
     2349            ptmenu->bTimeToHide = FALSE;
    23492350#endif
    2350                 if(TWEAK_WineLook == WIN31_LOOK)
    2351                     ptmenu->bTimeToHide = FALSE;
    2352             }
    2353 
    2354             return TRUE;
    2355         }
    2356         /* Else the click was on the menu bar, finish the tracking */
     2351        if(TWEAK_WineLook == WIN31_LOOK)
     2352            ptmenu->bTimeToHide = FALSE;
     2353        }
     2354
     2355        return TRUE;
     2356    }
     2357    /* Else the click was on the menu bar, finish the tracking */
    23572358    }
    23582359    return FALSE;
     
    23732374    if (hPtMenu)
    23742375    {
    2375         UINT id = 0;
    2376         POPUPMENU *ptmenu = MENU_GetMenu( hPtMenu );
    2377         MENUITEM *item;
     2376    UINT id = 0;
     2377    POPUPMENU *ptmenu = MENU_GetMenu( hPtMenu );
     2378    MENUITEM *item;
    23782379
    23792380        if( IS_SYSTEM_MENU(ptmenu) )
     
    23822383            item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
    23832384
    2384         if( item && (ptmenu->FocusedItem == id ))
    2385         {
    2386             if( !(item->fType & MF_POPUP) )
    2387                 return MENU_ExecFocusedItem( pmt, hPtMenu, wFlags);
    2388 
    2389             /* If we are dealing with the top-level menu            */
    2390             /* and this is a click on an already "popped" item:     */
    2391             /* Stop the menu tracking and close the opened submenus */
    2392             if((pmt->hTopMenu == hPtMenu) && (ptmenu->bTimeToHide == TRUE))
    2393                 return 0;
    2394         }
    2395         ptmenu->bTimeToHide = TRUE;
     2385    if( item && (ptmenu->FocusedItem == id ))
     2386    {
     2387        if( !(item->fType & MF_POPUP) )
     2388        return MENU_ExecFocusedItem( pmt, hPtMenu, wFlags);
     2389
     2390        /* If we are dealing with the top-level menu            */
     2391        /* and this is a click on an already "popped" item:     */
     2392        /* Stop the menu tracking and close the opened submenus */
     2393        if((pmt->hTopMenu == hPtMenu) && (ptmenu->bTimeToHide == TRUE))
     2394        return 0;
     2395    }
     2396    ptmenu->bTimeToHide = TRUE;
    23962397    }
    23972398    return -1;
     
    24112412    if( hPtMenu )
    24122413    {
    2413         ptmenu = MENU_GetMenu( hPtMenu );
     2414    ptmenu = MENU_GetMenu( hPtMenu );
    24142415        if( IS_SYSTEM_MENU(ptmenu) )
    2415             id = 0;
     2416        id = 0;
    24162417        else
    24172418            MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
     
    24202421    if( id == NO_SELECTED_ITEM )
    24212422    {
    2422         MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
    2423                         NO_SELECTED_ITEM, TRUE, pmt->hTopMenu);
     2423    MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
     2424            NO_SELECTED_ITEM, TRUE, pmt->hTopMenu);
    24242425
    24252426    }
    24262427    else if( ptmenu->FocusedItem != id )
    24272428    {
    2428             MENU_SwitchTracking( pmt, hPtMenu, id );
    2429             pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hPtMenu, FALSE, wFlags);
     2429        MENU_SwitchTracking( pmt, hPtMenu, id );
     2430        pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hPtMenu, FALSE, wFlags);
    24302431    }
    24312432    return TRUE;
     
    24462447    {
    24472448        MDINEXTMENU next_menu;
    2448         HMENU hNewMenu;
    2449         HWND  hNewWnd;
    2450         UINT  id = 0;
     2449    HMENU hNewMenu;
     2450    HWND  hNewWnd;
     2451    UINT  id = 0;
    24512452
    24522453        next_menu.hmenuIn = (IS_SYSTEM_MENU(menu)) ? GetSubMenu(pmt->hTopMenu,0) : pmt->hTopMenu;
     
    24552456        SendMessageW( pmt->hOwnerWnd, WM_NEXTMENU, vk, (LPARAM)&next_menu );
    24562457
    2457         TRACE("%04x [%04x] -> %04x [%04x]\n",
     2458    TRACE("%04x [%04x] -> %04x [%04x]\n",
    24582459              pmt->hCurrentMenu, pmt->hOwnerWnd, next_menu.hmenuNext, next_menu.hwndNext );
    24592460
    2460         if (!next_menu.hmenuNext || !next_menu.hwndNext)
    2461         {
     2461    if (!next_menu.hmenuNext || !next_menu.hwndNext)
     2462    {
    24622463            DWORD style = GetWindowLongA( pmt->hOwnerWnd, GWL_STYLE );
    2463             hNewWnd = pmt->hOwnerWnd;
    2464             if( IS_SYSTEM_MENU(menu) )
    2465             {
    2466                 /* switch to the menu bar */
     2464        hNewWnd = pmt->hOwnerWnd;
     2465        if( IS_SYSTEM_MENU(menu) )
     2466        {
     2467        /* switch to the menu bar */
    24672468
    24682469                if(style & WS_CHILD || !(hNewMenu = GetMenu(hNewWnd))) return FALSE;
    24692470
    2470                 if( vk == VK_LEFT )
    2471                 {
    2472                     menu = MENU_GetMenu( hNewMenu );
    2473                     id = menu->nItems - 1;
    2474                 }
    2475             }
    2476             else if (style & WS_SYSMENU )
    2477             {
    2478                 /* switch to the system menu */
    2479                 hNewMenu = get_win_sys_menu( hNewWnd );
    2480             }
     2471            if( vk == VK_LEFT )
     2472            {
     2473            menu = MENU_GetMenu( hNewMenu );
     2474            id = menu->nItems - 1;
     2475            }
     2476        }
     2477        else if (style & WS_SYSMENU )
     2478        {
     2479        /* switch to the system menu */
     2480            hNewMenu = get_win_sys_menu( hNewWnd );
     2481        }
    24812482            else return FALSE;
    2482         }
    2483         else    /* application returned a new menu to switch to */
    2484         {
     2483    }
     2484    else    /* application returned a new menu to switch to */
     2485    {
    24852486            hNewMenu = next_menu.hmenuNext;
    24862487            hNewWnd = WIN_GetFullHandle( next_menu.hwndNext );
    24872488
    2488             if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
    2489             {
     2489        if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
     2490        {
    24902491                DWORD style = GetWindowLongA( hNewWnd, GWL_STYLE );
    24912492
    2492                 if (style & WS_SYSMENU &&
    2493                     GetSubMenu(get_win_sys_menu(hNewWnd), 0) == hNewMenu )
    2494                 {
    2495                     /* get the real system menu */
    2496                     hNewMenu =  get_win_sys_menu(hNewWnd);
    2497                 }
    2498                 else if (style & WS_CHILD || GetMenu(hNewWnd) != hNewMenu )
    2499                 {
    2500                     /* FIXME: Not sure what to do here;
    2501                      * perhaps try to track hNewMenu as a popup? */
    2502 
    2503                     TRACE(" -- got confused.\n");
    2504                     return FALSE;
    2505                 }
    2506             }
    2507             else return FALSE;
    2508         }
    2509 
    2510         if( hNewMenu != pmt->hTopMenu )
    2511         {
    2512             MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM,
     2493        if (style & WS_SYSMENU &&
     2494            GetSubMenu(get_win_sys_menu(hNewWnd), 0) == hNewMenu )
     2495        {
     2496                /* get the real system menu */
     2497            hNewMenu =  get_win_sys_menu(hNewWnd);
     2498        }
     2499            else if (style & WS_CHILD || GetMenu(hNewWnd) != hNewMenu )
     2500        {
     2501            /* FIXME: Not sure what to do here;
     2502             * perhaps try to track hNewMenu as a popup? */
     2503
     2504            TRACE(" -- got confused.\n");
     2505            return FALSE;
     2506        }
     2507        }
     2508        else return FALSE;
     2509    }
     2510
     2511    if( hNewMenu != pmt->hTopMenu )
     2512    {
     2513        MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM,
    25132514                    FALSE, 0 );
    2514             if( pmt->hCurrentMenu != pmt->hTopMenu )
    2515                 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
    2516         }
    2517 
    2518         if( hNewWnd != pmt->hOwnerWnd )
    2519         {
    2520             ReleaseCapture();
    2521             pmt->hOwnerWnd = hNewWnd;
     2515        if( pmt->hCurrentMenu != pmt->hTopMenu )
     2516        MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
     2517    }
     2518
     2519    if( hNewWnd != pmt->hOwnerWnd )
     2520    {
     2521        ReleaseCapture();
     2522        pmt->hOwnerWnd = hNewWnd;
    25222523#ifdef __WIN32OS2__
    25232524            SetCapture(pmt->hOwnerWnd); //SvL: Don't know if this is good enough
    25242525#else
    2525             EVENT_Capture( pmt->hOwnerWnd, HTMENU );
     2526        EVENT_Capture( pmt->hOwnerWnd, HTMENU );
    25262527#endif
    2527         }
    2528 
    2529         pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
    2530         MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE, 0 );
    2531 
    2532         return TRUE;
     2528    }
     2529
     2530    pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
     2531    MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE, 0 );
     2532
     2533    return TRUE;
    25332534    }
    25342535    return FALSE;
     
    25522553    switch( uMsg )
    25532554    {
    2554         case WM_KEYDOWN:
    2555              PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
    2556              if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
    2557              {
    2558                 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
    2559                  PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
    2560                  if( msg.message == WM_KEYDOWN &&
    2561                     (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
    2562                  {
    2563                      pmt->trackFlags |= TF_SUSPENDPOPUP;
    2564                      return TRUE;
    2565                  }
    2566              }
    2567              break;
     2555    case WM_KEYDOWN:
     2556         PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
     2557         if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
     2558         {
     2559        PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
     2560             PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
     2561             if( msg.message == WM_KEYDOWN &&
     2562            (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
     2563             {
     2564             pmt->trackFlags |= TF_SUSPENDPOPUP;
     2565             return TRUE;
     2566             }
     2567         }
     2568         break;
    25682569    }
    25692570
     
    26242625    /* Try to move 1 column left (if possible) */
    26252626    if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
    2626         NO_SELECTED_ITEM ) {
    2627 
    2628         MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
    2629                         prevcol, TRUE, 0 );
    2630         return;
     2627    NO_SELECTED_ITEM ) {
     2628
     2629    MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
     2630            prevcol, TRUE, 0 );
     2631    return;
    26312632    }
    26322633
     
    26342635    while (hmenutmp != pmt->hCurrentMenu)
    26352636    {
    2636         hmenuprev = hmenutmp;
    2637         hmenutmp = MENU_GetSubPopup( hmenuprev );
     2637    hmenuprev = hmenutmp;
     2638    hmenutmp = MENU_GetSubPopup( hmenuprev );
    26382639    }
    26392640
     
    26432644    if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) )
    26442645    {
    2645         /* move menu bar selection if no more popups are left */
    2646 
    2647         if( !MENU_DoNextMenu( pmt, VK_LEFT) )
    2648              MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
    2649 
    2650         if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
    2651         {
    2652            /* A sublevel menu was displayed - display the next one
    2653             * unless there is another displacement coming up */
    2654 
    2655             if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
    2656                 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
    2657                                                 pmt->hTopMenu, TRUE, wFlags);
    2658         }
     2646    /* move menu bar selection if no more popups are left */
     2647
     2648    if( !MENU_DoNextMenu( pmt, VK_LEFT) )
     2649         MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
     2650
     2651    if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
     2652    {
     2653       /* A sublevel menu was displayed - display the next one
     2654        * unless there is another displacement coming up */
     2655
     2656        if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
     2657        pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
     2658                        pmt->hTopMenu, TRUE, wFlags);
     2659    }
    26592660    }
    26602661}
     
    26732674
    26742675    TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
    2675                   pmt->hCurrentMenu,
    2676                   debugstr_w((MENU_GetMenu(pmt->hCurrentMenu))->
    2677                      items[0].text),
    2678                   pmt->hTopMenu, debugstr_w(menu->items[0].text) );
     2676          pmt->hCurrentMenu,
     2677          debugstr_w((MENU_GetMenu(pmt->hCurrentMenu))->
     2678             items[0].text),
     2679          pmt->hTopMenu, debugstr_w(menu->items[0].text) );
    26792680
    26802681    if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu))
    26812682    {
    2682         /* If already displaying a popup, try to display sub-popup */
    2683 
    2684         hmenutmp = pmt->hCurrentMenu;
    2685         pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hmenutmp, TRUE, wFlags);
    2686 
    2687         /* if subpopup was displayed then we are done */
    2688         if (hmenutmp != pmt->hCurrentMenu) return;
     2683    /* If already displaying a popup, try to display sub-popup */
     2684
     2685    hmenutmp = pmt->hCurrentMenu;
     2686    pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hmenutmp, TRUE, wFlags);
     2687
     2688    /* if subpopup was displayed then we are done */
     2689    if (hmenutmp != pmt->hCurrentMenu) return;
    26892690    }
    26902691
    26912692    /* Check to see if there's another column */
    26922693    if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
    2693         NO_SELECTED_ITEM ) {
    2694         TRACE("Going to %d.\n", nextcol );
    2695         MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
    2696                         nextcol, TRUE, 0 );
    2697         return;
    2698     }
    2699 
    2700     if (!(menu->wFlags & MF_POPUP))     /* menu bar tracking */
    2701     {
    2702         if( pmt->hCurrentMenu != pmt->hTopMenu )
    2703         {
    2704             MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
    2705             hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
    2706         } else hmenutmp = 0;
    2707 
    2708         /* try to move to the next item */
    2709         if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
    2710              MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
    2711 
    2712         if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
    2713             if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
    2714                 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
    2715                                                        pmt->hTopMenu, TRUE, wFlags);
     2694    NO_SELECTED_ITEM ) {
     2695    TRACE("Going to %d.\n", nextcol );
     2696    MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
     2697            nextcol, TRUE, 0 );
     2698    return;
     2699    }
     2700
     2701    if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */
     2702    {
     2703    if( pmt->hCurrentMenu != pmt->hTopMenu )
     2704    {
     2705        MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
     2706        hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
     2707    } else hmenutmp = 0;
     2708
     2709    /* try to move to the next item */
     2710    if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
     2711         MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
     2712
     2713    if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
     2714        if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
     2715        pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
     2716                               pmt->hTopMenu, TRUE, wFlags);
    27162717    }
    27172718}
     
    27432744
    27442745    TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
    2745             hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
    2746             (lprect) ? lprect->right : 0,  (lprect) ? lprect->bottom : 0);
     2746        hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
     2747        (lprect) ? lprect->right : 0,  (lprect) ? lprect->bottom : 0);
    27472748
    27482749    fEndMenu = FALSE;
     
    27512752    if (wFlags & TPM_BUTTONDOWN)
    27522753    {
    2753         /* Get the result in order to start the tracking or not */
    2754         fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
    2755         fEndMenu = !fRemove;
     2754    /* Get the result in order to start the tracking or not */
     2755    fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
     2756    fEndMenu = !fRemove;
    27562757    }
    27572758
     
    27692770    while (!fEndMenu)
    27702771    {
    2771         menu = MENU_GetMenu( mt.hCurrentMenu );
    2772         if (!menu) /* sometimes happens if I do a window manager close */
    2773             break;
    2774 
    2775         /* we have to keep the message in the queue until it's
    2776         * clear that menu loop is not over yet. */
     2772    menu = MENU_GetMenu( mt.hCurrentMenu );
     2773    if (!menu) /* sometimes happens if I do a window manager close */
     2774        break;
     2775
     2776    /* we have to keep the message in the queue until it's
     2777    * clear that menu loop is not over yet. */
    27772778
    27782779        for (;;)
     
    28032804        }
    28042805
    2805         /* check if EndMenu() tried to cancel us, by posting this message */
     2806    /* check if EndMenu() tried to cancel us, by posting this message */
    28062807        if(msg.message == WM_CANCELMODE)
    2807         {
    2808             /* we are now out of the loop */
    2809             fEndMenu = TRUE;
     2808    {
     2809        /* we are now out of the loop */
     2810            fEndMenu = TRUE;
    28102811
    28112812#ifdef __WIN32OS2__
    2812             /* remove the message from the queue */
    2813             PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
     2813        /* remove the message from the queue */
     2814        PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
    28142815#endif
    2815             /* break out of internal loop, ala ESCAPE */
    2816             break;
    2817         }
     2816        /* break out of internal loop, ala ESCAPE */
     2817        break;
     2818    }
    28182819
    28192820        TranslateMessage( &msg );
    28202821        mt.pt = msg.pt;
    28212822
    2822         if ( (msg.hwnd==menu->hWnd) || (msg.message!=WM_TIMER) )
    2823           enterIdleSent=FALSE;
     2823    if ( (msg.hwnd==menu->hWnd) || (msg.message!=WM_TIMER) )
     2824      enterIdleSent=FALSE;
    28242825
    28252826        fRemove = FALSE;
    2826         if ((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
    2827         {
     2827    if ((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
     2828    {
    28282829            /*
    28292830             * use the mouse coordinates in lParam instead of those in the MSG
     
    28392840            ClientToScreen(msg.hwnd,&mt.pt);
    28402841
    2841             /* Find a menu for this mouse event */
    2842             hmenu = MENU_PtMenu( mt.hTopMenu, mt.pt );
    2843 
    2844             switch(msg.message)
    2845             {
    2846                 /* no WM_NC... messages in captured state */
    2847 
    2848                 case WM_RBUTTONDBLCLK:
    2849                 case WM_RBUTTONDOWN:
     2842        /* Find a menu for this mouse event */
     2843        hmenu = MENU_PtMenu( mt.hTopMenu, mt.pt );
     2844
     2845        switch(msg.message)
     2846        {
     2847        /* no WM_NC... messages in captured state */
     2848
     2849        case WM_RBUTTONDBLCLK:
     2850        case WM_RBUTTONDOWN:
    28502851#ifdef __WIN32OS2__
    2851                     if (!(wFlags & TPM_RIGHTBUTTON)) {
     2852            if (!(wFlags & TPM_RIGHTBUTTON)) {
    28522853                      MENUITEM *item;
    2853                       UINT id = 0;
    2854                        
     2854              UINT id = 0;
     2855
    28552856                       if( IS_SYSTEM_MENU(menu) )
    28562857                          item = menu->items;
    28572858                       else
    28582859                          item = MENU_FindItemByCoords( menu, mt.pt, &id );
    2859                        //@@PF If our pointer is over the menu - do nothing
    2860                        if (item) break; 
    2861                        //@@PF Time to close menu - win2k&98 checked
     2860               //@@PF If our pointer is over the menu - do nothing
     2861                       if (item) break;
     2862               //@@PF Time to close menu - win2k&98 checked
    28622863                       fEndMenu = 1;
    28632864                       break;
     
    28652866                    goto buttondown;
    28662867#else
    2867                     if (!(wFlags & TPM_RIGHTBUTTON)) break;
     2868            if (!(wFlags & TPM_RIGHTBUTTON)) break;
    28682869#endif
    2869                     /* fall through */
    2870                 case WM_LBUTTONDBLCLK:
     2870            /* fall through */
     2871        case WM_LBUTTONDBLCLK:
    28712872#ifdef __WIN32OS2__
    28722873                    if (bSysMenu && (hmenu == mt.hTopMenu))
     
    28892890
    28902891#endif
    2891                 case WM_LBUTTONDOWN:
    2892                     /* If the message belongs to the menu, removes it from the queue */
    2893                     /* Else, end menu tracking */
    2894                     fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
    2895                     fEndMenu = !fRemove;
    2896                     break;
    2897 
    2898                 case WM_RBUTTONUP:
    2899                     if (!(wFlags & TPM_RIGHTBUTTON)) break;
    2900                     /* fall through */
    2901                 case WM_LBUTTONUP:
    2902                     /* Check if a menu was selected by the mouse */
    2903                     if (hmenu)
    2904                     {
     2892        case WM_LBUTTONDOWN:
     2893            /* If the message belongs to the menu, removes it from the queue */
     2894            /* Else, end menu tracking */
     2895            fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
     2896            fEndMenu = !fRemove;
     2897            break;
     2898
     2899        case WM_RBUTTONUP:
     2900            if (!(wFlags & TPM_RIGHTBUTTON)) break;
     2901            /* fall through */
     2902        case WM_LBUTTONUP:
     2903            /* Check if a menu was selected by the mouse */
     2904            if (hmenu)
     2905            {
    29052906                        executedMenuId = MENU_ButtonUp( &mt, hmenu, wFlags);
    29062907
    2907                         /* End the loop if executedMenuId is an item ID */
    2908                         /* or if the job was done (executedMenuId = 0). */
     2908            /* End the loop if executedMenuId is an item ID */
     2909            /* or if the job was done (executedMenuId = 0). */
    29092910                        fEndMenu = fRemove = (executedMenuId != -1);
    2910                     }
     2911            }
    29112912                    /* No menu was selected by the mouse */
    29122913                    /* if the function was called by TrackPopupMenu, continue
     
    29152916                        fEndMenu = ((wFlags & TPM_POPUPMENU) ? FALSE : TRUE);
    29162917
    2917                     break;
    2918 
    2919                 case WM_MOUSEMOVE:
     2918            break;
     2919
     2920        case WM_MOUSEMOVE:
    29202921                    /* In win95 winelook, the selected menu item must be changed every time the
    29212922                       mouse moves. In Win31 winelook, the mouse button has to be held down */
     
    29242925                    //PF Win32 eats first mousemove to prevent auto-select of item
    29252926                    //on TrackMenuPopup pressed button - verified in Win2k
    2926                     if (bFirstMouseMove) 
    2927                     { 
    2928                         bFirstMouseMove = FALSE; 
     2927                    if (bFirstMouseMove)
     2928                    {
     2929                        bFirstMouseMove = FALSE;
    29292930                        break;
    29302931                    }
     
    29372938                           ((wFlags & TPM_RIGHTBUTTON) && (msg.wParam & MK_RBUTTON))) )
    29382939
    2939                         fEndMenu |= !MENU_MouseMove( &mt, hmenu, wFlags );
    2940 
    2941             } /* switch(msg.message) - mouse */
    2942         }
    2943         else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
    2944         {
     2940            fEndMenu |= !MENU_MouseMove( &mt, hmenu, wFlags );
     2941
     2942        } /* switch(msg.message) - mouse */
     2943    }
     2944    else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
     2945    {
    29452946            fRemove = TRUE;  /* Keyboard messages are always removed */
    2946             switch(msg.message)
    2947             {
    2948             case WM_KEYDOWN:
    2949                 switch(msg.wParam)
    2950                 {
    2951                 case VK_HOME:
    2952                 case VK_END:
    2953                     MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
    2954                                      NO_SELECTED_ITEM, FALSE, 0 );
    2955                 /* fall through */
    2956                 case VK_UP:
    2957                     MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
    2958                                        (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
    2959                     break;
    2960 
    2961                 case VK_DOWN: /* If on menu bar, pull-down the menu */
    2962 
    2963                     menu = MENU_GetMenu( mt.hCurrentMenu );
    2964                     if (!(menu->wFlags & MF_POPUP))
    2965                         mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags);
    2966                     else      /* otherwise try to move selection */
    2967                         MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
    2968                     break;
    2969 
    2970                 case VK_LEFT:
    2971                     MENU_KeyLeft( &mt, wFlags );
    2972                     break;
    2973 
    2974                 case VK_RIGHT:
    2975                     MENU_KeyRight( &mt, wFlags );
    2976                     break;
    2977 
    2978                 case VK_ESCAPE:
     2947        switch(msg.message)
     2948        {
     2949        case WM_KEYDOWN:
     2950        switch(msg.wParam)
     2951        {
     2952        case VK_HOME:
     2953        case VK_END:
     2954            MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
     2955                     NO_SELECTED_ITEM, FALSE, 0 );
     2956        /* fall through */
     2957        case VK_UP:
     2958            MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
     2959                       (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
     2960            break;
     2961
     2962        case VK_DOWN: /* If on menu bar, pull-down the menu */
     2963
     2964            menu = MENU_GetMenu( mt.hCurrentMenu );
     2965            if (!(menu->wFlags & MF_POPUP))
     2966            mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags);
     2967            else      /* otherwise try to move selection */
     2968            MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
     2969            break;
     2970
     2971        case VK_LEFT:
     2972            MENU_KeyLeft( &mt, wFlags );
     2973            break;
     2974
     2975        case VK_RIGHT:
     2976            MENU_KeyRight( &mt, wFlags );
     2977            break;
     2978
     2979        case VK_ESCAPE:
    29792980                    fEndMenu = MENU_KeyEscape(&mt, wFlags);
    2980                     break;
    2981 
    2982                 case VK_F1:
    2983                     {
    2984                         HELPINFO hi;
    2985                         hi.cbSize = sizeof(HELPINFO);
    2986                         hi.iContextType = HELPINFO_MENUITEM;
    2987                         if (menu->FocusedItem == NO_SELECTED_ITEM)
    2988                             hi.iCtrlId = 0;
    2989                         else
    2990                             hi.iCtrlId = menu->items[menu->FocusedItem].wID;
    2991                         hi.hItemHandle = hmenu;
    2992                         hi.dwContextId = menu->dwContextHelpID;
    2993                         hi.MousePos = msg.pt;
    2994                         SendMessageA(hwnd, WM_HELP, 0, (LPARAM)&hi);
    2995                         break;
    2996                     }
    2997 
    2998                 default:
    2999                     break;
    3000                 }
    3001                 break;  /* WM_KEYDOWN */
    3002 
    3003             case WM_SYSKEYDOWN:
    3004                 switch(msg.wParam)
    3005                 {
    3006                 case VK_MENU:
    3007                     fEndMenu = TRUE;
    3008                     break;
    3009 
    3010                 }
    3011                 break;  /* WM_SYSKEYDOWN */
    3012 
    3013             case WM_CHAR:
    3014                 {
    3015                     UINT        pos;
    3016 
    3017                     if (msg.wParam == '\r' || msg.wParam == ' ')
    3018                     {
     2981            break;
     2982
     2983        case VK_F1:
     2984            {
     2985            HELPINFO hi;
     2986            hi.cbSize = sizeof(HELPINFO);
     2987            hi.iContextType = HELPINFO_MENUITEM;
     2988            if (menu->FocusedItem == NO_SELECTED_ITEM)
     2989                hi.iCtrlId = 0;
     2990                else
     2991                hi.iCtrlId = menu->items[menu->FocusedItem].wID;
     2992            hi.hItemHandle = hmenu;
     2993            hi.dwContextId = menu->dwContextHelpID;
     2994            hi.MousePos = msg.pt;
     2995            SendMessageA(hwnd, WM_HELP, 0, (LPARAM)&hi);
     2996            break;
     2997            }
     2998
     2999        default:
     3000            break;
     3001        }
     3002        break;  /* WM_KEYDOWN */
     3003
     3004        case WM_SYSKEYDOWN:
     3005        switch(msg.wParam)
     3006        {
     3007        case VK_MENU:
     3008            fEndMenu = TRUE;
     3009            break;
     3010
     3011        }
     3012        break;  /* WM_SYSKEYDOWN */
     3013
     3014        case WM_CHAR:
     3015        {
     3016            UINT    pos;
     3017
     3018            if (msg.wParam == '\r' || msg.wParam == ' ')
     3019            {
    30193020                        executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
    30203021                        fEndMenu = (executedMenuId != -1);
    30213022
    3022                         break;
    3023                     }
    3024 
    3025                       /* Hack to avoid control chars. */
    3026                       /* We will find a better way real soon... */
    3027                     if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
    3028 
    3029                     pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
     3023            break;
     3024            }
     3025
     3026              /* Hack to avoid control chars. */
     3027              /* We will find a better way real soon... */
     3028            if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
     3029
     3030            pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
    30303031                                              LOWORD(msg.wParam), FALSE );
    3031                     if (pos == (UINT)-2) fEndMenu = TRUE;
    3032                     else if (pos == (UINT)-1) MessageBeep(0);
    3033                     else
    3034                     {
    3035                         MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos,
     3032            if (pos == (UINT)-2) fEndMenu = TRUE;
     3033            else if (pos == (UINT)-1) MessageBeep(0);
     3034            else
     3035            {
     3036            MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos,
    30363037                                TRUE, 0 );
    30373038                        executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
    30383039                        fEndMenu = (executedMenuId != -1);
    3039                     }
    3040                 }
    3041                 break;
    3042             }  /* switch(msg.message) - kbd */
    3043         }
    3044         else
    3045         {
    3046             DispatchMessageA( &msg );
    3047         }
    3048 
    3049         if (!fEndMenu) fRemove = TRUE;
    3050 
    3051         /* finally remove message from the queue */
     3040            }
     3041        }
     3042        break;
     3043        }  /* switch(msg.message) - kbd */
     3044    }
     3045    else
     3046    {
     3047        DispatchMessageA( &msg );
     3048    }
     3049
     3050    if (!fEndMenu) fRemove = TRUE;
     3051
     3052    /* finally remove message from the queue */
    30523053
    30533054        if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) )
    3054 #ifdef __WIN32OS2__ 
     3055#ifdef __WIN32OS2__
    30553056            ;
    30563057#else
    3057             PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
     3058        PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
    30583059#endif
    3059         else mt.trackFlags &= ~TF_SKIPREMOVE;
     3060    else mt.trackFlags &= ~TF_SKIPREMOVE;
    30603061    }
    30613062
     
    30713072    if( IsMenu( mt.hTopMenu ) )
    30723073    {
    3073         menu = MENU_GetMenu( mt.hTopMenu );
     3074    menu = MENU_GetMenu( mt.hTopMenu );
    30743075
    30753076        if( IsWindow( mt.hOwnerWnd ) )
    30763077        {
    3077             MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
    3078 
    3079             if (menu && menu->wFlags & MF_POPUP)
    3080             {
     3078        MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
     3079
     3080        if (menu && menu->wFlags & MF_POPUP)
     3081        {
    30813082                DestroyWindow( menu->hWnd );
    30823083                menu->hWnd = 0;
    3083             }
    3084             MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
    3085             SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 );
     3084        }
     3085        MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
     3086        SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 );
    30863087        }
    30873088
     
    31533154        if (parent != GetDesktopWindow()) ScreenToClient( parent, &pt );
    31543155
    3155         MENU_InitTracking( hWnd, hMenu, FALSE, wFlags );
    3156         MENU_TrackMenu( hMenu, wFlags, pt.x, pt.y, hWnd, NULL );
    3157         MENU_ExitTracking(hWnd);
     3156    MENU_InitTracking( hWnd, hMenu, FALSE, wFlags );
     3157    MENU_TrackMenu( hMenu, wFlags, pt.x, pt.y, hWnd, NULL );
     3158    MENU_ExitTracking(hWnd);
    31583159    }
    31593160}
     
    32413242
    32423243    if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
    3243         ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpRect );
     3244    ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpRect );
    32443245    MENU_ExitTracking(hWnd);
    32453246
    32463247    if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
    3247         ret = 1;
     3248    ret = 1;
    32483249
    32493250    return ret;
     
    32743275    {
    32753276    case WM_CREATE:
    3276         {
    3277             CREATESTRUCTW *cs = (CREATESTRUCTW*)lParam;
    3278             SetWindowLongW( hwnd, 0, (LONG)cs->lpCreateParams );
     3277    {
     3278        CREATESTRUCTW *cs = (CREATESTRUCTW*)lParam;
     3279        SetWindowLongW( hwnd, 0, (LONG)cs->lpCreateParams );
    32793280            return 0;
    3280         }
     3281    }
    32813282
    32823283    case WM_MOUSEACTIVATE:  /* We don't want to be activated */
     
    32843285
    32853286    case WM_PAINT:
    3286         {
    3287             PAINTSTRUCT ps;
    3288             BeginPaint( hwnd, &ps );
    3289             MENU_DrawPopupMenu( hwnd, ps.hdc,
     3287    {
     3288        PAINTSTRUCT ps;
     3289        BeginPaint( hwnd, &ps );
     3290        MENU_DrawPopupMenu( hwnd, ps.hdc,
    32903291                                (HMENU)GetWindowLongA( hwnd, 0 ) );
    3291             EndPaint( hwnd, &ps );
     3292        EndPaint( hwnd, &ps );
    32923293            return 0;
    3293         }
     3294    }
    32943295    case WM_ERASEBKGND:
    32953296        return 1;
     
    33023303    case WM_SHOWWINDOW:
    33033304
    3304         if( wParam )
    3305         {
     3305    if( wParam )
     3306    {
    33063307            if (!GetWindowLongW( hwnd, 0 )) ERR("no menu to display\n");
    3307         }
    3308         else
     3308    }
     3309    else
    33093310            SetWindowLongW( hwnd, 0, 0 );
    3310         break;
     3311    break;
    33113312
    33123313    case MM_SETMENUHANDLE:
     
    34193420
    34203421    TRACE("(%04x, %04X, %04X) !\n",
    3421                 hMenu, wItemID, wFlags);
     3422        hMenu, wItemID, wFlags);
    34223423
    34233424    /* Get the Popupmenu to access the owner menu */
    34243425    if (!(menu = MENU_GetMenu(hMenu)))
    3425         return (UINT)-1;
     3426    return (UINT)-1;
    34263427
    34273428    if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags )))
    3428         return (UINT)-1;
     3429    return (UINT)-1;
    34293430
    34303431    oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
     
    34333434    /* In win95 if the close item in the system menu change update the close button */
    34343435    if (TWEAK_WineLook == WIN95_LOOK)
    3435         if((item->wID == SC_CLOSE) && (oldflags != wFlags))
    3436         {
    3437             if (menu->hSysMenuOwner != 0)
    3438             {
    3439                 POPUPMENU* parentMenu;
    3440 
    3441                 /* Get the parent menu to access*/
    3442                 if (!(parentMenu = MENU_GetMenu(menu->hSysMenuOwner)))
    3443                     return (UINT)-1;
    3444 
    3445                 /* Refresh the frame to reflect the change*/
    3446                 SetWindowPos(parentMenu->hWnd, 0, 0, 0, 0, 0,
    3447                              SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
    3448             }
    3449         }
     3436    if((item->wID == SC_CLOSE) && (oldflags != wFlags))
     3437    {
     3438        if (menu->hSysMenuOwner != 0)
     3439        {
     3440        POPUPMENU* parentMenu;
     3441
     3442        /* Get the parent menu to access*/
     3443        if (!(parentMenu = MENU_GetMenu(menu->hSysMenuOwner)))
     3444            return (UINT)-1;
     3445
     3446        /* Refresh the frame to reflect the change*/
     3447        SetWindowPos(parentMenu->hWnd, 0, 0, 0, 0, 0,
     3448                 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
     3449        }
     3450    }
    34503451
    34513452    return oldflags;
     
    34573458 */
    34583459INT WINAPI GetMenuStringA(
    3459         HMENU hMenu,    /* [in] menuhandle */
    3460         UINT wItemID,   /* [in] menu item (dep. on wFlags) */
    3461         LPSTR str,      /* [out] outbuffer. If NULL, func returns entry length*/
    3462         INT nMaxSiz,    /* [in] length of buffer. if 0, func returns entry len*/
    3463         UINT wFlags     /* [in] MF_ flags */
     3460    HMENU hMenu,    /* [in] menuhandle */
     3461    UINT wItemID,   /* [in] menu item (dep. on wFlags) */
     3462    LPSTR str,  /* [out] outbuffer. If NULL, func returns entry length*/
     3463    INT nMaxSiz,    /* [in] length of buffer. if 0, func returns entry len*/
     3464    UINT wFlags /* [in] MF_ flags */
    34643465) {
    34653466    MENUITEM *item;
     
    34723473    str[0] = '\0';
    34733474    if (!WideCharToMultiByte( CP_ACP, 0, item->text, -1, str, nMaxSiz, NULL, NULL ))
     3475#ifdef __WIN32OS2__
     3476        lstrtrunc( str, nMaxSiz );
     3477#else
    34743478        str[nMaxSiz-1] = 0;
     3479#endif
    34753480    TRACE("returning '%s'\n", str );
    34763481    return strlen(str);
     
    35223527    MENUITEM *item;
    35233528    TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
    3524                 hMenu, wItemID, wFlags);
     3529        hMenu, wItemID, wFlags);
    35253530    if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
    35263531    debug_print_menuitem ("  item: ", item, "");
    35273532    if (item->fType & MF_POPUP)
    35283533    {
    3529         POPUPMENU *menu = MENU_GetMenu( item->hSubMenu );
    3530         if (!menu) return -1;
    3531         else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
     3534    POPUPMENU *menu = MENU_GetMenu( item->hSubMenu );
     3535    if (!menu) return -1;
     3536    else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
    35323537    }
    35333538    else
    35343539    {
    3535         /* We used to (from way back then) mask the result to 0xff.  */
    3536         /* I don't know why and it seems wrong as the documented */
    3537         /* return flag MF_SEPARATOR is outside that mask.  */
    3538         return (item->fType | item->fState);
     3540    /* We used to (from way back then) mask the result to 0xff.  */
     3541    /* I don't know why and it seems wrong as the documented */
     3542    /* return flag MF_SEPARATOR is outside that mask.  */
     3543    return (item->fType | item->fState);
    35393544    }
    35403545}
     
    35463551INT WINAPI GetMenuItemCount( HMENU hMenu )
    35473552{
    3548     LPPOPUPMENU menu = MENU_GetMenu(hMenu);
     3553    LPPOPUPMENU menu = MENU_GetMenu(hMenu);
    35493554    if (!menu) return -1;
    35503555    TRACE("(%04x) returning %d\n",
     
    35853590    if (IS_STRING_ITEM(flags) && str)
    35863591        TRACE("hMenu %04x, pos %d, flags %08x, "
    3587                       "id %04x, str %s\n",
     3592              "id %04x, str %s\n",
    35883593                      hMenu, pos, flags, id, debugstr_w(str) );
    35893594    else TRACE("hMenu %04x, pos %d, flags %08x, "
    3590                        "id %04x, str %08lx (not a string)\n",
     3595               "id %04x, str %08lx (not a string)\n",
    35913596                       hMenu, pos, flags, id, (DWORD)str );
    35923597
     
    36003605
    36013606    if (flags & MF_POPUP)  /* Set the MF_POPUP flag on the popup-menu */
    3602         (MENU_GetMenu((HMENU16)id))->wFlags |= MF_POPUP;
     3607    (MENU_GetMenu((HMENU16)id))->wFlags |= MF_POPUP;
    36033608
    36043609    item->hCheckBit = item->hUnCheckBit = 0;
     
    36563661BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags )
    36573662{
    3658     LPPOPUPMENU menu;
     3663    LPPOPUPMENU menu;
    36593664    MENUITEM *item;
    36603665
     
    36743679    else
    36753680    {
    3676         while(nPos < menu->nItems)
    3677         {
    3678             *item = *(item+1);
    3679             item++;
    3680             nPos++;
    3681         }
     3681    while(nPos < menu->nItems)
     3682    {
     3683        *item = *(item+1);
     3684        item++;
     3685        nPos++;
     3686    }
    36823687        menu->items = HeapReAlloc( GetProcessHeap(), 0, menu->items,
    36833688                                   menu->nItems * sizeof(MENUITEM) );
     
    37113716    if (IS_STRING_ITEM(flags))
    37123717    {
    3713         TRACE("%04x %d %04x %04x %s\n",
     3718    TRACE("%04x %d %04x %04x %s\n",
    37143719                      hMenu, pos, flags, id, debugstr_w(str) );
    37153720        if (!str) return FALSE;
     
    37173722    else
    37183723    {
    3719         TRACE("%04x %d %04x %04x %08lx\n",
     3724    TRACE("%04x %d %04x %04x %08lx\n",
    37203725                      hMenu, pos, flags, id, (DWORD)str );
    37213726    }
     
    37893794    if (!hNewCheck && !hNewUnCheck)
    37903795    {
    3791         item->fState &= ~MF_USECHECKBITMAPS;
     3796    item->fState &= ~MF_USECHECKBITMAPS;
    37923797    }
    37933798    else  /* Install new bitmaps */
    37943799    {
    3795         item->hCheckBit = hNewCheck;
    3796         item->hUnCheckBit = hNewUnCheck;
    3797         item->fState |= MF_USECHECKBITMAPS;
     3800    item->hCheckBit = hNewCheck;
     3801    item->hUnCheckBit = hNewUnCheck;
     3802    item->fState |= MF_USECHECKBITMAPS;
    37983803    }
    37993804    return TRUE;
     
    38803885    HMENU retvalue = 0;
    38813886
    3882     if(IsWindow(hWnd)) 
     3887    if(IsWindow(hWnd))
    38833888    {
    38843889        HMENU hSysMenu = getSysMenu(hWnd);
     
    39343939    if (wndPtr)
    39353940    {
    3936         if( wndPtr->hSysMenu )
    3937         {
    3938             if( bRevert )
    3939             {
    3940                 DestroyMenu(wndPtr->hSysMenu);
    3941                 wndPtr->hSysMenu = 0;
    3942             }
    3943             else
    3944             {
    3945                 POPUPMENU *menu = MENU_GetMenu( wndPtr->hSysMenu );
    3946                 if( menu )
     3941    if( wndPtr->hSysMenu )
     3942    {
     3943        if( bRevert )
     3944        {
     3945        DestroyMenu(wndPtr->hSysMenu);
     3946        wndPtr->hSysMenu = 0;
     3947        }
     3948        else
     3949        {
     3950        POPUPMENU *menu = MENU_GetMenu( wndPtr->hSysMenu );
     3951        if( menu )
    39473952                {
    3948                    if( menu->nItems > 0 && menu->items[0].hSubMenu == MENU_DefSysPopup )
    3949                       menu->items[0].hSubMenu = MENU_CopySysPopup();
    3950                 }
    3951                 else
    3952                 {
    3953                    WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
    3954                         wndPtr->hSysMenu, hWnd);
    3955                    wndPtr->hSysMenu = 0;
    3956                 }
    3957             }
    3958         }
    3959 
    3960         if(!wndPtr->hSysMenu && (wndPtr->dwStyle & WS_SYSMENU) )
    3961             wndPtr->hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
    3962 
    3963         if( wndPtr->hSysMenu )
    3964         {
    3965             POPUPMENU *menu;
    3966             retvalue = GetSubMenu(wndPtr->hSysMenu, 0);
    3967 
    3968             /* Store the dummy sysmenu handle to facilitate the refresh */
    3969             /* of the close button if the SC_CLOSE item change */
    3970             menu = MENU_GetMenu(retvalue);
    3971             if ( menu )
    3972                menu->hSysMenuOwner = wndPtr->hSysMenu;
     3953           if( menu->nItems > 0 && menu->items[0].hSubMenu == MENU_DefSysPopup )
     3954              menu->items[0].hSubMenu = MENU_CopySysPopup();
     3955        }
     3956        else
     3957        {
     3958           WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
     3959            wndPtr->hSysMenu, hWnd);
     3960           wndPtr->hSysMenu = 0;
     3961        }
     3962        }
     3963    }
     3964
     3965    if(!wndPtr->hSysMenu && (wndPtr->dwStyle & WS_SYSMENU) )
     3966        wndPtr->hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
     3967
     3968    if( wndPtr->hSysMenu )
     3969        {
     3970        POPUPMENU *menu;
     3971        retvalue = GetSubMenu(wndPtr->hSysMenu, 0);
     3972
     3973        /* Store the dummy sysmenu handle to facilitate the refresh */
     3974        /* of the close button if the SC_CLOSE item change */
     3975        menu = MENU_GetMenu(retvalue);
     3976        if ( menu )
     3977           menu->hSysMenuOwner = wndPtr->hSysMenu;
    39733978        }
    39743979        WIN_ReleaseWndPtr(wndPtr);
     
    39994004    if (wndPtr)
    40004005    {
    4001         if (wndPtr->hSysMenu) DestroyMenu( wndPtr->hSysMenu );
    4002         wndPtr->hSysMenu = MENU_GetSysMenu( hwnd, hMenu );
     4006    if (wndPtr->hSysMenu) DestroyMenu( wndPtr->hSysMenu );
     4007    wndPtr->hSysMenu = MENU_GetSysMenu( hwnd, hMenu );
    40034008        WIN_ReleaseWndPtr(wndPtr);
    4004         return TRUE;
     4009    return TRUE;
    40054010    }
    40064011    return FALSE;
     
    41264131    if (!fEndMenu && top_popup)
    41274132    {
    4128         /* terminate the menu handling code */
     4133    /* terminate the menu handling code */
    41294134        fEndMenu = TRUE;
    41304135
    4131         /* needs to be posted to wakeup the internal menu handler */
    4132         /* which will now terminate the menu, in the event that */
    4133         /* the main window was minimized, or lost focus, so we */
    4134         /* don't end up with an orphaned menu */
     4136    /* needs to be posted to wakeup the internal menu handler */
     4137    /* which will now terminate the menu, in the event that */
     4138    /* the main window was minimized, or lost focus, so we */
     4139    /* don't end up with an orphaned menu */
    41354140        PostMessageA( top_popup, WM_CANCELMODE, 0, 0);
    41364141    }
     
    41524157#ifndef __WIN32OS2__
    41534158/**********************************************************************
    4154  *          LoadMenu    (USER.150)
     4159 *      LoadMenu    (USER.150)
    41554160 */
    41564161HMENU16 WINAPI LoadMenu16( HINSTANCE16 instance, LPCSTR name )
     
    42044209
    42054210/**********************************************************************
    4206  *          LoadMenuIndirect    (USER.220)
     4211 *      LoadMenuIndirect    (USER.220)
    42074212 */
    42084213HMENU16 WINAPI LoadMenuIndirect16( LPCVOID template )
     
    42334238
    42344239/**********************************************************************
    4235  *          LoadMenuIndirectA    (USER32.@)
     4240 *      LoadMenuIndirectA    (USER32.@)
    42364241 */
    42374242HMENU WINAPI LoadMenuIndirectA( LPCVOID template )
     
    42474252      {
    42484253      case 0:
    4249         offset = GET_WORD(p);
    4250         p += sizeof(WORD) + offset;
    4251         if (!(hMenu = CreateMenu())) return 0;
    4252         if (!MENU_ParseResource( p, hMenu, TRUE ))
    4253           {
    4254             DestroyMenu( hMenu );
    4255             return 0;
    4256           }
    4257         return hMenu;
     4254    offset = GET_WORD(p);
     4255    p += sizeof(WORD) + offset;
     4256    if (!(hMenu = CreateMenu())) return 0;
     4257    if (!MENU_ParseResource( p, hMenu, TRUE ))
     4258      {
     4259        DestroyMenu( hMenu );
     4260        return 0;
     4261      }
     4262    return hMenu;
    42584263      case 1:
    4259         offset = GET_WORD(p);
    4260         p += sizeof(WORD) + offset;
    4261         if (!(hMenu = CreateMenu())) return 0;
    4262         if (!MENUEX_ParseResource( p, hMenu))
    4263           {
    4264             DestroyMenu( hMenu );
    4265             return 0;
    4266           }
    4267         return hMenu;
     4264    offset = GET_WORD(p);
     4265    p += sizeof(WORD) + offset;
     4266    if (!(hMenu = CreateMenu())) return 0;
     4267    if (!MENUEX_ParseResource( p, hMenu))
     4268      {
     4269        DestroyMenu( hMenu );
     4270        return 0;
     4271      }
     4272    return hMenu;
    42684273      default:
    42694274        ERR("version %d not supported.\n", version);
     
    42744279
    42754280/**********************************************************************
    4276  *          LoadMenuIndirectW    (USER32.@)
     4281 *      LoadMenuIndirectW    (USER32.@)
    42774282 */
    42784283HMENU WINAPI LoadMenuIndirectW( LPCVOID template )
     
    42844289
    42854290/**********************************************************************
    4286  *              IsMenu    (USER32.@)
     4291 *      IsMenu    (USER32.@)
    42874292 */
    42884293BOOL WINAPI IsMenu(HMENU hmenu)
     
    42934298
    42944299/**********************************************************************
    4295  *              GetMenuItemInfo_common
     4300 *      GetMenuItemInfo_common
    42964301 */
    42974302
    42984303static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
    4299                                         LPMENUITEMINFOW lpmii, BOOL unicode)
     4304                    LPMENUITEMINFOW lpmii, BOOL unicode)
    43004305{
    43014306    MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0);
     
    43044309
    43054310    if (!menu)
    4306         return FALSE;
     4311    return FALSE;
    43074312
    43084313    if (lpmii->fMask & MIIM_TYPE) {
    4309         lpmii->fType = menu->fType;
    4310         switch (MENU_ITEM_TYPE(menu->fType)) {
    4311         case MF_STRING:
     4314    lpmii->fType = menu->fType;
     4315    switch (MENU_ITEM_TYPE(menu->fType)) {
     4316    case MF_STRING:
    43124317            break;  /* will be done below */
    4313         case MF_OWNERDRAW:
    4314         case MF_BITMAP:
    4315             lpmii->dwTypeData = menu->text;
    4316             /* fall through */
    4317         default:
    4318             lpmii->cch = 0;
    4319         }
     4318    case MF_OWNERDRAW:
     4319    case MF_BITMAP:
     4320        lpmii->dwTypeData = menu->text;
     4321        /* fall through */
     4322    default:
     4323        lpmii->cch = 0;
     4324    }
    43204325    }
    43214326
     
    43374342                if (!WideCharToMultiByte( CP_ACP, 0, menu->text, -1,
    43384343                                          (LPSTR)lpmii->dwTypeData, lpmii->cch, NULL, NULL ))
     4344#ifdef __WIN32OS2__
     4345                    lstrtrunc((LPSTR)lpmii->dwTypeData, lpmii->cch );
     4346#else
    43394347                    ((LPSTR)lpmii->dwTypeData)[lpmii->cch-1] = 0;
     4348#endif
    43404349        }
    43414350        /* if we've copied a substring we return its length */
     
    43494358
    43504359    if (lpmii->fMask & MIIM_FTYPE)
    4351         lpmii->fType = menu->fType;
     4360    lpmii->fType = menu->fType;
    43524361
    43534362    if (lpmii->fMask & MIIM_BITMAP)
    4354         lpmii->hbmpItem = menu->hbmpItem;
     4363    lpmii->hbmpItem = menu->hbmpItem;
    43554364
    43564365    if (lpmii->fMask & MIIM_STATE)
    4357         lpmii->fState = menu->fState;
     4366    lpmii->fState = menu->fState;
    43584367
    43594368    if (lpmii->fMask & MIIM_ID)
    4360         lpmii->wID = menu->wID;
     4369    lpmii->wID = menu->wID;
    43614370
    43624371    if (lpmii->fMask & MIIM_SUBMENU)
    4363         lpmii->hSubMenu = menu->hSubMenu;
     4372    lpmii->hSubMenu = menu->hSubMenu;
    43644373
    43654374    if (lpmii->fMask & MIIM_CHECKMARKS) {
    4366         lpmii->hbmpChecked = menu->hCheckBit;
    4367         lpmii->hbmpUnchecked = menu->hUnCheckBit;
     4375    lpmii->hbmpChecked = menu->hCheckBit;
     4376    lpmii->hbmpUnchecked = menu->hUnCheckBit;
    43684377    }
    43694378    if (lpmii->fMask & MIIM_DATA)
    4370         lpmii->dwItemData = menu->dwItemData;
     4379    lpmii->dwItemData = menu->dwItemData;
    43714380
    43724381  return TRUE;
     
    43744383
    43754384/**********************************************************************
    4376  *              GetMenuItemInfoA    (USER32.@)
     4385 *      GetMenuItemInfoA    (USER32.@)
    43774386 */
    43784387BOOL WINAPI GetMenuItemInfoA( HMENU hmenu, UINT item, BOOL bypos,
     
    43844393
    43854394/**********************************************************************
    4386  *              GetMenuItemInfoW    (USER32.@)
     4395 *      GetMenuItemInfoW    (USER32.@)
    43874396 */
    43884397BOOL WINAPI GetMenuItemInfoW( HMENU hmenu, UINT item, BOOL bypos,
     
    44184427
    44194428/**********************************************************************
    4420  *              SetMenuItemInfo_common
     4429 *      SetMenuItemInfo_common
    44214430 */
    44224431
    44234432static BOOL SetMenuItemInfo_common(MENUITEM * menu,
    4424                                        const MENUITEMINFOW *lpmii,
    4425                                        BOOL unicode)
     4433                       const MENUITEMINFOW *lpmii,
     4434                       BOOL unicode)
    44264435{
    44274436    if (!menu) return FALSE;
     
    44304439
    44314440    if (lpmii->fMask & MIIM_TYPE ) {
    4432         /* Get rid of old string.  */
    4433         if ( IS_STRING_ITEM(menu->fType) && menu->text) {
    4434             HeapFree(GetProcessHeap(), 0, menu->text);
    4435             menu->text = NULL;
    4436         }
    4437 
    4438         /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
    4439         menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
    4440         menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
    4441 
    4442         menu->text = lpmii->dwTypeData;
     4441    /* Get rid of old string.  */
     4442    if ( IS_STRING_ITEM(menu->fType) && menu->text) {
     4443        HeapFree(GetProcessHeap(), 0, menu->text);
     4444        menu->text = NULL;
     4445    }
     4446
     4447    /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
     4448    menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
     4449    menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
     4450
     4451    menu->text = lpmii->dwTypeData;
    44434452
    44444453       if (IS_STRING_ITEM(menu->fType))
     
    44474456
    44484457    if (lpmii->fMask & MIIM_FTYPE ) {
    4449         /* free the string when the type is changing */
    4450         if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
    4451             HeapFree(GetProcessHeap(), 0, menu->text);
    4452             menu->text = NULL;
    4453         }
    4454         menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
    4455         menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
     4458    /* free the string when the type is changing */
     4459    if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
     4460        HeapFree(GetProcessHeap(), 0, menu->text);
     4461        menu->text = NULL;
     4462    }
     4463    menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
     4464    menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
    44564465        if ( IS_STRING_ITEM(menu->fType) && !menu->text )
    44574466            menu->fType |= MF_SEPARATOR;
     
    44594468
    44604469    if (lpmii->fMask & MIIM_STRING ) {
    4461         /* free the string when used */
    4462         if ( IS_STRING_ITEM(menu->fType) && menu->text) {
    4463             HeapFree(GetProcessHeap(), 0, menu->text);
     4470    /* free the string when used */
     4471    if ( IS_STRING_ITEM(menu->fType) && menu->text) {
     4472        HeapFree(GetProcessHeap(), 0, menu->text);
    44644473            set_menu_item_text( menu, lpmii->dwTypeData, unicode );
    4465         }
     4474    }
    44664475    }
    44674476
    44684477    if (lpmii->fMask & MIIM_STATE)
    44694478    {
    4470         /* FIXME: MFS_DEFAULT do we have to reset the other menu items? */
    4471         menu->fState = lpmii->fState;
     4479    /* FIXME: MFS_DEFAULT do we have to reset the other menu items? */
     4480    menu->fState = lpmii->fState;
    44724481    }
    44734482
    44744483    if (lpmii->fMask & MIIM_ID)
    4475         menu->wID = lpmii->wID;
     4484    menu->wID = lpmii->wID;
    44764485
    44774486    if (lpmii->fMask & MIIM_SUBMENU) {
    4478         menu->hSubMenu = lpmii->hSubMenu;
    4479         if (menu->hSubMenu) {
    4480             POPUPMENU *subMenu = MENU_GetMenu((UINT16)menu->hSubMenu);
    4481             if (subMenu) {
    4482                 subMenu->wFlags |= MF_POPUP;
    4483                 menu->fType |= MF_POPUP;
    4484             }
    4485             else
    4486                 /* FIXME: Return an error ? */
    4487                 menu->fType &= ~MF_POPUP;
    4488         }
    4489         else
    4490             menu->fType &= ~MF_POPUP;
     4487    menu->hSubMenu = lpmii->hSubMenu;
     4488    if (menu->hSubMenu) {
     4489        POPUPMENU *subMenu = MENU_GetMenu((UINT16)menu->hSubMenu);
     4490        if (subMenu) {
     4491        subMenu->wFlags |= MF_POPUP;
     4492        menu->fType |= MF_POPUP;
     4493        }
     4494        else
     4495        /* FIXME: Return an error ? */
     4496        menu->fType &= ~MF_POPUP;
     4497    }
     4498    else
     4499        menu->fType &= ~MF_POPUP;
    44914500    }
    44924501
     
    44964505            menu->fType |= MFT_RADIOCHECK;
    44974506
    4498         menu->hCheckBit = lpmii->hbmpChecked;
    4499         menu->hUnCheckBit = lpmii->hbmpUnchecked;
     4507    menu->hCheckBit = lpmii->hbmpChecked;
     4508    menu->hUnCheckBit = lpmii->hbmpUnchecked;
    45004509    }
    45014510    if (lpmii->fMask & MIIM_DATA)
    4502         menu->dwItemData = lpmii->dwItemData;
     4511    menu->dwItemData = lpmii->dwItemData;
    45034512
    45044513    debug_print_menuitem("SetMenuItemInfo_common to : ", menu, "");
     
    45074516
    45084517/**********************************************************************
    4509  *              SetMenuItemInfoA    (USER32.@)
     4518 *      SetMenuItemInfoA    (USER32.@)
    45104519 */
    45114520BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
     
    45134522{
    45144523    if ((lpmii->fType & (MF_HILITE|MF_POPUP)) || (lpmii->fState)) {
    4515         /* QuickTime does pass invalid data into SetMenuItemInfo.
    4516         * do some of the checks Windows does.
    4517         */
     4524    /* QuickTime does pass invalid data into SetMenuItemInfo.
     4525    * do some of the checks Windows does.
     4526    */
    45184527        WARN("Bad masks for type (0x%08x) or state (0x%08x)\n",
    45194528             lpmii->fType,lpmii->fState );
    4520         return FALSE;
     4529    return FALSE;
    45214530    }
    45224531
    45234532    return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
    4524                                     (const MENUITEMINFOW *)lpmii, FALSE);
     4533                    (const MENUITEMINFOW *)lpmii, FALSE);
    45254534}
    45264535
    45274536/**********************************************************************
    4528  *              SetMenuItemInfoW    (USER32.@)
     4537 *      SetMenuItemInfoW    (USER32.@)
    45294538 */
    45304539BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos,
     
    45324541{
    45334542    return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
    4534                                     lpmii, TRUE);
     4543                    lpmii, TRUE);
    45354544}
    45364545
    45374546/**********************************************************************
    4538  *              SetMenuDefaultItem    (USER32.@)
     4547 *      SetMenuDefaultItem    (USER32.@)
    45394548 *
    45404549 */
    45414550BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT uItem, UINT bypos)
    45424551{
    4543         UINT i;
    4544         POPUPMENU *menu;
    4545         MENUITEM *item;
    4546 
    4547         TRACE("(0x%x,%d,%d)\n", hmenu, uItem, bypos);
    4548 
    4549         if (!(menu = MENU_GetMenu(hmenu))) return FALSE;
    4550 
    4551         /* reset all default-item flags */
    4552         item = menu->items;
    4553         for (i = 0; i < menu->nItems; i++, item++)
    4554         {
    4555             item->fState &= ~MFS_DEFAULT;
    4556         }
    4557 
    4558         /* no default item */
    4559         if ( -1 == uItem)
    4560         {
    4561             return TRUE;
    4562         }
    4563 
    4564         item = menu->items;
    4565         if ( bypos )
    4566         {
    4567             if ( uItem >= menu->nItems ) return FALSE;
    4568             item[uItem].fState |= MFS_DEFAULT;
    4569             return TRUE;
    4570         }
    4571         else
    4572         {
    4573             for (i = 0; i < menu->nItems; i++, item++)
    4574             {
    4575                 if (item->wID == uItem)
    4576                 {
    4577                      item->fState |= MFS_DEFAULT;
    4578                      return TRUE;
    4579                 }
    4580             }
    4581 
    4582         }
    4583         return FALSE;
     4552    UINT i;
     4553    POPUPMENU *menu;
     4554    MENUITEM *item;
     4555
     4556    TRACE("(0x%x,%d,%d)\n", hmenu, uItem, bypos);
     4557
     4558    if (!(menu = MENU_GetMenu(hmenu))) return FALSE;
     4559
     4560    /* reset all default-item flags */
     4561    item = menu->items;
     4562    for (i = 0; i < menu->nItems; i++, item++)
     4563    {
     4564        item->fState &= ~MFS_DEFAULT;
     4565    }
     4566
     4567    /* no default item */
     4568    if ( -1 == uItem)
     4569    {
     4570        return TRUE;
     4571    }
     4572
     4573    item = menu->items;
     4574    if ( bypos )
     4575    {
     4576        if ( uItem >= menu->nItems ) return FALSE;
     4577        item[uItem].fState |= MFS_DEFAULT;
     4578        return TRUE;
     4579    }
     4580    else
     4581    {
     4582        for (i = 0; i < menu->nItems; i++, item++)
     4583        {
     4584        if (item->wID == uItem)
     4585        {
     4586             item->fState |= MFS_DEFAULT;
     4587             return TRUE;
     4588        }
     4589        }
     4590
     4591    }
     4592    return FALSE;
    45844593}
    45854594
    45864595/**********************************************************************
    4587  *              GetMenuDefaultItem    (USER32.@)
     4596 *      GetMenuDefaultItem    (USER32.@)
    45884597 */
    45894598UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags)
    45904599{
    4591         POPUPMENU *menu;
    4592         MENUITEM * item;
    4593         UINT i = 0;
    4594 
    4595         TRACE("(0x%x,%d,%d)\n", hmenu, bypos, flags);
    4596 
    4597         if (!(menu = MENU_GetMenu(hmenu))) return -1;
    4598 
    4599         /* find default item */
    4600         item = menu->items;
    4601 
    4602         /* empty menu */
    4603         if (! item) return -1;
    4604 
    4605         while ( !( item->fState & MFS_DEFAULT ) )
    4606         {
    4607             i++; item++;
    4608             if  (i >= menu->nItems ) return -1;
    4609         }
    4610 
    4611         /* default: don't return disabled items */
    4612         if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1;
    4613 
    4614         /* search rekursiv when needed */
    4615         if ( (item->fType & MF_POPUP) &&  (flags & GMDI_GOINTOPOPUPS) )
    4616         {
    4617             UINT ret;
    4618             ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags );
    4619             if ( -1 != ret ) return ret;
    4620 
    4621             /* when item not found in submenu, return the popup item */
    4622         }
    4623         return ( bypos ) ? i : item->wID;
     4600    POPUPMENU *menu;
     4601    MENUITEM * item;
     4602    UINT i = 0;
     4603
     4604    TRACE("(0x%x,%d,%d)\n", hmenu, bypos, flags);
     4605
     4606    if (!(menu = MENU_GetMenu(hmenu))) return -1;
     4607
     4608    /* find default item */
     4609    item = menu->items;
     4610
     4611    /* empty menu */
     4612    if (! item) return -1;
     4613
     4614    while ( !( item->fState & MFS_DEFAULT ) )
     4615    {
     4616        i++; item++;
     4617        if  (i >= menu->nItems ) return -1;
     4618    }
     4619
     4620    /* default: don't return disabled items */
     4621    if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1;
     4622
     4623    /* search rekursiv when needed */
     4624    if ( (item->fType & MF_POPUP) &&  (flags & GMDI_GOINTOPOPUPS) )
     4625    {
     4626        UINT ret;
     4627        ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags );
     4628        if ( -1 != ret ) return ret;
     4629
     4630        /* when item not found in submenu, return the popup item */
     4631    }
     4632    return ( bypos ) ? i : item->wID;
    46244633
    46254634}
     
    46274636
    46284637/**********************************************************************
    4629  *              InsertMenuItemA    (USER32.@)
     4638 *      InsertMenuItemA    (USER32.@)
    46304639 */
    46314640BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
     
    46384647
    46394648/**********************************************************************
    4640  *              InsertMenuItemW    (USER32.@)
     4649 *      InsertMenuItemW    (USER32.@)
    46414650 */
    46424651BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
     
    46484657
    46494658/**********************************************************************
    4650  *              CheckMenuRadioItem    (USER32.@)
     4659 *      CheckMenuRadioItem    (USER32.@)
    46514660 */
    46524661
    46534662BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
    4654                                    UINT first, UINT last, UINT check,
    4655                                    UINT bypos)
     4663                   UINT first, UINT last, UINT check,
     4664                   UINT bypos)
    46564665{
    46574666     MENUITEM *mifirst, *milast, *micheck;
     
    46594668
    46604669     TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
    4661                   hMenu, first, last, check, bypos);
     4670          hMenu, first, last, check, bypos);
    46624671
    46634672     mifirst = MENU_FindItem (&mfirst, &first, bypos);
     
    46664675
    46674676     if (mifirst == NULL || milast == NULL || micheck == NULL ||
    4668         mifirst > milast || mfirst != mlast || mfirst != mcheck ||
    4669         micheck > milast || micheck < mifirst)
    4670           return FALSE;
     4677    mifirst > milast || mfirst != mlast || mfirst != mcheck ||
     4678    micheck > milast || micheck < mifirst)
     4679      return FALSE;
    46714680
    46724681     while (mifirst <= milast)
    46734682     {
    4674           if (mifirst == micheck)
    4675           {
    4676                mifirst->fType |= MFT_RADIOCHECK;
    4677                mifirst->fState |= MFS_CHECKED;
    4678           } else {
    4679                mifirst->fType &= ~MFT_RADIOCHECK;
    4680                mifirst->fState &= ~MFS_CHECKED;
    4681           }
    4682           mifirst++;
     4683      if (mifirst == micheck)
     4684      {
     4685           mifirst->fType |= MFT_RADIOCHECK;
     4686           mifirst->fState |= MFS_CHECKED;
     4687      } else {
     4688           mifirst->fType &= ~MFT_RADIOCHECK;
     4689           mifirst->fState &= ~MFS_CHECKED;
     4690      }
     4691      mifirst++;
    46834692     }
    46844693
     
    46874696
    46884697/**********************************************************************
    4689  *              GetMenuItemRect    (USER32.@)
     4698 *      GetMenuItemRect    (USER32.@)
    46904699 *
    46914700 *      ATTENTION: Here, the returned values in rect are the screen
     
    46954704 */
    46964705BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
    4697                                 LPRECT rect)
     4706                LPRECT rect)
    46984707{
    46994708     POPUPMENU *itemMenu;
     
    47084717     if(!hwnd)
    47094718     {
    4710         itemMenu = MENU_GetMenu(hMenu);
    4711         if (itemMenu == NULL)
    4712              return FALSE;
    4713 
    4714         if(itemMenu->hWnd == 0)
    4715              return FALSE;
    4716         referenceHwnd = itemMenu->hWnd;
     4719    itemMenu = MENU_GetMenu(hMenu);
     4720    if (itemMenu == NULL)
     4721         return FALSE;
     4722
     4723    if(itemMenu->hWnd == 0)
     4724         return FALSE;
     4725    referenceHwnd = itemMenu->hWnd;
    47174726     }
    47184727
    47194728     if ((rect == NULL) || (item == NULL))
    4720         return FALSE;
     4729    return FALSE;
    47214730
    47224731     *rect = item->rect;
     
    47294738
    47304739/**********************************************************************
    4731  *              SetMenuInfo    (USER32.@)
     4740 *      SetMenuInfo    (USER32.@)
    47324741 *
    47334742 * FIXME
    4734  *      MIM_APPLYTOSUBMENUS
    4735  *      actually use the items to draw the menu
     4743 *  MIM_APPLYTOSUBMENUS
     4744 *  actually use the items to draw the menu
    47364745 */
    47374746BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
     
    47444753    {
    47454754
    4746         if (lpmi->fMask & MIM_BACKGROUND)
    4747             menu->hbrBack = lpmi->hbrBack;
    4748 
    4749         if (lpmi->fMask & MIM_HELPID)
    4750             menu->dwContextHelpID = lpmi->dwContextHelpID;
    4751 
    4752         if (lpmi->fMask & MIM_MAXHEIGHT)
    4753             menu->cyMax = lpmi->cyMax;
    4754 
    4755         if (lpmi->fMask & MIM_MENUDATA)
    4756             menu->dwMenuData = lpmi->dwMenuData;
    4757 
    4758         if (lpmi->fMask & MIM_STYLE)
    4759             menu->dwStyle = lpmi->dwStyle;
    4760 
    4761         return TRUE;
     4755    if (lpmi->fMask & MIM_BACKGROUND)
     4756        menu->hbrBack = lpmi->hbrBack;
     4757
     4758    if (lpmi->fMask & MIM_HELPID)
     4759        menu->dwContextHelpID = lpmi->dwContextHelpID;
     4760
     4761    if (lpmi->fMask & MIM_MAXHEIGHT)
     4762        menu->cyMax = lpmi->cyMax;
     4763
     4764    if (lpmi->fMask & MIM_MENUDATA)
     4765        menu->dwMenuData = lpmi->dwMenuData;
     4766
     4767    if (lpmi->fMask & MIM_STYLE)
     4768        menu->dwStyle = lpmi->dwStyle;
     4769
     4770    return TRUE;
    47624771    }
    47634772    return FALSE;
     
    47654774
    47664775/**********************************************************************
    4767  *              GetMenuInfo    (USER32.@)
     4776 *      GetMenuInfo    (USER32.@)
    47684777 *
    47694778 *  NOTES
    4770  *      win98/NT5.0
     4779 *  win98/NT5.0
    47714780 *
    47724781 */
     
    47794788    {
    47804789
    4781         if (lpmi->fMask & MIM_BACKGROUND)
    4782             lpmi->hbrBack = menu->hbrBack;
    4783 
    4784         if (lpmi->fMask & MIM_HELPID)
    4785             lpmi->dwContextHelpID = menu->dwContextHelpID;
    4786 
    4787         if (lpmi->fMask & MIM_MAXHEIGHT)
    4788             lpmi->cyMax = menu->cyMax;
    4789 
    4790         if (lpmi->fMask & MIM_MENUDATA)
    4791             lpmi->dwMenuData = menu->dwMenuData;
    4792 
    4793         if (lpmi->fMask & MIM_STYLE)
    4794             lpmi->dwStyle = menu->dwStyle;
    4795 
    4796         return TRUE;
     4790    if (lpmi->fMask & MIM_BACKGROUND)
     4791        lpmi->hbrBack = menu->hbrBack;
     4792
     4793    if (lpmi->fMask & MIM_HELPID)
     4794        lpmi->dwContextHelpID = menu->dwContextHelpID;
     4795
     4796    if (lpmi->fMask & MIM_MAXHEIGHT)
     4797        lpmi->cyMax = menu->cyMax;
     4798
     4799    if (lpmi->fMask & MIM_MENUDATA)
     4800        lpmi->dwMenuData = menu->dwMenuData;
     4801
     4802    if (lpmi->fMask & MIM_STYLE)
     4803        lpmi->dwStyle = menu->dwStyle;
     4804
     4805    return TRUE;
    47974806    }
    47984807    return FALSE;
     
    48104819    if ((menu = MENU_GetMenu(hMenu)))
    48114820    {
    4812         menu->dwContextHelpID = dwContextHelpID;
    4813         return TRUE;
     4821    menu->dwContextHelpID = dwContextHelpID;
     4822    return TRUE;
    48144823    }
    48154824    return FALSE;
     
    48274836    if ((menu = MENU_GetMenu(hMenu)))
    48284837    {
    4829         return menu->dwContextHelpID;
     4838    return menu->dwContextHelpID;
    48304839    }
    48314840    return 0;
     
    48474856}
    48484857
    4849 #ifdef __WIN32OS2__ 
     4858#ifdef __WIN32OS2__
    48504859//******************************************************************************
    48514860//******************************************************************************
     
    48534862{
    48544863    fDisableOdinSysMenuItems = TRUE;
     4864}
     4865/**********************************************************************
     4866 *           KBD_translate_accelerator
     4867 *
     4868 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP  -messages
     4869 */
     4870static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
     4871                                      BYTE fVirt,WORD key,WORD cmd)
     4872{
     4873    BOOL sendmsg = FALSE;
     4874
     4875    if(msg->wParam == key)
     4876    {
     4877        if (msg->message == WM_CHAR) {
     4878            if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
     4879            {
     4880                dprintf(("TranslateAccelerator: found accel for WM_CHAR: ('%c')\n", msg->wParam&0xff));
     4881                sendmsg=TRUE;
     4882            }
     4883        }
     4884        else
     4885        {
     4886            if(fVirt & FVIRTKEY) {
     4887                INT mask = 0;
     4888                if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
     4889                if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
     4890                if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
     4891
     4892                if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
     4893                        sendmsg=TRUE;
     4894                else    dprintf(("TranslateAccelerator: but incorrect SHIFT/CTRL/ALT-state %x != %x", mask, fVirt));
     4895            }
     4896            else
     4897            {
     4898                if (!(msg->lParam & 0x01000000))  /* no special_key */
     4899                {
     4900                    if ((fVirt & FALT) && (msg->lParam & 0x20000000))
     4901                    {                                                   /* ^^ ALT pressed */
     4902                        dprintf(("TranslateAccelerator: found accel for Alt-%c\n", msg->wParam&0xff));
     4903                        sendmsg=TRUE;
     4904                    }
     4905                }
     4906            }
     4907        }
     4908
     4909            dprintf(("TranslateAccelerator: not match for %x %x %x", fVirt, key, cmd));
     4910    }
     4911
     4912    else if( key >= 1 && key <= 26 && !( fVirt & FVIRTKEY )) // Ctrl-A to Ctrl-Z
     4913    {
     4914        int ctrlCh;
     4915
     4916        if( msg->message == WM_CHAR )
     4917            ctrlCh = toupper( msg->wParam ) - 'A' + 1;
     4918        else
     4919            ctrlCh = msg->wParam - VK_A + 1;
     4920
     4921        if( ctrlCh == key )
     4922        {
     4923            INT mask = 0;
     4924            if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
     4925            if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
     4926            if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
     4927
     4928            if(mask == FCONTROL)
     4929            {
     4930                sendmsg=TRUE;
     4931            }
     4932        }
     4933    }
     4934
     4935        if (sendmsg)      /* found an accelerator, but send a message... ? */
     4936        {
     4937            INT     iSysStat = -1,iStat = -1,mesg=0;
     4938            HMENU   hSysMenu, hMenu, hSubMenu;
     4939            UINT    nPos;
     4940
     4941            if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) {
     4942                mesg=1;
     4943            }
     4944            else
     4945                if (GetCapture())
     4946                    mesg=2;
     4947                else
     4948                if (!IsWindowEnabled(hWnd))
     4949                    mesg=3;
     4950                else
     4951                {
     4952                    hMenu = (GetWindowLongA(hWnd, GWL_STYLE) & WS_CHILD) ? NULL : GetMenu(hWnd);
     4953                    hSysMenu = getSysMenu(hWnd);
     4954
     4955                    hSubMenu = hSysMenu;
     4956                    nPos = cmd;
     4957                    if(MENU_FindItem(&hSubMenu, &nPos, MF_BYCOMMAND))
     4958                    {
     4959                        SendMessageA(hWnd, WM_INITMENU, (WPARAM)hSysMenu, 0L);
     4960                        if(hSubMenu != hSysMenu)
     4961                        {
     4962                            nPos = MENU_FindSubMenu(&hSysMenu, hSubMenu);
     4963                            dprintf(("hSysMenu = %04x, hSubMenu = %04x, nPos = %d\n", hSysMenu, hSubMenu, nPos));
     4964                            SendMessageA(hWnd, WM_INITMENUPOPUP, (WPARAM)hSubMenu, MAKELPARAM(nPos, TRUE));
     4965                        }
     4966                        iSysStat = GetMenuState(GetSubMenu(hSysMenu, 0), cmd, MF_BYCOMMAND);
     4967                    }
     4968                    else
     4969                    {
     4970                        hSubMenu = hMenu;
     4971                        nPos = cmd;
     4972                        if(MENU_FindItem(&hSubMenu, &nPos, MF_BYCOMMAND))
     4973                        {
     4974                            SendMessageA(hWnd, WM_INITMENU, (WPARAM)hMenu, 0L);
     4975                            if(hSubMenu != hMenu)
     4976                            {
     4977                                nPos = MENU_FindSubMenu(&hMenu, hSubMenu);
     4978                                dprintf(("hMenu = %04x, hSubMenu = %04x, nPos = %d\n", hMenu, hSubMenu, nPos));
     4979                                SendMessageA(hWnd, WM_INITMENUPOPUP, (WPARAM)hSubMenu, MAKELPARAM(nPos, FALSE));
     4980                            }
     4981                            iStat = GetMenuState(hMenu, cmd, MF_BYCOMMAND);
     4982                        }
     4983                    }
     4984
     4985                    if (iSysStat!=-1)
     4986                    {
     4987                        if (iSysStat & (MF_DISABLED|MF_GRAYED))
     4988                            mesg=4;
     4989                        else
     4990                            mesg=WM_SYSCOMMAND;
     4991                    }
     4992                    else
     4993                    {
     4994                        if (iStat!=-1)
     4995                        {
     4996                            if (IsIconic(hWnd)) {
     4997                                mesg=5;
     4998                            }
     4999                            else
     5000                            {
     5001                                if (iStat & (MF_DISABLED|MF_GRAYED))
     5002                                    mesg=6;
     5003                                else
     5004                                    mesg=WM_COMMAND;
     5005                            }
     5006                        }
     5007                        else
     5008                            mesg=WM_COMMAND;
     5009                    }
     5010                }
     5011                if ( mesg==WM_COMMAND )
     5012                    SendMessageA(hWnd, mesg, MAKEWPARAM( cmd, 1 ), NULL);
     5013                else if( mesg==WM_SYSCOMMAND )
     5014                    SendMessageA( hWnd, mesg, cmd, MAKELPARAM( 0, 1 ));
     5015                else
     5016                {
     5017                    /*  some reasons for NOT sending the WM_{SYS}COMMAND message:
     5018                     *   #0: unknown (please report!)
     5019                     *   #1: for WM_KEYUP,WM_SYSKEYUP
     5020                     *   #2: mouse is captured
     5021                     *   #3: window is disabled
     5022                     *   #4: it's a disabled system menu option
     5023                     *   #5: it's a menu option, but window is iconic
     5024                     *   #6: it's a menu option, but disabled
     5025                     */
     5026                    if(mesg==0)
     5027                            dprintf(("ERROR: unknown reason - please report!"));
     5028                    else    dprintf(("but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg));
     5029
     5030                }
     5031                return TRUE;
     5032            }
     5033
     5034    return FALSE;
     5035}
     5036/*****************************************************************************
     5037 * Name      : int WIN32API TranslateAcceleratorA
     5038 * Purpose   : Translate WM_*KEYDOWN messages to WM_COMMAND messages
     5039 *             according to Accelerator table
     5040 * Parameters: HWND hwnd, HACCEL haccel, LPMSG lpmsg
     5041 * Variables :
     5042 * Result    : int FALSE (no accelerator found) TRUE (accelerator found)
     5043 * Remark    : if a accelerator is found it is not neccesarely executed
     5044 *             depends on window stat
     5045 *
     5046 *****************************************************************************/
     5047INT WINAPI TranslateAcceleratorA(HWND hWnd, HACCEL hAccel, LPMSG msg)
     5048{
     5049    /* YES, Accel16! */
     5050    LPACCEL lpAccelTbl;
     5051    int i;
     5052
     5053    SetLastError(ERROR_SUCCESS);
     5054    if (msg == NULL)
     5055    {
     5056          dprintf(("TranslateAcceleratorAmsg null; should hang here to be win compatible"));
     5057          SetLastError(ERROR_INVALID_PARAMETER);
     5058          return 0;
     5059    }
     5060    if (!hAccel || !(lpAccelTbl = (LPACCEL)GlobalLock(hAccel)))
     5061    {
     5062          dprintf(("TranslateAcceleratorA: invalid accel handle=%x", hAccel));
     5063          SetLastError(ERROR_INVALID_PARAMETER);
     5064          return 0;
     5065    }
     5066    if(!IsWindow(hWnd)) {
     5067          dprintf(("TranslateAccelerator, window %x not found", hWnd));
     5068          SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     5069          return 0;
     5070    }
     5071    if ((msg->message != WM_KEYDOWN &&
     5072         msg->message != WM_KEYUP &&
     5073         msg->message != WM_SYSKEYDOWN &&
     5074         msg->message != WM_SYSKEYUP &&
     5075         msg->message != WM_CHAR))
     5076    {
     5077          return 0;
     5078    }
     5079
     5080/*    TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
     5081      "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
     5082      hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam); */
     5083
     5084    i = 0;
     5085    do
     5086    {
     5087        if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
     5088                                      lpAccelTbl[i].key,lpAccelTbl[i].cmd))
     5089        {
     5090            return 1;
     5091        }
     5092    }
     5093    while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
     5094
     5095//    WARN_(accel)("couldn't translate accelerator key\n");
     5096    return 0;
    48555097}
    48565098//******************************************************************************
     
    50465288}
    50475289#endif
     5290
     5291
  • trunk/src/user32/msgbox.c

    r10076 r10190  
    1 /* $Id: msgbox.c,v 1.7 2003-05-06 13:50:36 sandervl Exp $ */
     1/* $Id: msgbox.c,v 1.8 2003-07-31 15:56:43 sandervl Exp $ */
    22/*
    33 * Message boxes (based on Wine code)
     
    360360{
    361361    MSGBOXPARAMSA       msgboxa;
     362#ifdef __WIN32OS2__
     363    int ret;
     364#endif
    362365
    363366    memcpy(&msgboxa,msgbox,sizeof(msgboxa));
     367#ifdef __WIN32OS2__
     368    if (msgbox->lpszCaption)
     369        msgboxa.lpszCaption = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszCaption );
     370    if (msgbox->lpszText)
     371        msgboxa.lpszText = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszText );
     372    if( msgbox->lpszIcon && HIWORD( msgbox->lpszIcon ))
     373        msgboxa.lpszIcon = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszIcon );
     374
     375    ret = MessageBoxIndirectA(&msgboxa);
     376
     377    if (msgbox->lpszCaption)
     378        HeapFree( GetProcessHeap(), 0, ( LPVOID )msgboxa.lpszCaption );
     379    if (msgbox->lpszText)
     380        HeapFree( GetProcessHeap(), 0, ( LPVOID )msgboxa.lpszText );
     381    if( msgbox->lpszIcon && HIWORD( msgbox->lpszIcon ))
     382        HeapFree( GetProcessHeap(), 0, ( LPVOID )msgboxa.lpszIcon );
     383
     384    return ret;
     385#else
    364386    if (msgbox->lpszCaption)
    365387      lstrcpyWtoA((LPSTR)msgboxa.lpszCaption,msgbox->lpszCaption);
     
    368390
    369391    return MessageBoxIndirectA(&msgboxa);
     392#endif
     393
    370394}
    371395
  • trunk/src/user32/oslibmsg.cpp

    r10185 r10190  
    1 /* $Id: oslibmsg.cpp,v 1.71 2003-07-28 11:27:45 sandervl Exp $ */
     1/* $Id: oslibmsg.cpp,v 1.72 2003-07-31 15:56:43 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    226226  else {//is this allowed?
    227227//        dprintf(("WARNING: OSLibWinDispatchMsg: called with own message!"));
    228         return SendMessageA(msg->hwnd, msg->message, msg->wParam, msg->lParam);
     228        return isUnicode ? SendMessageW(msg->hwnd, msg->message, msg->wParam, msg->lParam) :
     229                           SendMessageA(msg->hwnd, msg->message, msg->wParam, msg->lParam);
    229230  }
    230231}
  • trunk/src/user32/oslibmsgtranslate.cpp

    r10189 r10190  
    1 /* $Id: oslibmsgtranslate.cpp,v 1.112 2003-07-31 12:25:57 sandervl Exp $ */
     1/* $Id: oslibmsgtranslate.cpp,v 1.113 2003-07-31 15:56:44 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    3838#include <winkeyboard.h>
    3939#include <winnls.h>
     40#include <heapstring.h>
    4041#include "hook.h"
    4142#include "user32api.h"
     
    732733        WORD  wWinScan;
    733734
    734         if (scanCode==0) goto dummymessage;
    735 
    736         KeyTranslatePMScanToWinVKey(usPMScanCode,
    737                                     FALSE,
    738                                     &bWinVKey,
    739                                     &wWinScan,
    740                                     &fWinExtended);
    741         winMsg->wParam = bWinVKey;
     735        if ( (!IsDBCSEnv() && scanCode == 0) ||
     736             (scanCode==0 ) && !( flags & KC_CHAR ) )
     737        {
     738            goto dummymessage;
     739        }
     740
     741        if( scanCode != 0 )
     742        {
     743            KeyTranslatePMScanToWinVKey(usPMScanCode,
     744                                        FALSE,
     745                                        &bWinVKey,
     746                                        &wWinScan,
     747                                        &fWinExtended);
     748            winMsg->wParam = bWinVKey;
     749        }
     750        else
     751        {
     752            dprintf(("PM: WM_CHAR: DBCS processing "));
     753
     754            winMsg->wParam = CHAR1FROMMP( os2Msg->mp2 );
     755
     756            wWinScan = 0;
     757            fWinExtended = 0;
     758
     759            if( CHAR2FROMMP( os2Msg->mp2 ))     // DBCS character
     760            {
     761                if( isUnicode )
     762                {
     763                    char  dbcsCh[] = { CHAR1FROMMP( os2Msg->mp2 ), CHAR2FROMMP( os2Msg->mp2 ), 0 };
     764                    WCHAR uniChar[ 2 ];
     765
     766                    lstrcpynAtoW(( LPWSTR )&uniChar, ( LPCSTR )&dbcsCh, 2 );
     767                    winMsg->wParam = ( WPARAM )uniChar[ 0 ];
     768                }
     769                // insert DBCS trail byte for Non-Unicode window
     770                else if(fMsgRemoved && !(teb->o.odin.fTranslated))
     771                {
     772                    MSG extramsg;
     773                    memcpy(&extramsg, winMsg, sizeof(MSG));
     774
     775                    //After SetFocus(0), all keystrokes are converted in WM_SYS*
     776                    extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
     777
     778                    extramsg.wParam = CHAR2FROMMP( os2Msg->mp2 );
     779                    extramsg.lParam = 0;
     780
     781                    setThreadQueueExtraCharMessage(teb, &extramsg);
     782                }
     783            }
     784        }
    742785        winMsg->lParam  = repeatCount & 0x0FFFF;                 // bit 0-15, repeatcount
    743786        winMsg->lParam |= (wWinScan & 0x1FF) << 16;  // bit 16-23, scancode + bit 15 extended
     
    797840            winMsg->lParam |= WIN_KEY_PREVSTATE;                    // bit 30, previous state, always 1 for a WM_KEYUP message
    798841            winMsg->lParam |= 1 << 31;                              // bit 31, transition state, always 1 for WM_KEYUP
     842          }
     843          else if( scanCode == 0 )
     844          {
     845            //After SetFocus(0), all keystrokes are converted in WM_SYS*
     846            winMsg->message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR :  WINWM_CHAR;
    799847          }
    800848          else
  • trunk/src/user32/pmwindow.cpp

    r10185 r10190  
    1 /* $Id: pmwindow.cpp,v 1.217 2003-07-28 11:27:47 sandervl Exp $ */
     1/* $Id: pmwindow.cpp,v 1.218 2003-07-31 15:56:44 sandervl Exp $ */
    22/*
    33 * Win32 Window Managment Code for OS/2
     
    514514    // - thread must not be suspended in WaitMessage
    515515    if(!teb || (msg != WM_CREATE && win32wnd == NULL) || teb->o.odin.fWaitMessageSuspend) {
    516         if(teb->o.odin.fWaitMessageSuspend)
     516        if(teb && teb->o.odin.fWaitMessageSuspend)
    517517             dprintf(("OS2: fWaitMessageSuspend window %x msg %x -> run default frame proc", hwnd, msg));
    518518        else dprintf(("OS2: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
     
    11821182    // - thread must not be suspended in WaitMessage
    11831183    if(!teb || (msg != WM_CREATE && win32wnd == NULL) || teb->o.odin.fWaitMessageSuspend) {
    1184         if(teb->o.odin.fWaitMessageSuspend)
     1184        if(teb && teb->o.odin.fWaitMessageSuspend)
    11851185             dprintf(("PMFRAME: fWaitMessageSuspend window %x msg %x -> run default frame proc", hwnd, msg));
    11861186        else dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
  • trunk/src/user32/resources/user32_Ko.orc

    r9491 r10190  
    77 MENUITEM "Å©±â º¯°æ(&S)", 61440
    88 MENUITEM "ŸÆÀÌÄÜ Ç¥œÃ(&N)", 61472
    9  MENUITEM "ÀüÃŒ È­žé Ç¥œÃ(&M)", 61488
     9 MENUITEM "ÀüÃŒ È­žé Ç¥œÃ(&F)", 61488
    1010 MENUITEM SEPARATOR
    1111 MENUITEM "ŽÝ±â(&C)\tAlt-F4", 61536
     
    1616SYSMENUWARP MENU LOADONCALL MOVEABLE DISCARDABLE
    1717{
    18  MENUITEM "º¹Í(&R)\tAlt-F5", 61728
    19  MENUITEM "ÀÌ¿(&M)\tAlt-F7", 61456
    20  MENUITEM "Åâ º¯°æ(&S)\tAlt-F8", 61440
    21  MENUITEM "ÆÀÌÄÜ ÇÃ(&N)\tAlt-F9", 61472
    22  MENUITEM "Àüà Ȟé ÇÃ(&M)\tAlt-F10", 61488
     18 MENUITEM "º¹±Í(&R)\tAlt-F5", 61728
     19 MENUITEM "À̵¿(&M)\tAlt-F7", 61456
     20 MENUITEM "Å©±â º¯°æ(&S)\tAlt-F8", 61440
     21 MENUITEM "ŸÆÀÌÄÜ Ç¥œÃ(&N)\tAlt-F9", 61472
     22 MENUITEM "ÀüÃŒ È­žé Ç¥œÃ(&F)\tAlt-F10", 61488
    2323 MENUITEM SEPARATOR
    24  MENUITEM "Ýâ(&C)\tAlt-F4", 61536
     24 MENUITEM "ŽÝ±â(&C)\tAlt-F4", 61536
    2525 MENUITEM SEPARATOR
    26  MENUITEM "ÀÛ÷ Àüȯ(&W) ...\tCtrl-Esc", 61744
     26 MENUITEM "ÀÛŸ÷ Àüȯ(&W) ...\tCtrl-Esc", 61744
    2727}
    2828
  • trunk/src/user32/win32wbase.cpp

    r10134 r10190  
    1 /* $Id: win32wbase.cpp,v 1.375 2003-06-03 09:51:05 sandervl Exp $ */
     1/* $Id: win32wbase.cpp,v 1.376 2003-07-31 15:56:45 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    8686//******************************************************************************
    8787//******************************************************************************
    88 Win32BaseWindow::Win32BaseWindow() 
     88Win32BaseWindow::Win32BaseWindow()
    8989                     : GenericObject(&windows, &critsect), ChildWindow(&critsect)
    9090{
     
    126126  windowNameA      = NULL;
    127127  windowNameW      = NULL;
    128   windowNameLength = 0;
    129  
     128  windowNameLengthA = 0;
     129  windowNameLengthW = 0;
     130
    130131  userWindowBytes  = NULL;;
    131132  nrUserWindowBytes= 0;
     
    228229    {
    229230        //if we're the last child that's being destroyed and our
    230         //parent window was also destroyed, then we 
     231        //parent window was also destroyed, then we
    231232        if(getParent()->IsWindowDestroyed())
    232233        {
     
    236237        }
    237238    }
    238     else 
     239    else
    239240    {
    240241        Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
     
    340341            }
    341342            if (window->getExStyle() & WS_EX_TOPMOST)
    342                  cs->dwExStyle |= WS_EX_TOPMOST;         
     343                 cs->dwExStyle |= WS_EX_TOPMOST;
    343344
    344345            RELEASE_WNDOBJ(window);
     
    389390        cs->lpszClass = buffer;
    390391    }
    391 
    392392    /* Fix the coordinates */
    393393    fXDefault = FALSE;
     
    446446                 RELEASE_WNDOBJ(wndparent);
    447447            }
    448             else owner = NULL;       
     448            else owner = NULL;
    449449
    450450            if(owner == NULL)
     
    582582        vertScrollInfo->flags  = ESB_ENABLE_BOTH;
    583583    }
    584  
     584
    585585    // initially allocate the window name fields
    586586    if(HIWORD(cs->lpszName))
     
    588588        if (!isUnicode)
    589589        {
    590             windowNameLength = strlen(cs->lpszName);
    591             windowNameA = (LPSTR)_smalloc(windowNameLength+1);
    592             memcpy(windowNameA,cs->lpszName,windowNameLength+1);
    593             windowNameW = (LPWSTR)_smalloc((windowNameLength+1)*sizeof(WCHAR));
    594             lstrcpynAtoW(windowNameW,windowNameA,windowNameLength+1);
    595             windowNameA[windowNameLength] = 0;
    596             windowNameW[windowNameLength] = 0;
     590            windowNameLengthA = strlen(cs->lpszName);
     591            windowNameA = (LPSTR)_smalloc(windowNameLengthA+1);
     592            strcpy(windowNameA,cs->lpszName);
     593
     594            windowNameLengthW = lstrlenAtoW( windowNameA, -1 );
     595            windowNameW = (LPWSTR)_smalloc(( windowNameLengthW + 1 ) * sizeof( WCHAR ) );
     596            lstrcpyAtoW( windowNameW, windowNameA );
    597597        }
    598598        else
    599599        {
    600600            // Wide
    601             windowNameLength = lstrlenW((LPWSTR)cs->lpszName);
    602             windowNameW = (LPWSTR)_smalloc( (windowNameLength+1)*sizeof(WCHAR) );
    603             memcpy(windowNameW,(LPWSTR)cs->lpszName, (windowNameLength+1)*sizeof(WCHAR) );
    604          
     601            windowNameLengthW = lstrlenW((LPWSTR)cs->lpszName);
     602            windowNameW = (LPWSTR)_smalloc((windowNameLengthW+1)*sizeof(WCHAR));
     603            strcpyW(windowNameW,(LPWSTR)cs->lpszName);
     604
    605605            // windowNameW[lstrlenW((LPWSTR)cs->lpszName)] = 0; // need ?
    606          
     606
    607607            // Ascii
    608             windowNameA = (LPSTR)_smalloc(windowNameLength+1);
    609             WideCharToMultiByte(CP_ACP,
    610                                 0,
    611                                 windowNameW,
    612                                 windowNameLength,
    613                                 windowNameA,
    614                                 windowNameLength + 1,
    615                                 0,
    616                                 NULL);
    617             windowNameA[windowNameLength] = 0;
    618         }
    619      
     608            windowNameLengthA = lstrlenWtoA( windowNameW, -1 );
     609            windowNameA = (LPSTR)_smalloc( windowNameLengthA + 1 );
     610            lstrcpyWtoA( windowNameA, windowNameW );
     611        }
     612
     613        dprintf(("windowNameA 0x%lx to 0x%lx windowNameW : 0x%lx to 0x%lx",
     614                windowNameA, windowNameA + windowNameLengthA,
     615                windowNameW, windowNameW + windowNameLengthW ));
     616
    620617        if(fOS2Look) {
    621618            OSLibWinSetTitleBarText(OS2HwndFrame, windowNameA);
     
    752749        //@@PF Popup children of inactive windows can thus bring inactive window
    753750        //on top, this is not correct, popup windows can be on top only if their owner
    754         //is in foreground, otherwise they are linked after owner. 
     751        //is in foreground, otherwise they are linked after owner.
    755752        if (((dwStyle & (WS_CHILD|WS_POPUP)) == WS_POPUP) && getOwner() && (getOwner()->getWindowHandle() != GetForegroundWindow()))
    756753        {
     
    10661063
    10671064    dprintf(("MsgButton %d at (%d,%d)", msg->message, msg->pt.x, msg->pt.y));
    1068     switch(msg->message) 
     1065    switch(msg->message)
    10691066    {
    10701067        case WM_LBUTTONDBLCLK:
     
    11321129    SendMessageA(getWindowHandle(),WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
    11331130
    1134     switch(msg->message) 
     1131    switch(msg->message)
    11351132    {
    11361133        case WM_LBUTTONDOWN:
     
    11551152}
    11561153//******************************************************************************
    1157 // 
     1154//
    11581155// Win32BaseWindow::saveAndValidateUpdateRegion
    11591156//
    1160 //   If an application doesn't validate the update region while processing 
     1157//   If an application doesn't validate the update region while processing
    11611158//   WM_PAINT, then we must remember it for the next time. Also validates
    11621159//   the current update region.
     
    11921189}
    11931190//******************************************************************************
    1194 // 
     1191//
    11951192// Win32BaseWindow::checkForDirtyUpdateRegion
    11961193//
    1197 //   If an application doesn't validate the update region while processing 
     1194//   If an application doesn't validate the update region while processing
    11981195//   WM_PAINT, then we must remember it for the next time. If the window has
    11991196//   a dirty update region, then invalidate that region.
     
    12501247ULONG Win32BaseWindow::MsgChar(MSG *msg)
    12511248{
    1252     return DispatchMsgA(msg);
     1249    return IsWindowUnicode() ? DispatchMsgW( msg ) : DispatchMsgA( msg );
    12531250}
    12541251//******************************************************************************
     
    12761273    //Send WM_PAINTICON here if minimized, because client window will
    12771274    //not receive a (valid) WM_PAINT message
    1278     if (getStyle() & WS_MINIMIZE) 
     1275    if (getStyle() & WS_MINIMIZE)
    12791276    {
    12801277        rc = SendMessageA(getWindowHandle(),WM_PAINTICON, 1, 0);
     
    13471344#endif
    13481345  //WS_EX_TOOLWINDOW is incompatible with the OS2Look (titlebar thinner + smaller font)
    1349   if(fOS2Look && ((dwStyle & WS_CAPTION) == WS_CAPTION) && !(dwExStyle & WS_EX_TOOLWINDOW)) 
     1346  if(fOS2Look && ((dwStyle & WS_CAPTION) == WS_CAPTION) && !(dwExStyle & WS_EX_TOOLWINDOW))
    13501347  {
    13511348      RECT rect = {0};
     
    13621359      rect.top    = rect.bottom - rect.top;
    13631360      rect.right  = rectWindow.right - rectWindow.left - rect.right;
    1364  
     1361
    13651362      rectOS2.xLeft   = rect.left;
    13661363      rectOS2.xRight  = rect.right;
     
    13681365      rectOS2.yTop    = height - rect.bottom;
    13691366
    1370       //@@PF Disable close button as well when needed by application 
     1367      //@@PF Disable close button as well when needed by application
    13711368      OSLibChangeCloseButtonState(getOS2FrameWindowHandle(), fCloseButton);
    13721369      OSLibWinPositionFrameControls(getOS2FrameWindowHandle(), &rectOS2,
    13731370                                    dwStyle, dwExStyle, IconForWindow(ICON_SMALL),
    1374                                     fCloseButton, windowClass->getIcon() != NULL);
     1371                    fCloseButton, windowClass->getIcon() != NULL);
    13751372  }
    13761373  return rc;
     
    15621559
    15631560    case WM_GETTEXTLENGTH:
    1564         return windowNameLength;
     1561        return windowNameLengthA;
    15651562
    15661563    case WM_GETTEXT:
    1567         if (!lParam || !wParam) 
     1564        if (!lParam || !wParam)
    15681565          return 0;
    1569         if (!windowNameA) 
     1566        if (!windowNameA)
    15701567          ((LPSTR)lParam)[0] = 0;
    1571         else 
    1572           memcpy((LPSTR)lParam, windowNameA, min(windowNameLength+1, wParam) );
    1573         return min(windowNameLength, wParam);
     1568        else
     1569          lstrcpynA(( LPSTR )lParam, windowNameA, wParam );
     1570        return strlen(( LPSTR )lParam );
    15741571
    15751572    case WM_SETTEXT:
    15761573    {
    15771574        LPCSTR lpsz = (LPCSTR)lParam;
    1578      
     1575
    15791576        // reallocate if new buffer is larger
    15801577        if (!lParam)
     
    15821579          free(windowNameA);
    15831580          free(windowNameW);
    1584           windowNameLength = 0;
     1581          windowNameLengthA = 0;
     1582          windowNameLengthW = 0;
    15851583          windowNameA      = NULL;
    15861584          windowNameW      = NULL;
     
    15901588          // determine length of new text
    15911589          int iTextLength = strlen(lpsz);
    1592          
    1593           if (windowNameLength < iTextLength)
     1590
     1591          if (windowNameLengthA < iTextLength)
    15941592          {
    15951593            if (windowNameA)
     
    15981596              windowNameA = NULL;
    15991597            }
    1600          
     1598
    16011599            if (windowNameW)
    16021600            {
     
    16051603            }
    16061604          }
    1607      
    1608           windowNameLength = iTextLength;
     1605
     1606          windowNameLengthA = iTextLength;
    16091607          if(!windowNameA)
    1610             windowNameA = (LPSTR)_smalloc(windowNameLength+1);
    1611           memcpy(windowNameA, lpsz, windowNameLength+1);
     1608            windowNameA = (LPSTR)_smalloc(windowNameLengthA+1);
     1609          strcpy(windowNameA, lpsz);
     1610          windowNameLengthW = lstrlenAtoW( windowNameA, -1 );
    16121611          if(!windowNameW)
    1613             windowNameW = (LPWSTR)_smalloc((windowNameLength+1)*sizeof(WCHAR));
    1614           lstrcpynAtoW(windowNameW, windowNameA, windowNameLength+1);
    1615         }
    1616      
     1612            windowNameW = (LPWSTR)_smalloc(( windowNameLengthW + 1 )*sizeof(WCHAR));
     1613          lstrcpyAtoW( windowNameW, windowNameA );
     1614        }
     1615
    16171616        dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
    16181617        if ((dwStyle & WS_CAPTION) == WS_CAPTION)
     
    16751674        dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
    16761675        if (::GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
    1677         {
    1678             LONG ret = ::SendMessageW( ::GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
    1679             if (ret) return ret;
    1680         }
    1681 
    1682         /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
     1676    {
     1677        LONG ret = ::SendMessageW( ::GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
     1678        if (ret) return ret;
     1679    }
     1680
     1681    /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
    16831682        return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
    16841683    }
     
    17541753        if (::GetWindowLongA( getWindowHandle(), GWL_STYLE ) & WS_CHILD)
    17551754            return ::SendMessageA( ::GetParent(getWindowHandle()), WM_MOUSEWHEEL, wParam, lParam );
    1756         break;
     1755    break;
    17571756
    17581757    case WM_WINDOWPOSCHANGED:
     
    17891788      RECT   rect;
    17901789      int    rc;
    1791      
    1792         if (!windowClass || (!windowClass->getBackgroundBrush() 
     1790
     1791        if (!windowClass || (!windowClass->getBackgroundBrush()
    17931792                              && !(getStyle() & WS_MINIMIZE))) return 0;
    17941793
     
    18041803                hBrush = GetSysColorBrush(hBrush-1);
    18051804        }
    1806              
     1805
    18071806
    18081807        rc = GetClipBox( (HDC)wParam, &rect );
     
    19051904
    19061905    case WM_KEYDOWN:
    1907         if(wParam == VK_F10) iF10Key = VK_F10;
    1908         break;
     1906    if(wParam == VK_F10) iF10Key = VK_F10;
     1907    break;
    19091908
    19101909    case WM_SYSKEYDOWN:
    19111910    {
    1912         if( HIWORD(lParam) & KEYDATA_ALT )
    1913         {
    1914             /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
    1915               if( wParam == VK_MENU && !iMenuSysKey )
    1916                 iMenuSysKey = 1;
    1917               else
    1918                 iMenuSysKey = 0;
    1919            
    1920             iF10Key = 0;
    1921 
    1922             if( wParam == VK_F4 )       /* try to close the window */
    1923             {
     1911    if( HIWORD(lParam) & KEYDATA_ALT )
     1912    {
     1913        /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
     1914          if( wParam == VK_MENU && !iMenuSysKey )
     1915        iMenuSysKey = 1;
     1916          else
     1917        iMenuSysKey = 0;
     1918
     1919        iF10Key = 0;
     1920
     1921        if( wParam == VK_F4 )   /* try to close the window */
     1922        {
    19241923                HWND top = GetTopParent();
    19251924                if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
    19261925                    PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
    1927             }
     1926        }
    19281927
    19291928            //Default OS/2 app behaviour for system keys
    19301929            if(fOS2Look)
    19311930            {
    1932                     if( wParam == VK_F5 )       /* try to restore the window */
    1933                     {
    1934                         HWND top = GetTopParent();
     1931            if( wParam == VK_F5 )   /* try to restore the window */
     1932            {
     1933                    HWND top = GetTopParent();
    19351934                        /* No checks needed SC_RESTORE handler does them */
    1936                         PostMessageW( top, WM_SYSCOMMAND, SC_RESTORE, 0 );
    1937                     }
    1938 
    1939                     if( wParam == VK_F7 )       /* size the window */
    1940                     {
    1941                         HWND top = GetTopParent();
    1942                         PostMessageW( top, WM_SYSCOMMAND, SC_MOVE, 0 );
    1943                     }
    1944 
    1945                     if( wParam == VK_F8 )       /* move the window */
    1946                     {
    1947                         HWND top = GetTopParent();
    1948                         if ( GetWindowLongA(top, GWL_STYLE) & WS_SIZEBOX)
    1949                         PostMessageW( top, WM_SYSCOMMAND, SC_SIZE, 0 );
    1950                     }
    1951 
    1952                     if( wParam == VK_F9 )       /* try to minimize the window */
    1953                     {
    1954                         HWND top = GetTopParent();
    1955                         if ( GetWindowLongA(top, GWL_STYLE) & WS_MINIMIZEBOX)
    1956                             PostMessageW( top, WM_SYSCOMMAND, SC_MINIMIZE, 0 );
    1957                     }
    1958 
    1959                     if( wParam == VK_F10 )      /* try to maximize the window */
    1960                     {
    1961                         HWND top = GetTopParent();
    1962                         if ( GetWindowLongA(top, GWL_STYLE) & WS_MAXIMIZEBOX)
    1963                             PostMessageW( top, WM_SYSCOMMAND, SC_MAXIMIZE, 0 );
    1964                     }
    1965             }
    1966 
    1967         }
    1968         else if( wParam == VK_F10 )
    1969                 iF10Key = 1;
    1970              else
    1971                 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
     1935                    PostMessageW( top, WM_SYSCOMMAND, SC_RESTORE, 0 );
     1936            }
     1937
     1938            if( wParam == VK_F7 )   /* size the window */
     1939            {
     1940                    HWND top = GetTopParent();
     1941                    PostMessageW( top, WM_SYSCOMMAND, SC_MOVE, 0 );
     1942            }
     1943
     1944            if( wParam == VK_F8 )   /* move the window */
     1945            {
     1946                    HWND top = GetTopParent();
     1947                    if ( GetWindowLongA(top, GWL_STYLE) & WS_SIZEBOX)
     1948                    PostMessageW( top, WM_SYSCOMMAND, SC_SIZE, 0 );
     1949            }
     1950
     1951            if( wParam == VK_F9 )   /* try to minimize the window */
     1952            {
     1953                    HWND top = GetTopParent();
     1954                    if ( GetWindowLongA(top, GWL_STYLE) & WS_MINIMIZEBOX)
     1955                        PostMessageW( top, WM_SYSCOMMAND, SC_MINIMIZE, 0 );
     1956            }
     1957
     1958            if( wParam == VK_F10 )  /* try to maximize the window */
     1959            {
     1960                    HWND top = GetTopParent();
     1961                    if ( GetWindowLongA(top, GWL_STYLE) & WS_MAXIMIZEBOX)
     1962                        PostMessageW( top, WM_SYSCOMMAND, SC_MAXIMIZE, 0 );
     1963            }
     1964            }
     1965
     1966    }
     1967    else if( wParam == VK_F10 )
     1968            iF10Key = 1;
     1969         else
     1970            if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
    19721971                    SendMessageW(getWindowHandle(), WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE );
    19731972        return 0;
     
    19791978        // no break;
    19801979    case WM_SYSKEYUP:
    1981         /* Press and release F10 or ALT */
    1982         if (((wParam == VK_MENU) && iMenuSysKey) ||
     1980    /* Press and release F10 or ALT */
     1981    if (((wParam == VK_MENU) && iMenuSysKey) ||
    19831982            ((wParam == VK_F10) && iF10Key))
    19841983              ::SendMessageW( GetTopParent(), WM_SYSCOMMAND, SC_KEYMENU, 0L );
    1985         iMenuSysKey = iF10Key = 0;
     1984    iMenuSysKey = iF10Key = 0;
    19861985        break;
    19871986
     
    20202019    case WM_RBUTTONUP:
    20212020        {
    2022             POINT pt;
    2023             pt.x = SLOWORD(lParam);
    2024             pt.y = SHIWORD(lParam);
    2025             ClientToScreen(getWindowHandle(), &pt);
     2021        POINT pt;
     2022        pt.x = SLOWORD(lParam);
     2023        pt.y = SHIWORD(lParam);
     2024        ClientToScreen(getWindowHandle(), &pt);
    20262025            SendMessageA( getWindowHandle(), WM_CONTEXTMENU, getWindowHandle(),MAKELPARAM(pt.x, pt.y) );
    20272026        }
     
    21362135    {
    21372136    case WM_GETTEXTLENGTH:
    2138         return windowNameLength;
     2137        return windowNameLengthW;
    21392138
    21402139    case WM_GETTEXT:
    2141         if (!lParam || !wParam) 
     2140        if (!lParam || !wParam)
    21422141          return 0;
    21432142        if (!windowNameW)
    21442143          ((LPWSTR)lParam)[0] = 0;
    2145         else
    2146           memcpy((LPSTR)lParam, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), wParam) );
    2147         return min(windowNameLength, wParam);
     2144        else
     2145          lstrcpynW(( LPWSTR )lParam, windowNameW, wParam );
     2146
     2147        return strlenW(( LPWSTR )lParam );
    21482148
    21492149    case WM_SETTEXT:
    21502150    {
    21512151        LPWSTR lpsz = (LPWSTR)lParam;
    2152      
     2152
    21532153        // reallocate if new buffer is larger
    21542154        if (!lParam)
     
    21562156          free(windowNameA);
    21572157          free(windowNameW);
    2158           windowNameLength = 0;
     2158          windowNameLengthA = 0;
     2159          windowNameLengthW = 0;
    21592160          windowNameA      = NULL;
    21602161          windowNameW      = NULL;
     
    21642165          // determine length of new text
    21652166          int iTextLength = lstrlenW(lpsz);
    2166          
    2167           if (windowNameLength < iTextLength)
     2167
     2168          if (windowNameLengthW < iTextLength)
    21682169          {
    21692170            if (windowNameA)
     
    21722173              windowNameA = NULL;
    21732174            }
    2174          
     2175
    21752176            if (windowNameW)
    21762177            {
     
    21792180            }
    21802181          }
    2181      
    2182           windowNameLength = iTextLength;
     2182
     2183          windowNameLengthW = iTextLength;
    21832184          if(!windowNameW)
    2184             windowNameW = (LPWSTR)_smalloc((windowNameLength+1)*sizeof(WCHAR));
    2185           memcpy(windowNameW, lpsz, (windowNameLength+1) * sizeof(WCHAR));
     2185            windowNameW = (LPWSTR)_smalloc((windowNameLengthW+1)*sizeof(WCHAR));
     2186          strcpyW(windowNameW, lpsz);
     2187          windowNameLengthA = lstrlenWtoA( windowNameW, -1 );
    21862188          if(!windowNameA)
    2187             windowNameA = (LPSTR)_smalloc(windowNameLength+1);
    2188           lstrcpynWtoA(windowNameA, windowNameW, windowNameLength+1);
    2189         }
    2190 
    2191         dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
     2189            windowNameA = (LPSTR)_smalloc( windowNameLengthA + 1 );
     2190          lstrcpyWtoA( windowNameA, windowNameW );
     2191        }
     2192
     2193        dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, windowNameA));
    21922194        if ((dwStyle & WS_CAPTION) == WS_CAPTION)
    21932195        {
     
    22592261        hWndIcon = windowClass->getIcon();
    22602262    else
    2261     if (!(dwStyle & DS_MODALFRAME)) 
     2263    if (!(dwStyle & DS_MODALFRAME))
    22622264    {//SvL: load it as shared or else we'll leak icons
    22632265         hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_SHARED);
     
    22792281        hWndIcon = windowClass->getIcon();
    22802282    else
    2281     if (!(dwStyle & DS_MODALFRAME)) 
     2283    if (!(dwStyle & DS_MODALFRAME))
    22822284    {//SvL: load it as shared or else we'll leak icons
    22832285         hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_SHARED);
     
    23102312        dprintf(("ShowWindow: GetProcessDword(0, GPD_STARTF_SHOWWINDOW) -> %x", nCmdShow));
    23112313    }
    2312  
     2314
    23132315
    23142316    switch(nCmdShow)
     
    24332435//******************************************************************************
    24342436//******************************************************************************
    2435 BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, 
     2437BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx,
    24362438                                   int cy, UINT fuFlags, BOOL fShowWindow)
    24372439{
     
    25382540        OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
    25392541    }
    2540     if((dwOldStyle & WS_MINIMIZE) && (getStyle() & WS_MINIMIZE)) 
     2542    if((dwOldStyle & WS_MINIMIZE) && (getStyle() & WS_MINIMIZE))
    25412543    {//don't allow size changes if the window is minimized
    25422544     //we will update the restore position at the end of this method
     
    25892591    //SvL: Must also deactivate the window when hiding it or else focus won't
    25902592    //     change. (NOTE: make sure this doesn't cause regressions (01-02-2003)
    2591     if((swp.fl & (SWPOS_HIDE|SWPOS_DEACTIVATE)) == (SWPOS_HIDE|SWPOS_DEACTIVATE)) 
     2593    if((swp.fl & (SWPOS_HIDE|SWPOS_DEACTIVATE)) == (SWPOS_HIDE|SWPOS_DEACTIVATE))
    25922594    {
    25932595        //we must make sure the owner is not disabled or else the focus will
     
    26872689         wpos->y      = rectWindow.top;
    26882690    }
    2689    
     2691
    26902692    WINDOWPOS wpOld = *wpos;
    26912693    if(!(wpos->flags & SWP_NOSENDCHANGING))
     
    28232825        return FALSE;
    28242826    }
    2825  
     2827
    28262828    if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
    28272829    {
     
    28542856    }
    28552857    dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
    2856  
     2858
    28572859    // check the handle for the last active popup window
    28582860    Win32BaseWindow* owner = getOwner();
     
    28702872        //     (MFC created modeless dialog)
    28712873        //TODO: This might be the wrong place to do it. EndDialog is called,
    2872         //      so perhaps it should be done there. (although Wine only 
     2874        //      so perhaps it should be done there. (although Wine only
    28732875        //      enables the owner if the dialog is modal)
    28742876        ::EnableWindow(owner->getWindowHandle(), 1);
    28752877    }
    2876  
     2878
    28772879    fDestroyWindowCalled = TRUE;
    28782880
     
    29292931  Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
    29302932
    2931     if(getStyle() & WS_CHILD) 
     2933    if(getStyle() & WS_CHILD)
    29322934    {
    29332935        if(wndparent) {
     
    29382940        return 0;
    29392941    }
    2940     else 
     2942    else
    29412943    if(getStyle() & WS_POPUP)
    29422944         return (getOwner()) ? getOwner()->getWindowHandle() : 0;
     
    30273029    // in release build.
    30283030    Win32BaseWindow *_parent = getParent();
    3029    
    3030     if(_parent) 
     3031
     3032    if(_parent)
    30313033    {
    30323034        if(_parent->getWindowHandle() == hwndParent)
    30333035            return TRUE;
    3034    
     3036
    30353037        return _parent->IsChild(hwndParent);
    30363038    }
    3037     else 
     3039    else
    30383040        return 0;
    30393041}
     
    32083210    dprintf(("EnumWindows %x %x", lpfn, lParam));
    32093211
    3210     for(int i=0;i<MAX_WINDOW_HANDLES;i++) 
     3212    for(int i=0;i<MAX_WINDOW_HANDLES;i++)
    32113213    {
    32123214        window = Win32BaseWindow::GetWindowFromHandle(hwnd);
     
    34403442             if(window->state >= STATE_POST_WMNCCREATE) {
    34413443                 hwndRelated = window->getWindowHandle();
    3442                  RELEASE_WNDOBJ(window); 
     3444                 RELEASE_WNDOBJ(window);
    34433445             }
    34443446             else {
    34453447                 hwndRelated = window->GetWindow(GW_HWNDNEXT);
    3446                  RELEASE_WNDOBJ(window); 
     3448                 RELEASE_WNDOBJ(window);
    34473449             }
    34483450        }
     
    34973499//******************************************************************************
    34983500PRECT Win32BaseWindow::getWindowRect()
    3499 { 
    3500     return &rectWindow; 
     3501{
     3502    return &rectWindow;
    35013503}
    35023504//******************************************************************************
     
    36683670{
    36693671    //if the destination window is created by this process, send message
    3670     if(dwProcessId == currentProcessId) 
     3672    if(dwProcessId == currentProcessId)
    36713673    {
    36723674        if(fUnicode) {
     
    36773679    //else get data directory from window structure
    36783680    //TODO: must lock window structure.... (TODO)
    3679     return windowNameLength;
     3681    return fUnicode ? windowNameLengthW : windowNameLengthA;
    36803682}
    36813683//******************************************************************************
     
    36893691        return SendMessageA(getWindowHandle(),WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
    36903692    }
    3691  
     3693
    36923694    //else get data directory from window structure
    36933695    if (!lpsz || !cch) return 0;
    36943696    if (!windowNameA) lpsz[0] = 0;
    3695     else memcpy(lpsz, windowNameA, min(windowNameLength + 1, cch) );
    3696     return min(windowNameLength, cch);
     3697    else lstrcpynA( lpsz, windowNameA, cch );
     3698    return strlen( lpsz );
    36973699}
    36983700//******************************************************************************
     
    37073709    }
    37083710    //else get data directory from window structure
    3709     if (!lpsz || !cch) 
     3711    if (!lpsz || !cch)
    37103712        return 0;
    3711     if (!windowNameW) 
     3713    if (!windowNameW)
    37123714        lpsz[0] = 0;
    3713     else 
    3714         memcpy(lpsz, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), cch));
    3715            
    3716     return min(windowNameLength, cch);
     3715    else
     3716        lstrcpynW( lpsz, windowNameW, cch );
     3717
     3718    return strlenW( lpsz );
    37173719}
    37183720//******************************************************************************
     
    37513753                SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
    37523754
    3753                 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), 
     3755                OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(),
    37543756                                    getStyle(), getExStyle(),ss.styleOld);
    37553757
     
    37603762        {
    37613763                STYLESTRUCT ss;
    3762  
     3764
    37633765                //SvL: TODO: Can you change minimize or maximize status here too?
    37643766
     
    37683770                }
    37693771                dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value));
    3770                
     3772
    37713773                //Changing WS_CHILD style is allowed
    37723774                ss.styleOld = getStyle();
     
    37763778                SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
    37773779
    3778                  OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), 
     3780                 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(),
    37793781                                    getStyle(), getExStyle(),ss.styleOld);
    37803782
     
    39413943    switch(index)
    39423944    {
    3943     case GWW_ID:         
    3944         if(HIWORD(getWindowId()))
     3945    case GWW_ID:
     3946        if(HIWORD(getWindowId()))
    39453947            dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId()));
    39463948        return (WORD)getWindowId();
    39473949
    3948     case GWW_HWNDPARENT: 
     3950    case GWW_HWNDPARENT:
    39493951        dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent()));
    3950         return (WORD) GetParent();
    3951 
    3952     case GWW_HINSTANCE: 
    3953         if (HIWORD(hInstance))
     3952        return (WORD) GetParent();
     3953
     3954    case GWW_HINSTANCE:
     3955        if (HIWORD(hInstance))
    39543956            dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance));
    39553957        return (WORD)hInstance;
     
    39693971//    VISRGN_NOTIFY_PROC lpNotifyProc    - notification handler
    39703972//    DWORD              dwUserData      - caller supplied parameter for handler invocations
    3971 // 
     3973//
    39723974// Returns:
    39733975//    TRUE              - Success
     
    39893991// Parameters:
    39903992//    BOOL   fDrawingAllowed    - drawing is allowed or not
    3991 // 
     3993//
    39923994// Returns:
    39933995//    TRUE              - Success
     
    39953997//
    39963998//******************************************************************************
    3997 void Win32BaseWindow::callVisibleRgnNotifyProc(BOOL fDrawingAllowed) 
     3999void Win32BaseWindow::callVisibleRgnNotifyProc(BOOL fDrawingAllowed)
    39984000{
    39994001    if(fDrawingAllowed) {
     
    40164018//    int  chdcWindow   - size of HDC array       (IN)
    40174019//    int *pnrdcs       - number of HDCs returned (OUT)
    4018 // 
     4020//
    40194021// Returns:
    40204022//    TRUE              - Success
     
    40504052// Parameters:
    40514053//    HDC hdc            - HDC to be added to our list of open DCs
    4052 // 
     4054//
    40534055// Returns:
    40544056//
     
    40834085// Parameters:
    40844086//    HDC hdc            - HDC to be removed from our list of open DCs
    4085 // 
     4087//
    40864088// Returns:
    40874089//
     
    41414143{
    41424144 DWORD            magic;
    4143  HWND             hwnd; 
     4145 HWND             hwnd;
    41444146
    41454147    if(hwndOS2 == OSLIB_HWND_DESKTOP)
     
    41574159//  dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
    41584160
    4159     //Now check if it's a fake window 
     4161    //Now check if it's a fake window
    41604162    Win32FakeWindow *window = Win32FakeWindow::GetWindowFromOS2Handle(hwndOS2);
    41614163    if(window) {
  • trunk/src/user32/win32wbase.h

    r10091 r10190  
    1 /* $Id: win32wbase.h,v 1.154 2003-05-15 12:40:20 sandervl Exp $ */
     1/* $Id: win32wbase.h,v 1.155 2003-07-31 15:56:47 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    3131#define NROF_WIN32WNDBYTES        16
    3232
    33 #define WINDOWFLAG_ACTIVE         1
     33#define WINDOWFLAG_ACTIVE     1
    3434
    3535#define WIN32PM_MAGIC             0x12345678
     
    3838#define MAX_OPENDCS               8
    3939
    40 #define TYPE_ASCII                0
    41 #define TYPE_UNICODE              1
     40#define TYPE_ASCII        0
     41#define TYPE_UNICODE          1
    4242
    4343#define GW_HWNDNEXTCHILD          (0x10000 | GW_HWNDNEXT)
     
    101101#define HAS_MENU() (!(getStyle() & WS_CHILD) && (getWindowId() != 0))
    102102
    103 #define STATE_INIT               0   //initial state
     103#define STATE_INIT           0   //initial state
    104104#define STATE_PRE_WMNCCREATE     1   //before WM_NCCREATE
    105105#define STATE_POST_WMNCCREATE    2   //after WM_NCCREATE
     
    234234
    235235         void   saveAndValidateUpdateRegion();
    236          void   checkForDirtyUpdateRegion();   
     236         void   checkForDirtyUpdateRegion();
    237237         BOOL   hasDirtUpdateRegion()             { return fDirtyUpdateRegion; };
    238238
     
    276276//hack alert (see DestroyWindow)
    277277         BOOL   IsChildDestructionInProgress() { return fChildDestructionInProgress; };
    278          void   SetChildDestructionInProgress(BOOL fDestuctionInProgress) 
    279          { 
     278         void   SetChildDestructionInProgress(BOOL fDestuctionInProgress)
     279         {
    280280             fChildDestructionInProgress = fDestuctionInProgress;
    281281         };
     
    310310         CHAR  *getWindowNameA()              { return windowNameA; }; //only for MDI windows!
    311311         WCHAR *getWindowNameW()              { return windowNameW; }; //only for MDI windows!
    312          int    getWindowNameLength()         { return windowNameLength; };
     312         int    getWindowNameLengthA()        { return windowNameLengthA; };
     313         int    getWindowNameLengthW()        { return windowNameLengthW; };
    313314         Win32WndClass  *getClass()  { return windowClass; };
    314315         Win32BaseWindow *getOwner() { return owner; };
     
    338339
    339340
    340          BOOL   isComingToTop()                 { return fComingToTop; };
    341          void   setComingToTop(BOOL fTop)       { fComingToTop = fTop; };
     341     BOOL   isComingToTop()         { return fComingToTop; };
     342     void   setComingToTop(BOOL fTop)   { fComingToTop = fTop; };
    342343         BOOL   isInTasklist()                  { return fTaskList; };
    343344
    344345         //window property methods
    345346         HANDLE getProp(LPCSTR str);
    346         BOOL   setProp(LPCSTR str, HANDLE handle);
    347         HANDLE removeProp(LPCSTR str);
    348         INT    enumPropsExA(PROPENUMPROCEXA func, LPARAM lParam);
    349         INT    enumPropsExW(PROPENUMPROCEXW func, LPARAM lParam);
     347    BOOL   setProp(LPCSTR str, HANDLE handle);
     348    HANDLE removeProp(LPCSTR str);
     349    INT    enumPropsExA(PROPENUMPROCEXA func, LPARAM lParam);
     350    INT    enumPropsExW(PROPENUMPROCEXW func, LPARAM lParam);
    350351
    351352#ifdef DEBUG
     
    391392        ULONG   userData;               //GWL_USERDATA
    392393        HWND    hwndLastActive;         // last active popup handle
    393  
     394
    394395        ULONG   cbExtra;
    395396        PVOID   pExtra;
     
    414415                 fCXDefault:1,
    415416                 fParentDC:1,
    416                  fComingToTop:1,
     417             fComingToTop:1,
    417418                 isUnicode:1,
    418419                 fMinMaxChange:1,        //set when switching between min/max/restored state
     
    440441        char   *windowNameA;
    441442        WCHAR  *windowNameW;
    442         int     windowNameLength;
    443  
     443        int     windowNameLengthA;
     444        int     windowNameLengthW;
     445
    444446        char   *userWindowBytes;
    445447        ULONG   nrUserWindowBytes;
     
    455457VISRGN_NOTIFY_PROC lpVisRgnNotifyProc;
    456458        DWORD   dwVisRgnNotifyParam;
    457        
     459
    458460        HANDLE  hTaskList; //PM specific (switchentry handle)
    459461
  • trunk/src/user32/winaccel.cpp

    r9974 r10190  
    1 /* $Id: winaccel.cpp,v 1.11 2003-04-02 12:58:02 sandervl Exp $ */
     1/* $Id: winaccel.cpp,v 1.12 2003-07-31 15:56:47 sandervl Exp $ */
    22/*
    33 * Win32 accelerator key functions for OS/2
     
    1818#include <misc.h>
    1919#include <heapstring.h>
    20 #include "win32wbase.h"
    2120#include <win\winnls.h>
    2221
     
    2423#include "dbglocal.h"
    2524
    26 /**********************************************************************
    27  *           KBD_translate_accelerator
    28  *
    29  * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP  -messages
    30  */
    31 static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
    32                                       BYTE fVirt,WORD key,WORD cmd)
    33 {
    34     BOOL sendmsg = FALSE;
    35 
    36     if(msg->wParam == key)
    37     {
    38         if (msg->message == WM_CHAR) {
    39             if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
    40             {
    41                 dprintf(("TranslateAccelerator: found accel for WM_CHAR: ('%c')\n", msg->wParam&0xff));
    42                 sendmsg=TRUE;
    43             }
    44         }
    45         else
    46         {
    47             if(fVirt & FVIRTKEY) {
    48                 INT mask = 0;
    49                 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
    50                 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
    51                 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
    52 
    53                 if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
    54                         sendmsg=TRUE;
    55                 else    dprintf(("TranslateAccelerator: but incorrect SHIFT/CTRL/ALT-state %x != %x", mask, fVirt));
    56             }
    57             else
    58             {
    59                 if (!(msg->lParam & 0x01000000))  /* no special_key */
    60                 {
    61                     if ((fVirt & FALT) && (msg->lParam & 0x20000000))
    62                     {                                                   /* ^^ ALT pressed */
    63                         dprintf(("TranslateAccelerator: found accel for Alt-%c\n", msg->wParam&0xff));
    64                         sendmsg=TRUE;
    65                     }
    66                 }
    67             }
    68         }
    69 
    70         if (sendmsg)      /* found an accelerator, but send a message... ? */
    71         {
    72             INT  iSysStat,iStat,mesg=0;
    73             HMENU hMenu;
    74 
    75             if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) {
    76                 mesg=1;
    77             }
    78             else
    79                 if (GetCapture())
    80                     mesg=2;
    81                 else
    82                 if (!IsWindowEnabled(hWnd))
    83                     mesg=3;
    84                 else
    85                 {
    86                     Win32BaseWindow *window;
    87 
    88                     window = Win32BaseWindow::GetWindowFromHandle(hWnd);
    89                     if(!window) {
    90                         return FALSE; //should never happen! (already checked)
    91                     }
    92 
    93                     hMenu = GetMenu(hWnd);
    94 
    95                     iSysStat = (window->GetSysMenu()) ? GetMenuState(GetSubMenu(window->GetSysMenu(), 0),
    96                                                                      cmd, MF_BYCOMMAND) : -1 ;
    97                     iStat = (hMenu) ? GetMenuState(hMenu, cmd, MF_BYCOMMAND) : -1 ;
    98 
    99                     if (iSysStat!=-1)
    100                     {
    101                         if (iSysStat & (MF_DISABLED|MF_GRAYED))
    102                             mesg=4;
    103                         else
    104                             mesg=WM_SYSCOMMAND;
    105                     }
    106                     else
    107                     {
    108                         if (iStat!=-1)
    109                         {
    110                             if (IsIconic(hWnd)) {
    111                                 mesg=5;
    112                             }
    113                             else
    114                             {
    115                                 if (iStat & (MF_DISABLED|MF_GRAYED))
    116                                     mesg=6;
    117                                 else
    118                                     mesg=WM_COMMAND;
    119                             }
    120                         }
    121                         else
    122                             mesg=WM_COMMAND;
    123                     }
    124                     RELEASE_WNDOBJ(window);
    125                 }
    126                 if ( mesg==WM_COMMAND || mesg==WM_SYSCOMMAND )
    127                 {
    128                     SendMessageA(hWnd, mesg, cmd, 0x00010000L);
    129                 }
    130                 else
    131                 {
    132                     /*  some reasons for NOT sending the WM_{SYS}COMMAND message:
    133                      *   #0: unknown (please report!)
    134                      *   #1: for WM_KEYUP,WM_SYSKEYUP
    135                      *   #2: mouse is captured
    136                      *   #3: window is disabled
    137                      *   #4: it's a disabled system menu option
    138                      *   #5: it's a menu option, but window is iconic
    139                      *   #6: it's a menu option, but disabled
    140                      */
    141                     if(mesg==0)
    142                             dprintf(("ERROR: unknown reason - please report!"));
    143                     else    dprintf(("but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg));
    144 
    145                 }
    146                 return TRUE;
    147             }
    148             dprintf(("TranslateAccelerator: not match for %x %x %x", fVirt, key, cmd));
    149     }
    150     return FALSE;
    151 }
    152 /*****************************************************************************
    153  * Name      : int WIN32API TranslateAcceleratorA
    154  * Purpose   : Translate WM_*KEYDOWN messages to WM_COMMAND messages
    155  *             according to Accelerator table
    156  * Parameters: HWND hwnd, HACCEL haccel, LPMSG lpmsg
    157  * Variables :
    158  * Result    : int FALSE (no accelerator found) TRUE (accelerator found)
    159  * Remark    : if a accelerator is found it is not neccesarely executed
    160  *             depends on window stat
    161  *
    162  *****************************************************************************/
    163 INT WINAPI TranslateAcceleratorA(HWND hWnd, HACCEL hAccel, LPMSG msg)
    164 {
    165     /* YES, Accel16! */
    166     LPACCEL lpAccelTbl;
    167     int i;
    168 
    169     SetLastError(ERROR_SUCCESS);
    170     if (msg == NULL)
    171     {
    172           dprintf(("TranslateAcceleratorAmsg null; should hang here to be win compatible"));
    173           SetLastError(ERROR_INVALID_PARAMETER);
    174           return 0;
    175     }
    176     if (!hAccel || !(lpAccelTbl = (LPACCEL)GlobalLock(hAccel)))
    177     {
    178           dprintf(("TranslateAcceleratorA: invalid accel handle=%x", hAccel));
    179           SetLastError(ERROR_INVALID_PARAMETER);
    180           return 0;
    181     }
    182     if(!IsWindow(hWnd)) {
    183           dprintf(("TranslateAccelerator, window %x not found", hWnd));
    184           SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    185           return 0;
    186     }
    187     if ((msg->message != WM_KEYDOWN &&
    188          msg->message != WM_KEYUP &&
    189          msg->message != WM_SYSKEYDOWN &&
    190          msg->message != WM_SYSKEYUP &&
    191          msg->message != WM_CHAR))
    192     {
    193           return 0;
    194     }
    195 
    196 /*    TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
    197       "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
    198       hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam); */
    199 
    200     i = 0;
    201     do
    202     {
    203         if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
    204                                       lpAccelTbl[i].key,lpAccelTbl[i].cmd))
    205         {
    206             return 1;
    207         }
    208     }
    209     while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
    210 
    211 //    WARN_(accel)("couldn't translate accelerator key\n");
    212     return 0;
    213 }
    21425/**********************************************************************
    21526 *                      LoadAccelerators32W     [USER.177]
  • trunk/src/user32/windowmsg.cpp

    r10185 r10190  
    1 /* $Id: windowmsg.cpp,v 1.43 2003-07-28 11:27:50 sandervl Exp $ */
     1/* $Id: windowmsg.cpp,v 1.44 2003-07-31 15:56:47 sandervl Exp $ */
    22/*
    33 * Win32 window message APIs for OS/2
     
    8686                return 0; /* invalid winproc */
    8787
    88             return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
     88            return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
    8989                                   msg->message, msg->wParam, GetTickCount() );
    9090        }
     
    319319    {
    320320    case WM_GETTEXT:
     321    case WM_ASKCBFORMATNAME:
    321322        {
    322323            LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
     
    330331    case WM_SETTEXT:
    331332    case WM_WININICHANGE:
     333    case WM_DEVMODECHANGE:
    332334    case CB_DIR:
    333335    case LB_DIR:
     
    431433        return 1;
    432434
    433     /* kso 2003-07-03: to make password field work, I took this from latest wine code. (winproc.c) */
     435    case WM_CHARTOITEM:
     436    case WM_MENUCHAR:
     437    case WM_CHAR:
     438    case WM_DEADCHAR:
     439    case WM_SYSCHAR:
     440    case WM_SYSDEADCHAR:
    434441    case EM_SETPASSWORDCHAR:
    435442        {
    436             BYTE    ch = LOWORD(*pwparam);
    437             WCHAR   wch = 0;
    438             MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&ch, 1, &wch, 1);
     443            char ch = LOWORD(*pwparam);
     444            WCHAR wch;
     445            MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
    439446            *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
    440447        }
    441448        return 0;
    442449
    443     case WM_ASKCBFORMATNAME:
    444     case WM_DEVMODECHANGE:
    445450    case WM_PAINTCLIPBOARD:
    446451    case WM_SIZECLIPBOARD:
     
    463468    {
    464469    case WM_GETTEXT:
     470    case WM_ASKCBFORMATNAME:
    465471        {
    466472            LPARAM *ptr = (LPARAM *)lParam - 1;
     
    495501    case WM_SETTEXT:
    496502    case WM_WININICHANGE:
     503    case WM_DEVMODECHANGE:
    497504    case CB_DIR:
    498505    case LB_DIR:
     
    569576 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
    570577 */
    571 INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM *plparam)
     578INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam)
    572579{   switch(msg)
    573580    {
    574581    case WM_GETTEXT:
    575         {
     582    case WM_ASKCBFORMATNAME:
     583        {
     584#ifdef __WIN32OS2__
     585            *pwparam = *pwparam * sizeof( WCHAR );  //DBCS
     586#endif
    576587            LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
    577                                                wParam + sizeof(LPARAM) );
     588                                               *pwparam + sizeof(LPARAM) );
    578589            if (!ptr) return -1;
    579590            *ptr++ = *plparam;  /* Store previous lParam */
     
    584595    case WM_SETTEXT:
    585596    case WM_WININICHANGE:
     597    case WM_DEVMODECHANGE:
    586598    case CB_DIR:
    587599    case LB_DIR:
     
    681693          if (!ptr) return -1;
    682694          *ptr++ = *plparam;  /* Store previous lParam */
     695#ifdef __WIN32OS2__
     696          *((WORD *) ptr) = len * sizeof(WCHAR);   /* Store the length */
     697#else
    683698          *((WORD *) ptr) = len;   /* Store the length */
     699#endif
    684700          *plparam = (LPARAM)ptr;
    685701        }
    686702        return 1;
    687703
    688     case WM_ASKCBFORMATNAME:
    689     case WM_DEVMODECHANGE:
     704    case WM_CHARTOITEM:
     705    case WM_MENUCHAR:
     706    case WM_CHAR:
     707    case WM_DEADCHAR:
     708    case WM_SYSCHAR:
     709    case WM_SYSDEADCHAR:
     710    case EM_SETPASSWORDCHAR:
     711        {
     712            WCHAR wch = LOWORD(*pwparam);
     713            char ch;
     714            WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
     715            *pwparam = MAKEWPARAM( ch, HIWORD(*pwparam) );
     716        }
     717        return 0;
     718
    690719    case WM_PAINTCLIPBOARD:
    691720    case WM_SIZECLIPBOARD:
    692     case EM_SETPASSWORDCHAR:
    693721        // FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg),msg );
    694722        return -1;
     
    709737    {
    710738    case WM_GETTEXT:
     739    case WM_ASKCBFORMATNAME:
    711740        {
    712741            LPARAM *ptr = (LPARAM *)lParam - 1;
     742
     743#ifdef __WIN32OS2__
     744            wParam = wParam / sizeof( WCHAR );
     745#endif
    713746            lstrcpynAtoW( (LPWSTR)*ptr, (LPSTR)lParam, wParam );
    714747            HeapFree( GetProcessHeap(), 0, ptr );
     
    718751    case WM_SETTEXT:
    719752    case WM_WININICHANGE:
     753    case WM_DEVMODECHANGE:
    720754    case CB_DIR:
    721755    case LB_DIR:
     
    800834    case EM_GETLINE:
    801835        { LPARAM * ptr = (LPARAM *)lParam - 1;  /* get the old lparam */
     836#ifdef __WIN32OS2__
     837          WORD len = *(WORD *)ptr/sizeof(WCHAR);
     838#else
    802839          WORD len = *(WORD *)ptr;
     840#endif
    803841          lstrcpynAtoW( (LPWSTR) *ptr, (LPSTR)lParam, len );
    804842          HeapFree( GetProcessHeap(), 0, ptr );
     
    819857    LRESULT result;
    820858
     859#ifdef __WIN32OS2__
     860    if( IsDBCSEnv() && msg == WM_CHAR )
     861    {
     862        static BYTE dbcsLead = 0;
     863        WCHAR charA = wParam;
     864        int size = dbcsLead ? 2 : 1;
     865
     866        if( dbcsLead )
     867               charA = ( charA << 8 ) | dbcsLead;
     868        else if( IsDBCSLeadByte( wParam ))
     869        {
     870            dbcsLead = wParam;
     871            return 0;
     872        }
     873        MultiByteToWideChar( CP_ACP, 0, ( LPSTR )&charA, size, ( LPWSTR )&wParam, 1 );
     874
     875        dbcsLead = 0;
     876    }
     877    else
     878#endif
    821879    if (WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam ) == -1) return 0;
     880
    822881    result = func( hwnd, msg, wParam, lParam );
    823882    WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
     883
     884#ifdef __WIN32OS2__
     885    if(IsDBCSEnv())
     886    {
     887      switch( msg )
     888      {
     889        case WM_GETTEXTLENGTH :
     890        {
     891            LPWSTR ustr = ( LPWSTR )HeapAlloc( GetProcessHeap(), 0, ( result + 1 ) * sizeof( WCHAR ));
     892            result = func( hwnd, WM_GETTEXT, ( WPARAM )( result + 1 ), ( LPARAM )ustr );
     893            result = lstrlenWtoA( ustr, result );
     894            HeapFree( GetProcessHeap(), 0, ustr );
     895            break;
     896        }
     897
     898        case LB_GETTEXTLEN :
     899        {
     900            LPWSTR ustr = ( LPWSTR )HeapAlloc( GetProcessHeap(), 0, ( result + 1 ) * sizeof( WCHAR ));
     901            result = func( hwnd, LB_GETTEXT, wParam, ( LPARAM )ustr );
     902            if( result != LB_ERR )
     903                result = lstrlenWtoA( ustr, result );
     904
     905            HeapFree( GetProcessHeap(), 0, ustr );
     906            break;
     907        }
     908
     909
     910        case CB_GETLBTEXTLEN :
     911        {
     912            LPWSTR ustr = ( LPWSTR )HeapAlloc( GetProcessHeap(), 0, ( result + 1 ) * sizeof( WCHAR ));
     913            result = func( hwnd, CB_GETLBTEXT, wParam, ( LPARAM )ustr );
     914            if( result != CB_ERR )
     915                result = lstrlenWtoA( ustr, result );
     916
     917            HeapFree( GetProcessHeap(), 0, ustr );
     918            break;
     919        }
     920      }
     921    }
     922#endif
    824923    return result;
    825924}
     
    836935    LRESULT result;
    837936
    838     if (WINPROC_MapMsg32WTo32A( hwnd, msg, wParam, &lParam ) == -1) return 0;
     937#ifdef __WIN32OS2__
     938    if( IsDBCSEnv() && msg == WM_CHAR )
     939    {
     940        char charA[ 2 ];
     941
     942        if( WideCharToMultiByte( CP_ACP, 0, ( LPWSTR )&wParam, 1, ( LPSTR )charA, 2, 0, 0 ) > 1 )
     943        {
     944            func( hwnd, msg, ( WPARAM )charA[ 0 ], lParam );
     945            wParam = charA[ 1 ];
     946        }
     947        else
     948            wParam = charA[ 0 ];
     949    }
     950    else
     951#endif
     952    if (WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam ) == -1) return 0;
    839953
    840954    result = func( hwnd, msg, wParam, lParam );
    841955    WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
     956
     957#ifdef __WIN32OS2__
     958    if( IsDBCSEnv() )
     959    {
     960      switch( msg )
     961      {
     962        case WM_GETTEXTLENGTH :
     963        {
     964            LPSTR astr = ( LPSTR )HeapAlloc( GetProcessHeap(), 0, result + 1 );
     965            result = func( hwnd, WM_GETTEXT, ( WPARAM )( result + 1 ), ( LPARAM )astr );
     966            result = lstrlenAtoW( astr, result );
     967            HeapFree( GetProcessHeap(), 0, astr );
     968            break;
     969        }
     970
     971        case LB_GETTEXTLEN :
     972        {
     973            LPSTR astr = ( LPSTR )HeapAlloc( GetProcessHeap(), 0, result + 1 );
     974            result = func( hwnd, LB_GETTEXT, wParam, ( LPARAM )astr );
     975            if( result != LB_ERR )
     976                result = lstrlenAtoW( astr, result );
     977
     978            HeapFree( GetProcessHeap(), 0, astr );
     979            break;
     980        }
     981
     982
     983        case CB_GETLBTEXTLEN :
     984        {
     985            LPSTR astr = ( LPSTR )HeapAlloc( GetProcessHeap(), 0, result + 1 );
     986            result = func( hwnd, CB_GETLBTEXT, wParam, ( LPARAM )astr );
     987            if( result != CB_ERR )
     988                result = lstrlenAtoW( astr, result );
     989
     990            HeapFree( GetProcessHeap(), 0, astr );
     991            break;
     992        }
     993      }
     994    }
     995#endif
    842996    return result;
    843997}
  • trunk/src/user32/winkeyboard.cpp

    r9974 r10190  
    1 /* $Id: winkeyboard.cpp,v 1.42 2003-04-02 12:58:02 sandervl Exp $ */
     1/* $Id: winkeyboard.cpp,v 1.43 2003-07-31 15:56:48 sandervl Exp $ */
    22/*
    33 * Win32 <-> PM key translation
     
    10561056BOOL WIN32API SetKeyboardState(PBYTE lpKeyState)
    10571057{
    1058   dprintf(("USER32: SetKeyboardState %x not implemented", lpKeyState));
    1059   return(TRUE);
     1058   dprintf(("USER32: SetKeyboardState %x not implemented", lpKeyState));
     1059
     1060   return(TRUE);
    10601061}
    10611062/***********************************************************************
     
    12041205       if(lpbKeyState[VK_LSHIFT]   & 0x80) shiftstate |= TCF_LSHIFT;
    12051206       if(lpbKeyState[VK_RSHIFT]   & 0x80) shiftstate |= TCF_RSHIFT;
     1207       else
     1208       if(lpbKeyState[VK_SHIFT]    & 0x80) shiftstate |= TCF_LSHIFT;
     1209
    12061210       if(lpbKeyState[VK_LCONTROL] & 0x80) shiftstate |= TCF_LCONTROL;
    12071211       if(lpbKeyState[VK_RCONTROL] & 0x80) shiftstate |= TCF_RCONTROL;
     1212       else
     1213       if(lpbKeyState[VK_CONTROL]  & 0x80) shiftstate |= TCF_LCONTROL;
     1214
    12081215       if(lpbKeyState[VK_LMENU]    & 0x80) shiftstate |= TCF_ALT;
    12091216       if(lpbKeyState[VK_RMENU]    & 0x80) shiftstate |= TCF_ALTGR;
     1217       else
     1218       if(lpbKeyState[VK_MENU]     & 0x80) shiftstate |= TCF_ALT;
     1219
    12101220       if(lpbKeyState[VK_CAPITAL]  & 1)    shiftstate |= TCF_CAPSLOCK;
    12111221       if(lpbKeyState[VK_NUMLOCK]  & 1)    shiftstate |= TCF_NUMLOCK;
     
    16151625    break;
    16161626
     1627    case 0:
     1628    {
     1629      UINT ret;
     1630      if( uCode >= VK_A && uCode <= VK_Z) {
     1631           ret = OSLibWinTranslateChar('A' + uCode - VK_A, TC_CHARTOSCANCODE, 0); 
     1632           dprintf(("MapVirtualKeyA %x (%c) -> %x", uCode, 'A' + uCode - VK_A, ret));
     1633           return ret;
     1634      }
     1635      else
     1636      if( uCode >= VK_0 && uCode <= VK_0) {
     1637           ret = OSLibWinTranslateChar('0' + uCode - VK_0, TC_CHARTOSCANCODE, 0); 
     1638           dprintf(("MapVirtualKeyA %x (%c) -> %x", uCode, '0' + uCode - VK_0, ret));
     1639           return ret;
     1640      }
     1641      break;
     1642    }
     1643
    16171644    case 1:
    16181645    case 3:
Note: See TracChangeset for help on using the changeset viewer.