Ignore:
Timestamp:
Aug 6, 2000, 10:31:01 PM (25 years ago)
Author:
sandervl
Message:

put back old toolbar+tooltips code

File:
1 edited

Legend:

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

    r3962 r3963  
    1 /* $Id: toolbar.cpp,v 1.8 2000-08-06 14:40:17 sandervl Exp $ */
     1/* $Id: toolbar.cpp,v 1.9 2000-08-06 20:28:28 sandervl Exp $ */
    22/*
    33 * Toolbar control
     
    1010 *   - A little bug in TOOLBAR_DrawMasked()
    1111 *   - Button wrapping (under construction).
    12  *   - Messages.
    13  *   - Notifications (under construction).
     12 *   - Messages (under construction).
     13 *   - Notifications.
    1414 *   - Fix TB_SETROWS.
    1515 *   - Tooltip support (almost complete).
    16  *   - Unicode suppport (under construction).
     16 *   - Unicode support (under construction).
    1717 *   - Fix TOOLBAR_SetButtonInfo32A/W.
    18  *   - Customize dialog (under construction).
    19  *   - TBSTYLE_AUTOSIZE for toolbar and buttons.
    20  *   - I_IMAGECALLBACK support.
     18 *   - Drag & drop of buttons
    2119 *
    2220 * Testing:
     
    3129
    3230/*
    33  - (WINE 20000608 level)
     31 - Corel 20000513 level
     32 - (WINE 991212 level)
    3433*/
    35 
    3634
    3735#include <string.h>
     
    4846#define BOTTOM_BORDER      2
    4947
    50 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
    51 
    52 static BOOL
    53 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
    54 {
    55     if ((index>=0) && (index < infoPtr->nNumBitmaps))
    56       return TRUE;
    57     else
    58       return FALSE;
    59 }
     48#define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO*)getInfoPtr(hwnd))
    6049
    6150
     
    7665}
    7766
    78 /*
    79  * Draw the text string for this button.
    80  * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
    81  *      is non-zero, so we can simply check himlDef to see if we have
    82  *      an image list
    83  */
     67
    8468static void
    8569TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
    86                     HDC hdc, INT nState, DWORD dwStyle)
     70                    HDC hdc, INT nState, DWORD dwStyle)
    8771{
    8872    RECT   rcText = btnPtr->rect;
     
    9074    INT    nOldBkMode;
    9175    COLORREF clrOld;
    92     LPWSTR lpText = NULL;
    93     HIMAGELIST himl = infoPtr->himlDef;
    94 
    95     // TRACE ("iString: %x\n", btnPtr->iString);
    96 
    97     /* get a pointer to the text */
    98     if (btnPtr->iString == -1)
    99         dprintf(("TOOLBAR_DrawString: Undocumented Index -1\n"));
    100     else if (HIWORD(btnPtr->iString) != 0)
    101         lpText = (LPWSTR)btnPtr->iString;
    102     else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
    103         lpText = infoPtr->strings[btnPtr->iString];
    104 
    105     // TRACE ("lpText: \"%s\"\n", debugstr_w(lpText));
    10676
    10777    /* draw text */
    108     if (lpText) {
    109 
    110         InflateRect (&rcText, -3, -3);
    111 
    112         if (himl && TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
    113                 if ((dwStyle & TBSTYLE_LIST) &&
    114                     ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
    115                     (btnPtr->iBitmap != I_IMAGENONE)) {
    116                     rcText.left += infoPtr->nBitmapWidth;
    117                 }
    118                 else {
    119                     rcText.top += infoPtr->nBitmapHeight;
    120                 }
    121         }
    122 
    123         if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
    124             OffsetRect (&rcText, 1, 1);
    125 
    126         hOldFont = SelectObject (hdc, infoPtr->hFont);
    127         nOldBkMode = SetBkMode (hdc, TRANSPARENT);
    128         if (!(nState & TBSTATE_ENABLED)) {
    129             clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
    130             OffsetRect (&rcText, 1, 1);
    131             DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
    132             SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
    133             OffsetRect (&rcText, -1, -1);
    134             DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
    135         }
    136         else if (nState & TBSTATE_INDETERMINATE) {
    137             clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
    138             DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
    139         }
    140         else {
    141             clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
    142             DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
    143         }
    144 
    145         SetTextColor (hdc, clrOld);
    146         SelectObject (hdc, hOldFont);
    147         if (nOldBkMode != TRANSPARENT)
    148             SetBkMode (hdc, nOldBkMode);
     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);
    149116    }
    150117}
     
    164131static void
    165132TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
    166                     HDC hdc, INT x, INT y)
     133                    HDC hdc, INT x, INT y)
    167134{
    168135    /* FIXME: this function is a hack since it uses image list
    169               internals directly */
     136              internals directly */
    170137
    171138    HIMAGELIST himl = infoPtr->himlDef;
     
    175142
    176143    if (!himl)
    177         return;
     144        return;
    178145
    179146    /* create new dc's */
     
    190157    SetTextColor (hdcImageList, RGB(0, 0, 0));
    191158    BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
    192               hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
     159              hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
    193160
    194161#if 0
     
    197164    SetBkColor (hdcImageList, RGB(0, 0, 0));
    198165    BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
    199               hdcImageList, himl->cx * btnPtr->iBitmap, 0, MERGEPAINT);
     166              hdcImageList, himl->cx * btnPtr->iBitmap, 0, MERGEPAINT);
    200167#endif
    201168
     
    203170    SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
    204171    BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
    205               hdcMask, 0, 0, 0xB8074A);
     172              hdcMask, 0, 0, 0xB8074A);
    206173
    207174    SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
    208175    BitBlt (hdc, x, y, himl->cx, himl->cy,
    209               hdcMask, 0, 0, 0xB8074A);
     176              hdcMask, 0, 0, 0xB8074A);
    210177
    211178    DeleteObject (hbmMask);
     
    222189    RECT rc;
    223190
    224     if (btnPtr->fsState & TBSTATE_HIDDEN)
    225         return;
     191    if (btnPtr->fsState & TBSTATE_HIDDEN) return;
    226192
    227193    rc = btnPtr->rect;
    228194
    229     // TRACE("iBitmap: %d\n", btnPtr->iBitmap);
    230 
    231195    /* separator */
    232     if (btnPtr->fsStyle & TBSTYLE_SEP) {
    233         /* with the FLAT style, iBitmap is the width and has already */
    234         /* been taken into consideration in calculating the width    */
    235         /* so now we need to draw the vertical separator             */
    236         /* empirical tests show that iBitmap can/will be non-zero    */
    237         /* when drawing the vertical bar...      */
    238         if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */)
    239             TOOLBAR_DrawFlatSeparator (&rc, hdc);
    240         return;
     196    if (btnPtr->fsStyle & TBSTYLE_SEP)
     197    {
     198      if ((dwStyle & TBSTYLE_FLAT) && (btnPtr->iBitmap == 0))
     199          TOOLBAR_DrawFlatSeparator (&rc, hdc);
     200      return;
    241201    }
    242202
    243203    /* disabled */
    244     if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
    245         if (!(dwStyle & TBSTYLE_FLAT))
    246             DrawEdge (hdc, &rc, EDGE_RAISED,
    247                       BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    248        
    249         if (infoPtr->himlDis &&
    250             TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
    251             ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
    252                                 rc.left+1, rc.top+1, ILD_NORMAL);
    253         else
    254             TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
    255 
    256         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    257         return;
     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;
    258218    }
    259219
    260220    /* pressed TBSTYLE_BUTTON */
    261     if (btnPtr->fsState & TBSTATE_PRESSED) {
    262         if (dwStyle & TBSTYLE_FLAT)
    263             DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE | BF_ADJUST);
    264         else
    265             DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
    266         if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
    267             ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
    268                         rc.left+2, rc.top+2, ILD_NORMAL);
    269         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    270         return;
    271     }
    272 
    273     /* checked TBSTYLE_CHECK */
     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*/
    274234    if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
    275         (btnPtr->fsState & TBSTATE_CHECKED)) {
    276         if (dwStyle & TBSTYLE_FLAT)
    277             DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
    278                         BF_RECT | BF_MIDDLE | BF_ADJUST);
    279         else
    280             DrawEdge (hdc, &rc, EDGE_SUNKEN,
    281                         BF_RECT | BF_MIDDLE | BF_ADJUST);
    282 
    283         TOOLBAR_DrawPattern (hdc, &rc);
    284        
    285         if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
    286             ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
    287                         rc.left+2, rc.top+2, ILD_NORMAL);
    288 
    289         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    290         return;
    291     }
    292 
    293     /* indeterminate */
    294     if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
    295         DrawEdge (hdc, &rc, EDGE_RAISED,
    296                     BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    297 
    298         TOOLBAR_DrawPattern (hdc, &rc);
    299         TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
    300         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    301         return;
     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;
    302262    }
    303263
     
    305265    if (dwStyle & TBSTYLE_FLAT)
    306266    {
    307         if (btnPtr->bHot)
    308             DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
    309         if (btnPtr->bHot && infoPtr->himlHot &&
    310             TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
    311             ImageList_Draw (infoPtr->himlHot, btnPtr->iBitmap, hdc,
    312                             rc.left +2, rc.top +2, ILD_NORMAL);
    313         else if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
    314             ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
    315                             rc.left +2, rc.top +2, ILD_NORMAL);
    316     }
    317     else
     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
    318277    {
    319         DrawEdge (hdc, &rc, EDGE_RAISED,
    320                 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    321 
    322         if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
    323             ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
    324                         rc.left+1, rc.top+1, ILD_NORMAL);
     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);
    325283    }
    326284
     
    330288
    331289static void
    332 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
     290TOOLBAR_Refresh (HWND hwnd, HDC hdc)
    333291{
    334292    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    335293    TBUTTON_INFO *btnPtr;
    336294    INT i;
    337     RECT rcTemp;
    338 
    339     /* redraw necessary buttons */
     295
     296    /* draw buttons */
    340297    btnPtr = infoPtr->buttons;
    341298    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
    342     {
    343         if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
    344             TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    345     }
    346 }
     299        TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
     300}
     301
    347302
    348303static void
    349 TOOLBAR_MeasureString(HWND hwnd, INT index, LPSIZE lpSize)
     304TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
    350305{
    351306    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    352307    TBUTTON_INFO *btnPtr;
     308    INT i;
    353309    HDC hdc;
    354310    HFONT hOldFont;
     311    SIZE sz;
    355312
    356313    lpSize->cx = 0;
     
    359316    hOldFont = SelectObject (hdc, infoPtr->hFont);
    360317
    361     btnPtr = &infoPtr->buttons[index];
    362 
    363     if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
    364          (btnPtr->iString > -1) &&
    365          (btnPtr->iString < infoPtr->nNumStrings))
    366     {
    367         LPWSTR lpText = infoPtr->strings[btnPtr->iString];
    368         GetTextExtentPoint32W (hdc, lpText, lstrlenW (lpText), lpSize);
     318    btnPtr = infoPtr->buttons;
     319    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        }
    369330    }
    370331
     
    372333    ReleaseDC (0, hdc);
    373334
    374     // TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
    375 }
    376 
    377 static void
    378 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
    379 {
    380     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    381     TBUTTON_INFO *btnPtr;
    382     INT i;
    383     SIZE sz;
    384 
    385 
    386     lpSize->cx = 0;
    387     lpSize->cy = 0;
    388 
    389     btnPtr = infoPtr->buttons;
    390     for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
    391         TOOLBAR_MeasureString(hwnd,i,&sz);
    392         if (sz.cx > lpSize->cx)
    393             lpSize->cx = sz.cx;
    394         if (sz.cy > lpSize->cy)
    395             lpSize->cy = sz.cy;
    396     }
    397 
    398     // TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
     335//    TRACE (toolbar, "string size %d x %d!\n", lpSize->cx, lpSize->cy);
    399336}
    400337
    401338/***********************************************************************
    402 *               TOOLBAR_WrapToolbar
     339*               TOOLBAR_WrapToolbar
    403340*
    404 * This function walks through the buttons and seperators in the 
    405 * toolbar, and sets the TBSTATE_WRAP flag only on those items where 
    406 * wrapping should occur based on the width of the toolbar window. 
    407 * It does *not* calculate button placement itself.  That task 
    408 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage 
    409 * the toolbar wrapping on it's own, it can use the TBSTYLE_WRAPPABLE 
     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
    410347* flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
    411 */ 
     348*/
    412349
    413350static void
     
    420357    BOOL bWrap, bButtonWrap;
    421358
    422     /*  When the toolbar window style is not TBSTYLE_WRAPABLE,  */
    423     /*  no layout is necessary. Applications may use this style */
    424     /*  to perform their own layout on the toolbar.             */
     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.             */
    425362    if( !(dwStyle & TBSTYLE_WRAPABLE) )
    426         return;
     363        return;
    427364
    428365    btnPtr = infoPtr->buttons;
    429366    x  = infoPtr->nIndent;
    430367
    431     /* this can get the parents width, to know how far we can extend
    432      * this toolbar.  We cannot use its height, as there may be multiple
    433      * toolbars in a rebar control
    434      */
    435368    GetClientRect( GetParent(hwnd), &rc );
    436369    infoPtr->nWidth = rc.right - rc.left;
     
    439372    for (i = 0; i < infoPtr->nNumButtons; i++ )
    440373    {
    441         bWrap = FALSE;
    442         btnPtr[i].fsState &= ~TBSTATE_WRAP;
    443        
    444         if (btnPtr[i].fsState & TBSTATE_HIDDEN)
    445             continue;
    446 
    447         /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
    448         /* it is the actual width of the separator. This is used for */
    449         /* custom controls in toolbars.                              */
    450         if (btnPtr[i].fsStyle & TBSTYLE_SEP)
    451             cx = (btnPtr[i].iBitmap > 0) ? 
    452                         btnPtr[i].iBitmap : SEPARATOR_WIDTH;
    453         else
    454             cx = infoPtr->nButtonWidth;
    455 
    456         /* Two or more adjacent separators form a separator group.   */
    457         /* The first separator in a group should be wrapped to the   */
    458         /* next row if the previous wrapping is on a button.         */
    459         if( bButtonWrap &&
    460                 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
    461                 (i + 1 < infoPtr->nNumButtons ) &&
    462                 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
    463         {
    464             btnPtr[i].fsState |= TBSTATE_WRAP;
    465             x = infoPtr->nIndent;
    466             i++;
    467             bButtonWrap = FALSE;
    468             continue;
    469         }
    470 
    471         /* The layout makes sure the bitmap is visible, but not the button. */
    472         if ( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
    473                  > infoPtr->nWidth )
    474         {
    475             BOOL bFound = FALSE;
    476 
    477             /*  If the current button is a separator and not hidden,  */
    478             /*  go to the next until it reaches a non separator.      */
    479             /*  Wrap the last separator if it is before a button.     */
    480             while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
    481                         (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
    482                         i < infoPtr->nNumButtons )
    483             {
    484                 i++;
    485                 bFound = TRUE;
    486             }
    487    
    488             if( bFound && i < infoPtr->nNumButtons )
    489             {
    490                 i--;
    491                 btnPtr[i].fsState |= TBSTATE_WRAP;
    492                 x = infoPtr->nIndent;
    493                 bButtonWrap = FALSE;
    494                 continue;
    495             }
    496             else if ( i >= infoPtr->nNumButtons)
    497                 break;
    498 
    499             /*  If the current button is not a separator, find the last  */
    500             /*  separator and wrap it.                                  */
    501             for ( j = i - 1; j >= 0  &&  !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
    502             {
    503                 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
    504                         !(btnPtr[j].fsState & TBSTATE_HIDDEN))
    505                 {
    506                     bFound = TRUE;
    507                     i = j;
    508                     x = infoPtr->nIndent;
    509                     btnPtr[j].fsState |= TBSTATE_WRAP;
    510                     bButtonWrap = FALSE;
    511                     break;
    512                 }
    513             }
    514 
    515             /*  If no separator available for wrapping, wrap one of     */
    516             /*  non-hidden previous button.                             */
    517             if (!bFound)
    518             {
    519                 for ( j = i - 1;
    520                         j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
    521                 {
    522                     if (btnPtr[j].fsState & TBSTATE_HIDDEN)
    523                         continue;
    524 
    525                     bFound = TRUE;
    526                     i = j;
    527                     x = infoPtr->nIndent;
    528                     btnPtr[j].fsState |= TBSTATE_WRAP;
    529                     bButtonWrap = TRUE;
    530                     break;
    531                 }
    532             }
    533 
    534             /* If all above failed, wrap the current button. */
    535             if (!bFound) 
    536             {
    537                 btnPtr[i].fsState |= TBSTATE_WRAP;
    538                 bFound = TRUE;
    539                 x = infoPtr->nIndent;
    540                 if (btnPtr[i].fsState & TBSTYLE_SEP )
    541                     bButtonWrap = FALSE;
    542                 else
    543                     bButtonWrap = TRUE;
    544             }               
    545         }
    546         else
    547             x += cx;
    548     }
    549 }
    550                                                                                        
     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
    551484/***********************************************************************
    552 *               TOOLBAR_CalcToolbar
     485*               TOOLBAR_CalcToolbar
    553486*
    554 * This function calculates button and separator placement. It first 
    555 * calculates the button sizes, gets the toolbar window width and then 
    556 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap 
     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
    557490* on. It assigns a new location to each item and sends this location to
    558 * the tooltip window if appropriate. Finally, it updates the rcBound 
    559 * rect and calculates the new required toolbar window height. 
    560 */ 
     491* the tooltip window if appropriate. Finally, it updates the rcBound
     492* rect and calculates the new required toolbar window height.
     493*/
    561494
    562495static void
     
    564497{
    565498    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
    566     DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
     499    DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
    567500    TBUTTON_INFO *btnPtr;
    568501    INT i, nRows, nSepRows;
    569502    INT x, y, cx, cy;
    570503    SIZE  sizeString;
     504    RECT rc;
    571505    BOOL bWrap;
    572506
     
    574508
    575509    if (dwStyle & TBSTYLE_LIST) {
    576         infoPtr->nButtonHeight = max(infoPtr->nBitmapHeight, sizeString.cy) + 6;
    577         infoPtr->nButtonWidth = infoPtr->nBitmapWidth + sizeString.cx + 6;
     510      infoPtr->nButtonHeight = max(infoPtr->nBitmapHeight, sizeString.cy) + 6;
     511      infoPtr->nButtonWidth = infoPtr->nBitmapWidth + sizeString.cx + 6;
    578512    }
    579513    else {
    580     BOOL usesBitmaps = FALSE;
    581     INT i;
    582 
    583     for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
    584         if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
    585             usesBitmaps = TRUE;
    586 
    587     if (sizeString.cy > 0) {
    588         if (usesBitmaps)
    589           infoPtr->nButtonHeight = sizeString.cy + infoPtr->nBitmapHeight + 6;
    590         else
    591           infoPtr->nButtonHeight = sizeString.cy + 6;
    592     }
    593     else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
    594         infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
    595 
    596     if (sizeString.cx > infoPtr->nBitmapWidth)
    597         infoPtr->nButtonWidth = sizeString.cx + 6;
    598     else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
    599         infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
    600     }
    601 
    602     if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
    603         infoPtr->nButtonWidth = infoPtr->cxMin;
    604     if ( infoPtr->cxMax >= 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
    605         infoPtr->nButtonWidth = infoPtr->cxMax;
     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    }
    606524
    607525    TOOLBAR_WrapToolbar( hwnd, dwStyle );
    608526
    609527    x  = infoPtr->nIndent;
    610     y  = (dwStyle & TBSTYLE_FLAT) ? 0 : TOP_BORDER;
    611 
    612    /*
    613     * We wills et the height below, and we set the width on entry
    614     * so we do not reset them here..
    615     */
    616 #if 0
    617     GetClientRect( hwnd, &rc );
    618     /* get initial values for toolbar */
    619     infoPtr->nWidth  = rc.right - rc.left;
    620     infoPtr->nHeight = rc.bottom - rc.top;
    621 #endif
    622 
    623     /* from above, minimum is a button, and possible text */
     528    y  = (dwStyle & TBSTYLE_FLAT) ? 0: TOP_BORDER;
    624529    cx = infoPtr->nButtonWidth;
    625     /* cannot use just ButtonHeight, we may have no buttons! */
    626     if (infoPtr->nNumButtons > 0)
    627       infoPtr->nHeight = infoPtr->nButtonHeight;
    628     cy = infoPtr->nHeight;
    629 
     530    cy = infoPtr->nButtonHeight;
    630531    nRows = nSepRows = 0;
    631532
     
    636537
    637538    btnPtr = infoPtr->buttons;
    638 
    639     /* do not base height/width on parent, if the parent is a */
    640     /* rebar control it could have multiple rows of toolbars  */
    641 /*    GetClientRect( GetParent(hwnd), &rc ); */
    642 /*    cx = rc.right - rc.left; */
    643 /*    cy = rc.bottom - rc.top; */
     539    GetClientRect( GetParent(hwnd), &rc );
     540    infoPtr->nWidth = rc.right - rc.left;
    644541
    645542    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
    646543    {
    647         bWrap = FALSE;
    648         if (btnPtr->fsState & TBSTATE_HIDDEN)
    649         {
    650             SetRectEmpty (&btnPtr->rect);
    651             continue;
    652         }
    653 
    654             /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
    655             /* it is the actual width of the separator. This is used for */
    656             /* custom controls in toolbars.                              */
    657         if (btnPtr->fsStyle & TBSTYLE_SEP)
    658                 cx = (btnPtr->iBitmap > 0) ?
    659                      btnPtr->iBitmap : SEPARATOR_WIDTH;
    660         else {
    661             if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
     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;
     592            else
    662593            {
    663               SIZE sz;
    664               TOOLBAR_MeasureString(hwnd,i,&sz);
    665               cx = sz.cx + 6;
     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++;
    666603            }
    667             else
    668               cx = infoPtr->nButtonWidth;
    669         }
    670         cy = infoPtr->nHeight;
    671 
    672         if (btnPtr->fsState & TBSTATE_WRAP )
    673                     bWrap = TRUE;
    674 
    675         SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
    676 
    677         if (infoPtr->rcBound.left > x)
    678             infoPtr->rcBound.left = x;
    679         if (infoPtr->rcBound.right < x + cx)
    680             infoPtr->rcBound.right = x + cx;
    681         if (infoPtr->rcBound.bottom < y + cy)
    682             infoPtr->rcBound.bottom = y + cy;
    683 
    684         /* Set the toolTip only for non-hidden, non-separator button */
    685         if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
    686         {
    687             TTTOOLINFOA ti;
    688 
    689             ZeroMemory (&ti, sizeof(TTTOOLINFOA));
    690             ti.cbSize = sizeof(TTTOOLINFOA);
    691             ti.hwnd = hwnd;
    692             ti.uId = btnPtr->idCommand;
    693             ti.rect = btnPtr->rect;
    694             SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
    695                             0, (LPARAM)&ti);
    696         }
    697 
    698         /* btnPtr->nRow is zero based. The space between the rows is    */
    699         /* also considered as a row.                                    */
    700         btnPtr->nRow = nRows + nSepRows;
    701         if( bWrap )
    702         {
    703             if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
    704             y += cy;
    705             else
    706             {   
    707                 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
    708                 /* it is the actual width of the separator. This is used for */
    709                 /* custom controls in toolbars.                              */
    710                 y += cy + ( (btnPtr->iBitmap > 0 ) ?
    711                         btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
    712              
    713                 /* nSepRows is used to calculate the extra height follwoing  */         
    714                 /* the last row.                                             */
    715                 nSepRows++;
    716             }
    717             x = infoPtr->nIndent;
    718                 nRows++;
    719         }
    720         else
    721             x += cx;
     604            x = infoPtr->nIndent;
     605                nRows++;
     606        }
     607        else
     608            x += cx;
    722609    }
    723610
     
    725612    infoPtr->nRows = nRows + nSepRows + 1;
    726613
    727     /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following   */
    728     /* the last row.                                                    */
    729     infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight + 
    730                         nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
    731                         nSepRows * (infoPtr->nBitmapHeight + 1) +
    732                         BOTTOM_BORDER;
    733     // TRACE("toolbar height %d\n", infoPtr->nHeight);
     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);
    734621}
    735622
     
    741628    TBUTTON_INFO *btnPtr;
    742629    INT i;
    743    
     630
    744631    btnPtr = infoPtr->buttons;
    745632    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
    746         if (btnPtr->fsState & TBSTATE_HIDDEN)
    747             continue;
    748 
    749         if (btnPtr->fsStyle & TBSTYLE_SEP) {
    750             if (PtInRect (&btnPtr->rect, *lpPt)) {
    751                 // TRACE(" ON SEPARATOR %d!\n", i);
    752                 return -i;
    753             }
    754         }
    755         else {
    756             if (PtInRect (&btnPtr->rect, *lpPt)) {
    757                 // TRACE(" ON BUTTON %d!\n", i);
    758                 return i;
    759             }
    760         }
    761     }
    762 
    763     // TRACE(" NOWHERE!\n");
     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");
    764651    return -1;
    765652}
     
    774661    btnPtr = infoPtr->buttons;
    775662    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
    776         if (btnPtr->idCommand == idCommand) {
    777             // TRACE("command=%d index=%d\n", idCommand, i);
    778             return i;
    779         }
    780     }
    781     // TRACE("no index found for command=%d\n", idCommand);
     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);
    782669    return -1;
    783670}
     
    791678
    792679    if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
    793         return -1;
     680        return -1;
    794681
    795682    /* check index button */
    796683    btnPtr = &infoPtr->buttons[nIndex];
    797684    if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
    798         if (btnPtr->fsState & TBSTATE_CHECKED)
    799             return nIndex;
     685        if (btnPtr->fsState & TBSTATE_CHECKED)
     686            return nIndex;
    800687    }
    801688
     
    803690    nRunIndex = nIndex - 1;
    804691    while (nRunIndex >= 0) {
    805         btnPtr = &infoPtr->buttons[nRunIndex];
    806         if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
    807             if (btnPtr->fsState & TBSTATE_CHECKED)
    808                 return nRunIndex;
    809         }
    810         else
    811             break;
    812         nRunIndex--;
     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--;
    813700    }
    814701
     
    816703    nRunIndex = nIndex + 1;
    817704    while (nRunIndex < infoPtr->nNumButtons) {
    818         btnPtr = &infoPtr->buttons[nRunIndex]; 
    819         if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
    820             if (btnPtr->fsState & TBSTATE_CHECKED)
    821                 return nRunIndex;
    822         }
    823         else
    824             break;
    825         nRunIndex++;
     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++;
    826713    }
    827714
     
    832719static VOID
    833720TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
    834                     WPARAM wParam, LPARAM lParam)
     721                    WPARAM wParam, LPARAM lParam)
    835722{
    836723    MSG msg;
     
    840727    msg.wParam = wParam;
    841728    msg.lParam = lParam;
    842     msg.time = GetMessageTime ();
    843     msg.pt.x = LOWORD(GetMessagePos ());
    844     msg.pt.y = HIWORD(GetMessagePos ());
    845 
    846     SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
    847 }
    848 
     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
     736static 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
     819static VOID TBCUSTOMIZE_AvailSelChange(HWND hwnd);
     820static VOID TBCUSTOMIZE_VisSelChange(HWND hwnd);
     821
     822static 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
     894static 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
     937static BOOL TBCUSTOMIZE_Close(HWND hwnd,WPARAM wParam,LPARAM lParam)
     938{
     939  EndDialog(hwnd,FALSE);
     940
     941  return TRUE;
     942}
     943
     944static 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
     973static 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
     986static 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
     1097static 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
     1217static 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
     1225static 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
     1263static 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
     1304static 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
     1315static 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
     1346static 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
     1406static 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
     1420static 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}
    8491511
    8501512/***********************************************************************
     
    8551517TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    8561518{
    857     TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongA (hwnd, DWL_USER);
    858     static HDSA hDsa = NULL;
     1519    TOOLBAR_INFO *infoPtr;
    8591520
    8601521    switch (uMsg)
    8611522    {
    862         case WM_INITDIALOG:
    863             infoPtr = (TOOLBAR_INFO *)lParam;
    864             SetWindowLongA (hwnd, DWL_USER, (DWORD)infoPtr);
    865 
    866             hDsa = DSA_Create (sizeof(TBUTTON_INFO), 5);
    867 
    868             if (infoPtr)
    869             {
    870                 TBUTTON_INFO *btnPtr;
    871                 INT i;
    872 
    873                 /* insert 'virtual' separator button into 'available buttons' list */
    874                 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
    875 
    876                 /* copy all buttons and append them to the right listbox */             
    877                 btnPtr = infoPtr->buttons;
    878                 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
    879                 {
    880                     DSA_InsertItem (hDsa, i, btnPtr);
    881 
    882                     /* FIXME: hidden buttons appear in the 'toolbar buttons' list too */
    883                     if (btnPtr->fsState & TBSTATE_HIDDEN)
    884                     {
    885                         SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
    886                     }
    887                     else
    888                     {
    889                         SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
    890                     }
    891                 }
    892 
    893                 /* append 'virtual' separator button to the 'toolbar buttons' list */
    894                 /* TODO */
    895             }
    896             return TRUE;
    897 
    898         case WM_CLOSE:
    899             EndDialog(hwnd, FALSE);
    900             return TRUE;
    901 
    902         case WM_COMMAND:
    903             switch (LOWORD(wParam))
    904             {
    905                 case IDCANCEL:
    906                     EndDialog(hwnd, FALSE);
    907                     break;
    908             }
    909             return TRUE;
    910 
    911         case WM_DESTROY:
    912             if (hDsa)
    913                 DSA_Destroy (hDsa);
    914             return TRUE;
    915 
    916         case WM_DRAWITEM:
    917             if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
    918             {
    919                 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
    920                 TBUTTON_INFO btnPtr;
    921                 RECT rcButton;
    922                 RECT rcText;
    923                 HPEN hOldPen;
    924                 HBRUSH hOldBrush;
    925                 COLORREF oldText = 0;
    926                 COLORREF oldBk = 0;
    927 
    928                 // FIXME("action: %x itemState: %x\n",
    929                 //    lpdis->itemAction, lpdis->itemState);             
    930 
    931                 DSA_GetItem (hDsa, 0 /*lpdis->itemID*/, &btnPtr);
    932 
    933                 if (lpdis->itemState & ODS_FOCUS)
    934                 {
    935                     oldBk = SetBkColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
    936                     oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
    937                 }
    938 
    939                 hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
    940                 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
    941 
    942                 /* fill background rectangle */
    943                 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
    944                            lpdis->rcItem.right, lpdis->rcItem.bottom);
    945 
    946                 /* calculate button and text rectangles */
    947                 CopyRect (&rcButton, &lpdis->rcItem);
    948                 InflateRect (&rcButton, -1, -1);
    949                 CopyRect (&rcText, &rcButton);
    950                 rcButton.right = rcButton.left + infoPtr->nBitmapWidth + 6;
    951                 rcText.left = rcButton.right + 2;
    952 
    953                 /* draw focus rectangle */
    954                 if (lpdis->itemState & ODS_FOCUS)
    955                     DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
    956 
    957                 /* draw button */
    958                 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
    959 
    960                 /* draw image and text */
    961                 if (wParam == IDC_AVAILBTN_LBOX && lpdis->itemID == 0)
    962                 {
    963                     /* virtual separator in the 'available' list */
    964                     DrawTextA (lpdis->hDC, "Separator", -1, &rcText,
    965                                DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    966                 }
    967                 else
    968                 {
    969                     /* real button */
    970 
    971                     ImageList_Draw (infoPtr->himlDef, btnPtr.iBitmap, lpdis->hDC,
    972                                     rcButton.left+1, rcButton.top+1, ILD_NORMAL);
    973 
    974                     DrawTextW (lpdis->hDC,  infoPtr->strings[btnPtr.iString], -1, &rcText,
    975                                DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    976 
    977                 }
    978 
    979                 if (lpdis->itemState & ODS_FOCUS)
    980                 {
    981                     SetBkColor (lpdis->hDC, oldBk);
    982                     SetTextColor (lpdis->hDC, oldText);
    983                 }
    984 
    985                 SelectObject (lpdis->hDC, hOldBrush);
    986                 SelectObject (lpdis->hDC, hOldPen);
    987 
    988                 return TRUE;
    989             }
    990             return FALSE;
    991 
    992         case WM_MEASUREITEM:
    993             if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
    994             {
    995                 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
    996 
    997                 if (infoPtr)
    998                     lpmis->itemHeight = infoPtr->nBitmapHeight + 8;
    999                 else
    1000                     lpmis->itemHeight = 15 + 8; /* default height */
    1001 
    1002                 return TRUE;
    1003             }
    1004             return FALSE;
    1005 
    1006         default:
    1007             return FALSE;
    1008     }
    1009 }
    1010 
     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}
    10111542
    10121543/***********************************************************************
     
    10191550    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    10201551    LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
    1021     INT nIndex = 0, nButtons, nCount;
     1552    INT nIndex = 0,nButtons;
    10221553    HBITMAP hbmLoad;
    10231554
    1024     // TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
    10251555    if (!lpAddBmp)
    1026         return -1;
     1556        return -1;
    10271557
    10281558    if (lpAddBmp->hInst == HINST_COMMCTRL)
    10291559    {
    1030         if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
    1031             nButtons = 15;
    1032         else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
    1033             nButtons = 13;
    1034         else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
    1035             nButtons = 5;
    1036         else
    1037             return -1;
    1038 
    1039         // TRACE ("adding %d internal bitmaps!\n", nButtons);
    1040 
    1041         /* Windows resize all the buttons to the size of a newly added standard image */
    1042         if (lpAddBmp->nID & 1)
    1043         {
    1044             /* large icons */
    1045             SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
    1046                           MAKELPARAM((WORD)26, (WORD)26));
    1047             SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
    1048                           MAKELPARAM((WORD)33, (WORD)33));
    1049         }       
    1050         else
    1051         {
    1052             /* small icons */
    1053             SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
    1054                           MAKELPARAM((WORD)16, (WORD)16));
    1055             SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
    1056                           MAKELPARAM((WORD)22, (WORD)22));
    1057         }
    1058        
    1059         TOOLBAR_CalcToolbar (hwnd);
     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);
    10601590    }
    10611591    else
    10621592    {
    1063         nButtons = (INT)wParam;
    1064         if (nButtons <= 0)
    1065             return -1;
    1066        
    1067         // TRACE ("adding %d bitmaps!\n", nButtons);
    1068     }
    1069    
     1593        nButtons = (INT)wParam;
     1594        if (nButtons <= 0)
     1595            return -1;
     1596
     1597        //TRACE ("adding %d bitmaps!\n", nButtons);
     1598    }
     1599
    10701600    if (!(infoPtr->himlDef)) {
    1071         /* create new default image list */
    1072         // TRACE ("creating default image list!\n");
    1073 
     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     
    10741605        infoPtr->himlDef =
    1075             ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
     1606            ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight-1,
    10761607                              ILC_COLOR | ILC_MASK, nButtons, 2);
    1077         infoPtr->himlInt = infoPtr->himlDef;
    1078     }
    1079 
    1080     nCount = ImageList_GetImageCount(infoPtr->himlDef);
     1608        infoPtr->himlInt = infoPtr->himlDef;
     1609    }
    10811610
    10821611    /* Add bitmaps to the default image list */
    10831612    if (lpAddBmp->hInst == (HINSTANCE)0)
    10841613    {
    1085         nIndex =
    1086             ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
    1087                                 CLR_DEFAULT);
     1614        nIndex =
     1615            ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
     1616                                CLR_DEFAULT);
    10881617    }
    10891618    else if (lpAddBmp->hInst == HINST_COMMCTRL)
    10901619    {
    1091         /* Add system bitmaps */
    1092         switch (lpAddBmp->nID)
    1093     {
    1094             case IDB_STD_SMALL_COLOR:
    1095                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1096                                        MAKEINTRESOURCEA(IDB_STD_SMALL));
    1097                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1098                                               hbmLoad, CLR_DEFAULT);
    1099                 DeleteObject (hbmLoad);
    1100                 break;
    1101 
    1102             case IDB_STD_LARGE_COLOR:
    1103                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1104                                        MAKEINTRESOURCEA(IDB_STD_LARGE));
    1105                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1106                                               hbmLoad, CLR_DEFAULT);
    1107                 DeleteObject (hbmLoad);
    1108                 break;
    1109 
    1110             case IDB_VIEW_SMALL_COLOR:
    1111                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1112                                        MAKEINTRESOURCEA(IDB_VIEW_SMALL));
    1113                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1114                                               hbmLoad, CLR_DEFAULT);
    1115                 DeleteObject (hbmLoad);
    1116                 break;
    1117 
    1118             case IDB_VIEW_LARGE_COLOR:
    1119                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1120                                        MAKEINTRESOURCEA(IDB_VIEW_LARGE));
    1121                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1122                                               hbmLoad, CLR_DEFAULT);
    1123                 DeleteObject (hbmLoad);
    1124                 break;
    1125 
    1126             case IDB_HIST_SMALL_COLOR:
    1127                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1128                                        MAKEINTRESOURCEA(IDB_HIST_SMALL));
    1129                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1130                                               hbmLoad, CLR_DEFAULT);
    1131                 DeleteObject (hbmLoad);
    1132                 break;
    1133 
    1134             case IDB_HIST_LARGE_COLOR:
    1135                 hbmLoad = LoadBitmapA (COMCTL32_hModule,
    1136                                        MAKEINTRESOURCEA(IDB_HIST_LARGE));
    1137                 nIndex = ImageList_AddMasked (infoPtr->himlDef,
    1138                                               hbmLoad, CLR_DEFAULT);
    1139                 DeleteObject (hbmLoad);
    1140                 break;
    1141 
    1142             default:
    1143         nIndex = ImageList_GetImageCount (infoPtr->himlDef);
    1144         // ERR ("invalid imagelist!\n");
    1145                 break;
    1146         }
     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        }
    11471676    }
    11481677    else
    11491678    {
    1150         hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
    1151         nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
    1152         DeleteObject (hbmLoad);
    1153     }
    1154 
    1155     if (nIndex != -1)
    1156     {
    1157        INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
    1158 
    1159        if (infoPtr->nNumBitmaps + nButtons != imagecount)
    1160        {
    1161          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",
    1162               infoPtr->nNumBitmaps, nCount, imagecount - nCount,
    1163               infoPtr->nNumBitmaps+nButtons,imagecount));
    1164 
    1165          infoPtr->nNumBitmaps = imagecount;
    1166        }
    1167        else
    1168          infoPtr->nNumBitmaps += nButtons;
    1169     }
     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;
    11701685
    11711686    return nIndex;
     
    11801695    INT nOldButtons, nNewButtons, nAddButtons, nCount;
    11811696
    1182     // TRACE("adding %d buttons!\n", wParam);
     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
     1754static LRESULT
     1755TOOLBAR_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);
    11831762
    11841763    nAddButtons = (UINT)wParam;
     
    11871766
    11881767    if (infoPtr->nNumButtons == 0) {
    1189         infoPtr->buttons =
    1190             (TBUTTON_INFO*) COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
     1768        infoPtr->buttons =
     1769            (TBUTTON_INFO*)COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
    11911770    }
    11921771    else {
    1193         TBUTTON_INFO *oldButtons = infoPtr->buttons;
    1194         infoPtr->buttons =
    1195             (TBUTTON_INFO*) COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
    1196         memcpy (&infoPtr->buttons[0], &oldButtons[0],
    1197                 nOldButtons * sizeof(TBUTTON_INFO));
     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));
    11981777        COMCTL32_Free (oldButtons);
    11991778    }
     
    12031782    /* insert new button data */
    12041783    for (nCount = 0; nCount < nAddButtons; nCount++) {
    1205         TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
    1206         btnPtr->iBitmap   = lpTbb[nCount].iBitmap;
    1207         btnPtr->idCommand = lpTbb[nCount].idCommand;
    1208         btnPtr->fsState   = lpTbb[nCount].fsState;
    1209         btnPtr->fsStyle   = lpTbb[nCount].fsStyle;
    1210         btnPtr->dwData    = lpTbb[nCount].dwData;
    1211         btnPtr->iString   = lpTbb[nCount].iString;
    1212         btnPtr->bHot      = FALSE;
    1213 
    1214         if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
    1215             TTTOOLINFOA ti;
    1216 
    1217             ZeroMemory (&ti, sizeof(TTTOOLINFOA));
    1218             ti.cbSize   = sizeof (TTTOOLINFOA);
    1219             ti.hwnd     = hwnd;
    1220             ti.uId      = btnPtr->idCommand;
    1221             ti.hinst    = 0;
    1222             ti.lpszText = LPSTR_TEXTCALLBACKA;
    1223 
    1224             SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
    1225                             0, (LPARAM)&ti);
    1226         }
     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        }
    12271806    }
    12281807
     
    12361815
    12371816static LRESULT
    1238 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1239 {
    1240     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    1241     LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
    1242     INT nOldButtons, nNewButtons, nAddButtons, nCount;
    1243 
    1244     // TRACE("adding %d buttons!\n", wParam);
    1245 
    1246     nAddButtons = (UINT)wParam;
    1247     nOldButtons = infoPtr->nNumButtons;
    1248     nNewButtons = nOldButtons + nAddButtons;
    1249 
    1250     if (infoPtr->nNumButtons == 0) {
    1251         infoPtr->buttons =
    1252             (TBUTTON_INFO*)COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
     1817TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
     1818{
     1819    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     1820    INT nIndex;
     1821
     1822    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++;
    12531849    }
    12541850    else {
    1255         TBUTTON_INFO *oldButtons = infoPtr->buttons;
    1256         infoPtr->buttons =
    1257             (TBUTTON_INFO*)COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
    1258         memcpy (&infoPtr->buttons[0], &oldButtons[0],
    1259                 nOldButtons * sizeof(TBUTTON_INFO));
    1260         COMCTL32_Free (oldButtons);
    1261     }
    1262 
    1263     infoPtr->nNumButtons = nNewButtons;
    1264 
    1265     /* insert new button data */
    1266     for (nCount = 0; nCount < nAddButtons; nCount++) {
    1267         TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
    1268         btnPtr->iBitmap   = lpTbb[nCount].iBitmap;
    1269         btnPtr->idCommand = lpTbb[nCount].idCommand;
    1270         btnPtr->fsState   = lpTbb[nCount].fsState;
    1271         btnPtr->fsStyle   = lpTbb[nCount].fsStyle;
    1272         btnPtr->dwData    = lpTbb[nCount].dwData;
    1273         btnPtr->iString   = lpTbb[nCount].iString;
    1274         btnPtr->bHot      = FALSE;
    1275 
    1276         if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
    1277             TTTOOLINFOW ti;
    1278 
    1279             ZeroMemory (&ti, sizeof(TTTOOLINFOW));
    1280             ti.cbSize   = sizeof (TTTOOLINFOW);
    1281             ti.hwnd     = hwnd;
    1282             ti.uId      = btnPtr->idCommand;
    1283             ti.hinst    = 0;
    1284             ti.lpszText = LPSTR_TEXTCALLBACKW;
    1285 
    1286             SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
    1287                             0, (LPARAM)&ti);
    1288         }
    1289     }
    1290 
    1291     TOOLBAR_CalcToolbar (hwnd);
    1292 
    1293     InvalidateRect(hwnd, NULL, FALSE);
    1294 
    1295     return TRUE;
    1296 }
    1297 
    1298 
    1299 static LRESULT
    1300 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1301 {
    1302     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    1303     INT nIndex;
    1304 
    1305     if ((wParam) && (HIWORD(lParam) == 0)) {
    1306         char szString[256];
    1307         INT len;
    1308         // TRACE("adding string from resource!\n");
    1309 
    1310         len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
    1311                              szString, 256);
    1312 
    1313         // TRACE("len=%d \"%s\"\n", len, szString);
    1314         nIndex = infoPtr->nNumStrings;
    1315         if (infoPtr->nNumStrings == 0) {
    1316             infoPtr->strings =
    1317                 (LPWSTR*) COMCTL32_Alloc (sizeof(LPWSTR));
    1318         }
    1319         else {
    1320             LPWSTR *oldStrings = infoPtr->strings;
    1321             infoPtr->strings =
    1322                 (LPWSTR*) COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
    1323             memcpy (&infoPtr->strings[0], &oldStrings[0],
    1324                     sizeof(LPWSTR) * infoPtr->nNumStrings);
    1325             COMCTL32_Free (oldStrings);
    1326         }
    1327 
    1328         infoPtr->strings[infoPtr->nNumStrings] =
    1329             (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
    1330         lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], szString);
    1331         infoPtr->nNumStrings++;
    1332     }
    1333     else {
    1334         LPSTR p = (LPSTR)lParam;
    1335         INT len;
    1336 
    1337         if (p == NULL)
    1338             return -1;
    1339         // TRACE("adding string(s) from array!\n");
    1340 
    1341         nIndex = infoPtr->nNumStrings;
    1342         while (*p) {
    1343             len = lstrlenA (p);
    1344             // TRACE("len=%d \"%s\"\n", len, p);
    1345 
    1346             if (infoPtr->nNumStrings == 0) {
    1347                 infoPtr->strings =
    1348                    (LPWSTR*) COMCTL32_Alloc (sizeof(LPWSTR));
    1349             }
    1350             else {
    1351                 LPWSTR *oldStrings = infoPtr->strings;
    1352                 infoPtr->strings =
    1353                     (LPWSTR*) COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
    1354                 memcpy (&infoPtr->strings[0], &oldStrings[0],
    1355                         sizeof(LPWSTR) * infoPtr->nNumStrings);
    1356                 COMCTL32_Free (oldStrings);
    1357             }
    1358 
    1359             infoPtr->strings[infoPtr->nNumStrings] =
    1360                 (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
    1361             lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], p);
    1362             infoPtr->nNumStrings++;
    1363 
    1364             p += (len+1);
    1365         }
    1366     }
    1367 
    1368     return nIndex;
    1369 }
    1370 
    1371 
    1372 static LRESULT
    1373 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1374 {
    1375 #define MAX_RESOURCE_STRING_LENGTH 512
    1376     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    1377     INT nIndex;
    1378 
    1379     if ((wParam) && (HIWORD(lParam) == 0)) {
    1380         WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
    1381         INT len;
    1382         // TRACE("adding string from resource!\n");
    1383 
    1384         len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
    1385                              szString, MAX_RESOURCE_STRING_LENGTH);
    1386 
    1387         // TRACE("len=%d \"%s\"\n", len, debugstr_w(szString));
    1388         // TRACE("First char: 0x%x\n", *szString);
    1389         if (szString[0] == L'|')
    1390         {
    1391             PWSTR p = szString + 1;
    1392                
    1393             nIndex = infoPtr->nNumStrings;
    1394             while (*p != L'|') {
    1395 
    1396             if (infoPtr->nNumStrings == 0) {
    1397                 infoPtr->strings =
    1398                     (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR));
    1399             }
    1400             else {
    1401                 LPWSTR *oldStrings = infoPtr->strings;
    1402                 infoPtr->strings =
    1403                     (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
    1404                 memcpy (&infoPtr->strings[0], &oldStrings[0],
    1405                         sizeof(LPWSTR) * infoPtr->nNumStrings);
    1406                 COMCTL32_Free (oldStrings);
    1407             }
    1408 
    1409             len = COMCTL32_StrChrW (p, L'|') - p;
    1410             // TRACE("len=%d \"%s\"\n", len, debugstr_w(p));
    1411             infoPtr->strings[infoPtr->nNumStrings] =
    1412                 (WCHAR *)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
    1413             lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len);
    1414             infoPtr->nNumStrings++;
    1415 
    1416                 p += (len+1);
    1417             }
    1418         }
    1419         else
    1420         {
    1421             nIndex = infoPtr->nNumStrings;
     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
    14221862            if (infoPtr->nNumStrings == 0) {
    14231863                infoPtr->strings =
     
    14351875            infoPtr->strings[infoPtr->nNumStrings] =
    14361876                (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
    1437             lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
     1877            lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], p);
    14381878            infoPtr->nNumStrings++;
    1439         }
     1879
     1880            p += (len+1);
     1881        }
     1882    }
     1883
     1884    return nIndex;
     1885}
     1886
     1887
     1888static LRESULT
     1889TOOLBAR_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++;
    14401921    }
    14411922    else {
    1442         LPWSTR p = (LPWSTR)lParam;
    1443         INT len;
    1444 
    1445         if (p == NULL)
    1446             return -1;
    1447         // TRACE("adding string(s) from array!\n");
    1448         nIndex = infoPtr->nNumStrings;
    1449         while (*p) {
    1450             len = lstrlenW (p);
    1451 
    1452             // TRACE("len=%d \"%s\"\n", len, debugstr_w(p));
    1453             if (infoPtr->nNumStrings == 0) {
    1454                 infoPtr->strings =
    1455                     (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR));
    1456             }
    1457             else {
    1458                 LPWSTR *oldStrings = infoPtr->strings;
    1459                 infoPtr->strings =
    1460                     (LPWSTR*)COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
    1461                 memcpy (&infoPtr->strings[0], &oldStrings[0],
    1462                         sizeof(LPWSTR) * infoPtr->nNumStrings);
    1463                 COMCTL32_Free (oldStrings);
    1464             }
    1465 
    1466             infoPtr->strings[infoPtr->nNumStrings] =
    1467                 (WCHAR*)COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
    1468             lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
    1469             infoPtr->nNumStrings++;
    1470 
    1471             p += (len+1);
    1472         }
     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        }
    14731954    }
    14741955
     
    14831964    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    14841965    RECT parent_rect;
    1485     RECT window_rect;
    14861966    HWND parent;
    14871967    INT  x, y;
    14881968    INT  cx, cy;
    1489     UINT uPosFlags = SWP_NOZORDER;
    1490 
    1491     // TRACE("resize forced, style=%lx!\n", dwStyle);
    1492 
     1969    UINT uPosFlags = 0;
     1970
     1971    //TRACE (toolbar, "resize forced!\n");
     1972
     1973    x = y = 0;
    14931974    parent = GetParent (hwnd);
    14941975    GetClientRect(parent, &parent_rect);
    14951976
    1496     x = parent_rect.left;
    1497     y = parent_rect.top;
    1498 
    14991977    if (dwStyle & CCS_NORESIZE) {
    1500         uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
    1501         cx = 0;
    1502         cy = 0;
     1978        uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
     1979        cx = 0;
     1980        cy = 0;
    15031981    }
    15041982    else {
    1505         infoPtr->nWidth = parent_rect.right - parent_rect.left;
    1506         TOOLBAR_CalcToolbar (hwnd);
    1507         InvalidateRect( hwnd, NULL, TRUE );
    1508         cy = infoPtr->nHeight;
    1509         cx = infoPtr->nWidth;
    1510 
    1511         if (dwStyle & CCS_NOMOVEY) {
    1512                 GetWindowRect(hwnd, &window_rect);
    1513                 ScreenToClient(parent, (LPPOINT)&window_rect.left);
    1514                 y = window_rect.top;
    1515         }
     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;
    15161988    }
    15171989
    15181990    if (dwStyle & CCS_NOPARENTALIGN)
    1519         uPosFlags |= SWP_NOMOVE;
     1991        uPosFlags |= SWP_NOMOVE;
    15201992
    15211993    if (!(dwStyle & CCS_NODIVIDER))
    1522         cy += GetSystemMetrics(SM_CYEDGE);
     1994        cy += GetSystemMetrics(SM_CYEDGE);
    15231995
    15241996    if (dwStyle & WS_BORDER)
     
    15312003    infoPtr->bAutoSize = TRUE;
    15322004    SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
    1533                         cx, cy, uPosFlags);
     2005                    cx, cy, uPosFlags);
     2006
    15342007    /* The following line makes sure that the infoPtr->bAutoSize is turned off after
    15352008     * the setwindowpos calls */
     
    15552028
    15562029    if (infoPtr == NULL) {
    1557 // ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
    1558 // ERR("infoPtr == NULL!\n");
    1559         return 0;
     2030//      ERR (toolbar, "(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
     2031//      ERR (toolbar, "infoPtr == NULL!\n");
     2032        return 0;
    15602033    }
    15612034
     
    15712044    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    15722045    TBUTTON_INFO *btnPtr;
     2046    HDC hdc;
    15732047    INT nIndex;
    15742048
    15752049    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    15762050    if (nIndex == -1)
    1577         return FALSE;
     2051        return FALSE;
    15782052
    15792053    btnPtr = &infoPtr->buttons[nIndex];
    15802054    btnPtr->iBitmap = LOWORD(lParam);
    15812055
    1582     InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     2056    hdc = GetDC (hwnd);
     2057    TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
     2058    ReleaseDC (hwnd, hdc);
    15832059
    15842060    return TRUE;
     
    15912067    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    15922068    TBUTTON_INFO *btnPtr;
     2069    HDC hdc;
    15932070    INT nIndex;
    15942071    INT nOldIndex = -1;
     
    15972074    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    15982075    if (nIndex == -1)
    1599         return FALSE;
     2076        return FALSE;
    16002077
    16012078    btnPtr = &infoPtr->buttons[nIndex];
    16022079
    16032080    if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
    1604         return FALSE;
     2081        return FALSE;
    16052082
    16062083    bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
    16072084
    16082085    if (LOWORD(lParam) == FALSE)
    1609         btnPtr->fsState &= ~TBSTATE_CHECKED;
     2086        btnPtr->fsState &= ~TBSTATE_CHECKED;
    16102087    else {
    1611         if (btnPtr->fsStyle & TBSTYLE_GROUP) {
    1612             nOldIndex =
    1613                 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
    1614             if (nOldIndex == nIndex)
    1615                 return 0;
    1616             if (nOldIndex != -1)
    1617                 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
    1618         }
    1619         btnPtr->fsState |= TBSTATE_CHECKED;
     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;
    16202097    }
    16212098
    16222099    if( bChecked != LOWORD(lParam) )
    16232100    {
    1624         if (nOldIndex != -1)
    1625             InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
    1626         InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     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);
    16272106    }
    16282107
     
    16402119    return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    16412120}
    1642 
    16432121
    16442122static LRESULT
     
    16492127    LPCVOID temp;
    16502128    HRSRC hRes;
    1651     NMHDR nmhdr;
     2129
     2130    if (infoPtr->nNumButtons == 0) return 0;
    16522131
    16532132    /* send TBN_BEGINADJUST notification */
    1654     nmhdr.hwndFrom = hwnd;
    1655     nmhdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
    1656     nmhdr.code     = TBN_BEGINADJUST;
    1657 
    1658     SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
    1659                   (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
     2133    sendNotify(hwnd,TBN_BEGINADJUST);
    16602134
    16612135    if (!(hRes = FindResourceA (COMCTL32_hModule,
    16622136                                MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
    16632137                                RT_DIALOGA)))
    1664         return FALSE;
     2138        return FALSE;
    16652139
    16662140    if(!(temp = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
    1667         return FALSE;
     2141        return FALSE;
    16682142
    16692143    ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
     
    16742148
    16752149    /* send TBN_ENDADJUST notification */
    1676     nmhdr.code = TBN_ENDADJUST;
    1677 
    1678     SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
    1679                   (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
     2150    sendNotify(hwnd,TBN_ENDADJUST);
    16802151
    16812152    return ret;
     
    16902161
    16912162    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    1692         return FALSE;
    1693 
    1694     if ((infoPtr->hwndToolTip) &&
    1695         !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
    1696         TTTOOLINFOA ti;
    1697 
    1698         ZeroMemory (&ti, sizeof(TTTOOLINFOA));
    1699         ti.cbSize   = sizeof (TTTOOLINFOA);
    1700         ti.hwnd     = hwnd;
    1701         ti.uId      = infoPtr->buttons[nIndex].idCommand;
    1702 
    1703         SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
    1704     }
    1705 
    1706     if (infoPtr->nNumButtons == 1) {
    1707         // TRACE(" simple delete!\n");
    1708         COMCTL32_Free (infoPtr->buttons);
    1709         infoPtr->buttons = NULL;
    1710         infoPtr->nNumButtons = 0;
    1711     }
    1712     else {
    1713         TBUTTON_INFO *oldButtons = infoPtr->buttons;
    1714         // TRACE("complex delete! [nIndex=%d]\n", nIndex);
    1715 
    1716         infoPtr->nNumButtons--;
    1717         infoPtr->buttons = (TBUTTON_INFO*)COMCTL32_Alloc (sizeof (TBUTTON_INFO) * 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);
    17182192        if (nIndex > 0) {
    17192193            memcpy (&infoPtr->buttons[0], &oldButtons[0],
     
    17262200        }
    17272201
    1728         COMCTL32_Free (oldButtons);
     2202        COMCTL32_Free (oldButtons);
    17292203    }
    17302204
     
    17422216    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    17432217    TBUTTON_INFO *btnPtr;
     2218    HDC hdc;
    17442219    INT nIndex;
    1745     DWORD bState;
     2220    BOOL bEnabled = FALSE;
    17462221
    17472222    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    17482223    if (nIndex == -1)
    1749         return FALSE;
     2224        return FALSE;
    17502225
    17512226    btnPtr = &infoPtr->buttons[nIndex];
    1752 
    1753     bState = btnPtr->fsState & TBSTATE_ENABLED;
    1754 
    1755     /* update the toolbar button state */
    1756     if(LOWORD(lParam) == FALSE) {
    1757         btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
    1758     } else {
    1759         btnPtr->fsState |= TBSTATE_ENABLED;
    1760     }
    1761 
    1762     /* redraw the button only if the state of the button changed */
    1763     if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
    1764         InvalidateRect(hwnd, &btnPtr->rect, TRUE);           
     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    }
    17652240
    17662241    return TRUE;
     
    17682243
    17692244
    1770 static inline LRESULT
     2245static LRESULT
    17712246TOOLBAR_GetAnchorHighlight (HWND hwnd)
    17722247{
     
    17852260    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    17862261    if (nIndex == -1)
    1787         return -1;
     2262        return -1;
    17882263
    17892264    return infoPtr->buttons[nIndex].iBitmap;
     
    17912266
    17922267
    1793 static inline LRESULT
     2268static LRESULT
    17942269TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
    17952270{
     
    18072282
    18082283    if (infoPtr == NULL)
    1809         return FALSE;
     2284        return FALSE;
    18102285
    18112286    if (lpTbb == NULL)
    1812         return FALSE;
     2287        return FALSE;
    18132288
    18142289    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    1815         return FALSE;
     2290        return FALSE;
    18162291
    18172292    btnPtr = &infoPtr->buttons[nIndex];
     
    18362311
    18372312    if (infoPtr == NULL)
    1838         return -1;
     2313        return -1;
    18392314    if (lpTbInfo == NULL)
    1840         return -1;
     2315        return -1;
    18412316    if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
    1842         return -1;
     2317        return -1;
    18432318
    18442319    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    18452320    if (nIndex == -1)
    1846         return -1;
     2321        return -1;
    18472322
    18482323    btnPtr = &infoPtr->buttons[nIndex];
    18492324
    18502325    if (lpTbInfo->dwMask & TBIF_COMMAND)
    1851         lpTbInfo->idCommand = btnPtr->idCommand;
     2326        lpTbInfo->idCommand = btnPtr->idCommand;
    18522327    if (lpTbInfo->dwMask & TBIF_IMAGE)
    1853         lpTbInfo->iImage = btnPtr->iBitmap;
     2328        lpTbInfo->iImage = btnPtr->iBitmap;
    18542329    if (lpTbInfo->dwMask & TBIF_LPARAM)
    1855         lpTbInfo->lParam = btnPtr->dwData;
     2330        lpTbInfo->lParam = btnPtr->dwData;
    18562331    if (lpTbInfo->dwMask & TBIF_SIZE)
    1857         lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
     2332        lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
    18582333    if (lpTbInfo->dwMask & TBIF_STATE)
    1859         lpTbInfo->fsState = btnPtr->fsState;
     2334        lpTbInfo->fsState = btnPtr->fsState;
    18602335    if (lpTbInfo->dwMask & TBIF_STYLE)
    1861         lpTbInfo->fsStyle = btnPtr->fsStyle;
    1862      if (lpTbInfo->dwMask & TBIF_TEXT) {
    1863          if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
    1864          {     
    1865              lstrcpynWtoA (lpTbInfo->pszText,
    1866                            (LPWSTR)infoPtr->strings[btnPtr->iString],
    1867                            lpTbInfo->cchText);
    1868          }
    1869          else lpTbInfo->pszText[0]=0;
    1870     }
     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
    18712344    return nIndex;
    18722345}
    18732346
    1874 
    1875 static LRESULT
    1876 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
     2347static LRESULT TOOLBAR_GetButtonInfoW(HWND hwnd,WPARAM wParam,LPARAM lParam)
    18772348{
    18782349    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     
    18822353
    18832354    if (infoPtr == NULL)
    1884         return -1;
     2355        return -1;
    18852356    if (lpTbInfo == NULL)
    1886         return -1;
     2357        return -1;
    18872358    if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
    1888         return -1;
     2359        return -1;
    18892360
    18902361    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    18912362    if (nIndex == -1)
    1892         return -1;
     2363        return -1;
    18932364
    18942365    btnPtr = &infoPtr->buttons[nIndex];
    18952366
    18962367    if (lpTbInfo->dwMask & TBIF_COMMAND)
    1897         lpTbInfo->idCommand = btnPtr->idCommand;
     2368        lpTbInfo->idCommand = btnPtr->idCommand;
    18982369    if (lpTbInfo->dwMask & TBIF_IMAGE)
    1899         lpTbInfo->iImage = btnPtr->iBitmap;
     2370        lpTbInfo->iImage = btnPtr->iBitmap;
    19002371    if (lpTbInfo->dwMask & TBIF_LPARAM)
    1901         lpTbInfo->lParam = btnPtr->dwData;
     2372        lpTbInfo->lParam = btnPtr->dwData;
    19022373    if (lpTbInfo->dwMask & TBIF_SIZE)
    1903         lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
     2374        lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
    19042375    if (lpTbInfo->dwMask & TBIF_STATE)
    1905         lpTbInfo->fsState = btnPtr->fsState;
     2376        lpTbInfo->fsState = btnPtr->fsState;
    19062377    if (lpTbInfo->dwMask & TBIF_STYLE)
    1907         lpTbInfo->fsStyle = btnPtr->fsStyle;
     2378        lpTbInfo->fsStyle = btnPtr->fsStyle;
    19082379    if (lpTbInfo->dwMask & TBIF_TEXT) {
    1909         if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
    1910             lstrcpynW (lpTbInfo->pszText,
    1911                        (LPWSTR)infoPtr->strings[btnPtr->iString],
    1912                        lpTbInfo->cchText);
     2380        if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
     2381            lstrcpynW (lpTbInfo->pszText,
     2382                       infoPtr->strings[btnPtr->iString],
     2383                       lpTbInfo->cchText);
    19132384    }
    19142385
     
    19232394
    19242395    return MAKELONG((WORD)infoPtr->nButtonWidth,
    1925                     (WORD)infoPtr->nButtonHeight);
     2396                    (WORD)infoPtr->nButtonHeight);
    19262397}
    19272398
     
    19352406    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    19362407    if (nIndex == -1)
    1937         return -1;
     2408        return -1;
    19382409
    19392410    nStringIndex = infoPtr->buttons[nIndex].iString;
    19402411
    1941     // TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
     2412//    TRACE (toolbar, "index=%d stringIndex=%d\n", nIndex, nStringIndex);
    19422413
    19432414    if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
    1944         return -1;
    1945 
    1946     if (lParam == 0)
    1947         return -1;
    1948 
    1949     lstrcpyWtoA ((LPSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);
    1950 
    1951     return lstrlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
    1952 }
    1953 
    1954 
    1955 static LRESULT
    1956 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
     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
     2424static LRESULT TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    19572425{
    19582426    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     
    19612429    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    19622430    if (nIndex == -1)
    1963         return -1;
     2431        return -1;
    19642432
    19652433    nStringIndex = infoPtr->buttons[nIndex].iString;
    19662434
    1967     // TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
     2435//    TRACE (toolbar, "index=%d stringIndex=%d\n", nIndex, nStringIndex);
    19682436
    19692437    if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
    1970         return -1;
    1971 
    1972     if (lParam == 0)
    1973         return -1;
    1974 
    1975     lstrcpyW ((LPWSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);
    1976 
    1977     return lstrlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
    1978 }
    1979 
    1980 
     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 >> */
    19812448/* << TOOLBAR_GetColorScheme >> */
    19822449
     
    19912458
    19922459
    1993 inline static LRESULT
     2460static LRESULT
    19942461TOOLBAR_GetExtendedStyle (HWND hwnd)
    19952462{
     
    20152482
    20162483    if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
    2017         return -1;
     2484        return -1;
    20182485
    20192486    if (infoPtr->nHotItem < 0)
    2020         return -1;
     2487        return -1;
    20212488
    20222489    return (LRESULT)infoPtr->nHotItem;
     
    20462513
    20472514    if (infoPtr == NULL)
    2048         return FALSE;
     2515        return FALSE;
    20492516    nIndex = (INT)wParam;
    20502517    btnPtr = &infoPtr->buttons[nIndex];
    20512518    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    2052         return FALSE;
     2519        return FALSE;
    20532520    lpRect = (LPRECT)lParam;
    20542521    if (lpRect == NULL)
    2055         return FALSE;
     2522        return FALSE;
    20562523    if (btnPtr->fsState & TBSTATE_HIDDEN)
    2057         return FALSE;
    2058    
     2524        return FALSE;
     2525
    20592526    TOOLBAR_CalcToolbar( hwnd );
    2060    
     2527
    20612528    lpRect->left   = btnPtr->rect.left;
    20622529    lpRect->right  = btnPtr->rect.right;
     
    20752542
    20762543    if (lpSize == NULL)
    2077         return FALSE;
     2544        return FALSE;
    20782545
    20792546    lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
    20802547    lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
    20812548
    2082     // TRACE("maximum size %d x %d\n",
    2083     // infoPtr->rcBound.right - infoPtr->rcBound.left,
    2084     //  infoPtr->rcBound.bottom - infoPtr->rcBound.top);
     2549//    TRACE (toolbar, "maximum size %d x %d\n",
     2550//        infoPtr->rcBound.right - infoPtr->rcBound.left,
     2551//         infoPtr->rcBound.bottom - infoPtr->rcBound.top);
    20852552
    20862553    return TRUE;
     
    21012568
    21022569    if (infoPtr == NULL)
    2103         return FALSE;
     2570        return FALSE;
    21042571    nIndex = (INT)wParam;
    21052572    btnPtr = &infoPtr->buttons[nIndex];
    21062573    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    2107         return FALSE;
     2574        return FALSE;
    21082575    lpRect = (LPRECT)lParam;
    21092576    if (lpRect == NULL)
    2110         return FALSE;
    2111    
     2577        return FALSE;
     2578
    21122579    lpRect->left   = btnPtr->rect.left;
    21132580    lpRect->right  = btnPtr->rect.right;
     
    21252592
    21262593    if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
    2127         return infoPtr->nRows;
     2594        return infoPtr->nRows;
    21282595    else
    2129         return 1;
     2596        return 1;
    21302597}
    21312598
     
    21392606    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    21402607    if (nIndex == -1)
    2141         return -1;
     2608        return -1;
    21422609
    21432610    return infoPtr->buttons[nIndex].fsState;
     
    21532620    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    21542621    if (nIndex == -1)
    2155         return -1;
     2622        return -1;
    21562623
    21572624    return infoPtr->buttons[nIndex].fsStyle;
     
    21652632
    21662633    if (infoPtr == NULL)
    2167         return 0;
     2634        return 0;
    21682635
    21692636    return infoPtr->nMaxTextRows;
     
    21762643    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    21772644
    2178     if (infoPtr == NULL)
    2179         return 0;
     2645    if (infoPtr == NULL) return 0;
    21802646    return infoPtr->hwndToolTip;
    2181 }
    2182 
    2183 
    2184 static LRESULT
    2185 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
    2186 {
    2187     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    2188 
    2189     // TRACE("%s hwnd=0x%x stub!\n",
    2190 //  infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
    2191 
    2192     return infoPtr->bUnicode;
    2193 }
    2194 
    2195 
    2196 inline static LRESULT
    2197 TOOLBAR_GetVersion (HWND hwnd)
    2198 {
    2199     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    2200     return infoPtr->iVersion;
    22012647}
    22022648
     
    22112657    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    22122658    if (nIndex == -1)
    2213         return FALSE;
     2659        return FALSE;
    22142660
    22152661    btnPtr = &infoPtr->buttons[nIndex];
    22162662    if (LOWORD(lParam) == FALSE)
    2217         btnPtr->fsState &= ~TBSTATE_HIDDEN;
     2663        btnPtr->fsState &= ~TBSTATE_HIDDEN;
    22182664    else
    2219         btnPtr->fsState |= TBSTATE_HIDDEN;
     2665        btnPtr->fsState |= TBSTATE_HIDDEN;
    22202666
    22212667    TOOLBAR_CalcToolbar (hwnd);
     
    22272673
    22282674
    2229 inline static LRESULT
     2675static LRESULT
    22302676TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
    22312677{
     
    22392685    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    22402686    TBUTTON_INFO *btnPtr;
     2687    HDC hdc;
    22412688    INT nIndex;
    22422689
    22432690    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    22442691    if (nIndex == -1)
    2245         return FALSE;
     2692        return FALSE;
    22462693
    22472694    btnPtr = &infoPtr->buttons[nIndex];
    22482695    if (LOWORD(lParam) == FALSE)
    2249         btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
     2696        btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
    22502697    else
    2251         btnPtr->fsState |= TBSTATE_INDETERMINATE;
    2252 
    2253     InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     2698        btnPtr->fsState |= TBSTATE_INDETERMINATE;
     2699
     2700    hdc = GetDC (hwnd);
     2701    TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
     2702    ReleaseDC (hwnd, hdc);
    22542703
    22552704    return TRUE;
     
    22662715
    22672716    if (lpTbb == NULL)
    2268         return FALSE;
     2717        return FALSE;
    22692718
    22702719    if (nIndex == -1) {
    22712720       /* EPP: this seems to be an undocumented call (from my IE4)
    2272         * I assume in that case that:
    2273         * - lpTbb->iString is a string pointer (not a string index in strings[] table
    2274         * - index of insertion is at the end of existing buttons
    2275         * I only see this happen with nIndex == -1, but it could have a special
    2276         * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
    2277         */
    2278        int      len;
    2279        LPSTR    ptr;
    2280 
    2281        if(lpTbb->iString) {
    2282            len = lstrlenA((char*)lpTbb->iString) + 2;
    2283            ptr = (CHAR*)COMCTL32_Alloc(len);
    2284            nIndex = infoPtr->nNumButtons;
    2285            strcpy(ptr, (char*)lpTbb->iString);
    2286            ptr[len - 1] = 0; /* ended by two '\0' */
    2287            lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
    2288            COMCTL32_Free(ptr);
    2289        }
    2290        else {
    2291   //         ERR("lpTbb->iString is NULL\n");
    2292            return FALSE;
    2293        }
     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);
    22942735
    22952736    } else if (nIndex < 0)
    22962737       return FALSE;
    22972738
    2298     // TRACE("inserting button index=%d\n", nIndex);
     2739
     2740//    TRACE (toolbar, "inserting button index=%d\n", nIndex);
    22992741    if (nIndex > infoPtr->nNumButtons) {
    2300         nIndex = infoPtr->nNumButtons;
    2301         // TRACE("adjust index=%d\n", nIndex);
     2742        nIndex = infoPtr->nNumButtons;
     2743//      TRACE (toolbar, "adjust index=%d\n", nIndex);
    23022744    }
    23032745
     
    23072749    /* pre insert copy */
    23082750    if (nIndex > 0) {
    2309         memcpy (&infoPtr->buttons[0], &oldButtons[0],
    2310                 nIndex * sizeof(TBUTTON_INFO));
     2751        memcpy (&infoPtr->buttons[0], &oldButtons[0],
     2752                nIndex * sizeof(TBUTTON_INFO));
    23112753    }
    23122754
     
    23202762
    23212763    if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
    2322         TTTOOLINFOA ti;
    2323 
    2324         ZeroMemory (&ti, sizeof(TTTOOLINFOA));
    2325         ti.cbSize   = sizeof (TTTOOLINFOA);
    2326         ti.hwnd     = hwnd;
    2327         ti.uId      = lpTbb->idCommand;
    2328         ti.hinst    = 0;
    2329         ti.lpszText = LPSTR_TEXTCALLBACKA;
    2330 
    2331         SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
    2332                         0, (LPARAM)&ti);
     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);
    23332775    }
    23342776
    23352777    /* post insert copy */
    23362778    if (nIndex < infoPtr->nNumButtons - 1) {
    2337         memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
    2338                 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
     2779        memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
     2780                (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
    23392781    }
    23402782
     
    23482790}
    23492791
    2350 
    2351 static LRESULT
    2352 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    2353 {
    2354     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    2355     LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
    2356     INT nIndex = (INT)wParam;
    2357     TBUTTON_INFO *oldButtons;
    2358 
    2359     if (lpTbb == NULL)
    2360         return FALSE;
    2361     if (nIndex < 0)
    2362         return FALSE;
    2363 
    2364     // TRACE("inserting button index=%d\n", nIndex);
    2365     if (nIndex > infoPtr->nNumButtons) {
    2366         nIndex = infoPtr->nNumButtons;
    2367         // TRACE("adjust index=%d\n", nIndex);
    2368     }
    2369 
    2370     oldButtons = infoPtr->buttons;
    2371     infoPtr->nNumButtons++;
    2372     infoPtr->buttons = (TBUTTON_INFO*)COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
    2373     /* pre insert copy */
    2374     if (nIndex > 0) {
    2375         memcpy (&infoPtr->buttons[0], &oldButtons[0],
    2376                 nIndex * sizeof(TBUTTON_INFO));
    2377     }
    2378 
    2379     /* insert new button */
    2380     infoPtr->buttons[nIndex].iBitmap   = lpTbb->iBitmap;
    2381     infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
    2382     infoPtr->buttons[nIndex].fsState   = lpTbb->fsState;
    2383     infoPtr->buttons[nIndex].fsStyle   = lpTbb->fsStyle;
    2384     infoPtr->buttons[nIndex].dwData    = lpTbb->dwData;
    2385     infoPtr->buttons[nIndex].iString   = lpTbb->iString;
    2386 
    2387     if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
    2388         TTTOOLINFOW ti;
    2389 
    2390         ZeroMemory (&ti, sizeof(TTTOOLINFOW));
    2391         ti.cbSize   = sizeof (TTTOOLINFOW);
    2392         ti.hwnd     = hwnd;
    2393         ti.uId      = lpTbb->idCommand;
    2394         ti.hinst    = 0;
    2395         ti.lpszText = LPSTR_TEXTCALLBACKW;
    2396 
    2397         SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
    2398                         0, (LPARAM)&ti);
    2399     }
    2400 
    2401     /* post insert copy */
    2402     if (nIndex < infoPtr->nNumButtons - 1) {
    2403         memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
    2404                 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
    2405     }
    2406 
    2407     COMCTL32_Free (oldButtons);
    2408 
    2409     TOOLBAR_CalcToolbar (hwnd);
    2410 
    2411     InvalidateRect (hwnd, NULL, FALSE);
    2412 
    2413     return TRUE;
    2414 }
    2415 
     2792static 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}
    24162798
    24172799/* << TOOLBAR_InsertMarkHitTest >> */
     
    24262808    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    24272809    if (nIndex == -1)
    2428         return FALSE;
     2810        return FALSE;
    24292811
    24302812    return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
     
    24402822    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    24412823    if (nIndex == -1)
    2442         return FALSE;
     2824        return FALSE;
    24432825
    24442826    return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
     
    24542836    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    24552837    if (nIndex == -1)
    2456         return FALSE;
     2838        return FALSE;
    24572839
    24582840    return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
     
    24682850    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    24692851    if (nIndex == -1)
    2470         return FALSE;
     2852        return FALSE;
    24712853
    24722854    return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
     
    24822864    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    24832865    if (nIndex == -1)
    2484         return FALSE;
     2866        return FALSE;
    24852867
    24862868    return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
     
    24962878    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    24972879    if (nIndex == -1)
    2498         return FALSE;
     2880        return FALSE;
    24992881
    25002882    return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
     
    25132895    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    25142896    TBUTTON_INFO *btnPtr;
     2897    HDC hdc;
    25152898    INT nIndex;
    25162899
    25172900    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    25182901    if (nIndex == -1)
    2519         return FALSE;
     2902        return FALSE;
    25202903
    25212904    btnPtr = &infoPtr->buttons[nIndex];
    25222905    if (LOWORD(lParam) == FALSE)
    2523         btnPtr->fsState &= ~TBSTATE_PRESSED;
     2906        btnPtr->fsState &= ~TBSTATE_PRESSED;
    25242907    else
    2525         btnPtr->fsState |= TBSTATE_PRESSED;
    2526 
    2527     InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     2908        btnPtr->fsState |= TBSTATE_PRESSED;
     2909
     2910    hdc = GetDC (hwnd);
     2911    TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
     2912    ReleaseDC (hwnd, hdc);
    25282913
    25292914    return TRUE;
     
    25442929
    25452930    if ((BOOL)wParam) {
    2546         /* save toolbar information */
    2547         // FIXME("save to \"%s\" \"%s\"\n",
    2548                lpSave->pszSubKey, lpSave->pszValueName);
     2931        /* save toolbar information */
     2932//      FIXME (toolbar, "save to \"%s\" \"%s\"\n",
     2933//             lpSave->pszSubKey, lpSave->pszValueName);
    25492934
    25502935
    25512936    }
    25522937    else {
    2553         /* restore toolbar information */
    2554 
    2555         // FIXME("restore from \"%s\" \"%s\"\n",
    2556                lpSave->pszSubKey, lpSave->pszValueName);
     2938        /* restore toolbar information */
     2939
     2940//      FIXME (toolbar, "restore from \"%s\" \"%s\"\n",
     2941//             lpSave->pszSubKey, lpSave->pszValueName);
    25572942
    25582943
     
    25632948}
    25642949
    2565 
    2566 static LRESULT
    2567 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
     2950static LRESULT TOOLBAR_SaveRestoreW(HWND hwnd,WPARAM wParam,LPARAM lParam)
    25682951{
    25692952#if 0
     
    25712954    LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
    25722955
    2573     if (lpSave == NULL)
    2574         return 0;
     2956    if (lpSave == NULL) return 0;
    25752957
    25762958    if ((BOOL)wParam) {
    2577         /* save toolbar information */
    2578         // FIXME("save to \"%s\" \"%s\"\n",
    2579                lpSave->pszSubKey, lpSave->pszValueName);
     2959        /* save toolbar information */
     2960//      FIXME (toolbar, "save to \"%s\" \"%s\"\n",
     2961//             lpSave->pszSubKey, lpSave->pszValueName);
    25802962
    25812963
    25822964    }
    25832965    else {
    2584         /* restore toolbar information */
    2585 
    2586         // FIXME("restore from \"%s\" \"%s\"\n",
    2587                lpSave->pszSubKey, lpSave->pszValueName);
     2966        /* restore toolbar information */
     2967
     2968//      FIXME (toolbar, "restore from \"%s\" \"%s\"\n",
     2969//             lpSave->pszSubKey, lpSave->pszValueName);
    25882970
    25892971
     
    25942976}
    25952977
     2978/* << TOOLBAR_SaveRestore32W >> */
    25962979
    25972980static LRESULT
     
    26122995    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    26132996
    2614     if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
    2615         return FALSE;
    2616 
    2617 //  if (infoPtr->nNumButtons > 0)
    2618 //      WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
    2619 //           infoPtr->nNumButtons,
    2620 //           infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
    2621 //           LOWORD(lParam), HIWORD(lParam));
     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;
    26223003
    26233004    infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
    26243005    infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
    2625 
    2626     /* uses image list internals directly */
    2627     if (infoPtr->himlDef) {
    2628         infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
    2629         infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
    2630     }
    26313006
    26323007    return TRUE;
     
    26433018
    26443019    if (lptbbi == NULL)
    2645         return FALSE;
     3020        return FALSE;
    26463021    if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
    2647         return FALSE;
    2648    
     3022        return FALSE;
     3023
    26493024    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    26503025    if (nIndex == -1)
    2651         return FALSE;
     3026        return FALSE;
    26523027
    26533028    btnPtr = &infoPtr->buttons[nIndex];
    26543029    if (lptbbi->dwMask & TBIF_COMMAND)
    2655         btnPtr->idCommand = lptbbi->idCommand;
     3030        btnPtr->idCommand = lptbbi->idCommand;
    26563031    if (lptbbi->dwMask & TBIF_IMAGE)
    2657         btnPtr->iBitmap = lptbbi->iImage;
     3032        btnPtr->iBitmap = lptbbi->iImage;
    26583033    if (lptbbi->dwMask & TBIF_LPARAM)
    2659         btnPtr->dwData = lptbbi->lParam;
     3034        btnPtr->dwData = lptbbi->lParam;
    26603035/*    if (lptbbi->dwMask & TBIF_SIZE) */
    2661 /*      btnPtr->cx = lptbbi->cx; */
     3036/*      btnPtr->cx = lptbbi->cx; */
    26623037    if (lptbbi->dwMask & TBIF_STATE)
    2663         btnPtr->fsState = lptbbi->fsState;
     3038        btnPtr->fsState = lptbbi->fsState;
    26643039    if (lptbbi->dwMask & TBIF_STYLE)
    2665         btnPtr->fsStyle = lptbbi->fsStyle;
     3040        btnPtr->fsStyle = lptbbi->fsStyle;
    26663041
    26673042    if (lptbbi->dwMask & TBIF_TEXT) {
    2668         if ((btnPtr->iString >= 0) ||
    2669             (btnPtr->iString < infoPtr->nNumStrings)) {
    2670            // TRACE("Ooooooch\n");
     3043        if ((btnPtr->iString >= 0) ||
     3044            (btnPtr->iString < infoPtr->nNumStrings)) {
    26713045#if 0
    2672             WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
    2673             INT len = lstrlenA (lptbbi->pszText);
    2674             *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
     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));
    26753049#endif
    26763050
    2677             /* this is the ultimate sollution */
    2678 /*          Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
    2679         }
     3051            /* this is the ultimate sollution */
     3052/*          Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
     3053        }
    26803054    }
    26813055
     
    26833057}
    26843058
    2685 
    2686 static LRESULT
    2687 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
     3059static LRESULT TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    26883060{
    26893061    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     
    26933065
    26943066    if (lptbbi == NULL)
    2695         return FALSE;
     3067        return FALSE;
    26963068    if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
    2697         return FALSE;
     3069        return FALSE;
    26983070
    26993071    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    27003072    if (nIndex == -1)
    2701         return FALSE;
     3073        return FALSE;
    27023074
    27033075    btnPtr = &infoPtr->buttons[nIndex];
    27043076    if (lptbbi->dwMask & TBIF_COMMAND)
    2705         btnPtr->idCommand = lptbbi->idCommand;
     3077        btnPtr->idCommand = lptbbi->idCommand;
    27063078    if (lptbbi->dwMask & TBIF_IMAGE)
    2707         btnPtr->iBitmap = lptbbi->iImage;
     3079        btnPtr->iBitmap = lptbbi->iImage;
    27083080    if (lptbbi->dwMask & TBIF_LPARAM)
    2709         btnPtr->dwData = lptbbi->lParam;
     3081        btnPtr->dwData = lptbbi->lParam;
    27103082/*    if (lptbbi->dwMask & TBIF_SIZE) */
    2711 /*      btnPtr->cx = lptbbi->cx; */
     3083/*      btnPtr->cx = lptbbi->cx; */
    27123084    if (lptbbi->dwMask & TBIF_STATE)
    2713         btnPtr->fsState = lptbbi->fsState;
     3085        btnPtr->fsState = lptbbi->fsState;
    27143086    if (lptbbi->dwMask & TBIF_STYLE)
    2715         btnPtr->fsStyle = lptbbi->fsStyle;
     3087        btnPtr->fsStyle = lptbbi->fsStyle;
    27163088
    27173089    if (lptbbi->dwMask & TBIF_TEXT) {
    2718         if ((btnPtr->iString >= 0) ||
    2719             (btnPtr->iString < infoPtr->nNumStrings)) {
     3090        if ((btnPtr->iString >= 0) ||
     3091            (btnPtr->iString < infoPtr->nNumStrings)) {
    27203092#if 0
    2721             WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
    2722             INT len = lstrlenW (lptbbi->pszText);
    2723             *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
     3093            WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
     3094            INT len = lstrlenW (lptbbi->pszText);
     3095            *lpString = COMCTL32_ReAlloc (lpString, sizeof(wchar)*(len+1));
    27243096#endif
    27253097
    2726             /* this is the ultimate sollution */
    2727 /*          Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
    2728         }
     3098            /* this is the ultimate sollution */
     3099/*          Str_SetPtrW (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
     3100        }
    27293101    }
    27303102
     
    27323104}
    27333105
    2734 
    27353106static LRESULT
    27363107TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
     
    27383109    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    27393110
    2740     if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
    2741     {
    2742 //      ERR("invalid parameter\n");
    2743         return FALSE;
    2744     }
     3111    if (((INT)LOWORD(lParam) <= 0) || ((INT)HIWORD(lParam) <= 0)) return FALSE;
    27453112
    27463113    /* Button size can only be set before adding any button to the toolbar
    27473114       according to the documentation.  */
    2748     /* this appears to be wrong. WINZIP32.EXE (ver 8) calls this on
    2749        one of its buttons after adding it to the toolbar, and it
    2750        checks that the return value is nonzero - mjm */
    27513115    if( infoPtr->nNumButtons != 0 )
    2752     {
    2753         // FIXME("Button size set after button in toolbar\n");
    2754         return TRUE;
    2755     }
     3116        return FALSE;
    27563117
    27573118    infoPtr->nButtonWidth = (INT)LOWORD(lParam);
    27583119    infoPtr->nButtonHeight = (INT)HIWORD(lParam);
     3120
    27593121    return TRUE;
    27603122}
     
    27673129
    27683130    if (infoPtr == NULL)
    2769         return FALSE;
     3131        return FALSE;
    27703132
    27713133    infoPtr->cxMin = (INT)LOWORD(lParam);
     
    27833145
    27843146    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
    2785         return FALSE;
     3147        return FALSE;
    27863148
    27873149    infoPtr->buttons[nIndex].idCommand = (INT)lParam;
     
    27893151    if (infoPtr->hwndToolTip) {
    27903152
    2791         // FIXME("change tool tip!\n");
     3153//      FIXME (toolbar, "change tool tip!\n");
    27923154
    27933155    }
     
    28053167    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    28063168    HIMAGELIST himlTemp;
    2807 
    28083169
    28093170    himlTemp = infoPtr->himlDis;
     
    28123173    /* FIXME: redraw ? */
    28133174
    2814     return (LRESULT)himlTemp; 
     3175    return (LRESULT)himlTemp;
    28153176}
    28163177
     
    28243185    dwTemp = infoPtr->dwDTFlags;
    28253186    infoPtr->dwDTFlags =
    2826         (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
     3187        (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
    28273188
    28283189    return (LRESULT)dwTemp;
     
    28393200    infoPtr->dwExStyle = (DWORD)lParam;
    28403201
    2841     return (LRESULT)dwTemp; 
     3202    return (LRESULT)dwTemp;
    28423203}
    28433204
     
    28543215    /* FIXME: redraw ? */
    28553216
    2856     return (LRESULT)himlTemp; 
     3217    return (LRESULT)himlTemp;
    28573218}
    28583219
     
    28663227    if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
    28673228    {
    2868         infoPtr->nHotItem = (INT)wParam;
    2869 
    2870         /* FIXME: What else must be done ??? */
     3229        infoPtr->nHotItem = (INT)wParam;
     3230
     3231        /* FIXME: What else must be done ??? */
    28713232
    28723233    }
    28733234
    28743235    if (nOldHotItem < 0)
    2875         return -1;
     3236        return -1;
    28763237
    28773238    return (LRESULT)nOldHotItem;
     
    28883249    infoPtr->himlDef = (HIMAGELIST)lParam;
    28893250
    2890      infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
    28913251    /* FIXME: redraw ? */
    28923252
    2893     return (LRESULT)himlTemp; 
     3253    return (LRESULT)himlTemp;
    28943254}
    28953255
     
    29323292
    29333293    if (infoPtr == NULL)
    2934         return FALSE;
     3294        return FALSE;
    29353295
    29363296    infoPtr->nMaxTextRows = (INT)wParam;
     
    29503310
    29513311    if (infoPtr == NULL)
    2952         return 0;
    2953     hwndOldNotify = infoPtr->hwndNotify;
    2954     infoPtr->hwndNotify = (HWND)wParam;
     3312        return 0;
     3313    hwndOldNotify = infoPtr->header.hwndNotify;
     3314    infoPtr->header.hwndNotify = (HWND)wParam;
    29553315
    29563316    return hwndOldNotify;
     
    29663326    if (LOWORD(wParam) > 1) {
    29673327
    2968         // FIXME("multiple rows not supported!\n");
     3328//      FIXME (toolbar, "multiple rows not supported!\n");
    29693329
    29703330    }
     
    29753335    /* return bounding rectangle */
    29763336    if (lprc) {
    2977         lprc->left   = infoPtr->rcBound.left;
    2978         lprc->right  = infoPtr->rcBound.right;
    2979         lprc->top    = infoPtr->rcBound.top;
    2980         lprc->bottom = infoPtr->rcBound.bottom;
     3337        lprc->left   = infoPtr->rcBound.left;
     3338        lprc->right  = infoPtr->rcBound.right;
     3339        lprc->top    = infoPtr->rcBound.top;
     3340        lprc->bottom = infoPtr->rcBound.bottom;
    29813341    }
    29823342
     
    29933353    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    29943354    TBUTTON_INFO *btnPtr;
     3355    HDC hdc;
    29953356    INT nIndex;
    29963357
    29973358    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    29983359    if (nIndex == -1)
    2999         return FALSE;
     3360        return FALSE;
    30003361
    30013362    btnPtr = &infoPtr->buttons[nIndex];
    30023363    btnPtr->fsState = LOWORD(lParam);
    30033364
    3004     InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     3365    hdc = GetDC (hwnd);
     3366    TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
     3367    ReleaseDC (hwnd, hdc);
    30053368
    30063369    return TRUE;
     
    30133376    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    30143377    TBUTTON_INFO *btnPtr;
     3378    HDC hdc;
    30153379    INT nIndex;
    30163380
    30173381    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    30183382    if (nIndex == -1)
    3019         return FALSE;
     3383        return FALSE;
    30203384
    30213385    btnPtr = &infoPtr->buttons[nIndex];
    30223386    btnPtr->fsStyle = LOWORD(lParam);
    30233387
    3024     InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     3388    hdc = GetDC (hwnd);
     3389    TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
     3390    ReleaseDC (hwnd, hdc);
    30253391
    30263392    if (infoPtr->hwndToolTip) {
    3027         // FIXME("change tool tip!\n");
     3393
     3394//      FIXME (toolbar, "change tool tip!\n");
     3395
    30283396    }
    30293397
     
    30323400
    30333401
    3034 inline static LRESULT
     3402static LRESULT
    30353403TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
    30363404{
     
    30383406
    30393407    if (infoPtr == NULL)
    3040         return 0;
     3408        return 0;
    30413409    infoPtr->hwndToolTip = (HWND)wParam;
    30423410    return 0;
    30433411}
    3044 
    3045 
    3046 static LRESULT
    3047 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
    3048 {
    3049     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    3050     BOOL bTemp;
    3051 
    3052     // TRACE("%s hwnd=0x%04x stub!\n",
    3053 //  ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
    3054 
    3055     bTemp = infoPtr->bUnicode;
    3056     infoPtr->bUnicode = (BOOL)wParam;
    3057 
    3058     return bTemp;
    3059 }
    3060 
    3061 
    3062 static LRESULT
    3063 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
    3064 {
    3065     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    3066     INT iOldVersion = infoPtr->iVersion;
    3067 
    3068     infoPtr->iVersion = iVersion;
    3069 
    3070     return iOldVersion;
    3071 }
    3072 
    30733412
    30743413static LRESULT
     
    30903429    infoPtr->cxMin = -1;
    30913430    infoPtr->cxMax = -1;
    3092     infoPtr->nNumBitmaps = 0;
    3093     infoPtr->nNumStrings = 0;
    30943431
    30953432    infoPtr->bCaptured = FALSE;
    3096     infoPtr->bUnicode = IsWindowUnicode (hwnd);
    30973433    infoPtr->nButtonDown = -1;
    30983434    infoPtr->nOldHit = -1;
    30993435    infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
    3100     infoPtr->hwndNotify = GetParent (hwnd);
    31013436    infoPtr->bTransparent = (dwStyle & TBSTYLE_FLAT);
    31023437    infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
    31033438    infoPtr->bAnchor = FALSE; /* no anchor highlighting */
    3104     infoPtr->iVersion = 0;
     3439
     3440    infoPtr->hwndToolbar = hwnd;
     3441    infoPtr->oldButtons = NULL;
     3442    infoPtr->nNumOldButtons = 0;
    31053443
    31063444    SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
    31073445    infoPtr->hFont = CreateFontIndirectA (&logFont);
    31083446
    3109     if (dwStyle & TBSTYLE_TOOLTIPS) {
    3110         /* Create tooltip control */
    3111         infoPtr->hwndToolTip =
    3112             CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
    3113                                CW_USEDEFAULT, CW_USEDEFAULT,
    3114                                CW_USEDEFAULT, CW_USEDEFAULT,
    3115                                hwnd, 0, 0, 0);
    3116 
    3117         /* Send NM_TOOLTIPSCREATED notification */
    3118         if (infoPtr->hwndToolTip) {
    3119             NMTOOLTIPSCREATED nmttc;
    3120 
    3121             nmttc.hdr.hwndFrom = hwnd;
    3122             nmttc.hdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
    3123             nmttc.hdr.code = NM_TOOLTIPSCREATED;
    3124             nmttc.hwndToolTips = infoPtr->hwndToolTip;
    3125 
    3126             SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
    3127                           (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
    3128         }
    3129     }
     3447    /* Create tooltip control */
     3448    if (dwStyle & TBSTYLE_TOOLTIPS)
     3449      infoPtr->hwndToolTip = createToolTip(hwnd,0,FALSE);
    31303450
    31313451    return 0;
     
    31373457{
    31383458    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    3139 
    3140     /* delete tooltip control */
    3141     if (infoPtr->hwndToolTip)
    3142         DestroyWindow (infoPtr->hwndToolTip);
    31433459
    31443460    /* delete button data */
    31453461    if (infoPtr->buttons)
    3146         COMCTL32_Free (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    }
    31473472
    31483473    /* delete strings */
    31493474    if (infoPtr->strings) {
    3150         INT i;
    3151         for (i = 0; i < infoPtr->nNumStrings; i++)
    3152             if (infoPtr->strings[i])
    3153                 COMCTL32_Free (infoPtr->strings[i]);
    3154 
    3155         COMCTL32_Free (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);
    31563481    }
    31573482
    31583483    /* destroy internal image list */
    31593484    if (infoPtr->himlInt)
    3160         ImageList_Destroy (infoPtr->himlInt);
     3485        ImageList_Destroy (infoPtr->himlInt);
    31613486
    31623487    /* delete default font */
    31633488    if (infoPtr->hFont)
    3164         DeleteObject (infoPtr->hFont);
     3489        DeleteObject (infoPtr->hFont);
    31653490
    31663491    /* free toolbar info data */
    3167     COMCTL32_Free (infoPtr);
    3168     SetWindowLongA (hwnd, 0, 0);
     3492    doneControl(hwnd);
    31693493
    31703494    return 0;
     
    31773501    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    31783502
    3179     if (infoPtr->bTransparent)
    3180         return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
     3503    //SvL: Check ptr
     3504    if (infoPtr && infoPtr->bTransparent)
     3505        return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
    31813506
    31823507    return DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
    31833508}
    31843509
    3185 
    31863510static LRESULT
    31873511TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
     
    31913515    return infoPtr->hFont;
    31923516}
    3193 
    31943517
    31953518static LRESULT
     
    32003523    POINT pt;
    32013524    INT   nHit;
     3525    HDC   hdc;
    32023526
    32033527    pt.x = (INT)LOWORD(lParam);
     
    32063530
    32073531    if (nHit >= 0) {
    3208         btnPtr = &infoPtr->buttons[nHit];
    3209         if (!(btnPtr->fsState & TBSTATE_ENABLED))
    3210             return 0;
    3211         SetCapture (hwnd);
    3212         infoPtr->bCaptured = TRUE;
    3213         infoPtr->nButtonDown = nHit;
    3214 
    3215         btnPtr->fsState |= TBSTATE_PRESSED;
    3216 
    3217         InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     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);
    32183544    }
    32193545    else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
    3220         TOOLBAR_Customize (hwnd);
     3546        TOOLBAR_Customize (hwnd);
    32213547
    32223548    return 0;
     
    32313557    POINT pt;
    32323558    INT   nHit;
     3559    HDC   hdc;
    32333560
    32343561    if (infoPtr->hwndToolTip)
    3235         TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
    3236                             WM_LBUTTONDOWN, wParam, lParam);
     3562        TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
     3563                            WM_LBUTTONDOWN, wParam, lParam);
    32373564
    32383565    pt.x = (INT)LOWORD(lParam);
     
    32413568
    32423569    if (nHit >= 0) {
    3243         btnPtr = &infoPtr->buttons[nHit];
    3244         if (!(btnPtr->fsState & TBSTATE_ENABLED))
    3245             return 0;
    3246 
    3247         if (btnPtr->fsStyle &  TBSTYLE_DROPDOWN)
    3248         {
    3249             NMTOOLBARA nmtb;
    3250 
    3251             nmtb.hdr.hwndFrom = hwnd;
    3252             nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
    3253             nmtb.hdr.code = TBN_DROPDOWN;
    3254             nmtb.iItem = btnPtr->idCommand;
    3255 
    3256             SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
    3257                           (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
    3258         }
    3259 
    3260         SetCapture (hwnd);
    3261         infoPtr->bCaptured = TRUE;
    3262         infoPtr->nButtonDown = nHit;
    3263         infoPtr->nOldHit = nHit;
    3264 
    3265         btnPtr->fsState |= TBSTATE_PRESSED;
    3266         btnPtr->bHot = FALSE;
    3267 
    3268         InvalidateRect(hwnd, &btnPtr->rect, TRUE);
     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);
    32693593    }
    32703594
    32713595    return 0;
    32723596}
     3597
    32733598
    32743599static LRESULT
     
    32803605    INT   nHit;
    32813606    INT   nOldIndex = -1;
     3607    HDC   hdc;
    32823608    BOOL  bSendMessage = TRUE;
    32833609
    32843610    if (infoPtr->hwndToolTip)
    3285         TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
    3286                             WM_LBUTTONUP, wParam, lParam);
     3611        TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
     3612                            WM_LBUTTONUP, wParam, lParam);
    32873613
    32883614    pt.x = (INT)LOWORD(lParam);
     
    32903616    nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
    32913617
    3292     /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
    3293     if(infoPtr->nHotItem >= 0)
    3294         infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
    3295 
    32963618    if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
    3297         infoPtr->bCaptured = FALSE;
    3298         ReleaseCapture ();
    3299         btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
    3300         btnPtr->fsState &= ~TBSTATE_PRESSED;
    3301 
    3302         if (nHit == infoPtr->nButtonDown) {
    3303             if (btnPtr->fsStyle & TBSTYLE_CHECK) {
    3304                 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
    3305                     nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
    3306                         infoPtr->nButtonDown);
    3307                     if (nOldIndex == infoPtr->nButtonDown)
    3308                         bSendMessage = FALSE;
    3309                     if ((nOldIndex != infoPtr->nButtonDown) &&
    3310                         (nOldIndex != -1))
    3311                         infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
    3312                     btnPtr->fsState |= TBSTATE_CHECKED;
    3313                 }
    3314                 else {
    3315                     if (btnPtr->fsState & TBSTATE_CHECKED)
    3316                         btnPtr->fsState &= ~TBSTATE_CHECKED;
    3317                     else
    3318                         btnPtr->fsState |= TBSTATE_CHECKED;
    3319                 }
    3320             }
    3321         }
    3322         else
    3323             bSendMessage = FALSE;
    3324 
    3325         if (nOldIndex != -1)
    3326             InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
    3327        
    3328         InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    3329 
    3330         if (bSendMessage) {
    3331             SendMessageA (GetParent(hwnd), WM_COMMAND,
    3332                           MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
    3333 
    3334 //          if ((GetWindowLongA(hwnd, GWL_STYLE) & TBSTYLE_DROPDOWN) ||
    3335 //              (btnPtr->fsStyle & 0x08/* BTNS_DROPDOWN */)) {
    3336        /*
    3337         * This appears to be an error. Instead of checking the style of the
    3338         * button in question wine was checking the style of the toolbar
    3339         * itself. This caused a number of strange behaviors. In my
    3340         * invistigation i think the whole dropdown thing is still fairly
    3341         * broken. but this helps fix some of the problems.
    3342         */
    3343 
    3344         if (btnPtr->fsStyle &  TBSTYLE_DROPDOWN) {
    3345                NMTOOLBARW       nmtb;
    3346 
    3347                nmtb.hdr.hwndFrom = hwnd;
    3348                nmtb.hdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
    3349                nmtb.hdr.code     = TBN_DROPDOWN;
    3350                nmtb.iItem        = nHit;
    3351                /* nmtb.tbButton not used with TBN_DROPDOWN */
    3352                if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings)) {
    3353                   nmtb.pszText      = infoPtr->strings[btnPtr->iString];
    3354                   nmtb.cchText      = lstrlenW(nmtb.pszText);
    3355                } else {
    3356                   nmtb.pszText      = NULL;
    3357                   nmtb.cchText      = 0;
    3358                }
    3359                nmtb.rcButton     = btnPtr->rect;
    3360 
    3361                SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
    3362                             (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
    3363             }
    3364         }
    3365         infoPtr->nButtonDown = -1;
    3366         infoPtr->nOldHit = -1;
     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;
    33673678    }
    33683679
     
    33703681}
    33713682
    3372 static LRESULT
    3373 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
    3374 {
    3375     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    3376     TBUTTON_INFO *hotBtnPtr;
    3377 
    3378     if (infoPtr->nOldHit < 0)
    3379       return TRUE;
    3380 
    3381     hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
    3382 
    3383     /* Redraw the button if the last button we were over is the hot button and it
    3384        is enabled */
    3385     if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
    3386     {
    3387         hotBtnPtr->bHot = FALSE;
    3388                    
    3389         InvalidateRect (hwnd, &hotBtnPtr->rect, TRUE);
    3390     }
    3391 
    3392     infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
    3393     infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
    3394 
    3395     return TRUE;
    3396 }
    33973683
    33983684static LRESULT
     
    34033689    POINT pt;
    34043690    INT   nHit;
    3405     TRACKMOUSEEVENT trackinfo;
    3406 
    3407     /* fill in the TRACKMOUSEEVENT struct */
    3408     trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
    3409     trackinfo.dwFlags = TME_QUERY;
    3410     trackinfo.hwndTrack = hwnd;
    3411     trackinfo.dwHoverTime = HOVER_DEFAULT;
    3412 
    3413     /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
    3414     _TrackMouseEvent(&trackinfo);
    3415 
    3416     /* Make sure tracking is enabled so we recieve a WM_MOUSELEAVE message */
    3417     if(!(trackinfo.dwFlags & TME_LEAVE)) {
    3418         trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
    3419 
    3420         /* call TRACKMOUSEEVENT so we recieve a WM_MOUSELEAVE message */
    3421         /* and can properly deactivate the hot toolbar button */
    3422         _TrackMouseEvent(&trackinfo);
    3423    }
     3691    HDC   hdc;
     3692    DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
    34243693
    34253694    if (infoPtr->hwndToolTip)
    3426         TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
    3427                             WM_MOUSEMOVE, wParam, lParam);
     3695        TOOLBAR_RelayEvent (infoPtr->hwndToolTip,hwnd,
     3696                            WM_MOUSEMOVE,wParam,lParam);
    34283697
    34293698    pt.x = (INT)LOWORD(lParam);
    34303699    pt.y = (INT)HIWORD(lParam);
    34313700
    3432     nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
     3701    nHit = TOOLBAR_InternalHitTest(hwnd,&pt);
    34333702
    34343703    if (infoPtr->nOldHit != nHit)
    34353704    {
    3436         /* Remove the effect of an old hot button if the button was enabled and was
    3437            drawn with the hot button effect */
    3438         if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
    3439                 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
    3440         {
    3441             oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
    3442             oldBtnPtr->bHot = FALSE;
    3443                    
    3444             InvalidateRect (hwnd, &oldBtnPtr->rect, TRUE);
    3445         }
    3446 
    3447         /* It's not a separator or in nowhere. It's a hot button. */
    3448         if (nHit >= 0)
    3449         {
    3450             btnPtr = &infoPtr->buttons[nHit];
    3451             btnPtr->bHot = TRUE;
    3452 
    3453             infoPtr->nHotItem = nHit;
    3454 
    3455             /* only enabled buttons show hot effect */           
    3456             if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
    3457                 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    3458         }
    3459 
    3460     if (infoPtr->bCaptured) {
    3461             btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
    3462             if (infoPtr->nOldHit == infoPtr->nButtonDown) {
    3463                 btnPtr->fsState &= ~TBSTATE_PRESSED;
    3464                 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    3465             }
    3466             else if (nHit == infoPtr->nButtonDown) {
    3467                 btnPtr->fsState |= TBSTATE_PRESSED;
    3468                 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
    3469             }
    3470         }
    3471         infoPtr->nOldHit = nHit;
     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;
    34723756    }
    34733757    return 0;
     
    34753759
    34763760
    3477 inline static LRESULT
     3761static LRESULT
    34783762TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
    34793763{
    34803764/*    if (wndPtr->dwStyle & CCS_NODIVIDER) */
    3481         return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
     3765        return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
    34823766/*    else */
    3483 /*      return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
    3484 }
    3485 
    3486 
    3487 inline static LRESULT
     3767/*      return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
     3768}
     3769
     3770
     3771static LRESULT
    34883772TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
    34893773{
    34903774    if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
    3491         ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
     3775        ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
    34923776
    34933777    return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
     
    35013785
    35023786    /* allocate memory for info structure */
    3503     infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
    3504     SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
     3787    infoPtr = (TOOLBAR_INFO*)initControl(hwnd,sizeof(TOOLBAR_INFO));
    35053788
    35063789    /* paranoid!! */
     
    35103793    if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
    35113794        HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
    3512         SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
     3795        SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
    35133796    }
    35143797
     
    35253808
    35263809    if (dwStyle & WS_MINIMIZE)
    3527         return 0; /* Nothing to do */
     3810        return 0; /* Nothing to do */
    35283811
    35293812    DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
    35303813
    35313814    if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
    3532         return 0;
     3815        return 0;
    35333816
    35343817    if (!(dwStyle & CCS_NODIVIDER))
    35353818    {
    3536         GetWindowRect (hwnd, &rcWindow);
    3537         OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
    3538         if( dwStyle & WS_BORDER )
    3539             OffsetRect (&rcWindow, 1, 1);
    3540         DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
     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);
    35413824    }
    35423825
     
    35473830
    35483831
    3549 inline static LRESULT
     3832static LRESULT
    35503833TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
    35513834{
     
    35533836    LPNMHDR lpnmh = (LPNMHDR)lParam;
    35543837
    3555     // TRACE("passing WM_NOTIFY!\n");
     3838//    TRACE (toolbar, "passing WM_NOTIFY!\n");
    35563839
    35573840    if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
    3558         SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,   wParam, lParam);
     3841        SendMessageA (infoPtr->header.hwndNotify, WM_NOTIFY,   wParam, lParam);
    35593842
    35603843#if 0
    3561         if (lpnmh->code == TTN_GETDISPINFOA) {
    3562             LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
    3563 
    3564             // FIXME("retrieving ASCII string\n");
    3565 
    3566         }
    3567         else if (lpnmh->code == TTN_GETDISPINFOW) {
    3568             LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
    3569 
    3570             // FIXME("retrieving UNICODE string\n");
    3571 
    3572         }
     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        }
    35733856#endif
    35743857    }
     
    35813864TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
    35823865{
    3583     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
    35843866    HDC hdc;
    35853867    PAINTSTRUCT ps;
    35863868
    3587     /* fill ps.rcPaint with a default rect */
    3588     memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
    3589 
    3590     TOOLBAR_CalcToolbar( hwnd );
    3591     hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
    3592     TOOLBAR_Refresh (hwnd, hdc, &ps);
     3869    TOOLBAR_CalcToolbar(hwnd);
     3870    hdc = wParam == 0 ? BeginPaint(hwnd,&ps) : (HDC)wParam;
     3871    TOOLBAR_Refresh(hwnd,hdc);
    35933872    if (!wParam) EndPaint (hwnd, &ps);
    3594 
    35953873    return 0;
    35963874}
     
    36033881    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    36043882    RECT parent_rect;
    3605     RECT window_rect;
    36063883    HWND parent;
    3607     INT  x, y;
    3608     INT  cx, cy;
     3884    INT  x = 0,y = 0,cx,cy;
    36093885    INT  flags;
    36103886    UINT uPosFlags = 0;
     
    36123888    /* Resize deadlock check */
    36133889    if (infoPtr->bAutoSize) {
    3614         infoPtr->bAutoSize = FALSE;
    3615         return 0;
     3890        infoPtr->bAutoSize = FALSE;
     3891        return 0;
    36163892    }
    36173893
     
    36223898     */
    36233899
    3624     // TRACE("sizing toolbar!\n");
     3900    //TRACE (toolbar, "sizing toolbar!\n");
    36253901
    36263902    if (flags == SIZE_RESTORED) {
    3627         /* width and height don't apply */
    3628         parent = GetParent (hwnd);
    3629         GetClientRect(parent, &parent_rect);
    3630         x = parent_rect.left;
    3631         y = parent_rect.top;
    3632 
    3633         if (dwStyle & CCS_NORESIZE) {
    3634             uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
    3635 
    3636             /*
    3637              * this sets the working width of the toolbar, and
    3638              * Calc Toolbar will not adjust it, only the height
    3639              */
    3640             infoPtr->nWidth = parent_rect.right - parent_rect.left;
    3641             cy = infoPtr->nHeight;
    3642             cx = infoPtr->nWidth;
    3643             TOOLBAR_CalcToolbar (hwnd);
    3644             infoPtr->nWidth = cx;
    3645             infoPtr->nHeight = cy;
    3646         }
    3647         else {
    3648             infoPtr->nWidth = parent_rect.right - parent_rect.left;
    3649             TOOLBAR_CalcToolbar (hwnd);
    3650             cy = infoPtr->nHeight;
    3651             cx = infoPtr->nWidth;
    3652 
    3653             if (dwStyle & CCS_NOMOVEY) {
    3654                 GetWindowRect(hwnd, &window_rect);
    3655                 ScreenToClient(parent, (LPPOINT)&window_rect.left);
    3656                 y = window_rect.top;
    3657             }
    3658         }
    3659 
    3660         if (dwStyle & CCS_NOPARENTALIGN) {
    3661             uPosFlags |= SWP_NOMOVE;
    3662             cy = infoPtr->nHeight;
    3663             cx = infoPtr->nWidth;
    3664         }
    3665 
    3666         if (!(dwStyle & CCS_NODIVIDER))
    3667             cy += GetSystemMetrics(SM_CYEDGE);
    3668 
    3669         if (dwStyle & WS_BORDER)
    3670         {
    3671             x = y = 1;
    3672             cy += GetSystemMetrics(SM_CYEDGE);
    3673             cx += GetSystemMetrics(SM_CYEDGE);
    3674         }
    3675 
    3676         SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
    3677                         cx, cy, uPosFlags | SWP_NOZORDER);
     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);
    36783944    }
    36793945    return 0;
     
    36873953
    36883954    if (nType == GWL_STYLE) {
    3689         if (lpStyle->styleNew & TBSTYLE_LIST) {
    3690             infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
    3691         }
    3692         else {
    3693             infoPtr->dwDTFlags = DT_CENTER;
    3694         }
     3955        if (lpStyle->styleNew & TBSTYLE_LIST) {
     3956            infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
     3957        }
     3958        else {
     3959            infoPtr->dwDTFlags = DT_CENTER;
     3960        }
    36953961    }
    36963962
     
    37073973ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    37083974{
    3709 
    3710     switch (uMsg)
     3975   switch (uMsg)
    37113976    {
    37123977       case WM_DESTROY:
     
    37243989    switch (uMsg)
    37253990    {
    3726         case TB_ADDBITMAP:
    3727             return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
    3728 
    3729         case TB_ADDBUTTONSA:
    3730             return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
    3731 
    3732         case TB_ADDBUTTONSW:
    3733             return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
    3734 
    3735         case TB_ADDSTRINGA:
    3736             return TOOLBAR_AddStringA (hwnd, wParam, lParam);
    3737 
    3738         case TB_ADDSTRINGW:
    3739             return TOOLBAR_AddStringW (hwnd, wParam, lParam);
    3740 
    3741         case TB_AUTOSIZE:
    3742             return TOOLBAR_AutoSize (hwnd);
    3743 
    3744         case TB_BUTTONCOUNT:
    3745             return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
    3746 
    3747         case TB_BUTTONSTRUCTSIZE:
    3748             return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
    3749 
    3750         case TB_CHANGEBITMAP:
    3751             return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
    3752 
    3753         case TB_CHECKBUTTON:
    3754             return TOOLBAR_CheckButton (hwnd, wParam, lParam);
    3755 
    3756         case TB_COMMANDTOINDEX:
    3757             return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
    3758 
    3759         case TB_CUSTOMIZE:
    3760             return TOOLBAR_Customize (hwnd);
    3761 
    3762         case TB_DELETEBUTTON:
    3763             return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
    3764 
    3765         case TB_ENABLEBUTTON:
    3766             return TOOLBAR_EnableButton (hwnd, wParam, lParam);
    3767 
    3768         case TB_GETANCHORHIGHLIGHT:
    3769             return TOOLBAR_GetAnchorHighlight (hwnd);
    3770 
    3771         case TB_GETBITMAP:
    3772             return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
    3773 
    3774         case TB_GETBITMAPFLAGS:
    3775             return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
    3776 
    3777         case TB_GETBUTTON:
    3778             return TOOLBAR_GetButton (hwnd, wParam, lParam);
    3779 
    3780         case TB_GETBUTTONINFOA:
    3781             return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
    3782 
    3783         case TB_GETBUTTONINFOW:
    3784             return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
    3785 
    3786         case TB_GETBUTTONSIZE:
    3787             return TOOLBAR_GetButtonSize (hwnd);
    3788 
    3789         case TB_GETBUTTONTEXTA:
    3790             return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
    3791 
    3792         case TB_GETBUTTONTEXTW:
    3793             return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
    3794 
    3795 /*      case TB_GETCOLORSCHEME:                 */ /* 4.71 */
    3796 
    3797         case TB_GETDISABLEDIMAGELIST:
    3798             return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
    3799 
    3800         case TB_GETEXTENDEDSTYLE:
    3801             return TOOLBAR_GetExtendedStyle (hwnd);
    3802 
    3803         case TB_GETHOTIMAGELIST:
    3804             return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
    3805 
    3806         case TB_GETHOTITEM:
    3807             return TOOLBAR_GetHotItem (hwnd);
    3808 
    3809         case TB_GETIMAGELIST:
    3810             return TOOLBAR_GetImageList (hwnd, wParam, lParam);
    3811 
    3812 /*      case TB_GETINSERTMARK:                  */ /* 4.71 */
    3813 /*      case TB_GETINSERTMARKCOLOR:             */ /* 4.71 */
    3814 
    3815         case TB_GETITEMRECT:
    3816             return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
    3817 
    3818         case TB_GETMAXSIZE:
    3819             return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
    3820 
    3821 /*      case TB_GETOBJECT:                      */ /* 4.71 */
    3822 /*      case TB_GETPADDING:                     */ /* 4.71 */
    3823 
    3824         case TB_GETRECT:
    3825             return TOOLBAR_GetRect (hwnd, wParam, lParam);
    3826 
    3827         case TB_GETROWS:
    3828             return TOOLBAR_GetRows (hwnd, wParam, lParam);
    3829 
    3830         case TB_GETSTATE:
    3831             return TOOLBAR_GetState (hwnd, wParam, lParam);
    3832 
    3833         case TB_GETSTYLE:
    3834             return TOOLBAR_GetStyle (hwnd, wParam, lParam);
    3835 
    3836         case TB_GETTEXTROWS:
    3837             return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
    3838 
    3839         case TB_GETTOOLTIPS:
    3840             return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
    3841 
    3842         case TB_GETUNICODEFORMAT:
    3843             return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
    3844 
    3845         case CCM_GETVERSION:
    3846             return TOOLBAR_GetVersion (hwnd);
    3847 
    3848         case TB_HIDEBUTTON:
    3849             return TOOLBAR_HideButton (hwnd, wParam, lParam);
    3850 
    3851         case TB_HITTEST:
    3852             return TOOLBAR_HitTest (hwnd, wParam, lParam);
    3853 
    3854         case TB_INDETERMINATE:
    3855             return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
    3856 
    3857         case TB_INSERTBUTTONA:
    3858             return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
    3859 
    3860         case TB_INSERTBUTTONW:
    3861             return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
    3862 
    3863 /*      case TB_INSERTMARKHITTEST:              */ /* 4.71 */
    3864 
    3865         case TB_ISBUTTONCHECKED:
    3866             return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
    3867 
    3868         case TB_ISBUTTONENABLED:
    3869             return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
    3870 
    3871         case TB_ISBUTTONHIDDEN:
    3872             return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
    3873 
    3874         case TB_ISBUTTONHIGHLIGHTED:
    3875             return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
    3876 
    3877         case TB_ISBUTTONINDETERMINATE:
    3878             return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
    3879 
    3880         case TB_ISBUTTONPRESSED:
    3881             return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
    3882 
    3883         case TB_LOADIMAGES:                        /* 4.70 */
    3884             // FIXME("missing standard imagelists\n");
    3885             return 0;
    3886 
    3887 /*      case TB_MAPACCELERATORA:                */ /* 4.71 */
    3888 /*      case TB_MAPACCELERATORW:                */ /* 4.71 */
    3889 /*      case TB_MARKBUTTON:                     */ /* 4.71 */
    3890 /*      case TB_MOVEBUTTON:                     */ /* 4.71 */
    3891 
    3892         case TB_PRESSBUTTON:
    3893             return TOOLBAR_PressButton (hwnd, wParam, lParam);
    3894 
    3895 /*      case TB_REPLACEBITMAP: */
    3896 
    3897         case TB_SAVERESTOREA:
    3898             return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
    3899 
    3900         case TB_SAVERESTOREW:
    3901             return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
    3902 
    3903         case TB_SETANCHORHIGHLIGHT:
    3904             return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
    3905 
    3906         case TB_SETBITMAPSIZE:
    3907             return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
    3908 
    3909         case TB_SETBUTTONINFOA:
    3910             return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
    3911 
    3912         case TB_SETBUTTONINFOW:
    3913             return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
    3914 
    3915         case TB_SETBUTTONSIZE:
    3916             return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
    3917 
    3918         case TB_SETBUTTONWIDTH:
    3919             return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
    3920 
    3921         case TB_SETCMDID:
    3922             return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
    3923 
    3924 /*      case TB_SETCOLORSCHEME:                 */ /* 4.71 */
    3925 
    3926         case TB_SETDISABLEDIMAGELIST:
    3927             return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
    3928 
    3929         case TB_SETDRAWTEXTFLAGS:
    3930             return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
    3931 
    3932         case TB_SETEXTENDEDSTYLE:
    3933             return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
    3934 
    3935         case TB_SETHOTIMAGELIST:
    3936             return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
    3937 
    3938         case TB_SETHOTITEM:
    3939             return TOOLBAR_SetHotItem (hwnd, wParam);
    3940 
    3941         case TB_SETIMAGELIST:
    3942             return TOOLBAR_SetImageList (hwnd, wParam, lParam);
    3943 
    3944         case TB_SETINDENT:
    3945             return TOOLBAR_SetIndent (hwnd, wParam, lParam);
    3946 
    3947 /*      case TB_SETINSERTMARK:                  */ /* 4.71 */
    3948 
    3949         case TB_SETINSERTMARKCOLOR:
    3950             return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
    3951 
    3952         case TB_SETMAXTEXTROWS:
    3953             return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
    3954 
    3955 /*      case TB_SETPADDING:                     */ /* 4.71 */
    3956 
    3957         case TB_SETPARENT:
    3958             return TOOLBAR_SetParent (hwnd, wParam, lParam);
    3959 
    3960         case TB_SETROWS:
    3961             return TOOLBAR_SetRows (hwnd, wParam, lParam);
    3962 
    3963         case TB_SETSTATE:
    3964             return TOOLBAR_SetState (hwnd, wParam, lParam);
    3965 
    3966         case TB_SETSTYLE:
    3967             return TOOLBAR_SetStyle (hwnd, wParam, lParam);
    3968 
    3969         case TB_SETTOOLTIPS:
    3970             return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
    3971 
    3972         case TB_SETUNICODEFORMAT:
    3973             return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
    3974 
    3975         case CCM_SETVERSION:
    3976             return TOOLBAR_SetVersion (hwnd, (INT)wParam);
    3977 
    3978 
    3979 /*      case WM_CHAR: */
    3980 
    3981         case WM_CREATE:
    3982             return TOOLBAR_Create (hwnd, wParam, lParam);
    3983 
    3984         case WM_ERASEBKGND:
    3985             return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
    3986 
    3987         case WM_GETFONT:
    3988                 return TOOLBAR_GetFont (hwnd, wParam, lParam);
    3989 
    3990 /*      case WM_KEYDOWN: */
    3991 /*      case WM_KILLFOCUS: */
    3992 
    3993         case WM_LBUTTONDBLCLK:
    3994             return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
    3995 
    3996         case WM_LBUTTONDOWN:
    3997             return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
    3998 
    3999         case WM_LBUTTONUP:
    4000             return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
    4001 
    4002         case WM_MOUSEMOVE:
    4003             return TOOLBAR_MouseMove (hwnd, wParam, lParam);
    4004 
    4005         case WM_MOUSELEAVE:
    4006             return TOOLBAR_MouseLeave (hwnd, wParam, lParam);   
    4007 
    4008         case WM_NCACTIVATE:
    4009             return TOOLBAR_NCActivate (hwnd, wParam, lParam);
    4010 
    4011         case WM_NCCALCSIZE:
    4012             return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
    4013 
    4014         case WM_NCPAINT:
    4015             return TOOLBAR_NCPaint (hwnd, wParam, lParam);
    4016 
    4017         case WM_NOTIFY:
    4018             return TOOLBAR_Notify (hwnd, wParam, lParam);
    4019 
    4020 /*      case WM_NOTIFYFORMAT: */
    4021 
    4022         case WM_PAINT:
    4023             return TOOLBAR_Paint (hwnd, wParam);
    4024 
    4025         case WM_SIZE:
    4026             return TOOLBAR_Size (hwnd, wParam, lParam);
    4027 
    4028         case WM_STYLECHANGED:
    4029             return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
    4030 
    4031 /*      case WM_SYSCOLORCHANGE: */
    4032 
    4033 /*      case WM_WININICHANGE: */
    4034 
    4035         case WM_CHARTOITEM:
    4036         case WM_COMMAND:
    4037         case WM_DRAWITEM:
    4038         case WM_MEASUREITEM:
    4039         case WM_VKEYTOITEM:
    4040             return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
     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);
    40414287
    40424288        default:
     
    40514297
    40524298VOID
    4053 TOOLBAR_Register (void)
     4299TOOLBAR_Register (VOID)
    40544300{
    40554301    WNDCLASSA wndClass;
     
    40634309    wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
    40644310    wndClass.lpszClassName = TOOLBARCLASSNAMEA;
    4065  
     4311
    40664312    RegisterClassA (&wndClass);
    40674313}
     
    40694315
    40704316VOID
    4071 TOOLBAR_Unregister (void)
     4317TOOLBAR_Unregister (VOID)
    40724318{
    40734319    UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);
Note: See TracChangeset for help on using the changeset viewer.