Ignore:
Timestamp:
Aug 6, 2000, 11:33:11 AM (25 years ago)
Author:
sandervl
Message:

PD: Updated comctl32/toolbar to Wine 20000801

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comctl32/toolbar.cpp

    r3585 r3956  
    1 /* $Id: toolbar.cpp,v 1.6 2000-05-22 17:25:12 cbratschi Exp $ */
    21/*
    32 * Toolbar control
     
    109 *   - A little bug in TOOLBAR_DrawMasked()
    1110 *   - Button wrapping (under construction).
    12  *   - Messages (under construction).
    13  *   - Notifications.
     11 *   - Messages.
     12 *   - Notifications (under construction).
    1413 *   - Fix TB_SETROWS.
    1514 *   - Tooltip support (almost complete).
    16  *   - Unicode support (under construction).
     15 *   - Unicode suppport (under construction).
    1716 *   - Fix TOOLBAR_SetButtonInfo32A/W.
    18  *   - Drag & drop of buttons
     17 *   - Customize dialog (under construction).
     18 *   - TBSTYLE_AUTOSIZE for toolbar and buttons.
     19 *   - I_IMAGECALLBACK support.
    1920 *
    2021 * Testing:
     
    2930
    3031/*
    31  - Corel 20000513 level
    32  - (WINE 991212 level)
     32 - (WINE 20000608 level)
    3333*/
     34
    3435
    3536#include <string.h>
     
    4647#define BOTTOM_BORDER      2
    4748
    48 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO*)getInfoPtr(hwnd))
     49#define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
     50
     51static BOOL
     52TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
     53{
     54    if ((index>=0) && (index < infoPtr->nNumBitmaps))
     55      return TRUE;
     56    else
     57      return FALSE;
     58}
    4959
    5060
     
    6575}
    6676
    67 
     77/*
     78 * Draw the text string for this button.
     79 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
     80 *      is non-zero, so we can simply check himlDef to see if we have
     81 *      an image list
     82 */
    6883static void
    6984TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
    70                     HDC hdc, INT nState, DWORD dwStyle)
     85                    HDC hdc, INT nState, DWORD dwStyle)
    7186{
    7287    RECT   rcText = btnPtr->rect;
     
    7489    INT    nOldBkMode;
    7590    COLORREF clrOld;
     91    LPWSTR lpText = NULL;
     92    HIMAGELIST himl = infoPtr->himlDef;
     93
     94    // TRACE ("iString: %x\n", btnPtr->iString);
     95
     96    /* get a pointer to the text */
     97    if (btnPtr->iString == -1)
     98        dprintf(("TOOLBAR_DrawString: Undocumented Index -1\n"));
     99    else if (HIWORD(btnPtr->iString) != 0)
     100        lpText = (LPWSTR)btnPtr->iString;
     101    else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
     102        lpText = infoPtr->strings[btnPtr->iString];
     103
     104    // TRACE ("lpText: \"%s\"\n", debugstr_w(lpText));
    76105
    77106    /* draw text */
    78     if ((btnPtr->iString > -1) && (btnPtr->iString < infoPtr->nNumStrings)) {
    79         InflateRect (&rcText, -3, -3);
    80         if (dwStyle & TBSTYLE_LIST) {
    81           rcText.left += infoPtr->nBitmapWidth;
    82         }
    83         else {
    84           rcText.top += infoPtr->nBitmapHeight;
    85         }
    86         if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
    87             OffsetRect (&rcText, 1, 1);
    88 
    89         hOldFont = SelectObject (hdc, infoPtr->hFont);
    90         nOldBkMode = SetBkMode (hdc, TRANSPARENT);
    91         if (!(nState & TBSTATE_ENABLED)) {
    92             clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
    93             OffsetRect (&rcText, 1, 1);
    94             DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
    95                          &rcText, infoPtr->dwDTFlags);
    96             SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
    97             OffsetRect (&rcText, -1, -1);
    98             DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
    99                          &rcText, infoPtr->dwDTFlags);
    100         }
    101         else if (nState & TBSTATE_INDETERMINATE) {
    102             clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
    103             DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
    104                          &rcText, infoPtr->dwDTFlags);
    105         }
    106         else {
    107             clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
    108             DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
    109                          &rcText, infoPtr->dwDTFlags);
    110         }
    111 
    112         SetTextColor (hdc, clrOld);
    113         SelectObject (hdc, hOldFont);
    114         if (nOldBkMode != TRANSPARENT)
    115             SetBkMode (hdc, nOldBkMode);
     107    if (lpText) {
     108
     109        InflateRect (&rcText, -3, -3);
     110
     111        if (himl && TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
     112                if ((dwStyle & TBSTYLE_LIST) &&
     113                    ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
     114                    (btnPtr->iBitmap != I_IMAGENONE)) {
     115                    rcText.left += infoPtr->nBitmapWidth;
     116                }
     117                else {
     118                    rcText.top += infoPtr->nBitmapHeight;
     119                }
     120        }
     121
     122        if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
     123            OffsetRect (&rcText, 1, 1);
     124
     125        hOldFont = SelectObject (hdc, infoPtr->hFont);
     126        nOldBkMode = SetBkMode (hdc, TRANSPARENT);
     127        if (!(nState & TBSTATE_ENABLED)) {
     128            clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
     129            OffsetRect (&rcText, 1, 1);
     130            DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
     131            SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
     132            OffsetRect (&rcText, -1, -1);
     133            DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
     134        }
     135        else if (nState & TBSTATE_INDETERMINATE) {
     136            clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
     137            DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
     138        }
     139        else {
     140            clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
     141            DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
     142        }
     143
     144        SetTextColor (hdc, clrOld);
     145        SelectObject (hdc, hOldFont);
     146        if (nOldBkMode != TRANSPARENT)
     147            SetBkMode (hdc, nOldBkMode);
    116148    }
    117149}
     
    131163static void
    132164TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
    133                     HDC hdc, INT x, INT y)
     165                    HDC hdc, INT x, INT y)
    134166{
    135167    /* FIXME: this function is a hack since it uses image list
    136               internals directly */
     168              internals directly */
    137169
    138170    HIMAGELIST himl = infoPtr->himlDef;
     
    142174
    143175    if (!himl)
    144         return;
     176        return;
    145177
    146178    /* create new dc's */
     
    157189    SetTextColor (hdcImageList, RGB(0, 0, 0));
    158190    BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
    159               hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
     191              hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
    160192
    161193#if 0
     
    164196    SetBkColor (hdcImageList, RGB(0, 0, 0));
    165197    BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
    166               hdcImageList, himl->cx * btnPtr->iBitmap, 0, MERGEPAINT);
     198              hdcImageList, himl->cx * btnPtr->iBitmap, 0, MERGEPAINT);
    167199#endif
    168200
     
    170202    SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
    171203    BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
    172               hdcMask, 0, 0, 0xB8074A);
     204              hdcMask, 0, 0, 0xB8074A);
    173205
    174206    SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
    175207    BitBlt (hdc, x, y, himl->cx, himl->cy,
    176               hdcMask, 0, 0, 0xB8074A);
     208              hdcMask, 0, 0, 0xB8074A);
    177209
    178210    DeleteObject (hbmMask);
     
    189221    RECT rc;
    190222
    191     if (btnPtr->fsState & TBSTATE_HIDDEN) return;
     223    if (btnPtr->fsState & TBSTATE_HIDDEN)
     224        return;
    192225
    193226    rc = btnPtr->rect;
    194227
     228    // TRACE("iBitmap: %d\n", btnPtr->iBitmap);
     229
    195230    /* separator */
    196     if (btnPtr->fsStyle & TBSTYLE_SEP)
    197     {
    198       if ((dwStyle & TBSTYLE_FLAT) && (btnPtr->iBitmap == 0))
    199           TOOLBAR_DrawFlatSeparator (&rc, hdc);
    200       return;
     231    if (btnPtr->fsStyle & TBSTYLE_SEP) {
     232        /* with the FLAT style, iBitmap is the width and has already */
     233        /* been taken into consideration in calculating the width    */
     234        /* so now we need to draw the vertical separator             */
     235        /* empirical tests show that iBitmap can/will be non-zero    */
     236        /* when drawing the vertical bar...      */
     237        if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */)
     238            TOOLBAR_DrawFlatSeparator (&rc, hdc);
     239        return;
    201240    }
    202241
    203242    /* disabled */
    204     if (!(btnPtr->fsState & TBSTATE_ENABLED))
    205     {
    206       if (!(dwStyle & TBSTYLE_FLAT))
    207         DrawEdge (hdc, &rc, EDGE_RAISED,
    208                   BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    209 
    210       if (infoPtr->himlDis)
    211         ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
    212                        rc.left+1, rc.top+1, ILD_NORMAL);
    213       else
    214         TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
    215 
    216       TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    217       return;
     243    if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
     244        if (!(dwStyle & TBSTYLE_FLAT))
     245            DrawEdge (hdc, &rc, EDGE_RAISED,
     246                      BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
     247       
     248        if (infoPtr->himlDis &&
     249            TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
     250            ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
     251                                rc.left+1, rc.top+1, ILD_NORMAL);
     252        else
     253            TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
     254
     255        TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
     256        return;
    218257    }
    219258
    220259    /* pressed TBSTYLE_BUTTON */
    221     if (btnPtr->fsState & TBSTATE_PRESSED)
    222     {
    223       if (dwStyle & TBSTYLE_FLAT)
    224         DrawEdge(hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE | BF_ADJUST);
    225       else
    226         DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
    227       ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
    228                       rc.left+2, rc.top+2, ILD_NORMAL);
    229       TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    230       return;
    231     }
    232 
    233     /* checked TBSTYLE_CHECK*/
     260    if (btnPtr->fsState & TBSTATE_PRESSED) {
     261        if (dwStyle & TBSTYLE_FLAT)
     262            DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE | BF_ADJUST);
     263        else
     264            DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
     265        if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
     266            ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
     267                        rc.left+2, rc.top+2, ILD_NORMAL);
     268        TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
     269        return;
     270    }
     271
     272    /* checked TBSTYLE_CHECK */
    234273    if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
    235         (btnPtr->fsState & TBSTATE_CHECKED)) {
    236         if (dwStyle & TBSTYLE_FLAT)
    237             DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
    238                         BF_RECT | BF_MIDDLE | BF_ADJUST);
    239         else
    240             DrawEdge (hdc, &rc, EDGE_SUNKEN,
    241                         BF_RECT | BF_MIDDLE | BF_ADJUST);
    242 
    243         TOOLBAR_DrawPattern (hdc, &rc);
    244 
    245         ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
    246                         rc.left+2, rc.top+2, ILD_NORMAL);
    247 
    248         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    249         return;
    250     }
    251 
    252     /* indeterminate */
    253     if (btnPtr->fsState & TBSTATE_INDETERMINATE)
    254     {
    255       DrawEdge (hdc, &rc, EDGE_RAISED,
    256                   BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    257 
    258       TOOLBAR_DrawPattern (hdc, &rc);
    259       TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
    260       TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    261       return;
     274        (btnPtr->fsState & TBSTATE_CHECKED)) {
     275        if (dwStyle & TBSTYLE_FLAT)
     276            DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
     277                        BF_RECT | BF_MIDDLE | BF_ADJUST);
     278        else
     279            DrawEdge (hdc, &rc, EDGE_SUNKEN,
     280                        BF_RECT | BF_MIDDLE | BF_ADJUST);
     281
     282        TOOLBAR_DrawPattern (hdc, &rc);
     283       
     284        if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
     285            ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
     286                        rc.left+2, rc.top+2, ILD_NORMAL);
     287
     288        TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
     289        return;
     290    }
     291
     292    /* indeterminate */
     293    if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
     294        DrawEdge (hdc, &rc, EDGE_RAISED,
     295                    BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
     296
     297        TOOLBAR_DrawPattern (hdc, &rc);
     298        TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
     299        TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
     300        return;
    262301    }
    263302
     
    265304    if (dwStyle & TBSTYLE_FLAT)
    266305    {
    267       if(btnPtr->bHot)
    268           DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
    269 
    270       if(btnPtr->bHot && infoPtr->himlHot)
    271           ImageList_Draw (infoPtr->himlHot, btnPtr->iBitmap, hdc,
    272                           rc.left +2, rc.top +2, ILD_NORMAL);
    273       else
    274           ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
    275                           rc.left +2, rc.top +2, ILD_NORMAL);
    276     } else
     306        if (btnPtr->bHot)
     307            DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
     308        if (btnPtr->bHot && infoPtr->himlHot &&
     309            TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
     310            ImageList_Draw (infoPtr->himlHot, btnPtr->iBitmap, hdc,
     311                            rc.left +2, rc.top +2, ILD_NORMAL);
     312        else if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
     313            ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
     314                            rc.left +2, rc.top +2, ILD_NORMAL);
     315    }
     316    else
    277317    {
    278       DrawEdge (hdc, &rc, EDGE_RAISED,
    279                 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    280 
    281       ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
    282                       rc.left+1, rc.top+1, ILD_NORMAL);
     318        DrawEdge (hdc, &rc, EDGE_RAISED,
     319                BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
     320
     321        if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
     322            ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
     323                        rc.left+1, rc.top+1, ILD_NORMAL);
    283324    }
    284325
     
    288329
    289330static void
    290 TOOLBAR_Refresh (HWND hwnd, HDC hdc)
     331TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
    291332{
    292333    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    293334    TBUTTON_INFO *btnPtr;
    294335    INT i;
    295 
    296     /* draw buttons */
     336    RECT rcTemp;
     337
     338    /* redraw necessary buttons */
    297339    btnPtr = infoPtr->buttons;
    298340    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
    299         TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    300 }
    301 
     341    {
     342        if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
     343            TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
     344    }
     345}
    302346
    303347static void
    304 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
     348TOOLBAR_MeasureString(HWND hwnd, INT index, LPSIZE lpSize)
    305349{
    306350    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    307351    TBUTTON_INFO *btnPtr;
    308     INT i;
    309352    HDC hdc;
    310353    HFONT hOldFont;
    311     SIZE sz;
    312354
    313355    lpSize->cx = 0;
     
    316358    hOldFont = SelectObject (hdc, infoPtr->hFont);
    317359
     360    btnPtr = &infoPtr->buttons[index];
     361
     362    if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
     363         (btnPtr->iString > -1) &&
     364         (btnPtr->iString < infoPtr->nNumStrings))
     365    {
     366        LPWSTR lpText = infoPtr->strings[btnPtr->iString];
     367        GetTextExtentPoint32W (hdc, lpText, lstrlenW (lpText), lpSize);
     368    }
     369
     370    SelectObject (hdc, hOldFont);
     371    ReleaseDC (0, hdc);
     372
     373    // TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
     374}
     375
     376static void
     377TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
     378{
     379    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     380    TBUTTON_INFO *btnPtr;
     381    INT i;
     382    SIZE sz;
     383
     384
     385    lpSize->cx = 0;
     386    lpSize->cy = 0;
     387
    318388    btnPtr = infoPtr->buttons;
    319389    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
    320         if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
    321             (btnPtr->iString > -1) &&
    322             (btnPtr->iString < infoPtr->nNumStrings)) {
    323             LPWSTR lpText = infoPtr->strings[btnPtr->iString];
    324             GetTextExtentPoint32W (hdc, lpText, lstrlenW (lpText), &sz);
    325             if (sz.cx > lpSize->cx)
    326                 lpSize->cx = sz.cx;
    327             if (sz.cy > lpSize->cy)
    328                 lpSize->cy = sz.cy;
    329         }
    330     }
    331 
    332     SelectObject (hdc, hOldFont);
    333     ReleaseDC (0, hdc);
    334 
    335 //    TRACE (toolbar, "string size %d x %d!\n", lpSize->cx, lpSize->cy);
     390        TOOLBAR_MeasureString(hwnd,i,&sz);
     391        if (sz.cx > lpSize->cx)
     392            lpSize->cx = sz.cx;
     393        if (sz.cy > lpSize->cy)
     394            lpSize->cy = sz.cy;
     395    }
     396
     397    // TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
    336398}
    337399
    338400/***********************************************************************
    339 *               TOOLBAR_WrapToolbar
     401*               TOOLBAR_WrapToolbar
    340402*
    341 * This function walks through the buttons and seperators in the
    342 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
    343 * wrapping should occur based on the width of the toolbar window.
    344 * It does *not* calculate button placement itself.  That task
    345 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
    346 * the toolbar wrapping on it's own, it can use the TBSTYLE_WRAPPABLE
     403* This function walks through the buttons and seperators in the 
     404* toolbar, and sets the TBSTATE_WRAP flag only on those items where 
     405* wrapping should occur based on the width of the toolbar window. 
     406* It does *not* calculate button placement itself.  That task 
     407* takes place in TOOLBAR_CalcToolbar. If the program wants to manage 
     408* the toolbar wrapping on it's own, it can use the TBSTYLE_WRAPPABLE 
    347409* flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
    348 */
     410*/ 
    349411
    350412static void
     
    357419    BOOL bWrap, bButtonWrap;
    358420
    359     /*  When the toolbar window style is not TBSTYLE_WRAPABLE,  */
    360     /*  no layout is necessary. Applications may use this style */
    361     /*  to perform their own layout on the toolbar.             */
     421    /*  When the toolbar window style is not TBSTYLE_WRAPABLE,  */
     422    /*  no layout is necessary. Applications may use this style */
     423    /*  to perform their own layout on the toolbar.             */
    362424    if( !(dwStyle & TBSTYLE_WRAPABLE) )
    363         return;
     425        return;
    364426
    365427    btnPtr = infoPtr->buttons;
    366428    x  = infoPtr->nIndent;
    367429
     430    /* this can get the parents width, to know how far we can extend
     431     * this toolbar.  We cannot use its height, as there may be multiple
     432     * toolbars in a rebar control
     433     */
    368434    GetClientRect( GetParent(hwnd), &rc );
    369435    infoPtr->nWidth = rc.right - rc.left;
     
    372438    for (i = 0; i < infoPtr->nNumButtons; i++ )
    373439    {
    374         bWrap = FALSE;
    375         btnPtr[i].fsState &= ~TBSTATE_WRAP;
    376 
    377         if (btnPtr[i].fsState & TBSTATE_HIDDEN)
    378             continue;
    379 
    380         /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
    381         /* it is the actual width of the separator. This is used for */
    382         /* custom controls in toolbars.                              */
    383         if (btnPtr[i].fsStyle & TBSTYLE_SEP)
    384             cx = (btnPtr[i].iBitmap > 0) ?
    385                         btnPtr[i].iBitmap : SEPARATOR_WIDTH;
    386         else
    387             cx = infoPtr->nButtonWidth;
    388 
    389         /* Two or more adjacent separators form a separator group.   */
    390         /* The first separator in a group should be wrapped to the   */
    391         /* next row if the previous wrapping is on a button.         */
    392         if( bButtonWrap &&
    393                 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
    394                 (i + 1 < infoPtr->nNumButtons ) &&
    395                 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
    396         {
    397             btnPtr[i].fsState |= TBSTATE_WRAP;
    398             x = infoPtr->nIndent;
    399             i++;
    400             bButtonWrap = FALSE;
    401             continue;
    402         }
    403 
    404         /* The layout makes sure the bitmap is visible, but not the button. */
    405         if ( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
    406                  > infoPtr->nWidth )
    407         {
    408             BOOL bFound = FALSE;
    409 
    410             /*  If the current button is a separator and not hidden,  */
    411             /*  go to the next until it reaches a non separator.      */
    412             /*  Wrap the last separator if it is before a button.     */
    413             while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
    414                         (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
    415                         i < infoPtr->nNumButtons )
    416             {
    417                 i++;
    418                 bFound = TRUE;
    419             }
    420 
    421             if( bFound && i < infoPtr->nNumButtons )
    422             {
    423                 i--;
    424                 btnPtr[i].fsState |= TBSTATE_WRAP;
    425                 x = infoPtr->nIndent;
    426                 bButtonWrap = FALSE;
    427                 continue;
    428             }
    429             else if ( i >= infoPtr->nNumButtons)
    430                 break;
    431 
    432             /*  If the current button is not a separator, find the last  */
    433             /*  separator and wrap it.                                  */
    434             for ( j = i - 1; j >= 0  &&  !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
    435             {
    436                 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
    437                         !(btnPtr[j].fsState & TBSTATE_HIDDEN))
    438                 {
    439                     bFound = TRUE;
    440                     i = j;
    441                     x = infoPtr->nIndent;
    442                     btnPtr[j].fsState |= TBSTATE_WRAP;
    443                     bButtonWrap = FALSE;
    444                     break;
    445                 }
    446             }
    447 
    448             /*  If no separator available for wrapping, wrap one of     */
    449             /*  non-hidden previous button.                             */
    450             if (!bFound)
    451             {
    452                 for ( j = i - 1;
    453                         j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
    454                 {
    455                     if (btnPtr[j].fsState & TBSTATE_HIDDEN)
    456                         continue;
    457 
    458                     bFound = TRUE;
    459                     i = j;
    460                     x = infoPtr->nIndent;
    461                     btnPtr[j].fsState |= TBSTATE_WRAP;
    462                     bButtonWrap = TRUE;
    463                     break;
    464                 }
    465             }
    466 
    467             /* If all above failed, wrap the current button. */
    468             if (!bFound)
    469             {
    470                 btnPtr[i].fsState |= TBSTATE_WRAP;
    471                 bFound = TRUE;
    472                 x = infoPtr->nIndent;
    473                 if (btnPtr[i].fsState & TBSTYLE_SEP )
    474                     bButtonWrap = FALSE;
    475                 else
    476                     bButtonWrap = TRUE;
    477             }
    478         }
    479         else
    480             x += cx;
    481     }
    482 }
    483 
     440        bWrap = FALSE;
     441        btnPtr[i].fsState &= ~TBSTATE_WRAP;
     442       
     443        if (btnPtr[i].fsState & TBSTATE_HIDDEN)
     444            continue;
     445
     446        /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
     447        /* it is the actual width of the separator. This is used for */
     448        /* custom controls in toolbars.                              */
     449        if (btnPtr[i].fsStyle & TBSTYLE_SEP)
     450            cx = (btnPtr[i].iBitmap > 0) ? 
     451                        btnPtr[i].iBitmap : SEPARATOR_WIDTH;
     452        else
     453            cx = infoPtr->nButtonWidth;
     454
     455        /* Two or more adjacent separators form a separator group.   */
     456        /* The first separator in a group should be wrapped to the   */
     457        /* next row if the previous wrapping is on a button.         */
     458        if( bButtonWrap &&
     459                (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
     460                (i + 1 < infoPtr->nNumButtons ) &&
     461                (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
     462        {
     463            btnPtr[i].fsState |= TBSTATE_WRAP;
     464            x = infoPtr->nIndent;
     465            i++;
     466            bButtonWrap = FALSE;
     467            continue;
     468        }
     469
     470        /* The layout makes sure the bitmap is visible, but not the button. */
     471        if ( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
     472                 > infoPtr->nWidth )
     473        {
     474            BOOL bFound = FALSE;
     475
     476            /*  If the current button is a separator and not hidden,  */
     477            /*  go to the next until it reaches a non separator.      */
     478            /*  Wrap the last separator if it is before a button.     */
     479            while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
     480                        (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
     481                        i < infoPtr->nNumButtons )
     482            {
     483                i++;
     484                bFound = TRUE;
     485            }
     486   
     487            if( bFound && i < infoPtr->nNumButtons )
     488            {
     489                i--;
     490                btnPtr[i].fsState |= TBSTATE_WRAP;
     491                x = infoPtr->nIndent;
     492                bButtonWrap = FALSE;
     493                continue;
     494            }
     495            else if ( i >= infoPtr->nNumButtons)
     496                break;
     497
     498            /*  If the current button is not a separator, find the last  */
     499            /*  separator and wrap it.                                  */
     500            for ( j = i - 1; j >= 0  &&  !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
     501            {
     502                if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
     503                        !(btnPtr[j].fsState & TBSTATE_HIDDEN))
     504                {
     505                    bFound = TRUE;
     506                    i = j;
     507                    x = infoPtr->nIndent;
     508                    btnPtr[j].fsState |= TBSTATE_WRAP;
     509                    bButtonWrap = FALSE;
     510                    break;
     511                }
     512            }
     513
     514            /*  If no separator available for wrapping, wrap one of     */
     515            /*  non-hidden previous button.                             */
     516            if (!bFound)
     517            {
     518                for ( j = i - 1;
     519                        j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
     520                {
     521                    if (btnPtr[j].fsState & TBSTATE_HIDDEN)
     522                        continue;
     523
     524                    bFound = TRUE;
     525                    i = j;
     526                    x = infoPtr->nIndent;
     527                    btnPtr[j].fsState |= TBSTATE_WRAP;
     528                    bButtonWrap = TRUE;
     529                    break;
     530                }
     531            }
     532
     533            /* If all above failed, wrap the current button. */
     534            if (!bFound) 
     535            {
     536                btnPtr[i].fsState |= TBSTATE_WRAP;
     537                bFound = TRUE;
     538                x = infoPtr->nIndent;
     539                if (btnPtr[i].fsState & TBSTYLE_SEP )
     540                    bButtonWrap = FALSE;
     541                else
     542                    bButtonWrap = TRUE;
     543            }               
     544        }
     545        else
     546            x += cx;
     547    }
     548}
     549                                                                                       
    484550/***********************************************************************
    485 *               TOOLBAR_CalcToolbar
     551*               TOOLBAR_CalcToolbar
    486552*
    487 * This function calculates button and separator placement. It first
    488 * calculates the button sizes, gets the toolbar window width and then
    489 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
     553* This function calculates button and separator placement. It first 
     554* calculates the button sizes, gets the toolbar window width and then 
     555* calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap 
    490556* on. It assigns a new location to each item and sends this location to
    491 * the tooltip window if appropriate. Finally, it updates the rcBound
    492 * rect and calculates the new required toolbar window height.
    493 */
     557* the tooltip window if appropriate. Finally, it updates the rcBound 
     558* rect and calculates the new required toolbar window height. 
     559*/ 
    494560
    495561static void
     
    497563{
    498564    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
    499     DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
     565    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    500566    TBUTTON_INFO *btnPtr;
    501567    INT i, nRows, nSepRows;
    502568    INT x, y, cx, cy;
    503569    SIZE  sizeString;
    504     RECT rc;
    505570    BOOL bWrap;
    506571
     
    508573
    509574    if (dwStyle & TBSTYLE_LIST) {
    510       infoPtr->nButtonHeight = max(infoPtr->nBitmapHeight, sizeString.cy) + 6;
    511       infoPtr->nButtonWidth = infoPtr->nBitmapWidth + sizeString.cx + 6;
     575        infoPtr->nButtonHeight = max(infoPtr->nBitmapHeight, sizeString.cy) + 6;
     576        infoPtr->nButtonWidth = infoPtr->nBitmapWidth + sizeString.cx + 6;
    512577    }
    513578    else {
    514       if (sizeString.cy > 0)
    515           infoPtr->nButtonHeight = sizeString.cy + infoPtr->nBitmapHeight + 6;
    516       else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
    517           infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
    518 
    519       if (sizeString.cx > infoPtr->nBitmapWidth)
    520           infoPtr->nButtonWidth = sizeString.cx + 6;
    521       else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
    522           infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
    523     }
     579    BOOL usesBitmaps = FALSE;
     580    INT i;
     581
     582    for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
     583        if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
     584            usesBitmaps = TRUE;
     585
     586    if (sizeString.cy > 0) {
     587        if (usesBitmaps)
     588          infoPtr->nButtonHeight = sizeString.cy + infoPtr->nBitmapHeight + 6;
     589        else
     590          infoPtr->nButtonHeight = sizeString.cy + 6;
     591    }
     592    else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
     593        infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
     594
     595    if (sizeString.cx > infoPtr->nBitmapWidth)
     596        infoPtr->nButtonWidth = sizeString.cx + 6;
     597    else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
     598        infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
     599    }
     600
     601    if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
     602        infoPtr->nButtonWidth = infoPtr->cxMin;
     603    if ( infoPtr->cxMax >= 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
     604        infoPtr->nButtonWidth = infoPtr->cxMax;
    524605
    525606    TOOLBAR_WrapToolbar( hwnd, dwStyle );
    526607
    527608    x  = infoPtr->nIndent;
    528     y  = (dwStyle & TBSTYLE_FLAT) ? 0: TOP_BORDER;
     609    y  = (dwStyle & TBSTYLE_FLAT) ? 0 : TOP_BORDER;
     610
     611   /*
     612    * We wills et the height below, and we set the width on entry
     613    * so we do not reset them here..
     614    */
     615#if 0
     616    GetClientRect( hwnd, &rc );
     617    /* get initial values for toolbar */
     618    infoPtr->nWidth  = rc.right - rc.left;
     619    infoPtr->nHeight = rc.bottom - rc.top;
     620#endif
     621
     622    /* from above, minimum is a button, and possible text */
    529623    cx = infoPtr->nButtonWidth;
    530     cy = infoPtr->nButtonHeight;
     624    /* cannot use just ButtonHeight, we may have no buttons! */
     625    if (infoPtr->nNumButtons > 0)
     626      infoPtr->nHeight = infoPtr->nButtonHeight;
     627    cy = infoPtr->nHeight;
     628
    531629    nRows = nSepRows = 0;
    532630
     
    537635
    538636    btnPtr = infoPtr->buttons;
    539     GetClientRect( GetParent(hwnd), &rc );
    540     infoPtr->nWidth = rc.right - rc.left;
     637
     638    /* do not base height/width on parent, if the parent is a */
     639    /* rebar control it could have multiple rows of toolbars  */
     640/*    GetClientRect( GetParent(hwnd), &rc ); */
     641/*    cx = rc.right - rc.left; */
     642/*    cy = rc.bottom - rc.top; */
    541643
    542644    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
    543645    {
    544         bWrap = FALSE;
    545         if (btnPtr->fsState & TBSTATE_HIDDEN)
    546         {
    547             SetRectEmpty (&btnPtr->rect);
    548             continue;
    549         }
    550 
    551             /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
    552             /* it is the actual width of the separator. This is used for */
    553             /* custom controls in toolbars.                              */
    554         if (btnPtr->fsStyle & TBSTYLE_SEP)
    555                 cx = (btnPtr->iBitmap > 0) ?
    556                      btnPtr->iBitmap : SEPARATOR_WIDTH;
    557         else
    558             cx = infoPtr->nButtonWidth;
    559 
    560         if (btnPtr->fsState & TBSTATE_WRAP )
    561                     bWrap = TRUE;
    562 
    563         SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
    564 
    565         if (infoPtr->rcBound.left > x)
    566             infoPtr->rcBound.left = x;
    567         if (infoPtr->rcBound.right < x + cx)
    568             infoPtr->rcBound.right = x + cx;
    569         if (infoPtr->rcBound.bottom < y + cy)
    570             infoPtr->rcBound.bottom = y + cy;
    571 
    572         /* Set the toolTip only for non-hidden, non-separator button */
    573         if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP))
    574         {
    575             TTTOOLINFOA ti;
    576 
    577             ZeroMemory (&ti,sizeof(TTTOOLINFOA));
    578             ti.cbSize = sizeof(TTTOOLINFOA);
    579             ti.hwnd = hwnd;
    580             ti.uId = btnPtr->idCommand;
    581             ti.rect = btnPtr->rect;
    582             SendMessageA(infoPtr->hwndToolTip,TTM_NEWTOOLRECTA,0,(LPARAM)&ti);
    583         }
    584 
    585         /* btnPtr->nRow is zero based. The space between the rows is    */
    586         /* also considered as a row.                                    */
    587         btnPtr->nRow = nRows + nSepRows;
    588         if( bWrap )
    589         {
    590             if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
    591             y += cy;
     646        bWrap = FALSE;
     647        if (btnPtr->fsState & TBSTATE_HIDDEN)
     648        {
     649            SetRectEmpty (&btnPtr->rect);
     650            continue;
     651        }
     652
     653            /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
     654            /* it is the actual width of the separator. This is used for */
     655            /* custom controls in toolbars.                              */
     656        if (btnPtr->fsStyle & TBSTYLE_SEP)
     657                cx = (btnPtr->iBitmap > 0) ?
     658                     btnPtr->iBitmap : SEPARATOR_WIDTH;
     659        else {
     660            if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
     661            {
     662              SIZE sz;
     663              TOOLBAR_MeasureString(hwnd,i,&sz);
     664              cx = sz.cx + 6;
     665            }
    592666            else
    593             {
    594                 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
    595                 /* it is the actual width of the separator. This is used for */
    596                 /* custom controls in toolbars.                              */
    597                 y += cy + ( (btnPtr->iBitmap > 0 ) ?
    598                         btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
    599 
    600                 /* nSepRows is used to calculate the extra height follwoing  */
    601                 /* the last row.                                             */
    602                 nSepRows++;
    603             }
    604             x = infoPtr->nIndent;
    605                 nRows++;
    606         }
    607         else
    608             x += cx;
     667              cx = infoPtr->nButtonWidth;
     668        }
     669        cy = infoPtr->nHeight;
     670
     671        if (btnPtr->fsState & TBSTATE_WRAP )
     672                    bWrap = TRUE;
     673
     674        SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
     675
     676        if (infoPtr->rcBound.left > x)
     677            infoPtr->rcBound.left = x;
     678        if (infoPtr->rcBound.right < x + cx)
     679            infoPtr->rcBound.right = x + cx;
     680        if (infoPtr->rcBound.bottom < y + cy)
     681            infoPtr->rcBound.bottom = y + cy;
     682
     683        /* Set the toolTip only for non-hidden, non-separator button */
     684        if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
     685        {
     686            TTTOOLINFOA ti;
     687
     688            ZeroMemory (&ti, sizeof(TTTOOLINFOA));
     689            ti.cbSize = sizeof(TTTOOLINFOA);
     690            ti.hwnd = hwnd;
     691            ti.uId = btnPtr->idCommand;
     692            ti.rect = btnPtr->rect;
     693            SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
     694                            0, (LPARAM)&ti);
     695        }
     696
     697        /* btnPtr->nRow is zero based. The space between the rows is    */
     698        /* also considered as a row.                                    */
     699        btnPtr->nRow = nRows + nSepRows;
     700        if( bWrap )
     701        {
     702            if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
     703            y += cy;
     704            else
     705            {   
     706                /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
     707                /* it is the actual width of the separator. This is used for */
     708                /* custom controls in toolbars.                              */
     709                y += cy + ( (btnPtr->iBitmap > 0 ) ?
     710                        btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
     711             
     712                /* nSepRows is used to calculate the extra height follwoing  */         
     713                /* the last row.                                             */
     714                nSepRows++;
     715            }
     716            x = infoPtr->nIndent;
     717                nRows++;
     718        }
     719        else
     720            x += cx;
    609721    }
    610722
     
    612724    infoPtr->nRows = nRows + nSepRows + 1;
    613725
    614     /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following   */
    615     /* the last row.                                                    */
    616     infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
    617                         nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
    618                         nSepRows * (infoPtr->nBitmapHeight + 1) +
    619                         BOTTOM_BORDER;
    620 //    TRACE (toolbar, "toolbar height %d\n", infoPtr->nHeight);
     726    /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following   */
     727    /* the last row.                                                    */
     728    infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight + 
     729                        nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
     730                        nSepRows * (infoPtr->nBitmapHeight + 1) +
     731                        BOTTOM_BORDER;
     732    // TRACE("toolbar height %d\n", infoPtr->nHeight);
    621733}
    622734
     
    628740    TBUTTON_INFO *btnPtr;
    629741    INT i;
    630 
     742   
    631743    btnPtr = infoPtr->buttons;
    632744    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
    633         if (btnPtr->fsState & TBSTATE_HIDDEN)
    634             continue;
    635 
    636         if (btnPtr->fsStyle & TBSTYLE_SEP) {
    637             if (PtInRect (&btnPtr->rect, *lpPt)) {
    638 //              TRACE (toolbar, " ON SEPARATOR %d!\n", i);
    639                 return -i;
    640             }
    641         }
    642         else {
    643             if (PtInRect (&btnPtr->rect, *lpPt)) {
    644 //              TRACE (toolbar, " ON BUTTON %d!\n", i);
    645                 return i;
    646             }
    647         }
    648     }
    649 
    650 //    TRACE (toolbar, " NOWHERE!\n");
     745        if (btnPtr->fsState & TBSTATE_HIDDEN)
     746            continue;
     747
     748        if (btnPtr->fsStyle & TBSTYLE_SEP) {
     749            if (PtInRect (&btnPtr->rect, *lpPt)) {
     750                // TRACE(" ON SEPARATOR %d!\n", i);
     751                return -i;
     752            }
     753        }
     754        else {
     755            if (PtInRect (&btnPtr->rect, *lpPt)) {
     756                // TRACE(" ON BUTTON %d!\n", i);
     757                return i;
     758            }
     759        }
     760    }
     761
     762    // TRACE(" NOWHERE!\n");
    651763    return -1;
    652764}
     
    661773    btnPtr = infoPtr->buttons;
    662774    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
    663         if (btnPtr->idCommand == idCommand) {
    664 //          TRACE (toolbar, "command=%d index=%d\n", idCommand, i);
    665             return i;
    666         }
    667     }
    668 //    TRACE (toolbar, "no index found for command=%d\n", idCommand);
     775        if (btnPtr->idCommand == idCommand) {
     776            // TRACE("command=%d index=%d\n", idCommand, i);
     777            return i;
     778        }
     779    }
     780    // TRACE("no index found for command=%d\n", idCommand);
    669781    return -1;
    670782}
     
    678790
    679791    if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
    680         return -1;
     792        return -1;
    681793
    682794    /* check index button */
    683795    btnPtr = &infoPtr->buttons[nIndex];
    684796    if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
    685         if (btnPtr->fsState & TBSTATE_CHECKED)
    686             return nIndex;
     797        if (btnPtr->fsState & TBSTATE_CHECKED)
     798            return nIndex;
    687799    }
    688800
     
    690802    nRunIndex = nIndex - 1;
    691803    while (nRunIndex >= 0) {
    692         btnPtr = &infoPtr->buttons[nRunIndex];
    693         if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
    694             if (btnPtr->fsState & TBSTATE_CHECKED)
    695                 return nRunIndex;
    696         }
    697         else
    698             break;
    699         nRunIndex--;
     804        btnPtr = &infoPtr->buttons[nRunIndex];
     805        if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
     806            if (btnPtr->fsState & TBSTATE_CHECKED)
     807                return nRunIndex;
     808        }
     809        else
     810            break;
     811        nRunIndex--;
    700812    }
    701813
     
    703815    nRunIndex = nIndex + 1;
    704816    while (nRunIndex < infoPtr->nNumButtons) {
    705         btnPtr = &infoPtr->buttons[nRunIndex];
    706         if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
    707             if (btnPtr->fsState & TBSTATE_CHECKED)
    708                 return nRunIndex;
    709         }
    710         else
    711             break;
    712         nRunIndex++;
     817        btnPtr = &infoPtr->buttons[nRunIndex]; 
     818        if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
     819            if (btnPtr->fsState & TBSTATE_CHECKED)
     820                return nRunIndex;
     821        }
     822        else
     823            break;
     824        nRunIndex++;
    713825    }
    714826
     
    719831static VOID
    720832TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
    721                     WPARAM wParam, LPARAM lParam)
     833                    WPARAM wParam, LPARAM lParam)
    722834{
    723835    MSG msg;
     
    727839    msg.wParam = wParam;
    728840    msg.lParam = lParam;
    729     msg.time = GetMessageTime();
    730     msg.pt.x = LOWORD(GetMessagePos());
    731     msg.pt.y = HIWORD(GetMessagePos());
    732 
    733     SendMessageA(hwndTip,TTM_RELAYEVENT,0,(LPARAM)&msg);
    734 }
    735 
    736 static void TBCUSTOMIZE_GetToolName(TOOLBAR_INFO* infoPtr,TBUTTON_INFO* btnPtr,INT pos)
    737 {
    738   if (btnPtr->iString > -1 && btnPtr->iString < infoPtr->nNumStrings)
    739   {
    740     if (!btnPtr->pszName) btnPtr->pszName = (WCHAR*)COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
    741     lstrcpynW(btnPtr->pszName,infoPtr->strings[btnPtr->iString],MAXTOOLNAME*sizeof(WCHAR));
    742 
    743     return;
    744   }
    745 
    746   if (btnPtr->fsStyle & TBSTYLE_SEP)
    747   {
    748     if (!btnPtr->pszName) btnPtr->pszName = (WCHAR*)COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
    749     lstrcpyW(btnPtr->pszName,(WCHAR*)L"Separator");
    750   } else
    751   {
    752     TBNOTIFYW tbNotify;
    753     BOOL unicode = isUnicodeNotify(&infoPtr->header);
    754 
    755     tbNotify.iItem    = pos;
    756     tbNotify.tbButton.iBitmap   = btnPtr->iBitmap;
    757     tbNotify.tbButton.idCommand = btnPtr->idCommand;
    758     tbNotify.tbButton.fsState   = btnPtr->fsState;
    759     tbNotify.tbButton.fsStyle   = btnPtr->fsStyle;
    760     tbNotify.tbButton.dwData    = btnPtr->dwData;
    761     tbNotify.tbButton.iString   = btnPtr->iString;
    762 
    763     tbNotify.cchText  = MAXTOOLNAME;
    764     if (unicode)
    765     {
    766       tbNotify.pszText  = (WCHAR*)COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
    767       tbNotify.pszText[0] = 0;
    768     } else
    769     {
    770       tbNotify.pszText  = (WCHAR*)COMCTL32_Alloc(MAXTOOLNAME*sizeof(CHAR));
    771       ((CHAR*)tbNotify.pszText)[0] = 0;
    772     }
    773 
    774     if (!sendNotify(infoPtr->hwndToolbar,unicode ? TBN_GETBUTTONINFOW:TBN_GETBUTTONINFOA,&tbNotify.hdr))
    775     { //CB: failed, try other methods
    776       if (infoPtr->hwndToolTip)
    777       { //try to get tool tip text
    778         TTTOOLINFOW ti;
    779 
    780         ZeroMemory (&ti,sizeof(ti));
    781         ti.cbSize   = sizeof(ti);
    782         ti.hwnd     = infoPtr->hwndToolbar;
    783         ti.uId      = btnPtr->idCommand;
    784         ti.hinst    = 0;
    785         ti.lpszText = (WCHAR*)COMCTL32_Alloc(INFOTIPSIZE*sizeof(WCHAR));
    786         ti.lpszText[0] = 0;
    787 
    788         SendMessageW(infoPtr->hwndToolTip,TTM_GETTEXTW,0,(LPARAM)&ti);
    789         if (unicode)
    790         {
    791           if (ti.lpszText[0] != 0) lstrcpynW(tbNotify.pszText,ti.lpszText,MAXTOOLNAME);
    792           else lstrcpyW(tbNotify.pszText,(WCHAR*)L"Button");
    793         } else
    794         {
    795           if (ti.lpszText[0] != 0) lstrcpynWtoA((CHAR*)tbNotify.pszText,ti.lpszText,MAXTOOLNAME);
    796           else lstrcpyWtoA((CHAR*)tbNotify.pszText,(WCHAR*)L"Button");
    797         }
    798 
    799         COMCTL32_Free(ti.lpszText);
    800 
    801       } else
    802       {
    803         if (unicode)
    804           lstrcpyW(tbNotify.pszText,(WCHAR*)L"Button");
    805         else
    806           lstrcpyA((CHAR*)tbNotify.pszText,"Button");
    807       }
    808     }
    809 
    810     if (!btnPtr->pszName) btnPtr->pszName = (WCHAR*)COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
    811     if (unicode)
    812       lstrcpyW(btnPtr->pszName,tbNotify.pszText);
    813     else
    814       lstrcpyAtoW(btnPtr->pszName,(CHAR*)tbNotify.pszText);
    815     COMCTL32_Free(tbNotify.pszText);
    816   }
    817 }
    818 
    819 static VOID TBCUSTOMIZE_AvailSelChange(HWND hwnd);
    820 static VOID TBCUSTOMIZE_VisSelChange(HWND hwnd);
    821 
    822 static BOOL TBCUSTOMIZE_FillData(HWND hwnd,TOOLBAR_INFO* infoPtr)
    823 {
    824   TBUTTON_INFO* btnPtr;
    825   INT i;
    826   INT leftCount = 0;
    827   INT rightCount = 0;
    828   INT nItem;
    829 
    830   SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,WM_SETREDRAW,FALSE,0);
    831   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,WM_SETREDRAW,FALSE,0);
    832   SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_RESETCONTENT,0,0);
    833   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_RESETCONTENT,0,0);
    834 
    835   /* insert 'virtual' separator button into 'available buttons' list */
    836   nItem = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"Separator");
    837   SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,nItem,0);
    838 
    839   /* copy all buttons and append them to the listboxes */
    840   btnPtr = infoPtr->buttons;
    841   for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
    842   {
    843     TBNOTIFYW tbNotify;
    844 
    845     tbNotify.iItem    = i;
    846     tbNotify.tbButton.iBitmap   = btnPtr->iBitmap;
    847     tbNotify.tbButton.idCommand = btnPtr->idCommand;
    848     tbNotify.tbButton.fsState   = btnPtr->fsState;
    849     tbNotify.tbButton.fsStyle   = btnPtr->fsStyle;
    850     tbNotify.tbButton.dwData    = btnPtr->dwData;
    851     tbNotify.tbButton.iString   = btnPtr->iString;
    852     tbNotify.cchText  = 0;
    853     tbNotify.pszText  = NULL;
    854 
    855     // send TBN_QUERYINSERT notification
    856     if (!sendNotify(infoPtr->hwndToolbar,TBN_QUERYINSERT,&tbNotify.hdr)) continue;
    857 
    858     // send TBN_QUERYDELETE notification
    859     btnPtr->bDelete = (BOOL)sendNotify(infoPtr->hwndToolbar,TBN_QUERYDELETE,&tbNotify.hdr);
    860 
    861     //get tool name
    862 
    863     TBCUSTOMIZE_GetToolName(infoPtr,btnPtr,i);
    864 
    865     if (btnPtr->fsState & TBSTATE_HIDDEN)
    866     {
    867       nItem = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
    868       SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,nItem,btnPtr->nCustomID);
    869       leftCount++;
    870     } else
    871     {
    872       nItem = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
    873       SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,nItem,btnPtr->nCustomID);
    874       rightCount++;
    875     }
    876   }
    877 
    878   SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETCURSEL,0,0);
    879   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,(rightCount > 0) ? 0:(WPARAM)-1,0);
    880 
    881   SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,WM_SETREDRAW,TRUE,0);
    882   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,WM_SETREDRAW,TRUE,0);
    883   InvalidateRect(GetDlgItem(hwnd,IDC_AVAILBTN_LBOX),NULL,TRUE);
    884   InvalidateRect(GetDlgItem(hwnd,IDC_TOOLBARBTN_LBOX),NULL,TRUE);
    885 
    886   if (leftCount == 0 && rightCount == 0) return FALSE;
    887 
    888   TBCUSTOMIZE_AvailSelChange(hwnd);
    889   TBCUSTOMIZE_VisSelChange(hwnd);
    890 
    891   return TRUE;
    892 }
    893 
    894 static BOOL TBCUSTOMIZE_InitDialog(HWND hwnd,WPARAM wParam,LPARAM lParam)
    895 {
    896   TOOLBAR_INFO* infoPtr;
    897   DWORD dwStyle;
    898 
    899   infoPtr = (TOOLBAR_INFO*)lParam;
    900   SetWindowLongA(hwnd,DWL_USER,(DWORD)infoPtr);
    901   dwStyle = GetWindowLongA(infoPtr->hwndToolbar,GWL_STYLE);
    902 
    903   if (infoPtr)
    904   {
    905     INT x,itemHeight;
    906 
    907     //custom ID: 1-nNumButtons, 0 == new separator
    908     for (x = 0;x < infoPtr->nNumButtons;x++)
    909     {
    910       infoPtr->buttons[x].nCustomID = x+1;
    911       infoPtr->buttons[x].pszName = NULL;
    912     }
    913     infoPtr->nMaxCustomID = infoPtr->nNumButtons;
    914 
    915     //save tools
    916     infoPtr->nNumOldButtons = infoPtr->nNumButtons;
    917     infoPtr->oldButtons = (TBUTTON_INFO*)COMCTL32_Alloc(infoPtr->nNumOldButtons*sizeof(TBUTTON_INFO));
    918     memcpy(&infoPtr->oldButtons[0],&infoPtr->buttons[0],infoPtr->nNumOldButtons*sizeof(TBUTTON_INFO));
    919 
    920     //set height
    921     if (dwStyle & TBSTYLE_FLAT)
    922       itemHeight = infoPtr->nBitmapHeight+4;
    923     else
    924       itemHeight = infoPtr->nBitmapHeight+8;
    925 
    926     SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMHEIGHT,0,itemHeight);
    927     SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMHEIGHT,0,itemHeight);
    928 
    929     infoPtr->changed = FALSE;
    930 
    931     if (!TBCUSTOMIZE_FillData(hwnd,infoPtr)) EndDialog(hwnd,FALSE);
    932   } else EndDialog(hwnd,FALSE);
    933 
    934   return TRUE;
    935 }
    936 
    937 static BOOL TBCUSTOMIZE_Close(HWND hwnd,WPARAM wParam,LPARAM lParam)
    938 {
    939   EndDialog(hwnd,FALSE);
    940 
    941   return TRUE;
    942 }
    943 
    944 static VOID TBCUSTOMIZE_Reset(HWND hwnd)
    945 {
    946   TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
    947   INT x;
    948 
    949   if (!infoPtr->changed) return;
    950 
    951   //Send TBN_RESET
    952   sendNotify(infoPtr->hwndToolbar,TBN_RESET);
    953 
    954   for (x = 0;x < infoPtr->nNumOldButtons;x++) COMCTL32_Free(infoPtr->oldButtons[x].pszName);
    955 
    956   //restore data
    957   if (infoPtr->nNumButtons != infoPtr->nNumOldButtons)
    958   {
    959     COMCTL32_Free(infoPtr->buttons);
    960     infoPtr->nNumButtons = infoPtr->nNumOldButtons;
    961     infoPtr->buttons = (TBUTTON_INFO*)COMCTL32_Alloc(infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
    962   }
    963   memcpy(&infoPtr->buttons[0],&infoPtr->oldButtons[0],infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
    964 
    965   if (!TBCUSTOMIZE_FillData(hwnd,infoPtr)) EndDialog(hwnd,FALSE);
    966 
    967   TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
    968   InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
    969 
    970   infoPtr->changed = FALSE;
    971 }
    972 
    973 static TBUTTON_INFO* TBCUSTOMIZE_GetBtnPtr(TOOLBAR_INFO* infoPtr,INT customID)
    974 {
    975   INT x;
    976   TBUTTON_INFO* btnPtr = infoPtr->buttons;
    977 
    978   if (customID == 0) return NULL;
    979 
    980   for (x = 0;x < infoPtr->nNumButtons;btnPtr++)
    981     if (btnPtr->nCustomID == customID) return btnPtr;
    982 
    983   return NULL;
    984 }
    985 
    986 static VOID TBCUSTOMIZE_AddTool(HWND hwnd)
    987 {
    988   TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
    989   LRESULT pos,count;
    990   INT customID;
    991   TBUTTON_INFO* btnPtr;
    992   LRESULT rightSel,rightCount,rightPos;
    993 
    994   pos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCURSEL,0,0);
    995   if (pos == (LRESULT)-1) return;
    996 
    997   count = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCOUNT,0,0);
    998 
    999   customID = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETITEMDATA,pos,0);
    1000   if (customID == 0) btnPtr = NULL; else
    1001   {
    1002     btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
    1003     if (btnPtr == NULL) return;
    1004 
    1005     SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_DELETESTRING,pos,0);
    1006   }
    1007 
    1008   rightSel = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
    1009   rightCount = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
    1010 
    1011   if (rightSel != (LRESULT)-1)
    1012     rightPos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_INSERTSTRING,rightSel,(LPARAM)"");
    1013   else
    1014     rightPos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
    1015   if (!btnPtr)
    1016   { //new separator
    1017     TBUTTON_INFO* newButtons;
    1018 
    1019     newButtons = (TBUTTON_INFO*)COMCTL32_Alloc((infoPtr->nNumButtons+1)*sizeof(TBUTTON_INFO));
    1020     memcpy(&newButtons[0],&infoPtr->buttons[0],infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
    1021     COMCTL32_Free(infoPtr->buttons);
    1022 
    1023     infoPtr->buttons = newButtons;
    1024     infoPtr->nNumButtons++;
    1025 
    1026     btnPtr = &infoPtr->buttons[infoPtr->nNumButtons-1];
    1027     ZeroMemory(btnPtr,sizeof(TBUTTON_INFO));
    1028     btnPtr->fsStyle = TBSTYLE_SEP;
    1029     btnPtr->bDelete = TRUE;
    1030 
    1031     customID = ++infoPtr->nMaxCustomID;
    1032     btnPtr->nCustomID = customID;
    1033     SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,rightPos,customID);
    1034   } else
    1035   {
    1036     SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,rightPos,customID);
    1037     btnPtr->fsState &= ~TBSTATE_HIDDEN;
    1038   }
    1039   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,rightPos,0);
    1040   TBCUSTOMIZE_VisSelChange(hwnd);
    1041 
    1042   if (rightCount > 0)
    1043   { //change order
    1044     TBUTTON_INFO* btnPtr2;
    1045     INT customID2,pos1,pos2;
    1046 
    1047     pos1 = 0;
    1048     while (infoPtr->buttons[pos1].nCustomID != customID) pos1++;
    1049     if (rightPos < rightCount)
    1050     { //insert before
    1051       customID2 = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,rightPos+1,0);
    1052       pos2 = 0;
    1053       while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
    1054     } else
    1055     { //insert behind
    1056       INT x;
    1057 
    1058       customID2 = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,rightPos-1,0);
    1059       pos2 = 0;
    1060       while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
    1061       //exchange to use first alogrithm
    1062       x = pos1;
    1063       pos1 = pos2;
    1064       pos2 = x;
    1065     }
    1066 
    1067     if (pos1+1 != pos2)
    1068     {
    1069       TBUTTON_INFO temp;
    1070       INT x;
    1071 
    1072       memcpy(&temp,&infoPtr->buttons[pos1],sizeof(TBUTTON_INFO));
    1073       if (pos1 < pos2)
    1074       {
    1075         for (x = pos1;x < pos2;x++)
    1076           memcpy(&infoPtr->buttons[x],&infoPtr->buttons[x+1],sizeof(TBUTTON_INFO));
    1077         memcpy(&infoPtr->buttons[pos2-1],&temp,sizeof(TBUTTON_INFO));
    1078       } else
    1079       {
    1080         for (x = pos1-1;x >= pos2;x--)
    1081           memcpy(&infoPtr->buttons[x+1],&infoPtr->buttons[x],sizeof(TBUTTON_INFO));
    1082         memcpy(&infoPtr->buttons[pos2],&temp,sizeof(TBUTTON_INFO));
    1083       }
    1084     }
    1085   }
    1086 
    1087   if (pos == count-1 && pos > 0) pos--;
    1088   SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETCURSEL,pos,0);
    1089   TBCUSTOMIZE_AvailSelChange(hwnd);
    1090 
    1091   TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
    1092   InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
    1093 
    1094   infoPtr->changed = TRUE;
    1095 }
    1096 
    1097 static VOID TBCUSTOMIZE_RemoveTool(HWND hwnd)
    1098 {
    1099   TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
    1100   LRESULT pos,count;
    1101   INT customID;
    1102   TBUTTON_INFO* btnPtr;
    1103 
    1104   pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
    1105   if (pos == (LRESULT)-1) return;
    1106 
    1107   count = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
    1108 
    1109   customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
    1110   if (customID == 0) return; //no allowed
    1111 
    1112   btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
    1113   if (btnPtr == NULL || !btnPtr->bDelete) return;
    1114 
    1115   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_DELETESTRING,pos,0);
    1116 
    1117   if (btnPtr->fsStyle & TBSTYLE_SEP)
    1118   { //remove separator
    1119     TBUTTON_INFO* newButtons;
    1120     INT nIndex,x;
    1121 
    1122     //find pos
    1123     for (x = 0;x < infoPtr->nNumButtons;x++) if (&infoPtr->buttons[x] == btnPtr)
    1124     {
    1125       nIndex = x;
    1126       break;
    1127     }
    1128 
    1129     infoPtr->nNumButtons--;
    1130     newButtons = (TBUTTON_INFO*)COMCTL32_Alloc(infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
    1131 
    1132     if (nIndex > 0)
    1133       memcpy(&newButtons[0],&infoPtr->buttons[0],nIndex*sizeof(TBUTTON_INFO));
    1134 
    1135     if (nIndex < infoPtr->nNumButtons)
    1136       memcpy (&newButtons[nIndex],&infoPtr->buttons[nIndex+1],(infoPtr->nNumButtons-nIndex)*sizeof(TBUTTON_INFO));
    1137 
    1138     COMCTL32_Free(infoPtr->buttons);
    1139     infoPtr->buttons = newButtons;
    1140   } else
    1141   {
    1142     LRESULT leftSel,leftCount,leftPos;
    1143 
    1144     leftSel = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCURSEL,0,0);
    1145     leftCount = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCOUNT,0,0);
    1146 
    1147     if (leftSel == 0)
    1148       if (leftCount > 1) leftSel++; else leftSel = -1;
    1149 
    1150     if (leftSel != (LRESULT)-1)
    1151       leftPos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_INSERTSTRING,leftSel,(LPARAM)"");
    1152     else
    1153       leftPos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
    1154     SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,leftPos,customID);
    1155 
    1156     SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETCURSEL,leftPos,0);
    1157     TBCUSTOMIZE_AvailSelChange(hwnd);
    1158 
    1159     btnPtr->fsState |= TBSTATE_HIDDEN;
    1160 
    1161     if (leftCount > 1)
    1162     { //change order
    1163       TBUTTON_INFO* btnPtr2;
    1164       INT customID2,pos1,pos2;
    1165 
    1166       pos1 = 0;
    1167       while (infoPtr->buttons[pos1].nCustomID != customID) pos1++;
    1168       if (leftPos < leftCount)
    1169       { //insert before
    1170         customID2 = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETITEMDATA,leftPos+1,0);
    1171         pos2 = 0;
    1172         while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
    1173       } else
    1174       { //insert behind
    1175         INT x;
    1176 
    1177         customID2 = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETITEMDATA,leftPos-1,0);
    1178         pos2 = 0;
    1179         while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
    1180         //exchange to use first alogrithm
    1181         x = pos1;
    1182         pos1 = pos2;
    1183         pos2 = x;
    1184       }
    1185 
    1186       if (pos1+1 != pos2)
    1187       {
    1188         TBUTTON_INFO temp;
    1189         INT x;
    1190 
    1191         memcpy(&temp,&infoPtr->buttons[pos1],sizeof(TBUTTON_INFO));
    1192         if (pos1 < pos2)
    1193         {
    1194           for (x = pos1;x < pos2;x++)
    1195             memcpy(&infoPtr->buttons[x],&infoPtr->buttons[x+1],sizeof(TBUTTON_INFO));
    1196           memcpy(&infoPtr->buttons[pos2-1],&temp,sizeof(TBUTTON_INFO));
    1197         } else
    1198         {
    1199           for (x = pos1-1;x >= pos2;x--)
    1200             memcpy(&infoPtr->buttons[x+1],&infoPtr->buttons[x],sizeof(TBUTTON_INFO));
    1201           memcpy(&infoPtr->buttons[pos2],&temp,sizeof(TBUTTON_INFO));
    1202         }
    1203       }
    1204     }
    1205   }
    1206 
    1207   if (pos == count-1) pos--;
    1208   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,pos,0);
    1209   TBCUSTOMIZE_VisSelChange(hwnd);
    1210 
    1211   TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
    1212   InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
    1213 
    1214   infoPtr->changed = TRUE;
    1215 }
    1216 
    1217 static VOID TBCUSTOMIZE_Help(HWND hwnd)
    1218 {
    1219  TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
    1220 
    1221  //Send TBN_CUSTHELP
    1222  sendNotify(infoPtr->hwndToolbar,TBN_CUSTHELP);
    1223 }
    1224 
    1225 static VOID TBCUSTOMIZE_MoveToolUp(HWND hwnd)
    1226 {
    1227   TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
    1228   LRESULT pos;
    1229   TBUTTON_INFO button;
    1230   INT customID;
    1231   TBUTTON_INFO* btnPtr1,* btnPtr2;
    1232 
    1233   pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
    1234   if (pos == (LRESULT)-1 || pos == 0) return;
    1235 
    1236   //update listbox
    1237 
    1238   customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
    1239   btnPtr1 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
    1240   if (btnPtr1 == NULL) return;
    1241 
    1242   customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos-1,0);
    1243   btnPtr2 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
    1244   if (btnPtr2 == NULL) return;
    1245 
    1246   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos,btnPtr2->nCustomID);
    1247   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos-1,btnPtr1->nCustomID);
    1248 
    1249   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,pos-1,0);
    1250   TBCUSTOMIZE_VisSelChange(hwnd);
    1251 
    1252   //update buttons
    1253   memcpy(&button,btnPtr1,sizeof(TBUTTON_INFO));
    1254   memcpy(btnPtr1,btnPtr2,sizeof(TBUTTON_INFO));
    1255   memcpy(btnPtr2,&button,sizeof(TBUTTON_INFO));
    1256 
    1257   TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
    1258   InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
    1259 
    1260   infoPtr->changed = TRUE;
    1261 }
    1262 
    1263 static VOID TBCUSTOMIZE_MoveToolDown(HWND hwnd)
    1264 {
    1265   TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
    1266   LRESULT pos,count;
    1267   TBUTTON_INFO button;
    1268   INT customID;
    1269   TBUTTON_INFO* btnPtr1,* btnPtr2;
    1270 
    1271   pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
    1272   if (pos == (LRESULT)-1) return;
    1273 
    1274   count = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
    1275   if (pos == count-1) return;
    1276 
    1277   //update listbox
    1278 
    1279   customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
    1280   btnPtr1 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
    1281   if (btnPtr1 == NULL) return;
    1282 
    1283   customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos+1,0);
    1284   btnPtr2 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
    1285   if (btnPtr2 == NULL) return;
    1286 
    1287   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos,btnPtr2->nCustomID);
    1288   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos+1,btnPtr1->nCustomID);
    1289 
    1290   SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,pos+1,0);
    1291   TBCUSTOMIZE_VisSelChange(hwnd);
    1292 
    1293   //update buttons
    1294   memcpy(&button,btnPtr1,sizeof(TBUTTON_INFO));
    1295   memcpy(btnPtr1,btnPtr2,sizeof(TBUTTON_INFO));
    1296   memcpy(btnPtr2,&button,sizeof(TBUTTON_INFO));
    1297 
    1298   TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
    1299   InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
    1300 
    1301   infoPtr->changed = TRUE;
    1302 }
    1303 
    1304 static VOID TBCUSTOMIZE_AvailSelChange(HWND hwnd)
    1305 {
    1306   LRESULT pos;
    1307   HWND hwndBtn;
    1308 
    1309   pos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCURSEL,0,0);
    1310 
    1311   hwndBtn = GetDlgItem(hwnd,IDOK);
    1312   EnableWindow(hwndBtn,(pos == (LRESULT)-1) ? FALSE:TRUE);
    1313 }
    1314 
    1315 static VOID TBCUSTOMIZE_VisSelChange(HWND hwnd)
    1316 {
    1317   TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
    1318   LRESULT pos;
    1319 
    1320   pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
    1321 
    1322   if (pos == (LRESULT)-1)
    1323   {
    1324     EnableWindow(GetDlgItem(hwnd,IDC_REMOVE_BTN),FALSE);
    1325     EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN),FALSE);
    1326     EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN),FALSE);
    1327   } else
    1328   {
    1329     INT customID;
    1330     TBUTTON_INFO* btnPtr;
    1331     LRESULT count;
    1332 
    1333     customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
    1334     btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
    1335     count = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
    1336 
    1337     if (btnPtr)
    1338       EnableWindow(GetDlgItem(hwnd,IDC_REMOVE_BTN),btnPtr->bDelete);
    1339     else
    1340       EnableWindow(GetDlgItem(hwnd,IDC_REMOVE_BTN),TRUE);
    1341     EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN),!(pos == 0));
    1342     EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN),!(pos == count-1));
    1343   }
    1344 }
    1345 
    1346 static BOOL TBCUSTOMIZE_Command(HWND hwnd,WPARAM wParam,LPARAM lParam)
    1347 {
    1348   switch(LOWORD(wParam))
    1349   {
    1350     case IDCANCEL:
    1351       EndDialog(hwnd,FALSE);
    1352       break;
    1353 
    1354     case IDC_RESET_BTN:
    1355       TBCUSTOMIZE_Reset(hwnd);
    1356       break;
    1357 
    1358     case IDOK: //== add tool
    1359       TBCUSTOMIZE_AddTool(hwnd);
    1360       break;
    1361 
    1362     case IDC_REMOVE_BTN:
    1363       TBCUSTOMIZE_RemoveTool(hwnd);
    1364       break;
    1365 
    1366     case IDC_HELP_BTN:
    1367       TBCUSTOMIZE_Help(hwnd);
    1368       break;
    1369 
    1370     case IDC_MOVEUP_BTN:
    1371       TBCUSTOMIZE_MoveToolUp(hwnd);
    1372       break;
    1373 
    1374     case IDC_MOVEDN_BTN:
    1375       TBCUSTOMIZE_MoveToolDown(hwnd);
    1376       break;
    1377 
    1378     case IDC_AVAILBTN_LBOX:
    1379       switch(HIWORD(wParam))
    1380       {
    1381         case LBN_SELCHANGE:
    1382           TBCUSTOMIZE_AvailSelChange(hwnd);
    1383           break;
    1384         case LBN_DBLCLK:
    1385           TBCUSTOMIZE_AddTool(hwnd);
    1386           break;
    1387       }
    1388       break;
    1389 
    1390     case IDC_TOOLBARBTN_LBOX:
    1391       switch(HIWORD(wParam))
    1392       {
    1393         case LBN_SELCHANGE:
    1394           TBCUSTOMIZE_VisSelChange(hwnd);
    1395           break;
    1396         case LBN_DBLCLK:
    1397           TBCUSTOMIZE_RemoveTool(hwnd);
    1398           break;
    1399       }
    1400       break;
    1401   }
    1402 
    1403   return TRUE;
    1404 }
    1405 
    1406 static BOOL TBCUSTOMIZE_Destroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
    1407 {
    1408   TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
    1409   INT x;
    1410 
    1411   for (x = 0;x < infoPtr->nNumOldButtons;x++)
    1412     COMCTL32_Free(infoPtr->oldButtons[x].pszName);
    1413   COMCTL32_Free(infoPtr->oldButtons);
    1414   infoPtr->oldButtons = NULL;
    1415   infoPtr->nNumOldButtons = 0;
    1416 
    1417   return TRUE;
    1418 }
    1419 
    1420 static BOOL TBCUSTOMIZE_DrawItem(HWND hwnd,WPARAM wParam,LPARAM lParam)
    1421 {
    1422   if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
    1423   {
    1424     TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
    1425     LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
    1426     RECT rcButton;
    1427     RECT rcText;
    1428     HPEN hOldPen;
    1429     HBRUSH hOldBrush;
    1430     COLORREF oldText = 0;
    1431     COLORREF oldBk = 0;
    1432     INT customID;
    1433     TBUTTON_INFO* btnPtr;
    1434     DWORD dwStyle = GetWindowLongA(infoPtr->hwndToolbar,GWL_STYLE);
    1435 
    1436     customID = SendDlgItemMessageA(hwnd,wParam,LB_GETITEMDATA,lpdis->itemID,0);
    1437     btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
    1438 
    1439     if (btnPtr != NULL && !btnPtr->bDelete)
    1440     {
    1441       if (lpdis->itemState & ODS_FOCUS) oldBk = SetBkColor(lpdis->hDC,GetSysColor(COLOR_HIGHLIGHT));
    1442       oldText = SetTextColor(lpdis->hDC,GetSysColor(COLOR_GRAYTEXT));
    1443     } else if (lpdis->itemState & ODS_FOCUS)
    1444     {
    1445       oldBk = SetBkColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
    1446       oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
    1447     }
    1448 
    1449 
    1450     hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
    1451     hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
    1452 
    1453     /* fill background rectangle */
    1454     Rectangle (lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,lpdis->rcItem.right,lpdis->rcItem.bottom);
    1455 
    1456     /* calculate button and text rectangles */
    1457     CopyRect (&rcButton, &lpdis->rcItem);
    1458     InflateRect (&rcButton, -1, -1);
    1459     CopyRect (&rcText, &rcButton);
    1460     rcButton.right = rcButton.left + infoPtr->nBitmapWidth + 6;
    1461     rcText.left = rcButton.right + 2;
    1462 
    1463     /* draw focus rectangle */
    1464     if (lpdis->itemState & ODS_FOCUS) DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
    1465 
    1466     //draw tool
    1467     if (btnPtr && !(btnPtr->fsStyle & TBSTYLE_SEP))
    1468     {
    1469       //draw button
    1470       if (dwStyle & TBSTYLE_FLAT)
    1471       {
    1472         ImageList_Draw(infoPtr->himlDef,btnPtr->iBitmap,lpdis->hDC,rcButton.left+2,rcButton.top+2,ILD_NORMAL);
    1473       } else
    1474       {
    1475         DrawEdge (lpdis->hDC,&rcButton,EDGE_RAISED,BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    1476 
    1477         ImageList_Draw(infoPtr->himlDef,btnPtr->iBitmap,lpdis->hDC,rcButton.left+1,rcButton.top+1,ILD_NORMAL);
    1478       }
    1479 
    1480     } else
    1481     { //draw separator
    1482       if (!(dwStyle & TBSTYLE_FLAT))
    1483         DrawEdge (lpdis->hDC,&rcButton,EDGE_RAISED,BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    1484 
    1485       TOOLBAR_DrawFlatSeparator(&rcButton,lpdis->hDC);
    1486     }
    1487 
    1488     /* draw text */
    1489     if (!btnPtr || btnPtr->fsStyle & TBSTYLE_SEP)
    1490     { //new separator
    1491       DrawTextA(lpdis->hDC,"Separator",-1,&rcText,DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    1492     } else if (btnPtr->pszName != NULL)
    1493     {
    1494       DrawTextW(lpdis->hDC,btnPtr->pszName,-1,&rcText,DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    1495     }
    1496 
    1497     if (lpdis->itemState & ODS_FOCUS)
    1498     {
    1499       SetBkColor (lpdis->hDC, oldBk);
    1500       SetTextColor (lpdis->hDC, oldText);
    1501     }
    1502 
    1503     SelectObject (lpdis->hDC, hOldBrush);
    1504     SelectObject (lpdis->hDC, hOldPen);
    1505 
    1506     return TRUE;
    1507   }
    1508 
    1509   return FALSE;
    1510 }
     841    msg.time = GetMessageTime ();
     842    msg.pt.x = LOWORD(GetMessagePos ());
     843    msg.pt.y = HIWORD(GetMessagePos ());
     844
     845    SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
     846}
     847
    1511848
    1512849/***********************************************************************
     
    1517854TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    1518855{
    1519     TOOLBAR_INFO *infoPtr;
     856    TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongA (hwnd, DWL_USER);
     857    static HDSA hDsa = NULL;
    1520858
    1521859    switch (uMsg)
    1522860    {
    1523         case WM_INITDIALOG:
    1524             return TBCUSTOMIZE_InitDialog(hwnd,wParam,lParam);
    1525 
    1526         case WM_CLOSE:
    1527             return TBCUSTOMIZE_Close(hwnd,wParam,lParam);
    1528 
    1529         case WM_COMMAND:
    1530             return TBCUSTOMIZE_Command(hwnd,wParam,lParam);
    1531 
    1532         case WM_DESTROY:
    1533             return TBCUSTOMIZE_Destroy(hwnd,wParam,lParam);
    1534 
    1535         case WM_DRAWITEM:
    1536             return TBCUSTOMIZE_DrawItem(hwnd,wParam,lParam);
    1537 
    1538         default:
    1539             return FALSE;
    1540     }
    1541 }
     861        case WM_INITDIALOG:
     862            infoPtr = (TOOLBAR_INFO *)lParam;
     863            SetWindowLongA (hwnd, DWL_USER, (DWORD)infoPtr);
     864
     865            hDsa = DSA_Create (sizeof(TBUTTON_INFO), 5);
     866
     867            if (infoPtr)
     868            {
     869                TBUTTON_INFO *btnPtr;
     870                INT i;
     871
     872                /* insert 'virtual' separator button into 'available buttons' list */
     873                SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
     874
     875                /* copy all buttons and append them to the right listbox */             
     876                btnPtr = infoPtr->buttons;
     877                for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
     878                {
     879                    DSA_InsertItem (hDsa, i, btnPtr);
     880
     881                    /* FIXME: hidden buttons appear in the 'toolbar buttons' list too */
     882                    if (btnPtr->fsState & TBSTATE_HIDDEN)
     883                    {
     884                        SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
     885                    }
     886                    else
     887                    {
     888                        SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
     889                    }
     890                }
     891
     892                /* append 'virtual' separator button to the 'toolbar buttons' list */
     893                /* TODO */
     894            }
     895            return TRUE;
     896
     897        case WM_CLOSE:
     898            EndDialog(hwnd, FALSE);
     899            return TRUE;
     900
     901        case WM_COMMAND:
     902            switch (LOWORD(wParam))
     903            {
     904                case IDCANCEL:
     905                    EndDialog(hwnd, FALSE);
     906                    break;
     907            }
     908            return TRUE;
     909
     910        case WM_DESTROY:
     911            if (hDsa)
     912                DSA_Destroy (hDsa);
     913            return TRUE;
     914
     915        case WM_DRAWITEM:
     916            if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
     917            {
     918                LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
     919                TBUTTON_INFO btnPtr;
     920                RECT rcButton;
     921                RECT rcText;
     922                HPEN hOldPen;
     923                HBRUSH hOldBrush;
     924                COLORREF oldText = 0;
     925                COLORREF oldBk = 0;
     926
     927                // FIXME("action: %x itemState: %x\n",
     928                //    lpdis->itemAction, lpdis->itemState);             
     929
     930                DSA_GetItem (hDsa, 0 /*lpdis->itemID*/, &btnPtr);
     931
     932                if (lpdis->itemState & ODS_FOCUS)
     933                {
     934                    oldBk = SetBkColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
     935                    oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
     936                }
     937
     938                hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
     939                hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
     940
     941                /* fill background rectangle */
     942                Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
     943                           lpdis->rcItem.right, lpdis->rcItem.bottom);
     944
     945                /* calculate button and text rectangles */
     946                CopyRect (&rcButton, &lpdis->rcItem);
     947                InflateRect (&rcButton, -1, -1);
     948                CopyRect (&rcText, &rcButton);
     949                rcButton.right = rcButton.left + infoPtr->nBitmapWidth + 6;
     950                rcText.left = rcButton.right + 2;
     951
     952                /* draw focus rectangle */
     953                if (lpdis->itemState & ODS_FOCUS)
     954                    DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
     955
     956                /* draw button */
     957                DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
     958
     959                /* draw image and text */
     960                if (wParam == IDC_AVAILBTN_LBOX && lpdis->itemID == 0)
     961                {
     962                    /* virtual separator in the 'available' list */
     963                    DrawTextA (lpdis->hDC, "Separator", -1, &rcText,
     964                               DT_LEFT | DT_VCENTER | DT_SINGLELINE);
     965                }
     966                else
     967                {
     968                    /* real button */
     969
     970                    ImageList_Draw (infoPtr->himlDef, btnPtr.iBitmap, lpdis->hDC,
     971                                    rcButton.left+1, rcButton.top+1, ILD_NORMAL);
     972
     973                    DrawTextW (lpdis->hDC,  infoPtr->strings[btnPtr.iString], -1, &rcText,
     974                               DT_LEFT | DT_VCENTER | DT_SINGLELINE);
     975
     976                }
     977
     978                if (lpdis->itemState & ODS_FOCUS)
     979                {
     980                    SetBkColor (lpdis->hDC, oldBk);
     981                    SetTextColor (lpdis->hDC, oldText);
     982                }
     983
     984                SelectObject (lpdis->hDC, hOldBrush);
     985                SelectObject (lpdis->hDC, hOldPen);
     986
     987                return TRUE;
     988            }
     989            return FALSE;
     990
     991        case WM_MEASUREITEM:
     992            if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
     993            {
     994                MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
     995
     996                if (infoPtr)
     997                    lpmis->itemHeight = infoPtr->nBitmapHeight + 8;
     998                else
     999                    lpmis->itemHeight = 15 + 8; /* default height */
     1000
     1001                return TRUE;
     1002            }
     1003            return FALSE;
     1004
     1005        default:
     1006            return FALSE;
     1007    }
     1008}
     1009
    15421010
    15431011/***********************************************************************
     
    15501018    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    15511019    LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
    1552     INT nIndex = 0,nButtons;
     1020    INT nIndex = 0, nButtons, nCount;
    15531021    HBITMAP hbmLoad;
    15541022
     1023    // TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
    15551024    if (!lpAddBmp)
    1556         return -1;
     1025        return -1;
    15571026
    15581027    if (lpAddBmp->hInst == HINST_COMMCTRL)
    15591028    {
    1560         if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
    1561             nButtons = 15;
    1562         else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
    1563             nButtons = 13;
    1564         else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
    1565             nButtons = 5;
    1566         else
    1567             return -1;
    1568 
    1569 //        TRACE ("adding %d internal bitmaps!\n", nButtons);
    1570 
    1571         /* Windows resize all the buttons to the size of a newly added standard Image*/
    1572         if (lpAddBmp->nID & 1)
    1573         {
    1574             /* large icons */
    1575             SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
    1576                           MAKELPARAM((WORD)26, (WORD)26));
    1577             SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
    1578                           MAKELPARAM((WORD)33, (WORD)33));
    1579         }
    1580         else
    1581         {
    1582             /* small icons */
    1583             SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
    1584                           MAKELPARAM((WORD)16, (WORD)16));
    1585             SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
    1586                           MAKELPARAM((WORD)22, (WORD)22));
    1587         }
    1588 
    1589         TOOLBAR_CalcToolbar (hwnd);
     1029        if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
     1030            nButtons = 15;
     1031        else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
     1032            nButtons = 13;
     1033        else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
     1034            nButtons = 5;
     1035        else
     1036            return -1;
     1037
     1038        // TRACE ("adding %d internal bitmaps!\n", nButtons);
     1039
     1040        /* Windows resize all the buttons to the size of a newly added standard image */
     1041        if (lpAddBmp->nID & 1)
     1042        {
     1043            /* large icons */
     1044            SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
     1045                          MAKELPARAM((WORD)26, (WORD)26));
     1046            SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
     1047                          MAKELPARAM((WORD)33, (WORD)33));
     1048        }       
     1049        else
     1050        {
     1051            /* small icons */
     1052            SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
     1053                          MAKELPARAM((WORD)16, (WORD)16));
     1054            SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
     1055                          MAKELPARAM((WORD)22, (WORD)22));
     1056        }
     1057       
     1058        TOOLBAR_CalcToolbar (hwnd);
    15901059    }
    15911060    else
    15921061    {
    1593         nButtons = (INT)wParam;
    1594         if (nButtons <= 0)
    1595             return -1;
    1596 
    1597         //TRACE ("adding %d bitmaps!\n", nButtons);
    1598     }
    1599 
     1062        nButtons = (INT)wParam;
     1063        if (nButtons <= 0)
     1064            return -1;
     1065       
     1066        // TRACE ("adding %d bitmaps!\n", nButtons);
     1067    }
     1068   
    16001069    if (!(infoPtr->himlDef)) {
    1601         /* create new default image list */
    1602         //TRACE ("creating default image list!\n");
    1603         /* It seems that the image list created is 1 pixel taller than the bitmap height */
    1604 //CB: nope, it's otherwise     
     1070        /* create new default image list */
     1071        // TRACE ("creating default image list!\n");
     1072
    16051073        infoPtr->himlDef =
    1606             ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight-1,
     1074            ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
    16071075                              ILC_COLOR | ILC_MASK, nButtons, 2);
    1608         infoPtr->himlInt = infoPtr->himlDef;
    1609     }
     1076        infoPtr->himlInt = infoPtr->himlDef;
     1077    }
     1078
     1079    nCount = ImageList_GetImageCount(infoPtr->himlDef);
    16101080
    16111081    /* Add bitmaps to the default image list */
    16121082    if (lpAddBmp->hInst == (HINSTANCE)0)
    16131083    {
    1614         nIndex =
    1615             ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
    1616                                 CLR_DEFAULT);
     1084        nIndex =
     1085            ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
     1086                                CLR_DEFAULT);
    16171087    }
    16181088    else if (lpAddBmp->hInst == HINST_COMMCTRL)
    16191089    {
    1620         /* Add system bitmaps */
    1621         switch (lpAddBmp->nID)
    1622       {
    1623             case IDB_STD_SMALL_COLOR:
    1624                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1625                                        MAKEINTRESOURCEA(IDB_STD_SMALL));
    1626                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1627                                               hbmLoad, CLR_DEFAULT);
    1628                 DeleteObject (hbmLoad);
    1629                 break;
    1630 
    1631             case IDB_STD_LARGE_COLOR:
    1632                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1633                                        MAKEINTRESOURCEA(IDB_STD_LARGE));
    1634                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1635                                               hbmLoad, CLR_DEFAULT);
    1636                 DeleteObject (hbmLoad);
    1637                 break;
    1638 
    1639             case IDB_VIEW_SMALL_COLOR:
    1640                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1641                                        MAKEINTRESOURCEA(IDB_VIEW_SMALL));
    1642                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1643                                               hbmLoad, CLR_DEFAULT);
    1644                 DeleteObject (hbmLoad);
    1645                 break;
    1646 
    1647             case IDB_VIEW_LARGE_COLOR:
    1648                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1649                                        MAKEINTRESOURCEA(IDB_VIEW_LARGE));
    1650                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1651                                               hbmLoad, CLR_DEFAULT);
    1652                 DeleteObject (hbmLoad);
    1653                 break;
    1654 
    1655             case IDB_HIST_SMALL_COLOR:
    1656                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1657                                        MAKEINTRESOURCEA(IDB_HIST_SMALL));
    1658                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1659                                               hbmLoad, CLR_DEFAULT);
    1660                 DeleteObject (hbmLoad);
    1661                 break;
    1662 
    1663             case IDB_HIST_LARGE_COLOR:
    1664                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1665                                        MAKEINTRESOURCEA(IDB_HIST_LARGE));
    1666                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1667                                               hbmLoad, CLR_DEFAULT);
    1668                 DeleteObject (hbmLoad);
    1669                 break;
    1670 
    1671             default:
    1672         nIndex = ImageList_GetImageCount (infoPtr->himlDef);
    1673                 //ERR ("invalid imagelist!\n");
    1674                 break;
    1675         }
     1090        /* Add system bitmaps */
     1091        switch (lpAddBmp->nID)
     1092    {
     1093            case IDB_STD_SMALL_COLOR:
     1094                hbmLoad = LoadBitmapA (COMCTL32_hModule,
     1095                                       MAKEINTRESOURCEA(IDB_STD_SMALL));
     1096                nIndex = ImageList_AddMasked (infoPtr->himlDef,
     1097                                              hbmLoad, CLR_DEFAULT);
     1098                DeleteObject (hbmLoad);
     1099                break;
     1100
     1101            case IDB_STD_LARGE_COLOR:
     1102                hbmLoad = LoadBitmapA (COMCTL32_hModule,
     1103                                       MAKEINTRESOURCEA(IDB_STD_LARGE));
     1104                nIndex = ImageList_AddMasked (infoPtr->himlDef,
     1105                                              hbmLoad, CLR_DEFAULT);
     1106                DeleteObject (hbmLoad);
     1107                break;
     1108
     1109            case IDB_VIEW_SMALL_COLOR:
     1110                hbmLoad = LoadBitmapA (COMCTL32_hModule,
     1111                                       MAKEINTRESOURCEA(IDB_VIEW_SMALL));
     1112                nIndex = ImageList_AddMasked (infoPtr->himlDef,
     1113                                              hbmLoad, CLR_DEFAULT);
     1114                DeleteObject (hbmLoad);
     1115                break;
     1116
     1117            case IDB_VIEW_LARGE_COLOR:
     1118                hbmLoad = LoadBitmapA (COMCTL32_hModule,
     1119                                       MAKEINTRESOURCEA(IDB_VIEW_LARGE));
     1120                nIndex = ImageList_AddMasked (infoPtr->himlDef,
     1121                                              hbmLoad, CLR_DEFAULT);
     1122                DeleteObject (hbmLoad);
     1123                break;
     1124
     1125            case IDB_HIST_SMALL_COLOR:
     1126                hbmLoad = LoadBitmapA (COMCTL32_hModule,
     1127                                       MAKEINTRESOURCEA(IDB_HIST_SMALL));
     1128                nIndex = ImageList_AddMasked (infoPtr->himlDef,
     1129                                              hbmLoad, CLR_DEFAULT);
     1130                DeleteObject (hbmLoad);
     1131                break;
     1132
     1133            case IDB_HIST_LARGE_COLOR:
     1134                hbmLoad = LoadBitmapA (COMCTL32_hModule,
     1135                                       MAKEINTRESOURCEA(IDB_HIST_LARGE));
     1136                nIndex = ImageList_AddMasked (infoPtr->himlDef,
     1137                                              hbmLoad, CLR_DEFAULT);
     1138                DeleteObject (hbmLoad);
     1139                break;
     1140
     1141            default:
     1142        nIndex = ImageList_GetImageCount (infoPtr->himlDef);
     1143        // ERR ("invalid imagelist!\n");
     1144                break;
     1145        }
    16761146    }
    16771147    else
    16781148    {
    1679         hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
    1680         nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
    1681         DeleteObject (hbmLoad);
    1682     }
    1683 
    1684     infoPtr->nNumBitmaps += nButtons;
     1149        hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
     1150        nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
     1151        DeleteObject (hbmLoad);
     1152    }
     1153
     1154    if (nIndex != -1)
     1155    {
     1156       INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
     1157
     1158       if (infoPtr->nNumBitmaps + nButtons != imagecount)
     1159       {
     1160         dprintf(("TOOLBAR_AddBitmap: Desired images do not match recieved images : Previous image number %i Previous images in list %i  added %i expecting total %i, Images in list %i\n",
     1161              infoPtr->nNumBitmaps, nCount, imagecount - nCount,
     1162              infoPtr->nNumBitmaps+nButtons,imagecount));
     1163
     1164         infoPtr->nNumBitmaps = imagecount;
     1165       }
     1166       else
     1167         infoPtr->nNumBitmaps += nButtons;
     1168    }
    16851169
    16861170    return nIndex;
     
    16951179    INT nOldButtons, nNewButtons, nAddButtons, nCount;
    16961180
    1697 //    TRACE (toolbar, "adding %d buttons!\n", wParam);
    1698 
    1699     nAddButtons = (UINT)wParam;
    1700     nOldButtons = infoPtr->nNumButtons;
    1701     nNewButtons = nOldButtons+nAddButtons;
    1702 
    1703     if (infoPtr->nNumButtons == 0)
    1704     {
    1705       infoPtr->buttons = (TBUTTON_INFO*)COMCTL32_Alloc(sizeof(TBUTTON_INFO)*nNewButtons);
    1706     } else
    1707     {
    1708       TBUTTON_INFO* oldButtons = infoPtr->buttons;
    1709 
    1710       infoPtr->buttons = (TBUTTON_INFO*)COMCTL32_Alloc(sizeof(TBUTTON_INFO)*nNewButtons);
    1711       memcpy(&infoPtr->buttons[0], &oldButtons[0],nOldButtons * sizeof(TBUTTON_INFO));
    1712       COMCTL32_Free(oldButtons);
    1713     }
    1714 
    1715     infoPtr->nNumButtons = nNewButtons;
    1716 
    1717     /* insert new button data */
    1718     for (nCount = 0; nCount < nAddButtons; nCount++)
    1719     {
    1720         TBUTTON_INFO* btnPtr = &infoPtr->buttons[nOldButtons+nCount];
    1721 
    1722         btnPtr->iBitmap   = lpTbb[nCount].iBitmap;
    1723         btnPtr->idCommand = lpTbb[nCount].idCommand;
    1724         btnPtr->fsState   = lpTbb[nCount].fsState;
    1725         btnPtr->fsStyle   = lpTbb[nCount].fsStyle;
    1726         btnPtr->dwData    = lpTbb[nCount].dwData;
    1727         btnPtr->iString   = lpTbb[nCount].iString;
    1728         btnPtr->bHot      = FALSE;
    1729         btnPtr->bDelete   = FALSE; //only used in customize
    1730         btnPtr->pszName   = NULL;
    1731 
    1732         if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP))
    1733         {
    1734             TTTOOLINFOA ti;
    1735 
    1736             ZeroMemory (&ti, sizeof(TTTOOLINFOA));
    1737             ti.cbSize   = sizeof (TTTOOLINFOA);
    1738             ti.hwnd     = hwnd;
    1739             ti.uId      = btnPtr->idCommand;
    1740             ti.hinst    = 0;
    1741             ti.lpszText = LPSTR_TEXTCALLBACKA;
    1742 
    1743             SendMessageA (infoPtr->hwndToolTip,TTM_ADDTOOLA,0,(LPARAM)&ti);
    1744         }
    1745     }
    1746 
    1747     TOOLBAR_CalcToolbar(hwnd);
    1748 
    1749     InvalidateRect(hwnd,NULL,FALSE);
    1750 
    1751     return TRUE;
    1752 }
    1753 
    1754 static LRESULT
    1755 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1756 {
    1757     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    1758     LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
    1759     INT nOldButtons, nNewButtons, nAddButtons, nCount;
    1760 
    1761 //    TRACE("adding %d buttons!\n", wParam);
     1181    // TRACE("adding %d buttons!\n", wParam);
    17621182
    17631183    nAddButtons = (UINT)wParam;
     
    17661186
    17671187    if (infoPtr->nNumButtons == 0) {
    1768         infoPtr->buttons =
    1769             (TBUTTON_INFO*)COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
     1188        infoPtr->buttons =
     1189            (TBUTTON_INFO*) COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
    17701190    }
    17711191    else {
    1772         TBUTTON_INFO *oldButtons = infoPtr->buttons;
    1773         infoPtr->buttons =
    1774             (TBUTTON_INFO*)COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
    1775         memcpy (&infoPtr->buttons[0], &oldButtons[0],
    1776                 nOldButtons * sizeof(TBUTTON_INFO));
     1192        TBUTTON_INFO *oldButtons = infoPtr->buttons;
     1193        infoPtr->buttons =
     1194            (TBUTTON_INFO*) COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
     1195        memcpy (&infoPtr->buttons[0], &oldButtons[0],
     1196                nOldButtons * sizeof(TBUTTON_INFO));
    17771197        COMCTL32_Free (oldButtons);
    17781198    }
     
    17821202    /* insert new button data */
    17831203    for (nCount = 0; nCount < nAddButtons; nCount++) {
    1784         TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
    1785         btnPtr->iBitmap   = lpTbb[nCount].iBitmap;
    1786         btnPtr->idCommand = lpTbb[nCount].idCommand;
    1787         btnPtr->fsState   = lpTbb[nCount].fsState;
    1788         btnPtr->fsStyle   = lpTbb[nCount].fsStyle;
    1789         btnPtr->dwData    = lpTbb[nCount].dwData;
    1790         btnPtr->iString   = lpTbb[nCount].iString;
    1791         btnPtr->bHot      = FALSE;
    1792 
    1793         if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
    1794             TTTOOLINFOW ti;
    1795 
    1796             ZeroMemory (&ti, sizeof(TTTOOLINFOW));
    1797             ti.cbSize   = sizeof (TTTOOLINFOW);
    1798             ti.hwnd     = hwnd;
    1799             ti.uId      = btnPtr->idCommand;
    1800             ti.hinst    = 0;
    1801             ti.lpszText = LPSTR_TEXTCALLBACKW;
    1802 
    1803             SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
    1804                             0, (LPARAM)&ti);
    1805         }
     1204        TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
     1205        btnPtr->iBitmap   = lpTbb[nCount].iBitmap;
     1206        btnPtr->idCommand = lpTbb[nCount].idCommand;
     1207        btnPtr->fsState   = lpTbb[nCount].fsState;
     1208        btnPtr->fsStyle   = lpTbb[nCount].fsStyle;
     1209        btnPtr->dwData    = lpTbb[nCount].dwData;
     1210        btnPtr->iString   = lpTbb[nCount].iString;
     1211        btnPtr->bHot      = FALSE;
     1212
     1213        if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
     1214            TTTOOLINFOA ti;
     1215
     1216            ZeroMemory (&ti, sizeof(TTTOOLINFOA));
     1217            ti.cbSize   = sizeof (TTTOOLINFOA);
     1218            ti.hwnd     = hwnd;
     1219            ti.uId      = btnPtr->idCommand;
     1220            ti.hinst    = 0;
     1221            ti.lpszText = LPSTR_TEXTCALLBACKA;
     1222
     1223            SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
     1224                            0, (LPARAM)&ti);
     1225        }
    18061226    }
    18071227
     
    18151235
    18161236static LRESULT
     1237TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
     1238{
     1239    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     1240    LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
     1241    INT nOldButtons, nNewButtons, nAddButtons, nCount;
     1242
     1243    // TRACE("adding %d buttons!\n", wParam);
     1244
     1245    nAddButtons = (UINT)wParam;
     1246    nOldButtons = infoPtr->nNumButtons;
     1247    nNewButtons = nOldButtons + nAddButtons;
     1248
     1249    if (infoPtr->nNumButtons == 0) {
     1250        infoPtr->buttons =
     1251            (TBUTTON_INFO*)COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
     1252    }
     1253    else {
     1254        TBUTTON_INFO *oldButtons = infoPtr->buttons;
     1255        infoPtr->buttons =
     1256            (TBUTTON_INFO*)COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
     1257        memcpy (&infoPtr->buttons[0], &oldButtons[0],
     1258                nOldButtons * sizeof(TBUTTON_INFO));
     1259        COMCTL32_Free (oldButtons);
     1260    }
     1261
     1262    infoPtr->nNumButtons = nNewButtons;
     1263
     1264    /* insert new button data */
     1265    for (nCount = 0; nCount < nAddButtons; nCount++) {
     1266        TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
     1267        btnPtr->iBitmap   = lpTbb[nCount].iBitmap;
     1268        btnPtr->idCommand = lpTbb[nCount].idCommand;
     1269        btnPtr->fsState   = lpTbb[nCount].fsState;
     1270        btnPtr->fsStyle   = lpTbb[nCount].fsStyle;
     1271        btnPtr->dwData    = lpTbb[nCount].dwData;
     1272        btnPtr->iString   = lpTbb[nCount].iString;
     1273        btnPtr->bHot      = FALSE;
     1274
     1275        if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
     1276            TTTOOLINFOW ti;
     1277
     1278            ZeroMemory (&ti, sizeof(TTTOOLINFOW));
     1279            ti.cbSize   = sizeof (TTTOOLINFOW);
     1280            ti.hwnd     = hwnd;
     1281            ti.uId      = btnPtr->idCommand;
     1282            ti.hinst    = 0;
     1283            ti.lpszText = LPSTR_TEXTCALLBACKW;
     1284
     1285            SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
     1286                            0, (LPARAM)&ti);
     1287        }
     1288    }
     1289
     1290    TOOLBAR_CalcToolbar (hwnd);
     1291
     1292    InvalidateRect(hwnd, NULL, FALSE);
     1293
     1294    return TRUE;
     1295}
     1296
     1297
     1298static LRESULT
    18171299TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
    18181300{
     
    18211303
    18221304    if ((wParam) && (HIWORD(lParam) == 0)) {
    1823         char szString[256];
    1824         INT len;
    1825 //      TRACE (toolbar, "adding string from resource!\n");
    1826 
    1827         len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
    1828                              szString, 256);
    1829 
    1830 //      TRACE (toolbar, "len=%d \"%s\"\n", len, szString);
    1831         nIndex = infoPtr->nNumStrings;
    1832         if (infoPtr->nNumStrings == 0) {
    1833             infoPtr->strings =
    1834                 (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR));
    1835         }
    1836         else {
    1837             LPWSTR *oldStrings = infoPtr->strings;
    1838             infoPtr->strings =
    1839                 (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
    1840             memcpy (&infoPtr->strings[0], &oldStrings[0],
    1841                     sizeof(LPWSTR) * infoPtr->nNumStrings);
    1842             COMCTL32_Free (oldStrings);
    1843         }
    1844 
    1845         infoPtr->strings[infoPtr->nNumStrings] =
    1846             (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
    1847         lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], szString);
    1848         infoPtr->nNumStrings++;
     1305        char szString[256];
     1306        INT len;
     1307        // TRACE("adding string from resource!\n");
     1308
     1309        len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
     1310                             szString, 256);
     1311
     1312        // TRACE("len=%d \"%s\"\n", len, szString);
     1313        nIndex = infoPtr->nNumStrings;
     1314        if (infoPtr->nNumStrings == 0) {
     1315            infoPtr->strings =
     1316                (LPWSTR*) COMCTL32_Alloc (sizeof(LPWSTR));
     1317        }
     1318        else {
     1319            LPWSTR *oldStrings = infoPtr->strings;
     1320            infoPtr->strings =
     1321                (LPWSTR*) COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
     1322            memcpy (&infoPtr->strings[0], &oldStrings[0],
     1323                    sizeof(LPWSTR) * infoPtr->nNumStrings);
     1324            COMCTL32_Free (oldStrings);
     1325        }
     1326
     1327        infoPtr->strings[infoPtr->nNumStrings] =
     1328            (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
     1329        lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], szString);
     1330        infoPtr->nNumStrings++;
    18491331    }
    18501332    else {
    1851         LPSTR p = (LPSTR)lParam;
    1852         INT len;
    1853 
    1854         if (p == NULL)
    1855             return -1;
    1856 //      TRACE (toolbar, "adding string(s) from array!\n");
    1857         nIndex = infoPtr->nNumStrings;
    1858         while (*p) {
    1859             len = lstrlenA (p);
    1860 //          TRACE (toolbar, "len=%d \"%s\"\n", len, p);
    1861 
     1333        LPSTR p = (LPSTR)lParam;
     1334        INT len;
     1335
     1336        if (p == NULL)
     1337            return -1;
     1338        // TRACE("adding string(s) from array!\n");
     1339
     1340        nIndex = infoPtr->nNumStrings;
     1341        while (*p) {
     1342            len = lstrlenA (p);
     1343            // TRACE("len=%d \"%s\"\n", len, p);
     1344
     1345            if (infoPtr->nNumStrings == 0) {
     1346                infoPtr->strings =
     1347                   (LPWSTR*) COMCTL32_Alloc (sizeof(LPWSTR));
     1348            }
     1349            else {
     1350                LPWSTR *oldStrings = infoPtr->strings;
     1351                infoPtr->strings =
     1352                    (LPWSTR*) COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
     1353                memcpy (&infoPtr->strings[0], &oldStrings[0],
     1354                        sizeof(LPWSTR) * infoPtr->nNumStrings);
     1355                COMCTL32_Free (oldStrings);
     1356            }
     1357
     1358            infoPtr->strings[infoPtr->nNumStrings] =
     1359                (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
     1360            lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], p);
     1361            infoPtr->nNumStrings++;
     1362
     1363            p += (len+1);
     1364        }
     1365    }
     1366
     1367    return nIndex;
     1368}
     1369
     1370
     1371static LRESULT
     1372TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
     1373{
     1374#define MAX_RESOURCE_STRING_LENGTH 512
     1375    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     1376    INT nIndex;
     1377
     1378    if ((wParam) && (HIWORD(lParam) == 0)) {
     1379        WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
     1380        INT len;
     1381        // TRACE("adding string from resource!\n");
     1382
     1383        len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
     1384                             szString, MAX_RESOURCE_STRING_LENGTH);
     1385
     1386        // TRACE("len=%d \"%s\"\n", len, debugstr_w(szString));
     1387        // TRACE("First char: 0x%x\n", *szString);
     1388        if (szString[0] == L'|')
     1389        {
     1390            PWSTR p = szString + 1;
     1391               
     1392            nIndex = infoPtr->nNumStrings;
     1393            while (*p != L'|') {
     1394
     1395            if (infoPtr->nNumStrings == 0) {
     1396                infoPtr->strings =
     1397                    (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR));
     1398            }
     1399            else {
     1400                LPWSTR *oldStrings = infoPtr->strings;
     1401                infoPtr->strings =
     1402                    (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
     1403                memcpy (&infoPtr->strings[0], &oldStrings[0],
     1404                        sizeof(LPWSTR) * infoPtr->nNumStrings);
     1405                COMCTL32_Free (oldStrings);
     1406            }
     1407
     1408            len = COMCTL32_StrChrW (p, L'|') - p;
     1409            // TRACE("len=%d \"%s\"\n", len, debugstr_w(p));
     1410            infoPtr->strings[infoPtr->nNumStrings] =
     1411                (WCHAR *)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
     1412            lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len);
     1413            infoPtr->nNumStrings++;
     1414
     1415                p += (len+1);
     1416            }
     1417        }
     1418        else
     1419        {
     1420            nIndex = infoPtr->nNumStrings;
    18621421            if (infoPtr->nNumStrings == 0) {
    18631422                infoPtr->strings =
     
    18751434            infoPtr->strings[infoPtr->nNumStrings] =
    18761435                (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
    1877             lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], p);
     1436            lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
    18781437            infoPtr->nNumStrings++;
    1879 
    1880             p += (len+1);
    18811438        }
    18821439    }
    1883 
    1884     return nIndex;
    1885 }
    1886 
    1887 
    1888 static LRESULT
    1889 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1890 {
    1891     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    1892     INT nIndex;
    1893 
    1894     if ((wParam) && (HIWORD(lParam) == 0)) {
    1895         WCHAR szString[256];
    1896         INT len;
    1897 //      TRACE (toolbar, "adding string from resource!\n");
    1898 
    1899         len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
    1900                              szString, 256);
    1901 
    1902 //      TRACE (toolbar, "len=%d \"%s\"\n", len, debugstr_w(szString));
    1903         nIndex = infoPtr->nNumStrings;
    1904         if (infoPtr->nNumStrings == 0) {
    1905             infoPtr->strings =
    1906                 (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR));
    1907         }
    1908         else {
    1909             LPWSTR *oldStrings = infoPtr->strings;
    1910             infoPtr->strings =
    1911                 (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
    1912             memcpy (&infoPtr->strings[0], &oldStrings[0],
    1913                     sizeof(LPWSTR) * infoPtr->nNumStrings);
    1914             COMCTL32_Free (oldStrings);
    1915         }
    1916 
    1917         infoPtr->strings[infoPtr->nNumStrings] =
    1918             (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
    1919         lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
    1920         infoPtr->nNumStrings++;
    1921     }
    19221440    else {
    1923         LPWSTR p = (LPWSTR)lParam;
    1924         INT len;
    1925 
    1926         if (p == NULL)
    1927             return -1;
    1928 //      TRACE (toolbar, "adding string(s) from array!\n");
    1929         nIndex = infoPtr->nNumStrings;
    1930         while (*p) {
    1931             len = lstrlenW (p);
    1932 //          TRACE (toolbar, "len=%d \"%s\"\n", len, debugstr_w(p));
    1933 
    1934             if (infoPtr->nNumStrings == 0) {
    1935                 infoPtr->strings =
    1936                     (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR));
    1937             }
    1938             else {
    1939                 LPWSTR *oldStrings = infoPtr->strings;
    1940                 infoPtr->strings =
    1941                     (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
    1942                 memcpy (&infoPtr->strings[0], &oldStrings[0],
    1943                         sizeof(LPWSTR) * infoPtr->nNumStrings);
    1944                 COMCTL32_Free (oldStrings);
    1945             }
    1946 
    1947             infoPtr->strings[infoPtr->nNumStrings] =
    1948                 (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
    1949             lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
    1950             infoPtr->nNumStrings++;
    1951 
    1952             p += (len+1);
    1953         }
     1441        LPWSTR p = (LPWSTR)lParam;
     1442        INT len;
     1443
     1444        if (p == NULL)
     1445            return -1;
     1446        // TRACE("adding string(s) from array!\n");
     1447        nIndex = infoPtr->nNumStrings;
     1448        while (*p) {
     1449            len = lstrlenW (p);
     1450
     1451            // TRACE("len=%d \"%s\"\n", len, debugstr_w(p));
     1452            if (infoPtr->nNumStrings == 0) {
     1453                infoPtr->strings =
     1454                    (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR));
     1455            }
     1456            else {
     1457                LPWSTR *oldStrings = infoPtr->strings;
     1458                infoPtr->strings =
     1459                    (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
     1460                memcpy (&infoPtr->strings[0], &oldStrings[0],
     1461                        sizeof(LPWSTR) * infoPtr->nNumStrings);
     1462                COMCTL32_Free (oldStrings);
     1463            }
     1464
     1465            infoPtr->strings[infoPtr->nNumStrings] =
     1466                (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
     1467            lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
     1468            infoPtr->nNumStrings++;
     1469
     1470            p += (len+1);
     1471        }
    19541472    }
    19551473
     
    19641482    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    19651483    RECT parent_rect;
     1484    RECT window_rect;
    19661485    HWND parent;
    19671486    INT  x, y;
    19681487    INT  cx, cy;
    1969     UINT uPosFlags = 0;
    1970 
    1971     //TRACE (toolbar, "resize forced!\n");
    1972 
    1973     x = y = 0;
     1488    UINT uPosFlags = SWP_NOZORDER;
     1489
     1490    // TRACE("resize forced, style=%lx!\n", dwStyle);
     1491
    19741492    parent = GetParent (hwnd);
    19751493    GetClientRect(parent, &parent_rect);
    19761494
     1495    x = parent_rect.left;
     1496    y = parent_rect.top;
     1497
    19771498    if (dwStyle & CCS_NORESIZE) {
    1978         uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
    1979         cx = 0;
    1980         cy = 0;
     1499        uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
     1500        cx = 0;
     1501        cy = 0;
    19811502    }
    19821503    else {
    1983         infoPtr->nWidth = parent_rect.right - parent_rect.left;
    1984         TOOLBAR_CalcToolbar (hwnd);
    1985         InvalidateRect( hwnd, NULL, TRUE );
    1986         cy = infoPtr->nHeight;
    1987         cx = infoPtr->nWidth;
     1504        infoPtr->nWidth = parent_rect.right - parent_rect.left;
     1505        TOOLBAR_CalcToolbar (hwnd);
     1506        InvalidateRect( hwnd, NULL, TRUE );
     1507        cy = infoPtr->nHeight;
     1508        cx = infoPtr->nWidth;
     1509
     1510        if (dwStyle & CCS_NOMOVEY) {
     1511                GetWindowRect(hwnd, &window_rect);
     1512                ScreenToClient(parent, (LPPOINT)&window_rect.left);
     1513                y = window_rect.top;
     1514        }
    19881515    }
    19891516
    19901517    if (dwStyle & CCS_NOPARENTALIGN)
    1991         uPosFlags |= SWP_NOMOVE;
     1518        uPosFlags |= SWP_NOMOVE;
    19921519
    19931520    if (!(dwStyle & CCS_NODIVIDER))
    1994         cy += GetSystemMetrics(SM_CYEDGE);
     1521        cy += GetSystemMetrics(SM_CYEDGE);
    19951522
    19961523    if (dwStyle & WS_BORDER)
     
    20031530    infoPtr->bAutoSize = TRUE;
    20041531    SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
    2005                     cx, cy, uPosFlags);
    2006 
     1532                        cx, cy, uPosFlags);
    20071533    /* The following line makes sure that the infoPtr->bAutoSize is turned off after
    20081534     * the setwindowpos calls */
     
    20281554
    20291555    if (infoPtr == NULL) {
    2030 //      ERR (toolbar, "(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
    2031 //      ERR (toolbar, "infoPtr == NULL!\n");
    2032         return 0;
     1556// ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
     1557// ERR("infoPtr == NULL!\n");
     1558        return 0;
    20331559    }
    20341560
     
    20441570    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    20451571    TBUTTON_INFO *btnPtr;
    2046     HDC hdc;
    20471572    INT nIndex;
    20481573
    20491574    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    20501575    if (nIndex == -1)
    2051         return FALSE;
     1576        return FALSE;
    20521577
    20531578    btnPtr = &infoPtr->buttons[nIndex];
    20541579    btnPtr->iBitmap = LOWORD(lParam);
    20551580
    2056     hdc = GetDC (hwnd);
    2057     TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    2058     ReleaseDC (hwnd, hdc);
     1581    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    20591582
    20601583    return TRUE;
     
    20671590    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    20681591    TBUTTON_INFO *btnPtr;
    2069     HDC hdc;
    20701592    INT nIndex;
    20711593    INT nOldIndex = -1;
     
    20741596    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    20751597    if (nIndex == -1)
    2076         return FALSE;
     1598        return FALSE;
    20771599
    20781600    btnPtr = &infoPtr->buttons[nIndex];
    20791601
    20801602    if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
    2081         return FALSE;
     1603        return FALSE;
    20821604
    20831605    bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
    20841606
    20851607    if (LOWORD(lParam) == FALSE)
    2086         btnPtr->fsState &= ~TBSTATE_CHECKED;
     1608        btnPtr->fsState &= ~TBSTATE_CHECKED;
    20871609    else {
    2088         if (btnPtr->fsStyle & TBSTYLE_GROUP) {
    2089             nOldIndex =
    2090                 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
    2091             if (nOldIndex == nIndex)
    2092                 return 0;
    2093             if (nOldIndex != -1)
    2094                 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
    2095         }
    2096         btnPtr->fsState |= TBSTATE_CHECKED;
     1610        if (btnPtr->fsStyle & TBSTYLE_GROUP) {
     1611            nOldIndex =
     1612                TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
     1613            if (nOldIndex == nIndex)
     1614                return 0;
     1615            if (nOldIndex != -1)
     1616                infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
     1617        }
     1618        btnPtr->fsState |= TBSTATE_CHECKED;
    20971619    }
    20981620
    20991621    if( bChecked != LOWORD(lParam) )
    21001622    {
    2101       hdc = GetDC (hwnd);
    2102       if (nOldIndex != -1)
    2103           TOOLBAR_DrawButton (hwnd, &infoPtr->buttons[nOldIndex], hdc);
    2104      TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    2105       ReleaseDC (hwnd, hdc);
     1623        if (nOldIndex != -1)
     1624            InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
     1625        InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    21061626    }
    21071627
     
    21191639    return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    21201640}
     1641
    21211642
    21221643static LRESULT
     
    21271648    LPCVOID temp;
    21281649    HRSRC hRes;
    2129 
    2130     if (infoPtr->nNumButtons == 0) return 0;
     1650    NMHDR nmhdr;
    21311651
    21321652    /* send TBN_BEGINADJUST notification */
    2133     sendNotify(hwnd,TBN_BEGINADJUST);
     1653    nmhdr.hwndFrom = hwnd;
     1654    nmhdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
     1655    nmhdr.code     = TBN_BEGINADJUST;
     1656
     1657    SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
     1658                  (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
    21341659
    21351660    if (!(hRes = FindResourceA (COMCTL32_hModule,
    21361661                                MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
    21371662                                RT_DIALOGA)))
    2138         return FALSE;
     1663        return FALSE;
    21391664
    21401665    if(!(temp = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
    2141         return FALSE;
     1666        return FALSE;
    21421667
    21431668    ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
     
    21481673
    21491674    /* send TBN_ENDADJUST notification */
    2150     sendNotify(hwnd,TBN_ENDADJUST);
     1675    nmhdr.code = TBN_ENDADJUST;
     1676
     1677    SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
     1678                  (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
    21511679
    21521680    return ret;
     
    21611689
    21621690    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    2163         return FALSE;
    2164 
    2165     if ((infoPtr->hwndToolTip) &&
    2166         !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
    2167         TTTOOLINFOA ti;
    2168 
    2169         ZeroMemory (&ti, sizeof(TTTOOLINFOA));
    2170         ti.cbSize   = sizeof (TTTOOLINFOA);
    2171         ti.hwnd     = hwnd;
    2172         ti.uId      = infoPtr->buttons[nIndex].idCommand;
    2173 
    2174         SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
    2175     }
    2176 
    2177     COMCTL32_Free(infoPtr->buttons[nIndex].pszName);
    2178 
    2179     if (infoPtr->nNumButtons == 1)
    2180     {
    2181 //      TRACE (toolbar, " simple delete!\n");
    2182         COMCTL32_Free (infoPtr->buttons);
    2183         infoPtr->buttons = NULL;
    2184         infoPtr->nNumButtons = 0;
    2185     } else
    2186     {
    2187         TBUTTON_INFO *oldButtons = infoPtr->buttons;
    2188 //        TRACE(toolbar, "complex delete! [nIndex=%d]\n", nIndex);
    2189 
    2190         infoPtr->nNumButtons--;
    2191         infoPtr->buttons = (TBUTTON_INFO*)COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
     1691        return FALSE;
     1692
     1693    if ((infoPtr->hwndToolTip) &&
     1694        !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
     1695        TTTOOLINFOA ti;
     1696
     1697        ZeroMemory (&ti, sizeof(TTTOOLINFOA));
     1698        ti.cbSize   = sizeof (TTTOOLINFOA);
     1699        ti.hwnd     = hwnd;
     1700        ti.uId      = infoPtr->buttons[nIndex].idCommand;
     1701
     1702        SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
     1703    }
     1704
     1705    if (infoPtr->nNumButtons == 1) {
     1706        // TRACE(" simple delete!\n");
     1707        COMCTL32_Free (infoPtr->buttons);
     1708        infoPtr->buttons = NULL;
     1709        infoPtr->nNumButtons = 0;
     1710    }
     1711    else {
     1712        TBUTTON_INFO *oldButtons = infoPtr->buttons;
     1713        // TRACE("complex delete! [nIndex=%d]\n", nIndex);
     1714
     1715        infoPtr->nNumButtons--;
     1716        infoPtr->buttons = (TBUTTON_INFO*)COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
    21921717        if (nIndex > 0) {
    21931718            memcpy (&infoPtr->buttons[0], &oldButtons[0],
     
    22001725        }
    22011726
    2202         COMCTL32_Free (oldButtons);
     1727        COMCTL32_Free (oldButtons);
    22031728    }
    22041729
     
    22161741    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    22171742    TBUTTON_INFO *btnPtr;
    2218     HDC hdc;
    22191743    INT nIndex;
    2220     BOOL bEnabled = FALSE;
     1744    DWORD bState;
    22211745
    22221746    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    22231747    if (nIndex == -1)
    2224         return FALSE;
     1748        return FALSE;
    22251749
    22261750    btnPtr = &infoPtr->buttons[nIndex];
    2227     bEnabled = (btnPtr->fsState & TBSTATE_ENABLED )? TRUE : FALSE ;
    2228 
    2229     if (LOWORD(lParam) == FALSE)
    2230         btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
    2231     else
    2232         btnPtr->fsState |= TBSTATE_ENABLED;
    2233 
    2234     if( bEnabled !=  LOWORD(lParam) )
    2235     {
    2236       hdc = GetDC (hwnd);
    2237       TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    2238       ReleaseDC (hwnd, hdc);
    2239     }
     1751
     1752    bState = btnPtr->fsState & TBSTATE_ENABLED;
     1753
     1754    /* update the toolbar button state */
     1755    if(LOWORD(lParam) == FALSE) {
     1756        btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
     1757    } else {
     1758        btnPtr->fsState |= TBSTATE_ENABLED;
     1759    }
     1760
     1761    /* redraw the button only if the state of the button changed */
     1762    if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
     1763        InvalidateRect(hwnd, &btnPtr->rect, TRUE);           
    22401764
    22411765    return TRUE;
     
    22431767
    22441768
    2245 static LRESULT
     1769static inline LRESULT
    22461770TOOLBAR_GetAnchorHighlight (HWND hwnd)
    22471771{
     
    22601784    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    22611785    if (nIndex == -1)
    2262         return -1;
     1786        return -1;
    22631787
    22641788    return infoPtr->buttons[nIndex].iBitmap;
     
    22661790
    22671791
    2268 static LRESULT
     1792static inline LRESULT
    22691793TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
    22701794{
     
    22821806
    22831807    if (infoPtr == NULL)
    2284         return FALSE;
     1808        return FALSE;
    22851809
    22861810    if (lpTbb == NULL)
    2287         return FALSE;
     1811        return FALSE;
    22881812
    22891813    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    2290         return FALSE;
     1814        return FALSE;
    22911815
    22921816    btnPtr = &infoPtr->buttons[nIndex];
     
    23111835
    23121836    if (infoPtr == NULL)
    2313         return -1;
     1837        return -1;
    23141838    if (lpTbInfo == NULL)
    2315         return -1;
     1839        return -1;
    23161840    if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
    2317         return -1;
     1841        return -1;
    23181842
    23191843    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    23201844    if (nIndex == -1)
    2321         return -1;
     1845        return -1;
    23221846
    23231847    btnPtr = &infoPtr->buttons[nIndex];
    23241848
    23251849    if (lpTbInfo->dwMask & TBIF_COMMAND)
    2326         lpTbInfo->idCommand = btnPtr->idCommand;
     1850        lpTbInfo->idCommand = btnPtr->idCommand;
    23271851    if (lpTbInfo->dwMask & TBIF_IMAGE)
    2328         lpTbInfo->iImage = btnPtr->iBitmap;
     1852        lpTbInfo->iImage = btnPtr->iBitmap;
    23291853    if (lpTbInfo->dwMask & TBIF_LPARAM)
    2330         lpTbInfo->lParam = btnPtr->dwData;
     1854        lpTbInfo->lParam = btnPtr->dwData;
    23311855    if (lpTbInfo->dwMask & TBIF_SIZE)
    2332         lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
     1856        lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
    23331857    if (lpTbInfo->dwMask & TBIF_STATE)
    2334         lpTbInfo->fsState = btnPtr->fsState;
     1858        lpTbInfo->fsState = btnPtr->fsState;
    23351859    if (lpTbInfo->dwMask & TBIF_STYLE)
    2336         lpTbInfo->fsStyle = btnPtr->fsStyle;
    2337     if (lpTbInfo->dwMask & TBIF_TEXT) {
    2338         if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
    2339             lstrcpynWtoA (lpTbInfo->pszText,
    2340                          infoPtr->strings[btnPtr->iString],
    2341                          lpTbInfo->cchText);
    2342     }
    2343 
     1860        lpTbInfo->fsStyle = btnPtr->fsStyle;
     1861     if (lpTbInfo->dwMask & TBIF_TEXT) {
     1862         if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
     1863         {     
     1864             lstrcpynWtoA (lpTbInfo->pszText,
     1865                           (LPWSTR)infoPtr->strings[btnPtr->iString],
     1866                           lpTbInfo->cchText);
     1867         }
     1868         else lpTbInfo->pszText[0]=0;
     1869    }
    23441870    return nIndex;
    23451871}
    23461872
    2347 static LRESULT TOOLBAR_GetButtonInfoW(HWND hwnd,WPARAM wParam,LPARAM lParam)
     1873
     1874static LRESULT
     1875TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    23481876{
    23491877    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     
    23531881
    23541882    if (infoPtr == NULL)
    2355         return -1;
     1883        return -1;
    23561884    if (lpTbInfo == NULL)
    2357         return -1;
     1885        return -1;
    23581886    if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
    2359         return -1;
     1887        return -1;
    23601888
    23611889    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    23621890    if (nIndex == -1)
    2363         return -1;
     1891        return -1;
    23641892
    23651893    btnPtr = &infoPtr->buttons[nIndex];
    23661894
    23671895    if (lpTbInfo->dwMask & TBIF_COMMAND)
    2368         lpTbInfo->idCommand = btnPtr->idCommand;
     1896        lpTbInfo->idCommand = btnPtr->idCommand;
    23691897    if (lpTbInfo->dwMask & TBIF_IMAGE)
    2370         lpTbInfo->iImage = btnPtr->iBitmap;
     1898        lpTbInfo->iImage = btnPtr->iBitmap;
    23711899    if (lpTbInfo->dwMask & TBIF_LPARAM)
    2372         lpTbInfo->lParam = btnPtr->dwData;
     1900        lpTbInfo->lParam = btnPtr->dwData;
    23731901    if (lpTbInfo->dwMask & TBIF_SIZE)
    2374         lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
     1902        lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
    23751903    if (lpTbInfo->dwMask & TBIF_STATE)
    2376         lpTbInfo->fsState = btnPtr->fsState;
     1904        lpTbInfo->fsState = btnPtr->fsState;
    23771905    if (lpTbInfo->dwMask & TBIF_STYLE)
    2378         lpTbInfo->fsStyle = btnPtr->fsStyle;
     1906        lpTbInfo->fsStyle = btnPtr->fsStyle;
    23791907    if (lpTbInfo->dwMask & TBIF_TEXT) {
    2380         if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
    2381             lstrcpynW (lpTbInfo->pszText,
    2382                        infoPtr->strings[btnPtr->iString],
    2383                        lpTbInfo->cchText);
     1908        if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
     1909            lstrcpynW (lpTbInfo->pszText,
     1910                       (LPWSTR)infoPtr->strings[btnPtr->iString],
     1911                       lpTbInfo->cchText);
    23841912    }
    23851913
     
    23941922
    23951923    return MAKELONG((WORD)infoPtr->nButtonWidth,
    2396                     (WORD)infoPtr->nButtonHeight);
     1924                    (WORD)infoPtr->nButtonHeight);
    23971925}
    23981926
     
    24061934    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    24071935    if (nIndex == -1)
    2408         return -1;
     1936        return -1;
    24091937
    24101938    nStringIndex = infoPtr->buttons[nIndex].iString;
    24111939
    2412 //    TRACE (toolbar, "index=%d stringIndex=%d\n", nIndex, nStringIndex);
     1940    // TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
    24131941
    24141942    if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
    2415         return -1;
    2416 
    2417     if (lParam == 0) return -1;
    2418 
    2419     lstrcpyWtoA ((LPSTR)lParam, infoPtr->strings[nStringIndex]);
    2420 
    2421     return lstrlenW (infoPtr->strings[nStringIndex]);
    2422 }
    2423 
    2424 static LRESULT TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
     1943        return -1;
     1944
     1945    if (lParam == 0)
     1946        return -1;
     1947
     1948    lstrcpyWtoA ((LPSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);
     1949
     1950    return lstrlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
     1951}
     1952
     1953
     1954static LRESULT
     1955TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    24251956{
    24261957    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     
    24291960    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    24301961    if (nIndex == -1)
    2431         return -1;
     1962        return -1;
    24321963
    24331964    nStringIndex = infoPtr->buttons[nIndex].iString;
    24341965
    2435 //    TRACE (toolbar, "index=%d stringIndex=%d\n", nIndex, nStringIndex);
     1966    // TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
    24361967
    24371968    if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
    2438         return -1;
    2439 
    2440     if (lParam == 0) return -1;
    2441 
    2442     lstrcpyW ((LPWSTR)lParam, infoPtr->strings[nStringIndex]);
    2443 
    2444     return lstrlenW (infoPtr->strings[nStringIndex]);
    2445 }
    2446 
    2447 /* << TOOLBAR_GetButtonText32W >> */
     1969        return -1;
     1970
     1971    if (lParam == 0)
     1972        return -1;
     1973
     1974    lstrcpyW ((LPWSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);
     1975
     1976    return lstrlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
     1977}
     1978
     1979
    24481980/* << TOOLBAR_GetColorScheme >> */
    24491981
     
    24581990
    24591991
    2460 static LRESULT
     1992inline static LRESULT
    24611993TOOLBAR_GetExtendedStyle (HWND hwnd)
    24621994{
     
    24822014
    24832015    if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
    2484         return -1;
     2016        return -1;
    24852017
    24862018    if (infoPtr->nHotItem < 0)
    2487         return -1;
     2019        return -1;
    24882020
    24892021    return (LRESULT)infoPtr->nHotItem;
     
    25132045
    25142046    if (infoPtr == NULL)
    2515         return FALSE;
     2047        return FALSE;
    25162048    nIndex = (INT)wParam;
    25172049    btnPtr = &infoPtr->buttons[nIndex];
    25182050    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    2519         return FALSE;
     2051        return FALSE;
    25202052    lpRect = (LPRECT)lParam;
    25212053    if (lpRect == NULL)
    2522         return FALSE;
     2054        return FALSE;
    25232055    if (btnPtr->fsState & TBSTATE_HIDDEN)
    2524         return FALSE;
    2525 
     2056        return FALSE;
     2057   
    25262058    TOOLBAR_CalcToolbar( hwnd );
    2527 
     2059   
    25282060    lpRect->left   = btnPtr->rect.left;
    25292061    lpRect->right  = btnPtr->rect.right;
     
    25422074
    25432075    if (lpSize == NULL)
    2544         return FALSE;
     2076        return FALSE;
    25452077
    25462078    lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
    25472079    lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
    25482080
    2549 //    TRACE (toolbar, "maximum size %d x %d\n",
    2550 //        infoPtr->rcBound.right - infoPtr->rcBound.left,
    2551 //         infoPtr->rcBound.bottom - infoPtr->rcBound.top);
     2081    // TRACE("maximum size %d x %d\n",
     2082    // infoPtr->rcBound.right - infoPtr->rcBound.left,
     2083    //  infoPtr->rcBound.bottom - infoPtr->rcBound.top);
    25522084
    25532085    return TRUE;
     
    25682100
    25692101    if (infoPtr == NULL)
    2570         return FALSE;
     2102        return FALSE;
    25712103    nIndex = (INT)wParam;
    25722104    btnPtr = &infoPtr->buttons[nIndex];
    25732105    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    2574         return FALSE;
     2106        return FALSE;
    25752107    lpRect = (LPRECT)lParam;
    25762108    if (lpRect == NULL)
    2577         return FALSE;
    2578 
     2109        return FALSE;
     2110   
    25792111    lpRect->left   = btnPtr->rect.left;
    25802112    lpRect->right  = btnPtr->rect.right;
     
    25922124
    25932125    if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
    2594         return infoPtr->nRows;
     2126        return infoPtr->nRows;
    25952127    else
    2596         return 1;
     2128        return 1;
    25972129}
    25982130
     
    26062138    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    26072139    if (nIndex == -1)
    2608         return -1;
     2140        return -1;
    26092141
    26102142    return infoPtr->buttons[nIndex].fsState;
     
    26202152    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    26212153    if (nIndex == -1)
    2622         return -1;
     2154        return -1;
    26232155
    26242156    return infoPtr->buttons[nIndex].fsStyle;
     
    26322164
    26332165    if (infoPtr == NULL)
    2634         return 0;
     2166        return 0;
    26352167
    26362168    return infoPtr->nMaxTextRows;
     
    26432175    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    26442176
    2645     if (infoPtr == NULL) return 0;
     2177    if (infoPtr == NULL)
     2178        return 0;
    26462179    return infoPtr->hwndToolTip;
     2180}
     2181
     2182
     2183static LRESULT
     2184TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
     2185{
     2186    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     2187
     2188    // TRACE("%s hwnd=0x%x stub!\n",
     2189//  infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
     2190
     2191    return infoPtr->bUnicode;
     2192}
     2193
     2194
     2195inline static LRESULT
     2196TOOLBAR_GetVersion (HWND hwnd)
     2197{
     2198    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     2199    return infoPtr->iVersion;
    26472200}
    26482201
     
    26572210    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    26582211    if (nIndex == -1)
    2659         return FALSE;
     2212        return FALSE;
    26602213
    26612214    btnPtr = &infoPtr->buttons[nIndex];
    26622215    if (LOWORD(lParam) == FALSE)
    2663         btnPtr->fsState &= ~TBSTATE_HIDDEN;
     2216        btnPtr->fsState &= ~TBSTATE_HIDDEN;
    26642217    else
    2665         btnPtr->fsState |= TBSTATE_HIDDEN;
     2218        btnPtr->fsState |= TBSTATE_HIDDEN;
    26662219
    26672220    TOOLBAR_CalcToolbar (hwnd);
     
    26732226
    26742227
    2675 static LRESULT
     2228inline static LRESULT
    26762229TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
    26772230{
     
    26852238    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    26862239    TBUTTON_INFO *btnPtr;
    2687     HDC hdc;
    26882240    INT nIndex;
    26892241
    26902242    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    26912243    if (nIndex == -1)
    2692         return FALSE;
     2244        return FALSE;
    26932245
    26942246    btnPtr = &infoPtr->buttons[nIndex];
    26952247    if (LOWORD(lParam) == FALSE)
    2696         btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
     2248        btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
    26972249    else
    2698         btnPtr->fsState |= TBSTATE_INDETERMINATE;
    2699 
    2700     hdc = GetDC (hwnd);
    2701     TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    2702     ReleaseDC (hwnd, hdc);
     2250        btnPtr->fsState |= TBSTATE_INDETERMINATE;
     2251
     2252    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    27032253
    27042254    return TRUE;
     
    27152265
    27162266    if (lpTbb == NULL)
    2717         return FALSE;
     2267        return FALSE;
    27182268
    27192269    if (nIndex == -1) {
    27202270       /* EPP: this seems to be an undocumented call (from my IE4)
    2721         * I assume in that case that:
    2722         * - lpTbb->iString is a string pointer (not a string index in strings[] table
    2723         * - index of insertion is at the end of existing buttons
    2724         * I only see this happen with nIndex == -1, but it could have a special
    2725         * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
    2726         */
    2727        int      len = lstrlenA((char*)lpTbb->iString) + 2;
    2728        LPSTR    ptr = (LPSTR)COMCTL32_Alloc(len);
    2729 
    2730        nIndex = infoPtr->nNumButtons;
    2731        strcpy(ptr, (char*)lpTbb->iString);
    2732        ptr[len - 1] = 0; /* ended by two '\0' */
    2733        lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
    2734        COMCTL32_Free(ptr);
     2271        * I assume in that case that:
     2272        * - lpTbb->iString is a string pointer (not a string index in strings[] table
     2273        * - index of insertion is at the end of existing buttons
     2274        * I only see this happen with nIndex == -1, but it could have a special
     2275        * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
     2276        */
     2277       int      len;
     2278       LPSTR    ptr;
     2279
     2280       if(lpTbb->iString) {
     2281           len = lstrlenA((char*)lpTbb->iString) + 2;
     2282           ptr = (CHAR*)COMCTL32_Alloc(len);
     2283           nIndex = infoPtr->nNumButtons;
     2284           strcpy(ptr, (char*)lpTbb->iString);
     2285           ptr[len - 1] = 0; /* ended by two '\0' */
     2286           lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
     2287           COMCTL32_Free(ptr);
     2288       }
     2289       else {
     2290  //         ERR("lpTbb->iString is NULL\n");
     2291           return FALSE;
     2292       }
    27352293
    27362294    } else if (nIndex < 0)
    27372295       return FALSE;
    27382296
    2739 
    2740 //    TRACE (toolbar, "inserting button index=%d\n", nIndex);
     2297    // TRACE("inserting button index=%d\n", nIndex);
    27412298    if (nIndex > infoPtr->nNumButtons) {
    2742         nIndex = infoPtr->nNumButtons;
    2743 //      TRACE (toolbar, "adjust index=%d\n", nIndex);
     2299        nIndex = infoPtr->nNumButtons;
     2300        // TRACE("adjust index=%d\n", nIndex);
    27442301    }
    27452302
     
    27492306    /* pre insert copy */
    27502307    if (nIndex > 0) {
    2751         memcpy (&infoPtr->buttons[0], &oldButtons[0],
    2752                 nIndex * sizeof(TBUTTON_INFO));
     2308        memcpy (&infoPtr->buttons[0], &oldButtons[0],
     2309                nIndex * sizeof(TBUTTON_INFO));
    27532310    }
    27542311
     
    27622319
    27632320    if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
    2764         TTTOOLINFOA ti;
    2765 
    2766         ZeroMemory (&ti, sizeof(TTTOOLINFOA));
    2767         ti.cbSize   = sizeof (TTTOOLINFOA);
    2768         ti.hwnd     = hwnd;
    2769         ti.uId      = lpTbb->idCommand;
    2770         ti.hinst    = 0;
    2771         ti.lpszText = LPSTR_TEXTCALLBACKA;
    2772 
    2773         SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
    2774                         0, (LPARAM)&ti);
     2321        TTTOOLINFOA ti;
     2322
     2323        ZeroMemory (&ti, sizeof(TTTOOLINFOA));
     2324        ti.cbSize   = sizeof (TTTOOLINFOA);
     2325        ti.hwnd     = hwnd;
     2326        ti.uId      = lpTbb->idCommand;
     2327        ti.hinst    = 0;
     2328        ti.lpszText = LPSTR_TEXTCALLBACKA;
     2329
     2330        SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
     2331                        0, (LPARAM)&ti);
    27752332    }
    27762333
    27772334    /* post insert copy */
    27782335    if (nIndex < infoPtr->nNumButtons - 1) {
    2779         memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
    2780                 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
     2336        memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
     2337                (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
    27812338    }
    27822339
     
    27902347}
    27912348
    2792 static LRESULT TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    2793 {
    2794   //CB: just call InsertButtonA, no Unicode used?!?
    2795 
    2796   return TOOLBAR_InsertButtonA(hwnd,wParam,lParam);
    2797 }
     2349
     2350static LRESULT
     2351TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
     2352{
     2353    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     2354    LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
     2355    INT nIndex = (INT)wParam;
     2356    TBUTTON_INFO *oldButtons;
     2357
     2358    if (lpTbb == NULL)
     2359        return FALSE;
     2360    if (nIndex < 0)
     2361        return FALSE;
     2362
     2363    // TRACE("inserting button index=%d\n", nIndex);
     2364    if (nIndex > infoPtr->nNumButtons) {
     2365        nIndex = infoPtr->nNumButtons;
     2366        // TRACE("adjust index=%d\n", nIndex);
     2367    }
     2368
     2369    oldButtons = infoPtr->buttons;
     2370    infoPtr->nNumButtons++;
     2371    infoPtr->buttons = (TBUTTON_INFO*)COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
     2372    /* pre insert copy */
     2373    if (nIndex > 0) {
     2374        memcpy (&infoPtr->buttons[0], &oldButtons[0],
     2375                nIndex * sizeof(TBUTTON_INFO));
     2376    }
     2377
     2378    /* insert new button */
     2379    infoPtr->buttons[nIndex].iBitmap   = lpTbb->iBitmap;
     2380    infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
     2381    infoPtr->buttons[nIndex].fsState   = lpTbb->fsState;
     2382    infoPtr->buttons[nIndex].fsStyle   = lpTbb->fsStyle;
     2383    infoPtr->buttons[nIndex].dwData    = lpTbb->dwData;
     2384    infoPtr->buttons[nIndex].iString   = lpTbb->iString;
     2385
     2386    if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
     2387        TTTOOLINFOW ti;
     2388
     2389        ZeroMemory (&ti, sizeof(TTTOOLINFOW));
     2390        ti.cbSize   = sizeof (TTTOOLINFOW);
     2391        ti.hwnd     = hwnd;
     2392        ti.uId      = lpTbb->idCommand;
     2393        ti.hinst    = 0;
     2394        ti.lpszText = LPSTR_TEXTCALLBACKW;
     2395
     2396        SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
     2397                        0, (LPARAM)&ti);
     2398    }
     2399
     2400    /* post insert copy */
     2401    if (nIndex < infoPtr->nNumButtons - 1) {
     2402        memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
     2403                (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
     2404    }
     2405
     2406    COMCTL32_Free (oldButtons);
     2407
     2408    TOOLBAR_CalcToolbar (hwnd);
     2409
     2410    InvalidateRect (hwnd, NULL, FALSE);
     2411
     2412    return TRUE;
     2413}
     2414
    27982415
    27992416/* << TOOLBAR_InsertMarkHitTest >> */
     
    28082425    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    28092426    if (nIndex == -1)
    2810         return FALSE;
     2427        return FALSE;
    28112428
    28122429    return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
     
    28222439    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    28232440    if (nIndex == -1)
    2824         return FALSE;
     2441        return FALSE;
    28252442
    28262443    return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
     
    28362453    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    28372454    if (nIndex == -1)
    2838         return FALSE;
     2455        return FALSE;
    28392456
    28402457    return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
     
    28502467    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    28512468    if (nIndex == -1)
    2852         return FALSE;
     2469        return FALSE;
    28532470
    28542471    return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
     
    28642481    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    28652482    if (nIndex == -1)
    2866         return FALSE;
     2483        return FALSE;
    28672484
    28682485    return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
     
    28782495    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    28792496    if (nIndex == -1)
    2880         return FALSE;
     2497        return FALSE;
    28812498
    28822499    return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
     
    28952512    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    28962513    TBUTTON_INFO *btnPtr;
    2897     HDC hdc;
    28982514    INT nIndex;
    28992515
    29002516    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    29012517    if (nIndex == -1)
    2902         return FALSE;
     2518        return FALSE;
    29032519
    29042520    btnPtr = &infoPtr->buttons[nIndex];
    29052521    if (LOWORD(lParam) == FALSE)
    2906         btnPtr->fsState &= ~TBSTATE_PRESSED;
     2522        btnPtr->fsState &= ~TBSTATE_PRESSED;
    29072523    else
    2908         btnPtr->fsState |= TBSTATE_PRESSED;
    2909 
    2910     hdc = GetDC (hwnd);
    2911     TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    2912     ReleaseDC (hwnd, hdc);
     2524        btnPtr->fsState |= TBSTATE_PRESSED;
     2525
     2526    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    29132527
    29142528    return TRUE;
     
    29292543
    29302544    if ((BOOL)wParam) {
    2931         /* save toolbar information */
    2932 //      FIXME (toolbar, "save to \"%s\" \"%s\"\n",
    2933 //             lpSave->pszSubKey, lpSave->pszValueName);
     2545        /* save toolbar information */
     2546        // FIXME("save to \"%s\" \"%s\"\n",
     2547               lpSave->pszSubKey, lpSave->pszValueName);
    29342548
    29352549
    29362550    }
    29372551    else {
    2938         /* restore toolbar information */
    2939 
    2940 //      FIXME (toolbar, "restore from \"%s\" \"%s\"\n",
    2941 //             lpSave->pszSubKey, lpSave->pszValueName);
     2552        /* restore toolbar information */
     2553
     2554        // FIXME("restore from \"%s\" \"%s\"\n",
     2555               lpSave->pszSubKey, lpSave->pszValueName);
    29422556
    29432557
     
    29482562}
    29492563
    2950 static LRESULT TOOLBAR_SaveRestoreW(HWND hwnd,WPARAM wParam,LPARAM lParam)
     2564
     2565static LRESULT
     2566TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    29512567{
    29522568#if 0
     
    29542570    LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
    29552571
    2956     if (lpSave == NULL) return 0;
     2572    if (lpSave == NULL)
     2573        return 0;
    29572574
    29582575    if ((BOOL)wParam) {
    2959         /* save toolbar information */
    2960 //      FIXME (toolbar, "save to \"%s\" \"%s\"\n",
    2961 //             lpSave->pszSubKey, lpSave->pszValueName);
     2576        /* save toolbar information */
     2577        // FIXME("save to \"%s\" \"%s\"\n",
     2578               lpSave->pszSubKey, lpSave->pszValueName);
    29622579
    29632580
    29642581    }
    29652582    else {
    2966         /* restore toolbar information */
    2967 
    2968 //      FIXME (toolbar, "restore from \"%s\" \"%s\"\n",
    2969 //             lpSave->pszSubKey, lpSave->pszValueName);
     2583        /* restore toolbar information */
     2584
     2585        // FIXME("restore from \"%s\" \"%s\"\n",
     2586               lpSave->pszSubKey, lpSave->pszValueName);
    29702587
    29712588
     
    29762593}
    29772594
    2978 /* << TOOLBAR_SaveRestore32W >> */
    29792595
    29802596static LRESULT
     
    29952611    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    29962612
    2997     if (((INT)LOWORD(lParam) <= 0) || ((INT)HIWORD(lParam) <= 0)) return FALSE;
    2998 
    2999     /* Bitmap size can only be set before adding any button to the toolbar
    3000        according to the documentation.  */
    3001     if( infoPtr->nNumButtons != 0 )
    3002         return FALSE;
     2613    if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
     2614        return FALSE;
     2615
     2616//  if (infoPtr->nNumButtons > 0)
     2617//      WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
     2618//           infoPtr->nNumButtons,
     2619//           infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
     2620//           LOWORD(lParam), HIWORD(lParam));
    30032621
    30042622    infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
    30052623    infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
     2624
     2625    /* uses image list internals directly */
     2626    if (infoPtr->himlDef) {
     2627        infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
     2628        infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
     2629    }
    30062630
    30072631    return TRUE;
     
    30182642
    30192643    if (lptbbi == NULL)
    3020         return FALSE;
     2644        return FALSE;
    30212645    if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
    3022         return FALSE;
    3023 
     2646        return FALSE;
     2647   
    30242648    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    30252649    if (nIndex == -1)
    3026         return FALSE;
     2650        return FALSE;
    30272651
    30282652    btnPtr = &infoPtr->buttons[nIndex];
    30292653    if (lptbbi->dwMask & TBIF_COMMAND)
    3030         btnPtr->idCommand = lptbbi->idCommand;
     2654        btnPtr->idCommand = lptbbi->idCommand;
    30312655    if (lptbbi->dwMask & TBIF_IMAGE)
    3032         btnPtr->iBitmap = lptbbi->iImage;
     2656        btnPtr->iBitmap = lptbbi->iImage;
    30332657    if (lptbbi->dwMask & TBIF_LPARAM)
    3034         btnPtr->dwData = lptbbi->lParam;
     2658        btnPtr->dwData = lptbbi->lParam;
    30352659/*    if (lptbbi->dwMask & TBIF_SIZE) */
    3036 /*      btnPtr->cx = lptbbi->cx; */
     2660/*      btnPtr->cx = lptbbi->cx; */
    30372661    if (lptbbi->dwMask & TBIF_STATE)
    3038         btnPtr->fsState = lptbbi->fsState;
     2662        btnPtr->fsState = lptbbi->fsState;
    30392663    if (lptbbi->dwMask & TBIF_STYLE)
    3040         btnPtr->fsStyle = lptbbi->fsStyle;
     2664        btnPtr->fsStyle = lptbbi->fsStyle;
    30412665
    30422666    if (lptbbi->dwMask & TBIF_TEXT) {
    3043         if ((btnPtr->iString >= 0) ||
    3044             (btnPtr->iString < infoPtr->nNumStrings)) {
     2667        if ((btnPtr->iString >= 0) ||
     2668            (btnPtr->iString < infoPtr->nNumStrings)) {
     2669           // TRACE("Ooooooch\n");
    30452670#if 0
    3046             CHAR **lpString = &infoPtr->strings[btnPtr->iString]; //wrong, it's Unicode!!!
    3047             INT len = lstrlenA (lptbbi->pszText);
    3048             *lpString = COMCTL32_ReAlloc (lpString, sizeof(char)*(len+1));
     2671            WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
     2672            INT len = lstrlenA (lptbbi->pszText);
     2673            *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
    30492674#endif
    30502675
    3051             /* this is the ultimate sollution */
    3052 /*          Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
    3053         }
     2676            /* this is the ultimate sollution */
     2677/*          Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
     2678        }
    30542679    }
    30552680
     
    30572682}
    30582683
    3059 static LRESULT TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
     2684
     2685static LRESULT
     2686TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    30602687{
    30612688    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     
    30652692
    30662693    if (lptbbi == NULL)
    3067         return FALSE;
     2694        return FALSE;
    30682695    if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
    3069         return FALSE;
     2696        return FALSE;
    30702697
    30712698    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    30722699    if (nIndex == -1)
    3073         return FALSE;
     2700        return FALSE;
    30742701
    30752702    btnPtr = &infoPtr->buttons[nIndex];
    30762703    if (lptbbi->dwMask & TBIF_COMMAND)
    3077         btnPtr->idCommand = lptbbi->idCommand;
     2704        btnPtr->idCommand = lptbbi->idCommand;
    30782705    if (lptbbi->dwMask & TBIF_IMAGE)
    3079         btnPtr->iBitmap = lptbbi->iImage;
     2706        btnPtr->iBitmap = lptbbi->iImage;
    30802707    if (lptbbi->dwMask & TBIF_LPARAM)
    3081         btnPtr->dwData = lptbbi->lParam;
     2708        btnPtr->dwData = lptbbi->lParam;
    30822709/*    if (lptbbi->dwMask & TBIF_SIZE) */
    3083 /*      btnPtr->cx = lptbbi->cx; */
     2710/*      btnPtr->cx = lptbbi->cx; */
    30842711    if (lptbbi->dwMask & TBIF_STATE)
    3085         btnPtr->fsState = lptbbi->fsState;
     2712        btnPtr->fsState = lptbbi->fsState;
    30862713    if (lptbbi->dwMask & TBIF_STYLE)
    3087         btnPtr->fsStyle = lptbbi->fsStyle;
     2714        btnPtr->fsStyle = lptbbi->fsStyle;
    30882715
    30892716    if (lptbbi->dwMask & TBIF_TEXT) {
    3090         if ((btnPtr->iString >= 0) ||
    3091             (btnPtr->iString < infoPtr->nNumStrings)) {
     2717        if ((btnPtr->iString >= 0) ||
     2718            (btnPtr->iString < infoPtr->nNumStrings)) {
    30922719#if 0
    3093             WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
    3094             INT len = lstrlenW (lptbbi->pszText);
    3095             *lpString = COMCTL32_ReAlloc (lpString, sizeof(wchar)*(len+1));
     2720            WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
     2721            INT len = lstrlenW (lptbbi->pszText);
     2722            *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
    30962723#endif
    30972724
    3098             /* this is the ultimate sollution */
    3099 /*          Str_SetPtrW (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
    3100         }
     2725            /* this is the ultimate sollution */
     2726/*          Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
     2727        }
    31012728    }
    31022729
     
    31042731}
    31052732
     2733
    31062734static LRESULT
    31072735TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
     
    31092737    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    31102738
    3111     if (((INT)LOWORD(lParam) <= 0) || ((INT)HIWORD(lParam) <= 0)) return FALSE;
     2739    if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
     2740    {
     2741//      ERR("invalid parameter\n");
     2742        return FALSE;
     2743    }
    31122744
    31132745    /* Button size can only be set before adding any button to the toolbar
    31142746       according to the documentation.  */
     2747    /* this appears to be wrong. WINZIP32.EXE (ver 8) calls this on
     2748       one of its buttons after adding it to the toolbar, and it
     2749       checks that the return value is nonzero - mjm */
    31152750    if( infoPtr->nNumButtons != 0 )
    3116         return FALSE;
     2751    {
     2752        // FIXME("Button size set after button in toolbar\n");
     2753        return TRUE;
     2754    }
    31172755
    31182756    infoPtr->nButtonWidth = (INT)LOWORD(lParam);
    31192757    infoPtr->nButtonHeight = (INT)HIWORD(lParam);
    3120 
    31212758    return TRUE;
    31222759}
     
    31292766
    31302767    if (infoPtr == NULL)
    3131         return FALSE;
     2768        return FALSE;
    31322769
    31332770    infoPtr->cxMin = (INT)LOWORD(lParam);
     
    31452782
    31462783    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    3147         return FALSE;
     2784        return FALSE;
    31482785
    31492786    infoPtr->buttons[nIndex].idCommand = (INT)lParam;
     
    31512788    if (infoPtr->hwndToolTip) {
    31522789
    3153 //      FIXME (toolbar, "change tool tip!\n");
     2790        // FIXME("change tool tip!\n");
    31542791
    31552792    }
     
    31672804    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    31682805    HIMAGELIST himlTemp;
     2806
    31692807
    31702808    himlTemp = infoPtr->himlDis;
     
    31732811    /* FIXME: redraw ? */
    31742812
    3175     return (LRESULT)himlTemp;
     2813    return (LRESULT)himlTemp; 
    31762814}
    31772815
     
    31852823    dwTemp = infoPtr->dwDTFlags;
    31862824    infoPtr->dwDTFlags =
    3187         (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
     2825        (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
    31882826
    31892827    return (LRESULT)dwTemp;
     
    32002838    infoPtr->dwExStyle = (DWORD)lParam;
    32012839
    3202     return (LRESULT)dwTemp;
     2840    return (LRESULT)dwTemp; 
    32032841}
    32042842
     
    32152853    /* FIXME: redraw ? */
    32162854
    3217     return (LRESULT)himlTemp;
     2855    return (LRESULT)himlTemp; 
    32182856}
    32192857
     
    32272865    if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
    32282866    {
    3229         infoPtr->nHotItem = (INT)wParam;
    3230 
    3231         /* FIXME: What else must be done ??? */
     2867        infoPtr->nHotItem = (INT)wParam;
     2868
     2869        /* FIXME: What else must be done ??? */
    32322870
    32332871    }
    32342872
    32352873    if (nOldHotItem < 0)
    3236         return -1;
     2874        return -1;
    32372875
    32382876    return (LRESULT)nOldHotItem;
     
    32492887    infoPtr->himlDef = (HIMAGELIST)lParam;
    32502888
     2889     infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
    32512890    /* FIXME: redraw ? */
    32522891
    3253     return (LRESULT)himlTemp;
     2892    return (LRESULT)himlTemp; 
    32542893}
    32552894
     
    32922931
    32932932    if (infoPtr == NULL)
    3294         return FALSE;
     2933        return FALSE;
    32952934
    32962935    infoPtr->nMaxTextRows = (INT)wParam;
     
    33102949
    33112950    if (infoPtr == NULL)
    3312         return 0;
    3313     hwndOldNotify = infoPtr->header.hwndNotify;
    3314     infoPtr->header.hwndNotify = (HWND)wParam;
     2951        return 0;
     2952    hwndOldNotify = infoPtr->hwndNotify;
     2953    infoPtr->hwndNotify = (HWND)wParam;
    33152954
    33162955    return hwndOldNotify;
     
    33262965    if (LOWORD(wParam) > 1) {
    33272966
    3328 //      FIXME (toolbar, "multiple rows not supported!\n");
     2967        // FIXME("multiple rows not supported!\n");
    33292968
    33302969    }
     
    33352974    /* return bounding rectangle */
    33362975    if (lprc) {
    3337         lprc->left   = infoPtr->rcBound.left;
    3338         lprc->right  = infoPtr->rcBound.right;
    3339         lprc->top    = infoPtr->rcBound.top;
    3340         lprc->bottom = infoPtr->rcBound.bottom;
     2976        lprc->left   = infoPtr->rcBound.left;
     2977        lprc->right  = infoPtr->rcBound.right;
     2978        lprc->top    = infoPtr->rcBound.top;
     2979        lprc->bottom = infoPtr->rcBound.bottom;
    33412980    }
    33422981
     
    33532992    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    33542993    TBUTTON_INFO *btnPtr;
    3355     HDC hdc;
    33562994    INT nIndex;
    33572995
    33582996    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    33592997    if (nIndex == -1)
    3360         return FALSE;
     2998        return FALSE;
    33612999
    33623000    btnPtr = &infoPtr->buttons[nIndex];
    33633001    btnPtr->fsState = LOWORD(lParam);
    33643002
    3365     hdc = GetDC (hwnd);
    3366     TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    3367     ReleaseDC (hwnd, hdc);
     3003    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    33683004
    33693005    return TRUE;
     
    33763012    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    33773013    TBUTTON_INFO *btnPtr;
    3378     HDC hdc;
    33793014    INT nIndex;
    33803015
    33813016    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    33823017    if (nIndex == -1)
    3383         return FALSE;
     3018        return FALSE;
    33843019
    33853020    btnPtr = &infoPtr->buttons[nIndex];
    33863021    btnPtr->fsStyle = LOWORD(lParam);
    33873022
    3388     hdc = GetDC (hwnd);
    3389     TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    3390     ReleaseDC (hwnd, hdc);
     3023    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    33913024
    33923025    if (infoPtr->hwndToolTip) {
    3393 
    3394 //      FIXME (toolbar, "change tool tip!\n");
    3395 
     3026        // FIXME("change tool tip!\n");
    33963027    }
    33973028
     
    34003031
    34013032
    3402 static LRESULT
     3033inline static LRESULT
    34033034TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
    34043035{
     
    34063037
    34073038    if (infoPtr == NULL)
    3408         return 0;
     3039        return 0;
    34093040    infoPtr->hwndToolTip = (HWND)wParam;
    34103041    return 0;
    34113042}
     3043
     3044
     3045static LRESULT
     3046TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
     3047{
     3048    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     3049    BOOL bTemp;
     3050
     3051    // TRACE("%s hwnd=0x%04x stub!\n",
     3052//  ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
     3053
     3054    bTemp = infoPtr->bUnicode;
     3055    infoPtr->bUnicode = (BOOL)wParam;
     3056
     3057    return bTemp;
     3058}
     3059
     3060
     3061static LRESULT
     3062TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
     3063{
     3064    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     3065    INT iOldVersion = infoPtr->iVersion;
     3066
     3067    infoPtr->iVersion = iVersion;
     3068
     3069    return iOldVersion;
     3070}
     3071
    34123072
    34133073static LRESULT
     
    34293089    infoPtr->cxMin = -1;
    34303090    infoPtr->cxMax = -1;
     3091    infoPtr->nNumBitmaps = 0;
     3092    infoPtr->nNumStrings = 0;
    34313093
    34323094    infoPtr->bCaptured = FALSE;
     3095    infoPtr->bUnicode = IsWindowUnicode (hwnd);
    34333096    infoPtr->nButtonDown = -1;
    34343097    infoPtr->nOldHit = -1;
    34353098    infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
     3099    infoPtr->hwndNotify = GetParent (hwnd);
    34363100    infoPtr->bTransparent = (dwStyle & TBSTYLE_FLAT);
    34373101    infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
    34383102    infoPtr->bAnchor = FALSE; /* no anchor highlighting */
    3439 
    3440     infoPtr->hwndToolbar = hwnd;
    3441     infoPtr->oldButtons = NULL;
    3442     infoPtr->nNumOldButtons = 0;
     3103    infoPtr->iVersion = 0;
    34433104
    34443105    SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
    34453106    infoPtr->hFont = CreateFontIndirectA (&logFont);
    34463107
    3447     /* Create tooltip control */
    3448     if (dwStyle & TBSTYLE_TOOLTIPS)
    3449       infoPtr->hwndToolTip = createToolTip(hwnd,0,FALSE);
     3108    if (dwStyle & TBSTYLE_TOOLTIPS) {
     3109        /* Create tooltip control */
     3110        infoPtr->hwndToolTip =
     3111            CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
     3112                               CW_USEDEFAULT, CW_USEDEFAULT,
     3113                               CW_USEDEFAULT, CW_USEDEFAULT,
     3114                               hwnd, 0, 0, 0);
     3115
     3116        /* Send NM_TOOLTIPSCREATED notification */
     3117        if (infoPtr->hwndToolTip) {
     3118            NMTOOLTIPSCREATED nmttc;
     3119
     3120            nmttc.hdr.hwndFrom = hwnd;
     3121            nmttc.hdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
     3122            nmttc.hdr.code = NM_TOOLTIPSCREATED;
     3123            nmttc.hwndToolTips = infoPtr->hwndToolTip;
     3124
     3125            SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
     3126                          (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
     3127        }
     3128    }
    34503129
    34513130    return 0;
     
    34573136{
    34583137    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     3138
     3139    /* delete tooltip control */
     3140    if (infoPtr->hwndToolTip)
     3141        DestroyWindow (infoPtr->hwndToolTip);
    34593142
    34603143    /* delete button data */
    34613144    if (infoPtr->buttons)
    3462     {
    3463       INT x;
    3464 
    3465       //SvL: Check pointers
    3466       for (x = 0;x < infoPtr->nNumButtons;x++)
    3467         if(infoPtr->buttons[x].pszName)
    3468                 COMCTL32_Free(infoPtr->buttons[x].pszName);
    3469 
    3470       COMCTL32_Free(infoPtr->buttons);
    3471     }
     3145        COMCTL32_Free (infoPtr->buttons);
    34723146
    34733147    /* delete strings */
    34743148    if (infoPtr->strings) {
    3475         INT i;
    3476         for (i = 0; i < infoPtr->nNumStrings; i++)
    3477             if (infoPtr->strings[i])
    3478                 COMCTL32_Free (infoPtr->strings[i]);
    3479 
    3480         COMCTL32_Free (infoPtr->strings);
     3149        INT i;
     3150        for (i = 0; i < infoPtr->nNumStrings; i++)
     3151            if (infoPtr->strings[i])
     3152                COMCTL32_Free (infoPtr->strings[i]);
     3153
     3154        COMCTL32_Free (infoPtr->strings);
    34813155    }
    34823156
    34833157    /* destroy internal image list */
    34843158    if (infoPtr->himlInt)
    3485         ImageList_Destroy (infoPtr->himlInt);
     3159        ImageList_Destroy (infoPtr->himlInt);
    34863160
    34873161    /* delete default font */
    34883162    if (infoPtr->hFont)
    3489         DeleteObject (infoPtr->hFont);
     3163        DeleteObject (infoPtr->hFont);
    34903164
    34913165    /* free toolbar info data */
    3492     doneControl(hwnd);
     3166    COMCTL32_Free (infoPtr);
     3167    SetWindowLongA (hwnd, 0, 0);
    34933168
    34943169    return 0;
     
    35013176    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    35023177
    3503     //SvL: Check ptr
    3504     if (infoPtr && infoPtr->bTransparent)
    3505         return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
     3178    if (infoPtr->bTransparent)
     3179        return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
    35063180
    35073181    return DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
    35083182}
    35093183
     3184
    35103185static LRESULT
    35113186TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
     
    35153190    return infoPtr->hFont;
    35163191}
     3192
    35173193
    35183194static LRESULT
     
    35233199    POINT pt;
    35243200    INT   nHit;
    3525     HDC   hdc;
    35263201
    35273202    pt.x = (INT)LOWORD(lParam);
     
    35303205
    35313206    if (nHit >= 0) {
    3532         btnPtr = &infoPtr->buttons[nHit];
    3533         if (!(btnPtr->fsState & TBSTATE_ENABLED))
    3534             return 0;
    3535         SetCapture (hwnd);
    3536         infoPtr->bCaptured = TRUE;
    3537         infoPtr->nButtonDown = nHit;
    3538 
    3539         btnPtr->fsState |= TBSTATE_PRESSED;
    3540 
    3541         hdc = GetDC (hwnd);
    3542         TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    3543         ReleaseDC (hwnd, hdc);
     3207        btnPtr = &infoPtr->buttons[nHit];
     3208        if (!(btnPtr->fsState & TBSTATE_ENABLED))
     3209            return 0;
     3210        SetCapture (hwnd);
     3211        infoPtr->bCaptured = TRUE;
     3212        infoPtr->nButtonDown = nHit;
     3213
     3214        btnPtr->fsState |= TBSTATE_PRESSED;
     3215
     3216        InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    35443217    }
    35453218    else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
    3546         TOOLBAR_Customize (hwnd);
     3219        TOOLBAR_Customize (hwnd);
    35473220
    35483221    return 0;
     
    35573230    POINT pt;
    35583231    INT   nHit;
    3559     HDC   hdc;
    35603232
    35613233    if (infoPtr->hwndToolTip)
    3562         TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
    3563                             WM_LBUTTONDOWN, wParam, lParam);
     3234        TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
     3235                            WM_LBUTTONDOWN, wParam, lParam);
    35643236
    35653237    pt.x = (INT)LOWORD(lParam);
     
    35683240
    35693241    if (nHit >= 0) {
    3570         btnPtr = &infoPtr->buttons[nHit];
    3571         if (!(btnPtr->fsState & TBSTATE_ENABLED))
    3572             return 0;
    3573 
    3574         if (btnPtr->fsStyle &  TBSTYLE_DROPDOWN)
    3575         {
    3576             NMTOOLBARA nmtb;
    3577 
    3578             nmtb.iItem = btnPtr->idCommand;
    3579 
    3580             sendNotify(hwnd,TBN_DROPDOWN,&nmtb.hdr);
    3581         }
    3582 
    3583         SetCapture (hwnd);
    3584         infoPtr->bCaptured = TRUE;
    3585         infoPtr->nButtonDown = nHit;
    3586         infoPtr->nOldHit = nHit;
    3587 
    3588         btnPtr->fsState |= TBSTATE_PRESSED;
    3589 
    3590         hdc = GetDC (hwnd);
    3591         TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    3592         ReleaseDC (hwnd, hdc);
     3242        btnPtr = &infoPtr->buttons[nHit];
     3243        if (!(btnPtr->fsState & TBSTATE_ENABLED))
     3244            return 0;
     3245
     3246        if (btnPtr->fsStyle &  TBSTYLE_DROPDOWN)
     3247        {
     3248            NMTOOLBARA nmtb;
     3249
     3250            nmtb.hdr.hwndFrom = hwnd;
     3251            nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
     3252            nmtb.hdr.code = TBN_DROPDOWN;
     3253            nmtb.iItem = btnPtr->idCommand;
     3254
     3255            SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
     3256                          (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
     3257        }
     3258
     3259        SetCapture (hwnd);
     3260        infoPtr->bCaptured = TRUE;
     3261        infoPtr->nButtonDown = nHit;
     3262        infoPtr->nOldHit = nHit;
     3263
     3264        btnPtr->fsState |= TBSTATE_PRESSED;
     3265        btnPtr->bHot = FALSE;
     3266
     3267        InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    35933268    }
    35943269
    35953270    return 0;
    35963271}
    3597 
    35983272
    35993273static LRESULT
     
    36053279    INT   nHit;
    36063280    INT   nOldIndex = -1;
    3607     HDC   hdc;
    36083281    BOOL  bSendMessage = TRUE;
    36093282
    36103283    if (infoPtr->hwndToolTip)
    3611         TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
    3612                             WM_LBUTTONUP, wParam, lParam);
     3284        TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
     3285                            WM_LBUTTONUP, wParam, lParam);
    36133286
    36143287    pt.x = (INT)LOWORD(lParam);
     
    36163289    nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
    36173290
     3291    /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
     3292    if(infoPtr->nHotItem >= 0)
     3293        infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
     3294
    36183295    if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
    3619         infoPtr->bCaptured = FALSE;
    3620         ReleaseCapture ();
    3621         btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
    3622         btnPtr->fsState &= ~TBSTATE_PRESSED;
    3623 
    3624         if (nHit == infoPtr->nButtonDown) {
    3625             if (btnPtr->fsStyle & TBSTYLE_CHECK) {
    3626                 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
    3627                     nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
    3628                         infoPtr->nButtonDown);
    3629                     if (nOldIndex == infoPtr->nButtonDown)
    3630                         bSendMessage = FALSE;
    3631                     if ((nOldIndex != infoPtr->nButtonDown) &&
    3632                         (nOldIndex != -1))
    3633                         infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
    3634                     btnPtr->fsState |= TBSTATE_CHECKED;
    3635                 }
    3636                 else {
    3637                     if (btnPtr->fsState & TBSTATE_CHECKED)
    3638                         btnPtr->fsState &= ~TBSTATE_CHECKED;
    3639                     else
    3640                         btnPtr->fsState |= TBSTATE_CHECKED;
    3641                 }
    3642             }
    3643         }
    3644         else
    3645             bSendMessage = FALSE;
    3646 
    3647         hdc = GetDC (hwnd);
    3648         if (nOldIndex != -1)
    3649             TOOLBAR_DrawButton (hwnd, &infoPtr->buttons[nOldIndex], hdc);
    3650         TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    3651         ReleaseDC (hwnd, hdc);
    3652 
    3653         if (bSendMessage) {
    3654             SendMessageA (GetParent(hwnd), WM_COMMAND,
    3655                           MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
    3656 
    3657             if ((GetWindowLongA(hwnd, GWL_STYLE) & TBSTYLE_DROPDOWN) ||
    3658                 (btnPtr->fsStyle & 0x08/* BTNS_DROPDOWN */)) {
    3659                NMTOOLBARW       nmtb;
    3660 
    3661                nmtb.iItem        = nHit;
    3662                /* nmtb.tbButton not used with TBN_DROPDOWN */
    3663                if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings)) {
    3664                   nmtb.pszText      = infoPtr->strings[btnPtr->iString];
    3665                   nmtb.cchText      = lstrlenW(nmtb.pszText);
    3666                } else {
    3667                   nmtb.pszText      = NULL;
    3668                   nmtb.cchText      = 0;
    3669                }
    3670                nmtb.rcButton     = btnPtr->rect;
    3671 
    3672                sendNotify(hwnd,TBN_DROPDOWN,&nmtb.hdr);
    3673             }
    3674         }
    3675 
    3676         infoPtr->nButtonDown = -1;
    3677         infoPtr->nOldHit = -1;
     3296        infoPtr->bCaptured = FALSE;
     3297        ReleaseCapture ();
     3298        btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
     3299        btnPtr->fsState &= ~TBSTATE_PRESSED;
     3300
     3301        if (nHit == infoPtr->nButtonDown) {
     3302            if (btnPtr->fsStyle & TBSTYLE_CHECK) {
     3303                if (btnPtr->fsStyle & TBSTYLE_GROUP) {
     3304                    nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
     3305                        infoPtr->nButtonDown);
     3306                    if (nOldIndex == infoPtr->nButtonDown)
     3307                        bSendMessage = FALSE;
     3308                    if ((nOldIndex != infoPtr->nButtonDown) &&
     3309                        (nOldIndex != -1))
     3310                        infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
     3311                    btnPtr->fsState |= TBSTATE_CHECKED;
     3312                }
     3313                else {
     3314                    if (btnPtr->fsState & TBSTATE_CHECKED)
     3315                        btnPtr->fsState &= ~TBSTATE_CHECKED;
     3316                    else
     3317                        btnPtr->fsState |= TBSTATE_CHECKED;
     3318                }
     3319            }
     3320        }
     3321        else
     3322            bSendMessage = FALSE;
     3323
     3324        if (nOldIndex != -1)
     3325            InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
     3326       
     3327        InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     3328
     3329        if (bSendMessage) {
     3330            SendMessageA (GetParent(hwnd), WM_COMMAND,
     3331                          MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
     3332
     3333//          if ((GetWindowLongA(hwnd, GWL_STYLE) & TBSTYLE_DROPDOWN) ||
     3334//              (btnPtr->fsStyle & 0x08/* BTNS_DROPDOWN */)) {
     3335       /*
     3336        * This appears to be an error. Instead of checking the style of the
     3337        * button in question wine was checking the style of the toolbar
     3338        * itself. This caused a number of strange behaviors. In my
     3339        * invistigation i think the whole dropdown thing is still fairly
     3340        * broken. but this helps fix some of the problems.
     3341        */
     3342
     3343        if (btnPtr->fsStyle &  TBSTYLE_DROPDOWN) {
     3344               NMTOOLBARW       nmtb;
     3345
     3346               nmtb.hdr.hwndFrom = hwnd;
     3347               nmtb.hdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
     3348               nmtb.hdr.code     = TBN_DROPDOWN;
     3349               nmtb.iItem        = nHit;
     3350               /* nmtb.tbButton not used with TBN_DROPDOWN */
     3351               if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings)) {
     3352                  nmtb.pszText      = infoPtr->strings[btnPtr->iString];
     3353                  nmtb.cchText      = lstrlenW(nmtb.pszText);
     3354               } else {
     3355                  nmtb.pszText      = NULL;
     3356                  nmtb.cchText      = 0;
     3357               }
     3358               nmtb.rcButton     = btnPtr->rect;
     3359
     3360               SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
     3361                            (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
     3362            }
     3363        }
     3364        infoPtr->nButtonDown = -1;
     3365        infoPtr->nOldHit = -1;
    36783366    }
    36793367
     
    36813369}
    36823370
     3371static LRESULT
     3372TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
     3373{
     3374    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     3375    TBUTTON_INFO *hotBtnPtr;
     3376
     3377    if (infoPtr->nOldHit < 0)
     3378      return TRUE;
     3379
     3380    hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
     3381
     3382    /* Redraw the button if the last button we were over is the hot button and it
     3383       is enabled */
     3384    if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
     3385    {
     3386        hotBtnPtr->bHot = FALSE;
     3387                   
     3388        InvalidateRect (hwnd, &hotBtnPtr->rect, TRUE);
     3389    }
     3390
     3391    infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
     3392    infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
     3393
     3394    return TRUE;
     3395}
    36833396
    36843397static LRESULT
     
    36893402    POINT pt;
    36903403    INT   nHit;
    3691     HDC   hdc;
    3692     DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
     3404    TRACKMOUSEEVENT trackinfo;
     3405
     3406    /* fill in the TRACKMOUSEEVENT struct */
     3407    trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
     3408    trackinfo.dwFlags = TME_QUERY;
     3409    trackinfo.hwndTrack = hwnd;
     3410    trackinfo.dwHoverTime = HOVER_DEFAULT;
     3411
     3412    /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
     3413    _TrackMouseEvent(&trackinfo);
     3414
     3415    /* Make sure tracking is enabled so we recieve a WM_MOUSELEAVE message */
     3416    if(!(trackinfo.dwFlags & TME_LEAVE)) {
     3417        trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
     3418
     3419        /* call TRACKMOUSEEVENT so we recieve a WM_MOUSELEAVE message */
     3420        /* and can properly deactivate the hot toolbar button */
     3421        _TrackMouseEvent(&trackinfo);
     3422   }
    36933423
    36943424    if (infoPtr->hwndToolTip)
    3695         TOOLBAR_RelayEvent (infoPtr->hwndToolTip,hwnd,
    3696                             WM_MOUSEMOVE,wParam,lParam);
     3425        TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
     3426                            WM_MOUSEMOVE, wParam, lParam);
    36973427
    36983428    pt.x = (INT)LOWORD(lParam);
    36993429    pt.y = (INT)HIWORD(lParam);
    37003430
    3701     nHit = TOOLBAR_InternalHitTest(hwnd,&pt);
     3431    nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
    37023432
    37033433    if (infoPtr->nOldHit != nHit)
    37043434    {
    3705       /* Remove the effect of an old hot button */
    3706       if(infoPtr->nOldHit == infoPtr->nHotItem)
    3707       {
    3708         oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
    3709         if (oldBtnPtr->bHot) //CB: dynamic buttons
    3710         {
    3711           oldBtnPtr->bHot = FALSE;
    3712 
    3713           if (dwStyle & TBSTYLE_FLAT) InvalidateRect(hwnd,&oldBtnPtr->rect,TRUE);
    3714         }
    3715       }
    3716 
    3717       /* It's not a separator or in nowhere. It's a hot button. */
    3718       if (nHit >= 0)
    3719       {
    3720         btnPtr = &infoPtr->buttons[nHit];
    3721         if (!btnPtr->bHot)
    3722         {
    3723           btnPtr->bHot = TRUE;
    3724 
    3725           if (dwStyle & TBSTYLE_FLAT)
    3726           {
    3727             hdc = GetDC (hwnd);
    3728             TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    3729             ReleaseDC (hwnd, hdc);
    3730           }
    3731 
    3732           infoPtr->nHotItem = nHit;
    3733         }
    3734       }
    3735 
    3736       if (infoPtr->bCaptured)
    3737       {
    3738         btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
    3739         if (infoPtr->nOldHit == infoPtr->nButtonDown)
    3740         {
    3741           btnPtr->fsState &= ~TBSTATE_PRESSED;
    3742 
    3743           hdc = GetDC (hwnd);
    3744           TOOLBAR_DrawButton(hwnd,btnPtr,hdc);
    3745           ReleaseDC(hwnd,hdc);
    3746         } else if (nHit == infoPtr->nButtonDown)
    3747         {
    3748           btnPtr->fsState |= TBSTATE_PRESSED;
    3749 
    3750           hdc = GetDC(hwnd);
    3751           TOOLBAR_DrawButton(hwnd,btnPtr,hdc);
    3752           ReleaseDC(hwnd,hdc);
    3753         }
    3754       }
    3755       infoPtr->nOldHit = nHit;
     3435        /* Remove the effect of an old hot button if the button was enabled and was
     3436           drawn with the hot button effect */
     3437        if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
     3438                (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
     3439        {
     3440            oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
     3441            oldBtnPtr->bHot = FALSE;
     3442                   
     3443            InvalidateRect (hwnd, &oldBtnPtr->rect, TRUE);
     3444        }
     3445
     3446        /* It's not a separator or in nowhere. It's a hot button. */
     3447        if (nHit >= 0)
     3448        {
     3449            btnPtr = &infoPtr->buttons[nHit];
     3450            btnPtr->bHot = TRUE;
     3451
     3452            infoPtr->nHotItem = nHit;
     3453
     3454            /* only enabled buttons show hot effect */           
     3455            if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
     3456                InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     3457        }
     3458
     3459    if (infoPtr->bCaptured) {
     3460            btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
     3461            if (infoPtr->nOldHit == infoPtr->nButtonDown) {
     3462                btnPtr->fsState &= ~TBSTATE_PRESSED;
     3463                InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     3464            }
     3465            else if (nHit == infoPtr->nButtonDown) {
     3466                btnPtr->fsState |= TBSTATE_PRESSED;
     3467                InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     3468            }
     3469        }
     3470        infoPtr->nOldHit = nHit;
    37563471    }
    37573472    return 0;
     
    37593474
    37603475
    3761 static LRESULT
     3476inline static LRESULT
    37623477TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
    37633478{
    37643479/*    if (wndPtr->dwStyle & CCS_NODIVIDER) */
    3765         return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
     3480        return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
    37663481/*    else */
    3767 /*      return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
    3768 }
    3769 
    3770 
    3771 static LRESULT
     3482/*      return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
     3483}
     3484
     3485
     3486inline static LRESULT
    37723487TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
    37733488{
    37743489    if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
    3775         ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
     3490        ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
    37763491
    37773492    return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
     
    37853500
    37863501    /* allocate memory for info structure */
    3787     infoPtr = (TOOLBAR_INFO*)initControl(hwnd,sizeof(TOOLBAR_INFO));
     3502    infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
     3503    SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
    37883504
    37893505    /* paranoid!! */
     
    37933509    if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
    37943510        HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
    3795         SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
     3511        SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
    37963512    }
    37973513
     
    38083524
    38093525    if (dwStyle & WS_MINIMIZE)
    3810         return 0; /* Nothing to do */
     3526        return 0; /* Nothing to do */
    38113527
    38123528    DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
    38133529
    38143530    if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
    3815         return 0;
     3531        return 0;
    38163532
    38173533    if (!(dwStyle & CCS_NODIVIDER))
    38183534    {
    3819         GetWindowRect (hwnd, &rcWindow);
    3820         OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
    3821         if( dwStyle & WS_BORDER )
    3822             OffsetRect (&rcWindow, 1, 1);
    3823         DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
     3535        GetWindowRect (hwnd, &rcWindow);
     3536        OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
     3537        if( dwStyle & WS_BORDER )
     3538            OffsetRect (&rcWindow, 1, 1);
     3539        DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
    38243540    }
    38253541
     
    38303546
    38313547
    3832 static LRESULT
     3548inline static LRESULT
    38333549TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
    38343550{
     
    38363552    LPNMHDR lpnmh = (LPNMHDR)lParam;
    38373553
    3838 //    TRACE (toolbar, "passing WM_NOTIFY!\n");
     3554    // TRACE("passing WM_NOTIFY!\n");
    38393555
    38403556    if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
    3841         SendMessageA (infoPtr->header.hwndNotify, WM_NOTIFY,   wParam, lParam);
     3557        SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,   wParam, lParam);
    38423558
    38433559#if 0
    3844         if (lpnmh->code == TTN_GETDISPINFOA) {
    3845             LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
    3846 
    3847 //          FIXME (toolbar, "retrieving ASCII string\n");
    3848 
    3849         }
    3850         else if (lpnmh->code == TTN_GETDISPINFOW) {
    3851             LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
    3852 
    3853 //          FIXME (toolbar, "retrieving UNICODE string\n");
    3854 
    3855         }
     3560        if (lpnmh->code == TTN_GETDISPINFOA) {
     3561            LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
     3562
     3563            // FIXME("retrieving ASCII string\n");
     3564
     3565        }
     3566        else if (lpnmh->code == TTN_GETDISPINFOW) {
     3567            LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
     3568
     3569            // FIXME("retrieving UNICODE string\n");
     3570
     3571        }
    38563572#endif
    38573573    }
     
    38643580TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
    38653581{
     3582    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
    38663583    HDC hdc;
    38673584    PAINTSTRUCT ps;
    38683585
    3869     TOOLBAR_CalcToolbar(hwnd);
    3870     hdc = wParam == 0 ? BeginPaint(hwnd,&ps) : (HDC)wParam;
    3871     TOOLBAR_Refresh(hwnd,hdc);
     3586    /* fill ps.rcPaint with a default rect */
     3587    memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
     3588
     3589    TOOLBAR_CalcToolbar( hwnd );
     3590    hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
     3591    TOOLBAR_Refresh (hwnd, hdc, &ps);
    38723592    if (!wParam) EndPaint (hwnd, &ps);
     3593
    38733594    return 0;
    38743595}
     
    38813602    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    38823603    RECT parent_rect;
     3604    RECT window_rect;
    38833605    HWND parent;
    3884     INT  x = 0,y = 0,cx,cy;
     3606    INT  x, y;
     3607    INT  cx, cy;
    38853608    INT  flags;
    38863609    UINT uPosFlags = 0;
     
    38883611    /* Resize deadlock check */
    38893612    if (infoPtr->bAutoSize) {
    3890         infoPtr->bAutoSize = FALSE;
    3891         return 0;
     3613        infoPtr->bAutoSize = FALSE;
     3614        return 0;
    38923615    }
    38933616
     
    38983621     */
    38993622
    3900     //TRACE (toolbar, "sizing toolbar!\n");
     3623    // TRACE("sizing toolbar!\n");
    39013624
    39023625    if (flags == SIZE_RESTORED) {
    3903         /* width and height don't apply */
    3904         parent = GetParent (hwnd);
    3905         GetClientRect(parent, &parent_rect);
    3906         x = parent_rect.left;
    3907         y = parent_rect.top;
    3908 
    3909         if (dwStyle & CCS_NORESIZE) {
    3910             uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
    3911             /* FIXME */
    3912 /*          infoPtr->nWidth = parent_rect.right - parent_rect.left; */
    3913             cy = infoPtr->nHeight;
    3914             cx = infoPtr->nWidth;
    3915             TOOLBAR_CalcToolbar (hwnd);
    3916             infoPtr->nWidth = cx;
    3917             infoPtr->nHeight = cy;
    3918         }
    3919         else {
    3920             infoPtr->nWidth = parent_rect.right - parent_rect.left;
    3921             TOOLBAR_CalcToolbar (hwnd);
    3922             cy = infoPtr->nHeight;
    3923             cx = infoPtr->nWidth;
    3924         }
    3925 
    3926         if (dwStyle & CCS_NOPARENTALIGN) {
    3927             uPosFlags |= SWP_NOMOVE;
    3928             cy = infoPtr->nHeight;
    3929             cx = infoPtr->nWidth;
    3930         }
    3931 
    3932         if (!(dwStyle & CCS_NODIVIDER))
    3933             cy += GetSystemMetrics(SM_CYEDGE);
    3934 
    3935         if (dwStyle & WS_BORDER)
    3936         {
    3937             x = y = 1;
    3938             cy += GetSystemMetrics(SM_CYEDGE);
    3939             cx += GetSystemMetrics(SM_CYEDGE);
    3940         }
    3941 
    3942         SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
    3943                         cx, cy, uPosFlags | SWP_NOZORDER);
     3626        /* width and height don't apply */
     3627        parent = GetParent (hwnd);
     3628        GetClientRect(parent, &parent_rect);
     3629        x = parent_rect.left;
     3630        y = parent_rect.top;
     3631
     3632        if (dwStyle & CCS_NORESIZE) {
     3633            uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
     3634
     3635            /*
     3636             * this sets the working width of the toolbar, and
     3637             * Calc Toolbar will not adjust it, only the height
     3638             */
     3639            infoPtr->nWidth = parent_rect.right - parent_rect.left;
     3640            cy = infoPtr->nHeight;
     3641            cx = infoPtr->nWidth;
     3642            TOOLBAR_CalcToolbar (hwnd);
     3643            infoPtr->nWidth = cx;
     3644            infoPtr->nHeight = cy;
     3645        }
     3646        else {
     3647            infoPtr->nWidth = parent_rect.right - parent_rect.left;
     3648            TOOLBAR_CalcToolbar (hwnd);
     3649            cy = infoPtr->nHeight;
     3650            cx = infoPtr->nWidth;
     3651
     3652            if (dwStyle & CCS_NOMOVEY) {
     3653                GetWindowRect(hwnd, &window_rect);
     3654                ScreenToClient(parent, (LPPOINT)&window_rect.left);
     3655                y = window_rect.top;
     3656            }
     3657        }
     3658
     3659        if (dwStyle & CCS_NOPARENTALIGN) {
     3660            uPosFlags |= SWP_NOMOVE;
     3661            cy = infoPtr->nHeight;
     3662            cx = infoPtr->nWidth;
     3663        }
     3664
     3665        if (!(dwStyle & CCS_NODIVIDER))
     3666            cy += GetSystemMetrics(SM_CYEDGE);
     3667
     3668        if (dwStyle & WS_BORDER)
     3669        {
     3670            x = y = 1;
     3671            cy += GetSystemMetrics(SM_CYEDGE);
     3672            cx += GetSystemMetrics(SM_CYEDGE);
     3673        }
     3674
     3675        SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
     3676                        cx, cy, uPosFlags | SWP_NOZORDER);
    39443677    }
    39453678    return 0;
     
    39533686
    39543687    if (nType == GWL_STYLE) {
    3955         if (lpStyle->styleNew & TBSTYLE_LIST) {
    3956             infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
    3957         }
    3958         else {
    3959             infoPtr->dwDTFlags = DT_CENTER;
    3960         }
     3688        if (lpStyle->styleNew & TBSTYLE_LIST) {
     3689            infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
     3690        }
     3691        else {
     3692            infoPtr->dwDTFlags = DT_CENTER;
     3693        }
    39613694    }
    39623695
     
    39733706ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    39743707{
    3975    switch (uMsg)
     3708
     3709    switch (uMsg)
    39763710    {
    39773711       case WM_DESTROY:
     
    39893723    switch (uMsg)
    39903724    {
    3991         case TB_ADDBITMAP:
    3992             return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
    3993 
    3994         case TB_ADDBUTTONSA:
    3995             return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
    3996 
    3997         case TB_ADDBUTTONSW:
    3998             return TOOLBAR_AddButtonsW(hwnd,wParam,lParam);
    3999 
    4000         case TB_ADDSTRINGA:
    4001             return TOOLBAR_AddStringA (hwnd, wParam, lParam);
    4002 
    4003         case TB_ADDSTRINGW:
    4004             return TOOLBAR_AddStringW (hwnd, wParam, lParam);
    4005 
    4006         case TB_AUTOSIZE:
    4007             return TOOLBAR_AutoSize (hwnd);
    4008 
    4009         case TB_BUTTONCOUNT:
    4010             return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
    4011 
    4012         case TB_BUTTONSTRUCTSIZE:
    4013             return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
    4014 
    4015         case TB_CHANGEBITMAP:
    4016             return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
    4017 
    4018         case TB_CHECKBUTTON:
    4019             return TOOLBAR_CheckButton (hwnd, wParam, lParam);
    4020 
    4021         case TB_COMMANDTOINDEX:
    4022             return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
    4023 
    4024         case TB_CUSTOMIZE:
    4025             return TOOLBAR_Customize (hwnd);
    4026 
    4027         case TB_DELETEBUTTON:
    4028             return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
    4029 
    4030         case TB_ENABLEBUTTON:
    4031             return TOOLBAR_EnableButton (hwnd, wParam, lParam);
    4032 
    4033         case TB_GETANCHORHIGHLIGHT:
    4034             return TOOLBAR_GetAnchorHighlight (hwnd);
    4035 
    4036         case TB_GETBITMAP:
    4037             return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
    4038 
    4039         case TB_GETBITMAPFLAGS:
    4040             return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
    4041 
    4042         case TB_GETBUTTON:
    4043             return TOOLBAR_GetButton (hwnd, wParam, lParam);
    4044 
    4045         case TB_GETBUTTONINFOA:
    4046             return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
    4047 
    4048         case TB_GETBUTTONINFOW:         /* 4.71 */
    4049             return TOOLBAR_GetButtonInfoW(hwnd,wParam,lParam);
    4050 
    4051         case TB_GETBUTTONSIZE:
    4052             return TOOLBAR_GetButtonSize (hwnd);
    4053 
    4054         case TB_GETBUTTONTEXTA:
    4055             return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
    4056 
    4057         case TB_GETBUTTONTEXTW:
    4058             return TOOLBAR_GetButtonTextW(hwnd,wParam,lParam);
    4059 
    4060 /*      case TB_GETCOLORSCHEME:                 */ /* 4.71 */
    4061 
    4062         case TB_GETDISABLEDIMAGELIST:
    4063             return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
    4064 
    4065         case TB_GETEXTENDEDSTYLE:
    4066             return TOOLBAR_GetExtendedStyle (hwnd);
    4067 
    4068         case TB_GETHOTIMAGELIST:
    4069             return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
    4070 
    4071         case TB_GETHOTITEM:
    4072             return TOOLBAR_GetHotItem (hwnd);
    4073 
    4074         case TB_GETIMAGELIST:
    4075             return TOOLBAR_GetImageList (hwnd, wParam, lParam);
    4076 
    4077 /*      case TB_GETINSERTMARK:                  */ /* 4.71 */
    4078 /*      case TB_GETINSERTMARKCOLOR:             */ /* 4.71 */
    4079 
    4080         case TB_GETITEMRECT:
    4081             return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
    4082 
    4083         case TB_GETMAXSIZE:
    4084             return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
    4085 
    4086 /*      case TB_GETOBJECT:                      */ /* 4.71 */
    4087 /*      case TB_GETPADDING:                     */ /* 4.71 */
    4088 
    4089         case TB_GETRECT:
    4090             return TOOLBAR_GetRect (hwnd, wParam, lParam);
    4091 
    4092         case TB_GETROWS:
    4093             return TOOLBAR_GetRows (hwnd, wParam, lParam);
    4094 
    4095         case TB_GETSTATE:
    4096             return TOOLBAR_GetState (hwnd, wParam, lParam);
    4097 
    4098         case TB_GETSTYLE:
    4099             return TOOLBAR_GetStyle (hwnd, wParam, lParam);
    4100 
    4101         case TB_GETTEXTROWS:
    4102             return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
    4103 
    4104         case TB_GETTOOLTIPS:
    4105             return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
    4106 
    4107         case TB_HIDEBUTTON:
    4108             return TOOLBAR_HideButton (hwnd, wParam, lParam);
    4109 
    4110         case TB_HITTEST:
    4111             return TOOLBAR_HitTest (hwnd, wParam, lParam);
    4112 
    4113         case TB_INDETERMINATE:
    4114             return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
    4115 
    4116         case TB_INSERTBUTTONA:
    4117             return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
    4118 
    4119         case TB_INSERTBUTTONW:
    4120             return TOOLBAR_InsertButtonW(hwnd,wParam,lParam);
    4121 
    4122 /*      case TB_INSERTMARKHITTEST:              */ /* 4.71 */
    4123 
    4124         case TB_ISBUTTONCHECKED:
    4125             return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
    4126 
    4127         case TB_ISBUTTONENABLED:
    4128             return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
    4129 
    4130         case TB_ISBUTTONHIDDEN:
    4131             return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
    4132 
    4133         case TB_ISBUTTONHIGHLIGHTED:
    4134             return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
    4135 
    4136         case TB_ISBUTTONINDETERMINATE:
    4137             return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
    4138 
    4139         case TB_ISBUTTONPRESSED:
    4140             return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
    4141 
    4142       case TB_LOADIMAGES:                      /* 4.70 */
    4143 //        FIXME("missing standard imagelists\n");
    4144         return 0;
    4145 /*      case TB_MAPACCELERATORA:                */ /* 4.71 */
    4146 /*      case TB_MAPACCELERATORW:                */ /* 4.71 */
    4147 /*      case TB_MARKBUTTON:                     */ /* 4.71 */
    4148 /*      case TB_MOVEBUTTON:                     */ /* 4.71 */
    4149 
    4150         case TB_PRESSBUTTON:
    4151             return TOOLBAR_PressButton (hwnd, wParam, lParam);
    4152 
    4153 /*      case TB_REPLACEBITMAP: */
    4154 
    4155         case TB_SAVERESTOREA:
    4156             return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
    4157 
    4158         case TB_SAVERESTOREW:
    4159             return TOOLBAR_SaveRestoreW(hwnd,wParam,lParam);
    4160 
    4161         case TB_SETANCHORHIGHLIGHT:
    4162             return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
    4163 
    4164         case TB_SETBITMAPSIZE:
    4165             return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
    4166 
    4167         case TB_SETBUTTONINFOA:
    4168             return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
    4169 
    4170         case TB_SETBUTTONINFOW:                 /* 4.71 */
    4171             return TOOLBAR_SetButtonInfoW(hwnd,wParam,lParam);
    4172 
    4173         case TB_SETBUTTONSIZE:
    4174             return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
    4175 
    4176         case TB_SETBUTTONWIDTH:
    4177             return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
    4178 
    4179         case TB_SETCMDID:
    4180             return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
    4181 
    4182 /*      case TB_SETCOLORSCHEME:                 */ /* 4.71 */
    4183 
    4184         case TB_SETDISABLEDIMAGELIST:
    4185             return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
    4186 
    4187         case TB_SETDRAWTEXTFLAGS:
    4188             return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
    4189 
    4190         case TB_SETEXTENDEDSTYLE:
    4191             return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
    4192 
    4193         case TB_SETHOTIMAGELIST:
    4194             return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
    4195 
    4196         case TB_SETHOTITEM:
    4197             return TOOLBAR_SetHotItem (hwnd, wParam);
    4198 
    4199         case TB_SETIMAGELIST:
    4200             return TOOLBAR_SetImageList (hwnd, wParam, lParam);
    4201 
    4202         case TB_SETINDENT:
    4203             return TOOLBAR_SetIndent (hwnd, wParam, lParam);
    4204 
    4205 /*      case TB_SETINSERTMARK:                  */ /* 4.71 */
    4206 
    4207         case TB_SETINSERTMARKCOLOR:
    4208             return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
    4209 
    4210         case TB_SETMAXTEXTROWS:
    4211             return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
    4212 
    4213 /*      case TB_SETPADDING:                     */ /* 4.71 */
    4214 
    4215         case TB_SETPARENT:
    4216             return TOOLBAR_SetParent (hwnd, wParam, lParam);
    4217 
    4218         case TB_SETROWS:
    4219             return TOOLBAR_SetRows (hwnd, wParam, lParam);
    4220 
    4221         case TB_SETSTATE:
    4222             return TOOLBAR_SetState (hwnd, wParam, lParam);
    4223 
    4224         case TB_SETSTYLE:
    4225             return TOOLBAR_SetStyle (hwnd, wParam, lParam);
    4226 
    4227         case TB_SETTOOLTIPS:
    4228             return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
    4229 
    4230 /*      case WM_CHAR: */
    4231 
    4232         case WM_CREATE:
    4233             return TOOLBAR_Create (hwnd, wParam, lParam);
    4234 
    4235         case WM_ERASEBKGND:
    4236             return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
    4237 
    4238         case WM_GETFONT:
    4239                 return TOOLBAR_GetFont (hwnd, wParam, lParam);
    4240 
    4241 /*      case WM_KEYDOWN: */
    4242 /*      case WM_KILLFOCUS: */
    4243 
    4244         case WM_LBUTTONDBLCLK:
    4245             return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
    4246 
    4247         case WM_LBUTTONDOWN:
    4248             return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
    4249 
    4250         case WM_LBUTTONUP:
    4251             return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
    4252 
    4253         case WM_MOUSEMOVE:
    4254             return TOOLBAR_MouseMove (hwnd, wParam, lParam);
    4255 
    4256         case WM_NCACTIVATE:
    4257             return TOOLBAR_NCActivate (hwnd, wParam, lParam);
    4258 
    4259         case WM_NCCALCSIZE:
    4260             return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
    4261 
    4262         case WM_NCPAINT:
    4263             return TOOLBAR_NCPaint (hwnd, wParam, lParam);
    4264 
    4265         case WM_NOTIFY:
    4266             return TOOLBAR_Notify (hwnd, wParam, lParam);
    4267 
    4268         case WM_PAINT:
    4269             return TOOLBAR_Paint (hwnd, wParam);
    4270 
    4271         case WM_SIZE:
    4272             return TOOLBAR_Size (hwnd, wParam, lParam);
    4273 
    4274         case WM_STYLECHANGED:
    4275             return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
    4276 
    4277 /*      case WM_SYSCOLORCHANGE: */
    4278 
    4279 /*      case WM_WININICHANGE: */
    4280 
    4281         case WM_CHARTOITEM:
    4282         case WM_COMMAND:
    4283         case WM_DRAWITEM:
    4284         case WM_MEASUREITEM:
    4285         case WM_VKEYTOITEM:
    4286             return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
     3725        case TB_ADDBITMAP:
     3726            return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
     3727
     3728        case TB_ADDBUTTONSA:
     3729            return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
     3730
     3731        case TB_ADDBUTTONSW:
     3732            return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
     3733
     3734        case TB_ADDSTRINGA:
     3735            return TOOLBAR_AddStringA (hwnd, wParam, lParam);
     3736
     3737        case TB_ADDSTRINGW:
     3738            return TOOLBAR_AddStringW (hwnd, wParam, lParam);
     3739
     3740        case TB_AUTOSIZE:
     3741            return TOOLBAR_AutoSize (hwnd);
     3742
     3743        case TB_BUTTONCOUNT:
     3744            return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
     3745
     3746        case TB_BUTTONSTRUCTSIZE:
     3747            return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
     3748
     3749        case TB_CHANGEBITMAP:
     3750            return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
     3751
     3752        case TB_CHECKBUTTON:
     3753            return TOOLBAR_CheckButton (hwnd, wParam, lParam);
     3754
     3755        case TB_COMMANDTOINDEX:
     3756            return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
     3757
     3758        case TB_CUSTOMIZE:
     3759            return TOOLBAR_Customize (hwnd);
     3760
     3761        case TB_DELETEBUTTON:
     3762            return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
     3763
     3764        case TB_ENABLEBUTTON:
     3765            return TOOLBAR_EnableButton (hwnd, wParam, lParam);
     3766
     3767        case TB_GETANCHORHIGHLIGHT:
     3768            return TOOLBAR_GetAnchorHighlight (hwnd);
     3769
     3770        case TB_GETBITMAP:
     3771            return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
     3772
     3773        case TB_GETBITMAPFLAGS:
     3774            return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
     3775
     3776        case TB_GETBUTTON:
     3777            return TOOLBAR_GetButton (hwnd, wParam, lParam);
     3778
     3779        case TB_GETBUTTONINFOA:
     3780            return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
     3781
     3782        case TB_GETBUTTONINFOW:
     3783            return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
     3784
     3785        case TB_GETBUTTONSIZE:
     3786            return TOOLBAR_GetButtonSize (hwnd);
     3787
     3788        case TB_GETBUTTONTEXTA:
     3789            return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
     3790
     3791        case TB_GETBUTTONTEXTW:
     3792            return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
     3793
     3794/*      case TB_GETCOLORSCHEME:                 */ /* 4.71 */
     3795
     3796        case TB_GETDISABLEDIMAGELIST:
     3797            return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
     3798
     3799        case TB_GETEXTENDEDSTYLE:
     3800            return TOOLBAR_GetExtendedStyle (hwnd);
     3801
     3802        case TB_GETHOTIMAGELIST:
     3803            return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
     3804
     3805        case TB_GETHOTITEM:
     3806            return TOOLBAR_GetHotItem (hwnd);
     3807
     3808        case TB_GETIMAGELIST:
     3809            return TOOLBAR_GetImageList (hwnd, wParam, lParam);
     3810
     3811/*      case TB_GETINSERTMARK:                  */ /* 4.71 */
     3812/*      case TB_GETINSERTMARKCOLOR:             */ /* 4.71 */
     3813
     3814        case TB_GETITEMRECT:
     3815            return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
     3816
     3817        case TB_GETMAXSIZE:
     3818            return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
     3819
     3820/*      case TB_GETOBJECT:                      */ /* 4.71 */
     3821/*      case TB_GETPADDING:                     */ /* 4.71 */
     3822
     3823        case TB_GETRECT:
     3824            return TOOLBAR_GetRect (hwnd, wParam, lParam);
     3825
     3826        case TB_GETROWS:
     3827            return TOOLBAR_GetRows (hwnd, wParam, lParam);
     3828
     3829        case TB_GETSTATE:
     3830            return TOOLBAR_GetState (hwnd, wParam, lParam);
     3831
     3832        case TB_GETSTYLE:
     3833            return TOOLBAR_GetStyle (hwnd, wParam, lParam);
     3834
     3835        case TB_GETTEXTROWS:
     3836            return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
     3837
     3838        case TB_GETTOOLTIPS:
     3839            return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
     3840
     3841        case TB_GETUNICODEFORMAT:
     3842            return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
     3843
     3844        case CCM_GETVERSION:
     3845            return TOOLBAR_GetVersion (hwnd);
     3846
     3847        case TB_HIDEBUTTON:
     3848            return TOOLBAR_HideButton (hwnd, wParam, lParam);
     3849
     3850        case TB_HITTEST:
     3851            return TOOLBAR_HitTest (hwnd, wParam, lParam);
     3852
     3853        case TB_INDETERMINATE:
     3854            return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
     3855
     3856        case TB_INSERTBUTTONA:
     3857            return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
     3858
     3859        case TB_INSERTBUTTONW:
     3860            return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
     3861
     3862/*      case TB_INSERTMARKHITTEST:              */ /* 4.71 */
     3863
     3864        case TB_ISBUTTONCHECKED:
     3865            return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
     3866
     3867        case TB_ISBUTTONENABLED:
     3868            return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
     3869
     3870        case TB_ISBUTTONHIDDEN:
     3871            return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
     3872
     3873        case TB_ISBUTTONHIGHLIGHTED:
     3874            return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
     3875
     3876        case TB_ISBUTTONINDETERMINATE:
     3877            return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
     3878
     3879        case TB_ISBUTTONPRESSED:
     3880            return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
     3881
     3882        case TB_LOADIMAGES:                        /* 4.70 */
     3883            // FIXME("missing standard imagelists\n");
     3884            return 0;
     3885
     3886/*      case TB_MAPACCELERATORA:                */ /* 4.71 */
     3887/*      case TB_MAPACCELERATORW:                */ /* 4.71 */
     3888/*      case TB_MARKBUTTON:                     */ /* 4.71 */
     3889/*      case TB_MOVEBUTTON:                     */ /* 4.71 */
     3890
     3891        case TB_PRESSBUTTON:
     3892            return TOOLBAR_PressButton (hwnd, wParam, lParam);
     3893
     3894/*      case TB_REPLACEBITMAP: */
     3895
     3896        case TB_SAVERESTOREA:
     3897            return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
     3898
     3899        case TB_SAVERESTOREW:
     3900            return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
     3901
     3902        case TB_SETANCHORHIGHLIGHT:
     3903            return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
     3904
     3905        case TB_SETBITMAPSIZE:
     3906            return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
     3907
     3908        case TB_SETBUTTONINFOA:
     3909            return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
     3910
     3911        case TB_SETBUTTONINFOW:
     3912            return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
     3913
     3914        case TB_SETBUTTONSIZE:
     3915            return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
     3916
     3917        case TB_SETBUTTONWIDTH:
     3918            return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
     3919
     3920        case TB_SETCMDID:
     3921            return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
     3922
     3923/*      case TB_SETCOLORSCHEME:                 */ /* 4.71 */
     3924
     3925        case TB_SETDISABLEDIMAGELIST:
     3926            return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
     3927
     3928        case TB_SETDRAWTEXTFLAGS:
     3929            return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
     3930
     3931        case TB_SETEXTENDEDSTYLE:
     3932            return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
     3933
     3934        case TB_SETHOTIMAGELIST:
     3935            return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
     3936
     3937        case TB_SETHOTITEM:
     3938            return TOOLBAR_SetHotItem (hwnd, wParam);
     3939
     3940        case TB_SETIMAGELIST:
     3941            return TOOLBAR_SetImageList (hwnd, wParam, lParam);
     3942
     3943        case TB_SETINDENT:
     3944            return TOOLBAR_SetIndent (hwnd, wParam, lParam);
     3945
     3946/*      case TB_SETINSERTMARK:                  */ /* 4.71 */
     3947
     3948        case TB_SETINSERTMARKCOLOR:
     3949            return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
     3950
     3951        case TB_SETMAXTEXTROWS:
     3952            return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
     3953
     3954/*      case TB_SETPADDING:                     */ /* 4.71 */
     3955
     3956        case TB_SETPARENT:
     3957            return TOOLBAR_SetParent (hwnd, wParam, lParam);
     3958
     3959        case TB_SETROWS:
     3960            return TOOLBAR_SetRows (hwnd, wParam, lParam);
     3961
     3962        case TB_SETSTATE:
     3963            return TOOLBAR_SetState (hwnd, wParam, lParam);
     3964
     3965        case TB_SETSTYLE:
     3966            return TOOLBAR_SetStyle (hwnd, wParam, lParam);
     3967
     3968        case TB_SETTOOLTIPS:
     3969            return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
     3970
     3971        case TB_SETUNICODEFORMAT:
     3972            return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
     3973
     3974        case CCM_SETVERSION:
     3975            return TOOLBAR_SetVersion (hwnd, (INT)wParam);
     3976
     3977
     3978/*      case WM_CHAR: */
     3979
     3980        case WM_CREATE:
     3981            return TOOLBAR_Create (hwnd, wParam, lParam);
     3982
     3983        case WM_ERASEBKGND:
     3984            return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
     3985
     3986        case WM_GETFONT:
     3987                return TOOLBAR_GetFont (hwnd, wParam, lParam);
     3988
     3989/*      case WM_KEYDOWN: */
     3990/*      case WM_KILLFOCUS: */
     3991
     3992        case WM_LBUTTONDBLCLK:
     3993            return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
     3994
     3995        case WM_LBUTTONDOWN:
     3996            return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
     3997
     3998        case WM_LBUTTONUP:
     3999            return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
     4000
     4001        case WM_MOUSEMOVE:
     4002            return TOOLBAR_MouseMove (hwnd, wParam, lParam);
     4003
     4004        case WM_MOUSELEAVE:
     4005            return TOOLBAR_MouseLeave (hwnd, wParam, lParam);   
     4006
     4007        case WM_NCACTIVATE:
     4008            return TOOLBAR_NCActivate (hwnd, wParam, lParam);
     4009
     4010        case WM_NCCALCSIZE:
     4011            return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
     4012
     4013        case WM_NCPAINT:
     4014            return TOOLBAR_NCPaint (hwnd, wParam, lParam);
     4015
     4016        case WM_NOTIFY:
     4017            return TOOLBAR_Notify (hwnd, wParam, lParam);
     4018
     4019/*      case WM_NOTIFYFORMAT: */
     4020
     4021        case WM_PAINT:
     4022            return TOOLBAR_Paint (hwnd, wParam);
     4023
     4024        case WM_SIZE:
     4025            return TOOLBAR_Size (hwnd, wParam, lParam);
     4026
     4027        case WM_STYLECHANGED:
     4028            return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
     4029
     4030/*      case WM_SYSCOLORCHANGE: */
     4031
     4032/*      case WM_WININICHANGE: */
     4033
     4034        case WM_CHARTOITEM:
     4035        case WM_COMMAND:
     4036        case WM_DRAWITEM:
     4037        case WM_MEASUREITEM:
     4038        case WM_VKEYTOITEM:
     4039            return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
    42874040
    42884041        default:
     
    42974050
    42984051VOID
    4299 TOOLBAR_Register (VOID)
     4052TOOLBAR_Register (void)
    43004053{
    43014054    WNDCLASSA wndClass;
     
    43094062    wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
    43104063    wndClass.lpszClassName = TOOLBARCLASSNAMEA;
    4311 
     4064 
    43124065    RegisterClassA (&wndClass);
    43134066}
     
    43154068
    43164069VOID
    4317 TOOLBAR_Unregister (VOID)
     4070TOOLBAR_Unregister (void)
    43184071{
    43194072    UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);
Note: See TracChangeset for help on using the changeset viewer.